@@ -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,10 @@ 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
+ /// Used to track the last value sent in a node_announcement "timestamp" field. We just set
361
+ /// them to be monotonically increasing since we don't assume access to a time source.
362
+ last_node_announcement_serial : AtomicUsize ,
363
+
360
364
/// The bulk of our storage will eventually be here (channels and message queues and the like).
361
365
/// If we are connected to a peer we always at least have an entry here, even if no channels
362
366
/// are currently open with that peer.
@@ -651,6 +655,8 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
651
655
} ) ,
652
656
our_network_key : keys_manager. get_node_secret ( ) ,
653
657
658
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
659
+
654
660
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
655
661
656
662
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1288,6 +1294,39 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
1288
1294
} )
1289
1295
}
1290
1296
1297
+ /// Generates a signed node_announcement from the given arguments and creates a
1298
+ /// BroadcastNodeAnnouncement event.
1299
+ ///
1300
+ /// RGB is a node "color" and alias a printable human-readable string to describe this node to
1301
+ /// humans. They carry no in-protocol meaning.
1302
+ ///
1303
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1304
+ /// incoming connections. These will be broadcast to the network, publicly tying these
1305
+ /// addresses together. If you wish to preserve user privacy, addresses should likely contain
1306
+ /// only Tor Onion addresses.
1307
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1308
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1309
+
1310
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1311
+ features : NodeFeatures :: supported ( ) ,
1312
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1313
+ node_id : self . get_our_node_id ( ) ,
1314
+ rgb, alias,
1315
+ addresses : addresses. to_vec ( ) ,
1316
+ excess_address_data : Vec :: new ( ) ,
1317
+ excess_data : Vec :: new ( ) ,
1318
+ } ;
1319
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1320
+
1321
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1322
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1323
+ msg : msgs:: NodeAnnouncement {
1324
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1325
+ contents : announcement
1326
+ } ,
1327
+ } ) ;
1328
+ }
1329
+
1291
1330
/// Processes HTLCs which are pending waiting on random forward delay.
1292
1331
///
1293
1332
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2889,6 +2928,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send> ChannelMessageHandler for
2889
2928
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2890
2929
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2891
2930
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2931
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2892
2932
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2893
2933
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2894
2934
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3202,6 +3242,8 @@ impl<ChanSigner: ChannelKeys + Writeable, M: Deref> Writeable for ChannelManager
3202
3242
peer_state. latest_features . write ( writer) ?;
3203
3243
}
3204
3244
3245
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3246
+
3205
3247
Ok ( ( ) )
3206
3248
}
3207
3249
}
@@ -3345,6 +3387,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3345
3387
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3346
3388
}
3347
3389
3390
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3391
+
3348
3392
let channel_manager = ChannelManager {
3349
3393
genesis_hash,
3350
3394
fee_estimator : args. fee_estimator ,
@@ -3364,6 +3408,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3364
3408
} ) ,
3365
3409
our_network_key : args. keys_manager . get_node_secret ( ) ,
3366
3410
3411
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3412
+
3367
3413
per_peer_state : RwLock :: new ( per_peer_state) ,
3368
3414
3369
3415
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments