FilesDir = "files"
)
+type TorrentStat struct {
+ stats torrent.ConnStats
+ rxSpeed int64
+ txSpeed int64
+}
+
var (
- TorrentStats = map[metainfo.Hash]torrent.TorrentStats{}
+ TorrentStats = map[metainfo.Hash]TorrentStat{}
TorrentStatsM sync.RWMutex
)
TorrentStatsM.RLock()
prev := TorrentStats[t.InfoHash()]
TorrentStatsM.RUnlock()
- rxSpeed := stats.BytesReadData.Int64() - prev.BytesReadData.Int64()
- txSpeed := stats.BytesWrittenData.Int64() - prev.BytesWrittenData.Int64()
var eta string
- if done < 100 && rxSpeed > 0 {
- etaRaw := time.Duration((t.Length() - t.BytesCompleted()) / rxSpeed)
+ if done < 100 && prev.rxSpeed > 0 {
+ etaRaw := time.Duration((t.Length() - t.BytesCompleted()) / prev.rxSpeed)
etaRaw *= time.Second
eta = etaRaw.String()
}
humanize.IBytes(uint64(t.Length())),
percColour, done, Reset,
ratio,
- Green, rxSpeed/1024, Reset,
- Magenta, txSpeed/1024, Reset,
+ Green, prev.rxSpeed/1024, Reset,
+ Magenta, prev.txSpeed/1024, Reset,
stats.TotalPeers,
stats.PendingPeers,
stats.ActivePeers,
continue
}
tStats := t.Stats()
+ cur := tStats.Copy()
TorrentStatsM.Lock()
- TorrentStats[t.InfoHash()] = tStats
+ prev := TorrentStats[t.InfoHash()].stats
+ TorrentStats[t.InfoHash()] = TorrentStat{
+ stats: cur,
+ rxSpeed: cur.BytesReadData.Int64() - prev.BytesReadData.Int64(),
+ txSpeed: cur.BytesWrittenData.Int64() - prev.BytesWrittenData.Int64(),
+ }
TorrentStatsM.Unlock()
peers += tStats.ActivePeers
}