Skip to content

feat: add a hole punching protocol try use on nat traversal #4873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

driftluo
Copy link
Collaborator

@driftluo driftluo commented Apr 15, 2025

What problem does this PR solve?

close #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.
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

Loading

Check List

Tests

  • Unit test
  • Integration test

Release note

Title Only: Include only the PR title in the release note.

@driftluo driftluo force-pushed the hole-puching-protocol branch 2 times, most recently from f46b1e0 to f246fdd Compare April 15, 2025 10:16
@driftluo driftluo changed the title feat: add a hote puching protocol try use on nat traversal feat: add a hole punching protocol try use on nat traversal Apr 15, 2025
@driftluo driftluo force-pushed the hole-puching-protocol branch 3 times, most recently from c45b12b to d4e1331 Compare April 15, 2025 11:14
@driftluo driftluo marked this pull request as ready for review April 15, 2025 12:18
@driftluo driftluo requested a review from a team as a code owner April 15, 2025 12:18
@driftluo driftluo requested review from doitian, quake, zhangsoledad and eval-exec and removed request for a team April 15, 2025 12:18
@eval-exec eval-exec added t:enhancement Type: Feature, refactoring. m:network labels Apr 15, 2025
@eval-exec eval-exec added this to Kanban Apr 15, 2025
@eval-exec eval-exec moved this to 🏗 In progress in Kanban Apr 15, 2025
@eval-exec eval-exec requested a review from Copilot April 16, 2025 15:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • util/gen-types/schemas/protocols.mol: Language not supported

@driftluo driftluo force-pushed the hole-puching-protocol branch 9 times, most recently from 9a32af6 to 344d4b0 Compare April 18, 2025 05:51
@driftluo driftluo force-pushed the hole-puching-protocol branch from 63bd180 to e2dcc08 Compare May 22, 2025 10:19
@driftluo driftluo force-pushed the hole-puching-protocol branch from 05cbd3e to e3b00fd Compare May 23, 2025 12:24
@driftluo driftluo requested a review from quake May 23, 2025 13:23
@driftluo driftluo force-pushed the hole-puching-protocol branch 5 times, most recently from e05a01e to 0127d11 Compare May 26, 2025 02:44
@driftluo driftluo requested a review from quake May 26, 2025 05:45
@driftluo driftluo force-pushed the hole-puching-protocol branch 3 times, most recently from 4f296d8 to 56d6fb5 Compare May 26, 2025 15:48
@driftluo driftluo force-pushed the hole-puching-protocol branch from 56d6fb5 to 4baa98d Compare May 26, 2025 16:24
quake
quake previously approved these changes May 26, 2025
doitian added a commit that referenced this pull request Jun 6, 2025
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]>
@doitian
Copy link
Member

doitian commented Jun 6, 2025

Already merged

@doitian doitian closed this Jun 6, 2025
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Kanban Jun 6, 2025
@driftluo driftluo deleted the hole-puching-protocol branch June 6, 2025 07:50
@doitian doitian mentioned this pull request Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
m:network t:enhancement Type: Feature, refactoring.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants