From ed1fe91dd2d11213afdb6c8ab49b3e4a12fa41e2 Mon Sep 17 00:00:00 2001 From: Nathanael Demacon Date: Mon, 23 May 2022 02:42:51 +0200 Subject: [PATCH] Implement a public `Peer.DownloadRate` (#750) --- peerconn.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/peerconn.go b/peerconn.go index 554da65f..4597ea47 100644 --- a/peerconn.go +++ b/peerconn.go @@ -351,6 +351,13 @@ func (cn *Peer) downloadRate() float64 { return float64(num) / cn.totalExpectingTime().Seconds() } +func (cn *Peer) DownloadRate() float64 { + cn.locker().Lock() + defer cn.locker().Unlock() + + return cn.downloadRate() +} + func (cn *Peer) iterContiguousPieceRequests(f func(piece pieceIndex, count int)) { var last Option[pieceIndex] var count int