Add ability to connect to raw libp2p nodes
This commit is contained in:
parent
40c0b70b22
commit
15c4062761
@ -1,6 +1,7 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use enr::Enr;
|
use enr::Enr;
|
||||||
use libp2p::gossipsub::{GossipsubConfig, GossipsubConfigBuilder};
|
use libp2p::gossipsub::{GossipsubConfig, GossipsubConfigBuilder};
|
||||||
|
use libp2p::Multiaddr;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -39,6 +40,9 @@ pub struct Config {
|
|||||||
/// List of nodes to initially connect to.
|
/// List of nodes to initially connect to.
|
||||||
pub boot_nodes: Vec<Enr>,
|
pub boot_nodes: Vec<Enr>,
|
||||||
|
|
||||||
|
/// List of libp2p nodes to initially connect to.
|
||||||
|
pub libp2p_nodes: Vec<Multiaddr>,
|
||||||
|
|
||||||
/// Client version
|
/// Client version
|
||||||
pub client_version: String,
|
pub client_version: String,
|
||||||
|
|
||||||
@ -66,6 +70,7 @@ impl Default for Config {
|
|||||||
.heartbeat_interval(Duration::from_secs(20))
|
.heartbeat_interval(Duration::from_secs(20))
|
||||||
.build(),
|
.build(),
|
||||||
boot_nodes: vec![],
|
boot_nodes: vec![],
|
||||||
|
libp2p_nodes: vec![],
|
||||||
client_version: version::version(),
|
client_version: version::version(),
|
||||||
topics: Vec::new(),
|
topics: Vec::new(),
|
||||||
}
|
}
|
||||||
@ -118,6 +123,17 @@ impl Config {
|
|||||||
.collect::<Result<Vec<Enr>, _>>()?;
|
.collect::<Result<Vec<Enr>, _>>()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(libp2p_addresses_str) = args.value_of("libp2p-addresses") {
|
||||||
|
self.libp2p_nodes = libp2p_addresses_str
|
||||||
|
.split(',')
|
||||||
|
.map(|multiaddr| {
|
||||||
|
multiaddr
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| format!("Invalid Multiaddr: {}", multiaddr))
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<Multiaddr>, _>>()?;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(discovery_address_str) = args.value_of("discovery-address") {
|
if let Some(discovery_address_str) = args.value_of("discovery-address") {
|
||||||
self.discovery_address = discovery_address_str
|
self.discovery_address = discovery_address_str
|
||||||
.parse()
|
.parse()
|
||||||
|
@ -37,6 +37,9 @@ pub struct Discovery<TSubstream> {
|
|||||||
/// The target number of connected peers on the libp2p interface.
|
/// The target number of connected peers on the libp2p interface.
|
||||||
max_peers: usize,
|
max_peers: usize,
|
||||||
|
|
||||||
|
/// directory to save ENR to
|
||||||
|
enr_dir: String,
|
||||||
|
|
||||||
/// The delay between peer discovery searches.
|
/// The delay between peer discovery searches.
|
||||||
peer_discovery_delay: Delay,
|
peer_discovery_delay: Delay,
|
||||||
|
|
||||||
@ -54,9 +57,6 @@ pub struct Discovery<TSubstream> {
|
|||||||
|
|
||||||
/// Logger for the discovery behaviour.
|
/// Logger for the discovery behaviour.
|
||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
|
|
||||||
/// directory to save ENR to
|
|
||||||
enr_dir: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TSubstream> Discovery<TSubstream> {
|
impl<TSubstream> Discovery<TSubstream> {
|
||||||
|
@ -76,6 +76,17 @@ impl<E: EthSpec> Service<E> {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// attempt to connect to user-input libp2p nodes
|
||||||
|
for multiaddr in config.libp2p_nodes {
|
||||||
|
match Swarm::dial_addr(&mut swarm, multiaddr.clone()) {
|
||||||
|
Ok(()) => debug!(log, "Dialing libp2p node: {}", multiaddr),
|
||||||
|
Err(err) => debug!(
|
||||||
|
log,
|
||||||
|
"Could not connect to node: {} error: {:?}", multiaddr, err
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// subscribe to default gossipsub topics
|
// subscribe to default gossipsub topics
|
||||||
let mut topics = vec![];
|
let mut topics = vec![];
|
||||||
//TODO: Handle multiple shard attestations. For now we simply use a separate topic for
|
//TODO: Handle multiple shard attestations. For now we simply use a separate topic for
|
||||||
|
@ -56,6 +56,13 @@ fn main() {
|
|||||||
.help("The address lighthouse will listen for UDP and TCP connections. (default 127.0.0.1).")
|
.help("The address lighthouse will listen for UDP and TCP connections. (default 127.0.0.1).")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("port")
|
||||||
|
.long("port")
|
||||||
|
.value_name("Lighthouse Port")
|
||||||
|
.help("The TCP/UDP port to listen on. The UDP port can be modified by the --discovery-port flag.")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("maxpeers")
|
Arg::with_name("maxpeers")
|
||||||
.long("maxpeers")
|
.long("maxpeers")
|
||||||
@ -70,13 +77,6 @@ fn main() {
|
|||||||
.help("One or more comma-delimited base64-encoded ENR's to bootstrap the p2p network.")
|
.help("One or more comma-delimited base64-encoded ENR's to bootstrap the p2p network.")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
|
||||||
Arg::with_name("port")
|
|
||||||
.long("port")
|
|
||||||
.value_name("Lighthouse Port")
|
|
||||||
.help("The TCP/UDP port to listen on. The UDP port can be modified by the --discovery-port flag.")
|
|
||||||
.takes_value(true),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("discovery-port")
|
Arg::with_name("discovery-port")
|
||||||
.long("disc-port")
|
.long("disc-port")
|
||||||
@ -91,6 +91,13 @@ fn main() {
|
|||||||
.help("The IP address to broadcast to other peers on how to reach this node.")
|
.help("The IP address to broadcast to other peers on how to reach this node.")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("libp2p-addresses")
|
||||||
|
.long("libp2p-addresses")
|
||||||
|
.value_name("MULTIADDR")
|
||||||
|
.help("One or more comma-delimited multiaddrs to manually connect to a libp2p peer without an ENR.")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
/*
|
/*
|
||||||
* gRPC parameters.
|
* gRPC parameters.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user