Add a comment explaining why Peer.IP is unambiguous
This commit is contained in:
parent
b628b934ac
commit
bfd8e110ea
2 changed files with 9 additions and 8 deletions
|
@ -54,37 +54,37 @@ func (tkr *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var createdIPv4, createdIPv6, snatchedIPv4, snatchedIPv6 bool
|
var createdv4, createdv6, snatchedv4, snatchedv6 bool
|
||||||
peer, peerv4, peerv6 := models.NewPeer(ann, user, torrent)
|
peer, peerv4, peerv6 := models.NewPeer(ann, user, torrent)
|
||||||
|
|
||||||
if peerv4 != nil {
|
if peerv4 != nil {
|
||||||
createdIPv4, err = updateSwarm(conn, ann, peerv4, torrent)
|
createdv4, err = updateSwarm(conn, ann, peerv4, torrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if peerv6 != nil {
|
if peerv6 != nil {
|
||||||
createdIPv6, err = updateSwarm(conn, ann, peerv6, torrent)
|
createdv6, err = updateSwarm(conn, ann, peerv6, torrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if peerv4 != nil {
|
if peerv4 != nil {
|
||||||
snatchedIPv4, err = handleEvent(conn, ann, peerv4, user, torrent)
|
snatchedv4, err = handleEvent(conn, ann, peerv4, user, torrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if peerv6 != nil {
|
if peerv6 != nil {
|
||||||
snatchedIPv6, err = handleEvent(conn, ann, peerv6, user, torrent)
|
snatchedv6, err = handleEvent(conn, ann, peerv6, user, torrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
created := createdIPv4 || createdIPv6
|
created := createdv4 || createdv6
|
||||||
snatched := snatchedIPv4 || snatchedIPv6
|
snatched := snatchedv4 || snatchedv6
|
||||||
|
|
||||||
if tkr.cfg.PrivateEnabled {
|
if tkr.cfg.PrivateEnabled {
|
||||||
delta := models.NewAnnounceDelta(ann, peer, user, torrent, created, snatched)
|
delta := models.NewAnnounceDelta(ann, peer, user, torrent, created, snatched)
|
||||||
|
@ -198,6 +198,7 @@ func handleEvent(c Conn, ann *models.Announce, p *models.Peer, u *models.User, t
|
||||||
// snatched.
|
// snatched.
|
||||||
_, v4seed := t.Seeders[models.NewPeerKey(p.ID, false)]
|
_, v4seed := t.Seeders[models.NewPeerKey(p.ID, false)]
|
||||||
_, v6seed := t.Seeders[models.NewPeerKey(p.ID, true)]
|
_, v6seed := t.Seeders[models.NewPeerKey(p.ID, true)]
|
||||||
|
|
||||||
if !(v4seed || v6seed) {
|
if !(v4seed || v6seed) {
|
||||||
snatched = true
|
snatched = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ type Peer struct {
|
||||||
UserID uint64 `json:"user_id"`
|
UserID uint64 `json:"user_id"`
|
||||||
TorrentID uint64 `json:"torrent_id"`
|
TorrentID uint64 `json:"torrent_id"`
|
||||||
|
|
||||||
IP net.IP `json:"ip,omitempty"`
|
IP net.IP `json:"ip,omitempty"` // Always has length net.IPv4len if IPv4, and net.IPv6len if IPv6
|
||||||
Port uint64 `json:"port"`
|
Port uint64 `json:"port"`
|
||||||
|
|
||||||
Uploaded uint64 `json:"uploaded"`
|
Uploaded uint64 `json:"uploaded"`
|
||||||
|
|
Loading…
Reference in a new issue