@@ -350,6 +350,8 @@ pub struct ChannelManager<ChanSigner: ChannelKeys> {
350
350
channel_state : Mutex < ChannelHolder < ChanSigner > > ,
351
351
our_network_key : SecretKey ,
352
352
353
+ last_node_announcement_serial : AtomicUsize ,
354
+
353
355
/// Per-peer state storage.
354
356
/// Because adding or removing an entry is rare, we usually take an outer read lock and then
355
357
/// operate on the inner value freely. Sadly, this prevents parallel operation when opening a
@@ -642,6 +644,8 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
642
644
} ) ,
643
645
our_network_key : keys_manager. get_node_secret ( ) ,
644
646
647
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
648
+
645
649
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
646
650
647
651
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1354,6 +1358,37 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
1354
1358
} )
1355
1359
}
1356
1360
1361
+ /// Generates a signed node_announcement from the given arguments and creates a
1362
+ /// BroadcastNodeAnnouncement event.
1363
+ ///
1364
+ /// RGB is a node "color" and alias a printable human-readable string to describe this node to
1365
+ /// humans. They carry no in-protocol meaning.
1366
+ ///
1367
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1368
+ /// incoming connections.
1369
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1370
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1371
+
1372
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1373
+ features : Features :: < msgs:: FeatureContextNode > :: our_features ( ) ,
1374
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1375
+ node_id : self . get_our_node_id ( ) ,
1376
+ rgb, alias,
1377
+ addresses : addresses. to_vec ( ) ,
1378
+ excess_address_data : Vec :: new ( ) ,
1379
+ excess_data : Vec :: new ( ) ,
1380
+ } ;
1381
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1382
+
1383
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1384
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1385
+ msg : msgs:: NodeAnnouncement {
1386
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1387
+ contents : announcement
1388
+ } ,
1389
+ } ) ;
1390
+ }
1391
+
1357
1392
/// Processes HTLCs which are pending waiting on random forward delay.
1358
1393
///
1359
1394
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2944,6 +2979,7 @@ impl<ChanSigner: ChannelKeys> ChannelMessageHandler for ChannelManager<ChanSigne
2944
2979
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2945
2980
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2946
2981
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2982
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2947
2983
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2948
2984
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2949
2985
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3257,6 +3293,8 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for ChannelManager<ChanSigne
3257
3293
peer_state. latest_features . write ( writer) ?;
3258
3294
}
3259
3295
3296
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3297
+
3260
3298
Ok ( ( ) )
3261
3299
}
3262
3300
}
@@ -3400,6 +3438,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
3400
3438
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3401
3439
}
3402
3440
3441
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3442
+
3403
3443
let channel_manager = ChannelManager {
3404
3444
genesis_hash,
3405
3445
fee_estimator : args. fee_estimator ,
@@ -3419,6 +3459,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
3419
3459
} ) ,
3420
3460
our_network_key : args. keys_manager . get_node_secret ( ) ,
3421
3461
3462
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3463
+
3422
3464
per_peer_state : RwLock :: new ( per_peer_state) ,
3423
3465
3424
3466
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments