|
1 | 1 | use std::{ |
2 | 2 | fs::File, |
3 | 3 | io::{BufRead, BufReader, Read}, |
| 4 | + net::IpAddr, |
4 | 5 | path::Path, |
5 | 6 | sync::Arc, |
6 | 7 | time::Duration, |
@@ -40,6 +41,7 @@ pub struct NodeBuilder { |
40 | 41 | p2p_no_discovery: bool, |
41 | 42 | p2p_is_started: bool, |
42 | 43 | initial_peers: Vec<P2pConnectionOutgoingInitOpts>, |
| 44 | + external_addrs: Vec<IpAddr>, |
43 | 45 | block_producer: Option<BlockProducerConfig>, |
44 | 46 | snarker: Option<SnarkerConfig>, |
45 | 47 | service: NodeServiceBuilder, |
@@ -73,6 +75,7 @@ impl NodeBuilder { |
73 | 75 | p2p_no_discovery: false, |
74 | 76 | p2p_is_started: false, |
75 | 77 | initial_peers: Vec::new(), |
| 78 | + external_addrs: Vec::new(), |
76 | 79 | block_producer: None, |
77 | 80 | snarker: None, |
78 | 81 | service: NodeServiceBuilder::new(rng_seed), |
@@ -121,6 +124,11 @@ impl NodeBuilder { |
121 | 124 | self |
122 | 125 | } |
123 | 126 |
|
| 127 | + pub fn external_addrs(&mut self, v: impl Iterator<Item = IpAddr>) -> &mut Self { |
| 128 | + self.external_addrs.extend(v); |
| 129 | + self |
| 130 | + } |
| 131 | + |
124 | 132 | /// Extend p2p initial peers from file. |
125 | 133 | pub fn initial_peers_from_file(&mut self, path: impl AsRef<Path>) -> anyhow::Result<&mut Self> { |
126 | 134 | peers_from_reader( |
@@ -282,6 +290,8 @@ impl NodeBuilder { |
282 | 290 | }) |
283 | 291 | .collect(); |
284 | 292 |
|
| 293 | + let external_addrs = self.external_addrs; |
| 294 | + |
285 | 295 | let srs = self.verifier_srs.unwrap_or_else(get_srs); |
286 | 296 | let block_verifier_index = self |
287 | 297 | .block_verifier_index |
@@ -311,6 +321,7 @@ impl NodeBuilder { |
311 | 321 | listen_port: self.http_port, |
312 | 322 | identity_pub_key: p2p_sec_key.public_key(), |
313 | 323 | initial_peers, |
| 324 | + external_addrs, |
314 | 325 | ask_initial_peers_interval: Duration::from_secs(3600), |
315 | 326 | enabled_channels: ChannelId::iter_all().collect(), |
316 | 327 | peer_discovery: !self.p2p_no_discovery, |
|
0 commit comments