From 9fbf906fb5bc6b83938fedbfdc7673d7d76aa605 Mon Sep 17 00:00:00 2001 From: Wondertan Date: Sat, 22 Jan 2022 13:34:19 +0200 Subject: [PATCH] feat: extract RawID from ID --- midgen.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/midgen.go b/midgen.go index 972f1b02..9d3acfc1 100644 --- a/midgen.go +++ b/midgen.go @@ -2,6 +2,8 @@ package pubsub import ( "sync" + + pb "github.com/libp2p/go-libp2p-pubsub/pb" ) // msgIDGenerator handles computing IDs for msgs @@ -33,6 +35,12 @@ 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() @@ -40,6 +48,5 @@ func (m *msgIDGenerator) ID(msg *Message) string { gen = m.Default } - msg.ID = gen(msg.Message) - return msg.ID + return gen(msg) }