Skip to content

Commit 2a49265

Browse files
authored
refactor(iroh): Factor out socket-related state & construction into magicsock::SocketState and ActorSocketState (#3203)
## Description This factors out the socket & related state from `MagicSock` into a `SocketState` struct, as well as from the `Actor` struct into an `ActorSocketState` struct. This helps reduce line noise in the `magicsock::Handle::with_name` function related to all the `#[cfg(not(wasm_browser))]`. In order to do this I needed to slightly modify how `UdpConn` is used. We now work *more* with `Arc<UdpSocket>` rather than `UdpConn`, and treat `UdpConn` only as a wrapper to allow us to implement `quinn::AsyncUdpSocket` for `Arc<UdpSocket>`. I've also moved the socket binding logic from `udp_conn.rs` to `magicsock.rs` and cleaned it up. The main difference between `SocketState` and `ActorSocketState` is that the former stores `UdpConn` and the latter stores `Arc<UdpSocket>`, as the former uses its sockets only to implement methods from `AsyncUdpSocket` for `MagicSock`, whereas the latter uses it for a bunch of things, including sending disco messages and port mapping. Finally, I also went ahead and renamed any `pconn4` and `pconn6` names to say `socket`, `socket.v4` or `socket.v6`, as I find that would make more sense. ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant.
1 parent 0c7a122 commit 2a49265

File tree

3 files changed

+186
-178
lines changed

3 files changed

+186
-178
lines changed

iroh-net-report/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use tracing::{debug, error, info_span, trace, warn, Instrument};
3737
mod defaults;
3838
#[cfg(not(wasm_browser))]
3939
mod dns;
40-
#[cfg(not(wasm_browser))]
4140
mod ip_mapped_addrs;
4241
mod metrics;
4342
#[cfg(not(wasm_browser))]
@@ -65,7 +64,6 @@ pub mod portmapper {
6564
}
6665
}
6766

68-
#[cfg(not(wasm_browser))]
6967
pub use ip_mapped_addrs::{IpMappedAddr, IpMappedAddrError, IpMappedAddresses, MAPPED_ADDR_PORT};
7068
pub use metrics::Metrics;
7169
pub use options::Options;

0 commit comments

Comments
 (0)