MystenLabs / scion-rs

This library provides an end-host networking stack for SCION and can be used in Rust applications to communicate over a SCION network.
Apache License 2.0
19 stars 5 forks source link

Revisit behavior of UDP socket and its connection states #89

Closed mlegner closed 9 months ago

mlegner commented 9 months ago

Currently, we can call connect repeatedly on a socket even if it already has a remote_address set. Additionally, we allow calling send_to(destination), even if it is already in a "connected" state.

We should decide if we want to change that behavior; e.g., return an AlreadyConnectedError when trying to repeatedly connect().

jpcsmith commented 9 months ago

From the UDP man pages and those for connect, send, and recv we can identify the following behaviours of the socket in order to be consistent:

When not connected:

When connected:

Both:

Other features which warrant their own issues:

Additionally, there are some race conditions worth paying attention to when working with bind + connect in standard UDP sockets. We should look which apply here.

mlegner commented 9 months ago

Thanks a lot for this detailed investigation, @jpcsmith!

Question: what behaviour do we want to observe if connect is called while a recv is in progress?

I guess there are two options: (1) Use the state from when recv was called or (2) use the new state. I can see arguments for both options, but would opt for (1).

jpcsmith commented 9 months ago

Regarding the race conditions, they are only applicable if we attempt to support "UDP accept" where we create new connected sockets for peers. This, however, would also require some kind of demultiplexing of incoming packets to the correct socket