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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

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 from fdbac35 to fc57269 Compare April 17, 2025 09:14
@driftluo driftluo force-pushed the hole-puching-protocol branch 6 times, most recently from ac72347 to e79b248 Compare April 17, 2025 15:56
@driftluo driftluo force-pushed the hole-puching-protocol branch 2 times, most recently from 9a32af6 to 344d4b0 Compare April 18, 2025 05:51
@zhangsoledad zhangsoledad requested a review from Copilot April 18, 2025 07:59
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.

Pull Request Overview

This PR introduces a new TCP hole punching protocol for improved NAT traversal, while removing legacy dialing behavior.

  • Adds a “HolePunching” support protocol in config files and network modules.
  • Implements protocol components for connection requests, delivered messages, sync messages, and NAT traversal logic.
  • Adjusts peer store and network service handling to integrate the new protocol.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
util/app-config/src/configs/network.rs Adds HolePunching enum variant and updates defaults.
resource/ckb.toml Appends HolePunching to supported protocols list.
network/src/services/outbound_peer.rs Removes legacy try_dial_observed behavior.
network/src/protocols/support_protocols.rs Adds protocol string and port for HolePunching.
network/src/protocols/{identify,mod.rs,hole_punching/*} Implements and integrates new HolePunching protocol.
network/src/peer_store/peer_store_impl.rs Introduces fetch_nat_addrs and updates observed address logic.
network/src/network.rs Integrates new HolePunching protocol into network service.
Files not reviewed (1)
  • util/gen-types/schemas/protocols.mol: Language not supported
Comments suppressed due to low confidence (2)

network/src/protocols/hole_punching/component/connection_request.rs:186

  • The function name 'forword_request' appears to be a typo. Consider renaming it to 'forward_request' to improve clarity.
let content = forword_request(self.message, self_peer_id);

network/src/protocols/hole_punching/component/connection_sync.rs:71

  • The function name 'forword_sync' is likely misspelled; renaming it to 'forward_sync' would better reflect its purpose.
let content = forword_sync(self.message);

@driftluo driftluo force-pushed the hole-puching-protocol branch from 344d4b0 to cbe4c7d Compare April 18, 2025 11:16
eval-exec
eval-exec previously approved these changes Apr 25, 2025
@driftluo driftluo force-pushed the hole-puching-protocol branch from 2c1acf7 to b089e28 Compare April 25, 2025 09:04
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: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants