Update to libp2p v0.4 (#1836)

This commit is contained in:
Pierre Krieger
2019-02-21 10:04:53 +01:00
committed by Gav Wood
parent 19ac5e1e95
commit 2b71b3e84b
8 changed files with 159 additions and 210 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ bytes = "0.4"
error-chain = { version = "0.12", default-features = false }
fnv = "1.0"
futures = "0.1"
libp2p = { version = "0.3.1", default-features = false, features = ["secio-secp256k1", "libp2p-websocket"] }
libp2p = { version = "0.4.0", default-features = false, features = ["secio-secp256k1", "libp2p-websocket"] }
parking_lot = "0.7.1"
lazy_static = "1.2"
log = "0.4"
@@ -246,7 +246,7 @@ impl<TMessage, TSubstream> NetworkBehaviourEventProcess<IdentifyEvent> for Behav
info.listen_addrs.truncate(30);
}
for addr in &info.listen_addrs {
self.discovery.kademlia.add_address(&peer_id, addr.clone());
self.discovery.kademlia.add_connected_address(&peer_id, addr.clone());
}
self.custom_protocols.add_discovered_addrs(
&peer_id,
@@ -255,6 +255,10 @@ impl<TMessage, TSubstream> NetworkBehaviourEventProcess<IdentifyEvent> for Behav
self.events.push(BehaviourOut::Identified { peer_id, info });
}
IdentifyEvent::Error { .. } => {}
IdentifyEvent::SendBack { result: Err(ref err), ref peer_id } =>
debug!(target: "sub-libp2p", "Error when sending back identify info \
to {:?} => {}", peer_id, err),
IdentifyEvent::SendBack { .. } => {}
}
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ pub use crate::secret::obtain_private_key;
pub use crate::service_task::{start_service, Service, ServiceEvent};
pub use crate::traits::{NetworkConfiguration, NodeIndex, NodeId, NonReservedPeerMode};
pub use crate::traits::{ProtocolId, Secret, Severity};
pub use libp2p::{Multiaddr, multiaddr::{Protocol}, multiaddr, PeerId, core::PublicKey};
pub use libp2p::{Multiaddr, multiaddr::Protocol, build_multiaddr, PeerId, core::PublicKey};
/// Check if node url is valid
pub fn validate_node_url(url: &str) -> Result<(), Error> {
@@ -22,7 +22,7 @@ use crate::custom_proto::{CustomMessage, RegisteredProtocol, RegisteredProtocols
use crate::{Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
use fnv::FnvHashMap;
use futures::{prelude::*, Stream};
use libp2p::{multiaddr::Protocol, Multiaddr, PeerId, multiaddr};
use libp2p::{multiaddr::Protocol, Multiaddr, PeerId, build_multiaddr};
use libp2p::core::{Swarm, nodes::Substream, transport::boxed::Boxed, muxing::StreamMuxerBox};
use libp2p::core::nodes::ConnectedPoint;
use log::{debug, info, warn};
@@ -88,8 +88,8 @@ where TProtos: IntoIterator<Item = RegisteredProtocol<TMessage>>,
// If the format of the bootstrap node is not a multiaddr, try to parse it as
// a `SocketAddr`. This corresponds to the format `IP:PORT`.
let addr = match bootnode.parse::<SocketAddr>() {
Ok(SocketAddr::V4(socket)) => multiaddr![Ip4(*socket.ip()), Tcp(socket.port())],
Ok(SocketAddr::V6(socket)) => multiaddr![Ip6(*socket.ip()), Tcp(socket.port())],
Ok(SocketAddr::V4(socket)) => build_multiaddr![Ip4(*socket.ip()), Tcp(socket.port())],
Ok(SocketAddr::V6(socket)) => build_multiaddr![Ip6(*socket.ip()), Tcp(socket.port())],
_ => {
warn!(target: "sub-libp2p", "Not a valid bootnode address: {}", bootnode);
continue
+3 -3
View File
@@ -16,7 +16,7 @@
use futures::{future, stream, prelude::*, try_ready};
use std::{io, iter};
use substrate_network_libp2p::{CustomMessage, ServiceEvent, multiaddr};
use substrate_network_libp2p::{CustomMessage, Protocol, ServiceEvent, build_multiaddr};
/// Builds two services. The second one and further have the first one as its bootstrap node.
/// This is to be used only for testing, and a panic will happen if something goes wrong.
@@ -29,12 +29,12 @@ fn build_nodes<TMsg>(num: usize) -> Vec<substrate_network_libp2p::Service<TMsg>>
let mut boot_nodes = Vec::new();
if !result.is_empty() {
let mut bootnode = result[0].listeners().next().unwrap().clone();
bootnode.append(libp2p::multiaddr::Protocol::P2p(result[0].peer_id().clone().into()));
bootnode.append(Protocol::P2p(result[0].peer_id().clone().into()));
boot_nodes.push(bootnode.to_string());
}
let config = substrate_network_libp2p::NetworkConfiguration {
listen_addresses: vec![multiaddr![Ip4([127, 0, 0, 1]), Tcp(0u16)]],
listen_addresses: vec![build_multiaddr![Ip4([127, 0, 0, 1]), Tcp(0u16)]],
boot_nodes,
..substrate_network_libp2p::NetworkConfiguration::default()
};