@@ -29,8 +29,8 @@ use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
29
29
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
+ use ln:: features:: { InitFeatures , NodeFeatures } ;
32
33
use ln:: router:: Route ;
33
- use ln:: features:: InitFeatures ;
34
34
use ln:: msgs;
35
35
use ln:: onion_utils;
36
36
use ln:: msgs:: { ChannelMessageHandler , DecodeError , LightningError } ;
@@ -368,6 +368,10 @@ pub struct ChannelManager<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref,
368
368
channel_state : Mutex < ChannelHolder < ChanSigner > > ,
369
369
our_network_key : SecretKey ,
370
370
371
+ /// Used to track the last value sent in a node_announcement "timestamp" field. We just set
372
+ /// them to be monotonically increasing since we don't assume access to a time source.
373
+ last_node_announcement_serial : AtomicUsize ,
374
+
371
375
/// The bulk of our storage will eventually be here (channels and message queues and the like).
372
376
/// If we are connected to a peer we always at least have an entry here, even if no channels
373
377
/// are currently open with that peer.
@@ -665,6 +669,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
665
669
} ) ,
666
670
our_network_key : keys_manager. get_node_secret ( ) ,
667
671
672
+ last_node_announcement_serial : AtomicUsize :: new ( 0 ) ,
673
+
668
674
per_peer_state : RwLock :: new ( HashMap :: new ( ) ) ,
669
675
670
676
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
@@ -1333,6 +1339,39 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1333
1339
} )
1334
1340
}
1335
1341
1342
+ /// Generates a signed node_announcement from the given arguments and creates a
1343
+ /// BroadcastNodeAnnouncement event.
1344
+ ///
1345
+ /// RGB is a node "color" and alias ia a printable human-readable string to describe this node
1346
+ /// to humans. They carry no in-protocol meaning.
1347
+ ///
1348
+ /// addresses represent the set (possibly empty) of socket addresses on which this node accepts
1349
+ /// incoming connections. These will be broadcast to the network, publicly tying these
1350
+ /// addresses together. If you wish to preserve user privacy, addresses should likely contain
1351
+ /// only Tor Onion addresses.
1352
+ pub fn broadcast_node_announcement ( & self , rgb : [ u8 ; 3 ] , alias : [ u8 ; 32 ] , addresses : msgs:: NetAddressSet ) {
1353
+ let _ = self . total_consistency_lock . read ( ) . unwrap ( ) ;
1354
+
1355
+ let announcement = msgs:: UnsignedNodeAnnouncement {
1356
+ features : NodeFeatures :: supported ( ) ,
1357
+ timestamp : self . last_node_announcement_serial . fetch_add ( 1 , Ordering :: AcqRel ) as u32 ,
1358
+ node_id : self . get_our_node_id ( ) ,
1359
+ rgb, alias,
1360
+ addresses : addresses. into_vec ( ) ,
1361
+ excess_address_data : Vec :: new ( ) ,
1362
+ excess_data : Vec :: new ( ) ,
1363
+ } ;
1364
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & announcement. encode( ) [ ..] ) [ ..] ) ;
1365
+
1366
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1367
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: BroadcastNodeAnnouncement {
1368
+ msg : msgs:: NodeAnnouncement {
1369
+ signature : self . secp_ctx . sign ( & msghash, & self . our_network_key ) ,
1370
+ contents : announcement
1371
+ } ,
1372
+ } ) ;
1373
+ }
1374
+
1336
1375
/// Processes HTLCs which are pending waiting on random forward delay.
1337
1376
///
1338
1377
/// Should only really ever be called in response to a PendingHTLCsForwardable event.
@@ -2969,6 +3008,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
2969
3008
& events:: MessageSendEvent :: SendShutdown { ref node_id, .. } => node_id != their_node_id,
2970
3009
& events:: MessageSendEvent :: SendChannelReestablish { ref node_id, .. } => node_id != their_node_id,
2971
3010
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
3011
+ & events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
2972
3012
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
2973
3013
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != their_node_id,
2974
3014
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
@@ -3287,6 +3327,8 @@ impl<ChanSigner: ChannelKeys + Writeable, M: Deref, T: Deref, K: Deref, F: Deref
3287
3327
peer_state. latest_features . write ( writer) ?;
3288
3328
}
3289
3329
3330
+ ( self . last_node_announcement_serial . load ( Ordering :: Acquire ) as u32 ) . write ( writer) ?;
3331
+
3290
3332
Ok ( ( ) )
3291
3333
}
3292
3334
}
@@ -3443,6 +3485,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref, T
3443
3485
per_peer_state. insert ( peer_pubkey, Mutex :: new ( peer_state) ) ;
3444
3486
}
3445
3487
3488
+ let last_node_announcement_serial: u32 = Readable :: read ( reader) ?;
3489
+
3446
3490
let channel_manager = ChannelManager {
3447
3491
genesis_hash,
3448
3492
fee_estimator : args. fee_estimator ,
@@ -3462,6 +3506,8 @@ impl<'a, R : ::std::io::Read, ChanSigner: ChannelKeys + Readable<R>, M: Deref, T
3462
3506
} ) ,
3463
3507
our_network_key : args. keys_manager . get_node_secret ( ) ,
3464
3508
3509
+ last_node_announcement_serial : AtomicUsize :: new ( last_node_announcement_serial as usize ) ,
3510
+
3465
3511
per_peer_state : RwLock :: new ( per_peer_state) ,
3466
3512
3467
3513
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
0 commit comments