From e66f0e3b9c150632c00538100a90bf27446fb54a Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 5 Sep 2023 11:11:40 -0400 Subject: [PATCH] fix: content topic usage on the examples --- examples/basic2/main.go | 20 +++++++++++++------- examples/chat2/flags.go | 7 ++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/basic2/main.go b/examples/basic2/main.go index 0aafe58f..e43521a0 100644 --- a/examples/basic2/main.go +++ b/examples/basic2/main.go @@ -21,9 +21,15 @@ import ( ) var log = utils.Logger().Named("basic2") -var contentTopic = protocol.NewContentTopic("basic2", 1, "test", "proto").String() func main() { + var cTopic, err = protocol.NewContentTopic("basic2", 1, "test", "proto") + if err != nil { + fmt.Println("Invalid contentTopic") + return + } + contentTopic := cTopic.String() + hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0") key, err := randomHex(32) if err != nil { @@ -54,8 +60,8 @@ func main() { return } - go writeLoop(ctx, wakuNode) - go readLoop(ctx, wakuNode) + go writeLoop(ctx, wakuNode, contentTopic) + go readLoop(ctx, wakuNode, contentTopic) // Wait for a SIGINT or SIGTERM signal ch := make(chan os.Signal, 1) @@ -76,7 +82,7 @@ func randomHex(n int) (string, error) { return hex.EncodeToString(bytes), nil } -func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { +func write(ctx context.Context, wakuNode *node.WakuNode, contentTopic string, msgContent string) { var version uint32 = 0 var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource()) @@ -103,14 +109,14 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { } } -func writeLoop(ctx context.Context, wakuNode *node.WakuNode) { +func writeLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) { for { time.Sleep(2 * time.Second) - write(ctx, wakuNode, "Hello world!") + write(ctx, wakuNode, contentTopic, "Hello world!") } } -func readLoop(ctx context.Context, wakuNode *node.WakuNode) { +func readLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) { sub, err := wakuNode.Relay().Subscribe(ctx) if err != nil { log.Error("Could not subscribe", zap.Error(err)) diff --git a/examples/chat2/flags.go b/examples/chat2/flags.go index 3702098e..725f30a8 100644 --- a/examples/chat2/flags.go +++ b/examples/chat2/flags.go @@ -34,7 +34,12 @@ func getFlags() []cli.Flag { // Defaults options.Fleet = fleetProd - testnetContentTopic := protocol.NewContentTopic("toy-chat", 3, "mingde", "proto").String() + testCT, err := protocol.NewContentTopic("toy-chat", 3, "mingde", "proto") + if err != nil { + fmt.Println("Invalid contentTopic") + return nil + } + testnetContentTopic := testCT.String() return []cli.Flag{ &cli.GenericFlag{