netapp/src
networkException 47a470b281
everywhere: support unix sockets
This patch adds support for listening on and connecting to unix sockets.

This requires having wrapper types for various tokio specific network
abstractions while also supporting things like serialization and
deserialization.

Unfortionately i was unable to find a published crate fulfilling these
requirements.

For this reason I've published a crate myself. Called `tokio-unix-tcp`,
it serves as a drop in replacement for Tokio's TCP and Unix network
types.

I plan to maintain this library outside the scope of this project as
well, in general the code should be simple and stable enough however
to not require maintainance going forward.

As i said this crate aims to support the requirement mentioned above.
In addition to this it also strives to be more correct about handling
the different types of unix sockets, which the libraries i reviewed
were weak at. A list of these crates can be found in the crate README
under "Related work".

---

The changes to netapp can be summarized as the following:

- `std::net::SocketAddr` has been replaced by
  `tokio_unix_tcp::NamedSocketAddr` in most places. This enum encapsulates
  a IP address and port as well as a path in its variants and describes
  a concrete socket address netapp can bind or connect to.

- In some places `tokio_unix_tcp::SocketAddr` is used instead of
  `tokio_unix_tcp::NamedSocketAddr` as mentioned above. This is due to
  the way unix sockets work:

  The remote peer of a client from the perspective of a server is not
  a concrete path but `unnamed`. They just share a file descriptor
  for the actual communication channel. The local address of the server
  is the actual file system path the server is listening on.

  In some cases netapp might be configured to connect to another peer
  using a unix socket and to not send a reachable IP address and port
  or unix socket path using the `HelloMessage`.

  As per the above (the client's remote address will be `unnamed`),
  we have no way of connecting back to that peer. This will currently
  cause the connection to be aborted by the server.

- Listening on Unix sockets requires some additional handling like
  removing a previous file at the bind path and setting a correct
  mode (defaulting to `0o222` currently). This is handled by
  `tokio_unix_tcp`.

---

I've tested these changes by including them in garage and running basic
administration commands against a node and by running the unit tests here.

Basalt peering is currently lacking a proper cost calculation for unix
sockets - I'm sadly not familiar with this code.
2023-11-05 22:29:12 +01:00
..
peering everywhere: support unix sockets 2023-11-05 22:29:12 +01:00
bytes_buf.rs fix clippy 2023-01-31 23:57:33 +01:00
client.rs everywhere: support unix sockets 2023-11-05 22:29:12 +01:00
endpoint.rs fix comment 2022-09-13 11:52:35 +02:00
error.rs Add OrderTag to Req and Resp, refactor errors 2022-09-01 12:15:50 +02:00
lib.rs Add OrderTag to Req and Resp, refactor errors 2022-09-01 12:15:50 +02:00
message.rs update rmp-serde to v1.1, bump to 0.10.0 2023-09-27 12:32:54 +02:00
netapp.rs everywhere: support unix sockets 2023-11-05 22:29:12 +01:00
recv.rs Uniformize flag naming 2022-09-13 12:25:37 +02:00
send.rs Fix potential memory leak 2022-09-13 12:37:55 +02:00
server.rs everywhere: support unix sockets 2023-11-05 22:29:12 +01:00
stream.rs fill_buffer do something only if buf is empty 2022-09-13 12:08:33 +02:00
test.rs everywhere: support unix sockets 2023-11-05 22:29:12 +01:00
util.rs everywhere: support unix sockets 2023-11-05 22:29:12 +01:00