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

增加初始化时端口占用检查 #58

Merged
merged 2 commits into from
Aug 4, 2024
Merged

增加初始化时端口占用检查 #58

merged 2 commits into from
Aug 4, 2024

Conversation

cxz66666
Copy link
Collaborator

@cxz66666 cxz66666 commented Jul 30, 2024

假设在 zjuconnect运行前之前有一个 “nc” 进程运行,监听相同的 tcp/udp 端口​​。按理说 zjuconnect 需要报告此端口已被使用并退出,但是由于“nc”使用了“SO_REUSEPORT”和“SO_REUSEADDR”,zjuconnect 仍然可以成功绑定到此端口,但是绑定到该端口的所有套接字的行为是不确定的(https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#using-so_reuseaddr) 。因此我们需要在初始化期间检查是否存在任何潜在的端口冲突。

请注意,目前我们使用严格的检查策略,例如假设 nc 监听本地 TCP 地址“192.168.189.123:1234”,而我们想要监听 127.0.0.1:1234,目前使用的策略也会禁止此操作,尽管此操作可能是合法的。

BTW,删除了dockerfile中使用dockerproxy的部分,注释掉了使用goproxy.cn的部分,有需要自行build的可以自行开启

Assuming there is a "nc" process run before zjuconnect, which listening same tcp/udp port. By rights zjuconnect need report this port is already in use and exit, however due to "nc" use "SO_REUSEPORT" and "SO_REUSEADDR", zjuconnect still can bind to this port successfully, however the behavior for all sockets bound to that port is indeterminate (https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#using-so_reuseaddr). So we need to check for any potential port conflicts during initialization.

Be attention that we use a strict policy to check, for example assume nc listen to local TCP addr "192.168.189.123:1234", and we want to listen to 127.0.0.1:1234, we also prohibit this operation although this operation maybe legal.
@Mythologyli Mythologyli merged commit 579a029 into main Aug 4, 2024
35 checks passed
@cxz66666 cxz66666 deleted the check_bind_port branch August 4, 2024 06:54
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