Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cli/src/commands/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub struct Node {
#[arg(env = "MINA_LIBP2P_PASS")]
pub libp2p_password: Option<String>,

/// List of external addresses at which this node is accessible
#[arg(long)]
pub libp2p_external_ip: Vec<String>,

/// Http port to listen on
#[arg(long, short, env, default_value = "3000")]
pub port: u16,
Expand Down Expand Up @@ -194,6 +198,12 @@ impl Node {

node_builder.p2p_libp2p_port(self.libp2p_port);

node_builder.external_addrs(
self.libp2p_external_ip
.into_iter()
.filter_map(|s| s.parse().ok()),
);

self.seed.then(|| node_builder.p2p_seed_node());
self.no_peers_discovery
.then(|| node_builder.p2p_no_discovery());
Expand Down
11 changes: 11 additions & 0 deletions node/native/src/node/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fs::File,
io::{BufRead, BufReader, Read},
net::IpAddr,
path::Path,
sync::Arc,
time::Duration,
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct NodeBuilder {
p2p_no_discovery: bool,
p2p_is_started: bool,
initial_peers: Vec<P2pConnectionOutgoingInitOpts>,
external_addrs: Vec<IpAddr>,
block_producer: Option<BlockProducerConfig>,
snarker: Option<SnarkerConfig>,
service: NodeServiceBuilder,
Expand Down Expand Up @@ -73,6 +75,7 @@ impl NodeBuilder {
p2p_no_discovery: false,
p2p_is_started: false,
initial_peers: Vec::new(),
external_addrs: Vec::new(),
block_producer: None,
snarker: None,
service: NodeServiceBuilder::new(rng_seed),
Expand Down Expand Up @@ -121,6 +124,11 @@ impl NodeBuilder {
self
}

pub fn external_addrs(&mut self, v: impl Iterator<Item = IpAddr>) -> &mut Self {
self.external_addrs.extend(v);
self
}

/// Extend p2p initial peers from file.
pub fn initial_peers_from_file(&mut self, path: impl AsRef<Path>) -> anyhow::Result<&mut Self> {
peers_from_reader(
Expand Down Expand Up @@ -282,6 +290,8 @@ impl NodeBuilder {
})
.collect();

let external_addrs = self.external_addrs;

let srs = self.verifier_srs.unwrap_or_else(get_srs);
let block_verifier_index = self
.block_verifier_index
Expand Down Expand Up @@ -311,6 +321,7 @@ impl NodeBuilder {
listen_port: self.http_port,
identity_pub_key: p2p_sec_key.public_key(),
initial_peers,
external_addrs,
ask_initial_peers_interval: Duration::from_secs(3600),
enabled_channels: ChannelId::iter_all().collect(),
peer_discovery: !self.p2p_no_discovery,
Expand Down
1 change: 1 addition & 0 deletions node/testing/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl Cluster {
listen_port: Some(http_port),
identity_pub_key: p2p_sec_key.public_key(),
initial_peers,
external_addrs: vec![],
ask_initial_peers_interval: testing_config.ask_initial_peers_interval,
enabled_channels: ChannelId::iter_all().collect(),
peer_discovery: true,
Expand Down
1 change: 1 addition & 0 deletions node/web/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl NodeBuilder {
listen_port: None,
identity_pub_key: p2p_sec_key.public_key(),
initial_peers,
external_addrs: vec![],
ask_initial_peers_interval: Duration::from_secs(3600),
enabled_channels: ChannelId::iter_all().collect(),
peer_discovery: !self.p2p_no_discovery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ impl P2pNetworkIdentifyStreamEffectfulAction {
peer_id,
stream_id,
} => {
let mut listen_addrs = Vec::new();
let config = &store.state().config;
let ips = &config.external_addrs;
let port = config.libp2p_port.unwrap_or(8302);

let mut listen_addrs = ips
.iter()
.map(|ip| Multiaddr::from(*ip).with(multiaddr::Protocol::Tcp(port)))
.collect::<Vec<_>>();

for addr in store
.state()
.network
Expand Down
4 changes: 3 additions & 1 deletion p2p/src/p2p_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeSet, time::Duration};
use std::{collections::BTreeSet, net::IpAddr, time::Duration};

use serde::{Deserialize, Serialize};

Expand All @@ -22,6 +22,8 @@ pub struct P2pConfig {
pub identity_pub_key: PublicKey,
/// A list addresses of seed nodes.
pub initial_peers: Vec<P2pConnectionOutgoingInitOpts>,
/// External addresses
pub external_addrs: Vec<IpAddr>,

/// The time interval that must elapse before the next peer discovery request.
/// The node periodically polls peers for their connections to keep our list up to date.
Expand Down
1 change: 1 addition & 0 deletions p2p/testing/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ impl Cluster {
listen_port: Some(listen_port),
identity_pub_key: secret_key.public_key(),
initial_peers,
external_addrs: vec![],
ask_initial_peers_interval: Duration::from_secs(5),
enabled_channels: p2p::channels::ChannelId::for_libp2p().collect(),
peer_discovery: config.discovery,
Expand Down
Loading