diff --git a/examples/chat2/go.sum b/examples/chat2/go.sum index 6650a38b..4f18125b 100644 --- a/examples/chat2/go.sum +++ b/examples/chat2/go.sum @@ -950,6 +950,8 @@ github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5 h1 github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f h1:/KXMnxtAe0ZrbErvgZPkKilpLCmd7g1CIKQ4x17Al5I= github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4 h1:LaoaRVhtEu5kCzcEVn+l3sprDbTqpzWFsVT2lmAcHcA= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw= github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU= diff --git a/go.mod b/go.mod index 27eb9f81..eac605c1 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/spf13/cobra v1.1.3 github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/viper v1.7.1 - github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f + github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4 go.opencensus.io v0.23.0 gopkg.in/ini.v1 v1.62.0 // indirect ) diff --git a/go.sum b/go.sum index 17d0d049..8dc7454d 100644 --- a/go.sum +++ b/go.sum @@ -838,6 +838,10 @@ github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5 h1 github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f h1:/KXMnxtAe0ZrbErvgZPkKilpLCmd7g1CIKQ4x17Al5I= github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721190623-e23032977d88 h1:z8s92pjvJVGL+LonCwyHZNs5YuMpTMFn2Svhu7r81x4= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721190623-e23032977d88/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4 h1:LaoaRVhtEu5kCzcEVn+l3sprDbTqpzWFsVT2lmAcHcA= +github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE= github.com/status-im/status-go/extkeys v1.0.0/go.mod h1:GdqJbrcpkNm5ZsSCpp+PdMxnXx+OcRBdm3PI0rs1FpU= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= diff --git a/waku/v2/protocol/filter/waku_filter.go b/waku/v2/protocol/filter/waku_filter.go index 85af5c38..95c6481a 100644 --- a/waku/v2/protocol/filter/waku_filter.go +++ b/waku/v2/protocol/filter/waku_filter.go @@ -199,7 +199,7 @@ func NewWakuFilter(ctx context.Context, host host.Host, handler MessagePushHandl wf.pushHandler = handler wf.peerChan = peerChan - wf.h.SetStreamHandler(WakuFilterProtocolId, wf.onRequest) + wf.h.SetStreamHandlerMatch(WakuFilterProtocolId, protocol.PrefixTextMatch(WakuFilterCodec), wf.onRequest) go wf.FilterListener() go wf.peerListener() diff --git a/waku/v2/protocol/lightpush/waku_lightpush.go b/waku/v2/protocol/lightpush/waku_lightpush.go index 34103db9..83d1719a 100644 --- a/waku/v2/protocol/lightpush/waku_lightpush.go +++ b/waku/v2/protocol/lightpush/waku_lightpush.go @@ -20,7 +20,8 @@ import ( var log = logging.Logger("waku_lightpush") -const WakuLightPushProtocolId = libp2pProtocol.ID("/vac/waku/lightpush/2.0.0-beta1") +const WakuLightPushCodec = "/vac/waku/lightpush/2.0.0-beta1" +const WakuLightPushProtocolId = libp2pProtocol.ID(WakuLightPushCodec) var ( ErrNoPeersAvailable = errors.New("no suitable remote peers") @@ -39,7 +40,7 @@ func NewWakuLightPush(ctx context.Context, h host.Host, relay *relay.WakuRelay) wakuLP.ctx = ctx wakuLP.h = h - wakuLP.h.SetStreamHandler(WakuLightPushProtocolId, wakuLP.onRequest) + wakuLP.h.SetStreamHandlerMatch(WakuLightPushProtocolId, protocol.PrefixTextMatch(WakuLightPushCodec), wakuLP.onRequest) log.Info("Light Push protocol started") return wakuLP diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index 210465b0..76d9f8c5 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -9,6 +9,7 @@ import ( logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p-core/host" + "github.com/status-im/go-waku/waku/v2/protocol" "github.com/status-im/go-waku/waku/v2/protocol/pb" wakurelay "github.com/status-im/go-wakurelay-pubsub" ) @@ -36,7 +37,7 @@ func NewWakuRelay(ctx context.Context, h host.Host, opts ...wakurelay.Option) (* w.wakuRelayTopics = make(map[Topic]*wakurelay.Topic) w.relaySubs = make(map[Topic]*wakurelay.Subscription) - ps, err := wakurelay.NewWakuRelaySub(ctx, h, opts...) + ps, err := wakurelay.NewWakuRelaySubWithMatcherFunc(ctx, h, protocol.PrefixTextMatch(string(wakurelay.WakuRelayID_v200)), opts...) if err != nil { return nil, err } diff --git a/waku/v2/protocol/store/waku_store.go b/waku/v2/protocol/store/waku_store.go index f21153d7..a4d79a0b 100644 --- a/waku/v2/protocol/store/waku_store.go +++ b/waku/v2/protocol/store/waku_store.go @@ -30,7 +30,8 @@ import ( var log = logging.Logger("wakustore") -const WakuStoreProtocolId = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta3") +const WakuStoreCodec = "/vac/waku/store/2.0.0-beta3" +const WakuStoreProtocolId = libp2pProtocol.ID(WakuStoreCodec) const MaxPageSize = 100 // Maximum number of waku messages in each page const DefaultContentTopic = "/waku/2/default-content/proto" @@ -247,7 +248,7 @@ func (store *WakuStore) Start(ctx context.Context, h host.Host, peerChan chan *e return } - store.h.SetStreamHandler(WakuStoreProtocolId, store.onRequest) + store.h.SetStreamHandlerMatch(WakuStoreProtocolId, protocol.PrefixTextMatch(WakuStoreCodec), store.onRequest) go store.storeIncomingMessages(ctx) diff --git a/waku/v2/protocol/utils.go b/waku/v2/protocol/utils.go new file mode 100644 index 00000000..8f538275 --- /dev/null +++ b/waku/v2/protocol/utils.go @@ -0,0 +1,15 @@ +package protocol + +import "strings" + +func FulltextMatch(expectedProtocol string) func(string) bool { + return func(receivedProtocol string) bool { + return receivedProtocol == expectedProtocol + } +} + +func PrefixTextMatch(prefix string) func(string) bool { + return func(receivedProtocol string) bool { + return strings.HasPrefix(receivedProtocol, prefix) + } +}