mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 13:48:00 +00:00
Update network-libp2p to edition 2018 (#1481)
This commit is contained in:
@@ -18,12 +18,14 @@ use crate::custom_proto::{CustomProtos, CustomProtosOut, RegisteredProtocols};
|
||||
use crate::{NetworkConfiguration, ProtocolId};
|
||||
use bytes::Bytes;
|
||||
use futures::prelude::*;
|
||||
use libp2p::NetworkBehaviour;
|
||||
use libp2p::core::{PeerId, ProtocolsHandler};
|
||||
use libp2p::core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
|
||||
use libp2p::core::swarm::{NetworkBehaviourEventProcess, PollParameters};
|
||||
use libp2p::identify::{Identify, IdentifyEvent};
|
||||
use libp2p::kad::{Kademlia, KademliaOut, KademliaTopology};
|
||||
use libp2p::ping::{Ping, PingEvent};
|
||||
use log::{debug, trace, warn};
|
||||
use std::{cmp, time::Duration, time::Instant};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::Delay;
|
||||
|
||||
@@ -22,6 +22,7 @@ use fnv::{FnvHashMap, FnvHashSet};
|
||||
use futures::prelude::*;
|
||||
use libp2p::core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use libp2p::core::{protocols_handler::ProtocolsHandler, PeerId};
|
||||
use log::{debug, trace, warn};
|
||||
use smallvec::SmallVec;
|
||||
use std::{io, marker::PhantomData, time::Duration, time::Instant};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
@@ -23,6 +23,7 @@ use libp2p::core::{
|
||||
protocols_handler::ProtocolsHandlerUpgrErr,
|
||||
upgrade::{InboundUpgrade, OutboundUpgrade}
|
||||
};
|
||||
use log::{trace, warn};
|
||||
use smallvec::SmallVec;
|
||||
use std::{fmt, io};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::ProtocolId;
|
||||
use bytes::Bytes;
|
||||
use libp2p::core::{UpgradeInfo, InboundUpgrade, OutboundUpgrade, upgrade::ProtocolName};
|
||||
use libp2p::tokio_codec::Framed;
|
||||
use log::debug;
|
||||
use std::{collections::VecDeque, io, vec::IntoIter as VecIntoIter};
|
||||
use futures::{prelude::*, future, stream};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use unsigned_varint::codec::UviBytes;
|
||||
use ProtocolId;
|
||||
|
||||
/// Connection upgrade for a single protocol.
|
||||
///
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use error_chain::*;
|
||||
use std::{io, net, fmt};
|
||||
use libc::{ENFILE, EMFILE};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum DisconnectReason
|
||||
{
|
||||
pub enum DisconnectReason {
|
||||
DisconnectRequested,
|
||||
TCPError,
|
||||
BadProtocol,
|
||||
@@ -135,18 +134,6 @@ error_chain! {
|
||||
display("Packet is too large"),
|
||||
}
|
||||
|
||||
#[doc = "Reached system resource limits for this process"]
|
||||
ProcessTooManyFiles {
|
||||
description("Too many open files in process."),
|
||||
display("Too many open files in this process. Check your resource limits and restart parity"),
|
||||
}
|
||||
|
||||
#[doc = "Reached system wide resource limits"]
|
||||
SystemTooManyFiles {
|
||||
description("Too many open files on system."),
|
||||
display("Too many open files on system. Consider closing some processes/release some file handlers or increas the system-wide resource limits and restart parity."),
|
||||
}
|
||||
|
||||
#[doc = "An unknown IO error occurred."]
|
||||
Io(err: io::Error) {
|
||||
description("IO Error"),
|
||||
@@ -157,15 +144,10 @@ error_chain! {
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Self {
|
||||
match err.raw_os_error() {
|
||||
Some(ENFILE) => ErrorKind::ProcessTooManyFiles.into(),
|
||||
Some(EMFILE) => ErrorKind::SystemTooManyFiles.into(),
|
||||
_ => Error::from_kind(ErrorKind::Io(err))
|
||||
}
|
||||
Error::from_kind(ErrorKind::Io(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<net::AddrParseError> for Error {
|
||||
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }
|
||||
}
|
||||
@@ -179,26 +161,3 @@ fn test_errors() {
|
||||
}
|
||||
assert_eq!(DisconnectReason::Unknown, r);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_io_errors() {
|
||||
use libc::{EMFILE, ENFILE};
|
||||
|
||||
assert_matches!(
|
||||
<Error as From<io::Error>>::from(
|
||||
io::Error::from_raw_os_error(ENFILE)
|
||||
).kind(),
|
||||
ErrorKind::ProcessTooManyFiles);
|
||||
|
||||
assert_matches!(
|
||||
<Error as From<io::Error>>::from(
|
||||
io::Error::from_raw_os_error(EMFILE)
|
||||
).kind(),
|
||||
ErrorKind::SystemTooManyFiles);
|
||||
|
||||
assert_matches!(
|
||||
<Error as From<io::Error>>::from(
|
||||
io::Error::from_raw_os_error(0)
|
||||
).kind(),
|
||||
ErrorKind::Io(_));
|
||||
}
|
||||
|
||||
@@ -16,33 +16,6 @@
|
||||
|
||||
//! Networking layer of Substrate.
|
||||
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
extern crate parking_lot;
|
||||
extern crate fnv;
|
||||
extern crate futures;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_timer;
|
||||
extern crate libc;
|
||||
#[macro_use]
|
||||
extern crate libp2p;
|
||||
extern crate rand;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate serde_json;
|
||||
extern crate smallvec;
|
||||
extern crate void;
|
||||
extern crate bytes;
|
||||
extern crate unsigned_varint;
|
||||
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(test)] #[macro_use]
|
||||
extern crate assert_matches;
|
||||
|
||||
mod behaviour;
|
||||
mod custom_proto;
|
||||
mod error;
|
||||
@@ -52,13 +25,13 @@ mod topology;
|
||||
mod traits;
|
||||
mod transport;
|
||||
|
||||
pub use custom_proto::RegisteredProtocol;
|
||||
pub use error::{Error, ErrorKind, DisconnectReason};
|
||||
pub use crate::custom_proto::RegisteredProtocol;
|
||||
pub use crate::error::{Error, ErrorKind, DisconnectReason};
|
||||
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 secret::obtain_private_key;
|
||||
pub use service_task::{start_service, Service, ServiceEvent};
|
||||
pub use traits::{NetworkConfiguration, NodeIndex, NodeId, NonReservedPeerMode};
|
||||
pub use traits::{ProtocolId, Secret, Severity};
|
||||
|
||||
/// Check if node url is valid
|
||||
pub fn validate_node_url(url: &str) -> Result<(), Error> {
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::NetworkConfiguration;
|
||||
use libp2p::secio;
|
||||
use rand::{self, Rng};
|
||||
use std::fs;
|
||||
use log::{trace, warn};
|
||||
use rand::Rng;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Write};
|
||||
use std::path::Path;
|
||||
use NetworkConfiguration;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
// File where the private key is stored.
|
||||
const SECRET_FILE: &str = "secret";
|
||||
|
||||
@@ -15,22 +15,23 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{behaviour::Behaviour, custom_proto::CustomProtosOut, secret::obtain_private_key, transport};
|
||||
use crate::custom_proto::{RegisteredProtocol, RegisteredProtocols};
|
||||
use crate::topology::NetTopology;
|
||||
use crate::{Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
|
||||
use bytes::Bytes;
|
||||
use custom_proto::{RegisteredProtocol, RegisteredProtocols};
|
||||
use fnv::FnvHashMap;
|
||||
use futures::{prelude::*, Stream};
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
use libp2p::{Multiaddr, PeerId, multiaddr};
|
||||
use libp2p::core::{Swarm, nodes::Substream, transport::boxed::Boxed, muxing::StreamMuxerBox};
|
||||
use libp2p::core::nodes::ConnectedPoint;
|
||||
use log::{debug, info, warn};
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::fs;
|
||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use topology::NetTopology;
|
||||
use tokio_timer::Interval;
|
||||
use {Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
|
||||
|
||||
// File where the network topology is stored.
|
||||
const NODES_FILE: &str = "nodes.json";
|
||||
|
||||
@@ -18,7 +18,8 @@ use fnv::FnvHashMap;
|
||||
use libp2p::{Multiaddr, PeerId, identify::IdentifyTopology, multihash::Multihash};
|
||||
use libp2p::core::{PublicKey, swarm::ConnectedPoint, topology::DisconnectReason, topology::Topology};
|
||||
use libp2p::kad::{KBucketsPeerId, KadConnectionType, KademliaTopology};
|
||||
use serde_json;
|
||||
use log::{debug, info, trace, warn};
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use std::{cmp, fs, iter, vec};
|
||||
use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write, BufReader, BufWriter};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
Reference in New Issue
Block a user