various small fixes

This commit is contained in:
Leo Balduf 2016-02-19 14:15:40 +01:00 committed by Jimmy Zelinskie
parent b1f186b665
commit 3b54069a1b
4 changed files with 11 additions and 6 deletions

View file

@ -24,7 +24,7 @@ type AnnounceRequest struct {
Port uint16 Port uint16
Compact bool Compact bool
NumWant uint64 NumWant int32
Left, Downloaded, Uploaded uint64 Left, Downloaded, Uploaded uint64

View file

@ -64,7 +64,8 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest
return nil, errors.NewBadRequest("failed to parse parameter: uploaded") 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") port, err := q.Uint64("port")
if err != nil { if err != nil {

View file

@ -41,8 +41,8 @@ func (s *clientStore) CreateClient(clientID string) error {
func (s *clientStore) FindClient(peerID string) (bool, error) { func (s *clientStore) FindClient(peerID string) (bool, error) {
clientID := clientid.New(peerID) clientID := clientid.New(peerID)
s.Lock() s.RLock()
defer s.Unlock() defer s.RUnlock()
_, ok := s.clientIDs[clientID] _, ok := s.clientIDs[clientID]

View file

@ -119,7 +119,7 @@ func (s *peerStore) DeleteSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) erro
delete(shard.peers[key], peerKey(p)) delete(shard.peers[key], peerKey(p))
if len(shard.peers[key]) == 0 { if len(shard.peers[key]) == 0 {
shard.peers[key] = nil delete(shard.peers, key)
} }
return nil return nil
@ -158,7 +158,7 @@ func (s *peerStore) DeleteLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) err
delete(shard.peers[key], peerKey(p)) delete(shard.peers[key], peerKey(p))
if len(shard.peers[key]) == 0 { if len(shard.peers[key]) == 0 {
shard.peers[key] = nil delete(shard.peers, key)
} }
return nil 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() shard.Unlock()
runtime.Gosched() runtime.Gosched()
} }