@@ -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 } ;
@@ -355,6 +355,10 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref> where M::Target: Ma
355
355
channel_state : Mutex < ChannelHolder < ChanSigner > > ,
356
356
our_network_key : SecretKey ,
357
357
358
+ /// Used to track the last value sent in a node_announcement "timestamp" field. We just set
359
+ /// them to be monotonically increasing since we don't assume access to a time source.
360
+ last_node_announcement_serial : AtomicUsize ,
361
+
358
362
/// The bulk of our storage will eventually be here (channels and message queues and the like).
359
363
/// If we are connected to a peer we always at least have an entry here, even if no channels
360
364
/// are currently open with that peer.
@@ -649,6 +653,8 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
649
653
} ) ,
650
654
our_network_key : keys_manager. get_node_secret ( ) ,
651
655
656
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
657
+
652
658
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
653
659
654
660
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1317,6 +1323,39 @@ impl<ChanSigner: ChannelKeys, M: Deref> ChannelManager<ChanSigner, M> where M::T
1317
1323
} )
1318
1324
}
1319
1325
1326
+ /// Generates a signed node_announcement from the given arguments and creates a
1327
+ /// BroadcastNodeAnnouncement event.
1328
+ ///
1329
+ /// RGB is a node "color" and alias a printable human-readable string to describe this node to
1330
+ /// humans. They carry no in-protocol meaning.
1331
+ ///
1332
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1333
+ /// incoming connections. These will be broadcast to the network, publicly tying these
1334
+ /// addresses together. If you wish to preserve user privacy, addresses should likely contain
1335
+ /// only Tor Onion addresses.
1336
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1337
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1338
+
1339
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1340
+ features : NodeFeatures :: supported ( ) ,
1341
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1342
+ node_id : self . get_our_node_id ( ) ,
1343
+ rgb, alias,
1344
+ addresses : addresses. to_vec ( ) ,
1345
+ excess_address_data : Vec :: new ( ) ,
1346
+ excess_data : Vec :: new ( ) ,
1347
+ } ;
1348
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1349
+
1350
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1351
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1352
+ msg : msgs:: NodeAnnouncement {
1353
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1354
+ contents : announcement
1355
+ } ,
1356
+ } ) ;
1357
+ }
1358
+
1320
1359
/// Processes HTLCs which are pending waiting on random forward delay.
1321
1360
///
1322
1361
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2918,6 +2957,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send> ChannelMessageHandler for
2918
2957
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2919
2958
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2920
2959
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
2960
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2921
2961
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2922
2962
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2923
2963
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3231,6 +3271,8 @@ impl<ChanSigner: ChannelKeys + Writeable, M: Deref> Writeable for ChannelManager
3231
3271
peer_state. latest_features . write ( writer) ?;
3232
3272
}
3233
3273
3274
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3275
+
3234
3276
Ok ( ( ) )
3235
3277
}
3236
3278
}
@@ -3374,6 +3416,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3374
3416
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3375
3417
}
3376
3418
3419
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3420
+
3377
3421
let channel_manager = ChannelManager {
3378
3422
genesis_hash,
3379
3423
fee_estimator : args. fee_estimator ,
@@ -3393,6 +3437,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref> R
3393
3437
} ) ,
3394
3438
our_network_key : args. keys_manager . get_node_secret ( ) ,
3395
3439
3440
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3441
+
3396
3442
per_peer_state : RwLock :: new ( per_peer_state) ,
3397
3443
3398
3444
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments