diff --git a/example_config.yaml b/example_config.yaml index 3f89637..182591f 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -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 diff --git a/storage/memory/peer_store.go b/storage/memory/peer_store.go index 3f7f9c2..ab18273 100644 --- a/storage/memory/peer_store.go +++ b/storage/memory/peer_store.go @@ -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()