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 committed Jan 22, 2022
1 parent ae2e1e3 commit 6961f54
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions midgen.go
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 6961f54

Please sign in to comment.