From 3b54069a1b73a20fb6d820fbb2568cfb6021aceb Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Fri, 19 Feb 2016 14:15:40 +0100 Subject: [PATCH] various small fixes --- chihaya.go | 2 +- server/http/request.go | 3 ++- server/store/memory/client_store.go | 4 ++-- server/store/memory/peer_store.go | 8 ++++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/chihaya.go b/chihaya.go index 7b25e0a..7daba32 100644 --- a/chihaya.go +++ b/chihaya.go @@ -24,7 +24,7 @@ type AnnounceRequest struct { Port uint16 Compact bool - NumWant uint64 + NumWant int32 Left, Downloaded, Uploaded uint64 diff --git a/server/http/request.go b/server/http/request.go index d5cb131..7320c9b 100644 --- a/server/http/request.go +++ b/server/http/request.go @@ -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 { diff --git a/server/store/memory/client_store.go b/server/store/memory/client_store.go index ac1e3e3..b0342fd 100644 --- a/server/store/memory/client_store.go +++ b/server/store/memory/client_store.go @@ -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] diff --git a/server/store/memory/peer_store.go b/server/store/memory/peer_store.go index 465b8e6..28e8f26 100644 --- a/server/store/memory/peer_store.go +++ b/server/store/memory/peer_store.go @@ -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() }