-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add network service * reuse config method * add local_keypair to p2p_config * add network service to fuel-core * add p2p args * move channels out of service initialization * add p2p channels to other modules/services * fmt is hard in the online editor * ooops * Sorry for ruining commit history * oops * pass bootstrap nodes in a vector instead * remove box from db trait object * update peering port * cleanup filter map * unwrap to default * add default values * start p2p network service only if name is provided * update cli values * add correct default values for topics * set tcp port to be chosen automatically * merge master * add some comments * clean up * clean extra space * set default values within clap * use fuel-crypto for key generation * add p2p optional feature * Update fuel-core/Cargo.toml Co-authored-by: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Co-authored-by: ControlC ControlV <controlc@ControlCs-MacBook-Pro.local> Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
- Loading branch information
1 parent
aacc5fa
commit e50553a
Showing
19 changed files
with
542 additions
and
163 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
use std::{ | ||
net::{IpAddr, Ipv4Addr}, | ||
path::PathBuf, | ||
time::Duration, | ||
}; | ||
|
||
use clap::Args; | ||
|
||
use fuel_p2p::{config::P2PConfig, Multiaddr}; | ||
|
||
#[derive(Debug, Clone, Args)] | ||
pub struct P2pArgs { | ||
/// Path to the location of DER-encoded Secp256k1 Keypair | ||
#[clap(long = "keypair")] | ||
pub keypair: Option<PathBuf>, | ||
|
||
/// The name of the p2p Network | ||
/// If this value is not provided the p2p network won't start | ||
#[clap(long = "network", default_value = "")] | ||
pub network: String, | ||
|
||
/// p2p network's IP Address | ||
#[clap(long = "address")] | ||
pub address: Option<IpAddr>, | ||
|
||
/// p2p network's TCP Port | ||
#[clap(long = "peering-port", default_value = "4001")] | ||
pub peering_port: u16, | ||
|
||
/// Max Block size | ||
#[clap(long = "max_block_size", default_value = "100000")] | ||
pub max_block_size: usize, | ||
|
||
/// Addresses of the bootstrap nodes | ||
/// They should contain PeerId at the end of the specified Multiaddr | ||
#[clap(long = "bootstrap_nodes")] | ||
pub bootstrap_nodes: Vec<Multiaddr>, | ||
|
||
/// Allow nodes to be discoverable on the local network | ||
#[clap(long = "enable_mdns")] | ||
pub enable_mdns: bool, | ||
|
||
/// Maximum amount of allowed connected peers | ||
#[clap(long = "max_peers_connected", default_value = "50")] | ||
pub max_peers_connected: usize, | ||
|
||
/// Enable random walk for p2p node discovery | ||
#[clap(long = "enable_random_walk")] | ||
pub enable_random_walk: bool, | ||
|
||
/// Choose to include private IPv4/IPv6 addresses as discoverable | ||
/// except for the ones stored in `bootstrap_nodes` | ||
#[clap(long = "allow_private_addresses")] | ||
pub allow_private_addresses: bool, | ||
|
||
/// Choose how long will connection keep alive if idle | ||
#[clap(long = "connection_idle_timeout", default_value = "120")] | ||
pub connection_idle_timeout: u64, | ||
|
||
/// Choose how often to recieve PeerInfo from other nodes | ||
#[clap(long = "info_interval", default_value = "3")] | ||
pub info_interval: u64, | ||
|
||
/// Choose the interval at which identification requests are sent to | ||
/// the remote on established connections after the first request | ||
#[clap(long = "identify_interval", default_value = "5")] | ||
pub identify_interval: u64, | ||
|
||
/// Choose which topics to subscribe to via gossipsub protocol | ||
#[clap(long = "topics", default_values = &["new_tx", "new_block", "consensus_vote"])] | ||
pub topics: Vec<String>, | ||
|
||
/// Choose max mesh size for gossipsub protocol | ||
#[clap(long = "max_mesh_size", default_value = "12")] | ||
pub max_mesh_size: usize, | ||
|
||
/// Choose min mesh size for gossipsub protocol | ||
#[clap(long = "min_mesh_size", default_value = "4")] | ||
pub min_mesh_size: usize, | ||
|
||
/// Choose ideal mesh size for gossipsub protocol | ||
#[clap(long = "ideal_mesh_size", default_value = "6")] | ||
pub ideal_mesh_size: usize, | ||
|
||
/// Choose timeout for sent requests in RequestResponse protocol | ||
#[clap(long = "request_timeout", default_value = "20")] | ||
pub request_timeout: u64, | ||
|
||
/// Choose how long RequestResponse protocol connections will live if idle | ||
#[clap(long = "connection_keep_alive", default_value = "20")] | ||
pub connection_keep_alive: u64, | ||
} | ||
|
||
impl From<P2pArgs> for anyhow::Result<P2PConfig> { | ||
fn from(args: P2pArgs) -> Self { | ||
let local_keypair = { | ||
match args.keypair { | ||
Some(path) => { | ||
let phrase = std::fs::read_to_string(path)?; | ||
|
||
let secret_key = fuel_crypto::SecretKey::new_from_mnemonic_phrase_with_path( | ||
&phrase, | ||
"m/44'/60'/0'/0/0", | ||
)?; | ||
|
||
fuel_p2p::config::convert_to_libp2p_keypair(&mut secret_key.to_vec())? | ||
} | ||
_ => { | ||
let mut rand = fuel_crypto::rand::thread_rng(); | ||
let secret_key = fuel_crypto::SecretKey::random(&mut rand); | ||
|
||
fuel_p2p::config::convert_to_libp2p_keypair(&mut secret_key.to_vec())? | ||
} | ||
} | ||
}; | ||
|
||
Ok(P2PConfig { | ||
local_keypair, | ||
network_name: args.network, | ||
address: args | ||
.address | ||
.unwrap_or_else(|| IpAddr::V4(Ipv4Addr::from([0, 0, 0, 0]))), | ||
tcp_port: args.peering_port, | ||
max_block_size: args.max_block_size, | ||
bootstrap_nodes: args.bootstrap_nodes, | ||
enable_mdns: args.enable_mdns, | ||
max_peers_connected: args.max_peers_connected, | ||
allow_private_addresses: args.allow_private_addresses, | ||
enable_random_walk: args.enable_random_walk, | ||
connection_idle_timeout: Some(Duration::from_secs(args.connection_idle_timeout)), | ||
topics: args.topics, | ||
max_mesh_size: args.max_mesh_size, | ||
min_mesh_size: args.min_mesh_size, | ||
ideal_mesh_size: args.ideal_mesh_size, | ||
set_request_timeout: Duration::from_secs(args.request_timeout), | ||
set_connection_keep_alive: Duration::from_secs(args.connection_keep_alive), | ||
info_interval: Some(Duration::from_secs(args.info_interval)), | ||
identify_interval: Some(Duration::from_secs(args.identify_interval)), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.