mirror of
https://github.com/SinTan1729/privtracker.git
synced 2024-12-26 23:38:37 -06:00
simplified logic
This commit is contained in:
parent
6c907e2840
commit
e3d1d82f5b
1 changed files with 12 additions and 23 deletions
35
storage.go
35
storage.go
|
@ -95,19 +95,8 @@ func GetPeers(room, infoHash string, numWant uint, seeding bool) (peersv4, peers
|
||||||
h := sha1.Sum([]byte(room + infoHash))
|
h := sha1.Sum([]byte(room + infoHash))
|
||||||
shard := shards[shardIndex(h)]
|
shard := shards[shardIndex(h)]
|
||||||
shard.RLock()
|
shard.RLock()
|
||||||
if seeding {
|
// seeders don't need other seeders
|
||||||
for serialized := range shard.swarms[h].leechers {
|
if !seeding {
|
||||||
if numWant == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
|
||||||
peersv4 = append(peersv4, serialized[12:]...)
|
|
||||||
} else {
|
|
||||||
peersv6 = append(peersv6, serialized...)
|
|
||||||
}
|
|
||||||
numWant--
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for serialized := range shard.swarms[h].seeders {
|
for serialized := range shard.swarms[h].seeders {
|
||||||
if numWant == 0 {
|
if numWant == 0 {
|
||||||
break
|
break
|
||||||
|
@ -119,17 +108,17 @@ func GetPeers(room, infoHash string, numWant uint, seeding bool) (peersv4, peers
|
||||||
}
|
}
|
||||||
numWant--
|
numWant--
|
||||||
}
|
}
|
||||||
for serialized := range shard.swarms[h].leechers {
|
}
|
||||||
if numWant == 0 {
|
for serialized := range shard.swarms[h].leechers {
|
||||||
break
|
if numWant == 0 {
|
||||||
}
|
break
|
||||||
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
|
||||||
peersv4 = append(peersv4, serialized[12:]...)
|
|
||||||
} else {
|
|
||||||
peersv6 = append(peersv6, serialized...)
|
|
||||||
}
|
|
||||||
numWant--
|
|
||||||
}
|
}
|
||||||
|
if bytes.HasPrefix([]byte(serialized), v4InV6Prefix) {
|
||||||
|
peersv4 = append(peersv4, serialized[12:]...)
|
||||||
|
} else {
|
||||||
|
peersv6 = append(peersv6, serialized...)
|
||||||
|
}
|
||||||
|
numWant--
|
||||||
}
|
}
|
||||||
numSeeders = len(shard.swarms[h].seeders)
|
numSeeders = len(shard.swarms[h].seeders)
|
||||||
numLeechers = len(shard.swarms[h].leechers)
|
numLeechers = len(shard.swarms[h].leechers)
|
||||||
|
|
Loading…
Reference in a new issue