1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 09:52:20 +08:00

fix(bitswap): release the lock last

The area above the lock was getting big. Moving this up to avoid
mistakes down the road.
This commit is contained in:
Brian Tiger Chow
2015-01-18 23:40:23 -08:00
parent df9e6ce640
commit aa4c0d1b90

View File

@ -160,6 +160,9 @@ func (e *Engine) Peers() []peer.ID {
// MessageReceived performs book-keeping. Returns error if passed invalid
// arguments.
func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
e.lock.Lock()
defer e.lock.Unlock()
log := log.Prefix("bitswap.Engine.MessageReceived(%s)", p)
log.Debugf("enter. %d entries %d blocks", len(m.Wantlist()), len(m.Blocks()))
defer log.Debugf("exit")
@ -175,9 +178,6 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
}
}()
e.lock.Lock()
defer e.lock.Unlock()
l := e.findOrCreate(p)
if m.Full() {
l.wantList = wl.New()