Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ parking_lot = "0.12"
once_cell = "1.21"

# Networking
saorsa-transport = "0.28"
saorsa-transport = { git = "https://github.com/jacderida/saorsa-transport.git", branch = "feat-nat_traversal_attempts" }
Comment thread
jacderida marked this conversation as resolved.
Comment thread
jacderida marked this conversation as resolved.

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

saorsa-transport is pulled from a personal fork (jacderida/saorsa-transport) and a moving branch, which increases supply-chain risk and makes downstream builds non-reproducible (downstream users won’t use this repo’s Cargo.lock). Please switch to the saorsa-labs/saorsa-transport repo and pin an immutable rev (or a crates.io release/tag) before merging, especially if saorsa-core is intended to be publishable on crates.io (git deps generally block publishing).

Suggested change
saorsa-transport = { git = "https://github.com/jacderida/saorsa-transport.git", branch = "feat-nat_traversal_attempts" }
saorsa-transport = "0.27"

Copilot uses AI. Check for mistakes.

# Core-specific dependencies
dirs = "6.0"
Expand Down
36 changes: 32 additions & 4 deletions src/transport_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,38 @@ impl TransportHandle {
channel_id, protocol
);

if !self.peers.read().await.contains_key(channel_id) {
return Err(P2PError::Network(NetworkError::PeerNotFound(
channel_id.to_string().into(),
)));
// If the peer isn't in `self.peers`, register it on the fly.
// Hole-punched connections are accepted at the transport layer and
// registered in P2pEndpoint::connected_peers, but the event chain
// to populate TransportHandle::peers may not have completed yet.
//
// Uses a single write lock with entry() to avoid a TOCTOU race
// where a concurrent event handler could insert a fully-populated
// PeerInfo between a read-check and our write.
{
let mut peers = self.peers.write().await;
peers.entry(channel_id.to_string()).or_insert_with(|| {
info!(
"send_on_channel: registering new channel {} on the fly",
channel_id
);
// Parse the channel_id as a SocketAddr to populate the
// address field, so lookups like get_channel_id_by_address
// can find this peer.
let addresses = channel_id
.parse::<std::net::SocketAddr>()
.map(|addr| vec![MultiAddr::quic(addr)])
.unwrap_or_default();
PeerInfo {
channel_id: channel_id.to_string(),
addresses,
status: ConnectionStatus::Connected,
last_seen: Instant::now(),
connected_at: Instant::now(),
protocols: Vec::new(),
heartbeat_count: 0,
}
});
}
Comment thread
jacderida marked this conversation as resolved.

if !self.is_connection_active(channel_id).await {
Expand Down
Loading