英文:
Is it possible to receive from one port and send through another in mainline dht?
问题
I'm trying to implement mainline dht. While implementing I found it easier to use multithreading to handle requests and send requests at the same time. But it's impossible for a singular port to both send and receive at the same time. There's two solutions I thought of, one of those would be using different ports for receiving and sending, however in mainline dht it seems like whenever you send a request, nodes will remember you based on the port you send the request on. Is it possible to still implement a different port for receiving and sending?
英文:
I'm trying to implement mainline dht. While implementing I found it easier to use multithreading to handle requests and send requests at the same time. But it's impossible for a singular port to both send and receive at the same time. There's two solutions I thought of, one of those would be using different ports for receiving and sending, however in mainline dht it seems like whenever you send a request, nodes will remember you based on the port you send the request on. Is it possible to still implement a different port for receiving and sending?
答案1
得分: 1
DHT要求使用相同的端口进行发送和接收。
> 但是一个端口同时进行发送和接收是不可能的。
套接字是线程安全的,你可以同时向同一个套接字发出发送和接收系统调用。
如果你想在多个线程之间平衡读取,可以通过SO_REUSEPORT
打开绑定到相同端口的多个套接字,但这不应该是必要的,因为任何常规的DHT实现每秒只会看到十几个数据包,可能会短暂地增加到数千个,这是单个核心可以轻松处理的。
英文:
The DHT requires that the same port is used for sending and receiving.
> But it's impossible for a singular port to both send and receive at the same time.
Sockets are thread-safe, you can issue send and receive syscalls to the same socket at the same time.
If you want to load-balance reading across multiple threads you can open multiple sockets bound to the same port via SO_REUSEPORT
but that shouldn't be necessary because any regular DHT implementation will only see a dozen packets per second, perhaps with short burts into the thousands, something that a single core can comfortably handle.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论