From adc68830282a80a2d2cd392ea38ec082db478870 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 29 Jul 2021 12:21:36 -0400 Subject: [PATCH] fix: add protocol to matcher function --- pubsub.go | 6 ++++-- wakurelaysub.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pubsub.go b/pubsub.go index 14722c9..3ad8db2 100644 --- a/pubsub.go +++ b/pubsub.go @@ -311,8 +311,10 @@ func NewPubSub(ctx context.Context, h host.Host, rt PubSubRouter, opts ...Option return ps, nil } +type MatchFunction func(string) func(string) bool + // NewPubSubWithMatcherFunc returns a new PubSub management object, using a matcher function for the protocol id -func NewPubSubWithMatcherFunc(ctx context.Context, h host.Host, rt PubSubRouter, match func(string) bool, opts ...Option) (*PubSub, error) { +func NewPubSubWithMatcherFunc(ctx context.Context, h host.Host, rt PubSubRouter, match MatchFunction, opts ...Option) (*PubSub, error) { ps, err := createPubSub(ctx, h, rt, opts...) if err != nil { return nil, err @@ -321,7 +323,7 @@ func NewPubSubWithMatcherFunc(ctx context.Context, h host.Host, rt PubSubRouter, rt.Attach(ps) for _, id := range rt.Protocols() { - h.SetStreamHandlerMatch(id, match, ps.handleNewStream) + h.SetStreamHandlerMatch(id, match(string(id)), ps.handleNewStream) } h.Network().Notify((*PubSubNotif)(ps)) diff --git a/wakurelaysub.go b/wakurelaysub.go index 2f83090..9d7eb78 100644 --- a/wakurelaysub.go +++ b/wakurelaysub.go @@ -231,7 +231,7 @@ func NewWakuRelaySub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, // It has the folowing options set as default: WithMessageSignaturePolicy(StrictNoSign), // WithNoAuthor, and WithMessageIdFn that hashes the message content // Allows setting a function for protocol id matching -func NewWakuRelaySubWithMatcherFunc(ctx context.Context, h host.Host, match func(string) bool, opts ...Option) (*PubSub, error) { +func NewWakuRelaySubWithMatcherFunc(ctx context.Context, h host.Host, match MatchFunction, opts ...Option) (*PubSub, error) { rt := createWakuRelaySub(ctx, h) // use the withInternalTracer option to hook up the tag tracer