Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Add QUIC Address Discovery to iroh (#3049)
## Description There were two main things to "solve" on the iroh side: 1) gross circular dependency between magicsock and the quinn endpoint 2) needing to handle QAD packets in a special way, like we do with STUN packets that get sent from net-report The first was accomplished by figuring out how to make `MagicSock::spawn` be the location that builds the `quinn::Endpoint`. This is what was changed: - implemented `AsyncUdpSocket` on `MagicSock` itself, rather than `magicsock::Handle` - `magicsock::Handle` now contains the `quinn::Endpoint` - we now pass down a `server_config` as a `MagicSock::Option` - in `MagicSock::spawn`: - after building the `MagicSock` we now build the `quinn::Endpoint` using `Arc<MagicSock>` as the `AsyncUdpSocket` - then we clone the `quinn::Endpoint` and passed it to the `magicsock::Actor` (which is independent of `MagicSock`) - give the `quinn::Endpoint` to the `magicsock::Handle`, which is the actual struct that we use to interact with the magicsocket - the `iroh::Endpoint` now interacts with the `quinn::Endpoint` using `msock.endpoint()` in all places ~The second was accomplished by keeping a list of special "QAD addresses" on the `NodeMap` (`NodeMap::qad_addrs`), and using specific methods to `add_qad_addrs`, `get_qad_addrs_for_send` and `get_qad_addrs_for_recv` to deal with the fickle way that the `quinn::Endpoint` expects SocketAddrs to behave when it dials and when it receives packets:~ - ~before we do a net-report, we first attempt to resolve the `RelayUrl`s in the `RelayMap` to get the `SocketAddr`s that we expect we will dial when we do a QAD probe~ - ~we add those addresses to the `NodeMap` ~ - ~on the "send" side of the `AsyncUdpSocket`, after we do our normal checks for QuicMappedAddrs, we then check to see if the QuicMappedAddr is actually just a normal socket addr that we expect to use for QAD. If so, we just send the packets using the `get_qad_addr_for_send` address~ - ~on the "recv" side of the `AsyncUdpSocket`, after we check to see if the recv'd address can be mapped to a QuicMappedAddr & therefore can be received using our normal process, we then check to see if the address is one that we expect for QAD. If so, we make sure to associate the packet with the `get_qad_addr_for_recv` address and pass it along~ ~The most "unreliable" bits of this are due to dns. Before running a net report, we now have to do dns discovery for all the RelayUrls. I've capped this at 300 ms but it means that until we cache the dns responses then we have this delay before starting net-report. I've also done a bit of a cheat: when we initially start the `magicsock::Actor`, I've added a call to `resolve_qad_addrs` that has a timeout of 10 ms, just to send out the dns packets and hopefully get a jump on caching the responses.~ The second was accomplished by creating a new `IpMappedAddrs` struct that keeps track of `IpMappedAddrs` to the actual `SocketAddr` that it represents. This is akin to how we deal with `QuicMappedAddr` (which is now called `NodeIdMappedAddr`. `netreport` now takes an optional `IpMappedAddrs`, and when it resolves a `RelayUrl`, it adds the resolved IP addr to the `IpMappedAddrs`, and uses the mapped address when sending on QUIC. In `iroh`, we check to see if the destination or source address is an `IpMappedAddr` or a `NodeIdMappedAddr`. If so, it maps the addresses correctly before returning the transmit to the endpoint or sending the transmit over UDP. ## Most interesting bit So...if someone adds an IP address to `IpMappedAddrs`, we can allow folks to use the Endpoint as a sort of normal quinn::Endpoint, bypassing our special iroh holepunching sauce. depends on #3032 ## Breaking Changes - `iroh-net-report` - changed - `iroh_net_report::Client::new` now takes additional parameter `mapped_addrs: `Option<IpMappedAddrs>` ## Change checklist - [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. - [x] Tests if relevant. - [ ] All breaking changes documented. --------- Co-authored-by: “ramfox” <“kasey@n0.computer”> Co-authored-by: Floris Bruynooghe <flub@n0.computer> Co-authored-by: Asmir Avdicevic <asmir.avdicevic64@gmail.com>
- Loading branch information