Skip to content
Merged
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
28 changes: 11 additions & 17 deletions crates/core/src/node/network_bridge/p2p_protoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use futures::FutureExt;
use futures::StreamExt;
use std::convert::Infallible;
use std::future::Future;
use std::net::{IpAddr, SocketAddr};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::pin::Pin;
use std::time::Duration;
use std::{
Expand Down Expand Up @@ -148,34 +148,28 @@ impl P2pConnManager {
let gateways = config.get_gateways()?;
let key_pair = config.key_pair.clone();

// Initialize our peer identity.
// - Gateways must know their public address upfront (required)
// - Peers with configured public_address use that
// - Peers behind NAT start with a placeholder (127.0.0.1) which will be updated
// when they receive ObservedAddress from a gateway
let advertised_addr = if config.is_gateway {
// Gateways must have a public address configured
// Initialize our peer identity before any connection attempts so join requests can
// reference the correct address.
let advertised_addr = {
let advertised_ip = config
.peer_id
.as_ref()
.map(|peer| peer.addr.ip())
.or(config.config.network_api.public_address)
.expect("Gateway must have public_address configured");
.unwrap_or_else(|| {
if listener_ip.is_unspecified() {
IpAddr::V4(Ipv4Addr::LOCALHOST)
} else {
listener_ip
}
});
let advertised_port = config
.peer_id
.as_ref()
.map(|peer| peer.addr.port())
.or(config.config.network_api.public_port)
.unwrap_or(listen_port);
SocketAddr::new(advertised_ip, advertised_port)
} else if let Some(public_addr) = config.config.network_api.public_address {
// Non-gateway peer with explicitly configured public address
let port = config.config.network_api.public_port.unwrap_or(listen_port);
SocketAddr::new(public_addr, port)
} else {
// Non-gateway peer behind NAT: use placeholder address.
// This will be updated when we receive ObservedAddress from gateway.
SocketAddr::new(std::net::Ipv4Addr::new(127, 0, 0, 1).into(), listen_port)
};
bridge
.op_manager
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/node/p2p_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ impl NodeP2P {
.min(u8::MAX as usize) as u8;
let target_connections = self.op_manager.ring.connection_manager.min_connections;

let is_gateway = self.op_manager.ring.connection_manager.is_gateway();
let (tx, op, msg) = ConnectOp::initiate_join_request(
joiner,
query_target.clone(),
ideal_location,
ttl,
target_connections,
self.op_manager.connect_forward_estimator.clone(),
is_gateway,
);

tracing::debug!(
Expand Down
Loading
Loading