@@ -55,6 +55,7 @@ struct DirectionalChannelInfo {
55
55
htlc_minimum_msat : u64 ,
56
56
fee_base_msat : u32 ,
57
57
fee_proportional_millionths : u32 ,
58
+ bitcoin_key : PublicKey ,
58
59
}
59
60
60
61
impl std:: fmt:: Display for DirectionalChannelInfo {
@@ -68,6 +69,8 @@ struct ChannelInfo {
68
69
features : GlobalFeatures ,
69
70
one_to_two : DirectionalChannelInfo ,
70
71
two_to_one : DirectionalChannelInfo ,
72
+ //this is cached here so we can send out it later if required by route_init_sync
73
+ announcement_message : Option < msgs:: ChannelAnnouncement > ,
71
74
}
72
75
73
76
impl std:: fmt:: Display for ChannelInfo {
@@ -91,6 +94,8 @@ struct NodeInfo {
91
94
rgb : [ u8 ; 3 ] ,
92
95
alias : [ u8 ; 32 ] ,
93
96
addresses : Vec < NetAddress > ,
97
+ //this is cached here so we can send out it later if required by route_init_sync
98
+ announcement_message : Option < msgs:: NodeAnnouncement > ,
94
99
}
95
100
96
101
impl std:: fmt:: Display for NodeInfo {
@@ -184,7 +189,7 @@ pub struct RouteHint {
184
189
/// Tracks a view of the network, receiving updates from peers and generating Routes to
185
190
/// payment destinations.
186
191
pub struct Router {
187
- secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
192
+ secp_ctx : Secp256k1 < secp256k1:: All > ,
188
193
network_map : RwLock < NetworkMap > ,
189
194
chain_monitor : Arc < ChainWatchInterface > ,
190
195
logger : Arc < Logger > ,
@@ -221,6 +226,7 @@ impl RoutingMessageHandler for Router {
221
226
node. rgb = msg. contents . rgb ;
222
227
node. alias = msg. contents . alias ;
223
228
node. addresses = msg. contents . addresses . clone ( ) ;
229
+
224
230
Ok ( msg. contents . excess_data . is_empty ( ) && msg. contents . excess_address_data . is_empty ( ) && !msg. contents . features . supports_unknown_bits ( ) )
225
231
}
226
232
}
@@ -279,6 +285,7 @@ impl RoutingMessageHandler for Router {
279
285
htlc_minimum_msat : u64:: max_value ( ) ,
280
286
fee_base_msat : u32:: max_value ( ) ,
281
287
fee_proportional_millionths : u32:: max_value ( ) ,
288
+ bitcoin_key : msg. contents . bitcoin_key_1 . clone ( ) ,
282
289
} ,
283
290
two_to_one : DirectionalChannelInfo {
284
291
src_node_id : msg. contents . node_id_2 . clone ( ) ,
@@ -288,7 +295,9 @@ impl RoutingMessageHandler for Router {
288
295
htlc_minimum_msat : u64:: max_value ( ) ,
289
296
fee_base_msat : u32:: max_value ( ) ,
290
297
fee_proportional_millionths : u32:: max_value ( ) ,
291
- }
298
+ bitcoin_key : msg. contents . bitcoin_key_2 . clone ( ) ,
299
+ } ,
300
+ announcement_message : Some ( msg. clone ( ) ) ,
292
301
} ;
293
302
294
303
match network. channels . entry ( NetworkMap :: get_key ( msg. contents . short_channel_id , msg. contents . chain_hash ) ) {
@@ -332,6 +341,7 @@ impl RoutingMessageHandler for Router {
332
341
rgb: [ 0 ; 3 ] ,
333
342
alias: [ 0 ; 32 ] ,
334
343
addresses: Vec :: new( ) ,
344
+ announcement_message: None ,
335
345
} ) ;
336
346
}
337
347
}
@@ -430,13 +440,66 @@ impl RoutingMessageHandler for Router {
430
440
431
441
impl NetworkTopology for Router {
432
442
fn get_all_channel_announcements ( & self ) -> Result < Vec < msgs:: ChannelAnnouncement > , std:: fmt:: Error > {
433
- unimplemented ! ( ) ;
443
+ let result = Vec :: new ( ) ;
444
+ let network = self . network_map . read ( ) . unwrap ( ) ;
445
+ for ( key, value) in network. channels . iter ( ) {
446
+ if let Some ( i) = value. announcement_message {
447
+ result. push ( i. clone ( ) ) ;
448
+ }
449
+ }
450
+ return Ok ( result)
451
+ /* #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
452
+ return Ok(Vec::new());
453
+ #[cfg(feature = "non_bitcoin_chain_hash_routing")]{
454
+ let result = Vec::new();
455
+ let network = self.network_map.read().unwrap();
456
+ for (key, value) in network.channels.iter(){
457
+ let (id, chainhash) = key;
458
+ let msg_contents = msgs::UnsignedChannelAnnouncement {
459
+ features: value.features.clone(),
460
+ chain_hash: chainhash,
461
+ short_channel_id: id.clone(),
462
+ node_id_1: value.one_to_two.src_node_id.clone(),
463
+ node_id_2: value.two_to_one.src_node_id.clone(),
464
+ bitcoin_key_1: value.one_to_two.bitcoin_key.clone(),
465
+ bitcoin_key_2: value.two_to_one.bitcoin_key.clone(),
466
+ excess_data: Vec::new()};
467
+ let msg_hash = Message::from_slice(&Sha256dHash::from_data(&msg_contents.encode()[..])[..]).unwrap();
468
+ let msg_signature = self.secp_ctx.sign(&msg_hash, key);
469
+ result.push(msgs::ChannelAnnouncement {
470
+ signature: msg_signature,
471
+ contents: msg_contents,
472
+ })
473
+ }
474
+ return Ok(result)}*/
434
475
}
476
+ ///This function generates a vec of all node_annoucment messages for all nodes it known of
435
477
fn get_all_node_announcements ( & self ) -> Result < Vec < msgs:: NodeAnnouncement > , std:: fmt:: Error > {
436
- unimplemented ! ( ) ;
478
+ let result = Vec :: new ( ) ;
479
+ let network = self . network_map . read ( ) . unwrap ( ) ;
480
+ for ( key, value) in network. nodes . iter ( ) {
481
+ if let Some ( i) = value. announcement_message {
482
+ result. push ( i. clone ( ) ) ;
483
+ }
484
+ /*let msg_contents = msgs::UnsignedNodeAnnouncement{
485
+ features: value.features.clone(),
486
+ timestamp: value.last_update,
487
+ node_id: key.clone(),
488
+ rgb: value.rgb.clone(),
489
+ alias: value.alias.clone(),
490
+ addresses: value.addresses.clone(),
491
+ excess_address_data: Vec::new(),
492
+ excess_data: Vec::new(),};
493
+ let msg_hash = Message::from_slice(&Sha256dHash::from_data(&msg_contents.encode()[..])[..]).unwrap();
494
+ let msg_signature = self.secp_ctx.sign(&msg_hash, key);
495
+ result.push(msgs::NodeAnnouncement {
496
+ signature: msg_signature,
497
+ contents: msg_contents,
498
+ })*/
499
+ }
500
+ Ok ( result)
437
501
}
438
502
}
439
-
440
503
#[ derive( Eq , PartialEq ) ]
441
504
struct RouteGraphNode {
442
505
pubkey : PublicKey ,
@@ -478,9 +541,10 @@ impl Router {
478
541
rgb : [ 0 ; 3 ] ,
479
542
alias : [ 0 ; 32 ] ,
480
543
addresses : Vec :: new ( ) ,
544
+ announcement_message : None ,
481
545
} ) ;
482
546
Router {
483
- secp_ctx : Secp256k1 :: verification_only ( ) ,
547
+ secp_ctx : Secp256k1 :: new ( ) ,
484
548
network_map : RwLock :: new ( NetworkMap {
485
549
channels : HashMap :: new ( ) ,
486
550
our_node_id : our_pubkey,
0 commit comments