diff --git a/gossipsub.go b/gossipsub.go index d2d46f7..31c5724 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -76,7 +76,7 @@ func (gs *GossipSubRouter) Attach(p *PubSub) { gs.p = p gs.tracer = p.tracer // start using the same msg ID function as PubSub for caching messages. - gs.mcache.ChangeMsgIdFn(p.msgID) + gs.mcache.SetMsgIdFn(p.msgID) go gs.heartbeatTimer() } diff --git a/mcache.go b/mcache.go index cbb9a95..e085297 100644 --- a/mcache.go +++ b/mcache.go @@ -39,7 +39,7 @@ type MessageCache struct { msgID MsgIdFunction } -func (mc *MessageCache) ChangeMsgIdFn(msgID MsgIdFunction) { +func (mc *MessageCache) SetMsgIdFn(msgID MsgIdFunction) { mc.msgID = msgID } diff --git a/pubsub.go b/pubsub.go index b1d872d..b8bd579 100644 --- a/pubsub.go +++ b/pubsub.go @@ -254,6 +254,10 @@ type MsgIdFunction func(pmsg *pb.Message) string func WithMessageIdFn(fn MsgIdFunction) Option { return func(p *PubSub) error { p.msgID = fn + // the tracer Option may already be set. Update its message ID function to make options order-independent. + if p.tracer != nil { + p.tracer.msgID = fn + } return nil } }