Add network routes to API

This commit is contained in:
Paul Hauner
2019-08-14 18:23:26 +10:00
parent f2dedfac50
commit c93d2baa91
11 changed files with 134 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ use futures::prelude::*;
use libp2p::{
core::identity::Keypair,
discv5::Discv5Event,
enr::Enr,
gossipsub::{Gossipsub, GossipsubEvent},
identify::{Identify, IdentifyEvent},
ping::{Ping, PingConfig, PingEvent},
@@ -78,6 +79,10 @@ impl<TSubstream: AsyncRead + AsyncWrite> Behaviour<TSubstream> {
log: behaviour_log,
})
}
pub fn discovery(&self) -> &Discovery<TSubstream> {
&self.discovery
}
}
// Implement the NetworkBehaviourEventProcess trait so that we can derive NetworkBehaviour for Behaviour

View File

@@ -103,6 +103,10 @@ impl<TSubstream> Discovery<TSubstream> {
})
}
pub fn local_enr(&self) -> &Enr {
self.discovery.local_enr()
}
/// Manually search for peers. This restarts the discovery round, sparking multiple rapid
/// queries.
pub fn discover_peers(&mut self) {
@@ -120,6 +124,11 @@ impl<TSubstream> Discovery<TSubstream> {
self.connected_peers.len()
}
/// The current number of connected libp2p peers.
pub fn connected_peer_set(&self) -> &HashSet<PeerId> {
&self.connected_peers
}
/// Search for new peers using the underlying discovery mechanism.
fn find_peers(&mut self) {
// pick a random NodeId

View File

@@ -17,6 +17,7 @@ pub use behaviour::PubsubMessage;
pub use config::{
Config as NetworkConfig, BEACON_ATTESTATION_TOPIC, BEACON_BLOCK_TOPIC, SHARD_TOPIC_PREFIX,
};
pub use libp2p::enr::Enr;
pub use libp2p::gossipsub::{Topic, TopicHash};
pub use libp2p::multiaddr;
pub use libp2p::Multiaddr;

View File

@@ -15,7 +15,7 @@ use libp2p::core::{
transport::boxed::Boxed,
upgrade::{InboundUpgradeExt, OutboundUpgradeExt},
};
use libp2p::{core, secio, PeerId, Swarm, Transport};
use libp2p::{core, enr::Enr, secio, PeerId, Swarm, Transport};
use slog::{debug, info, trace, warn};
use std::fs::File;
use std::io::prelude::*;