Commit Graph

33 Commits

Author SHA1 Message Date
Cassondra Foesch 861a8eaf5c pointer receivers and statusFromError(uint32, error) 2021-02-22 12:11:42 +00:00
Nicola Murino 3f969fcd59 add optional AllocationModeOptimized
after processing a packet we keep in memory the allocated slices and we reuse
them for new packets.
Slices are allocated in:

- recvPacket
- when we receive a sshFxpReadPacket (downloads)

The allocated slices have a fixed size = maxMsgLength.

Allocated slices are referenced to the request order id and are marked for reuse
after a request is served in maybeSendPackets.

The allocator is added to the packetManager struct and it is cleaned at the end
of the Serve() function.

This allocation mode is optional and disabled by default
2020-03-14 19:42:19 +01:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
John Eikenberry 05f7f0a92c add comment about purpose of context use in example/tests 2019-02-04 13:22:46 -08:00
John Eikenberry c71cbb17d3 'open' directory on opendir packet
Just like with files, the call to the hander to create the Lister is
done when the OPENDIR packet is received. This eliminates the need for
the lock in the filelist() method and opens the path for eliminating
more locks.
2019-01-29 14:49:22 -08:00
John Eikenberry 0a96e0de8a initial test of opening 'file' on open packet
Testing feasibility of creating the reader/writer when first receiving
the Open packet instead of waiting for the Get/Put.

This work is meant to make the Request locks easier to manage and
ultimately reducing/eliminating them as much as possible.
2019-01-29 14:49:22 -08:00
John Eikenberry 91a21603c9 add WithContext() calls to each test handler
Want to catch issues with using Context objects in tests. Instigated by
a deadlock bug (#280) when calling WithContext(). This triggers that
bug.
2019-01-29 14:49:05 -08:00
John Eikenberry 4cad28be43 eliminate bare values in composite literals
Using key-value pairs is much more future proof.
2018-07-23 14:49:12 -07:00
John Eikenberry 59287c7bbc test case to trigger error on opendir handle reuse 2018-06-05 18:34:07 -07:00
John Eikenberry 6227cfc71f organization of some tests didn't make sense 2018-06-05 16:35:42 -07:00
John Eikenberry 68e5d2f242 better/clearer function name 2018-03-10 12:51:41 -08:00
John Eikenberry 50208af173 refactor state lock to allow request copying
This refactors Request.state's lock use and converts it into a pointer
to allow for cleaner copying and better organization.
2018-02-06 11:59:15 -08:00
John Eikenberry b2b7fdff00 test custom error message returns 2018-01-16 14:12:00 -08:00
John Eikenberry 8722020a70 simpify Request struct and Method updating
In #192 we normalized all Request use to have pointer receivers. This
simplified reasoning and allowed for a simpler Request struct. This
change completes that work by eliminating the need for the
state/stackLock pointers and also removes the need for a new Request
each packet, reducing the pressure on the GC.

The main bit is that the RequestServer.openRequests[] map now stores Request
pointers and it only creates new Requests (replacing the mapped entry) when the
Method changes. It never updates/modifies an existing Request and the packet to
Method mapping is now all in place place (requestMethod).
2017-12-23 16:34:22 -08:00
John Eikenberry 87518d071d remove vestigial packets channel from request
Request object had a packet channel where it stored packets for
read/write/readdir handling. It was required in an earlier version of
the code (that was refactored before merging) and never got cleaned up.

This removes that channel and just passes the packet through the methods
instead. This is much simpler and would have eliminated the chance of
issue #195. It also looks like it should allow for a few more
simplifications as well.
2017-08-22 19:24:14 -07:00
John Eikenberry 19d66c2d96 change request.handle() to request.callHandler()
Handle was already used for sftp's session 'handle' which is the name
used in the other code and sftp specs.
2017-08-20 17:51:45 -07:00
John Eikenberry aedf9a737a Fix #192 all Request methods use pointer recivers
Prevents subtle copy bugs and made the 1 required Request copy explicit.
2017-08-20 17:03:15 -07:00
John Eikenberry cffd2fabb0 Fix #195 Handler wrappers deal with errors
TLDR; have the Handler wrappers generate the response packets for the
errors instead of returning the errors.

Errors from the handers was returned up the stack to the request-server
handler call. In cases of errors the packet for the error was then
generated using the passed in packet (the incoming packet).

For file read/write/list operations the incoming packet data (includeing
ID) is put in a queue/channel so that it can be handled by the same file
handling code returned by the handler.

Due to gorouting scheduling, in some cases the packets in the channel
won't line up with the incoming packets. That is the worker that took an
incoming packet with one ID might respond with a packet with a different
ID. This doesn't matter as the reply order of packets doesn't matter.

BUT when this response packet that doesn't match IDs with the incoming
packet system returns an error, it uses the incoming packets ID to
generate the error packet. So the error response would use that ID and
the packet from the queue, once processed, would also use that ID
(because on success  it uses the ID from the packet in the queue).

This patch fixes the issue by having the code that works with the
packets, either incoming or from the queue, generate the error packet.
So there is no chance of them getting out of sync.
2017-08-20 16:15:01 -07:00
John Eikenberry bd3f00a6ea Merge pull request #194 from pkg/move-handle-ptr-request
Move Request.handle to *Request
2017-08-20 15:09:04 -07:00
sandreas 653e2f1043 Merge branch 'master' into master 2017-08-13 17:00:45 +02:00
andreas 4d7bb970c4 Resolved conflict with SftpServerWorkerCount
Splitted cleanPath into cleanPacketPath and cleanPath for better handling of slashes in file paths
Added test for cleanPath func
Removed code duplication => filepath.ToSlash(filepath.Clean(...)) => cleanPath(...)
Fixed tests for runLs to match year or time
Renamed constants to fit hound rules
2017-08-13 14:00:08 +02:00
Dave Cheney f2782dd6fa Move Request.handle to *Request
Updates #192

Move handle() onto *Request, this has flow on effects to the interface
types declared in request-interface.go, the examples and the tests.

The decision to address #192 started with advice from gopl.io, but I
think has uncovered several bugs as many of the request methods operate
on copies of data stored in the RequestServer's cache. I think this is
unintentional, but may point to some correctness issues, see #193.
2017-08-13 17:22:00 +10:00
John Eikenberry 1a91f318a0 make (sS)ftpServerWorkerCount constant public
The number of workers is important for some functionality in
request-server extentions. It is a constant, so making it public
seems easy and safe.
2017-08-10 17:53:41 -07:00
John Eikenberry 733115c415 Fixes #184; better fix for file batching
I didn't like how the initial fix for #184 required the handler author
to track the token/offset for the filelist. I came up with a way to do
it that mimic'd the FileReader handler interface using a method
something like ReaderAt except for file lists.

changed MaxFileinfoList to a var for testing and tweaking

Renaming FileInfoer interface to FileLister.
FileInfoer -> FileLister
Fileinfo -> Filelist
2017-08-10 15:36:41 -07:00
John Eikenberry 016dabfa49 golint and go vet fixes 2017-02-18 18:20:37 -08:00
John Eikenberry ce4586e8a5 convert request to be pass by value
Encapsulate stateful data into sub-structures with pointer references
from the Request structure. This allows me to pass by value in most
cases to keep non-stateful (write once) data data race free and tightly
controlling access to stateful data to ease locking.
2017-02-18 18:20:37 -08:00
John Eikenberry 94ae9c6822 fix issue with out-of-order packets 2017-02-18 18:20:37 -08:00
John Eikenberry 9962211713 linter fixes 2017-02-18 18:20:37 -08:00
John Eikenberry 96da577ac9 remove superfluous pflags field from request
Pflags specify file open operations which don't make sense for the
request based interface and they were never used.
2017-02-18 18:20:37 -08:00
John Eikenberry a15e6f57e3 updated tests 2017-02-18 18:20:37 -08:00
John Eikenberry f6042b29bc remove redundant 'request' from handle method name 2017-02-18 18:20:36 -08:00
John Eikenberry e307459f45 factor out response struct 2017-02-18 18:20:36 -08:00
John Eikenberry 8b3c376b5a add request tests 2017-02-18 18:20:36 -08:00