Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 14, 2024
1 parent e189147 commit bb03359
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
6 changes: 5 additions & 1 deletion network/core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,12 @@ where
use autonat::Event::*;
match event {
StatusChanged { old, new } => {
if let Some(public_address) = self.swarm.behaviour().autonat.public_address() {
if let Some(public_address) = self.swarm.behaviour().autonat.public_address().cloned() {
info!(target: LOG_TARGET, "🌍️ Autonat: Our public address is {public_address}");
self.swarm
.behaviour_mut()
.peer_sync
.add_known_local_public_addresses(vec![public_address]);
}

self.autonat_status_sender.send_if_modified(|prev| {
Expand Down
19 changes: 9 additions & 10 deletions network/libp2p-messaging/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use libp2p::{
ConnectionDenied,
ConnectionHandler,
ConnectionId,
DialError,
DialFailure,
FromSwarm,
NetworkBehaviour,
Expand Down Expand Up @@ -128,12 +129,12 @@ where TCodec: Codec + Send + Clone + 'static
},
None => {
let stream_id = self.next_outbound_stream_id();
tracing::debug!("create a new outbound dial {stream_id}");
let (sink, stream) = stream::channel(stream_id, peer_id);

self.pending_events.push_back(ToSwarm::Dial {
opts: DialOpts::peer_id(peer_id).build(),
});
let opts = DialOpts::peer_id(peer_id).build();
let connection_id = opts.connection_id();
self.pending_events.push_back(ToSwarm::Dial { opts });
tracing::debug!("create a new outbound dial (conn_id={connection_id}, stream {stream_id})");

self.pending_outbound_dials.insert(peer_id, (sink.clone(), stream));
sink
Expand Down Expand Up @@ -198,13 +199,11 @@ where TCodec: Codec + Send + Clone + 'static
}

fn on_dial_failure(&mut self, DialFailure { peer_id, error, .. }: DialFailure) {
if matches!(error, DialError::DialPeerConditionFalse(_)) {
return;
}

if let Some(peer) = peer_id {
// If there are pending outgoing messages when a dial failure occurs,
// it is implied that we are not connected to the peer, since pending
// outgoing messages are drained when a connection is established and
// only created when a peer is not connected when a request is made.
// Thus these requests must be considered failed, even if there is
// another, concurrent dialing attempt ongoing.
if let Some((_sink, stream)) = self.pending_outbound_dials.remove(&peer) {
self.pending_events
.push_back(ToSwarm::GenerateEvent(Event::OutboundFailure {
Expand Down
19 changes: 5 additions & 14 deletions network/libp2p-peersync/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ where TPeerStore: PeerStore
return;
}

let mut is_any_new = false;
for addr in addrs {
self.local_peer_record.add_address(addr.clone());
is_any_new |= self.local_peer_record.add_address(addr.clone());
}

self.handle_update_local_record();
if is_any_new {
self.handle_update_local_record();
}
}

pub async fn want_peers<I: IntoIterator<Item = PeerId>>(&mut self, peers: I) -> Result<(), Error> {
Expand Down Expand Up @@ -309,18 +312,6 @@ where TPeerStore: PeerStore

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.pending_events.pop_front() {
// if let
// ToSwarm::GenerateEvent(event) =
// &event {
// match event {
// Event::InboundFailure { peer_id, .. } => {}
// Event::OutboundFailure { peer_id, .. } => {}
// Event::InboundStreamInterrupted { peer_id, .. } => {}
// Event::OutboundStreamInterrupted { peer_id, .. } => {}
// Event::ResponseStreamComplete { peer_id, .. } => {}
// Event::Error(_) => {}
// }
// }
return Poll::Ready(event);
}
if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD {
Expand Down
10 changes: 7 additions & 3 deletions network/libp2p-peersync/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ impl LocalPeerRecord {
self.keypair.public().to_peer_id()
}

pub fn add_address(&mut self, address: Multiaddr) {
self.addresses.insert(address);
self.sign();
pub fn add_address(&mut self, address: Multiaddr) -> bool {
if self.addresses.insert(address) {
// Sign only if the address was not already there
self.sign();
return true;
}
false
}

pub fn remove_address(&mut self, address: &Multiaddr) {
Expand Down
4 changes: 4 additions & 0 deletions network/libp2p-substream/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl Behaviour {
}

fn on_dial_failure(&mut self, DialFailure { peer_id, error, .. }: DialFailure) {
if matches!(error, DialError::DialPeerConditionFalse(_)) {
return;
}

if let Some(peer) = peer_id {
// If there are pending outgoing stream requests when a dial failure occurs,
// it is implied that we are not connected to the peer, since pending
Expand Down

0 comments on commit bb03359

Please sign in to comment.