forked from cenkalti/rain
/
announce.go
37 lines (33 loc) 路 919 Bytes
/
announce.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package torrent
import (
"math"
"sync/atomic"
"github.com/cenkalti/rain/internal/tracker"
)
func (t *torrent) handleNewTrackers(trackers []tracker.Tracker) {
t.trackers = append(t.trackers, trackers...)
status := t.status()
if status != Stopping && status != Stopped {
for _, tr := range trackers {
t.startNewAnnouncer(tr)
}
}
}
func (t *torrent) announcerFields() tracker.Torrent {
tr := tracker.Torrent{
InfoHash: t.infoHash,
PeerID: t.peerID,
Port: t.port,
BytesDownloaded: atomic.LoadInt64(&t.resumerStats.BytesDownloaded),
BytesUploaded: atomic.LoadInt64(&t.resumerStats.BytesUploaded),
}
t.mBitfield.RLock()
if t.bitfield == nil {
// Some trackers don't send any peer address if don't tell we have missing bytes.
tr.BytesLeft = math.MaxUint32
} else {
tr.BytesLeft = t.info.TotalLength - t.bytesComplete()
}
t.mBitfield.RUnlock()
return tr
}