mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-12-26 00:05:17 +00:00
Supports custom public ip to announce file (#233)
Some checks are pending
abi-consistent-check / build-and-compare (push) Waiting to run
code-coverage / unittest-cov (push) Waiting to run
rust / check (push) Waiting to run
rust / test (push) Waiting to run
rust / lints (push) Waiting to run
functional-test / test (push) Waiting to run
Some checks are pending
abi-consistent-check / build-and-compare (push) Waiting to run
code-coverage / unittest-cov (push) Waiting to run
rust / check (push) Waiting to run
rust / test (push) Waiting to run
rust / lints (push) Waiting to run
functional-test / test (push) Waiting to run
* Supports custom public ip to announce file * Fix comment
This commit is contained in:
parent
a4b02a21b7
commit
e701c8fdbd
@ -10,7 +10,7 @@ mod service;
|
||||
use duration_str::deserialize_duration;
|
||||
use network::Multiaddr;
|
||||
use serde::Deserialize;
|
||||
use std::time::Duration;
|
||||
use std::{net::IpAddr, time::Duration};
|
||||
|
||||
pub use crate::service::RouterService;
|
||||
|
||||
@ -26,6 +26,7 @@ pub struct Config {
|
||||
pub libp2p_nodes: Vec<Multiaddr>,
|
||||
pub private_ip_enabled: bool,
|
||||
pub check_announced_ip: bool,
|
||||
pub public_address: Option<IpAddr>,
|
||||
|
||||
// batcher
|
||||
/// Timeout to publish messages in batch
|
||||
@ -47,6 +48,7 @@ impl Default for Config {
|
||||
libp2p_nodes: vec![],
|
||||
private_ip_enabled: false,
|
||||
check_announced_ip: false,
|
||||
public_address: None,
|
||||
|
||||
batcher_timeout: Duration::from_secs(1),
|
||||
batcher_file_capacity: 1,
|
||||
|
@ -348,17 +348,26 @@ impl Libp2pEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_listen_addr_or_add(&self) -> Option<Multiaddr> {
|
||||
async fn construct_announced_ip(&self) -> Option<Multiaddr> {
|
||||
// public address configured
|
||||
if let Some(ip) = self.config.public_address {
|
||||
let mut addr = Multiaddr::empty();
|
||||
addr.push(ip.into());
|
||||
addr.push(Protocol::Tcp(self.network_globals.listen_port_tcp()));
|
||||
return Some(addr);
|
||||
}
|
||||
|
||||
// public listen address
|
||||
if let Some(addr) = self.get_listen_addr() {
|
||||
return Some(addr);
|
||||
}
|
||||
|
||||
// auto detect public IP address
|
||||
let ipv4_addr = public_ip::addr_v4().await?;
|
||||
|
||||
let mut addr = Multiaddr::empty();
|
||||
addr.push(Protocol::Ip4(ipv4_addr));
|
||||
addr.push(Protocol::Tcp(self.network_globals.listen_port_tcp()));
|
||||
addr.push(Protocol::P2p(self.network_globals.local_peer_id().into()));
|
||||
|
||||
self.network_globals
|
||||
.listen_multiaddrs
|
||||
@ -420,7 +429,7 @@ impl Libp2pEventHandler {
|
||||
|
||||
let peer_id = *self.network_globals.peer_id.read();
|
||||
|
||||
let addr = self.get_listen_addr_or_add().await?;
|
||||
let addr = self.construct_announced_ip().await?;
|
||||
|
||||
let timestamp = timestamp_now();
|
||||
let shard_config = self.store.get_store().get_shard_config();
|
||||
@ -452,7 +461,7 @@ impl Libp2pEventHandler {
|
||||
shard_config: ShardConfig,
|
||||
) -> Option<PubsubMessage> {
|
||||
let peer_id = *self.network_globals.peer_id.read();
|
||||
let addr = self.get_listen_addr_or_add().await?;
|
||||
let addr = self.construct_announced_ip().await?;
|
||||
let timestamp = timestamp_now();
|
||||
|
||||
let msg = AnnounceShardConfig {
|
||||
@ -528,7 +537,7 @@ impl Libp2pEventHandler {
|
||||
index_end: u64,
|
||||
) -> Option<PubsubMessage> {
|
||||
let peer_id = *self.network_globals.peer_id.read();
|
||||
let addr = self.get_listen_addr_or_add().await?;
|
||||
let addr = self.construct_announced_ip().await?;
|
||||
let timestamp = timestamp_now();
|
||||
|
||||
let msg = AnnounceChunks {
|
||||
|
@ -200,6 +200,13 @@ impl ZgsConfig {
|
||||
pub fn router_config(&self, network_config: &NetworkConfig) -> Result<router::Config, String> {
|
||||
let mut router_config = self.router.clone();
|
||||
router_config.libp2p_nodes = network_config.libp2p_nodes.to_vec();
|
||||
|
||||
if router_config.public_address.is_none() {
|
||||
if let Some(addr) = &self.network_enr_address {
|
||||
router_config.public_address = Some(addr.parse().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(router_config)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user