Skip to content

Conversation

@notsure2
Copy link
Contributor

This adds multiple parameters to config (documented in README.md) which allow precise and control control over socket buffers.
For incoming, buffer must be set on listener socket, and for outgoing it must be set before connection.

@notsure2
Copy link
Contributor Author

@cbeuw i have been using this 1 year+ without issue can we get merge ?

@notsure2 notsure2 marked this pull request as draft May 2, 2025 07:19
@notsure2
Copy link
Contributor Author

notsure2 commented May 2, 2025

I will review this one more time to be 100% absolutely sure

@cbeuw
Copy link
Owner

cbeuw commented May 2, 2025

Sorry for leaving this, I will give it a proper look at in the next day or so, testing it together with uTLS updates

data, after which the connection will be closed by Cloak. Cloak will not enforce any timeout on TCP connections after it
is established.

`LoopbackTcpSendBuffer` is the number of bytes to use for the tcp loopback send buffer. Use a low value like 4096 to reduce upload bufferbloat on client.
Copy link
Owner

Choose a reason for hiding this comment

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

Given that this parameter controls the send buffer from ck-client to e.g. shadowsocks client, shouldn't this be relevant to download instead of upload? And LoopbackTcpReceiveBuffer below should affect upload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's cases where cloak is used in tunnel mode not with ss, so user would upload to cloak and then to cloak server directly, not to ss first. This parameter is made for that case.

For usage with ss, it will be ss local receive that needs clamping, in such case buffer between ss client and ck-client will also need clamping (either from ss send side or ck receive side), I have implemented that in ss-rust in the past and it's part it for some time now already.

Copy link
Owner

Choose a reason for hiding this comment

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

There's cases where cloak is used in tunnel mode not with ss, so user would upload to cloak and then to cloak server directly, not to ss first.

But even in this case, uploaded data from user would fill up the receive buffer in ck-client, rather than send buffer, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's why the ck-client tcp receive needs to be clamped. I put controls for all 4 sides, local send/ local receive / remote send / remote receieve for client and server.

The general principle is all the parts that are on the same machine need to have clamped buffers, and only the ends exposed to the remote internet need to have open buffers, otherwise, bufferbloat will happen.

Copy link
Owner

Choose a reason for hiding this comment

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

I understand the need for clamping, my issue is with the line

Use a low value like 4096 to reduce upload bufferbloat on client.

This should describe LoopbackTcpReceiveBuffer, not here.

Copy link
Owner

Choose a reason for hiding this comment

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

It may be better to name these LocalTcpUploadBuffer, LocalTcpDownloadBuffer, RemoteTcpUploadBuffer and RemoteTcpDownloadBuffer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes renaming it makes sense it was very confusing even to me. I will check and update this PR.

Copy link
Contributor Author

@notsure2 notsure2 May 13, 2025

Choose a reason for hiding this comment

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

For client the rename may make sense but for the server not. Because loopback for server point of view means any direction of socket that's connected on loopback IP whether it's to the "proxybook" or to the "incoming client"

The consideration of clamping the buffers applies mainly to Loopback IP in any side of the connection. To remove confusion I will implement the 4 properties for the server as well. Where for server local is to the proxy book and remote is to the client. The unification of terminology will make things simpler.

@notsure2 notsure2 marked this pull request as ready for review May 8, 2025 11:39
@notsure2
Copy link
Contributor Author

notsure2 commented May 8, 2025

I tested my changs again and it works fine

@notsure2 notsure2 force-pushed the tcp-buffer-controls branch from c7d1b5d to c3cde8d Compare May 8, 2025 18:51
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.

2 participants