subscribe to multiple topics

This commit is contained in:
Richard Ramos 2021-04-15 17:23:07 -04:00
parent 9572a766a8
commit 183b8f52c1
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
2 changed files with 12 additions and 3 deletions

View File

@ -57,6 +57,7 @@ var rootCmd = &cobra.Command{
dbPath, _ := cmd.Flags().GetString("dbpath") dbPath, _ := cmd.Flags().GetString("dbpath")
storenode, _ := cmd.Flags().GetString("storenode") storenode, _ := cmd.Flags().GetString("storenode")
staticnodes, _ := cmd.Flags().GetStringSlice("staticnodes") staticnodes, _ := cmd.Flags().GetStringSlice("staticnodes")
topics, _ := cmd.Flags().GetStringSlice("topics")
hostAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprint("0.0.0.0:", port)) hostAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprint("0.0.0.0:", port))
@ -104,6 +105,12 @@ var rootCmd = &cobra.Command{
wakuNode.StartStore() wakuNode.StartStore()
} }
for _, t := range topics {
nodeTopic := node.Topic(t)
_, err := wakuNode.Subscribe(&nodeTopic)
checkError(err, "Error subscring to topic")
}
if storenode != "" && !store { if storenode != "" && !store {
checkError(errors.New("Store protocol was not started"), "") checkError(errors.New("Store protocol was not started"), "")
} else { } else {
@ -142,6 +149,7 @@ func init() {
rootCmd.Flags().Int("port", 9000, "Libp2p TCP listening port (0 for random)") 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().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().StringSlice("staticnodes", []string{}, "Multiaddr of peer to directly connect with. Argument may be repeated")
rootCmd.Flags().Bool("store", false, "Enable store protocol") rootCmd.Flags().Bool("store", false, "Enable store protocol")
rootCmd.Flags().String("dbpath", "./store.db", "Path to DB file") rootCmd.Flags().String("dbpath", "./store.db", "Path to DB file")

View File

@ -323,11 +323,12 @@ func (node *WakuNode) upsertSubscription(topic Topic) (*wakurelay.Subscription,
return nil, err return nil, err
} }
node.relaySubs[topic] = sub node.relaySubs[topic] = sub
}
if node.store != nil && node.isStore { if node.store != nil && node.isStore {
log.Info("Subscribing store to ", topic)
node.bcaster.Register(node.store.MsgC) node.bcaster.Register(node.store.MsgC)
} }
}
return sub, nil return sub, nil
} }