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

Make tcp keepalive optional on client -> server and server -> proxy connections, controllable via config. #82

Merged
merged 1 commit into from
Apr 4, 2020

Conversation

notsure2
Copy link
Contributor

@notsure2 notsure2 commented Dec 14, 2019

Hello,
This pull request just makes the default tcp keepalive since GO 1.13 of 15 seconds explicit.
It is enabled on the client app, in the client cloak --> remote cloak direction
and it is enabled on the server app in the server cloak --> server proxy direction.

@notsure2
Copy link
Contributor Author

notsure2 commented Apr 4, 2020

@cbeuw I would appreciate any comments :-)

@cbeuw
Copy link
Owner

cbeuw commented Apr 4, 2020

Sorry I forgot about the original pull request you made quite a few months ago. But thanks for the code.

My main concern is that while this definitely improves connection stability, TCP keep-alive relies on sending keep-alive packets every so often. This may be used to detect Cloak, especially when most web browsers and web servers don't use keep-alive'd connections.

I suggest to make this optional. There can be a KeepAlive field in the config file. If its value is non-zero, the KeepAlivePeriod is set to its value

@notsure2
Copy link
Contributor Author

notsure2 commented Apr 4, 2020

@cbeuw

I don't believe the client actually sends a steady stream of keep alive packets. It just sets socket option that tells the OS to send a keepalive packet after the period (15 seconds) of no activity. So in practice its effect is actually small. It should be noted that go already made this the default, so cloak has always been sending it anyway.

Edit: I'll implement the option. With the default actually disabling keepalive.

@cbeuw
Copy link
Owner

cbeuw commented Apr 4, 2020

It should be noted that go already made this the default

Thanks I didn't know that D:

time.Sleep(time.Second * 3)
goto makeconn
}
err = remoteConn.(*net.TCPConn).SetKeepAlivePeriod(time.Duration(15 * time.Second))
Copy link
Owner

Choose a reason for hiding this comment

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

In https://golang.org/pkg/net/#Dialer it says when Diailer.KeepAlive (defined on line 35) is zero, it defaults to 15 seconds. Is this explicit setting still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like to be explicit about the timing in case of compiling with different go versions.

Copy link
Owner

Choose a reason for hiding this comment

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

I think this behaviour was added in Go 1.12: golang/go#23459. That's the minimum version needed to compile Cloak. In order to be explicit it may be better to set the KeepAlive field on line 35. Errors will be caught on line 43

@@ -180,6 +180,18 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
user.CloseSession(ci.SessionId, "Failed to connect to proxy server")
continue
}
err = localConn.(*net.TCPConn).SetKeepAlive(true)
Copy link
Owner

Choose a reason for hiding this comment

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

localConn could be a UDP conn. This timeout should be dealt with in Pipe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is TCP keepalive, not sending of data. I think in Pipe it is too late to set any socket options. I can just check if the connect is a TCPConn instead.

…ctions. Use KeepAlive value in config (seconds).
@notsure2
Copy link
Contributor Author

notsure2 commented Apr 4, 2020

@cbeuw Can you check again ? It should now default to explicit off, otherwise it will be taken from KeepAlive config key. Value is expected to be in seconds.

@notsure2 notsure2 changed the title Add a 10 second tcp keepalive on client and server Make tcp keepalive optional on client -> server and server -> proxy connections, controllable via config. Apr 4, 2020
@cbeuw cbeuw merged commit 2de034e into cbeuw:master Apr 4, 2020
@notsure2 notsure2 deleted the tcp-keepalive branch April 4, 2020 15:05
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.

None yet

2 participants