File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -7,30 +7,27 @@ use std::{
77
88use crate :: { meta_addr:: MetaAddr , AddressBookPeers , PeerSocketAddr } ;
99
10- const DEFAULT_RTT : Duration = Duration :: from_millis ( 100 ) ;
11-
1210/// A mock [`AddressBookPeers`] implementation that's always empty.
1311#[ derive( Debug , Default , Clone ) ]
1412pub struct MockAddressBookPeers {
1513 /// Return value for mock `recently_live_peers` method.
1614 recently_live_peers : Vec < MetaAddr > ,
17- default_rtt : Duration ,
1815}
1916
2017impl MockAddressBookPeers {
2118 /// Creates a new [`MockAddressBookPeers`]
2219 pub fn new ( recently_live_peers : Vec < MetaAddr > ) -> Self {
2320 Self {
2421 recently_live_peers,
25- default_rtt : DEFAULT_RTT ,
2622 }
2723 }
2824
2925 /// Adds a peer to the mock address book.
3026 pub fn add_peer ( & mut self , peer : PeerSocketAddr ) -> bool {
3127 // The real add peer will use `MetaAddr::new_initial_peer` but we just want to get a `MetaAddr` for the mock.
28+ let rtt = Duration :: from_millis ( 100 ) ;
3229 self . recently_live_peers . push (
33- MetaAddr :: new_responded ( peer, self . default_rtt ) . into_new_meta_addr (
30+ MetaAddr :: new_responded ( peer, rtt ) . into_new_meta_addr (
3431 Instant :: now ( ) ,
3532 chrono:: Utc :: now ( )
3633 . try_into ( )
Original file line number Diff line number Diff line change @@ -192,8 +192,7 @@ pub struct MetaAddr {
192192 /// The last measured round-trip time (RTT) for this peer, if available.
193193 ///
194194 /// This value is updated when the peer responds to a ping (Pong).
195- #[ allow( dead_code) ]
196- pub ( crate ) rtt : Option < Duration > ,
195+ rtt : Option < Duration > ,
197196
198197 /// The last time we tried to open an outbound connection to this peer.
199198 ///
@@ -459,6 +458,13 @@ impl MetaAddr {
459458 self . is_inbound
460459 }
461460
461+ /// Returns the round-trip time (RTT) for this peer, if available,
462+ /// as the number of seconds (f64). This value is updated when the peer
463+ /// responds to a ping (Pong).
464+ pub fn rtt ( & self ) -> Option < f64 > {
465+ self . rtt . map ( |duration| duration. as_secs_f64 ( ) )
466+ }
467+
462468 /// Returns the unverified "last seen time" gossiped by the remote peer that
463469 /// sent us this address.
464470 ///
Original file line number Diff line number Diff line change @@ -2940,7 +2940,8 @@ async fn rpc_addnode() {
29402940 [ PeerInfo {
29412941 addr,
29422942 inbound: false ,
2943- pingtime: None ,
2943+ // TODO: Fix this when mock address book provides other values
2944+ pingtime: Some ( 0.1f64 ) ,
29442945 pingwait: None ,
29452946 } ]
29462947 ) ;
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ impl From<MetaAddr> for PeerInfo {
3232 addr : meta_addr. addr ( ) ,
3333 inbound : meta_addr. is_inbound ( ) ,
3434 // TODO: Fill in pingtime and pingwait once live ping tracking is implemented.
35- pingtime : None ,
35+ pingtime : meta_addr . rtt ( ) ,
3636 pingwait : None ,
3737 }
3838 }
You can’t perform that action at this time.
0 commit comments