Add connected peers to protocol, use in sync provider (#1857)

* add connected peers to protocol, use in sync provider

* use PeerId::random

* address comments`

* docs

* fix import of PeerId

* rewrite rpc tests using PeerId::random

* whitespace

* nits

* remove option around peer id and remove field

* further removal of the option around peer id

* fix rpc tests
This commit is contained in:
Gregory Terzian
2019-02-28 01:50:47 +08:00
committed by Gav Wood
parent ea7da0d4a4
commit bc15fa31ff
7 changed files with 140 additions and 74 deletions
@@ -134,6 +134,8 @@ where TProtos: IntoIterator<Item = RegisteredProtocol<TMessage>>,
pub enum ServiceEvent<TMessage> {
/// A custom protocol substream has been opened with a node.
OpenedCustomProtocol {
/// The Id of the node.
peer_id: PeerId,
/// Index of the node.
node_index: NodeIndex,
/// Protocol that has been opened.
@@ -381,8 +383,9 @@ where TMessage: CustomMessage + Send + 'static {
match self.swarm.poll() {
Ok(Async::Ready(Some(BehaviourOut::CustomProtocolOpen { protocol_id, peer_id, version, endpoint }))) => {
debug!(target: "sub-libp2p", "Opened custom protocol with {:?}", peer_id);
let node_index = self.index_of_peer_or_assign(peer_id, endpoint);
let node_index = self.index_of_peer_or_assign(peer_id.clone(), endpoint);
break Ok(Async::Ready(Some(ServiceEvent::OpenedCustomProtocol {
peer_id,
node_index,
protocol: protocol_id,
version,