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

Add a fn listen_addresses() to NetworkService #6409

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 14 additions & 1 deletion client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{
protocol::{self, event::Event, LegacyConnectionKillError, sync::SyncState, PeerInfo, Protocol},
transport, ReputationChange,
};
use futures::prelude::*;
use futures::{channel::oneshot, prelude::*};
use libp2p::{PeerId, Multiaddr};
use libp2p::core::{ConnectedPoint, Executor, connection::{ConnectionError, PendingConnectionError}, either::EitherError};
use libp2p::kad::record;
Expand Down Expand Up @@ -747,6 +747,15 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
.unbounded_send(ServiceToWorkerMsg::UpdateChain);
}

/// Returns a stream containing the listen addresses
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns a stream containing the listen addresses
/// Returns the list of addresses we are currently listening on.
///
/// Please be aware that this list might change over time.

pub fn listen_addresses(&self) -> impl Future<Output = Vec<Multiaddr>> {
let (tx, rx) = oneshot::channel();
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::ListenAddresses(tx));

async {
rx.await.expect("the sender is never dropped; qed")
}
}
}

impl<B: BlockT + 'static, H: ExHashT> sp_consensus::SyncOracle
Expand Down Expand Up @@ -813,6 +822,7 @@ enum ServiceToWorkerMsg<B: BlockT, H: ExHashT> {
},
DisconnectPeer(PeerId),
UpdateChain,
ListenAddresses(oneshot::Sender<Vec<Multiaddr>>),
}

/// Main network worker. Must be polled in order for the network to advance.
Expand Down Expand Up @@ -1143,6 +1153,9 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
this.network_service.user_protocol_mut().disconnect_peer(&who),
ServiceToWorkerMsg::UpdateChain =>
this.network_service.user_protocol_mut().update_chain(),
ServiceToWorkerMsg::ListenAddresses(sender) => {
let _ = sender.send(this.listen_addresses().cloned().collect());
},
}
}

Expand Down