@@ -47,7 +47,7 @@ const METRICS_GOSPUBSUB_TOPIC: &str = "atoma-p2p-usage-metrics";
4747const METRICS_UPDATE_INTERVAL : Duration = Duration :: from_secs ( 15 ) ;
4848
4949/// The protocol name for the Kademlia DHT
50- const IPFS_PROTO_NAME : StreamProtocol = StreamProtocol :: new ( "/ipfs /kad/1.0.0" ) ;
50+ const KAD_PROTOCOL_NAME : StreamProtocol = StreamProtocol :: new ( "/atoma-network /kad/1.0.0" ) ;
5151
5252// Well connected nodes to bootstrap the network (see https://docs.ipfs.tech/concepts/public-utilities/#amino-dht-bootstrappers)
5353const IPFS_BOOTSTRAP_NODES : [ & str ; 4 ] = [
@@ -57,9 +57,6 @@ const IPFS_BOOTSTRAP_NODES: [&str; 4] = [
5757 "QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt" ,
5858] ;
5959
60- // The proxy bootstrap nodes
61- const PROXY_BOOTSTRAP_NODES : [ & str ; 1 ] = [ "12D3KooWHXsXfELpyB91QUXebbLMLSQDB3kcGyogn4pogABSj1eZ" ] ;
62-
6360pub type StateManagerEvent = ( AtomaP2pEvent , Option < oneshot:: Sender < bool > > ) ;
6461
6562/// Network behavior configuration for the P2P Atoma node, combining multiple libp2p protocols.
@@ -128,6 +125,9 @@ pub struct AtomaP2pNode {
128125
129126 /// Add registry field
130127 metrics_registry : Registry ,
128+
129+ /// Bootstrap node peer IDs
130+ bootstrap_node_peer_ids : Option < Vec < String > > ,
131131}
132132
133133impl AtomaP2pNode {
@@ -291,7 +291,7 @@ impl AtomaP2pNode {
291291 )
292292 . map_err ( |e| AtomaP2pNodeError :: InvalidConfig ( e. to_string ( ) ) ) ?;
293293
294- let mut cfg = kad:: Config :: new ( IPFS_PROTO_NAME ) ;
294+ let mut cfg = kad:: Config :: new ( KAD_PROTOCOL_NAME ) ;
295295 cfg. set_query_timeout ( Duration :: from_secs ( 5 * 60 ) ) ;
296296 let store = kad:: store:: MemoryStore :: new ( local_peer_id) ;
297297 let kademlia = kad:: Behaviour :: with_config ( local_peer_id, store, cfg) ;
@@ -438,31 +438,33 @@ impl AtomaP2pNode {
438438 }
439439
440440 // Dial the proxy bootstrap nodes
441- for peer_id in PROXY_BOOTSTRAP_NODES {
442- match peer_id. parse :: < PeerId > ( ) {
443- // We don't need bootstrap nodes to dial themselves
444- Ok ( peer_id) if peer_id != * swarm. local_peer_id ( ) => {
445- // add quic multiaddr
446- swarm
447- . behaviour_mut ( )
448- . kademlia
449- . add_address ( & peer_id, config. bootstrap_node_addrs [ 0 ] . parse ( ) ?) ;
450- // add tcp multiaddr
451- swarm
452- . behaviour_mut ( )
453- . kademlia
454- . add_address ( & peer_id, config. bootstrap_node_addrs [ 1 ] . parse ( ) ?) ;
455- }
456- Err ( e) => {
457- error ! (
458- target = "atoma-p2p" ,
459- event = "bootstrap_node_parse_error" ,
460- peer_id = %peer_id,
461- error = %e,
462- "Failed to parse proxy bootstrap node address"
463- ) ;
441+ if let Some ( bootstrap_node_peer_ids) = & config. bootstrap_node_peer_ids {
442+ for peer_id in bootstrap_node_peer_ids {
443+ match peer_id. parse :: < PeerId > ( ) {
444+ // We don't need bootstrap nodes to dial themselves
445+ Ok ( peer_id) if peer_id != * swarm. local_peer_id ( ) => {
446+ // add quic multiaddr
447+ swarm
448+ . behaviour_mut ( )
449+ . kademlia
450+ . add_address ( & peer_id, config. bootstrap_node_addrs [ 0 ] . parse ( ) ?) ;
451+ // add tcp multiaddr
452+ swarm
453+ . behaviour_mut ( )
454+ . kademlia
455+ . add_address ( & peer_id, config. bootstrap_node_addrs [ 1 ] . parse ( ) ?) ;
456+ }
457+ Err ( e) => {
458+ error ! (
459+ target = "atoma-p2p" ,
460+ event = "bootstrap_node_parse_error" ,
461+ peer_id = %peer_id,
462+ error = %e,
463+ "Failed to parse proxy bootstrap node address"
464+ ) ;
465+ }
466+ _ => { }
464467 }
465- _ => { }
466468 }
467469 }
468470
@@ -475,6 +477,7 @@ impl AtomaP2pNode {
475477 is_client,
476478 network_metrics,
477479 metrics_registry,
480+ bootstrap_node_peer_ids : config. bootstrap_node_peer_ids ,
478481 } )
479482 }
480483
@@ -736,13 +739,15 @@ impl AtomaP2pNode {
736739 connection_id = %connection_id,
737740 "Peer connection established"
738741 ) ;
739- if PROXY_BOOTSTRAP_NODES . iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
740- info!(
741- target = "atoma-p2p" ,
742- event = "incoming_connection_bootstrap_node" ,
743- peer_id = %peer_id,
744- "Incoming connection from proxy bootstrap node"
745- ) ;
742+ if let Some ( bootstrap_node_peer_ids) = & self . bootstrap_node_peer_ids {
743+ if bootstrap_node_peer_ids. iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
744+ info!(
745+ target = "atoma-p2p" ,
746+ event = "incoming_connection_bootstrap_node" ,
747+ peer_id = %peer_id,
748+ "Incoming connection from proxy bootstrap node"
749+ ) ;
750+ }
746751 }
747752 }
748753 SwarmEvent :: ConnectionClosed {
@@ -799,14 +804,16 @@ impl AtomaP2pNode {
799804 ) ;
800805 TOTAL_DIALS_ATTEMPTED . add( 1 , & [ KeyValue :: new( "peerId" , peer_id. unwrap( ) . to_base58( ) ) ] ) ;
801806 if let Some ( peer_id) = peer_id {
802- if PROXY_BOOTSTRAP_NODES . iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
803- info!(
804- target = "atoma-p2p" ,
805- event = "dialing_bootstrap_node" ,
806- peer_id = %peer_id,
807- connection_id = %connection_id,
808- "Dialing proxy bootstrap node"
809- ) ;
807+ if let Some ( bootstrap_node_peer_ids) = & self . bootstrap_node_peer_ids {
808+ if bootstrap_node_peer_ids. iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
809+ info!(
810+ target = "atoma-p2p" ,
811+ event = "dialing_bootstrap_node" ,
812+ peer_id = %peer_id,
813+ connection_id = %connection_id,
814+ "Dialing proxy bootstrap node"
815+ ) ;
816+ }
810817 }
811818 }
812819 }
@@ -818,6 +825,16 @@ impl AtomaP2pNode {
818825 event = "incoming_connection" ,
819826 "Incoming connection"
820827 ) ;
828+ if let Some ( bootstrap_node_peer_ids) = & self . bootstrap_node_peer_ids {
829+ if bootstrap_node_peer_ids. iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id. to_string( ) == peer_id) . unwrap_or( false ) ) {
830+ info!(
831+ target = "atoma-p2p" ,
832+ event = "incoming_connection_bootstrap_node" ,
833+ peer_id = %peer_id,
834+ "Incoming connection from proxy bootstrap node"
835+ ) ;
836+ }
837+ }
821838 }
822839 SwarmEvent :: IncomingConnectionError {
823840 ..
@@ -840,13 +857,15 @@ impl AtomaP2pNode {
840857 ) ;
841858 TOTAL_DIALS_FAILED . add( 1 , & [ KeyValue :: new( "peerId" , peer_id. unwrap( ) . to_base58( ) ) ] ) ;
842859 if let Some ( peer_id) = peer_id {
843- if PROXY_BOOTSTRAP_NODES . iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
844- error!(
845- target = "atoma-p2p" ,
846- event = "outgoing_connection_error_bootstrap_node" ,
847- peer_id = %peer_id,
848- "Outgoing connection error to proxy bootstrap node"
849- ) ;
860+ if let Some ( bootstrap_node_peer_ids) = & self . bootstrap_node_peer_ids {
861+ if bootstrap_node_peer_ids. iter( ) . any( |node| node. parse:: <PeerId >( ) . map( |id| id == peer_id) . unwrap_or( false ) ) {
862+ error!(
863+ target = "atoma-p2p" ,
864+ event = "outgoing_connection_error_bootstrap_node" ,
865+ peer_id = %peer_id,
866+ "Outgoing connection error to proxy bootstrap node"
867+ ) ;
868+ }
850869 }
851870 }
852871 }
0 commit comments