mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 16:47:57 +00:00
Rewrite the libp2p networking (#742)
* Rewrite the libp2p networking * Fix erroneous replacement during rebase * Update libp2p * Update libp2p * Remove the logic error about useless substreams * Use the new NodeHandler system of libp2p * Commit the Cargo.lock * Upgrade yamux * Forward port latest changes * Fix compilation issues * Implement the external URL * Update to latest networking fixes * Forward port rest of v0.2 * Fix reserved peers being dropped when we're full
This commit is contained in:
committed by
Arkadiy Paronyan
parent
abf799f78f
commit
52dbf0cace
@@ -25,15 +25,18 @@ extern crate parking_lot;
|
||||
extern crate fnv;
|
||||
extern crate futures;
|
||||
extern crate tokio;
|
||||
extern crate tokio_executor;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_timer;
|
||||
extern crate libc;
|
||||
#[macro_use]
|
||||
extern crate libp2p;
|
||||
extern crate rand;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate serde_json;
|
||||
extern crate smallvec;
|
||||
extern crate bytes;
|
||||
extern crate unsigned_varint;
|
||||
|
||||
@@ -46,18 +49,25 @@ extern crate log;
|
||||
#[cfg(test)] #[macro_use]
|
||||
extern crate assert_matches;
|
||||
|
||||
use libp2p::PeerId;
|
||||
|
||||
pub use connection_filter::{ConnectionFilter, ConnectionDirection};
|
||||
pub use error::{Error, ErrorKind, DisconnectReason};
|
||||
pub use libp2p::{Multiaddr, multiaddr::AddrComponent};
|
||||
pub use libp2p::{Multiaddr, multiaddr::Protocol};
|
||||
pub use traits::*;
|
||||
|
||||
pub type TimerToken = usize;
|
||||
|
||||
// TODO: remove as it is unused ; however modifying `network` causes a clusterfuck of dependencies
|
||||
// resolve errors at the moment
|
||||
mod connection_filter;
|
||||
mod custom_proto;
|
||||
mod error;
|
||||
mod network_state;
|
||||
mod node_handler;
|
||||
mod secret;
|
||||
mod service;
|
||||
mod service_task;
|
||||
mod swarm;
|
||||
mod timeouts;
|
||||
mod topology;
|
||||
mod traits;
|
||||
@@ -67,8 +77,19 @@ pub use service::NetworkService;
|
||||
|
||||
/// Check if node url is valid
|
||||
pub fn validate_node_url(url: &str) -> Result<(), Error> {
|
||||
match url.parse::<libp2p::multiaddr::Multiaddr>() {
|
||||
match url.parse::<Multiaddr>() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(ErrorKind::InvalidNodeId.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a string address and returns the component, if valid.
|
||||
pub(crate) fn parse_str_addr(addr_str: &str) -> Result<(PeerId, Multiaddr), Error> {
|
||||
let mut addr: Multiaddr = addr_str.parse().map_err(|_| ErrorKind::AddressParse)?;
|
||||
let who = match addr.pop() {
|
||||
Some(Protocol::P2p(key)) =>
|
||||
PeerId::from_multihash(key).map_err(|_| ErrorKind::AddressParse)?,
|
||||
_ => return Err(ErrorKind::AddressParse.into()),
|
||||
};
|
||||
Ok((who, addr))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user