Commit Graph

17 Commits

Author SHA1 Message Date
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