various small fixes
This commit is contained in:
parent
b1f186b665
commit
3b54069a1b
4 changed files with 11 additions and 6 deletions
|
@ -24,7 +24,7 @@ type AnnounceRequest struct {
|
|||
Port uint16
|
||||
|
||||
Compact bool
|
||||
NumWant uint64
|
||||
NumWant int32
|
||||
|
||||
Left, Downloaded, Uploaded uint64
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest
|
|||
return nil, errors.NewBadRequest("failed to parse parameter: uploaded")
|
||||
}
|
||||
|
||||
request.NumWant, _ = q.Uint64("numwant")
|
||||
numwant, _ := q.Uint64("numwant")
|
||||
request.NumWant = int32(numwant)
|
||||
|
||||
port, err := q.Uint64("port")
|
||||
if err != nil {
|
||||
|
|
|
@ -41,8 +41,8 @@ func (s *clientStore) CreateClient(clientID string) error {
|
|||
|
||||
func (s *clientStore) FindClient(peerID string) (bool, error) {
|
||||
clientID := clientid.New(peerID)
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
|
||||
_, ok := s.clientIDs[clientID]
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ func (s *peerStore) DeleteSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) erro
|
|||
delete(shard.peers[key], peerKey(p))
|
||||
|
||||
if len(shard.peers[key]) == 0 {
|
||||
shard.peers[key] = nil
|
||||
delete(shard.peers, key)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -158,7 +158,7 @@ func (s *peerStore) DeleteLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) err
|
|||
delete(shard.peers[key], peerKey(p))
|
||||
|
||||
if len(shard.peers[key]) == 0 {
|
||||
shard.peers[key] = nil
|
||||
delete(shard.peers, key)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -207,6 +207,10 @@ func (s *peerStore) CollectGarbage(cutoff time.Time) error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(shard.peers[key] == 0) {
|
||||
delete(shard.peers, key)
|
||||
}
|
||||
|
||||
shard.Unlock()
|
||||
runtime.Gosched()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue