node-canary: switch to using Waku instead of Whisper

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-08-26 00:04:10 +02:00 committed by Jakub
parent d09eaeacb8
commit 3996aa7853
1 changed files with 28 additions and 28 deletions

View File

@ -26,7 +26,7 @@ import (
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/ext" "github.com/status-im/status-go/services/ext"
"github.com/status-im/status-go/services/shhext" "github.com/status-im/status-go/services/wakuext"
"github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/t/helpers"
) )
@ -38,13 +38,13 @@ const (
var logger = log.New("package", "status-go/cmd/node-canary") var logger = log.New("package", "status-go/cmd/node-canary")
var ( var (
staticEnodeAddr = flag.String("staticnode", "", "checks if static node talks whisper protocol (e.g. enode://abc123@1.2.3.4:30303)") staticEnodeAddr = flag.String("staticnode", "", "checks if static node talks waku protocol (e.g. enode://abc123@1.2.3.4:30303)")
mailserverEnodeAddr = flag.String("mailserver", "", "queries mail server for historic messages (e.g. enode://123abc@4.3.2.1:30504)") mailserverEnodeAddr = flag.String("mailserver", "", "queries mail server for historic messages (e.g. enode://123abc@4.3.2.1:30504)")
publicChannel = flag.String("channel", "status", "The public channel name to retrieve historic messages from (used with 'mailserver' flag)") publicChannel = flag.String("channel", "status", "The public channel name to retrieve historic messages from (used with 'mailserver' flag)")
timeout = flag.Int("timeout", 10, "Timeout when connecting to node or fetching messages from mailserver, in seconds") timeout = flag.Int("timeout", 10, "Timeout when connecting to node or fetching messages from mailserver, in seconds")
period = flag.Int("period", 24*60*60, "How far in the past to request messages from mailserver, in seconds") period = flag.Int("period", 24*60*60, "How far in the past to request messages from mailserver, in seconds")
minPow = flag.Float64("shh.pow", params.WhisperMinimumPoW, "PoW for messages to be added to queue, in float format") minPow = flag.Float64("waku.pow", params.WakuMinimumPoW, "PoW for messages to be added to queue, in float format")
ttl = flag.Int("shh.ttl", params.WhisperTTL, "Time to live for messages, in seconds") ttl = flag.Int("waku.ttl", params.WakuTTL, "Time to live for messages, in seconds")
homePath = flag.String("home-dir", ".", "Home directory where state is stored") homePath = flag.String("home-dir", ".", "Home directory where state is stored")
logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`) logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`)
logFile = flag.String("logfile", "", "Path to the log file") logFile = flag.String("logfile", "", "Path to the log file")
@ -108,15 +108,15 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) {
defer func() { _ = clientBackend.StopNode() }() defer func() { _ = clientBackend.StopNode() }()
clientNode := clientBackend.StatusNode() clientNode := clientBackend.StatusNode()
clientGethWhisperService, err := clientNode.WhisperService() clientGethWakuService, err := clientNode.WakuService()
if err != nil { if err != nil {
logger.Error("Could not retrieve Whisper service", "error", err) logger.Error("Could not retrieve waku service", "error", err)
os.Exit(1) os.Exit(1)
} }
clientWhisperService := gethbridge.NewGethWhisperWrapper(clientGethWhisperService) clientWakuService := gethbridge.NewGethWakuWrapper(clientGethWakuService)
clientShhExtService, err := clientNode.ShhExtService() clientWakuExtService, err := clientNode.WakuExtService()
if err != nil { if err != nil {
logger.Error("Could not retrieve shhext service", "error", err) logger.Error("Could not retrieve wakuext service", "error", err)
os.Exit(1) os.Exit(1)
} }
@ -136,14 +136,14 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) {
} }
// add mailserver sym key // add mailserver sym key
mailServerKeyID, err := clientWhisperService.AddSymKeyFromPassword(mailboxPassword) mailServerKeyID, err := clientWakuService.AddSymKeyFromPassword(mailboxPassword)
if err != nil { if err != nil {
logger.Error("Error adding mailserver sym key to client peer", "error", err) logger.Error("Error adding mailserver sym key to client peer", "error", err)
os.Exit(1) os.Exit(1)
} }
mailboxPeer := mailserverNode.ID().Bytes() mailboxPeer := mailserverNode.ID().Bytes()
err = clientGethWhisperService.AllowP2PMessagesFromPeer(mailboxPeer) err = clientGethWakuService.AllowP2PMessagesFromPeer(mailboxPeer)
if err != nil { if err != nil {
logger.Error("Failed to allow P2P messages from mailserver peer", "error", err, mailserverNode.String()) logger.Error("Failed to allow P2P messages from mailserver peer", "error", err, mailserverNode.String())
os.Exit(1) os.Exit(1)
@ -151,7 +151,7 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) {
clientRPCClient := clientNode.RPCClient() clientRPCClient := clientNode.RPCClient()
_, topic, _, err := joinPublicChat(clientWhisperService, clientRPCClient, *publicChannel) _, topic, _, err := joinPublicChat(clientWakuService, clientRPCClient, *publicChannel)
if err != nil { if err != nil {
logger.Error("Failed to join public chat", "error", err) logger.Error("Failed to join public chat", "error", err)
os.Exit(1) os.Exit(1)
@ -159,20 +159,20 @@ func verifyMailserverBehavior(mailserverNode *enode.Node) {
// watch for envelopes to be available in filters in the client // watch for envelopes to be available in filters in the client
envelopeAvailableWatcher := make(chan types.EnvelopeEvent, 1024) envelopeAvailableWatcher := make(chan types.EnvelopeEvent, 1024)
sub := clientWhisperService.SubscribeEnvelopeEvents(envelopeAvailableWatcher) sub := clientWakuService.SubscribeEnvelopeEvents(envelopeAvailableWatcher)
defer sub.Unsubscribe() defer sub.Unsubscribe()
// watch for mailserver responses in the client // watch for mailserver responses in the client
mailServerResponseWatcher := make(chan types.EnvelopeEvent, 1024) mailServerResponseWatcher := make(chan types.EnvelopeEvent, 1024)
sub = clientWhisperService.SubscribeEnvelopeEvents(mailServerResponseWatcher) sub = clientWakuService.SubscribeEnvelopeEvents(mailServerResponseWatcher)
defer sub.Unsubscribe() defer sub.Unsubscribe()
// request messages from mailbox // request messages from mailbox
shhextAPI := shhext.NewPublicAPI(clientShhExtService) wakuextAPI := wakuext.NewPublicAPI(clientWakuExtService)
requestIDBytes, err := shhextAPI.RequestMessages(context.TODO(), requestIDBytes, err := wakuextAPI.RequestMessages(context.TODO(),
ext.MessagesRequest{ ext.MessagesRequest{
MailServerPeer: mailserverNode.String(), MailServerPeer: mailserverNode.String(),
From: uint32(clientWhisperService.GetCurrentTime().Add(-time.Duration(*period) * time.Second).Unix()), From: uint32(clientWakuService.GetCurrentTime().Add(-time.Duration(*period) * time.Second).Unix()),
Limit: 1, Limit: 1,
Topic: topic, Topic: topic,
SymKeyID: mailServerKeyID, SymKeyID: mailServerKeyID,
@ -282,16 +282,16 @@ func makeNodeConfig() (*params.NodeConfig, error) {
} }
} }
return whisperConfig(nodeConfig) return wakuConfig(nodeConfig)
} }
// whisperConfig creates node configuration object from flags // wakuConfig creates node configuration object from flags
func whisperConfig(nodeConfig *params.NodeConfig) (*params.NodeConfig, error) { func wakuConfig(nodeConfig *params.NodeConfig) (*params.NodeConfig, error) {
whisperConfig := &nodeConfig.WhisperConfig wakuConfig := &nodeConfig.WakuConfig
whisperConfig.Enabled = true wakuConfig.Enabled = true
whisperConfig.LightClient = true wakuConfig.LightClient = true
whisperConfig.MinimumPoW = *minPow wakuConfig.MinimumPoW = *minPow
whisperConfig.TTL = *ttl wakuConfig.TTL = *ttl
return nodeConfig, nil return nodeConfig, nil
} }
@ -313,7 +313,7 @@ func startClientNode() (*api.GethStatusBackend, error) {
return clientBackend, err return clientBackend, err
} }
func joinPublicChat(w types.Whisper, rpcClient *rpc.Client, name string) (string, types.TopicType, string, error) { func joinPublicChat(w types.Waku, rpcClient *rpc.Client, name string) (string, types.TopicType, string, error) {
keyID, err := w.AddSymKeyFromPassword(name) keyID, err := w.AddSymKeyFromPassword(name)
if err != nil { if err != nil {
return "", types.TopicType{}, "", err return "", types.TopicType{}, "", err
@ -327,8 +327,8 @@ func joinPublicChat(w types.Whisper, rpcClient *rpc.Client, name string) (string
fullTopic := h.Sum(nil) fullTopic := h.Sum(nil)
topic := types.BytesToTopic(fullTopic) topic := types.BytesToTopic(fullTopic)
whisperAPI := w.PublicWhisperAPI() wakuAPI := w.PublicWakuAPI()
filterID, err := whisperAPI.NewMessageFilter(types.Criteria{SymKeyID: keyID, Topics: []types.TopicType{topic}}) filterID, err := wakuAPI.NewMessageFilter(types.Criteria{SymKeyID: keyID, Topics: []types.TopicType{topic}})
return keyID, topic, filterID, err return keyID, topic, filterID, err
} }