Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/nat_traversal_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,8 +1474,12 @@ impl NatTraversalEndpoint {
let (nack_tx, nack_rx) = mpsc::unbounded_channel();
inner_endpoint.set_nack_tx(nack_tx);

// Channel for background handshake completion (persistent across accept calls)
let (hs_tx, hs_rx) = mpsc::channel(32);
// Channel for background handshake completion (persistent across accept calls).
// Capacity 1024: the consumer (accept_connection_direct → P2pEndpoint::accept)
// can stall briefly under write-lock contention in saorsa-core's accept loop.
// A small buffer (32) caused the pipeline to back up after 15+ hours in a
// 1000-node testnet, blocking all new connection handoffs.
let (hs_tx, hs_rx) = mpsc::channel(1024);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Capacity duplicated in two constructors

The value 1024 appears at both line 1482 and line 1958. A named constant would make future adjustments atomic and signal intent:

/// Buffer for completed handshakes. Sized above the peak backlog observed
/// in the ant-rc-18 testnet (1 079 connections) so transient consumer
/// stalls don't block the accept loop.
const HANDSHAKE_CHANNEL_CAPACITY: usize = 1024;

Then mpsc::channel(HANDSHAKE_CHANNEL_CAPACITY) at both sites.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/nat_traversal_api.rs
Line: 1482

Comment:
**Capacity duplicated in two constructors**

The value `1024` appears at both line 1482 and line 1958. A named constant would make future adjustments atomic and signal intent:

```rust
/// Buffer for completed handshakes. Sized above the peak backlog observed
/// in the ant-rc-18 testnet (1 079 connections) so transient consumer
/// stalls don't block the accept loop.
const HANDSHAKE_CHANNEL_CAPACITY: usize = 1024;
```

Then `mpsc::channel(HANDSHAKE_CHANNEL_CAPACITY)` at both sites.

How can I resolve this? If you propose a fix, please make it concise.


// Compute local peer ID = BLAKE3(public_key_spki) for
// deterministic simultaneous-connect tie-breaking.
Expand Down Expand Up @@ -1946,8 +1950,12 @@ impl NatTraversalEndpoint {
let (nack_tx, nack_rx) = mpsc::unbounded_channel();
inner_endpoint.set_nack_tx(nack_tx);

// Channel for background handshake completion (persistent across accept calls)
let (hs_tx, hs_rx) = mpsc::channel(32);
// Channel for background handshake completion (persistent across accept calls).
// Capacity 1024: the consumer (accept_connection_direct → P2pEndpoint::accept)
// can stall briefly under write-lock contention in saorsa-core's accept loop.
// A small buffer (32) caused the pipeline to back up after 15+ hours in a
// 1000-node testnet, blocking all new connection handoffs.
let (hs_tx, hs_rx) = mpsc::channel(1024);

// Compute local peer ID = BLAKE3(public_key_spki) for
// deterministic simultaneous-connect tie-breaking.
Expand Down
Loading