When sending a UDP packet, we need to specify its destination. According to L115-L131, sender_vec stores the SockAddr from a incoming packet(usually from a client) one by one, then consumes them when the response arrives.
However, this would work only under some ideal conditions, where there is only one client sending, and the number of response packets should be the same. Otherwise, the program would drop some of the response packets, or incorrectly send them to another peer, or have the SockAddr left in sender_vec...
Instead of counting the incoming SockAddr one by one, I think we should record the associated pairs of incoming SockAddr and remote SockAddr for a period of time. To deal with multiple clients, maybe we need to allocate a unique local SockAddr for each incoming Sockaddr, and also have it recorded. Finally, the UDP part would work somewhat like a NAT device.
This will bring extra complexity and costs. I think add these codes to a new module would be a better choice.
And we should consider to make UDP forwarding optional, since not everyone needs it.
As has been mentioned in #21, sometimes UDP forwarding does not work properly.
https://github.com/zhboner/realm/blob/3243f54e045aef77f5db028fbbd1cfe5f38a88f9/src/relay.rs#L115-L131
When sending a UDP packet, we need to specify its destination. According to L115-L131,
sender_vec
stores theSockAddr
from a incoming packet(usually from a client) one by one, then consumes them when the response arrives.However, this would work only under some ideal conditions, where there is only one client sending, and the number of response packets should be the same. Otherwise, the program would drop some of the response packets, or incorrectly send them to another peer, or have the
SockAddr
left insender_vec
...Instead of counting the
incoming SockAddr
one by one, I think we should record the associated pairs ofincoming SockAddr
andremote SockAddr
for a period of time. To deal with multiple clients, maybe we need to allocate a uniquelocal SockAddr
for eachincoming Sockaddr
, and also have it recorded. Finally, the UDP part would work somewhat like a NAT device.