mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 22:38:27 +08:00
p2p: hold lock when handling new streams
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -50,6 +50,7 @@ func newListenerRegistry(id peer.ID, host p2phost.Host) *ListenerRegistry {
|
||||
host.SetStreamHandlerMatch("/x/", func(p string) bool {
|
||||
reg.RLock()
|
||||
defer reg.RUnlock()
|
||||
|
||||
for _, l := range reg.Listeners {
|
||||
if l.ListenAddress().Equal(addr) && string(l.Protocol()) == p {
|
||||
return true
|
||||
@ -58,13 +59,15 @@ func newListenerRegistry(id peer.ID, host p2phost.Host) *ListenerRegistry {
|
||||
|
||||
return false
|
||||
}, func(stream net.Stream) {
|
||||
reg.RLock()
|
||||
defer reg.RUnlock()
|
||||
|
||||
for _, l := range reg.Listeners {
|
||||
if l.ListenAddress().Equal(addr) && l.Protocol() == stream.Protocol() {
|
||||
l.(*remoteListener).handleStream(stream)
|
||||
go l.(*remoteListener).handleStream(stream)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// panic?
|
||||
})
|
||||
|
||||
return reg
|
||||
|
Reference in New Issue
Block a user