mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-27 15:58:35 -06:00
share leechers with leechers, why not
This commit is contained in:
parent
9e7f58b987
commit
42b408b5a3
1 changed files with 33 additions and 17 deletions
40
storage.go
40
storage.go
|
@ -96,18 +96,7 @@ func GetPeers(room, infoHash string, numWant uint, seeding bool) (peersv4, peers
|
||||||
shard := shards[shardIndex(h)]
|
shard := shards[shardIndex(h)]
|
||||||
shard.RLock()
|
shard.RLock()
|
||||||
if seeding {
|
if seeding {
|
||||||
peersv4, peersv6 = getPeersFromSwarm(numWant, shard.swarms[h].leechers)
|
for serialized := range shard.swarms[h].leechers {
|
||||||
} else {
|
|
||||||
peersv4, peersv6 = getPeersFromSwarm(numWant, shard.swarms[h].seeders)
|
|
||||||
}
|
|
||||||
numSeeders = len(shard.swarms[h].seeders)
|
|
||||||
numLeechers = len(shard.swarms[h].leechers)
|
|
||||||
shard.RUnlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPeersFromSwarm(numWant uint, peers map[serializedPeer]int64) (peersv4, peersv6 []byte) {
|
|
||||||
for serialized := range peers {
|
|
||||||
if numWant == 0 {
|
if numWant == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -118,6 +107,33 @@ func getPeersFromSwarm(numWant uint, peers map[serializedPeer]int64) (peersv4, p
|
||||||
}
|
}
|
||||||
numWant--
|
numWant--
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for serialized := range shard.swarms[h].seeders {
|
||||||
|
if numWant == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
||||||
|
peersv4 = append(peersv4, serialized[12:]...)
|
||||||
|
} else {
|
||||||
|
peersv6 = append(peersv6, serialized...)
|
||||||
|
}
|
||||||
|
numWant--
|
||||||
|
}
|
||||||
|
for serialized := range shard.swarms[h].leechers {
|
||||||
|
if numWant == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
||||||
|
peersv4 = append(peersv4, serialized[12:]...)
|
||||||
|
} else {
|
||||||
|
peersv6 = append(peersv6, serialized...)
|
||||||
|
}
|
||||||
|
numWant--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numSeeders = len(shard.swarms[h].seeders)
|
||||||
|
numLeechers = len(shard.swarms[h].leechers)
|
||||||
|
shard.RUnlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue