fix: add protocol to matcher function

This commit is contained in:
Richard Ramos 2021-07-29 12:21:36 -04:00
parent 184b435d0b
commit adc6883028
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
2 changed files with 5 additions and 3 deletions

View File

@ -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))

View File

@ -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