From 2f009cb69f8dd0f0cf5ab341126179bb2b76327a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 9 Feb 2023 08:53:37 -0400 Subject: [PATCH] fix: basic2 example --- examples/basic2/main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/basic2/main.go b/examples/basic2/main.go index 731c205a..355ce725 100644 --- a/examples/basic2/main.go +++ b/examples/basic2/main.go @@ -21,6 +21,7 @@ import ( ) var log = utils.Logger().Named("basic2") +var contentTopic = protocol.NewContentTopic("basic2", 1, "test", "proto").String() func main() { hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0") @@ -76,8 +77,6 @@ func randomHex(n int) (string, error) { } func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { - contentTopic := protocol.NewContentTopic("basic2", 1, "test", "proto") - var version uint32 = 0 var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource()) @@ -94,7 +93,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { msg := &pb.WakuMessage{ Payload: payload, Version: version, - ContentTopic: contentTopic.String(), + ContentTopic: contentTopic, Timestamp: timestamp, } @@ -118,11 +117,15 @@ func readLoop(ctx context.Context, wakuNode *node.WakuNode) { return } - for value := range sub.C { - payload, err := payload.DecodePayload(value.Message(), &payload.KeyInfo{Kind: payload.None}) + for envelope := range sub.C { + if envelope.Message().ContentTopic != contentTopic { + continue + } + + payload, err := payload.DecodePayload(envelope.Message(), &payload.KeyInfo{Kind: payload.None}) if err != nil { - fmt.Println(err) - return + log.Error("Error decoding payload", zap.Error(err)) + continue } log.Info("Received msg, ", zap.String("data", string(payload.Data)))