Skip to content

Commit

Permalink
feat: extract RawID from ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored and vyzo committed Jan 23, 2022
1 parent 6faf473 commit 9fbf906
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions midgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package pubsub

import (
"sync"

pb "github.com/libp2p/go-libp2p-pubsub/pb"
)

// msgIDGenerator handles computing IDs for msgs
Expand Down Expand Up @@ -33,13 +35,18 @@ func (m *msgIDGenerator) ID(msg *Message) string {
return msg.ID
}

msg.ID = m.RawID(msg.Message)
return msg.ID
}

// RawID computes ID for the proto 'msg'.
func (m *msgIDGenerator) RawID(msg *pb.Message) string {
m.topicGensLk.RLock()
gen, ok := m.topicGens[msg.GetTopic()]
m.topicGensLk.RUnlock()
if !ok {
gen = m.Default
}

msg.ID = gen(msg.Message)
return msg.ID
return gen(msg)
}

0 comments on commit 9fbf906

Please sign in to comment.