@@ -10,8 +10,7 @@ import (
10
10
)
11
11
12
12
type Torrent struct {
13
- // put at first postition to prevent memorty align issues.
14
- Stats torrent.TorrentStats
13
+ sync.Mutex
15
14
16
15
//anacrolix/torrent
17
16
InfoHash string
@@ -24,6 +23,7 @@ type Torrent struct {
24
23
Files []* File
25
24
26
25
//cloud torrent
26
+ Stats * torrent.TorrentStats
27
27
Started bool
28
28
Done bool
29
29
DoneCmdCalled bool
@@ -44,7 +44,6 @@ type Torrent struct {
44
44
e * Engine
45
45
dropWait chan struct {}
46
46
cld Server
47
- sync.Mutex
48
47
}
49
48
50
49
type File struct {
@@ -86,19 +85,19 @@ func (torrent *Torrent) updateOnGotInfo(t *torrent.Torrent) {
86
85
87
86
func (torrent * Torrent ) updateConnStat () {
88
87
lastStat := torrent .Stats
89
- torrent .Stats = torrent .t .Stats ()
88
+ curStat := torrent .t .Stats ()
89
+ now := time .Now ()
90
90
91
91
// calculate ratio
92
- bRead := torrent . Stats .BytesReadUsefulData .Int64 ()
93
- bWrite := torrent . Stats .BytesWrittenData .Int64 ()
92
+ bRead := curStat .BytesReadUsefulData .Int64 ()
93
+ bWrite := curStat .BytesWrittenData .Int64 ()
94
94
if bRead > 0 {
95
95
torrent .SeedRatio = float32 (bWrite ) / float32 (bRead )
96
96
} else if torrent .Done {
97
97
torrent .SeedRatio = float32 (bWrite ) / float32 (torrent .Size )
98
98
}
99
99
100
- now := time .Now ()
101
- if ! torrent .updatedAt .IsZero () {
100
+ if lastStat != nil {
102
101
// calculate rate
103
102
dtinv := float32 (time .Second ) / float32 (now .Sub (torrent .updatedAt ))
104
103
@@ -112,6 +111,7 @@ func (torrent *Torrent) updateConnStat() {
112
111
torrent .Downloaded = torrent .t .BytesCompleted ()
113
112
torrent .Uploaded = bWrite
114
113
torrent .updatedAt = now
114
+ torrent .Stats = & curStat
115
115
}
116
116
117
117
func (torrent * Torrent ) updateFileStatus () {
0 commit comments