@@ -350,6 +350,8 @@ pub struct ChannelManager<ChanSigner: ChannelKeys> {
350350 channel_state : Mutex < ChannelHolder < ChanSigner > > ,
351351 our_network_key : SecretKey ,
352352
353+ last_node_announcement_serial : AtomicUsize ,
354+
353355 /// Per-peer state storage.
354356 /// Because adding or removing an entry is rare, we usually take an outer read lock and then
355357 /// operate on the inner value freely. Sadly, this prevents parallel operation when opening a
@@ -642,6 +644,8 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
642644 } ) ,
643645 our_network_key : keys_manager. get_node_secret ( ) ,
644646
647+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
648+
645649 per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
646650
647651 pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1354,6 +1358,37 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
13541358 } )
13551359 }
13561360
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+
13571392 /// Processes HTLCs which are pending waiting on random forward delay.
13581393 ///
13591394 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2944,6 +2979,7 @@ impl<ChanSigner: ChannelKeys> ChannelMessageHandler for ChannelManager<ChanSigne
29442979 & events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
29452980 & events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
29462981 & events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2982+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
29472983 & events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
29482984 & events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
29492985 & events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3257,6 +3293,8 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for ChannelManager<ChanSigne
32573293 peer_state. latest_features . write ( writer) ?;
32583294 }
32593295
3296+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3297+
32603298 Ok ( ( ) )
32613299 }
32623300}
@@ -3400,6 +3438,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
34003438 per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
34013439 }
34023440
3441+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3442+
34033443 let channel_manager = ChannelManager {
34043444 genesis_hash,
34053445 fee_estimator : args. fee_estimator ,
@@ -3419,6 +3459,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
34193459 } ) ,
34203460 our_network_key : args. keys_manager . get_node_secret ( ) ,
34213461
3462+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3463+
34223464 per_peer_state : RwLock :: new ( per_peer_state) ,
34233465
34243466 pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments