Commit 05bc3bd9 authored by Łukasz Magiera's avatar Łukasz Magiera

p2p: simplify remote handler matching

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 228a71ae
...@@ -44,31 +44,19 @@ func newListenersP2P(id peer.ID, host p2phost.Host) *Listeners { ...@@ -44,31 +44,19 @@ func newListenersP2P(id peer.ID, host p2phost.Host) *Listeners {
starting: map[string]struct{}{}, starting: map[string]struct{}{},
} }
addr, err := ma.NewMultiaddr(maPrefix + id.Pretty())
if err != nil {
panic(err)
}
host.SetStreamHandlerMatch("/x/", func(p string) bool { host.SetStreamHandlerMatch("/x/", func(p string) bool {
reg.RLock() reg.RLock()
defer reg.RUnlock() defer reg.RUnlock()
for _, l := range reg.Listeners { _, ok := reg.Listeners[p]
if l.ListenAddress().Equal(addr) && string(l.Protocol()) == p { return ok
return true
}
}
return false
}, func(stream net.Stream) { }, func(stream net.Stream) {
reg.RLock() reg.RLock()
defer reg.RUnlock() defer reg.RUnlock()
for _, l := range reg.Listeners { l := reg.Listeners[string(stream.Protocol())]
if l.ListenAddress().Equal(addr) && l.Protocol() == stream.Protocol() { if l != nil {
go l.(*remoteListener).handleStream(stream) go l.(*remoteListener).handleStream(stream)
return
}
} }
}) })
......
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