Skip to content

Commit 565ebec

Browse files
chore: unify nat traversal naming (#445)
* remove iroh from code, in favor of n0; remove hole punching in favor of nat traversal * updates * url fmt
1 parent 8fc9cdd commit 565ebec

8 files changed

Lines changed: 86 additions & 65 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Iroh Quinn
1+
# n0 Quinn
22

33
> This is a fork based on [quinn](https://github.com/quinn-rs/quinn), maintained
44
> by [n0](https://github.com/n0-computer). Currently published to crates.io under

quinn-proto/src/config/transport.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ impl TransportConfig {
450450
/// Sets the maximum number of nat traversal addresses this endpoint allows the remote to
451451
/// advertise
452452
///
453-
/// Setting this to any nonzero value will enable Iroh's holepunching, loosely based in the Nat
454-
/// Traversal Extension for QUIC, see
453+
/// Setting this to any nonzero value will enable n0's nat traversal protocol, loosely based in
454+
/// the Nat Traversal Extension for QUIC, see
455455
/// <https://www.ietf.org/archive/id/draft-seemann-quic-nat-traversal-02.html>
456456
///
457457
/// This implementation expects the multipath extension to be enabled as well. if not yet

quinn-proto/src/connection/mod.rs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
self, Close, DataBlocked, Datagram, FrameStruct, NewToken, ObservedAddr, StreamDataBlocked,
3535
StreamsBlocked,
3636
},
37-
iroh_hp,
37+
n0_nat_traversal,
3838
packet::{
3939
FixedLengthConnectionIdParser, Header, InitialHeader, InitialPacket, LongType, Packet,
4040
PacketNumber, PartialDecode, SpaceId,
@@ -309,7 +309,8 @@ pub struct Connection {
309309
// paths. Or a set together with a minimum. Or something.
310310
abandoned_paths: FxHashSet<PathId>,
311311

312-
iroh_hp: iroh_hp::State,
312+
/// State for n0's (<https://n0.computer>) nat traversal protocol.
313+
n0_nat_traversal: n0_nat_traversal::State,
313314
qlog: QlogSink,
314315
}
315316

@@ -483,8 +484,7 @@ impl Connection {
483484
max_path_id_with_cids: PathId::ZERO,
484485
abandoned_paths: Default::default(),
485486

486-
// iroh's nat traversal
487-
iroh_hp: Default::default(),
487+
n0_nat_traversal: Default::default(),
488488
qlog,
489489
};
490490
if path_validated {
@@ -1999,7 +1999,7 @@ impl Connection {
19991999
buf: &mut Vec<u8>,
20002000
path_id: PathId,
20012001
) -> Option<Transmit> {
2002-
let server_side = self.iroh_hp.server_side_mut().ok()?;
2002+
let server_side = self.n0_nat_traversal.server_side_mut().ok()?;
20032003
let probe = server_side.next_probe()?;
20042004
if !self.paths.get(&path_id)?.data.validated {
20052005
// Path is not usable for probing
@@ -5150,7 +5150,7 @@ impl Connection {
51505150
}
51515151
}
51525152
Frame::AddAddress(addr) => {
5153-
let client_state = match self.iroh_hp.client_side_mut() {
5153+
let client_state = match self.n0_nat_traversal.client_side_mut() {
51545154
Ok(state) => state,
51555155
Err(err) => {
51565156
return Err(TransportError::PROTOCOL_VIOLATION(format!(
@@ -5168,7 +5168,7 @@ impl Connection {
51685168
Ok(maybe_added) => {
51695169
if let Some(added) = maybe_added {
51705170
self.events.push_back(Event::NatTraversal(
5171-
iroh_hp::Event::AddressAdded(added),
5171+
n0_nat_traversal::Event::AddressAdded(added),
51725172
));
51735173
}
51745174
}
@@ -5178,7 +5178,7 @@ impl Connection {
51785178
}
51795179
}
51805180
Frame::RemoveAddress(addr) => {
5181-
let client_state = match self.iroh_hp.client_side_mut() {
5181+
let client_state = match self.n0_nat_traversal.client_side_mut() {
51825182
Ok(state) => state,
51835183
Err(err) => {
51845184
return Err(TransportError::PROTOCOL_VIOLATION(format!(
@@ -5187,15 +5187,14 @@ impl Connection {
51875187
}
51885188
};
51895189
if let Some(removed_addr) = client_state.remove_remote_address(addr) {
5190-
self.events
5191-
.push_back(Event::NatTraversal(iroh_hp::Event::AddressRemoved(
5192-
removed_addr,
5193-
)));
5190+
self.events.push_back(Event::NatTraversal(
5191+
n0_nat_traversal::Event::AddressRemoved(removed_addr),
5192+
));
51945193
}
51955194
}
51965195
Frame::ReachOut(reach_out) => {
51975196
let ipv6 = self.is_ipv6();
5198-
let server_state = match self.iroh_hp.server_side_mut() {
5197+
let server_state = match self.n0_nat_traversal.server_side_mut() {
51995198
Ok(state) => state,
52005199
Err(err) => {
52015200
return Err(TransportError::PROTOCOL_VIOLATION(format!(
@@ -6207,11 +6206,14 @@ impl Connection {
62076206
{
62086207
let max_local_addresses = max_remotely_allowed_remote_addresses.get();
62096208
let max_remote_addresses = max_locally_allowed_remote_addresses.get();
6210-
self.iroh_hp =
6211-
iroh_hp::State::new(max_remote_addresses, max_local_addresses, self.side());
6209+
self.n0_nat_traversal = n0_nat_traversal::State::new(
6210+
max_remote_addresses,
6211+
max_local_addresses,
6212+
self.side(),
6213+
);
62126214
debug!(
62136215
%max_remote_addresses, %max_local_addresses,
6214-
"iroh hole punching negotiated"
6216+
"n0's nat traversal negotiated"
62156217
);
62166218

62176219
match self.side() {
@@ -6236,7 +6238,7 @@ impl Connection {
62366238
}
62376239
}
62386240
} else {
6239-
debug!("iroh nat traversal enabled for both endpoints, but multipath is missing")
6241+
debug!("n0 nat traversal enabled for both endpoints, but multipath is missing")
62406242
}
62416243
}
62426244

@@ -6591,8 +6593,11 @@ impl Connection {
65916593
}
65926594

65936595
/// Add addresses the local endpoint considers are reachable for nat traversal.
6594-
pub fn add_nat_traversal_address(&mut self, address: SocketAddr) -> Result<(), iroh_hp::Error> {
6595-
if let Some(added) = self.iroh_hp.add_local_address(address)? {
6596+
pub fn add_nat_traversal_address(
6597+
&mut self,
6598+
address: SocketAddr,
6599+
) -> Result<(), n0_nat_traversal::Error> {
6600+
if let Some(added) = self.n0_nat_traversal.add_local_address(address)? {
65966601
self.spaces[SpaceId::Data].pending.add_address.insert(added);
65976602
};
65986603
Ok(())
@@ -6604,8 +6609,8 @@ impl Connection {
66046609
pub fn remove_nat_traversal_address(
66056610
&mut self,
66066611
address: SocketAddr,
6607-
) -> Result<(), iroh_hp::Error> {
6608-
if let Some(removed) = self.iroh_hp.remove_local_address(address)? {
6612+
) -> Result<(), n0_nat_traversal::Error> {
6613+
if let Some(removed) = self.n0_nat_traversal.remove_local_address(address)? {
66096614
self.spaces[SpaceId::Data]
66106615
.pending
66116616
.remove_address
@@ -6615,14 +6620,18 @@ impl Connection {
66156620
}
66166621

66176622
/// Get the current local nat traversal addresses
6618-
pub fn get_local_nat_traversal_addresses(&self) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
6619-
self.iroh_hp.get_local_nat_traversal_addresses()
6623+
pub fn get_local_nat_traversal_addresses(
6624+
&self,
6625+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
6626+
self.n0_nat_traversal.get_local_nat_traversal_addresses()
66206627
}
66216628

66226629
/// Get the currently advertised nat traversal addresses by the server
6623-
pub fn get_remote_nat_traversal_addresses(&self) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
6630+
pub fn get_remote_nat_traversal_addresses(
6631+
&self,
6632+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
66246633
Ok(self
6625-
.iroh_hp
6634+
.n0_nat_traversal
66266635
.client_side()?
66276636
.get_remote_nat_traversal_addresses())
66286637
}
@@ -6670,14 +6679,14 @@ impl Connection {
66706679
pub fn initiate_nat_traversal_round(
66716680
&mut self,
66726681
now: Instant,
6673-
) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
6682+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
66746683
if self.state.is_closed() {
6675-
return Err(iroh_hp::Error::Closed);
6684+
return Err(n0_nat_traversal::Error::Closed);
66766685
}
66776686

66786687
let ipv6 = self.is_ipv6();
6679-
let client_state = self.iroh_hp.client_side_mut()?;
6680-
let iroh_hp::NatTraversalRound {
6688+
let client_state = self.n0_nat_traversal.client_side_mut()?;
6689+
let n0_nat_traversal::NatTraversalRound {
66816690
new_round,
66826691
reach_out_at,
66836692
addresses_to_probe,
@@ -6724,7 +6733,7 @@ impl Connection {
67246733
probed_addresses.push(remote);
67256734
}
67266735
Err(e) => {
6727-
self.iroh_hp
6736+
self.n0_nat_traversal
67286737
.client_side_mut()
67296738
.expect("validated")
67306739
.report_in_continuation(id, e);
@@ -6736,11 +6745,11 @@ impl Connection {
67366745
if let Some(err) = err {
67376746
// We failed to probe any addresses, bail out
67386747
if probed_addresses.is_empty() {
6739-
return Err(iroh_hp::Error::Multipath(err));
6748+
return Err(n0_nat_traversal::Error::Multipath(err));
67406749
}
67416750
}
67426751

6743-
self.iroh_hp
6752+
self.n0_nat_traversal
67446753
.client_side_mut()
67456754
.expect("connection side validated")
67466755
.set_round_path_ids(path_ids);
@@ -6754,10 +6763,10 @@ impl Connection {
67546763
/// successfully open.
67556764
fn continue_nat_traversal_round(&mut self, now: Instant) -> Option<bool> {
67566765
let ipv6 = self.is_ipv6();
6757-
let client_state = self.iroh_hp.client_side_mut().ok()?;
6766+
let client_state = self.n0_nat_traversal.client_side_mut().ok()?;
67586767
let (id, address) = client_state.continue_nat_traversal_round(ipv6)?;
67596768
let open_result = self.open_nat_traversal_path(now, address);
6760-
let client_state = self.iroh_hp.client_side_mut().expect("validated");
6769+
let client_state = self.n0_nat_traversal.client_side_mut().expect("validated");
67616770
match open_result {
67626771
Ok(None) => Some(true),
67636772
Ok(Some((path_id, _remote))) => {
@@ -7029,8 +7038,8 @@ pub enum Event {
70297038
DatagramsUnblocked,
70307039
/// (Multi)Path events
70317040
Path(PathEvent),
7032-
/// Iroh's nat traversal events
7033-
NatTraversal(iroh_hp::Event),
7041+
/// n0's nat traversal events
7042+
NatTraversal(n0_nat_traversal::Event),
70347043
}
70357044

70367045
impl From<PathEvent> for Event {

quinn-proto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod address_discovery;
110110
mod token_memory_cache;
111111
pub use token_memory_cache::TokenMemoryCache;
112112

113-
pub mod iroh_hp;
113+
pub mod n0_nat_traversal;
114114

115115
// Deal with time
116116
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! iroh NAT Traversal
1+
//! n0's (<https://n0.computer>) NAT Traversal protocol implementation.
22
33
use std::{
44
collections::hash_map::Entry,
@@ -25,7 +25,7 @@ pub enum Error {
2525
#[error("Not allowed for this endpoint's connection side")]
2626
WrongConnectionSide,
2727
/// The extension was not negotiated
28-
#[error("Iroh's nat traversal was not negotiated")]
28+
#[error("n0's nat traversal was not negotiated")]
2929
ExtensionNotNegotiated,
3030
/// Not enough addresses to complete the operation
3131
#[error("Not enough addresses")]
@@ -63,7 +63,7 @@ pub enum Event {
6363
AddressRemoved(SocketAddr),
6464
}
6565

66-
/// State kept for Iroh's nat traversal
66+
/// State kept for n0's nat traversal
6767
#[derive(Debug, Default)]
6868
pub(crate) enum State {
6969
#[default]
@@ -91,7 +91,7 @@ pub(crate) struct ClientState {
9191
/// Candidate addresses the local client reports as potentially reachable, to use for nat
9292
/// traversal attempts.
9393
local_addresses: FxHashSet<IpPort>,
94-
/// Current nat holepunching round.
94+
/// Current nat traversal round.
9595
round: VarInt,
9696
/// [`PathId`]s used to probe remotes assigned to this round.
9797
round_path_ids: Vec<PathId>,
@@ -296,7 +296,7 @@ pub(crate) struct ServerState {
296296
local_addresses: FxHashMap<IpPort, VarInt>,
297297
/// The next id to use for local addresses sent to the client.
298298
next_local_addr_id: VarInt,
299-
/// Current nat holepunching round
299+
/// Current nat traversal round
300300
///
301301
/// Servers keep track of the client's most recent round and cancel probing related to previous
302302
/// rounds.

quinn-proto/src/tests/util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,36 +728,36 @@ impl ConnPair {
728728
&mut self,
729729
side: Side,
730730
address: SocketAddr,
731-
) -> Result<(), iroh_hp::Error> {
731+
) -> Result<(), n0_nat_traversal::Error> {
732732
self.conn_mut(side).add_nat_traversal_address(address)
733733
}
734734

735735
pub(super) fn remove_nat_traversal_address(
736736
&mut self,
737737
side: Side,
738738
address: SocketAddr,
739-
) -> Result<(), iroh_hp::Error> {
739+
) -> Result<(), n0_nat_traversal::Error> {
740740
self.conn_mut(side).remove_nat_traversal_address(address)
741741
}
742742

743743
pub(super) fn get_local_nat_traversal_addresses(
744744
&self,
745745
side: Side,
746-
) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
746+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
747747
self.conn(side).get_local_nat_traversal_addresses()
748748
}
749749

750750
pub(super) fn get_remote_nat_traversal_addresses(
751751
&self,
752752
side: Side,
753-
) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
753+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
754754
self.conn(side).get_remote_nat_traversal_addresses()
755755
}
756756

757757
pub(super) fn initiate_nat_traversal_round(
758758
&mut self,
759759
side: Side,
760-
) -> Result<Vec<SocketAddr>, iroh_hp::Error> {
760+
) -> Result<Vec<SocketAddr>, n0_nat_traversal::Error> {
761761
let now = self.pair.time;
762762
self.conn_mut(side).initiate_nat_traversal_round(now)
763763
}

quinn-proto/src/transport_parameters.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl TransportParameters {
416416
w.write(val);
417417
}
418418
}
419-
TransportParameterId::IrohNatTraversal => {
419+
TransportParameterId::N0NatTraversal => {
420420
if let Some(val) = self.max_remote_nat_traversal_addresses {
421421
w.write_var(id as u64);
422422
w.write(VarInt(1));
@@ -548,7 +548,7 @@ impl TransportParameters {
548548

549549
params.initial_max_path_id = Some(value);
550550
}
551-
TransportParameterId::IrohNatTraversal => {
551+
TransportParameterId::N0NatTraversal => {
552552
if params.max_remote_nat_traversal_addresses.is_some() {
553553
return Err(Error::Malformed);
554554
}
@@ -731,8 +731,8 @@ pub(crate) enum TransportParameterId {
731731
InitialMaxPathId = 0x3e,
732732

733733
// inspired by https://www.ietf.org/archive/id/draft-seemann-quic-nat-traversal-02.html,
734-
// simplified to iroh's needs
735-
IrohNatTraversal = 0x3d7f91120401,
734+
// simplified to n0's own protocol.
735+
N0NatTraversal = 0x3d7f91120401,
736736
}
737737

738738
impl TransportParameterId {
@@ -761,7 +761,7 @@ impl TransportParameterId {
761761
Self::MinAckDelayDraft07,
762762
Self::ObservedAddr,
763763
Self::InitialMaxPathId,
764-
Self::IrohNatTraversal,
764+
Self::N0NatTraversal,
765765
];
766766
}
767767

@@ -803,7 +803,7 @@ impl TryFrom<u64> for TransportParameterId {
803803
id if Self::MinAckDelayDraft07 == id => Self::MinAckDelayDraft07,
804804
id if Self::ObservedAddr == id => Self::ObservedAddr,
805805
id if Self::InitialMaxPathId == id => Self::InitialMaxPathId,
806-
id if Self::IrohNatTraversal == id => Self::IrohNatTraversal,
806+
id if Self::N0NatTraversal == id => Self::N0NatTraversal,
807807
_ => return Err(()),
808808
};
809809
Ok(param)

0 commit comments

Comments
 (0)