Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Penguin v7 #33

Closed
wants to merge 14 commits into from
Closed

Penguin v7 #33

wants to merge 14 commits into from

Conversation

myzhang1029
Copy link
Owner

@myzhang1029 myzhang1029 commented Mar 20, 2024

There have been a few issues accumulating that requires a protocol update to implement. Planned changes:

  • Stream ID Combine the source and destination ports (stream frame) into one 32-bit stream ID
  • Bind Add a Bind operation to the stream protocol
  • 32-bit rwnd Change the frame buffer type from u64 to u32

Stream ID

Rationale

There has been no reason to have two ports like actual TCP/IP. The only purpose of this field is to uniquely identify multiplexed channel. Using a single u16 reduces overhead and possible error conditions.

Potential Considerations

The stream ID probably has to be generated by the client, since the client initiates the channel.

With two ports, each side maintains a connection hash table based on the port number, so duplicate ports never affects the other side. However, now one side is responsible for generating the stream ID, the server needs to be able to deal with ill-implemented clients generating duplicate stream IDs.

Proposed solution: once a duplicate Syn is detected, it is Rsted and both the original (established) channel and this new channel are aborted.

Bind

Rationale

This would allow the client to ask the server to bind to a port, which makes it possible to implement #24 and SOCKS5 BIND.

Potential Considerations

The server now needs to be able to initiate channels for incoming connections, so the code for establishing new channels needs to become symmetrical, at least more so.

32-bit rwnd

Rationale

In this implementation, the default rwnd has been 2<<9 which is far lower than 2<<63. Using u32 will allow penguin to work on platforms with no AtomicU64.

Potential Considerations

None right now.

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 93.04636% with 21 lines in your changes missing coverage. Please review.

Project coverage is 78.71%. Comparing base (9fe3c67) to head (124d62f).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/mux/frame.rs 94.44% 6 Missing ⚠️
src/mux/inner.rs 78.57% 6 Missing ⚠️
src/arg.rs 33.33% 2 Missing ⚠️
src/client/maybe_retryable.rs 0.00% 2 Missing ⚠️
src/mux/lib.rs 0.00% 2 Missing ⚠️
src/mux/stream.rs 0.00% 2 Missing ⚠️
src/mux/timing.rs 99.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   77.63%   78.71%   +1.08%     
==========================================
  Files          31       30       -1     
  Lines        5370     5216     -154     
==========================================
- Hits         4169     4106      -63     
+ Misses       1201     1110      -91     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@myzhang1029
Copy link
Owner Author

Also nice to remove UDP client ID and make that fully symmetric too.

@myzhang1029 myzhang1029 force-pushed the penguin-v7 branch 2 times, most recently from e383ef7 to 3b51ffa Compare April 3, 2025 00:35
@myzhang1029 myzhang1029 requested a review from Copilot April 3, 2025 01:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the protocol for Penguin v7 by revising the stream frame structure. Key changes include:

  • Combining source and destination ports into a single 32-bit stream ID.
  • Adding a new bind operation via a dedicated opcode.
  • Changing the receive window field type from u64 to u32.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mux/frame.rs Refactored stream frame structure and methods to support Penguin v7.
PROTOCOL.md Updated protocol version and stream frame format details for v7.

@myzhang1029 myzhang1029 requested a review from Copilot April 3, 2025 02:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR upgrades the protocol to "Penguin v7" by revising how streams are identified and by switching frame buffer types from 64-bit to 32-bit. Key changes include:

  • Combining separate source and destination port fields into a single 16‑bit stream ID throughout the code.
  • Changing internal counters and window size types from u64 to u32.
  • Updating protocol documentation and error messages to reflect these changes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mux/test.rs Updated logging to reflect the new stream_id field instead of separate port numbers.
src/mux/stream.rs Converted port-based fields to use stream_id and updated associated atomic types to u32.
src/mux/lib.rs Revised error types and module exports reflecting updated stream identification.
src/mux/inner.rs Modified stream management logic to use stream_id and updated task names and associated comments.
src/mux/frame.rs Adjusted frame serialization and deserialization to use stream_id and new opcode definitions.
src/mux/config.rs Changed RWND and threshold types from u64 to u32.
PROTOCOL.md Updated protocol version to v7 and modified frame format details to align with new stream_id usage.
.github/workflows/cross-releases.yml Enabled additional rust targets by uncommenting previously disabled targets.
Comments suppressed due to low confidence (1)

PROTOCOL.md:115

  • The protocol documentation states the stream ID is a 32-bit unsigned integer, but the implementation uses a 16-bit stream ID. Please update the documentation to accurately reflect the implementation.
frame with the `Syn` operation code and the stream ID set to a unique 32-bit unsigned integer in network byte order.

src/mux/inner.rs Outdated
Comment on lines 491 to 494
let entry = streams.get_mut(&stream_id).expect("TODO");
// Change the state of the stream to `Established`
let Some(sender) = entry.establish(stream_data) else {
return Err(Error::BogusSynAck);
todo!();
Copy link
Preview

Copilot AI Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the placeholder error message 'TODO' with a descriptive message and handle the case where the stream cannot be established instead of panicking.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@myzhang1029
Copy link
Owner Author

Change: since both the server and client might initiate multiplexed streams/datagrams, Stream ID is reverted to sport/dport to avoid race conditions.

@myzhang1029 myzhang1029 force-pushed the penguin-v7 branch 4 times, most recently from 0c98d97 to c250829 Compare April 4, 2025 03:42
@@ -262,18 +244,16 @@
#[tracing::instrument(skip(self), level = "debug")]
#[inline]
pub async fn send_datagram(&self, frame: DatagramFrame) -> Result<()> {
let payload: Bytes = Vec::<u8>::try_from(frame)?.into();
// Always flush datagrams immediately
// Always flush datagrams immediately TODO

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
@myzhang1029 myzhang1029 requested a review from Copilot April 4, 2025 03:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.

@myzhang1029 myzhang1029 marked this pull request as ready for review April 4, 2025 03:54
Signed-off-by: Zhang Maiyun <[email protected]>
Signed-off-by: Zhang Maiyun <[email protected]>
Signed-off-by: Zhang Maiyun <[email protected]>
Signed-off-by: Zhang Maiyun <[email protected]>
Signed-off-by: Zhang Maiyun <[email protected]>
Signed-off-by: Zhang Maiyun <[email protected]>
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