@@ -44,11 +44,14 @@ use io;
4444use prelude:: * ;
4545use core:: time:: Duration ;
4646use sync:: { Mutex , Arc } ;
47- use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
47+ use core:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
4848use core:: { cmp, mem} ;
4949use bitcoin:: bech32:: u5;
5050use chain:: keysinterface:: { InMemorySigner , Recipient , KeyMaterial } ;
5151
52+ #[ cfg( feature = "std" ) ]
53+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
54+
5255pub struct TestVecWriter ( pub Vec < u8 > ) ;
5356impl Writer for TestVecWriter {
5457 fn write_all ( & mut self , buf : & [ u8 ] ) -> Result < ( ) , io:: Error > {
@@ -342,6 +345,7 @@ pub struct TestRoutingMessageHandler {
342345 pub chan_upds_recvd : AtomicUsize ,
343346 pub chan_anns_recvd : AtomicUsize ,
344347 pending_events : Mutex < Vec < events:: MessageSendEvent > > ,
348+ pub request_full_sync : AtomicBool ,
345349}
346350
347351impl TestRoutingMessageHandler {
@@ -350,6 +354,7 @@ impl TestRoutingMessageHandler {
350354 chan_upds_recvd : AtomicUsize :: new ( 0 ) ,
351355 chan_anns_recvd : AtomicUsize :: new ( 0 ) ,
352356 pending_events : Mutex :: new ( vec ! [ ] ) ,
357+ request_full_sync : AtomicBool :: new ( false ) ,
353358 }
354359 }
355360}
@@ -384,13 +389,31 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
384389 Vec :: new ( )
385390 }
386391
387- fn peer_connected ( & self , their_node_id : & PublicKey , _init_msg : & msgs:: Init ) {
392+ fn peer_connected ( & self , their_node_id : & PublicKey , init_msg : & msgs:: Init ) {
393+ if !init_msg. features . supports_gossip_queries ( ) {
394+ return ( ) ;
395+ }
396+
397+ let should_request_full_sync = self . request_full_sync . load ( Ordering :: Acquire ) ;
398+
399+ #[ allow( unused_mut, unused_assignments) ]
400+ let mut gossip_start_time = 0 ;
401+ #[ cfg( feature = "std" ) ]
402+ {
403+ gossip_start_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ;
404+ if should_request_full_sync {
405+ gossip_start_time -= 60 * 60 * 24 * 7 * 2 ; // 2 weeks ago
406+ } else {
407+ gossip_start_time -= 60 * 60 ; // an hour ago
408+ }
409+ }
410+
388411 let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
389412 pending_events. push ( events:: MessageSendEvent :: SendGossipTimestampFilter {
390413 node_id : their_node_id. clone ( ) ,
391414 msg : msgs:: GossipTimestampFilter {
392415 chain_hash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) ,
393- first_timestamp : 0 ,
416+ first_timestamp : gossip_start_time as u32 ,
394417 timestamp_range : u32:: max_value ( ) ,
395418 } ,
396419 } ) ;
0 commit comments