Although in https://github.com/libp2p/go-libp2p-pubsub/pull/503 we introduced injectible PubSubRouter into the GossipSub, there are several places in the code that initializing a GossipSub instance with a customized PubSubRouter is failing due to the strict type assertions, e.g., example-1, example-2, and example-3.
Although the rt (router) attribute of the GossipSub is deemed as a PubSubRouter interface type, nevertheless through the initialization phase of the GossipSub the rt attribute is strictly asserted as a GossipSubRouter value type. This is a blocker for initializing GossipSub with customized wrappers around GossipSubRouter as it no longer is going to be a GossipSubRouter strict value type. Hence the initialization fails with an pubsub router is not gossipsub error.
Contributions
In order to resolve the initialization failure due to the strict type assertions with GossipSubRouter this PR introduces the following changes:
We define the GossipPubSubRouter interface type, and replaced strict type assertions with interface type assertions.
We decouple the option functions that deal with GossipSubRouterstruct type from those deal with the PubSub.
Problem Statement
Although in https://github.com/libp2p/go-libp2p-pubsub/pull/503 we introduced injectible
PubSubRouter
into theGossipSub
, there are several places in the code that initializing aGossipSub
instance with a customizedPubSubRouter
is failing due to the strict type assertions, e.g., example-1, example-2, and example-3.Although the
rt
(router) attribute of theGossipSub
is deemed as aPubSubRouter
interface type, nevertheless through the initialization phase of theGossipSub
thert
attribute is strictly asserted as aGossipSubRouter
value type. This is a blocker for initializingGossipSub
with customized wrappers aroundGossipSubRouter
as it no longer is going to be aGossipSubRouter
strict value type. Hence the initialization fails with anpubsub router is not gossipsub
error.Contributions
In order to resolve the initialization failure due to the strict type assertions with
GossipSubRouter
this PR introduces the following changes:GossipPubSubRouter
interface type, and replaced strict type assertions with interface type assertions.GossipSubRouter
struct
type from those deal with thePubSub
.