mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-26 23:38:37 -06:00
peers rename
This commit is contained in:
parent
b900c2862f
commit
1fafa13c95
2 changed files with 8 additions and 8 deletions
6
main.go
6
main.go
|
@ -57,7 +57,7 @@ func announce(c *gin.Context) {
|
||||||
default:
|
default:
|
||||||
PutPeer(c.Param("room"), req.InfoHash, req.IP, req.Port, req.IsSeeding())
|
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
|
interval := 120
|
||||||
if numSeeders == 0 {
|
if numSeeders == 0 {
|
||||||
interval /= 2
|
interval /= 2
|
||||||
|
@ -68,8 +68,8 @@ func announce(c *gin.Context) {
|
||||||
Interval: interval,
|
Interval: interval,
|
||||||
Complete: numSeeders,
|
Complete: numSeeders,
|
||||||
Incomplete: numLeechers,
|
Incomplete: numLeechers,
|
||||||
Peers: string(peersv4),
|
Peers: string(peersIPv4),
|
||||||
PeersIPv6: string(peersv6),
|
PeersIPv6: string(peersIPv6),
|
||||||
}
|
}
|
||||||
if err := bencode.Marshal(c.Writer, resp); err != nil {
|
if err := bencode.Marshal(c.Writer, resp); err != nil {
|
||||||
c.Error(err)
|
c.Error(err)
|
||||||
|
|
10
storage.go
10
storage.go
|
@ -91,7 +91,7 @@ func GraduateLeecher(room, infoHash, ip string, port uint16) {
|
||||||
shard.Unlock()
|
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))
|
h := sha1.Sum([]byte(room + infoHash))
|
||||||
shard := shards[shardIndex(h)]
|
shard := shards[shardIndex(h)]
|
||||||
shard.RLock()
|
shard.RLock()
|
||||||
|
@ -103,9 +103,9 @@ func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
|
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
|
||||||
peersv4 = append(peersv4, peer[12:]...)
|
peersIPv4 = append(peersIPv4, peer[12:]...)
|
||||||
} else {
|
} else {
|
||||||
peersv6 = append(peersv6, peer...)
|
peersIPv6 = append(peersIPv6, peer...)
|
||||||
}
|
}
|
||||||
numWant--
|
numWant--
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,9 @@ func GetPeers(room, infoHash, ip string, port uint16, seeding bool, numWant uint
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
|
if bytes.HasPrefix([]byte(peer), v4InV6Prefix) {
|
||||||
peersv4 = append(peersv4, peer[12:]...)
|
peersIPv4 = append(peersIPv4, peer[12:]...)
|
||||||
} else {
|
} else {
|
||||||
peersv6 = append(peersv6, peer...)
|
peersIPv6 = append(peersIPv6, peer...)
|
||||||
}
|
}
|
||||||
numWant--
|
numWant--
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue