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

Commit a801957

Browse files
author
Roman S. Borschel
committed
Finishing touches.
1 parent ada6946 commit a801957

File tree

6 files changed

+161
-156
lines changed

6 files changed

+161
-156
lines changed

client/network-gossip/src/bridge.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,21 @@ impl<B: BlockT> Future for GossipEngineInner<B> {
178178
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
179179
let this = &mut *self;
180180

181-
while let Poll::Ready(Some(event)) = this.network_event_stream.poll_next_unpin(cx) {
182-
match event {
183-
Event::NotificationStreamOpened { remote, engine_id: msg_engine_id, roles } => {
181+
while let Poll::Ready(next) = this.network_event_stream.poll_next_unpin(cx) {
182+
match next {
183+
Some(Event::NotificationStreamOpened { remote, engine_id: msg_engine_id, roles }) => {
184184
if msg_engine_id != this.engine_id {
185185
continue;
186186
}
187187
this.state_machine.new_peer(&mut *this.network, remote, roles);
188188
}
189-
Event::NotificationStreamClosed { remote, engine_id: msg_engine_id } => {
189+
Some(Event::NotificationStreamClosed { remote, engine_id: msg_engine_id }) => {
190190
if msg_engine_id != this.engine_id {
191191
continue;
192192
}
193193
this.state_machine.peer_disconnected(&mut *this.network, remote);
194194
},
195-
Event::NotificationsReceived { remote, messages } => {
195+
Some(Event::NotificationsReceived { remote, messages }) => {
196196
let engine_id = this.engine_id.clone();
197197
this.state_machine.on_incoming(
198198
&mut *this.network,
@@ -204,7 +204,11 @@ impl<B: BlockT> Future for GossipEngineInner<B> {
204204
.collect()
205205
);
206206
},
207-
Event::Dht(_) => {}
207+
Some(Event::Dht(_)) => {}
208+
None => {
209+
log::debug!("Gossip engine terminating due to network shutdown.");
210+
return Poll::Ready(())
211+
}
208212
}
209213
}
210214

client/network/src/discovery.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl DiscoveryBehaviour {
149149
/// If we didn't know this address before, also generates a `Discovered` event.
150150
pub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr) {
151151
if self.user_defined.iter().all(|(p, a)| *p != peer_id && *a != addr) {
152+
self.kademlia.add_address(&peer_id, addr.clone());
152153
self.discoveries.push_back(peer_id.clone());
153154
self.user_defined.push((peer_id, addr));
154155
}
@@ -329,8 +330,9 @@ impl NetworkBehaviour for DiscoveryBehaviour {
329330
while let Poll::Ready(_) = self.next_kad_random_query.poll_unpin(cx) {
330331
if self.num_connections < self.discovery_only_if_under_num {
331332
let random_peer_id = PeerId::random();
332-
debug!(target: "sub-libp2p", "Libp2p <= Starting random Kademlia request for \
333-
{:?}", random_peer_id);
333+
debug!(target: "sub-libp2p",
334+
"Libp2p <= Starting random Kademlia request for {:?}",
335+
random_peer_id);
334336

335337
self.kademlia.get_closest_peers(random_peer_id);
336338
} else {

0 commit comments

Comments
 (0)