mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-26 07:18:37 -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
50
storage.go
50
storage.go
|
@ -96,9 +96,40 @@ func GetPeers(room, infoHash string, numWant uint, seeding bool) (peersv4, peers
|
|||
shard := shards[shardIndex(h)]
|
||||
shard.RLock()
|
||||
if seeding {
|
||||
peersv4, peersv6 = getPeersFromSwarm(numWant, shard.swarms[h].leechers)
|
||||
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--
|
||||
}
|
||||
} else {
|
||||
peersv4, peersv6 = getPeersFromSwarm(numWant, shard.swarms[h].seeders)
|
||||
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)
|
||||
|
@ -106,21 +137,6 @@ func GetPeers(room, infoHash string, numWant uint, seeding bool) (peersv4, peers
|
|||
return
|
||||
}
|
||||
|
||||
func getPeersFromSwarm(numWant uint, peers map[serializedPeer]int64) (peersv4, peersv6 []byte) {
|
||||
for serialized := range peers {
|
||||
if numWant == 0 {
|
||||
break
|
||||
}
|
||||
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
||||
peersv4 = append(peersv4, serialized[12:]...)
|
||||
} else {
|
||||
peersv6 = append(peersv6, serialized...)
|
||||
}
|
||||
numWant--
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetStats(room, infoHash string) (numSeeders, numLeechers int) {
|
||||
h := sha1.Sum([]byte(room + infoHash))
|
||||
shard := shards[shardIndex(h)]
|
||||
|
|
Loading…
Reference in a new issue