@@ -8,6 +8,7 @@ use util::events::{EventsProvider,Event};
8
8
9
9
use std:: collections:: { HashMap , LinkedList } ;
10
10
use std:: sync:: { Arc , Mutex } ;
11
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
11
12
use std:: { cmp, error, mem, hash, fmt} ;
12
13
13
14
pub struct MessageHandler {
@@ -86,6 +87,7 @@ pub struct PeerManager<Descriptor: SocketDescriptor> {
86
87
peers : Mutex < PeerHolder < Descriptor > > ,
87
88
pending_events : Mutex < Vec < Event > > ,
88
89
our_node_secret : SecretKey ,
90
+ initial_syncs_sent : AtomicUsize ,
89
91
}
90
92
91
93
@@ -101,6 +103,9 @@ macro_rules! encode_msg {
101
103
}
102
104
}
103
105
106
+ //TODO: Really should do something smarter for this
107
+ const INITIAL_SYNCS_TO_SEND : usize = 5 ;
108
+
104
109
/// Manages and reacts to connection events. You probably want to use file descriptors as PeerIds.
105
110
/// PeerIds may repeat, but only after disconnect_event() has been called.
106
111
impl < Descriptor : SocketDescriptor > PeerManager < Descriptor > {
@@ -110,6 +115,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
110
115
peers : Mutex :: new ( PeerHolder { peers : HashMap :: new ( ) , node_id_to_descriptor : HashMap :: new ( ) } ) ,
111
116
pending_events : Mutex :: new ( Vec :: new ( ) ) ,
112
117
our_node_secret : our_node_secret,
118
+ initial_syncs_sent : AtomicUsize :: new ( 0 ) ,
113
119
}
114
120
}
115
121
@@ -333,9 +339,14 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
333
339
peer. pending_read_is_header = true ;
334
340
335
341
insert_node_id = Some ( peer. their_node_id . unwrap ( ) ) ;
342
+ let mut local_features = msgs:: LocalFeatures :: new ( ) ;
343
+ if self . initial_syncs_sent . load ( Ordering :: Acquire ) < INITIAL_SYNCS_TO_SEND {
344
+ self . initial_syncs_sent . fetch_add ( 1 , Ordering :: AcqRel ) ;
345
+ local_features. set_initial_routing_sync ( ) ;
346
+ }
336
347
encode_and_send_msg ! ( msgs:: Init {
337
348
global_features: msgs:: GlobalFeatures :: new( ) ,
338
- local_features: msgs :: LocalFeatures :: new ( ) ,
349
+ local_features,
339
350
} , 16 ) ;
340
351
} ,
341
352
NextNoiseStep :: ActThree => {
@@ -381,9 +392,14 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
381
392
peer. their_local_features = Some ( msg. local_features ) ;
382
393
383
394
if !peer. outbound {
395
+ let mut local_features = msgs:: LocalFeatures :: new ( ) ;
396
+ if self . initial_syncs_sent . load ( Ordering :: Acquire ) < INITIAL_SYNCS_TO_SEND {
397
+ self . initial_syncs_sent . fetch_add ( 1 , Ordering :: AcqRel ) ;
398
+ local_features. set_initial_routing_sync ( ) ;
399
+ }
384
400
encode_and_send_msg ! ( msgs:: Init {
385
401
global_features: msgs:: GlobalFeatures :: new( ) ,
386
- local_features: msgs :: LocalFeatures :: new ( ) ,
402
+ local_features,
387
403
} , 16 ) ;
388
404
}
389
405
} ,
0 commit comments