memory: add max numwant
This commit is contained in:
parent
6fddcb8eea
commit
a553ded043
2 changed files with 15 additions and 11 deletions
|
@ -15,11 +15,10 @@ trakr:
|
|||
allow_ip_spoofing: false
|
||||
|
||||
storage:
|
||||
name: memory
|
||||
config:
|
||||
shards: 1
|
||||
gc_interval: 14m
|
||||
peer_lifetime: 15m
|
||||
gc_interval: 14m
|
||||
peer_lifetime: 15m
|
||||
shards: 1
|
||||
max_numwant: 100
|
||||
|
||||
prehooks:
|
||||
- name: jwt
|
||||
|
|
|
@ -12,13 +12,12 @@ import (
|
|||
"github.com/jzelinskie/trakr/storage"
|
||||
)
|
||||
|
||||
// TODO(jzelinskie): separate ipv4 and ipv6 swarms
|
||||
|
||||
// Config holds the configuration of a memory PeerStore.
|
||||
type Config struct {
|
||||
GarbageCollectionInterval time.Duration `yaml:"gc_interval"`
|
||||
PeerLifetime time.Duration `yaml:"peer_lifetime"`
|
||||
ShardCount int `yaml:"shard_count"`
|
||||
MaxNumWant int `yaml:"max_numwant"`
|
||||
}
|
||||
|
||||
// New creates a new PeerStore backed by memory.
|
||||
|
@ -29,8 +28,9 @@ func New(cfg Config) (storage.PeerStore, error) {
|
|||
}
|
||||
|
||||
ps := &peerStore{
|
||||
shards: make([]*peerShard, shardCount*2),
|
||||
closed: make(chan struct{}),
|
||||
shards: make([]*peerShard, shardCount*2),
|
||||
closed: make(chan struct{}),
|
||||
maxNumWant: cfg.MaxNumWant,
|
||||
}
|
||||
|
||||
for i := 0; i < shardCount*2; i++ {
|
||||
|
@ -67,8 +67,9 @@ type swarm struct {
|
|||
}
|
||||
|
||||
type peerStore struct {
|
||||
shards []*peerShard
|
||||
closed chan struct{}
|
||||
shards []*peerShard
|
||||
closed chan struct{}
|
||||
maxNumWant int
|
||||
}
|
||||
|
||||
var _ storage.PeerStore = &peerStore{}
|
||||
|
@ -246,6 +247,10 @@ func (s *peerStore) AnnouncePeers(ih bittorrent.InfoHash, seeder bool, numWant i
|
|||
default:
|
||||
}
|
||||
|
||||
if numWant > s.maxNumWant {
|
||||
numWant = s.maxNumWant
|
||||
}
|
||||
|
||||
shard := s.shards[s.shardIndex(ih, announcer)]
|
||||
shard.RLock()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue