Skip to content

Commit

Permalink
PR feedback: name change and account for different options order
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Dec 16, 2019
1 parent 7981f9b commit 6bd07a7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion mcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type MessageCache struct {
msgID MsgIdFunction
}

func (mc *MessageCache) ChangeMsgIdFn(msgID MsgIdFunction) {
func (mc *MessageCache) SetMsgIdFn(msgID MsgIdFunction) {
mc.msgID = msgID
}

Expand Down
4 changes: 4 additions & 0 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 6bd07a7

Please sign in to comment.