Skip to content

Conversation

@richard-ramos
Copy link
Contributor

This allows setting a custom protocol matching function.

fullTextMatch := func(expectedProtocol string) func(string) bool {
    return func(protocolToVerify string) bool {
	return protocolToVerify == expectedProtocol
    }
}

// create a new PubSub service using the GossipSub router
ps, err := pubsub.NewGossipSub(ctx, h, pubsub.WithProtocolMatchFunction(fullTextMatch))

Could potentially be used to allow semver matching

protoMinor := protocol.ID("/testing/1.2.0")
mfunc, err := helpers.MultistreamSemverMatcher(protoMinor)
if err != nil {
    t.Fatal(err)
}
ps, err := pubsub.NewGossipSub(ctx, h, 
     pubsub.WithProtocolMatchFunction(mfunc),
     pubsub.WithGossipSubProtocols([]protocol.ID{pubsub.GossipSubID_v11, pubsub.GossipSubID_v10, pubsub.FloodSubID, protoMinor}, pubsub.GossipSubDefaultFeatures)
)

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this looks useful.

A couple of small changes are needed:

  • It should probably be combined with the appropriate feature test function in gossipsub.
    Mind adding some about this in the documentation?
  • No need to use a pointer! functions can be tested against nil with !=

@vyzo
Copy link
Collaborator

vyzo commented Jul 29, 2021

Also, can you add a test?

@richard-ramos richard-ramos requested a review from vyzo July 29, 2021 21:54
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, this is looking good. Just a couple of minor things to fix and we can merge.

pubsub.go Outdated
peerOutboundQueueSize: 32,
signID: h.ID(),
signKey: nil,
protoMatchFunc: nil,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to initialize this, the default is fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we do it for signKey to be explicit about it, as these are grouped together.

pubsub.go Outdated
Comment on lines 489 to 490
// be used by the protocol handler on the Host's Mux. Can be combined with
// WithGossipSubProtocols feature function for checking if a protocol is supported
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say here "Should be combined ... for checking if certain protocol features are supported"

@richard-ramos
Copy link
Contributor Author

I finished the required changes. Thank you for the code review!

@richard-ramos richard-ramos requested a review from vyzo July 30, 2021 12:59
@vyzo vyzo merged commit 37d36d7 into libp2p:master Jul 30, 2021
@vyzo
Copy link
Collaborator

vyzo commented Jul 30, 2021

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants