From 183b8f52c14fa1cd824f72c2ff649dcf50d764b9 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 15 Apr 2021 17:23:07 -0400 Subject: [PATCH] subscribe to multiple topics --- waku/node.go | 8 ++++++++ waku/v2/node/wakunode2.go | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/waku/node.go b/waku/node.go index 477a2ee7..abcc88c5 100644 --- a/waku/node.go +++ b/waku/node.go @@ -57,6 +57,7 @@ var rootCmd = &cobra.Command{ dbPath, _ := cmd.Flags().GetString("dbpath") storenode, _ := cmd.Flags().GetString("storenode") staticnodes, _ := cmd.Flags().GetStringSlice("staticnodes") + topics, _ := cmd.Flags().GetStringSlice("topics") hostAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprint("0.0.0.0:", port)) @@ -104,6 +105,12 @@ var rootCmd = &cobra.Command{ wakuNode.StartStore() } + for _, t := range topics { + nodeTopic := node.Topic(t) + _, err := wakuNode.Subscribe(&nodeTopic) + checkError(err, "Error subscring to topic") + } + if storenode != "" && !store { checkError(errors.New("Store protocol was not started"), "") } else { @@ -142,6 +149,7 @@ func init() { rootCmd.Flags().Int("port", 9000, "Libp2p TCP listening port (0 for random)") rootCmd.Flags().String("nodekey", "", "P2P node private key as hex (default random)") + rootCmd.Flags().StringSlice("topics", []string{string(node.DefaultWakuTopic)}, fmt.Sprintf("List of topics to listen (default %s)", node.DefaultWakuTopic)) rootCmd.Flags().StringSlice("staticnodes", []string{}, "Multiaddr of peer to directly connect with. Argument may be repeated") rootCmd.Flags().Bool("store", false, "Enable store protocol") rootCmd.Flags().String("dbpath", "./store.db", "Path to DB file") diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 8529d0c6..cab6f410 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -323,10 +323,11 @@ func (node *WakuNode) upsertSubscription(topic Topic) (*wakurelay.Subscription, return nil, err } node.relaySubs[topic] = sub - } - if node.store != nil && node.isStore { - node.bcaster.Register(node.store.MsgC) + if node.store != nil && node.isStore { + log.Info("Subscribing store to ", topic) + node.bcaster.Register(node.store.MsgC) + } } return sub, nil