@@ -10,8 +10,7 @@ import (
1010)
1111
1212type Torrent struct {
13- // put at first postition to prevent memorty align issues.
14- Stats torrent.TorrentStats
13+ sync.Mutex
1514
1615 //anacrolix/torrent
1716 InfoHash string
@@ -24,6 +23,7 @@ type Torrent struct {
2423 Files []* File
2524
2625 //cloud torrent
26+ Stats * torrent.TorrentStats
2727 Started bool
2828 Done bool
2929 DoneCmdCalled bool
@@ -44,7 +44,6 @@ type Torrent struct {
4444 e * Engine
4545 dropWait chan struct {}
4646 cld Server
47- sync.Mutex
4847}
4948
5049type File struct {
@@ -86,19 +85,19 @@ func (torrent *Torrent) updateOnGotInfo(t *torrent.Torrent) {
8685
8786func (torrent * Torrent ) updateConnStat () {
8887 lastStat := torrent .Stats
89- torrent .Stats = torrent .t .Stats ()
88+ curStat := torrent .t .Stats ()
89+ now := time .Now ()
9090
9191 // calculate ratio
92- bRead := torrent . Stats .BytesReadUsefulData .Int64 ()
93- bWrite := torrent . Stats .BytesWrittenData .Int64 ()
92+ bRead := curStat .BytesReadUsefulData .Int64 ()
93+ bWrite := curStat .BytesWrittenData .Int64 ()
9494 if bRead > 0 {
9595 torrent .SeedRatio = float32 (bWrite ) / float32 (bRead )
9696 } else if torrent .Done {
9797 torrent .SeedRatio = float32 (bWrite ) / float32 (torrent .Size )
9898 }
9999
100- now := time .Now ()
101- if ! torrent .updatedAt .IsZero () {
100+ if lastStat != nil {
102101 // calculate rate
103102 dtinv := float32 (time .Second ) / float32 (now .Sub (torrent .updatedAt ))
104103
@@ -112,6 +111,7 @@ func (torrent *Torrent) updateConnStat() {
112111 torrent .Downloaded = torrent .t .BytesCompleted ()
113112 torrent .Uploaded = bWrite
114113 torrent .updatedAt = now
114+ torrent .Stats = & curStat
115115}
116116
117117func (torrent * Torrent ) updateFileStatus () {
0 commit comments