peers rename

This commit is contained in:
Michał Adamski 2020-12-08 14:29:56 +01:00
parent b900c2862f
commit 1fafa13c95
2 changed files with 8 additions and 8 deletions

View file

@ -57,7 +57,7 @@ func announce(c *gin.Context) {
default:
PutPeer(c.Param("room"), req.InfoHash, req.IP, req.Port, req.IsSeeding())
}
peersv4, peersv6, numSeeders, numLeechers := GetPeers(c.Param("room"), req.InfoHash, req.IP, req.Port, req.IsSeeding(), req.Numwant)
peersIPv4, peersIPv6, numSeeders, numLeechers := GetPeers(c.Param("room"), req.InfoHash, req.IP, req.Port, req.IsSeeding(), req.Numwant)
interval := 120
if numSeeders == 0 {
interval /= 2
@ -68,8 +68,8 @@ func announce(c *gin.Context) {
Interval: interval,
Complete: numSeeders,
Incomplete: numLeechers,
Peers: string(peersv4),
PeersIPv6: string(peersv6),
Peers: string(peersIPv4),
PeersIPv6: string(peersIPv6),
}
if err := bencode.Marshal(c.Writer, resp); err != nil {
c.Error(err)

View file

@ -91,7 +91,7 @@ func GraduateLeecher(room, infoHash, ip string, port uint16) {
shard.Unlock()
}
func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint) (peersv4, peersv6 []byte, numSeeders, numLeechers int) {
func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint) (peersIPv4, peersIPv6 []byte, numSeeders, numLeechers int) {
h := sha1.Sum([]byte(room + infoHash))
shard := shards[shardIndex(h)]
shard.RLock()
@ -103,9 +103,9 @@ func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint
break
}
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
peersv4 = append(peersv4, peer[12:]...)
peersIPv4 = append(peersIPv4, peer[12:]...)
} else {
peersv6 = append(peersv6, peer...)
peersIPv6 = append(peersIPv6, peer...)
}
numWant--
}
@ -118,9 +118,9 @@ func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint
break
}
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
peersv4 = append(peersv4, peer[12:]...)
peersIPv4 = append(peersIPv4, peer[12:]...)
} else {
peersv6 = append(peersv6, peer...)
peersIPv6 = append(peersIPv6, peer...)
}
numWant--
}