Repository navigation
feat: enable zstd compression auto-negotiation - #3108
Merged
Merged
Conversation
oferchen
force-pushed
the
feat/zstd-auto-negotiation
branch
from
April 6, 2026 06:17
f81d261 to
b900313
Compare
oferchen
marked this pull request as draft
April 6, 2026 06:19
Add zstd to the supported compression list advertised during vstring negotiation, gated on the `zstd` feature flag. When both peers support zstd, it is automatically selected as the preferred compression codec instead of falling back to zlibx/zlib. This mirrors upstream rsync's compat.c:100-112 where SUPPORT_ZSTD gates zstd in the preference list. The zstd per-token wire framing was validated in PR #3081, making it safe for auto-negotiation. Lz4 remains excluded until its wire format is interop-validated (task #1380). Graceful fallback to zlibx/zlib occurs when the remote peer does not advertise zstd support.
oferchen
force-pushed
the
feat/zstd-auto-negotiation
branch
from
April 6, 2026 06:31
b900313 to
79316cb
Compare
oferchen
marked this pull request as ready for review
April 6, 2026 06:31
Create the CompressedTokenEncoder once at session level in run_transfer_loop() and pass it to per-file functions, matching upstream token.c's single compression context pattern. Previously each file created a new encoder (new ZSTD_CCtx), breaking zstd's continuous-stream contract where the receiver expects one DCtx for the entire session. upstream: token.c uses a single compression context across all files
oferchen
added a commit
that referenced
this pull request
May 1, 2026
* feat: enable zstd compression auto-negotiation Add zstd to the supported compression list advertised during vstring negotiation, gated on the `zstd` feature flag. When both peers support zstd, it is automatically selected as the preferred compression codec instead of falling back to zlibx/zlib. This mirrors upstream rsync's compat.c:100-112 where SUPPORT_ZSTD gates zstd in the preference list. The zstd per-token wire framing was validated in PR #3081, making it safe for auto-negotiation. Lz4 remains excluded until its wire format is interop-validated (task #1380). Graceful fallback to zlibx/zlib occurs when the remote peer does not advertise zstd support. * fix: reuse sender-side CompressedTokenEncoder across files for zstd Create the CompressedTokenEncoder once at session level in run_transfer_loop() and pass it to per-file functions, matching upstream token.c's single compression context pattern. Previously each file created a new encoder (new ZSTD_CCtx), breaking zstd's continuous-stream contract where the receiver expects one DCtx for the entire session. upstream: token.c uses a single compression context across all files
oferchen
added a commit
that referenced
this pull request
May 5, 2026
* feat: enable zstd compression auto-negotiation Add zstd to the supported compression list advertised during vstring negotiation, gated on the `zstd` feature flag. When both peers support zstd, it is automatically selected as the preferred compression codec instead of falling back to zlibx/zlib. This mirrors upstream rsync's compat.c:100-112 where SUPPORT_ZSTD gates zstd in the preference list. The zstd per-token wire framing was validated in PR #3081, making it safe for auto-negotiation. Lz4 remains excluded until its wire format is interop-validated (task #1380). Graceful fallback to zlibx/zlib occurs when the remote peer does not advertise zstd support. * fix: reuse sender-side CompressedTokenEncoder across files for zstd Create the CompressedTokenEncoder once at session level in run_transfer_loop() and pass it to per-file functions, matching upstream token.c's single compression context pattern. Previously each file created a new encoder (new ZSTD_CCtx), breaking zstd's continuous-stream contract where the receiver expects one DCtx for the entire session. upstream: token.c uses a single compression context across all files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
supported_compressions()negotiation list, gated on thezstdfeature flag, matching upstream rsync'scompat.c:100-112preference order (zstd > zlibx > zlib > none)CompressedTokenEncoderlifecycle: create once at session level inrun_transfer_loop()and reuse across all files, matching upstreamtoken.c's single compression context pattern. Previously each file created a new encoder (newZSTD_CCtx), breaking zstd's continuous-stream contract where the receiver expects oneDCtxfor the entire sessionChanges
crates/protocol/src/negotiation/capabilities/algorithms.rs"zstd"as first entry insupported_compressions()vstring list (behind#[cfg(feature = "zstd")])crates/transfer/src/generator/delta.rscreate_token_encoder()visibility topub(super)sotransfer.rscan call it at session startstream_whole_file_transfer()signature: replacecompression: Option<CompressionAlgorithm>withencoder: Option<&mut CompressedTokenEncoder>(caller-provided)write_delta_with_compression()signature: replacecompression: Option<CompressionAlgorithm>withencoder: Option<&mut CompressedTokenEncoder>+is_zlib: boolcreate_token_encoder()calls) from both functionscrates/transfer/src/generator/transfer.rsCompressedTokenEncoderonce at session level before the transfer loopOption<&mut CompressedTokenEncoder>to per-file functionsfile_compression()to gate per-file encoder usage (skip-compress files getNone)crates/transfer/src/generator/tests.rsUpstream reference
token.c- single compression context per session,finish()resets run state between files but preserves CCtxcompat.c:100-112- zstd > zlibx > zlib negotiation preference orderTest plan