在主线DHT中,是否可以从一个端口接收然后通过另一个端口发送?

huangapple go评论57阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月18日 04:23:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定