@@ -346,6 +346,8 @@ pub struct ChannelManager<ChanSigner: ChannelKeys> {
346346 channel_state : Mutex < ChannelHolder < ChanSigner > > ,
347347 our_network_key : SecretKey ,
348348
349+ last_node_announcement_serial : AtomicUsize ,
350+
349351 pending_events : Mutex < Vec < events:: Event > > ,
350352 /// Used when we have to take a BIG lock to make sure everything is self-consistent.
351353 /// Essentially just when we're serializing ourselves out.
@@ -625,6 +627,8 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
625627 } ) ,
626628 our_network_key : keys_manager. get_node_secret ( ) ,
627629
630+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
631+
628632 pending_events : Mutex :: new ( Vec :: new ( ) ) ,
629633 total_consistency_lock : RwLock :: new ( ( ) ) ,
630634
@@ -1286,6 +1290,37 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
12861290 } )
12871291 }
12881292
1293+ /// Generates a signed node_announcement from the given arguments and creates a
1294+ /// BroadcastNodeAnnouncement event.
1295+ ///
1296+ /// RGB is a node "color" and alias a printable human-readable string to describe this node to
1297+ /// humans. They carry no in-protocol meaning.
1298+ ///
1299+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1300+ /// incoming connections.
1301+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1302+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1303+
1304+ let announcement = msgs:: UnsignedNodeAnnouncement {
1305+ features : Features :: < msgs:: FeatureContextNode > :: our_features ( ) ,
1306+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1307+ node_id : self . get_our_node_id ( ) ,
1308+ rgb, alias,
1309+ addresses : addresses. to_vec ( ) ,
1310+ excess_address_data : Vec :: new ( ) ,
1311+ excess_data : Vec :: new ( ) ,
1312+ } ;
1313+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1314+
1315+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1316+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1317+ msg : msgs:: NodeAnnouncement {
1318+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1319+ contents : announcement
1320+ } ,
1321+ } ) ;
1322+ }
1323+
12891324 /// Processes HTLCs which are pending waiting on random forward delay.
12901325 ///
12911326 /// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2874,6 +2909,7 @@ impl<ChanSigner: ChannelKeys> ChannelMessageHandler for ChannelManager<ChanSigne
28742909 & events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
28752910 & events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
28762911 & events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2912+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
28772913 & events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
28782914 & events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
28792915 & events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3160,6 +3196,8 @@ impl<ChanSigner: ChannelKeys + Writeable> Writeable for ChannelManager<ChanSigne
31603196 }
31613197 }
31623198
3199+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3200+
31633201 Ok ( ( ) )
31643202 }
31653203}
@@ -3293,6 +3331,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
32933331 claimable_htlcs. insert ( payment_hash, previous_hops) ;
32943332 }
32953333
3334+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3335+
32963336 let channel_manager = ChannelManager {
32973337 genesis_hash,
32983338 fee_estimator : args. fee_estimator ,
@@ -3312,6 +3352,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>> ReadableArg
33123352 } ) ,
33133353 our_network_key : args. keys_manager . get_node_secret ( ) ,
33143354
3355+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3356+
33153357 pending_events : Mutex :: new ( Vec :: new ( ) ) ,
33163358 total_consistency_lock : RwLock :: new ( ( ) ) ,
33173359 keys_manager : args. keys_manager ,
0 commit comments