@@ -31,6 +31,7 @@ type P2p interface {
3131 NewStreamWithDedicatedConn (ctx context.Context , id peer.ID , proto libp2pProtocol.ID ) (network.Stream , error )
3232 SubscribeConnectionEvents (onConnected , onDisconnected func (network.Network , network.Conn ))
3333 ProtectPeer (id peer.ID )
34+ RecordPeerLatency (id peer.ID , rtt time.Duration )
3435}
3536
3637type AuthStatus struct {
@@ -125,6 +126,7 @@ func (s *AuthStatus) ExchangeNewStatusInfo(ctx context.Context, remotePeerID pee
125126
126127 _ , isBlocked := s .conf .GetBlockedPeer (remotePeerID .String ())
127128 myPeerInfo := s .createPeerInfo (knownPeer , s .conf .P2pNode .Name , isBlocked )
129+ timeStarted := time .Now ()
128130 err = protocol .SendStatus (stream , myPeerInfo )
129131 if err != nil {
130132 return fmt .Errorf ("sending status info: %v" , err )
@@ -134,6 +136,7 @@ func (s *AuthStatus) ExchangeNewStatusInfo(ctx context.Context, remotePeerID pee
134136 if err != nil {
135137 return fmt .Errorf ("receiving status info: %v" , err )
136138 }
139+ s .p2p .RecordPeerLatency (remotePeerID , time .Since (timeStarted ))
137140
138141 s .logger .Infof ("successfully exchanged status info (outbound) with %s (%s)" , knownPeer .DisplayName (), remotePeerID .String ())
139142 if isBlocked {
@@ -270,6 +273,7 @@ func (s *AuthStatus) SendAuthRequest(ctx context.Context, peerID peer.ID, req pr
270273 _ = stream .Close ()
271274 }()
272275
276+ timeStarted := time .Now ()
273277 err = protocol .SendAuth (stream , req )
274278 if err != nil {
275279 return fmt .Errorf ("sending auth: %v" , err )
@@ -279,6 +283,7 @@ func (s *AuthStatus) SendAuthRequest(ctx context.Context, peerID peer.ID, req pr
279283 if err != nil {
280284 return fmt .Errorf ("receiving auth response from %s: %v" , peerID , err )
281285 }
286+ s .p2p .RecordPeerLatency (peerID , time .Since (timeStarted ))
282287
283288 if authResponse .Confirmed || authResponse .Declined {
284289 s .authsLock .Lock ()
0 commit comments