mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 16:41:10 +00:00
Remove dialing without a PeerId
This commit is contained in:
committed by
Bastian Köcher
parent
90cd8a8479
commit
ead437d0f4
@@ -22,14 +22,13 @@ use crate::custom_proto::{CustomMessage, RegisteredProtocol, RegisteredProtocols
|
|||||||
use crate::{NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
|
use crate::{NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use futures::{prelude::*, Stream};
|
use futures::{prelude::*, Stream};
|
||||||
use libp2p::{multiaddr::Protocol, Multiaddr, PeerId, build_multiaddr};
|
use libp2p::{multiaddr::Protocol, Multiaddr, PeerId};
|
||||||
use libp2p::core::{Swarm, nodes::Substream, transport::boxed::Boxed, muxing::StreamMuxerBox};
|
use libp2p::core::{Swarm, nodes::Substream, transport::boxed::Boxed, muxing::StreamMuxerBox};
|
||||||
use libp2p::core::nodes::ConnectedPoint;
|
use libp2p::core::nodes::ConnectedPoint;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
|
||||||
use std::net::SocketAddr;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@@ -81,27 +80,8 @@ where TProtos: IntoIterator<Item = RegisteredProtocol<TMessage>>,
|
|||||||
// Connect to the bootnodes.
|
// Connect to the bootnodes.
|
||||||
for bootnode in config.boot_nodes.iter() {
|
for bootnode in config.boot_nodes.iter() {
|
||||||
match parse_str_addr(bootnode) {
|
match parse_str_addr(bootnode) {
|
||||||
Ok((peer_id, _)) => {
|
Ok((peer_id, _)) => Swarm::dial(&mut swarm, peer_id),
|
||||||
Swarm::dial(&mut swarm, peer_id);
|
Err(_) => warn!(target: "sub-libp2p", "Not a valid bootnode address: {}", bootnode),
|
||||||
},
|
|
||||||
Err(_) => {
|
|
||||||
// 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)) => 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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
info!(target: "sub-libp2p", "Dialing {} with no peer id. Keep in mind that doing \
|
|
||||||
so is vulnerable to man-in-the-middle attacks.", addr);
|
|
||||||
if let Err(addr) = Swarm::dial_addr(&mut swarm, addr) {
|
|
||||||
warn!(target: "sub-libp2p", "Bootstrap address not supported: {}", addr)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user