Skip to content

Commit d7831ad

Browse files
authored
Merge pull request #33 from n0-computer/rae/fix-naming
2 parents 9a34710 + 70585e4 commit d7831ad

File tree

7 files changed

+79
-100
lines changed

7 files changed

+79
-100
lines changed

concepts/discovery.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ There are four different implementations of the discovery service in iroh. **By
2727
### The motivation
2828

2929
We want iroh to establish connections with as little friction as possible. Our
30-
first big push toward chipping away at this goal was adding [holepunching](/concepts/holepunching) into
30+
first big push toward chipping away at this goal was adding [NAT traversal](/concepts/nat-traversal) into
3131
iroh. Now, devs no longer need to worry about opening up ports on their servers
3232
/ firewalls or be resigned to only creating connections to
3333
computers inside their local NAT.
3434

35-
But even with holepunching, you need to know *where* to dial. Dialing an endpoint in
35+
But even with NAT traversal, you need to know *where* to dial. Dialing an endpoint in
3636
iroh needs either an IP address to talk to, or the URL of a relay to which the
3737
remote endpoint is connected. To make things easier, you can use
3838
[tickets](/concepts/tickets) early-on. Tickets are easily encodable

concepts/holepunching.mdx

Lines changed: 0 additions & 91 deletions
This file was deleted.

concepts/nat-traversal.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: "NAT Traversal"
3+
---
4+
5+
NAT traversal is the set of techniques iroh uses to establish direct peer-to-peer connections between devices that sit behind NATs and firewalls. With NAT traversal, iroh applications can:
6+
7+
- **Connect directly** between devices without manual network configuration
8+
- **Reduce latency** by avoiding servers when possible
9+
- **Save bandwidth** by keeping data transfer peer-to-peer
10+
- **Improve resilience and reliability** by not depending on all traffic being routed through third parties
11+
12+
All of this happens automatically — you don't need to understand the technical details to benefit from it.
13+
14+
## The Problem: NATs and Firewalls Block Direct Connections
15+
16+
Imagine you're trying to connect two devices directly — both sitting behind home or office routers. The routers' firewalls block incoming connections because they don't recognise them as responses to outbound traffic. The combination of NAT (which translates addresses) and firewall rules (which filter traffic) makes direct connections challenging.
17+
18+
Most home and office networks use NAT, which acts like a one-way door — devices inside the network can reach out to the internet, but the internet can't easily reach back in. This causes reliance on central servers, which can introduce latency and reliability issues.
19+
20+
Traditionally, this problem was solved by:
21+
- **Port forwarding**: Manually configuring your router to allow specific connections (tedious and requires technical knowledge)
22+
- **Relay servers**: Routing all traffic through a third-party server (slow and expensive)
23+
24+
## How NAT Traversal Works in iroh
25+
26+
iroh's NAT traversal is built on top of QUIC and integrates tightly with the [relay system](/concepts/relays). The core technique is simultaneous outbound connection — sometimes called "holepunching" — where both peers send packets to each other at the same time, causing their respective firewalls and NATs to create mappings that allow the traffic through.
27+
28+
Note that despite the "NAT" in the name, this technique applies equally to firewalls that don't involve NAT. iroh uses it whenever a direct connection needs to be established through any restrictive network boundary.
29+
30+
NAT traversal succeeds in the vast majority of real-world conditions — roughly 9 out of 10 network configurations allow a direct connection to be established. iroh's implementation is deterministic: if it works between two devices once, it will continue to work as long as their networking setup stays stable. Where it fails — some corporate firewalls or cellular networks — iroh automatically falls back to the relay.
31+
32+
### 1. Initial Contact Through a Relay
33+
34+
Both peers first connect to a shared [relay server](/concepts/relays). The relay acts as a meeting point where peers can coordinate before a direct path is established.
35+
36+
The relay server observes each node's public IP address and port (the address from which it sees incoming traffic). This *reflective address* can be used by the remote peer to reach through the firewall, provided the firewall considers it expected traffic.
37+
38+
### 2. Sharing Connection Information
39+
40+
Through the relay, peers exchange their:
41+
- **Public IP addresses** (how they appear to the outside internet)
42+
- **Port numbers** (the specific door number the router assigned them)
43+
- **Local addresses** (in case they're on the same network)
44+
45+
Both nodes simultaneously send UDP datagrams to each other's reflective addresses. Since both are sending on the same 4-tuple (source IP, source port, destination IP, destination port), the firewalls recognise the incoming packets as matching outbound traffic and allow them through.
46+
47+
The relay server doesn't actively participate in this process — it simply forwards encrypted packets between nodes without knowledge of whether they contain application data or coordination messages.
48+
49+
### 3. Simultaneous Outbound Connection
50+
51+
Both peers try to connect to each other **at the same time**. When peer A sends a packet to peer B's public address, A's NAT creates a mapping and the firewall creates a temporary rule allowing responses from B. When peer B sends a packet to peer A at the same moment, B's NAT and firewall do the same.
52+
53+
Because both mappings are now established and both firewalls expect traffic from each other, the packets get through and a direct connection is formed.
54+
55+
### 4. Fallback to Relay
56+
57+
If NAT traversal fails (some networks use particularly strict configurations), iroh automatically falls back to routing traffic through the relay server. This ensures connections always work, even if they can't be direct.
58+
59+
## Read more
60+
61+
- [iroh's NAT traversal implementation](https://docs.rs/iroh/latest/iroh/endpoint/index.html#nat-traversal)
62+
- [Relay system documentation](/concepts/relays)
63+
- [Dedicated infrastructure setup](/deployment/dedicated-infrastructure)
64+
- [Endpoint configuration](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html)

concepts/relays.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ There are situations where a direct connection can’t be established, and in th
77

88
Relays serve two roles in iroh:
99

10-
1. **Holepunching assistance.** When two endpoints first connect, they exchange network information through the relay to attempt a direct P2P connection.
10+
1. **NAT Traversal.** When two endpoints first connect, they exchange network information through the relay to attempt a direct P2P connection.
1111
2. **Encrypted traffic fallback.** If a direct connection can't be established (due to strict NATs, firewalls, or other network conditions), traffic flows through the relay instead.
1212

1313
Once a direct path is established, the relay steps back and data flows peer-to-peer. Relay servers **cannot read** any of the traffic they handle — it's encrypted end-to-end.

deployment/dedicated-infrastructure.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ title: "Dedicated Infrastructure"
55
import RelayEndpointConfig from '/snippets/relay-endpoint-config.mdx';
66

77
By default, iroh will use public shared infrastructure to facilitate connections over
8-
DNS and end-to-end encryption over relays. This infrastructure comprises:
8+
address lookup and end-to-end encryption over relays. This infrastructure comprises:
99

1010
1. [Relays](/concepts/relays)
11-
2. [Discovery Servers (DNS)](/concepts/discovery)
11+
2. [Address Lookup](/concepts/discovery)
1212

1313
Relays forward traffic when direct connections are not possible as well
14-
as facilitates holepunching for direct connections. These servers are managed and
14+
as facilitates NAT traversal for direct connections. These servers are managed and
1515
maintained by [n0.computer](https://n0.computer), and are shared by a global public network of
1616
developers.
1717

docs.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"concepts/tickets",
2828
"concepts/discovery",
2929
"concepts/relays",
30-
"concepts/holepunching",
30+
"concepts/nat-traversal",
3131
"concepts/protocols"
3232
]
3333
}
@@ -153,5 +153,11 @@
153153
},
154154
"integrations": {
155155
"plausible": { "domain": "docs.iroh.computer" }
156-
}
156+
},
157+
"redirects": [
158+
{
159+
"source": "/concepts/holepunching",
160+
"destination": "/concepts/nat-traversal"
161+
}
162+
]
157163
}

iroh-services/access.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Some features on your Iroh Services project require authorization.
77

88
Examples of what **doesn't** require authorization:
99
- Synchronizing data across relays
10-
- [Holepunching](/concepts/holepunching) connections to other iroh endpoints
10+
- [NAT traversal](/concepts/nat-traversal) connections to other iroh endpoints
1111

1212
Examples of what **does** require authorization:
1313
- Uploading metrics from endpoints to your project

0 commit comments

Comments
 (0)