PR feedback: name change and account for different options order

This commit is contained in:
protolambda 2019-12-16 12:46:30 +01:00
parent 7981f9bfbd
commit 6bd07a71fc
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 6 additions and 2 deletions

View File

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

View File

@ -39,7 +39,7 @@ type MessageCache struct {
msgID MsgIdFunction
}
func (mc *MessageCache) ChangeMsgIdFn(msgID MsgIdFunction) {
func (mc *MessageCache) SetMsgIdFn(msgID MsgIdFunction) {
mc.msgID = msgID
}

View File

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