Skip to content

Rework sftp packet decoding#62

Merged
mkj merged 8 commits into
mainfrom
pr/sftp-decode
Jul 16, 2026
Merged

Rework sftp packet decoding#62
mkj merged 8 commits into
mainfrom
pr/sftp-decode

Conversation

@mkj

@mkj mkj commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Previously SftpHandler had separate paths for decoding full packets
(Init state) and partial packets (ProcessFragment). Packet decoding
used either the input buffer directly, or the RequestHolder buffer.

Unknown packet handling was incorrect in some cases, triggerable by
repeated rename commands. When one occurred across a fragmented packet,
that would fail.

This can be simplified by making packet boundary detection separate from
the packet decoding. Now a single buffer is stored in a SftpSource, with
the SftpSource::fill() function reading from input based only (mostly)
on the packet length field. Once a full packet is accumulated,
SftpSource::decode() will decode it to either a packet or an appropriate
error.

Some special handling is needed for UnknownPackets and Write packets
which don't decode to the full length.

RequestHolder is removed, with its functionality and the proto::decode
functions moved into SftpSource. The byte-at-a-time decoding of
RequestHolder isn't needed any more.

The BBQueue input queue size is now adjusted with some documentation on
sizing, though requires further work.

The input buffer (previously used by RequestHolder) is now allocated
internally as MAX_REQUEST_LEN. That should perhaps be configurable
or passed as a buffer.

@mkj
mkj force-pushed the pr/sftp-decode branch 2 times, most recently from 168655a to 3142787 Compare July 13, 2026 14:53
@mkj

mkj commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@jubeormk1 I've changed the API for SftpServerHandler a bit now, I think it's close to the final shape of an API, allowing programs to specify req/resp buffer sizes, and use static storage for the buffers.

mkj added 8 commits July 16, 2026 21:56
Not widely used, and probably should be plain "en" anyway.
Reduced some other logging
Was missed in previous OutputProducer changes, no functional change.
Can be used for validating that the length is consistent.
Previously SftpHandler had separate paths for decoding full packets
(Init state) and partial packets (ProcessFragment).  Packet decoding
used either the input buffer directly, or the RequestHolder buffer.

Unknown packet handling was incorrect in some cases, triggerable by
repeated rename commands. When one occurred across a fragmented packet,
that would fail.

This can be simplified by making packet boundary detection separate from
the packet decoding. Now a single buffer is stored in a SftpSource, with
the SftpSource::fill() function reading from input based only (mostly)
on the packet length field. Once a full packet is accumulated,
SftpSource::decode() will decode it to either a packet or an appropriate
error.

Some special handling is needed for UnknownPackets and Write packets
which don't decode to the full length.

RequestHolder is removed, with its functionality and the proto::decode
functions moved into SftpSource. The byte-at-a-time decoding of
RequestHolder isn't needed any more.

The BBQueue input queue size is now adjusted with some documentation on
sizing, though requires further work.

The input buffer (previously used by RequestHolder) is now allocated
internally as MAX_REQUEST_LEN. That should perhaps be configurable
or passed as a buffer.
Both sides run in the same future, so only one waker is needed.
Avoids maitake-sync dependencies.
This now stores buffers within a SftpServerHandler, allowing
it to be kept in static storage, with sizes provided by the application.

Internal handling is renamed to Handler.

Tidy various documentation.

sftp demo is changed to reuse a SftpHandlerServer as an example.
@mkj
mkj force-pushed the pr/sftp-decode branch from 3142787 to 122a4cf Compare July 16, 2026 13:56
@mkj
mkj merged commit 122a4cf into main Jul 16, 2026
4 checks passed
@mkj
mkj deleted the pr/sftp-decode branch July 16, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant