Skip to content

Commit

Permalink
Merge pull request #31 from libp2p/fix/hash-under-lock
Browse files Browse the repository at this point in the history
fix: avoid hashing under a lock
  • Loading branch information
Stebalien committed May 24, 2019
2 parents 509f053 + a3a726c commit 163fb2a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ func (rt *RoutingTable) Update(p peer.ID) (evicted peer.ID, err error) {
// Remove deletes a peer from the routing table. This is to be used
// when we are sure a node has disconnected completely.
func (rt *RoutingTable) Remove(p peer.ID) {
rt.tabLock.Lock()
defer rt.tabLock.Unlock()
peerID := ConvertPeerID(p)
cpl := CommonPrefixLen(peerID, rt.local)

rt.tabLock.Lock()
defer rt.tabLock.Unlock()

bucketID := cpl
if bucketID >= len(rt.Buckets) {
bucketID = len(rt.Buckets) - 1
Expand Down

0 comments on commit 163fb2a

Please sign in to comment.