Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Finishing touches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman S. Borschel committed Mar 3, 2020
1 parent ada6946 commit a801957
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 156 deletions.
16 changes: 10 additions & 6 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,21 @@ impl<B: BlockT> Future for GossipEngineInner<B> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let this = &mut *self;

while let Poll::Ready(Some(event)) = this.network_event_stream.poll_next_unpin(cx) {
match event {
Event::NotificationStreamOpened { remote, engine_id: msg_engine_id, roles } => {
while let Poll::Ready(next) = this.network_event_stream.poll_next_unpin(cx) {
match next {
Some(Event::NotificationStreamOpened { remote, engine_id: msg_engine_id, roles }) => {
if msg_engine_id != this.engine_id {
continue;
}
this.state_machine.new_peer(&mut *this.network, remote, roles);
}
Event::NotificationStreamClosed { remote, engine_id: msg_engine_id } => {
Some(Event::NotificationStreamClosed { remote, engine_id: msg_engine_id }) => {
if msg_engine_id != this.engine_id {
continue;
}
this.state_machine.peer_disconnected(&mut *this.network, remote);
},
Event::NotificationsReceived { remote, messages } => {
Some(Event::NotificationsReceived { remote, messages }) => {
let engine_id = this.engine_id.clone();
this.state_machine.on_incoming(
&mut *this.network,
Expand All @@ -204,7 +204,11 @@ impl<B: BlockT> Future for GossipEngineInner<B> {
.collect()
);
},
Event::Dht(_) => {}
Some(Event::Dht(_)) => {}
None => {
log::debug!("Gossip engine terminating due to network shutdown.");
return Poll::Ready(())
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl DiscoveryBehaviour {
/// If we didn't know this address before, also generates a `Discovered` event.
pub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr) {
if self.user_defined.iter().all(|(p, a)| *p != peer_id && *a != addr) {
self.kademlia.add_address(&peer_id, addr.clone());
self.discoveries.push_back(peer_id.clone());
self.user_defined.push((peer_id, addr));
}
Expand Down Expand Up @@ -329,8 +330,9 @@ impl NetworkBehaviour for DiscoveryBehaviour {
while let Poll::Ready(_) = self.next_kad_random_query.poll_unpin(cx) {
if self.num_connections < self.discovery_only_if_under_num {
let random_peer_id = PeerId::random();
debug!(target: "sub-libp2p", "Libp2p <= Starting random Kademlia request for \
{:?}", random_peer_id);
debug!(target: "sub-libp2p",
"Libp2p <= Starting random Kademlia request for {:?}",
random_peer_id);

self.kademlia.get_closest_peers(random_peer_id);
} else {
Expand Down
Loading

0 comments on commit a801957

Please sign in to comment.