Skip to content

Conversation

@chaoticlonghair
Copy link
Contributor

What problem does this PR solve?

Add a protocol to try connecting peers behind firewalls or NAT routers.

What is changed and how it works?

To be continued ...

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code ci-runs-only: [ quick_checks,linters ]

Side effects

  • Performance regression
  • Breaking backward compatibility

Release note

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

@chaoticlonghair chaoticlonghair requested a review from a team as a code owner January 3, 2025 02:05
@chaoticlonghair chaoticlonghair requested review from quake and removed request for a team January 3, 2025 02:05
.support_protocols
.contains(&SupportProtocol::Penetration)
{
let feeler_meta = SupportProtocols::Penetration.build_meta_with_service_handle({
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. name typo, it should penetration_meta
  2. build_meta_with_service_handle is not set compress to protocol. does this protocol need to be compressed?

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]>
@driftluo
Copy link
Collaborator

driftluo commented Jun 6, 2025

closed by #4873

@driftluo driftluo closed this Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants