mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-07 15:23:08 +00:00
feat: extract RawID from ID
This commit is contained in:
parent
6faf473cad
commit
9fbf906fb5
11
midgen.go
11
midgen.go
@ -2,6 +2,8 @@ package pubsub
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// msgIDGenerator handles computing IDs for msgs
|
// msgIDGenerator handles computing IDs for msgs
|
||||||
@ -33,6 +35,12 @@ func (m *msgIDGenerator) ID(msg *Message) string {
|
|||||||
return msg.ID
|
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()
|
m.topicGensLk.RLock()
|
||||||
gen, ok := m.topicGens[msg.GetTopic()]
|
gen, ok := m.topicGens[msg.GetTopic()]
|
||||||
m.topicGensLk.RUnlock()
|
m.topicGensLk.RUnlock()
|
||||||
@ -40,6 +48,5 @@ func (m *msgIDGenerator) ID(msg *Message) string {
|
|||||||
gen = m.Default
|
gen = m.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.ID = gen(msg.Message)
|
return gen(msg)
|
||||||
return msg.ID
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user