-
Notifications
You must be signed in to change notification settings - Fork 191
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
refactor: clean up TCP and UDP serving #146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick review. I ended up adding UDP without realizing you had already reviewed. Would you mind reviewing the new code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
service/tcp.go
Outdated
ciphers: ciphers, | ||
m: m, | ||
readTimeout: timeout, | ||
replayCache: replayCache, | ||
targetIPValidator: onet.RequirePublicIP, | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit why do we wrap the tcpHandler in brackets ()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
service/udp.go
Outdated
} | ||
|
||
func (s *udpService) SetTargetIPValidator(targetIPValidator onet.TargetIPValidator) { | ||
func (s *packetHandler) SetTargetIPValidator(targetIPValidator onet.TargetIPValidator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit maybe use p
(stands for packetHandler
) instead of s
(stands for udpService
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with h
, for "handler"
This PR makes the serving logic a lot simpler. Serve() was already tied to the listener lifetime, so now that's explicit, and closing the listener is the way to stop serving. We no longer need the complicated mutex logic.
This introduces a
StreamListener
concept that can return any type of StreamConn, allowing for listening on Unix sockets or introduce intermediate transports (e.g. Websockets). We no longer require TCP.The handler will allow for easier replacement of the protocol in the future. That also makes it easier to test.