Add a comment explaining why Peer.IP is unambiguous

This commit is contained in:
Justin Li 2014-08-01 12:50:24 -04:00
parent b628b934ac
commit bfd8e110ea
2 changed files with 9 additions and 8 deletions

View file

@ -54,37 +54,37 @@ func (tkr *Tracker) HandleAnnounce(ann *models.Announce, w Writer) error {
return err
}
var createdIPv4, createdIPv6, snatchedIPv4, snatchedIPv6 bool
var createdv4, createdv6, snatchedv4, snatchedv6 bool
peer, peerv4, peerv6 := models.NewPeer(ann, user, torrent)
if peerv4 != nil {
createdIPv4, err = updateSwarm(conn, ann, peerv4, torrent)
createdv4, err = updateSwarm(conn, ann, peerv4, torrent)
if err != nil {
return err
}
}
if peerv6 != nil {
createdIPv6, err = updateSwarm(conn, ann, peerv6, torrent)
createdv6, err = updateSwarm(conn, ann, peerv6, torrent)
if err != nil {
return err
}
}
if peerv4 != nil {
snatchedIPv4, err = handleEvent(conn, ann, peerv4, user, torrent)
snatchedv4, err = handleEvent(conn, ann, peerv4, user, torrent)
if err != nil {
return err
}
}
if peerv6 != nil {
snatchedIPv6, err = handleEvent(conn, ann, peerv6, user, torrent)
snatchedv6, err = handleEvent(conn, ann, peerv6, user, torrent)
if err != nil {
return err
}
}
created := createdIPv4 || createdIPv6
snatched := snatchedIPv4 || snatchedIPv6
created := createdv4 || createdv6
snatched := snatchedv4 || snatchedv6
if tkr.cfg.PrivateEnabled {
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.
_, v4seed := t.Seeders[models.NewPeerKey(p.ID, false)]
_, v6seed := t.Seeders[models.NewPeerKey(p.ID, true)]
if !(v4seed || v6seed) {
snatched = true
}

View file

@ -46,7 +46,7 @@ type Peer struct {
UserID uint64 `json:"user_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"`
Uploaded uint64 `json:"uploaded"`