Commit 4db3e96d authored by Brian Tiger Chow's avatar Brian Tiger Chow

fix(bitswap): release the lock last

The area above the lock was getting big. Moving this up to avoid
mistakes down the road.
parent 02c7adcf
...@@ -160,6 +160,9 @@ func (e *Engine) Peers() []peer.ID { ...@@ -160,6 +160,9 @@ func (e *Engine) Peers() []peer.ID {
// MessageReceived performs book-keeping. Returns error if passed invalid // MessageReceived performs book-keeping. Returns error if passed invalid
// arguments. // arguments.
func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error { 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 := log.Prefix("bitswap.Engine.MessageReceived(%s)", p)
log.Debugf("enter. %d entries %d blocks", len(m.Wantlist()), len(m.Blocks())) log.Debugf("enter. %d entries %d blocks", len(m.Wantlist()), len(m.Blocks()))
defer log.Debugf("exit") defer log.Debugf("exit")
...@@ -175,9 +178,6 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error { ...@@ -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) l := e.findOrCreate(p)
if m.Full() { if m.Full() {
l.wantList = wl.New() l.wantList = wl.New()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment