@@ -10,7 +10,7 @@ use std::time::Duration;
10
10
use tokio:: sync:: mpsc;
11
11
12
12
use crate :: behaviour:: { DriaBehaviour , DriaBehaviourEvent } ;
13
- use crate :: DriaP2PProtocol ;
13
+ use crate :: { DriaNodes , DriaP2PProtocol } ;
14
14
15
15
use super :: commands:: DriaP2PCommand ;
16
16
use super :: DriaP2PCommander ;
@@ -46,9 +46,7 @@ impl DriaP2PClient {
46
46
pub fn new (
47
47
keypair : Keypair ,
48
48
listen_addr : Multiaddr ,
49
- bootstraps : impl Iterator < Item = Multiaddr > ,
50
- relays : impl Iterator < Item = Multiaddr > ,
51
- rpcs : impl Iterator < Item = Multiaddr > ,
49
+ nodes : & DriaNodes ,
52
50
protocol : DriaP2PProtocol ,
53
51
) -> Result < (
54
52
DriaP2PClient ,
@@ -89,15 +87,18 @@ impl DriaP2PClient {
89
87
. set_mode ( Some ( libp2p:: kad:: Mode :: Server ) ) ;
90
88
91
89
// initiate bootstrap
92
- for addr in bootstraps {
90
+ for addr in & nodes . bootstrap_nodes {
93
91
log:: info!( "Dialling bootstrap: {:#?}" , addr) ;
94
92
if let Some ( peer_id) = addr. iter ( ) . find_map ( |p| match p {
95
93
Protocol :: P2p ( peer_id) => Some ( peer_id) ,
96
94
_ => None ,
97
95
} ) {
98
96
swarm. dial ( addr. clone ( ) ) ?;
99
97
log:: info!( "Adding {} to Kademlia routing table" , addr) ;
100
- swarm. behaviour_mut ( ) . kademlia . add_address ( & peer_id, addr) ;
98
+ swarm
99
+ . behaviour_mut ( )
100
+ . kademlia
101
+ . add_address ( & peer_id, addr. clone ( ) ) ;
101
102
} else {
102
103
log:: warn!( "Missing peerID in address: {}" , addr) ;
103
104
}
@@ -115,17 +116,29 @@ impl DriaP2PClient {
115
116
// listen on all interfaces for incoming connections
116
117
log:: info!( "Listening p2p network on: {}" , listen_addr) ;
117
118
swarm. listen_on ( listen_addr) ?;
118
- for addr in relays {
119
+
120
+ // listen on relay addresses with p2p circuit
121
+ for addr in & nodes. relay_nodes {
119
122
log:: info!( "Listening to relay: {}" , addr) ;
120
123
swarm. listen_on ( addr. clone ( ) . with ( Protocol :: P2pCircuit ) ) ?;
121
124
}
122
125
123
126
// dial rpc nodes
124
- for rpc_addr in rpcs {
127
+ for rpc_addr in & nodes . rpc_nodes {
125
128
log:: info!( "Dialing RPC node: {}" , rpc_addr) ;
126
- swarm. dial ( rpc_addr) ?;
129
+ swarm. dial ( rpc_addr. clone ( ) ) ?;
127
130
}
128
131
132
+ // add rpcs as explicit peers
133
+ // TODO: may not be necessary
134
+ // for rpc_peer_id in &nodes.rpc_peerids {
135
+ // log::info!("Adding {} as explicit peer.", rpc_peer_id);
136
+ // swarm
137
+ // .behaviour_mut()
138
+ // .gossipsub
139
+ // .add_explicit_peer(rpc_peer_id);
140
+ // }
141
+
129
142
// create commander
130
143
let ( cmd_tx, cmd_rx) = mpsc:: channel ( COMMAND_CHANNEL_BUFSIZE ) ;
131
144
let commander = DriaP2PCommander :: new ( cmd_tx, protocol. clone ( ) ) ;
0 commit comments