mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-04-04 15:35:18 +00:00
Supports custom public ip to announce file
This commit is contained in:
parent
82fd29968b
commit
a42fad5572
@ -10,7 +10,7 @@ mod service;
|
|||||||
use duration_str::deserialize_duration;
|
use duration_str::deserialize_duration;
|
||||||
use network::Multiaddr;
|
use network::Multiaddr;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::time::Duration;
|
use std::{net::IpAddr, time::Duration};
|
||||||
|
|
||||||
pub use crate::service::RouterService;
|
pub use crate::service::RouterService;
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ pub struct Config {
|
|||||||
pub libp2p_nodes: Vec<Multiaddr>,
|
pub libp2p_nodes: Vec<Multiaddr>,
|
||||||
pub private_ip_enabled: bool,
|
pub private_ip_enabled: bool,
|
||||||
pub check_announced_ip: bool,
|
pub check_announced_ip: bool,
|
||||||
|
pub public_address: Option<IpAddr>,
|
||||||
|
|
||||||
// batcher
|
// batcher
|
||||||
/// Timeout to publish messages in batch
|
/// Timeout to publish messages in batch
|
||||||
@ -47,6 +48,7 @@ impl Default for Config {
|
|||||||
libp2p_nodes: vec![],
|
libp2p_nodes: vec![],
|
||||||
private_ip_enabled: false,
|
private_ip_enabled: false,
|
||||||
check_announced_ip: false,
|
check_announced_ip: false,
|
||||||
|
public_address: None,
|
||||||
|
|
||||||
batcher_timeout: Duration::from_secs(1),
|
batcher_timeout: Duration::from_secs(1),
|
||||||
batcher_file_capacity: 1,
|
batcher_file_capacity: 1,
|
||||||
|
@ -353,12 +353,14 @@ impl Libp2pEventHandler {
|
|||||||
return Some(addr);
|
return Some(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ipv4_addr = public_ip::addr_v4().await?;
|
let ip_protocol = match self.config.public_address {
|
||||||
|
Some(addr) => addr.into(),
|
||||||
|
None => Protocol::Ip4(public_ip::addr_v4().await?),
|
||||||
|
};
|
||||||
|
|
||||||
let mut addr = Multiaddr::empty();
|
let mut addr = Multiaddr::empty();
|
||||||
addr.push(Protocol::Ip4(ipv4_addr));
|
addr.push(ip_protocol);
|
||||||
addr.push(Protocol::Tcp(self.network_globals.listen_port_tcp()));
|
addr.push(Protocol::Tcp(self.network_globals.listen_port_tcp()));
|
||||||
addr.push(Protocol::P2p(self.network_globals.local_peer_id().into()));
|
|
||||||
|
|
||||||
self.network_globals
|
self.network_globals
|
||||||
.listen_multiaddrs
|
.listen_multiaddrs
|
||||||
|
@ -200,6 +200,13 @@ impl ZgsConfig {
|
|||||||
pub fn router_config(&self, network_config: &NetworkConfig) -> Result<router::Config, String> {
|
pub fn router_config(&self, network_config: &NetworkConfig) -> Result<router::Config, String> {
|
||||||
let mut router_config = self.router.clone();
|
let mut router_config = self.router.clone();
|
||||||
router_config.libp2p_nodes = network_config.libp2p_nodes.to_vec();
|
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)
|
Ok(router_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user