@@ -3,7 +3,7 @@ use dkn_p2p::{
3
3
gossipsub:: { Message , MessageAcceptance , MessageId } ,
4
4
PeerId ,
5
5
} ,
6
- DriaP2PClient , DriaP2PCommander , DriaP2PProtocol ,
6
+ DriaNodes , DriaP2PClient , DriaP2PCommander , DriaP2PProtocol ,
7
7
} ;
8
8
use eyre:: Result ;
9
9
use std:: collections:: HashSet ;
@@ -13,7 +13,7 @@ use tokio_util::{either::Either, sync::CancellationToken};
13
13
use crate :: {
14
14
config:: * ,
15
15
handlers:: * ,
16
- utils:: { crypto:: secret_to_keypair, AvailableNodes , DKNMessage } ,
16
+ utils:: { crypto:: secret_to_keypair, refresh_dria_nodes , DriaMessage } ,
17
17
workers:: workflow:: { WorkflowsWorker , WorkflowsWorkerInput , WorkflowsWorkerOutput } ,
18
18
} ;
19
19
@@ -26,7 +26,8 @@ const PUBLISH_CHANNEL_BUFSIZE: usize = 1024;
26
26
27
27
pub struct DriaComputeNode {
28
28
pub config : DriaComputeNodeConfig ,
29
- pub available_nodes : AvailableNodes ,
29
+ /// Pre-defined nodes that belong to Dria, e.g. bootstraps, relays and RPCs.
30
+ pub dria_nodes : DriaNodes ,
30
31
/// Peer-to-peer client commander to interact with the network.
31
32
pub p2p : DriaP2PCommander ,
32
33
/// Gossipsub message receiver, used by peer-to-peer client in a separate thread.
@@ -63,10 +64,10 @@ impl DriaComputeNode {
63
64
let keypair = secret_to_keypair ( & config. secret_key ) ;
64
65
65
66
// get available nodes (bootstrap, relay, rpc) for p2p
66
- let mut available_nodes = AvailableNodes :: new ( config. network_type ) ;
67
- available_nodes . populate_with_statics ( ) ;
68
- available_nodes . populate_with_env ( ) ;
69
- if let Err ( e) = available_nodes . populate_with_api ( ) . await {
67
+ let mut available_nodes = DriaNodes :: new ( config. network_type )
68
+ . with_statics ( )
69
+ . with_envs ( ) ;
70
+ if let Err ( e) = refresh_dria_nodes ( & mut available_nodes ) . await {
70
71
log:: error!( "Error populating available nodes: {:?}" , e) ;
71
72
} ;
72
73
@@ -81,7 +82,7 @@ impl DriaComputeNode {
81
82
config. p2p_listen_addr . clone ( ) ,
82
83
available_nodes. bootstrap_nodes . clone ( ) . into_iter ( ) ,
83
84
available_nodes. relay_nodes . clone ( ) . into_iter ( ) ,
84
- available_nodes. rpc_addrs . clone ( ) . into_iter ( ) ,
85
+ available_nodes. rpc_nodes . clone ( ) . into_iter ( ) ,
85
86
protocol,
86
87
) ?;
87
88
@@ -110,7 +111,7 @@ impl DriaComputeNode {
110
111
DriaComputeNode {
111
112
config,
112
113
p2p : p2p_commander,
113
- available_nodes,
114
+ dria_nodes : available_nodes,
114
115
message_rx,
115
116
publish_rx,
116
117
workflow_batch_tx,
@@ -160,7 +161,7 @@ impl DriaComputeNode {
160
161
///
161
162
/// Internally, identity is attached to the the message which is then JSON serialized to bytes
162
163
/// and then published to the network as is.
163
- pub async fn publish ( & mut self , mut message : DKNMessage ) -> Result < ( ) > {
164
+ pub async fn publish ( & mut self , mut message : DriaMessage ) -> Result < ( ) > {
164
165
// attach protocol name to the message
165
166
message = message. with_identity ( self . p2p . protocol ( ) . name . clone ( ) ) ;
166
167
@@ -203,17 +204,17 @@ impl DriaComputeNode {
203
204
) ;
204
205
205
206
// ensure that message is from the known RPCs
206
- if !self . available_nodes . rpc_nodes . contains ( & source_peer_id) {
207
+ if !self . dria_nodes . rpc_peerids . contains ( & source_peer_id) {
207
208
log:: warn!(
208
209
"Received message from unauthorized source: {}" ,
209
210
source_peer_id
210
211
) ;
211
- log:: debug!( "Allowed sources: {:#?}" , self . available_nodes . rpc_nodes ) ;
212
+ log:: debug!( "Allowed sources: {:#?}" , self . dria_nodes . rpc_peerids ) ;
212
213
return MessageAcceptance :: Ignore ;
213
214
}
214
215
215
216
// parse the raw gossipsub message to a prepared DKN message
216
- let message = match DKNMessage :: try_from_gossipsub_message (
217
+ let message = match DriaMessage :: try_from_gossipsub_message (
217
218
& message,
218
219
& self . config . admin_public_key ,
219
220
) {
@@ -414,20 +415,22 @@ impl DriaComputeNode {
414
415
/// Updates the local list of available nodes by refreshing it.
415
416
/// Dials the RPC nodes again for better connectivity.
416
417
async fn handle_available_nodes_refresh ( & mut self ) {
417
- log:: info!( "Refreshing available nodes." ) ;
418
+ log:: info!( "Refreshing available Dria nodes." ) ;
418
419
419
420
// refresh available nodes
420
- if let Err ( e) = self . available_nodes . populate_with_api ( ) . await {
421
+ if let Err ( e) = refresh_dria_nodes ( & mut self . dria_nodes ) . await {
421
422
log:: error!( "Error refreshing available nodes: {:?}" , e) ;
422
423
} ;
423
424
424
425
// dial all rpc nodes
425
- for rpc_addr in self . available_nodes . rpc_addrs . iter ( ) {
426
- log:: debug !( "Dialling RPC node: {}" , rpc_addr) ;
426
+ for rpc_addr in self . dria_nodes . rpc_nodes . iter ( ) {
427
+ log:: info !( "Dialling RPC node: {}" , rpc_addr) ;
427
428
if let Err ( e) = self . p2p . dial ( rpc_addr. clone ( ) ) . await {
428
429
log:: warn!( "Error dialling RPC node: {:?}" , e) ;
429
430
} ;
430
431
}
432
+
433
+ log:: info!( "Finished refreshing!" ) ;
431
434
}
432
435
}
433
436
@@ -462,7 +465,7 @@ mod tests {
462
465
463
466
// publish a dummy message
464
467
let topic = "foo" ;
465
- let message = DKNMessage :: new ( "hello from the other side" , topic) ;
468
+ let message = DriaMessage :: new ( "hello from the other side" , topic) ;
466
469
node. subscribe ( topic) . await . expect ( "should subscribe" ) ;
467
470
node. publish ( message) . await . expect ( "should publish" ) ;
468
471
node. unsubscribe ( topic) . await . expect ( "should unsubscribe" ) ;
0 commit comments