@@ -30,7 +30,7 @@ use chain::transaction::OutPoint;
30
30
use ln:: channel:: { Channel , ChannelError } ;
31
31
use ln:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdateErr , ManyChannelMonitor , CLTV_CLAIM_BUFFER , LATENCY_GRACE_PERIOD_BLOCKS , ANTI_REORG_DELAY } ;
32
32
use ln:: router:: Route ;
33
- use ln:: features:: InitFeatures ;
33
+ use ln:: features:: { InitFeatures , NodeFeatures } ;
34
34
use ln:: msgs;
35
35
use ln:: onion_utils;
36
36
use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError } ;
@@ -357,6 +357,8 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref> where M::Target: Ma
357
357
channel_state : Mutex < ChannelHolder < ChanSigner > > ,
358
358
our_network_key : SecretKey ,
359
359
360
+ last_node_announcement_serial : AtomicUsize ,
361
+
360
362
/// The bulk of our storage will eventually be here (channels and message queues and the like).
361
363
/// If we are connected to a peer we always at least have an entry here, even if no channels
362
364
/// are currently open with that peer.
@@ -651,6 +653,8 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
651
653
} ) ,
652
654
our_network_key : keys_manager. get_node_secret ( ) ,
653
655
656
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
657
+
654
658
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
655
659
656
660
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1285,6 +1289,37 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
1285
1289
} )
1286
1290
}
1287
1291
1292
+ /// Generates a signed node_announcement from the given arguments and creates a
1293
+ /// BroadcastNodeAnnouncement event.
1294
+ ///
1295
+ /// RGB is a node "color" and alias a printable human-readable string to describe this node to
1296
+ /// humans. They carry no in-protocol meaning.
1297
+ ///
1298
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1299
+ /// incoming connections.
1300
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1301
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1302
+
1303
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1304
+ features : NodeFeatures :: supported ( ) ,
1305
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1306
+ node_id : self . get_our_node_id ( ) ,
1307
+ rgb, alias,
1308
+ addresses : addresses. to_vec ( ) ,
1309
+ excess_address_data : Vec :: new ( ) ,
1310
+ excess_data : Vec :: new ( ) ,
1311
+ } ;
1312
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1313
+
1314
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1315
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1316
+ msg : msgs:: NodeAnnouncement {
1317
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1318
+ contents : announcement
1319
+ } ,
1320
+ } ) ;
1321
+ }
1322
+
1288
1323
/// Processes HTLCs which are pending waiting on random forward delay.
1289
1324
///
1290
1325
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2880,6 +2915,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send> ChannelMessageHandler for
2880
2915
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2881
2916
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2882
2917
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2918
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2883
2919
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2884
2920
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2885
2921
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3193,6 +3229,8 @@ impl<ChanSigner: ChannelKeys + Writeable, M: Deref> Writeable for ChannelManager
3193
3229
peer_state. latest_features . write ( writer) ?;
3194
3230
}
3195
3231
3232
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3233
+
3196
3234
Ok ( ( ) )
3197
3235
}
3198
3236
}
@@ -3336,6 +3374,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3336
3374
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3337
3375
}
3338
3376
3377
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3378
+
3339
3379
let channel_manager = ChannelManager {
3340
3380
genesis_hash,
3341
3381
fee_estimator : args. fee_estimator ,
@@ -3355,6 +3395,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3355
3395
} ) ,
3356
3396
our_network_key : args. keys_manager . get_node_secret ( ) ,
3357
3397
3398
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3399
+
3358
3400
per_peer_state : RwLock :: new ( per_peer_state) ,
3359
3401
3360
3402
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments