Skip to content

Commit 925dc62

Browse files
doitiandriftluo
andcommitted
Merge pull request #4873 from driftluo:hole-puching-protocol
feat: add a hole punching protocol try use on nat traversal closes #4824 #4766 This PR introduces a protocol to coordinate node connection behavior, attempting to perform TCP traversal through coordination: 1. Removed the `try dial observe address` behavior. 2. The protocol currently does not support the wasm target and does not support establishing WebSocket protocol connections. 3. The protocol has only three messages, with the following behavior: 1. Schedule finding peer IDs from the peer store that want to establish a connection and broadcasting their possible listening addresses. 2. The node receives a Request message and determines if the target object is itself. 1. If the `to` object is itself, it returns a Delivered message. 2. If the `to` object is not itself, it broadcasts the route and ttl modified. 3. The node receives a Delivered message response. 1. If the `from` object is itself, it starts a TCP connection request and responds with a Sync message 2. If the `from` object is not itself, it modifies the route and ttl and propagates the message to the next router object. 4. The node receives a Sync message response. 1. If the `to` object is itself, it starts a TCP connection request. 2. If the `to` object is not itself, it propagates the message to the next router object. ```mermaid sequenceDiagram participant A as Initiator Node A participant B as Relay Node B participant C as Target Node C autonumber A->>B: ConnectionRequest B->>C: Forward(ConnectionRequest) activate C C-->>C: Validate Target C->>B: ConnectionRequestDelivered (incl. Observed Addr) deactivate C B->>A: Forward(ConnectionRequestDelivered) activate A A-->>A: Process Reply (Store Observed Addr) Note right of A: Delay start early NAT<br/>traversal attempt here (ttl/2) A->>B: ConnectionSync deactivate A B->>C: Forward(ConnectionSync) par Start NAT Traversal & Direct Connection Attempt activate A A-->>A: Start NAT Traversal A-->>C: Direct Connection Attempt (e.g., TCP Hole Punching) deactivate A and activate C C-->>C: Start NAT Traversal C-->>A: Direct Connection Attempt (e.g., TCP Hole Punching) deactivate C end ``` Co-Authored-By: driftluo <[email protected]>
1 parent a26ca43 commit 925dc62

File tree

28 files changed

+3354
-170
lines changed

28 files changed

+3354
-170
lines changed

Cargo.lock

Lines changed: 55 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ crossbeam = "0.8.2"
201201
crossbeam-channel = "0.5.1"
202202
ctrlc = "3.1"
203203
daggy = "0.8.0"
204-
dashmap = "4.0"
204+
dashmap = "6.0"
205205
derive_more = { version = "1", default-features = false }
206206
eaglesong = "0.1"
207207
env_logger = "0.10"
@@ -213,7 +213,11 @@ fs2 = "0.4.3"
213213
futures = "0.3"
214214
futures-util = "0.3.21"
215215
golomb-coded-set = "0.2.0"
216-
governor = "0.3.1"
216+
governor = { version = "0.10", default-features = false, features = [
217+
"std",
218+
"jitter",
219+
"quanta",
220+
] }
217221
hex = "0.4"
218222
hickory-resolver = "0.24.2"
219223
http-body-util = "0.1"

network/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ p2p = { workspace = true, default-features = false, features = [
4646
"ws",
4747
] }
4848
socket2 = "0.5"
49+
governor.workspace = true
4950

5051
[target.'cfg(target_family = "wasm")'.dependencies]
51-
p2p = { workspace = true, default-features = false, features = [
52-
"wasm-timer",
53-
] }
52+
p2p = { workspace = true, default-features = false, features = ["wasm-timer"] }
5453
idb = "0.6"
5554
serde-wasm-bindgen = "0.6.5"
5655

0 commit comments

Comments
 (0)