diff --git a/cmd/geth/config.go b/cmd/geth/config.go
index 01ca0a9cfbd9..b5701e998a0d 100644
--- a/cmd/geth/config.go
+++ b/cmd/geth/config.go
@@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/naoina/toml"
)
@@ -40,7 +39,7 @@ var (
Name: "dumpconfig",
Usage: "Show configuration values",
ArgsUsage: "",
- Flags: append(append(nodeFlags, rpcFlags...), whisperFlags...),
+ Flags: append(nodeFlags, rpcFlags...),
Category: "MISCELLANEOUS COMMANDS",
Description: `The dumpconfig command shows configuration values.`,
}
@@ -74,7 +73,6 @@ type ethstatsConfig struct {
type gethConfig struct {
Eth eth.Config
- Shh whisper.Config
Node node.Config
Ethstats ethstatsConfig
}
@@ -108,7 +106,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults.
cfg := gethConfig{
Eth: eth.DefaultConfig,
- Shh: whisper.DefaultConfig,
Node: defaultNodeConfig(),
}
@@ -129,40 +126,14 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
if ctx.GlobalIsSet(utils.EthStatsURLFlag.Name) {
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
}
- utils.SetShhConfig(ctx, stack, &cfg.Shh)
return stack, cfg
}
-// enableWhisper returns true in case one of the whisper flags is set.
-func enableWhisper(ctx *cli.Context) bool {
- for _, flag := range whisperFlags {
- if ctx.GlobalIsSet(flag.GetName()) {
- return true
- }
- }
- return false
-}
-
func makeFullNode(ctx *cli.Context) *node.Node {
stack, cfg := makeConfigNode(ctx)
utils.RegisterEthService(stack, &cfg.Eth)
- // Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode
- shhEnabled := enableWhisper(ctx)
- shhAutoEnabled := !ctx.GlobalIsSet(utils.WhisperEnabledFlag.Name) && ctx.GlobalIsSet(utils.DeveloperFlag.Name)
- if shhEnabled || shhAutoEnabled {
- if ctx.GlobalIsSet(utils.WhisperMaxMessageSizeFlag.Name) {
- cfg.Shh.MaxMessageSize = uint32(ctx.Int(utils.WhisperMaxMessageSizeFlag.Name))
- }
- if ctx.GlobalIsSet(utils.WhisperMinPOWFlag.Name) {
- cfg.Shh.MinimumAcceptedPOW = ctx.Float64(utils.WhisperMinPOWFlag.Name)
- }
- if ctx.GlobalIsSet(utils.WhisperRestrictConnectionBetweenLightClientsFlag.Name) {
- cfg.Shh.RestrictConnectionBetweenLightClients = true
- }
- utils.RegisterShhService(stack, &cfg.Shh)
- }
// Configure GraphQL if requested
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
utils.RegisterGraphQLService(stack, cfg.Node.GraphQLEndpoint(), cfg.Node.GraphQLCors, cfg.Node.GraphQLVirtualHosts, cfg.Node.HTTPTimeouts)
diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go
index 2a304636eb62..a25479140bd0 100644
--- a/cmd/geth/consolecmd.go
+++ b/cmd/geth/consolecmd.go
@@ -38,7 +38,7 @@ var (
Action: utils.MigrateFlags(localConsole),
Name: "console",
Usage: "Start an interactive JavaScript environment",
- Flags: append(append(append(nodeFlags, rpcFlags...), consoleFlags...), whisperFlags...),
+ Flags: append(append(nodeFlags, rpcFlags...), consoleFlags...),
Category: "CONSOLE COMMANDS",
Description: `
The Geth console is an interactive shell for the JavaScript runtime environment
diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go
index a2489892e48b..be72cf8db8c2 100644
--- a/cmd/geth/consolecmd_test.go
+++ b/cmd/geth/consolecmd_test.go
@@ -31,7 +31,7 @@ import (
)
const (
- ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0"
+ ipcAPIs = "admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 web3:1.0"
)
@@ -43,8 +43,7 @@ func TestConsoleWelcome(t *testing.T) {
// Start a geth console, make sure it's cleaned up and terminate the console
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
- "--etherbase", coinbase, "--shh",
- "console")
+ "--etherbase", coinbase, "console")
// Gather all the infos the welcome message needs to contain
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS })
@@ -83,11 +82,9 @@ func TestIPCAttachWelcome(t *testing.T) {
defer os.RemoveAll(ws)
ipc = filepath.Join(ws, "geth.ipc")
}
- // Note: we need --shh because testAttachWelcome checks for default
- // list of ipc modules and shh is included there.
geth := runGeth(t,
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
- "--etherbase", coinbase, "--shh", "--ipcpath", ipc)
+ "--etherbase", coinbase, "--ipcpath", ipc)
defer func() {
geth.Interrupt()
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 62aa44e26476..38f4d865ca70 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -193,13 +193,6 @@ var (
utils.RPCGlobalTxFeeCap,
}
- whisperFlags = []cli.Flag{
- utils.WhisperEnabledFlag,
- utils.WhisperMaxMessageSizeFlag,
- utils.WhisperMinPOWFlag,
- utils.WhisperRestrictConnectionBetweenLightClientsFlag,
- }
-
metricsFlags = []cli.Flag{
utils.MetricsEnabledFlag,
utils.MetricsEnabledExpensiveFlag,
@@ -257,7 +250,6 @@ func init() {
app.Flags = append(app.Flags, consoleFlags...)
app.Flags = append(app.Flags, debug.Flags...)
app.Flags = append(app.Flags, debug.DeprecatedFlags...)
- app.Flags = append(app.Flags, whisperFlags...)
app.Flags = append(app.Flags, metricsFlags...)
app.Before = func(ctx *cli.Context) error {
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index 277774b0cc5b..16c6910b99b4 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -212,10 +212,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
Name: "METRICS AND STATS",
Flags: metricsFlags,
},
- {
- Name: "WHISPER (EXPERIMENTAL)",
- Flags: whisperFlags,
- },
{
Name: "ALIASED (deprecated)",
Flags: append([]cli.Flag{
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 68c3449fe544..d95601f995a8 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -64,7 +64,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
+ "github.com/ethereum/whisper"
pcsclite "github.com/gballet/go-libpcsclite"
cli "gopkg.in/urfave/cli.v1"
)
@@ -643,24 +643,6 @@ var (
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
Value: eth.DefaultConfig.GPO.Percentile,
}
- WhisperEnabledFlag = cli.BoolFlag{
- Name: "shh",
- Usage: "Enable Whisper",
- }
- WhisperMaxMessageSizeFlag = cli.IntFlag{
- Name: "shh.maxmessagesize",
- Usage: "Max message size accepted",
- Value: int(whisper.DefaultMaxMessageSize),
- }
- WhisperMinPOWFlag = cli.Float64Flag{
- Name: "shh.pow",
- Usage: "Minimum POW accepted",
- Value: whisper.DefaultMinimumPoW,
- }
- WhisperRestrictConnectionBetweenLightClientsFlag = cli.BoolFlag{
- Name: "shh.restrict-light",
- Usage: "Restrict connection between two whisper light clients",
- }
// Metrics flags
MetricsEnabledFlag = cli.BoolFlag{
@@ -1482,19 +1464,6 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
}
}
-// SetShhConfig applies shh-related command line flags to the config.
-func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) {
- if ctx.GlobalIsSet(WhisperMaxMessageSizeFlag.Name) {
- cfg.MaxMessageSize = uint32(ctx.GlobalUint(WhisperMaxMessageSizeFlag.Name))
- }
- if ctx.GlobalIsSet(WhisperMinPOWFlag.Name) {
- cfg.MinimumAcceptedPOW = ctx.GlobalFloat64(WhisperMinPOWFlag.Name)
- }
- if ctx.GlobalIsSet(WhisperRestrictConnectionBetweenLightClientsFlag.Name) {
- cfg.RestrictConnectionBetweenLightClients = true
- }
-}
-
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
// Avoid conflicting network flags
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
deleted file mode 100644
index 677cad7ef142..000000000000
--- a/cmd/wnode/main.go
+++ /dev/null
@@ -1,774 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of go-ethereum.
-//
-// go-ethereum is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// go-ethereum is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with go-ethereum. If not, see .
-
-// This is a simple Whisper node. It could be used as a stand-alone bootstrap node.
-// Also, could be used for different test and diagnostics purposes.
-
-package main
-
-import (
- "bufio"
- "crypto/ecdsa"
- crand "crypto/rand"
- "crypto/sha512"
- "encoding/binary"
- "encoding/hex"
- "flag"
- "fmt"
- "io/ioutil"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
-
- "github.com/ethereum/go-ethereum/cmd/utils"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/console/prompt"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/p2p/enode"
- "github.com/ethereum/go-ethereum/p2p/nat"
- "github.com/ethereum/go-ethereum/whisper/mailserver"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
- "golang.org/x/crypto/pbkdf2"
-)
-
-const quitCommand = "~Q"
-const entropySize = 32
-
-// singletons
-var (
- server *p2p.Server
- shh *whisper.Whisper
- done chan struct{}
- mailServer mailserver.WMailServer
- entropy [entropySize]byte
-
- input = bufio.NewReader(os.Stdin)
-)
-
-// encryption
-var (
- symKey []byte
- pub *ecdsa.PublicKey
- asymKey *ecdsa.PrivateKey
- nodeid *ecdsa.PrivateKey
- topic whisper.TopicType
-
- asymKeyID string
- asymFilterID string
- symFilterID string
- symPass string
- msPassword string
-)
-
-// cmd arguments
-var (
- bootstrapMode = flag.Bool("standalone", false, "boostrap node: don't initiate connection to peers, just wait for incoming connections")
- forwarderMode = flag.Bool("forwarder", false, "forwarder mode: only forward messages, neither encrypt nor decrypt messages")
- mailServerMode = flag.Bool("mailserver", false, "mail server mode: delivers expired messages on demand")
- requestMail = flag.Bool("mailclient", false, "request expired messages from the bootstrap server")
- asymmetricMode = flag.Bool("asym", false, "use asymmetric encryption")
- generateKey = flag.Bool("generatekey", false, "generate and show the private key")
- fileExMode = flag.Bool("fileexchange", false, "file exchange mode")
- fileReader = flag.Bool("filereader", false, "load and decrypt messages saved as files, display as plain text")
- testMode = flag.Bool("test", false, "use of predefined parameters for diagnostics (password, etc.)")
- echoMode = flag.Bool("echo", false, "echo mode: prints some arguments for diagnostics")
-
- argVerbosity = flag.Int("verbosity", int(log.LvlError), "log verbosity level")
- argTTL = flag.Uint("ttl", 30, "time-to-live for messages in seconds")
- argWorkTime = flag.Uint("work", 5, "work time in seconds")
- argMaxSize = flag.Uint("maxsize", uint(whisper.DefaultMaxMessageSize), "max size of message")
- argPoW = flag.Float64("pow", whisper.DefaultMinimumPoW, "PoW for normal messages in float format (e.g. 2.7)")
- argServerPoW = flag.Float64("mspow", whisper.DefaultMinimumPoW, "PoW requirement for Mail Server request")
-
- argIP = flag.String("ip", "", "IP address and port of this node (e.g. 127.0.0.1:30303)")
- argPub = flag.String("pub", "", "public key for asymmetric encryption")
- argDBPath = flag.String("dbpath", "", "path to the server's DB directory")
- argIDFile = flag.String("idfile", "", "file name with node id (private key)")
- argEnode = flag.String("boot", "", "bootstrap node you want to connect to (e.g. enode://e454......08d50@52.176.211.200:16428)")
- argTopic = flag.String("topic", "", "topic in hexadecimal format (e.g. 70a4beef)")
- argSaveDir = flag.String("savedir", "", "directory where all incoming messages will be saved as files")
-)
-
-func main() {
- processArgs()
- initialize()
- run()
- shutdown()
-}
-
-func processArgs() {
- flag.Parse()
-
- if len(*argIDFile) > 0 {
- var err error
- nodeid, err = crypto.LoadECDSA(*argIDFile)
- if err != nil {
- utils.Fatalf("Failed to load file [%s]: %s.", *argIDFile, err)
- }
- }
-
- const enodePrefix = "enode://"
- if len(*argEnode) > 0 {
- if (*argEnode)[:len(enodePrefix)] != enodePrefix {
- *argEnode = enodePrefix + *argEnode
- }
- }
-
- if len(*argTopic) > 0 {
- x, err := hex.DecodeString(*argTopic)
- if err != nil {
- utils.Fatalf("Failed to parse the topic: %s", err)
- }
- topic = whisper.BytesToTopic(x)
- }
-
- if *asymmetricMode && len(*argPub) > 0 {
- var err error
- if pub, err = crypto.UnmarshalPubkey(common.FromHex(*argPub)); err != nil {
- utils.Fatalf("invalid public key")
- }
- }
-
- if len(*argSaveDir) > 0 {
- if _, err := os.Stat(*argSaveDir); os.IsNotExist(err) {
- utils.Fatalf("Download directory '%s' does not exist", *argSaveDir)
- }
- } else if *fileExMode {
- utils.Fatalf("Parameter 'savedir' is mandatory for file exchange mode")
- }
-
- if *echoMode {
- echo()
- }
-}
-
-func echo() {
- fmt.Printf("ttl = %d \n", *argTTL)
- fmt.Printf("workTime = %d \n", *argWorkTime)
- fmt.Printf("pow = %f \n", *argPoW)
- fmt.Printf("mspow = %f \n", *argServerPoW)
- fmt.Printf("ip = %s \n", *argIP)
- fmt.Printf("pub = %s \n", hexutil.Encode(crypto.FromECDSAPub(pub)))
- fmt.Printf("idfile = %s \n", *argIDFile)
- fmt.Printf("dbpath = %s \n", *argDBPath)
- fmt.Printf("boot = %s \n", *argEnode)
-}
-
-func initialize() {
- log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*argVerbosity), log.StreamHandler(os.Stderr, log.TerminalFormat(false))))
-
- done = make(chan struct{})
- var peers []*enode.Node
- var err error
-
- if *generateKey {
- key, err := crypto.GenerateKey()
- if err != nil {
- utils.Fatalf("Failed to generate private key: %s", err)
- }
- k := hex.EncodeToString(crypto.FromECDSA(key))
- fmt.Printf("Random private key: %s \n", k)
- os.Exit(0)
- }
-
- if *testMode {
- symPass = "wwww" // ascii code: 0x77777777
- msPassword = "wwww"
- }
-
- if *bootstrapMode {
- if len(*argIP) == 0 {
- argIP = scanLineA("Please enter your IP and port (e.g. 127.0.0.1:30348): ")
- }
- } else if *fileReader {
- *bootstrapMode = true
- } else {
- if len(*argEnode) == 0 {
- argEnode = scanLineA("Please enter the peer's enode: ")
- }
- peer := enode.MustParse(*argEnode)
- peers = append(peers, peer)
- }
-
- if *mailServerMode {
- if len(msPassword) == 0 {
- msPassword, err = prompt.Stdin.PromptPassword("Please enter the Mail Server password: ")
- if err != nil {
- utils.Fatalf("Failed to read Mail Server password: %s", err)
- }
- }
- }
-
- cfg := &whisper.Config{
- MaxMessageSize: uint32(*argMaxSize),
- MinimumAcceptedPOW: *argPoW,
- }
-
- shh = whisper.New(cfg)
-
- if *argPoW != whisper.DefaultMinimumPoW {
- err := shh.SetMinimumPoW(*argPoW)
- if err != nil {
- utils.Fatalf("Failed to set PoW: %s", err)
- }
- }
-
- if uint32(*argMaxSize) != whisper.DefaultMaxMessageSize {
- err := shh.SetMaxMessageSize(uint32(*argMaxSize))
- if err != nil {
- utils.Fatalf("Failed to set max message size: %s", err)
- }
- }
-
- asymKeyID, err = shh.NewKeyPair()
- if err != nil {
- utils.Fatalf("Failed to generate a new key pair: %s", err)
- }
-
- asymKey, err = shh.GetPrivateKey(asymKeyID)
- if err != nil {
- utils.Fatalf("Failed to retrieve a new key pair: %s", err)
- }
-
- if nodeid == nil {
- tmpID, err := shh.NewKeyPair()
- if err != nil {
- utils.Fatalf("Failed to generate a new key pair: %s", err)
- }
-
- nodeid, err = shh.GetPrivateKey(tmpID)
- if err != nil {
- utils.Fatalf("Failed to retrieve a new key pair: %s", err)
- }
- }
-
- maxPeers := 80
- if *bootstrapMode {
- maxPeers = 800
- }
-
- _, err = crand.Read(entropy[:])
- if err != nil {
- utils.Fatalf("crypto/rand failed: %s", err)
- }
-
- if *mailServerMode {
- shh.RegisterServer(&mailServer)
- if err := mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW); err != nil {
- utils.Fatalf("Failed to init MailServer: %s", err)
- }
- }
-
- server = &p2p.Server{
- Config: p2p.Config{
- PrivateKey: nodeid,
- MaxPeers: maxPeers,
- Name: common.MakeName("wnode", "6.0"),
- Protocols: shh.Protocols(),
- ListenAddr: *argIP,
- NAT: nat.Any(),
- BootstrapNodes: peers,
- StaticNodes: peers,
- TrustedNodes: peers,
- },
- }
-}
-
-func startServer() error {
- err := server.Start()
- if err != nil {
- fmt.Printf("Failed to start Whisper peer: %s.", err)
- return err
- }
-
- fmt.Printf("my public key: %s \n", hexutil.Encode(crypto.FromECDSAPub(&asymKey.PublicKey)))
- fmt.Println(server.NodeInfo().Enode)
-
- if *bootstrapMode {
- configureNode()
- fmt.Println("Bootstrap Whisper node started")
- } else {
- fmt.Println("Whisper node started")
- // first see if we can establish connection, then ask for user input
- waitForConnection(true)
- configureNode()
- }
-
- if *fileExMode {
- fmt.Printf("Please type the file name to be send. To quit type: '%s'\n", quitCommand)
- } else if *fileReader {
- fmt.Printf("Please type the file name to be decrypted. To quit type: '%s'\n", quitCommand)
- } else if !*forwarderMode {
- fmt.Printf("Please type the message. To quit type: '%s'\n", quitCommand)
- }
- return nil
-}
-
-func configureNode() {
- var err error
- var p2pAccept bool
-
- if *forwarderMode {
- return
- }
-
- if *asymmetricMode {
- if len(*argPub) == 0 {
- s := scanLine("Please enter the peer's public key: ")
- b := common.FromHex(s)
- if b == nil {
- utils.Fatalf("Error: can not convert hexadecimal string")
- }
- if pub, err = crypto.UnmarshalPubkey(b); err != nil {
- utils.Fatalf("Error: invalid peer public key")
- }
- }
- }
-
- if *requestMail {
- p2pAccept = true
- if len(msPassword) == 0 {
- msPassword, err = prompt.Stdin.PromptPassword("Please enter the Mail Server password: ")
- if err != nil {
- utils.Fatalf("Failed to read Mail Server password: %s", err)
- }
- }
- }
-
- if !*asymmetricMode && !*forwarderMode {
- if len(symPass) == 0 {
- symPass, err = prompt.Stdin.PromptPassword("Please enter the password for symmetric encryption: ")
- if err != nil {
- utils.Fatalf("Failed to read password: %v", err)
- }
- }
-
- symKeyID, err := shh.AddSymKeyFromPassword(symPass)
- if err != nil {
- utils.Fatalf("Failed to create symmetric key: %s", err)
- }
- symKey, err = shh.GetSymKey(symKeyID)
- if err != nil {
- utils.Fatalf("Failed to save symmetric key: %s", err)
- }
- if len(*argTopic) == 0 {
- generateTopic([]byte(symPass))
- }
-
- fmt.Printf("Filter is configured for the topic: %x \n", topic)
- }
-
- if *mailServerMode {
- if len(*argDBPath) == 0 {
- argDBPath = scanLineA("Please enter the path to DB file: ")
- }
- }
-
- symFilter := whisper.Filter{
- KeySym: symKey,
- Topics: [][]byte{topic[:]},
- AllowP2P: p2pAccept,
- }
- symFilterID, err = shh.Subscribe(&symFilter)
- if err != nil {
- utils.Fatalf("Failed to install filter: %s", err)
- }
-
- asymFilter := whisper.Filter{
- KeyAsym: asymKey,
- Topics: [][]byte{topic[:]},
- AllowP2P: p2pAccept,
- }
- asymFilterID, err = shh.Subscribe(&asymFilter)
- if err != nil {
- utils.Fatalf("Failed to install filter: %s", err)
- }
-}
-
-func generateTopic(password []byte) {
- x := pbkdf2.Key(password, password, 4096, 128, sha512.New)
- for i := 0; i < len(x); i++ {
- topic[i%whisper.TopicLength] ^= x[i]
- }
-}
-
-func waitForConnection(timeout bool) {
- var cnt int
- var connected bool
- for !connected {
- time.Sleep(time.Millisecond * 50)
- connected = server.PeerCount() > 0
- if timeout {
- cnt++
- if cnt > 1000 {
- utils.Fatalf("Timeout expired, failed to connect")
- }
- }
- }
-
- fmt.Println("Connected to peer.")
-}
-
-func run() {
- err := startServer()
- if err != nil {
- return
- }
- defer server.Stop()
- shh.Start(nil)
- defer shh.Stop()
-
- if !*forwarderMode {
- go messageLoop()
- }
-
- if *requestMail {
- requestExpiredMessagesLoop()
- } else if *fileExMode {
- sendFilesLoop()
- } else if *fileReader {
- fileReaderLoop()
- } else {
- sendLoop()
- }
-}
-
-func shutdown() {
- close(done)
- mailServer.Close()
-}
-
-func sendLoop() {
- for {
- s := scanLine("")
- if s == quitCommand {
- fmt.Println("Quit command received")
- return
- }
- sendMsg([]byte(s))
- if *asymmetricMode {
- // print your own message for convenience,
- // because in asymmetric mode it is impossible to decrypt it
- timestamp := time.Now().Unix()
- from := crypto.PubkeyToAddress(asymKey.PublicKey)
- fmt.Printf("\n%d <%x>: %s\n", timestamp, from, s)
- }
- }
-}
-
-func sendFilesLoop() {
- for {
- s := scanLine("")
- if s == quitCommand {
- fmt.Println("Quit command received")
- return
- }
- b, err := ioutil.ReadFile(s)
- if err != nil {
- fmt.Printf(">>> Error: %s \n", err)
- } else {
- h := sendMsg(b)
- if (h == common.Hash{}) {
- fmt.Printf(">>> Error: message was not sent \n")
- } else {
- timestamp := time.Now().Unix()
- from := crypto.PubkeyToAddress(asymKey.PublicKey)
- fmt.Printf("\n%d <%x>: sent message with hash %x\n", timestamp, from, h)
- }
- }
- }
-}
-
-func fileReaderLoop() {
- watcher1 := shh.GetFilter(symFilterID)
- watcher2 := shh.GetFilter(asymFilterID)
- if watcher1 == nil && watcher2 == nil {
- fmt.Println("Error: neither symmetric nor asymmetric filter is installed")
- return
- }
-
- for {
- s := scanLine("")
- if s == quitCommand {
- fmt.Println("Quit command received")
- return
- }
- raw, err := ioutil.ReadFile(s)
- if err != nil {
- fmt.Printf(">>> Error: %s \n", err)
- } else {
- env := whisper.Envelope{Data: raw} // the topic is zero
- msg := env.Open(watcher1) // force-open envelope regardless of the topic
- if msg == nil {
- msg = env.Open(watcher2)
- }
- if msg == nil {
- fmt.Printf(">>> Error: failed to decrypt the message \n")
- } else {
- printMessageInfo(msg)
- }
- }
- }
-}
-
-func scanLine(prompt string) string {
- if len(prompt) > 0 {
- fmt.Print(prompt)
- }
- txt, err := input.ReadString('\n')
- if err != nil {
- utils.Fatalf("input error: %s", err)
- }
- txt = strings.TrimRight(txt, "\n\r")
- return txt
-}
-
-func scanLineA(prompt string) *string {
- s := scanLine(prompt)
- return &s
-}
-
-func scanUint(prompt string) uint32 {
- s := scanLine(prompt)
- i, err := strconv.Atoi(s)
- if err != nil {
- utils.Fatalf("Fail to parse the lower time limit: %s", err)
- }
- return uint32(i)
-}
-
-func sendMsg(payload []byte) common.Hash {
- params := whisper.MessageParams{
- Src: asymKey,
- Dst: pub,
- KeySym: symKey,
- Payload: payload,
- Topic: topic,
- TTL: uint32(*argTTL),
- PoW: *argPoW,
- WorkTime: uint32(*argWorkTime),
- }
-
- msg, err := whisper.NewSentMessage(¶ms)
- if err != nil {
- utils.Fatalf("failed to create new message: %s", err)
- }
-
- envelope, err := msg.Wrap(¶ms)
- if err != nil {
- fmt.Printf("failed to seal message: %v \n", err)
- return common.Hash{}
- }
-
- err = shh.Send(envelope)
- if err != nil {
- fmt.Printf("failed to send message: %v \n", err)
- return common.Hash{}
- }
-
- return envelope.Hash()
-}
-
-func messageLoop() {
- sf := shh.GetFilter(symFilterID)
- if sf == nil {
- utils.Fatalf("symmetric filter is not installed")
- }
-
- af := shh.GetFilter(asymFilterID)
- if af == nil {
- utils.Fatalf("asymmetric filter is not installed")
- }
-
- ticker := time.NewTicker(time.Millisecond * 50)
- defer ticker.Stop()
-
- for {
- select {
- case <-ticker.C:
- m1 := sf.Retrieve()
- m2 := af.Retrieve()
- messages := append(m1, m2...)
- for _, msg := range messages {
- reportedOnce := false
- if !*fileExMode && len(msg.Payload) <= 2048 {
- printMessageInfo(msg)
- reportedOnce = true
- }
-
- // All messages are saved upon specifying argSaveDir.
- // fileExMode only specifies how messages are displayed on the console after they are saved.
- // if fileExMode == true, only the hashes are displayed, since messages might be too big.
- if len(*argSaveDir) > 0 {
- writeMessageToFile(*argSaveDir, msg, !reportedOnce)
- }
- }
- case <-done:
- return
- }
- }
-}
-
-func printMessageInfo(msg *whisper.ReceivedMessage) {
- timestamp := fmt.Sprintf("%d", msg.Sent) // unix timestamp for diagnostics
- text := string(msg.Payload)
-
- var address common.Address
- if msg.Src != nil {
- address = crypto.PubkeyToAddress(*msg.Src)
- }
-
- if whisper.IsPubKeyEqual(msg.Src, &asymKey.PublicKey) {
- fmt.Printf("\n%s <%x>: %s\n", timestamp, address, text) // message from myself
- } else {
- fmt.Printf("\n%s [%x]: %s\n", timestamp, address, text) // message from a peer
- }
-}
-
-func writeMessageToFile(dir string, msg *whisper.ReceivedMessage, show bool) {
- if len(dir) == 0 {
- return
- }
-
- timestamp := fmt.Sprintf("%d", msg.Sent)
- name := fmt.Sprintf("%x", msg.EnvelopeHash)
-
- var address common.Address
- if msg.Src != nil {
- address = crypto.PubkeyToAddress(*msg.Src)
- }
-
- env := shh.GetEnvelope(msg.EnvelopeHash)
- if env == nil {
- fmt.Printf("\nUnexpected error: envelope not found: %x\n", msg.EnvelopeHash)
- return
- }
-
- // this is a sample code; uncomment if you don't want to save your own messages.
- //if whisper.IsPubKeyEqual(msg.Src, &asymKey.PublicKey) {
- // fmt.Printf("\n%s <%x>: message from myself received, not saved: '%s'\n", timestamp, address, name)
- // return
- //}
-
- fullpath := filepath.Join(dir, name)
- err := ioutil.WriteFile(fullpath, env.Data, 0644)
- if err != nil {
- fmt.Printf("\n%s {%x}: message received but not saved: %s\n", timestamp, address, err)
- } else if show {
- fmt.Printf("\n%s {%x}: message received and saved as '%s' (%d bytes)\n", timestamp, address, name, len(env.Data))
- }
-}
-
-func requestExpiredMessagesLoop() {
- var key, peerID, bloom []byte
- var timeLow, timeUpp uint32
- var t string
- var xt whisper.TopicType
-
- keyID, err := shh.AddSymKeyFromPassword(msPassword)
- if err != nil {
- utils.Fatalf("Failed to create symmetric key for mail request: %s", err)
- }
- key, err = shh.GetSymKey(keyID)
- if err != nil {
- utils.Fatalf("Failed to save symmetric key for mail request: %s", err)
- }
- peerID = extractIDFromEnode(*argEnode)
- shh.AllowP2PMessagesFromPeer(peerID)
-
- for {
- timeLow = scanUint("Please enter the lower limit of the time range (unix timestamp): ")
- timeUpp = scanUint("Please enter the upper limit of the time range (unix timestamp): ")
- t = scanLine("Enter the topic (hex). Press enter to request all messages, regardless of the topic: ")
- if len(t) == whisper.TopicLength*2 {
- x, err := hex.DecodeString(t)
- if err != nil {
- fmt.Printf("Failed to parse the topic: %s \n", err)
- continue
- }
- xt = whisper.BytesToTopic(x)
- bloom = whisper.TopicToBloom(xt)
- obfuscateBloom(bloom)
- } else if len(t) == 0 {
- bloom = whisper.MakeFullNodeBloom()
- } else {
- fmt.Println("Error: topic is invalid, request aborted")
- continue
- }
-
- if timeUpp == 0 {
- timeUpp = 0xFFFFFFFF
- }
-
- data := make([]byte, 8, 8+whisper.BloomFilterSize)
- binary.BigEndian.PutUint32(data, timeLow)
- binary.BigEndian.PutUint32(data[4:], timeUpp)
- data = append(data, bloom...)
-
- var params whisper.MessageParams
- params.PoW = *argServerPoW
- params.Payload = data
- params.KeySym = key
- params.Src = asymKey
- params.WorkTime = 5
-
- msg, err := whisper.NewSentMessage(¶ms)
- if err != nil {
- utils.Fatalf("failed to create new message: %s", err)
- }
- env, err := msg.Wrap(¶ms)
- if err != nil {
- utils.Fatalf("Wrap failed: %s", err)
- }
-
- err = shh.RequestHistoricMessages(peerID, env)
- if err != nil {
- utils.Fatalf("Failed to send P2P message: %s", err)
- }
-
- time.Sleep(time.Second * 5)
- }
-}
-
-func extractIDFromEnode(s string) []byte {
- n, err := enode.Parse(enode.ValidSchemes, s)
- if err != nil {
- utils.Fatalf("Failed to parse node: %s", err)
- }
- return n.ID().Bytes()
-}
-
-// obfuscateBloom adds 16 random bits to the bloom
-// filter, in order to obfuscate the containing topics.
-// it does so deterministically within every session.
-// despite additional bits, it will match on average
-// 32000 times less messages than full node's bloom filter.
-func obfuscateBloom(bloom []byte) {
- const half = entropySize / 2
- for i := 0; i < half; i++ {
- x := int(entropy[i])
- if entropy[half+i] < 128 {
- x += 256
- }
-
- bloom[x/8] = 1 << uint(x%8) // set the bit number X
- }
-}
diff --git a/go.mod b/go.mod
index 2299eb501753..ab9f41d0d475 100644
--- a/go.mod
+++ b/go.mod
@@ -8,59 +8,60 @@ require (
github.com/Azure/go-autorest/autorest/adal v0.8.0 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.5.7
- github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847
+ github.com/aristanetworks/goarista v0.0.0-20191023202215-f096da5361bb
github.com/aws/aws-sdk-go v1.25.48
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6
github.com/cespare/cp v0.1.0
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9
github.com/davecgh/go-spew v1.1.1
- github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea
+ github.com/deckarep/golang-set v1.7.1
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf
github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87
- github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c
- github.com/fatih/color v1.3.0
- github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc
- github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff
+ github.com/edsrzf/mmap-go v1.0.0
+ github.com/ethereum/whisper v0.0.0-20200722130531-908586bd9448
+ github.com/fatih/color v1.7.0
+ github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5
+ github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect
github.com/go-stack/stack v1.8.0
- github.com/golang/protobuf v1.3.2-0.20190517061210-b285ee9cfc6c
+ github.com/golang/protobuf v1.3.2
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26
github.com/google/go-cmp v0.3.1 // indirect
- github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989
+ github.com/gorilla/websocket v1.4.1
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277
github.com/hashicorp/golang-lru v0.5.4
github.com/holiman/uint256 v1.1.1
github.com/huin/goupnp v1.0.0
- github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883
+ github.com/influxdata/influxdb v1.7.9
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458
- github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21
- github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356
+ github.com/julienschmidt/httprouter v1.2.0
+ github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9
github.com/kr/pretty v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
- github.com/mattn/go-colorable v0.1.0
- github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035
+ github.com/mattn/go-colorable v0.1.4
+ github.com/mattn/go-isatty v0.0.10
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
- github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c
- github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222
+ github.com/olekukonko/tablewriter v0.0.2
+ github.com/pborman/uuid v1.2.0
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
- github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150
- github.com/rjeczalik/notify v0.9.1
- github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00
+ github.com/prometheus/tsdb v0.10.0
+ github.com/rjeczalik/notify v0.9.2
+ github.com/rs/cors v1.7.0
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521 // indirect
github.com/shirou/gopsutil v2.20.5+incompatible
- github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
+ github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/stretchr/testify v1.4.0
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
- github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef
+ github.com/tyler-smith/go-bip39 v1.0.2
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
- golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
+ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
diff --git a/go.sum b/go.sum
index 4c46eeb5afb0..1519c2ce42bd 100644
--- a/go.sum
+++ b/go.sum
@@ -1,3 +1,4 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
github.com/Azure/azure-pipeline-go v0.2.2 h1:6oiIS9yaG6XCCzhgAgKFfIWyo4LLCiDhZot6ltoThhY=
github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc=
@@ -20,7 +21,10 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L
github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k=
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
+github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
+github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw=
@@ -29,11 +33,20 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
+github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
+github.com/apilayer/freegeoip v3.5.0+incompatible/go.mod h1:CUfFqErhFhXneJendyQ/rRcuA8kH8JxHvYnbOozmlCU=
+github.com/aristanetworks/fsnotify v1.4.2/go.mod h1:D/rtu7LpjYM8tRJphJ0hUBYpjai8SfX+aSNsWDTq/Ks=
+github.com/aristanetworks/glog v0.0.0-20180419172825-c15b03b3054f/go.mod h1:KASm+qXFKs/xjSoWn30NrWBBvdTTQq+UjkhjEJHfSFA=
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 h1:rtI0fD4oG/8eVokGVPYJEW1F88p1ZNgXiEIs9thEE4A=
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ=
+github.com/aristanetworks/goarista v0.0.0-20191023202215-f096da5361bb h1:gXDS2cX8AS8KbnP32J6XMSjzC1FhHEdHfUUCy018VrA=
+github.com/aristanetworks/goarista v0.0.0-20191023202215-f096da5361bb/go.mod h1:Z4RTxGAuYhPzcq8+EdRM+R8M48Ssle2TsWtwRKa+vns=
+github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc=
github.com/aws/aws-sdk-go v1.25.48 h1:J82DYDGZHOKHdhx6hD24Tm30c2C3GchYGfN0mf9iKUk=
github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
+github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
+github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6 h1:Eey/GGQ/E5Xp1P2Lyx1qj007hLZfbi0+CoVeJruGCtI=
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
@@ -42,6 +55,7 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9 h1:J82+/8rub3qSy0HxEnoYD8cs+HDlHWYrqYXe2Vqxluk=
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
@@ -50,6 +64,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0=
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
+github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
+github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -59,20 +75,37 @@ github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf h1:sh8rkQZavChcmak
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87 h1:OMbqMXf9OAXzH1dDH82mQMrddBE8LIIwDtxeK4wE1/A=
github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
+github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
+github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
+github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c h1:JHHhtb9XWJrGNMcrVP6vyzO4dusgi/HnceHTgxSejUM=
github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
+github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
+github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
+github.com/elastic/gosigar v0.10.5/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs=
+github.com/ethereum/go-ethereum v1.9.17/go.mod h1:kihoiSg74VC4dZAXMkmoWp70oQabz48BJg1tuzricFc=
+github.com/ethereum/whisper v0.0.0-20200722130531-908586bd9448 h1:ay7ckHlEImDlzQfN573ocGZq9vCrxAnJ83+wqfkNw3M=
+github.com/ethereum/whisper v0.0.0-20200722130531-908586bd9448/go.mod h1:P2qvdDzflqfh+J8Vvsctq/jxHwmqwGMtZDpyWnlIEFc=
github.com/fatih/color v1.3.0 h1:YehCCcyeQ6Km0D6+IapqPinWBK6y+0eB5umvZXK9WPs=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
+github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
+github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc h1:jtW8jbpkO4YirRSyepBOH8E+2HEw6/hKkBvFPwhUN8c=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
+github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
+github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
+github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays=
+github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0 h1:8HUsc87TaSWLKwrnumgC8/YconD2fJQsRJAsWaPg2ic=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
+github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible h1:0b/xya7BKGhXuqFESKM4oIiRo9WOt2ebz7KxfreD6ug=
@@ -80,23 +113,38 @@ github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2-0.20190517061210-b285ee9cfc6c h1:zqAKixg3cTcIasAMJV+EcfVbWwLpOZ7LeoWJvcuD/5Q=
github.com/golang/protobuf v1.3.2-0.20190517061210-b285ee9cfc6c/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26 h1:lMm2hD9Fy0ynom5+85/pbdkiYcBqM1JWmhpAXLmy0fw=
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
+github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989 h1:giknQ4mEuDFmmHSrGcbargOuLHQGtywqo4mheITex54=
github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
+github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
+github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277 h1:E0whKxgp2ojts0FDgUA8dl62bmH0LxKanMoBr6MDTDM=
github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc=
+github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
+github.com/holiman/uint256 v1.1.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.1.1 h1:4JywC80b+/hSfljFlEBLHrrh+CIONLDz9NuFl0af4Mw=
github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
+github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
@@ -104,14 +152,27 @@ github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883 h1:FSeK4fZCo8u40n2JMnyAsd6x7+SbvoOMHvQOU/n10P4=
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
+github.com/influxdata/influxdb v1.7.9 h1:uSeBTNO4rBkbp1Be5FKRsAmglM9nlx25TzVQRQt1An4=
+github.com/influxdata/influxdb v1.7.9/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
+github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458 h1:6OvNmYgJyexcZ3pYbTI9jWx5tHo1Dee/tWbLMfPe2TA=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
+github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
+github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
+github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21 h1:F/iKcka0K2LgnKy/fgSBf235AETtm1n1TvBzqu40LE0=
github.com/julienschmidt/httprouter v1.1.1-0.20170430222011-975b5c4c7c21/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
+github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
+github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356 h1:I/yrLt2WilKxlQKCM52clh5rGzTKpVctGT1lH4Dc8Jw=
github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
+github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 h1:ZHuwnjpP8LsVsUYqTqeVAI+GfDfJ6UNPrExZF+vX/DQ=
+github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU=
+github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
+github.com/klauspost/reedsolomon v1.9.2/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -123,15 +184,26 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
+github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
+github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d h1:oNAwILwmgWKFpuU+dXvI6dl9jG2mAWAZLX3r9s0PPiw=
github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc=
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 h1:USWjF42jDCSEeikX/G1g40ZWnsPXN5WkZ4jMHZWyBK4=
github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
+github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
+github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
+github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcouEdwIeOtOGA/ELRUw/GwvxwfT+0=
@@ -140,72 +212,133 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c h1:1RHs3tNxjXGHeul8z2t6H2N2TlAqpKe5yryJztRx4Jk=
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
+github.com/olekukonko/tablewriter v0.0.2 h1:sq53g+DWf0J6/ceFUHpQ0nAEb6WgM++fq16MZ91cS6o=
+github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
+github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
+github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc=
+github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696/go.mod h1:ym2A+zigScwkSEb/cVQB0/ZMpU3rqiH6X7WRRsxgOGw=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
+github.com/oschwald/maxminddb-golang v1.5.0/go.mod h1:3jhIUymTJ5VREKyIhWm66LJiQt04F0UCDdodShpjWsY=
github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222 h1:goeTyGkArOZIVOMA0dQbyuPWGNQJZGPwPu/QS9GlpnA=
github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
+github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
+github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
+github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
+github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
+github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
+github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
+github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
+github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
+github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
+github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150 h1:ZeU+auZj1iNzN8iVhff6M38Mfu73FQiJve/GEXYJBjE=
github.com/prometheus/tsdb v0.6.2-0.20190402121629-4f204dcbc150/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
+github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic=
+github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4=
+github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
+github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
+github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
+github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00 h1:8DPul/X0IT/1TNMIxoKLwdemEOBBHDC/K4EB16Cw5WE=
github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
+github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
+github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521 h1:3hxavr+IHMsQBrYUPQM5v0CgENFktkkbg1sfpgM3h20=
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shirou/gopsutil v2.20.5+incompatible h1:tYH07UPoQt0OCQdgWWMgYHy3/a9bcxNpBIysykNIP7I=
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
+github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 h1:Gb2Tyox57NRNuZ2d3rmvB3pcmbu7O1RS3m8WRx7ilrg=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
+github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 h1:ju5UTwk5Odtm4trrY+4Ca4RMj5OyXbmVeDAVad2T0Jw=
+github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 h1:gIlAHnH1vJb5vwEjIp5kBj/eu99p/bl0Ay2goiPe5xE=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 h1:njlZPzLwU639dk2kqnCPPv+wNjq7Xb6EfUxe/oX0/NM=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
+github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
+github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
+github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZW24CsNJDfeh9Ex6Pm0Rcpc7qrgKBiL44vF4=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
+github.com/tyler-smith/go-bip39 v1.0.2 h1:+t3w+KwLXO6154GNJY+qUtIxLTmFjfUmpguQT1OlOT8=
+github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 h1:1cngl9mPEoITZG8s8cVcUy5CeIBYhEESkOB7m6Gmkrk=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees=
+github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
+github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
+github.com/xtaci/kcp-go v5.4.5+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
+github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
+golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -214,16 +347,31 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.0.0-20190912185636-87d9f09c5d89/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
+gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
+gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=
+gopkg.in/jcmturner/dnsutils.v1 v1.0.1/go.mod h1:m3v+5svpVOhtFAP/wSz+yzh4Mc0Fg7eRhxkJMWSIz9Q=
+gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
+gopkg.in/jcmturner/gokrb5.v7 v7.2.3/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM=
+gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 h1:a6cXbcDDUkSBlpnkWV1bJ+vv3mOgQEltEJ2rPxroVu0=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns=
+gopkg.in/redis.v4 v4.2.4/go.mod h1:8KREHdypkCEojGKQcjMqAODMICIVwZAONWq8RowTITA=
+gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
@@ -233,3 +381,4 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/mobile/geth.go b/mobile/geth.go
index f20243426b5f..ca26960af545 100644
--- a/mobile/geth.go
+++ b/mobile/geth.go
@@ -35,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/params"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
)
// NodeConfig represents the collection of configuration values to fine tune the Geth
@@ -71,9 +70,6 @@ type NodeConfig struct {
// It has the form "nodename:secret@host:port"
EthereumNetStats string
- // WhisperEnabled specifies whether the node should run the Whisper protocol.
- WhisperEnabled bool
-
// Listening address of pprof server.
PprofAddress string
}
@@ -192,14 +188,6 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
}
}
}
- // Register the Whisper protocol if requested
- if config.WhisperEnabled {
- if err := rawStack.Register(func(*node.ServiceContext) (node.Service, error) {
- return whisper.New(&whisper.DefaultConfig), nil
- }); err != nil {
- return nil, fmt.Errorf("whisper init: %v", err)
- }
- }
return &Node{rawStack}, nil
}
diff --git a/mobile/shhclient.go b/mobile/shhclient.go
deleted file mode 100644
index 90a8b83c39f9..000000000000
--- a/mobile/shhclient.go
+++ /dev/null
@@ -1,195 +0,0 @@
-// Copyright 2018 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Contains a wrapper for the Whisper client.
-
-package geth
-
-import (
- "github.com/ethereum/go-ethereum/whisper/shhclient"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
-)
-
-// WhisperClient provides access to the Ethereum APIs.
-type WhisperClient struct {
- client *shhclient.Client
-}
-
-// NewWhisperClient connects a client to the given URL.
-func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) {
- rawClient, err := shhclient.Dial(rawurl)
- return &WhisperClient{rawClient}, err
-}
-
-// GetVersion returns the Whisper sub-protocol version.
-func (wc *WhisperClient) GetVersion(ctx *Context) (version string, _ error) {
- return wc.client.Version(ctx.context)
-}
-
-// Info returns diagnostic information about the whisper node.
-func (wc *WhisperClient) GetInfo(ctx *Context) (info *Info, _ error) {
- rawInfo, err := wc.client.Info(ctx.context)
- return &Info{&rawInfo}, err
-}
-
-// SetMaxMessageSize sets the maximal message size allowed by this node. Incoming
-// and outgoing messages with a larger size will be rejected. Whisper message size
-// can never exceed the limit imposed by the underlying P2P protocol (10 Mb).
-func (wc *WhisperClient) SetMaxMessageSize(ctx *Context, size int32) error {
- return wc.client.SetMaxMessageSize(ctx.context, uint32(size))
-}
-
-// SetMinimumPoW (experimental) sets the minimal PoW required by this node.
-// This experimental function was introduced for the future dynamic adjustment of
-// PoW requirement. If the node is overwhelmed with messages, it should raise the
-// PoW requirement and notify the peers. The new value should be set relative to
-// the old value (e.g. double). The old value could be obtained via shh_info call.
-func (wc *WhisperClient) SetMinimumPoW(ctx *Context, pow float64) error {
- return wc.client.SetMinimumPoW(ctx.context, pow)
-}
-
-// Marks specific peer trusted, which will allow it to send historic (expired) messages.
-// Note This function is not adding new nodes, the node needs to exists as a peer.
-func (wc *WhisperClient) MarkTrustedPeer(ctx *Context, enode string) error {
- return wc.client.MarkTrustedPeer(ctx.context, enode)
-}
-
-// NewKeyPair generates a new public and private key pair for message decryption and encryption.
-// It returns an identifier that can be used to refer to the key.
-func (wc *WhisperClient) NewKeyPair(ctx *Context) (string, error) {
- return wc.client.NewKeyPair(ctx.context)
-}
-
-// AddPrivateKey stored the key pair, and returns its ID.
-func (wc *WhisperClient) AddPrivateKey(ctx *Context, key []byte) (string, error) {
- return wc.client.AddPrivateKey(ctx.context, key)
-}
-
-// DeleteKeyPair delete the specifies key.
-func (wc *WhisperClient) DeleteKeyPair(ctx *Context, id string) (string, error) {
- return wc.client.DeleteKeyPair(ctx.context, id)
-}
-
-// HasKeyPair returns an indication if the node has a private key or
-// key pair matching the given ID.
-func (wc *WhisperClient) HasKeyPair(ctx *Context, id string) (bool, error) {
- return wc.client.HasKeyPair(ctx.context, id)
-}
-
-// GetPublicKey return the public key for a key ID.
-func (wc *WhisperClient) GetPublicKey(ctx *Context, id string) ([]byte, error) {
- return wc.client.PublicKey(ctx.context, id)
-}
-
-// GetPrivateKey return the private key for a key ID.
-func (wc *WhisperClient) GetPrivateKey(ctx *Context, id string) ([]byte, error) {
- return wc.client.PrivateKey(ctx.context, id)
-}
-
-// NewSymmetricKey generates a random symmetric key and returns its identifier.
-// Can be used encrypting and decrypting messages where the key is known to both parties.
-func (wc *WhisperClient) NewSymmetricKey(ctx *Context) (string, error) {
- return wc.client.NewSymmetricKey(ctx.context)
-}
-
-// AddSymmetricKey stores the key, and returns its identifier.
-func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, error) {
- return wc.client.AddSymmetricKey(ctx.context, key)
-}
-
-// GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier.
-func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd string) (string, error) {
- return wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd)
-}
-
-// HasSymmetricKey returns an indication if the key associated with the given id is stored in the node.
-func (wc *WhisperClient) HasSymmetricKey(ctx *Context, id string) (bool, error) {
- return wc.client.HasSymmetricKey(ctx.context, id)
-}
-
-// GetSymmetricKey returns the symmetric key associated with the given identifier.
-func (wc *WhisperClient) GetSymmetricKey(ctx *Context, id string) ([]byte, error) {
- return wc.client.GetSymmetricKey(ctx.context, id)
-}
-
-// DeleteSymmetricKey deletes the symmetric key associated with the given identifier.
-func (wc *WhisperClient) DeleteSymmetricKey(ctx *Context, id string) error {
- return wc.client.DeleteSymmetricKey(ctx.context, id)
-}
-
-// Post a message onto the network.
-func (wc *WhisperClient) Post(ctx *Context, message *NewMessage) (string, error) {
- return wc.client.Post(ctx.context, *message.newMessage)
-}
-
-// NewHeadHandler is a client-side subscription callback to invoke on events and
-// subscription failure.
-type NewMessageHandler interface {
- OnNewMessage(message *Message)
- OnError(failure string)
-}
-
-// SubscribeMessages subscribes to messages that match the given criteria. This method
-// is only supported on bi-directional connections such as websockets and IPC.
-// NewMessageFilter uses polling and is supported over HTTP.
-func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, handler NewMessageHandler, buffer int) (*Subscription, error) {
- // Subscribe to the event internally
- ch := make(chan *whisper.Message, buffer)
- rawSub, err := wc.client.SubscribeMessages(ctx.context, *criteria.criteria, ch)
- if err != nil {
- return nil, err
- }
- // Start up a dispatcher to feed into the callback
- go func() {
- for {
- select {
- case message := <-ch:
- handler.OnNewMessage(&Message{message})
-
- case err := <-rawSub.Err():
- if err != nil {
- handler.OnError(err.Error())
- }
- return
- }
- }
- }()
- return &Subscription{rawSub}, nil
-}
-
-// NewMessageFilter creates a filter within the node. This filter can be used to poll
-// for new messages (see FilterMessages) that satisfy the given criteria. A filter can
-// timeout when it was polled for in whisper.filterTimeout.
-func (wc *WhisperClient) NewMessageFilter(ctx *Context, criteria *Criteria) (string, error) {
- return wc.client.NewMessageFilter(ctx.context, *criteria.criteria)
-}
-
-// DeleteMessageFilter removes the filter associated with the given id.
-func (wc *WhisperClient) DeleteMessageFilter(ctx *Context, id string) error {
- return wc.client.DeleteMessageFilter(ctx.context, id)
-}
-
-// GetFilterMessages retrieves all messages that are received between the last call to
-// this function and match the criteria that where given when the filter was created.
-func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, error) {
- rawFilterMessages, err := wc.client.FilterMessages(ctx.context, id)
- if err != nil {
- return nil, err
- }
- res := make([]*whisper.Message, len(rawFilterMessages))
- copy(res, rawFilterMessages)
- return &Messages{res}, nil
-}
diff --git a/mobile/types.go b/mobile/types.go
index b9c44c25d7a9..a1cd063fb4ab 100644
--- a/mobile/types.go
+++ b/mobile/types.go
@@ -26,7 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
+ whisper "github.com/ethereum/whisper"
)
// A Nonce is a 64-bit hash which proves (combined with the mix-hash) that
diff --git a/tests/fuzzers/whisperv6/corpus/009c5adfa4fd685caef58e1ce932fa7fb209730a b/tests/fuzzers/whisperv6/corpus/009c5adfa4fd685caef58e1ce932fa7fb209730a
deleted file mode 100644
index af2f08267304..000000000000
Binary files a/tests/fuzzers/whisperv6/corpus/009c5adfa4fd685caef58e1ce932fa7fb209730a and /dev/null differ
diff --git a/tests/fuzzers/whisperv6/whisper-fuzzer.go b/tests/fuzzers/whisperv6/whisper-fuzzer.go
deleted file mode 100644
index 379e4224fd53..000000000000
--- a/tests/fuzzers/whisperv6/whisper-fuzzer.go
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "bytes"
-
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/rlp"
- "github.com/ethereum/go-ethereum/whisper/whisperv6"
-)
-
-type MessageParams struct {
- Topic whisperv6.TopicType
- WorkTime uint32
- TTL uint32
- KeySym []byte
- Payload []byte
-}
-
-//export fuzzer_entry
-func Fuzz(input []byte) int {
-
- var paramsDecoded MessageParams
- err := rlp.DecodeBytes(input, ¶msDecoded)
- if err != nil {
- return 0
- }
- var params whisperv6.MessageParams
- params.KeySym = make([]byte, 32)
- if len(paramsDecoded.KeySym) <= 32 {
- copy(params.KeySym, paramsDecoded.KeySym)
- }
- if input[0] == 255 {
- params.PoW = 0.01
- params.WorkTime = 1
- } else {
- params.PoW = 0
- params.WorkTime = 0
- }
- params.TTL = paramsDecoded.TTL
- params.Payload = paramsDecoded.Payload
- text := make([]byte, 0, 512)
- text = append(text, params.Payload...)
- params.Topic = paramsDecoded.Topic
- params.Src, err = crypto.GenerateKey()
- if err != nil {
- return 0
- }
- msg, err := whisperv6.NewSentMessage(¶ms)
- if err != nil {
- panic(err)
- //return
- }
- env, err := msg.Wrap(¶ms)
- if err != nil {
- panic(err)
- }
- decrypted, err := env.OpenSymmetric(params.KeySym)
- if err != nil {
- panic(err)
- }
- if !decrypted.ValidateAndParse() {
- panic("ValidateAndParse failed")
- }
- if !bytes.Equal(text, decrypted.Payload) {
- panic("text != decrypted.Payload")
- }
- if len(decrypted.Signature) != 65 {
- panic("Unexpected signature length")
- }
- if !whisperv6.IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) {
- panic("Unexpected public key")
- }
- return 0
-}
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
deleted file mode 100644
index 7312bbe23daf..000000000000
--- a/whisper/mailserver/mailserver.go
+++ /dev/null
@@ -1,209 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Package mailserver provides a naive, example mailserver implementation
-package mailserver
-
-import (
- "encoding/binary"
- "fmt"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/rlp"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
- "github.com/syndtr/goleveldb/leveldb"
- "github.com/syndtr/goleveldb/leveldb/errors"
- "github.com/syndtr/goleveldb/leveldb/opt"
- "github.com/syndtr/goleveldb/leveldb/util"
-)
-
-// WMailServer represents the state data of the mailserver.
-type WMailServer struct {
- db *leveldb.DB
- w *whisper.Whisper
- pow float64
- key []byte
-}
-
-type DBKey struct {
- timestamp uint32
- hash common.Hash
- raw []byte
-}
-
-// NewDbKey is a helper function that creates a levelDB
-// key from a hash and an integer.
-func NewDbKey(t uint32, h common.Hash) *DBKey {
- const sz = common.HashLength + 4
- var k DBKey
- k.timestamp = t
- k.hash = h
- k.raw = make([]byte, sz)
- binary.BigEndian.PutUint32(k.raw, k.timestamp)
- copy(k.raw[4:], k.hash[:])
- return &k
-}
-
-// Init initializes the mail server.
-func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, pow float64) error {
- var err error
- if len(path) == 0 {
- return fmt.Errorf("DB file is not specified")
- }
-
- if len(password) == 0 {
- return fmt.Errorf("password is not specified")
- }
-
- s.db, err = leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 32})
- if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
- s.db, err = leveldb.RecoverFile(path, nil)
- }
- if err != nil {
- return fmt.Errorf("open DB file: %s", err)
- }
-
- s.w = shh
- s.pow = pow
-
- MailServerKeyID, err := s.w.AddSymKeyFromPassword(password)
- if err != nil {
- return fmt.Errorf("create symmetric key: %s", err)
- }
- s.key, err = s.w.GetSymKey(MailServerKeyID)
- if err != nil {
- return fmt.Errorf("save symmetric key: %s", err)
- }
- return nil
-}
-
-// Close cleans up before shutdown.
-func (s *WMailServer) Close() {
- if s.db != nil {
- s.db.Close()
- }
-}
-
-// Archive stores the
-func (s *WMailServer) Archive(env *whisper.Envelope) {
- key := NewDbKey(env.Expiry-env.TTL, env.Hash())
- rawEnvelope, err := rlp.EncodeToBytes(env)
- if err != nil {
- log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
- } else {
- err = s.db.Put(key.raw, rawEnvelope, nil)
- if err != nil {
- log.Error(fmt.Sprintf("Writing to DB failed: %s", err))
- }
- }
-}
-
-// DeliverMail responds with saved messages upon request by the
-// messages' owner.
-func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope) {
- if peer == nil {
- log.Error("Whisper peer is nil")
- return
- }
-
- ok, lower, upper, bloom := s.validateRequest(peer.ID(), request)
- if ok {
- s.processRequest(peer, lower, upper, bloom)
- }
-}
-
-func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, bloom []byte) []*whisper.Envelope {
- ret := make([]*whisper.Envelope, 0)
- var err error
- var zero common.Hash
- kl := NewDbKey(lower, zero)
- ku := NewDbKey(upper+1, zero) // LevelDB is exclusive, while the Whisper API is inclusive
- i := s.db.NewIterator(&util.Range{Start: kl.raw, Limit: ku.raw}, nil)
- defer i.Release()
-
- for i.Next() {
- var envelope whisper.Envelope
- err = rlp.DecodeBytes(i.Value(), &envelope)
- if err != nil {
- log.Error(fmt.Sprintf("RLP decoding failed: %s", err))
- }
-
- if whisper.BloomFilterMatch(bloom, envelope.Bloom()) {
- if peer == nil {
- // used for test purposes
- ret = append(ret, &envelope)
- } else {
- err = s.w.SendP2PDirect(peer, &envelope)
- if err != nil {
- log.Error(fmt.Sprintf("Failed to send direct message to peer: %s", err))
- return nil
- }
- }
- }
- }
-
- err = i.Error()
- if err != nil {
- log.Error(fmt.Sprintf("Level DB iterator error: %s", err))
- }
-
- return ret
-}
-
-func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope) (bool, uint32, uint32, []byte) {
- if s.pow > 0.0 && request.PoW() < s.pow {
- return false, 0, 0, nil
- }
-
- f := whisper.Filter{KeySym: s.key}
- decrypted := request.Open(&f)
- if decrypted == nil {
- log.Warn("Failed to decrypt p2p request")
- return false, 0, 0, nil
- }
-
- src := crypto.FromECDSAPub(decrypted.Src)
- if len(src)-len(peerID) == 1 {
- src = src[1:]
- }
-
- // if you want to check the signature, you can do it here. e.g.:
- // if !bytes.Equal(peerID, src) {
- if src == nil {
- log.Warn("Wrong signature of p2p request")
- return false, 0, 0, nil
- }
-
- var bloom []byte
- payloadSize := len(decrypted.Payload)
- if payloadSize < 8 {
- log.Warn("Undersized p2p request")
- return false, 0, 0, nil
- } else if payloadSize == 8 {
- bloom = whisper.MakeFullNodeBloom()
- } else if payloadSize < 8+whisper.BloomFilterSize {
- log.Warn("Undersized bloom filter in p2p request")
- return false, 0, 0, nil
- } else {
- bloom = decrypted.Payload[8 : 8+whisper.BloomFilterSize]
- }
-
- lower := binary.BigEndian.Uint32(decrypted.Payload[:4])
- upper := binary.BigEndian.Uint32(decrypted.Payload[4:8])
- return true, lower, upper, bloom
-}
diff --git a/whisper/mailserver/server_test.go b/whisper/mailserver/server_test.go
deleted file mode 100644
index 4f80e550aa22..000000000000
--- a/whisper/mailserver/server_test.go
+++ /dev/null
@@ -1,212 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package mailserver
-
-import (
- "bytes"
- "crypto/ecdsa"
- "encoding/binary"
- "io/ioutil"
- "math/rand"
- "testing"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
-)
-
-const powRequirement = 0.00001
-
-var keyID string
-var shh *whisper.Whisper
-var seed = time.Now().Unix()
-
-type ServerTestParams struct {
- topic whisper.TopicType
- low uint32
- upp uint32
- key *ecdsa.PrivateKey
-}
-
-func assert(statement bool, text string, t *testing.T) {
- if !statement {
- t.Fatal(text)
- }
-}
-
-func TestDBKey(t *testing.T) {
- var h common.Hash
- i := uint32(time.Now().Unix())
- k := NewDbKey(i, h)
- assert(len(k.raw) == common.HashLength+4, "wrong DB key length", t)
- assert(byte(i%0x100) == k.raw[3], "raw representation should be big endian", t)
- assert(byte(i/0x1000000) == k.raw[0], "big endian expected", t)
-}
-
-func generateEnvelope(t *testing.T) *whisper.Envelope {
- h := crypto.Keccak256Hash([]byte("test sample data"))
- params := &whisper.MessageParams{
- KeySym: h[:],
- Topic: whisper.TopicType{0x1F, 0x7E, 0xA1, 0x7F},
- Payload: []byte("test payload"),
- PoW: powRequirement,
- WorkTime: 2,
- }
-
- msg, err := whisper.NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed to wrap with seed %d: %s.", seed, err)
- }
- return env
-}
-
-func TestMailServer(t *testing.T) {
- const password = "password_for_this_test"
- const dbPath = "whisper-server-test"
-
- dir, err := ioutil.TempDir("", dbPath)
- if err != nil {
- t.Fatal(err)
- }
-
- var server WMailServer
- shh = whisper.New(&whisper.DefaultConfig)
- shh.RegisterServer(&server)
-
- err = server.Init(shh, dir, password, powRequirement)
- if err != nil {
- t.Fatal(err)
- }
- defer server.Close()
-
- keyID, err = shh.AddSymKeyFromPassword(password)
- if err != nil {
- t.Fatalf("Failed to create symmetric key for mail request: %s", err)
- }
-
- rand.Seed(seed)
- env := generateEnvelope(t)
- server.Archive(env)
- deliverTest(t, &server, env)
-}
-
-func deliverTest(t *testing.T, server *WMailServer, env *whisper.Envelope) {
- id, err := shh.NewKeyPair()
- if err != nil {
- t.Fatalf("failed to generate new key pair with seed %d: %s.", seed, err)
- }
- testPeerID, err := shh.GetPrivateKey(id)
- if err != nil {
- t.Fatalf("failed to retrieve new key pair with seed %d: %s.", seed, err)
- }
- birth := env.Expiry - env.TTL
- p := &ServerTestParams{
- topic: env.Topic,
- low: birth - 1,
- upp: birth + 1,
- key: testPeerID,
- }
-
- singleRequest(t, server, env, p, true)
-
- p.low, p.upp = birth+1, 0xffffffff
- singleRequest(t, server, env, p, false)
-
- p.low, p.upp = 0, birth-1
- singleRequest(t, server, env, p, false)
-
- p.low = birth - 1
- p.upp = birth + 1
- p.topic[0] = 0xFF
- singleRequest(t, server, env, p, false)
-}
-
-func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *ServerTestParams, expect bool) {
- request := createRequest(t, p)
- src := crypto.FromECDSAPub(&p.key.PublicKey)
- ok, lower, upper, bloom := server.validateRequest(src, request)
- if !ok {
- t.Fatalf("request validation failed, seed: %d.", seed)
- }
- if lower != p.low {
- t.Fatalf("request validation failed (lower bound), seed: %d.", seed)
- }
- if upper != p.upp {
- t.Fatalf("request validation failed (upper bound), seed: %d.", seed)
- }
- expectedBloom := whisper.TopicToBloom(p.topic)
- if !bytes.Equal(bloom, expectedBloom) {
- t.Fatalf("request validation failed (topic), seed: %d.", seed)
- }
-
- var exist bool
- mail := server.processRequest(nil, p.low, p.upp, bloom)
- for _, msg := range mail {
- if msg.Hash() == env.Hash() {
- exist = true
- break
- }
- }
-
- if exist != expect {
- t.Fatalf("error: exist = %v, seed: %d.", exist, seed)
- }
-
- src[0]++
- ok, lower, upper, _ = server.validateRequest(src, request)
- if !ok {
- // request should be valid regardless of signature
- t.Fatalf("request validation false negative, seed: %d (lower: %d, upper: %d).", seed, lower, upper)
- }
-}
-
-func createRequest(t *testing.T, p *ServerTestParams) *whisper.Envelope {
- bloom := whisper.TopicToBloom(p.topic)
- data := make([]byte, 8)
- binary.BigEndian.PutUint32(data, p.low)
- binary.BigEndian.PutUint32(data[4:], p.upp)
- data = append(data, bloom...)
-
- key, err := shh.GetSymKey(keyID)
- if err != nil {
- t.Fatalf("failed to retrieve sym key with seed %d: %s.", seed, err)
- }
-
- params := &whisper.MessageParams{
- KeySym: key,
- Topic: p.topic,
- Payload: data,
- PoW: powRequirement * 2,
- WorkTime: 2,
- Src: p.key,
- }
-
- msg, err := whisper.NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed to wrap with seed %d: %s.", seed, err)
- }
- return env
-}
diff --git a/whisper/shhclient/client.go b/whisper/shhclient/client.go
deleted file mode 100644
index 49731136744a..000000000000
--- a/whisper/shhclient/client.go
+++ /dev/null
@@ -1,193 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package shhclient
-
-import (
- "context"
-
- ethereum "github.com/ethereum/go-ethereum"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/rpc"
- whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
-)
-
-// Client defines typed wrappers for the Whisper v6 RPC API.
-type Client struct {
- c *rpc.Client
-}
-
-// Dial connects a client to the given URL.
-func Dial(rawurl string) (*Client, error) {
- c, err := rpc.Dial(rawurl)
- if err != nil {
- return nil, err
- }
- return NewClient(c), nil
-}
-
-// NewClient creates a client that uses the given RPC client.
-func NewClient(c *rpc.Client) *Client {
- return &Client{c}
-}
-
-// Version returns the Whisper sub-protocol version.
-func (sc *Client) Version(ctx context.Context) (string, error) {
- var result string
- err := sc.c.CallContext(ctx, &result, "shh_version")
- return result, err
-}
-
-// Info returns diagnostic information about the whisper node.
-func (sc *Client) Info(ctx context.Context) (whisper.Info, error) {
- var info whisper.Info
- err := sc.c.CallContext(ctx, &info, "shh_info")
- return info, err
-}
-
-// SetMaxMessageSize sets the maximal message size allowed by this node. Incoming
-// and outgoing messages with a larger size will be rejected. Whisper message size
-// can never exceed the limit imposed by the underlying P2P protocol (10 Mb).
-func (sc *Client) SetMaxMessageSize(ctx context.Context, size uint32) error {
- var ignored bool
- return sc.c.CallContext(ctx, &ignored, "shh_setMaxMessageSize", size)
-}
-
-// SetMinimumPoW (experimental) sets the minimal PoW required by this node.
-// This experimental function was introduced for the future dynamic adjustment of
-// PoW requirement. If the node is overwhelmed with messages, it should raise the
-// PoW requirement and notify the peers. The new value should be set relative to
-// the old value (e.g. double). The old value could be obtained via shh_info call.
-func (sc *Client) SetMinimumPoW(ctx context.Context, pow float64) error {
- var ignored bool
- return sc.c.CallContext(ctx, &ignored, "shh_setMinPoW", pow)
-}
-
-// MarkTrustedPeer marks specific peer trusted, which will allow it to send historic (expired) messages.
-// Note This function is not adding new nodes, the node needs to exists as a peer.
-func (sc *Client) MarkTrustedPeer(ctx context.Context, enode string) error {
- var ignored bool
- return sc.c.CallContext(ctx, &ignored, "shh_markTrustedPeer", enode)
-}
-
-// NewKeyPair generates a new public and private key pair for message decryption and encryption.
-// It returns an identifier that can be used to refer to the key.
-func (sc *Client) NewKeyPair(ctx context.Context) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_newKeyPair")
-}
-
-// AddPrivateKey stored the key pair, and returns its ID.
-func (sc *Client) AddPrivateKey(ctx context.Context, key []byte) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_addPrivateKey", hexutil.Bytes(key))
-}
-
-// DeleteKeyPair delete the specifies key.
-func (sc *Client) DeleteKeyPair(ctx context.Context, id string) (string, error) {
- var ignored bool
- return id, sc.c.CallContext(ctx, &ignored, "shh_deleteKeyPair", id)
-}
-
-// HasKeyPair returns an indication if the node has a private key or
-// key pair matching the given ID.
-func (sc *Client) HasKeyPair(ctx context.Context, id string) (bool, error) {
- var has bool
- return has, sc.c.CallContext(ctx, &has, "shh_hasKeyPair", id)
-}
-
-// PublicKey return the public key for a key ID.
-func (sc *Client) PublicKey(ctx context.Context, id string) ([]byte, error) {
- var key hexutil.Bytes
- return []byte(key), sc.c.CallContext(ctx, &key, "shh_getPublicKey", id)
-}
-
-// PrivateKey return the private key for a key ID.
-func (sc *Client) PrivateKey(ctx context.Context, id string) ([]byte, error) {
- var key hexutil.Bytes
- return []byte(key), sc.c.CallContext(ctx, &key, "shh_getPrivateKey", id)
-}
-
-// NewSymmetricKey generates a random symmetric key and returns its identifier.
-// Can be used encrypting and decrypting messages where the key is known to both parties.
-func (sc *Client) NewSymmetricKey(ctx context.Context) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_newSymKey")
-}
-
-// AddSymmetricKey stores the key, and returns its identifier.
-func (sc *Client) AddSymmetricKey(ctx context.Context, key []byte) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_addSymKey", hexutil.Bytes(key))
-}
-
-// GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier.
-func (sc *Client) GenerateSymmetricKeyFromPassword(ctx context.Context, passwd string) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_generateSymKeyFromPassword", passwd)
-}
-
-// HasSymmetricKey returns an indication if the key associated with the given id is stored in the node.
-func (sc *Client) HasSymmetricKey(ctx context.Context, id string) (bool, error) {
- var found bool
- return found, sc.c.CallContext(ctx, &found, "shh_hasSymKey", id)
-}
-
-// GetSymmetricKey returns the symmetric key associated with the given identifier.
-func (sc *Client) GetSymmetricKey(ctx context.Context, id string) ([]byte, error) {
- var key hexutil.Bytes
- return []byte(key), sc.c.CallContext(ctx, &key, "shh_getSymKey", id)
-}
-
-// DeleteSymmetricKey deletes the symmetric key associated with the given identifier.
-func (sc *Client) DeleteSymmetricKey(ctx context.Context, id string) error {
- var ignored bool
- return sc.c.CallContext(ctx, &ignored, "shh_deleteSymKey", id)
-}
-
-// Post a message onto the network.
-func (sc *Client) Post(ctx context.Context, message whisper.NewMessage) (string, error) {
- var hash string
- return hash, sc.c.CallContext(ctx, &hash, "shh_post", message)
-}
-
-// SubscribeMessages subscribes to messages that match the given criteria. This method
-// is only supported on bi-directional connections such as websockets and IPC.
-// NewMessageFilter uses polling and is supported over HTTP.
-func (sc *Client) SubscribeMessages(ctx context.Context, criteria whisper.Criteria, ch chan<- *whisper.Message) (ethereum.Subscription, error) {
- return sc.c.ShhSubscribe(ctx, ch, "messages", criteria)
-}
-
-// NewMessageFilter creates a filter within the node. This filter can be used to poll
-// for new messages (see FilterMessages) that satisfy the given criteria. A filter can
-// timeout when it was polled for in whisper.filterTimeout.
-func (sc *Client) NewMessageFilter(ctx context.Context, criteria whisper.Criteria) (string, error) {
- var id string
- return id, sc.c.CallContext(ctx, &id, "shh_newMessageFilter", criteria)
-}
-
-// DeleteMessageFilter removes the filter associated with the given id.
-func (sc *Client) DeleteMessageFilter(ctx context.Context, id string) error {
- var ignored bool
- return sc.c.CallContext(ctx, &ignored, "shh_deleteMessageFilter", id)
-}
-
-// FilterMessages retrieves all messages that are received between the last call to
-// this function and match the criteria that where given when the filter was created.
-func (sc *Client) FilterMessages(ctx context.Context, id string) ([]*whisper.Message, error) {
- var messages []*whisper.Message
- return messages, sc.c.CallContext(ctx, &messages, "shh_getFilterMessages", id)
-}
diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go
deleted file mode 100644
index d6d4c8d3ded6..000000000000
--- a/whisper/whisperv6/api.go
+++ /dev/null
@@ -1,593 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "context"
- "crypto/ecdsa"
- "errors"
- "fmt"
- "sync"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p/enode"
- "github.com/ethereum/go-ethereum/rpc"
-)
-
-// List of errors
-var (
- ErrSymAsym = errors.New("specify either a symmetric or an asymmetric key")
- ErrInvalidSymmetricKey = errors.New("invalid symmetric key")
- ErrInvalidPublicKey = errors.New("invalid public key")
- ErrInvalidSigningPubKey = errors.New("invalid signing public key")
- ErrTooLowPoW = errors.New("message rejected, PoW too low")
- ErrNoTopics = errors.New("missing topic(s)")
-)
-
-// PublicWhisperAPI provides the whisper RPC service that can be
-// use publicly without security implications.
-type PublicWhisperAPI struct {
- w *Whisper
-
- mu sync.Mutex
- lastUsed map[string]time.Time // keeps track when a filter was polled for the last time.
-}
-
-// NewPublicWhisperAPI create a new RPC whisper service.
-func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI {
- api := &PublicWhisperAPI{
- w: w,
- lastUsed: make(map[string]time.Time),
- }
- return api
-}
-
-// Version returns the Whisper sub-protocol version.
-func (api *PublicWhisperAPI) Version(ctx context.Context) string {
- return ProtocolVersionStr
-}
-
-// Info contains diagnostic information.
-type Info struct {
- Memory int `json:"memory"` // Memory size of the floating messages in bytes.
- Messages int `json:"messages"` // Number of floating messages.
- MinPow float64 `json:"minPow"` // Minimal accepted PoW
- MaxMessageSize uint32 `json:"maxMessageSize"` // Maximum accepted message size
-}
-
-// Info returns diagnostic information about the whisper node.
-func (api *PublicWhisperAPI) Info(ctx context.Context) Info {
- stats := api.w.Stats()
- return Info{
- Memory: stats.memoryUsed,
- Messages: len(api.w.messageQueue) + len(api.w.p2pMsgQueue),
- MinPow: api.w.MinPow(),
- MaxMessageSize: api.w.MaxMessageSize(),
- }
-}
-
-// SetMaxMessageSize sets the maximum message size that is accepted.
-// Upper limit is defined by MaxMessageSize.
-func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32) (bool, error) {
- return true, api.w.SetMaxMessageSize(size)
-}
-
-// SetMinPoW sets the minimum PoW, and notifies the peers.
-func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
- return true, api.w.SetMinimumPoW(pow)
-}
-
-// SetBloomFilter sets the new value of bloom filter, and notifies the peers.
-func (api *PublicWhisperAPI) SetBloomFilter(ctx context.Context, bloom hexutil.Bytes) (bool, error) {
- return true, api.w.SetBloomFilter(bloom)
-}
-
-// MarkTrustedPeer marks a peer trusted, which will allow it to send historic (expired) messages.
-// Note: This function is not adding new nodes, the node needs to exists as a peer.
-func (api *PublicWhisperAPI) MarkTrustedPeer(ctx context.Context, url string) (bool, error) {
- n, err := enode.Parse(enode.ValidSchemes, url)
- if err != nil {
- return false, err
- }
- return true, api.w.AllowP2PMessagesFromPeer(n.ID().Bytes())
-}
-
-// NewKeyPair generates a new public and private key pair for message decryption and encryption.
-// It returns an ID that can be used to refer to the keypair.
-func (api *PublicWhisperAPI) NewKeyPair(ctx context.Context) (string, error) {
- return api.w.NewKeyPair()
-}
-
-// AddPrivateKey imports the given private key.
-func (api *PublicWhisperAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) {
- key, err := crypto.ToECDSA(privateKey)
- if err != nil {
- return "", err
- }
- return api.w.AddKeyPair(key)
-}
-
-// DeleteKeyPair removes the key with the given key if it exists.
-func (api *PublicWhisperAPI) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
- if ok := api.w.DeleteKeyPair(key); ok {
- return true, nil
- }
- return false, fmt.Errorf("key pair %s not found", key)
-}
-
-// HasKeyPair returns an indication if the node has a key pair that is associated with the given id.
-func (api *PublicWhisperAPI) HasKeyPair(ctx context.Context, id string) bool {
- return api.w.HasKeyPair(id)
-}
-
-// GetPublicKey returns the public key associated with the given key. The key is the hex
-// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
-func (api *PublicWhisperAPI) GetPublicKey(ctx context.Context, id string) (hexutil.Bytes, error) {
- key, err := api.w.GetPrivateKey(id)
- if err != nil {
- return hexutil.Bytes{}, err
- }
- return crypto.FromECDSAPub(&key.PublicKey), nil
-}
-
-// GetPrivateKey returns the private key associated with the given key. The key is the hex
-// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
-func (api *PublicWhisperAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error) {
- key, err := api.w.GetPrivateKey(id)
- if err != nil {
- return hexutil.Bytes{}, err
- }
- return crypto.FromECDSA(key), nil
-}
-
-// NewSymKey generate a random symmetric key.
-// It returns an ID that can be used to refer to the key.
-// Can be used encrypting and decrypting messages where the key is known to both parties.
-func (api *PublicWhisperAPI) NewSymKey(ctx context.Context) (string, error) {
- return api.w.GenerateSymKey()
-}
-
-// AddSymKey import a symmetric key.
-// It returns an ID that can be used to refer to the key.
-// Can be used encrypting and decrypting messages where the key is known to both parties.
-func (api *PublicWhisperAPI) AddSymKey(ctx context.Context, key hexutil.Bytes) (string, error) {
- return api.w.AddSymKeyDirect([]byte(key))
-}
-
-// GenerateSymKeyFromPassword derive a key from the given password, stores it, and returns its ID.
-func (api *PublicWhisperAPI) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
- return api.w.AddSymKeyFromPassword(passwd)
-}
-
-// HasSymKey returns an indication if the node has a symmetric key associated with the given key.
-func (api *PublicWhisperAPI) HasSymKey(ctx context.Context, id string) bool {
- return api.w.HasSymKey(id)
-}
-
-// GetSymKey returns the symmetric key associated with the given id.
-func (api *PublicWhisperAPI) GetSymKey(ctx context.Context, id string) (hexutil.Bytes, error) {
- return api.w.GetSymKey(id)
-}
-
-// DeleteSymKey deletes the symmetric key that is associated with the given id.
-func (api *PublicWhisperAPI) DeleteSymKey(ctx context.Context, id string) bool {
- return api.w.DeleteSymKey(id)
-}
-
-// MakeLightClient turns the node into light client, which does not forward
-// any incoming messages, and sends only messages originated in this node.
-func (api *PublicWhisperAPI) MakeLightClient(ctx context.Context) bool {
- api.w.SetLightClientMode(true)
- return api.w.LightClientMode()
-}
-
-// CancelLightClient cancels light client mode.
-func (api *PublicWhisperAPI) CancelLightClient(ctx context.Context) bool {
- api.w.SetLightClientMode(false)
- return !api.w.LightClientMode()
-}
-
-//go:generate gencodec -type NewMessage -field-override newMessageOverride -out gen_newmessage_json.go
-
-// NewMessage represents a new whisper message that is posted through the RPC.
-type NewMessage struct {
- SymKeyID string `json:"symKeyID"`
- PublicKey []byte `json:"pubKey"`
- Sig string `json:"sig"`
- TTL uint32 `json:"ttl"`
- Topic TopicType `json:"topic"`
- Payload []byte `json:"payload"`
- Padding []byte `json:"padding"`
- PowTime uint32 `json:"powTime"`
- PowTarget float64 `json:"powTarget"`
- TargetPeer string `json:"targetPeer"`
-}
-
-type newMessageOverride struct {
- PublicKey hexutil.Bytes
- Payload hexutil.Bytes
- Padding hexutil.Bytes
-}
-
-// Post posts a message on the Whisper network.
-// returns the hash of the message in case of success.
-func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) {
- var (
- symKeyGiven = len(req.SymKeyID) > 0
- pubKeyGiven = len(req.PublicKey) > 0
- err error
- )
-
- // user must specify either a symmetric or an asymmetric key
- if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
- return nil, ErrSymAsym
- }
-
- params := &MessageParams{
- TTL: req.TTL,
- Payload: req.Payload,
- Padding: req.Padding,
- WorkTime: req.PowTime,
- PoW: req.PowTarget,
- Topic: req.Topic,
- }
-
- // Set key that is used to sign the message
- if len(req.Sig) > 0 {
- if params.Src, err = api.w.GetPrivateKey(req.Sig); err != nil {
- return nil, err
- }
- }
-
- // Set symmetric key that is used to encrypt the message
- if symKeyGiven {
- if params.Topic == (TopicType{}) { // topics are mandatory with symmetric encryption
- return nil, ErrNoTopics
- }
- if params.KeySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
- return nil, err
- }
- if !validateDataIntegrity(params.KeySym, aesKeyLength) {
- return nil, ErrInvalidSymmetricKey
- }
- }
-
- // Set asymmetric key that is used to encrypt the message
- if pubKeyGiven {
- if params.Dst, err = crypto.UnmarshalPubkey(req.PublicKey); err != nil {
- return nil, ErrInvalidPublicKey
- }
- }
-
- // encrypt and sent message
- whisperMsg, err := NewSentMessage(params)
- if err != nil {
- return nil, err
- }
-
- var result []byte
- env, err := whisperMsg.Wrap(params)
- if err != nil {
- return nil, err
- }
-
- // send to specific node (skip PoW check)
- if len(req.TargetPeer) > 0 {
- n, err := enode.Parse(enode.ValidSchemes, req.TargetPeer)
- if err != nil {
- return nil, fmt.Errorf("failed to parse target peer: %s", err)
- }
- err = api.w.SendP2PMessage(n.ID().Bytes(), env)
- if err == nil {
- hash := env.Hash()
- result = hash[:]
- }
- return result, err
- }
-
- // ensure that the message PoW meets the node's minimum accepted PoW
- if req.PowTarget < api.w.MinPow() {
- return nil, ErrTooLowPoW
- }
-
- err = api.w.Send(env)
- if err == nil {
- hash := env.Hash()
- result = hash[:]
- }
- return result, err
-}
-
-//go:generate gencodec -type Criteria -field-override criteriaOverride -out gen_criteria_json.go
-
-// Criteria holds various filter options for inbound messages.
-type Criteria struct {
- SymKeyID string `json:"symKeyID"`
- PrivateKeyID string `json:"privateKeyID"`
- Sig []byte `json:"sig"`
- MinPow float64 `json:"minPow"`
- Topics []TopicType `json:"topics"`
- AllowP2P bool `json:"allowP2P"`
-}
-
-type criteriaOverride struct {
- Sig hexutil.Bytes
-}
-
-// Messages set up a subscription that fires events when messages arrive that match
-// the given set of criteria.
-func (api *PublicWhisperAPI) Messages(ctx context.Context, crit Criteria) (*rpc.Subscription, error) {
- var (
- symKeyGiven = len(crit.SymKeyID) > 0
- pubKeyGiven = len(crit.PrivateKeyID) > 0
- err error
- )
-
- // ensure that the RPC connection supports subscriptions
- notifier, supported := rpc.NotifierFromContext(ctx)
- if !supported {
- return nil, rpc.ErrNotificationsUnsupported
- }
-
- // user must specify either a symmetric or an asymmetric key
- if (symKeyGiven && pubKeyGiven) || (!symKeyGiven && !pubKeyGiven) {
- return nil, ErrSymAsym
- }
-
- filter := Filter{
- PoW: crit.MinPow,
- Messages: make(map[common.Hash]*ReceivedMessage),
- AllowP2P: crit.AllowP2P,
- }
-
- if len(crit.Sig) > 0 {
- if filter.Src, err = crypto.UnmarshalPubkey(crit.Sig); err != nil {
- return nil, ErrInvalidSigningPubKey
- }
- }
-
- for i, bt := range crit.Topics {
- if len(bt) == 0 || len(bt) > 4 {
- return nil, fmt.Errorf("subscribe: topic %d has wrong size: %d", i, len(bt))
- }
- filter.Topics = append(filter.Topics, bt[:])
- }
-
- // listen for message that are encrypted with the given symmetric key
- if symKeyGiven {
- if len(filter.Topics) == 0 {
- return nil, ErrNoTopics
- }
- key, err := api.w.GetSymKey(crit.SymKeyID)
- if err != nil {
- return nil, err
- }
- if !validateDataIntegrity(key, aesKeyLength) {
- return nil, ErrInvalidSymmetricKey
- }
- filter.KeySym = key
- filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym)
- }
-
- // listen for messages that are encrypted with the given public key
- if pubKeyGiven {
- filter.KeyAsym, err = api.w.GetPrivateKey(crit.PrivateKeyID)
- if err != nil || filter.KeyAsym == nil {
- return nil, ErrInvalidPublicKey
- }
- }
-
- id, err := api.w.Subscribe(&filter)
- if err != nil {
- return nil, err
- }
-
- // create subscription and start waiting for message events
- rpcSub := notifier.CreateSubscription()
- go func() {
- // for now poll internally, refactor whisper internal for channel support
- ticker := time.NewTicker(250 * time.Millisecond)
- defer ticker.Stop()
-
- for {
- select {
- case <-ticker.C:
- if filter := api.w.GetFilter(id); filter != nil {
- for _, rpcMessage := range toMessage(filter.Retrieve()) {
- if err := notifier.Notify(rpcSub.ID, rpcMessage); err != nil {
- log.Error("Failed to send notification", "err", err)
- }
- }
- }
- case <-rpcSub.Err():
- api.w.Unsubscribe(id)
- return
- case <-notifier.Closed():
- api.w.Unsubscribe(id)
- return
- }
- }
- }()
-
- return rpcSub, nil
-}
-
-//go:generate gencodec -type Message -field-override messageOverride -out gen_message_json.go
-
-// Message is the RPC representation of a whisper message.
-type Message struct {
- Sig []byte `json:"sig,omitempty"`
- TTL uint32 `json:"ttl"`
- Timestamp uint32 `json:"timestamp"`
- Topic TopicType `json:"topic"`
- Payload []byte `json:"payload"`
- Padding []byte `json:"padding"`
- PoW float64 `json:"pow"`
- Hash []byte `json:"hash"`
- Dst []byte `json:"recipientPublicKey,omitempty"`
-}
-
-type messageOverride struct {
- Sig hexutil.Bytes
- Payload hexutil.Bytes
- Padding hexutil.Bytes
- Hash hexutil.Bytes
- Dst hexutil.Bytes
-}
-
-// ToWhisperMessage converts an internal message into an API version.
-func ToWhisperMessage(message *ReceivedMessage) *Message {
- msg := Message{
- Payload: message.Payload,
- Padding: message.Padding,
- Timestamp: message.Sent,
- TTL: message.TTL,
- PoW: message.PoW,
- Hash: message.EnvelopeHash.Bytes(),
- Topic: message.Topic,
- }
-
- if message.Dst != nil {
- b := crypto.FromECDSAPub(message.Dst)
- if b != nil {
- msg.Dst = b
- }
- }
-
- if isMessageSigned(message.Raw[0]) {
- b := crypto.FromECDSAPub(message.SigToPubKey())
- if b != nil {
- msg.Sig = b
- }
- }
-
- return &msg
-}
-
-// toMessage converts a set of messages to its RPC representation.
-func toMessage(messages []*ReceivedMessage) []*Message {
- msgs := make([]*Message, len(messages))
- for i, msg := range messages {
- msgs[i] = ToWhisperMessage(msg)
- }
- return msgs
-}
-
-// GetFilterMessages returns the messages that match the filter criteria and
-// are received between the last poll and now.
-func (api *PublicWhisperAPI) GetFilterMessages(id string) ([]*Message, error) {
- api.mu.Lock()
- f := api.w.GetFilter(id)
- if f == nil {
- api.mu.Unlock()
- return nil, fmt.Errorf("filter not found")
- }
- api.lastUsed[id] = time.Now()
- api.mu.Unlock()
-
- receivedMessages := f.Retrieve()
- messages := make([]*Message, 0, len(receivedMessages))
- for _, msg := range receivedMessages {
- messages = append(messages, ToWhisperMessage(msg))
- }
-
- return messages, nil
-}
-
-// DeleteMessageFilter deletes a filter.
-func (api *PublicWhisperAPI) DeleteMessageFilter(id string) (bool, error) {
- api.mu.Lock()
- defer api.mu.Unlock()
-
- delete(api.lastUsed, id)
- return true, api.w.Unsubscribe(id)
-}
-
-// NewMessageFilter creates a new filter that can be used to poll for
-// (new) messages that satisfy the given criteria.
-func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) {
- var (
- src *ecdsa.PublicKey
- keySym []byte
- keyAsym *ecdsa.PrivateKey
- topics [][]byte
-
- symKeyGiven = len(req.SymKeyID) > 0
- asymKeyGiven = len(req.PrivateKeyID) > 0
-
- err error
- )
-
- // user must specify either a symmetric or an asymmetric key
- if (symKeyGiven && asymKeyGiven) || (!symKeyGiven && !asymKeyGiven) {
- return "", ErrSymAsym
- }
-
- if len(req.Sig) > 0 {
- if src, err = crypto.UnmarshalPubkey(req.Sig); err != nil {
- return "", ErrInvalidSigningPubKey
- }
- }
-
- if symKeyGiven {
- if keySym, err = api.w.GetSymKey(req.SymKeyID); err != nil {
- return "", err
- }
- if !validateDataIntegrity(keySym, aesKeyLength) {
- return "", ErrInvalidSymmetricKey
- }
- }
-
- if asymKeyGiven {
- if keyAsym, err = api.w.GetPrivateKey(req.PrivateKeyID); err != nil {
- return "", err
- }
- }
-
- if len(req.Topics) > 0 {
- topics = make([][]byte, len(req.Topics))
- for i, topic := range req.Topics {
- topics[i] = make([]byte, TopicLength)
- copy(topics[i], topic[:])
- }
- }
-
- f := &Filter{
- Src: src,
- KeySym: keySym,
- KeyAsym: keyAsym,
- PoW: req.MinPow,
- AllowP2P: req.AllowP2P,
- Topics: topics,
- Messages: make(map[common.Hash]*ReceivedMessage),
- }
-
- id, err := api.w.Subscribe(f)
- if err != nil {
- return "", err
- }
-
- api.mu.Lock()
- api.lastUsed[id] = time.Now()
- api.mu.Unlock()
-
- return id, nil
-}
diff --git a/whisper/whisperv6/api_test.go b/whisper/whisperv6/api_test.go
deleted file mode 100644
index 6d7157f57fd2..000000000000
--- a/whisper/whisperv6/api_test.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2018 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "bytes"
- "testing"
- "time"
-)
-
-func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
- w := New(nil)
-
- keyID, err := w.GenerateSymKey()
- if err != nil {
- t.Fatalf("Error generating symmetric key: %v", err)
- }
- api := PublicWhisperAPI{
- w: w,
- lastUsed: make(map[string]time.Time),
- }
-
- t1 := [4]byte{0xde, 0xea, 0xbe, 0xef}
- t2 := [4]byte{0xca, 0xfe, 0xde, 0xca}
-
- crit := Criteria{
- SymKeyID: keyID,
- Topics: []TopicType{TopicType(t1), TopicType(t2)},
- }
-
- _, err = api.NewMessageFilter(crit)
- if err != nil {
- t.Fatalf("Error creating the filter: %v", err)
- }
-
- found := false
- candidates := w.filters.getWatchersByTopic(TopicType(t1))
- for _, f := range candidates {
- if len(f.Topics) == 2 {
- if bytes.Equal(f.Topics[0], t1[:]) && bytes.Equal(f.Topics[1], t2[:]) {
- found = true
- }
- }
- }
-
- if !found {
- t.Fatalf("Could not find filter with both topics")
- }
-}
diff --git a/whisper/whisperv6/benchmarks_test.go b/whisper/whisperv6/benchmarks_test.go
deleted file mode 100644
index 0473179da5a5..000000000000
--- a/whisper/whisperv6/benchmarks_test.go
+++ /dev/null
@@ -1,208 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "crypto/sha256"
- "testing"
-
- "github.com/ethereum/go-ethereum/crypto"
- "golang.org/x/crypto/pbkdf2"
-)
-
-func BenchmarkDeriveKeyMaterial(b *testing.B) {
- for i := 0; i < b.N; i++ {
- pbkdf2.Key([]byte("test"), nil, 65356, aesKeyLength, sha256.New)
- }
-}
-
-func BenchmarkEncryptionSym(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- for i := 0; i < b.N; i++ {
- msg, _ := NewSentMessage(params)
- _, err := msg.Wrap(params)
- if err != nil {
- b.Errorf("failed Wrap with seed %d: %s.", seed, err)
- b.Errorf("i = %d, len(msg.Raw) = %d, params.Payload = %d.", i, len(msg.Raw), len(params.Payload))
- return
- }
- }
-}
-
-func BenchmarkEncryptionAsym(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- key, err := crypto.GenerateKey()
- if err != nil {
- b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- params.KeySym = nil
- params.Dst = &key.PublicKey
-
- for i := 0; i < b.N; i++ {
- msg, _ := NewSentMessage(params)
- _, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- }
-}
-
-func BenchmarkDecryptionSymValid(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, _ := NewSentMessage(params)
- env, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- f := Filter{KeySym: params.KeySym}
-
- for i := 0; i < b.N; i++ {
- msg := env.Open(&f)
- if msg == nil {
- b.Fatalf("failed to open with seed %d.", seed)
- }
- }
-}
-
-func BenchmarkDecryptionSymInvalid(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, _ := NewSentMessage(params)
- env, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- f := Filter{KeySym: []byte("arbitrary stuff here")}
-
- for i := 0; i < b.N; i++ {
- msg := env.Open(&f)
- if msg != nil {
- b.Fatalf("opened envelope with invalid key, seed: %d.", seed)
- }
- }
-}
-
-func BenchmarkDecryptionAsymValid(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- key, err := crypto.GenerateKey()
- if err != nil {
- b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- f := Filter{KeyAsym: key}
- params.KeySym = nil
- params.Dst = &key.PublicKey
- msg, _ := NewSentMessage(params)
- env, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- for i := 0; i < b.N; i++ {
- msg := env.Open(&f)
- if msg == nil {
- b.Fatalf("fail to open, seed: %d.", seed)
- }
- }
-}
-
-func BenchmarkDecryptionAsymInvalid(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- key, err := crypto.GenerateKey()
- if err != nil {
- b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- params.KeySym = nil
- params.Dst = &key.PublicKey
- msg, _ := NewSentMessage(params)
- env, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- key, err = crypto.GenerateKey()
- if err != nil {
- b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- f := Filter{KeyAsym: key}
-
- for i := 0; i < b.N; i++ {
- msg := env.Open(&f)
- if msg != nil {
- b.Fatalf("opened envelope with invalid key, seed: %d.", seed)
- }
- }
-}
-
-func increment(x []byte) {
- for i := 0; i < len(x); i++ {
- x[i]++
- if x[i] != 0 {
- break
- }
- }
-}
-
-func BenchmarkPoW(b *testing.B) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- params.Payload = make([]byte, 32)
- params.PoW = 10.0
- params.TTL = 1
-
- for i := 0; i < b.N; i++ {
- increment(params.Payload)
- msg, _ := NewSentMessage(params)
- _, err := msg.Wrap(params)
- if err != nil {
- b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- }
-}
diff --git a/whisper/whisperv6/config.go b/whisper/whisperv6/config.go
deleted file mode 100644
index 38eb9551ccd7..000000000000
--- a/whisper/whisperv6/config.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-// Config represents the configuration state of a whisper node.
-type Config struct {
- MaxMessageSize uint32 `toml:",omitempty"`
- MinimumAcceptedPOW float64 `toml:",omitempty"`
- RestrictConnectionBetweenLightClients bool `toml:",omitempty"`
-}
-
-// DefaultConfig represents (shocker!) the default configuration.
-var DefaultConfig = Config{
- MaxMessageSize: DefaultMaxMessageSize,
- MinimumAcceptedPOW: DefaultMinimumPoW,
- RestrictConnectionBetweenLightClients: true,
-}
diff --git a/whisper/whisperv6/doc.go b/whisper/whisperv6/doc.go
deleted file mode 100644
index 44c0c3271c7f..000000000000
--- a/whisper/whisperv6/doc.go
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-/*
-Package whisper implements the Whisper protocol (version 6).
-
-Whisper combines aspects of both DHTs and datagram messaging systems (e.g. UDP).
-As such it may be likened and compared to both, not dissimilar to the
-matter/energy duality (apologies to physicists for the blatant abuse of a
-fundamental and beautiful natural principle).
-
-Whisper is a pure identity-based messaging system. Whisper provides a low-level
-(non-application-specific) but easily-accessible API without being based upon
-or prejudiced by the low-level hardware attributes and characteristics,
-particularly the notion of singular endpoints.
-*/
-
-// Contains the Whisper protocol constant definitions
-
-package whisperv6
-
-import (
- "time"
-
- "github.com/ethereum/go-ethereum/crypto"
-)
-
-// Whisper protocol parameters
-const (
- ProtocolVersion = uint64(6) // Protocol version number
- ProtocolVersionStr = "6.0" // The same, as a string
- ProtocolName = "shh" // Nickname of the protocol in geth
-
- // whisper protocol message codes, according to EIP-627
- statusCode = 0 // used by whisper protocol
- messagesCode = 1 // normal whisper message
- powRequirementCode = 2 // PoW requirement
- bloomFilterExCode = 3 // bloom filter exchange
- p2pRequestCode = 126 // peer-to-peer message, used by Dapp protocol
- p2pMessageCode = 127 // peer-to-peer message (to be consumed by the peer, but not forwarded any further)
- NumberOfMessageCodes = 128
-
- SizeMask = byte(3) // mask used to extract the size of payload size field from the flags
- signatureFlag = byte(4)
-
- TopicLength = 4 // in bytes
- signatureLength = crypto.SignatureLength // in bytes
- aesKeyLength = 32 // in bytes
- aesNonceLength = 12 // in bytes; for more info please see cipher.gcmStandardNonceSize & aesgcm.NonceSize()
- keyIDSize = 32 // in bytes
- BloomFilterSize = 64 // in bytes
- flagsLength = 1
-
- EnvelopeHeaderLength = 20
-
- MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
- DefaultMaxMessageSize = uint32(1024 * 1024)
- DefaultMinimumPoW = 0.2
-
- padSizeLimit = 256 // just an arbitrary number, could be changed without breaking the protocol
- messageQueueLimit = 1024
-
- expirationCycle = time.Second
- transmissionCycle = 300 * time.Millisecond
-
- DefaultTTL = 50 // seconds
- DefaultSyncAllowance = 10 // seconds
-)
-
-// MailServer represents a mail server, capable of
-// archiving the old messages for subsequent delivery
-// to the peers. Any implementation must ensure that both
-// functions are thread-safe. Also, they must return ASAP.
-// DeliverMail should use directMessagesCode for delivery,
-// in order to bypass the expiry checks.
-type MailServer interface {
- Archive(env *Envelope)
- DeliverMail(whisperPeer *Peer, request *Envelope)
-}
diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go
deleted file mode 100644
index 5b6925edb3b5..000000000000
--- a/whisper/whisperv6/envelope.go
+++ /dev/null
@@ -1,280 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Contains the Whisper protocol Envelope element.
-
-package whisperv6
-
-import (
- "crypto/ecdsa"
- "encoding/binary"
- "fmt"
- gmath "math"
- "math/big"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/crypto/ecies"
- "github.com/ethereum/go-ethereum/rlp"
-)
-
-// Envelope represents a clear-text data packet to transmit through the Whisper
-// network. Its contents may or may not be encrypted and signed.
-type Envelope struct {
- Expiry uint32
- TTL uint32
- Topic TopicType
- Data []byte
- Nonce uint64
-
- pow float64 // Message-specific PoW as described in the Whisper specification.
-
- // the following variables should not be accessed directly, use the corresponding function instead: Hash(), Bloom()
- hash common.Hash // Cached hash of the envelope to avoid rehashing every time.
- bloom []byte
-}
-
-// size returns the size of envelope as it is sent (i.e. public fields only)
-func (e *Envelope) size() int {
- return EnvelopeHeaderLength + len(e.Data)
-}
-
-// rlpWithoutNonce returns the RLP encoded envelope contents, except the nonce.
-func (e *Envelope) rlpWithoutNonce() []byte {
- res, _ := rlp.EncodeToBytes([]interface{}{e.Expiry, e.TTL, e.Topic, e.Data})
- return res
-}
-
-// NewEnvelope wraps a Whisper message with expiration and destination data
-// included into an envelope for network forwarding.
-func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage) *Envelope {
- env := Envelope{
- Expiry: uint32(time.Now().Add(time.Second * time.Duration(ttl)).Unix()),
- TTL: ttl,
- Topic: topic,
- Data: msg.Raw,
- Nonce: 0,
- }
-
- return &env
-}
-
-// Seal closes the envelope by spending the requested amount of time as a proof
-// of work on hashing the data.
-func (e *Envelope) Seal(options *MessageParams) error {
- if options.PoW == 0 {
- // PoW is not required
- return nil
- }
-
- var target, bestLeadingZeros int
- if options.PoW < 0 {
- // target is not set - the function should run for a period
- // of time specified in WorkTime param. Since we can predict
- // the execution time, we can also adjust Expiry.
- e.Expiry += options.WorkTime
- } else {
- target = e.powToFirstBit(options.PoW)
- }
-
- rlp := e.rlpWithoutNonce()
- buf := make([]byte, len(rlp)+8)
- copy(buf, rlp)
- asAnInt := new(big.Int)
-
- finish := time.Now().Add(time.Duration(options.WorkTime) * time.Second).UnixNano()
- for nonce := uint64(0); time.Now().UnixNano() < finish; {
- for i := 0; i < 1024; i++ {
- binary.BigEndian.PutUint64(buf[len(rlp):], nonce)
- h := crypto.Keccak256(buf)
- asAnInt.SetBytes(h)
- leadingZeros := 256 - asAnInt.BitLen()
- if leadingZeros > bestLeadingZeros {
- e.Nonce, bestLeadingZeros = nonce, leadingZeros
- if target > 0 && bestLeadingZeros >= target {
- return nil
- }
- }
- nonce++
- }
- }
-
- if target > 0 && bestLeadingZeros < target {
- return fmt.Errorf("failed to reach the PoW target, specified pow time (%d seconds) was insufficient", options.WorkTime)
- }
-
- return nil
-}
-
-// PoW computes (if necessary) and returns the proof of work target
-// of the envelope.
-func (e *Envelope) PoW() float64 {
- if e.pow == 0 {
- e.calculatePoW(0)
- }
- return e.pow
-}
-
-func (e *Envelope) calculatePoW(diff uint32) {
- rlp := e.rlpWithoutNonce()
- buf := make([]byte, len(rlp)+8)
- copy(buf, rlp)
- binary.BigEndian.PutUint64(buf[len(rlp):], e.Nonce)
- powHash := new(big.Int).SetBytes(crypto.Keccak256(buf))
- leadingZeroes := 256 - powHash.BitLen()
- x := gmath.Pow(2, float64(leadingZeroes))
- x /= float64(len(rlp))
- x /= float64(e.TTL + diff)
- e.pow = x
-}
-
-func (e *Envelope) powToFirstBit(pow float64) int {
- x := pow
- x *= float64(e.size())
- x *= float64(e.TTL)
- bits := gmath.Log2(x)
- bits = gmath.Ceil(bits)
- res := int(bits)
- if res < 1 {
- res = 1
- }
- return res
-}
-
-// Hash returns the SHA3 hash of the envelope, calculating it if not yet done.
-func (e *Envelope) Hash() common.Hash {
- if (e.hash == common.Hash{}) {
- encoded, _ := rlp.EncodeToBytes(e)
- e.hash = crypto.Keccak256Hash(encoded)
- }
- return e.hash
-}
-
-// DecodeRLP decodes an Envelope from an RLP data stream.
-func (e *Envelope) DecodeRLP(s *rlp.Stream) error {
- raw, err := s.Raw()
- if err != nil {
- return err
- }
- // The decoding of Envelope uses the struct fields but also needs
- // to compute the hash of the whole RLP-encoded envelope. This
- // type has the same structure as Envelope but is not an
- // rlp.Decoder (does not implement DecodeRLP function).
- // Only public members will be encoded.
- type rlpenv Envelope
- if err := rlp.DecodeBytes(raw, (*rlpenv)(e)); err != nil {
- return err
- }
- e.hash = crypto.Keccak256Hash(raw)
- return nil
-}
-
-// OpenAsymmetric tries to decrypt an envelope, potentially encrypted with a particular key.
-func (e *Envelope) OpenAsymmetric(key *ecdsa.PrivateKey) (*ReceivedMessage, error) {
- message := &ReceivedMessage{Raw: e.Data}
- err := message.decryptAsymmetric(key)
- switch err {
- case nil:
- return message, nil
- case ecies.ErrInvalidPublicKey: // addressed to somebody else
- return nil, err
- default:
- return nil, fmt.Errorf("unable to open envelope, decrypt failed: %v", err)
- }
-}
-
-// OpenSymmetric tries to decrypt an envelope, potentially encrypted with a particular key.
-func (e *Envelope) OpenSymmetric(key []byte) (msg *ReceivedMessage, err error) {
- msg = &ReceivedMessage{Raw: e.Data}
- err = msg.decryptSymmetric(key)
- if err != nil {
- msg = nil
- }
- return msg, err
-}
-
-// Open tries to decrypt an envelope, and populates the message fields in case of success.
-func (e *Envelope) Open(watcher *Filter) (msg *ReceivedMessage) {
- if watcher == nil {
- return nil
- }
-
- // The API interface forbids filters doing both symmetric and asymmetric encryption.
- if watcher.expectsAsymmetricEncryption() && watcher.expectsSymmetricEncryption() {
- return nil
- }
-
- if watcher.expectsAsymmetricEncryption() {
- msg, _ = e.OpenAsymmetric(watcher.KeyAsym)
- if msg != nil {
- msg.Dst = &watcher.KeyAsym.PublicKey
- }
- } else if watcher.expectsSymmetricEncryption() {
- msg, _ = e.OpenSymmetric(watcher.KeySym)
- if msg != nil {
- msg.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym)
- }
- }
-
- if msg != nil {
- ok := msg.ValidateAndParse()
- if !ok {
- return nil
- }
- msg.Topic = e.Topic
- msg.PoW = e.PoW()
- msg.TTL = e.TTL
- msg.Sent = e.Expiry - e.TTL
- msg.EnvelopeHash = e.Hash()
- }
- return msg
-}
-
-// Bloom maps 4-bytes Topic into 64-byte bloom filter with 3 bits set (at most).
-func (e *Envelope) Bloom() []byte {
- if e.bloom == nil {
- e.bloom = TopicToBloom(e.Topic)
- }
- return e.bloom
-}
-
-// TopicToBloom converts the topic (4 bytes) to the bloom filter (64 bytes)
-func TopicToBloom(topic TopicType) []byte {
- b := make([]byte, BloomFilterSize)
- var index [3]int
- for j := 0; j < 3; j++ {
- index[j] = int(topic[j])
- if (topic[3] & (1 << uint(j))) != 0 {
- index[j] += 256
- }
- }
-
- for j := 0; j < 3; j++ {
- byteIndex := index[j] / 8
- bitIndex := index[j] % 8
- b[byteIndex] = (1 << uint(bitIndex))
- }
- return b
-}
-
-// GetEnvelope retrieves an envelope from the message queue by its hash.
-// It returns nil if the envelope can not be found.
-func (w *Whisper) GetEnvelope(hash common.Hash) *Envelope {
- w.poolMu.RLock()
- defer w.poolMu.RUnlock()
- return w.envelopes[hash]
-}
diff --git a/whisper/whisperv6/envelope_test.go b/whisper/whisperv6/envelope_test.go
deleted file mode 100644
index c0bb4373b884..000000000000
--- a/whisper/whisperv6/envelope_test.go
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Contains the tests associated with the Whisper protocol Envelope object.
-
-package whisperv6
-
-import (
- mrand "math/rand"
- "testing"
-
- "github.com/ethereum/go-ethereum/crypto"
-)
-
-func TestPoWCalculationsWithNoLeadingZeros(t *testing.T) {
- e := Envelope{
- TTL: 1,
- Data: []byte{0xde, 0xad, 0xbe, 0xef},
- Nonce: 100000,
- }
-
- e.calculatePoW(0)
-
- if e.pow != 0.07692307692307693 {
- t.Fatalf("invalid PoW calculation. Expected 0.07692307692307693, got %v", e.pow)
- }
-}
-
-func TestPoWCalculationsWith8LeadingZeros(t *testing.T) {
- e := Envelope{
- TTL: 1,
- Data: []byte{0xde, 0xad, 0xbe, 0xef},
- Nonce: 276,
- }
- e.calculatePoW(0)
-
- if e.pow != 19.692307692307693 {
- t.Fatalf("invalid PoW calculation. Expected 19.692307692307693, got %v", e.pow)
- }
-}
-
-func TestEnvelopeOpenAcceptsOnlyOneKeyTypeInFilter(t *testing.T) {
- symKey := make([]byte, aesKeyLength)
- mrand.Read(symKey)
-
- asymKey, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
-
- params := MessageParams{
- PoW: 0.01,
- WorkTime: 1,
- TTL: uint32(mrand.Intn(1024)),
- Payload: make([]byte, 50),
- KeySym: symKey,
- Dst: nil,
- }
-
- mrand.Read(params.Payload)
-
- msg, err := NewSentMessage(¶ms)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
-
- e, err := msg.Wrap(¶ms)
- if err != nil {
- t.Fatalf("Failed to Wrap the message in an envelope with seed %d: %s", seed, err)
- }
-
- f := Filter{KeySym: symKey, KeyAsym: asymKey}
-
- decrypted := e.Open(&f)
- if decrypted != nil {
- t.Fatalf("Managed to decrypt a message with an invalid filter, seed %d", seed)
- }
-}
diff --git a/whisper/whisperv6/filter.go b/whisper/whisperv6/filter.go
deleted file mode 100644
index 6a5b79674b5c..000000000000
--- a/whisper/whisperv6/filter.go
+++ /dev/null
@@ -1,262 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "crypto/ecdsa"
- "fmt"
- "sync"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
-)
-
-// Filter represents a Whisper message filter
-type Filter struct {
- Src *ecdsa.PublicKey // Sender of the message
- KeyAsym *ecdsa.PrivateKey // Private Key of recipient
- KeySym []byte // Key associated with the Topic
- Topics [][]byte // Topics to filter messages with
- PoW float64 // Proof of work as described in the Whisper spec
- AllowP2P bool // Indicates whether this filter is interested in direct peer-to-peer messages
- SymKeyHash common.Hash // The Keccak256Hash of the symmetric key, needed for optimization
- id string // unique identifier
-
- Messages map[common.Hash]*ReceivedMessage
- mutex sync.RWMutex
-}
-
-// Filters represents a collection of filters
-type Filters struct {
- watchers map[string]*Filter
-
- topicMatcher map[TopicType]map[*Filter]struct{} // map a topic to the filters that are interested in being notified when a message matches that topic
- allTopicsMatcher map[*Filter]struct{} // list all the filters that will be notified of a new message, no matter what its topic is
-
- whisper *Whisper
- mutex sync.RWMutex
-}
-
-// NewFilters returns a newly created filter collection
-func NewFilters(w *Whisper) *Filters {
- return &Filters{
- watchers: make(map[string]*Filter),
- topicMatcher: make(map[TopicType]map[*Filter]struct{}),
- allTopicsMatcher: make(map[*Filter]struct{}),
- whisper: w,
- }
-}
-
-// Install will add a new filter to the filter collection
-func (fs *Filters) Install(watcher *Filter) (string, error) {
- if watcher.KeySym != nil && watcher.KeyAsym != nil {
- return "", fmt.Errorf("filters must choose between symmetric and asymmetric keys")
- }
-
- if watcher.Messages == nil {
- watcher.Messages = make(map[common.Hash]*ReceivedMessage)
- }
-
- id, err := GenerateRandomID()
- if err != nil {
- return "", err
- }
-
- fs.mutex.Lock()
- defer fs.mutex.Unlock()
-
- if fs.watchers[id] != nil {
- return "", fmt.Errorf("failed to generate unique ID")
- }
-
- if watcher.expectsSymmetricEncryption() {
- watcher.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym)
- }
-
- watcher.id = id
- fs.watchers[id] = watcher
- fs.addTopicMatcher(watcher)
- return id, err
-}
-
-// Uninstall will remove a filter whose id has been specified from
-// the filter collection
-func (fs *Filters) Uninstall(id string) bool {
- fs.mutex.Lock()
- defer fs.mutex.Unlock()
- if fs.watchers[id] != nil {
- fs.removeFromTopicMatchers(fs.watchers[id])
- delete(fs.watchers, id)
- return true
- }
- return false
-}
-
-// addTopicMatcher adds a filter to the topic matchers.
-// If the filter's Topics array is empty, it will be tried on every topic.
-// Otherwise, it will be tried on the topics specified.
-func (fs *Filters) addTopicMatcher(watcher *Filter) {
- if len(watcher.Topics) == 0 {
- fs.allTopicsMatcher[watcher] = struct{}{}
- } else {
- for _, t := range watcher.Topics {
- topic := BytesToTopic(t)
- if fs.topicMatcher[topic] == nil {
- fs.topicMatcher[topic] = make(map[*Filter]struct{})
- }
- fs.topicMatcher[topic][watcher] = struct{}{}
- }
- }
-}
-
-// removeFromTopicMatchers removes a filter from the topic matchers
-func (fs *Filters) removeFromTopicMatchers(watcher *Filter) {
- delete(fs.allTopicsMatcher, watcher)
- for _, topic := range watcher.Topics {
- delete(fs.topicMatcher[BytesToTopic(topic)], watcher)
- }
-}
-
-// getWatchersByTopic returns a slice containing the filters that
-// match a specific topic
-func (fs *Filters) getWatchersByTopic(topic TopicType) []*Filter {
- res := make([]*Filter, 0, len(fs.allTopicsMatcher))
- for watcher := range fs.allTopicsMatcher {
- res = append(res, watcher)
- }
- for watcher := range fs.topicMatcher[topic] {
- res = append(res, watcher)
- }
- return res
-}
-
-// Get returns a filter from the collection with a specific ID
-func (fs *Filters) Get(id string) *Filter {
- fs.mutex.RLock()
- defer fs.mutex.RUnlock()
- return fs.watchers[id]
-}
-
-// NotifyWatchers notifies any filter that has declared interest
-// for the envelope's topic.
-func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
- var msg *ReceivedMessage
-
- fs.mutex.RLock()
- defer fs.mutex.RUnlock()
-
- candidates := fs.getWatchersByTopic(env.Topic)
- for _, watcher := range candidates {
- if p2pMessage && !watcher.AllowP2P {
- log.Trace(fmt.Sprintf("msg [%x], filter [%s]: p2p messages are not allowed", env.Hash(), watcher.id))
- continue
- }
-
- var match bool
- if msg != nil {
- match = watcher.MatchMessage(msg)
- } else {
- match = watcher.MatchEnvelope(env)
- if match {
- msg = env.Open(watcher)
- if msg == nil {
- log.Trace("processing message: failed to open", "message", env.Hash().Hex(), "filter", watcher.id)
- }
- } else {
- log.Trace("processing message: does not match", "message", env.Hash().Hex(), "filter", watcher.id)
- }
- }
-
- if match && msg != nil {
- log.Trace("processing message: decrypted", "hash", env.Hash().Hex())
- if watcher.Src == nil || IsPubKeyEqual(msg.Src, watcher.Src) {
- watcher.Trigger(msg)
- }
- }
- }
-}
-
-func (f *Filter) expectsAsymmetricEncryption() bool {
- return f.KeyAsym != nil
-}
-
-func (f *Filter) expectsSymmetricEncryption() bool {
- return f.KeySym != nil
-}
-
-// Trigger adds a yet-unknown message to the filter's list of
-// received messages.
-func (f *Filter) Trigger(msg *ReceivedMessage) {
- f.mutex.Lock()
- defer f.mutex.Unlock()
-
- if _, exist := f.Messages[msg.EnvelopeHash]; !exist {
- f.Messages[msg.EnvelopeHash] = msg
- }
-}
-
-// Retrieve will return the list of all received messages associated
-// to a filter.
-func (f *Filter) Retrieve() (all []*ReceivedMessage) {
- f.mutex.Lock()
- defer f.mutex.Unlock()
-
- all = make([]*ReceivedMessage, 0, len(f.Messages))
- for _, msg := range f.Messages {
- all = append(all, msg)
- }
-
- f.Messages = make(map[common.Hash]*ReceivedMessage) // delete old messages
- return all
-}
-
-// MatchMessage checks if the filter matches an already decrypted
-// message (i.e. a Message that has already been handled by
-// MatchEnvelope when checked by a previous filter).
-// Topics are not checked here, since this is done by topic matchers.
-func (f *Filter) MatchMessage(msg *ReceivedMessage) bool {
- if f.PoW > 0 && msg.PoW < f.PoW {
- return false
- }
-
- if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() {
- return IsPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst)
- } else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() {
- return f.SymKeyHash == msg.SymKeyHash
- }
- return false
-}
-
-// MatchEnvelope checks if it's worth decrypting the message. If
-// it returns `true`, client code is expected to attempt decrypting
-// the message and subsequently call MatchMessage.
-// Topics are not checked here, since this is done by topic matchers.
-func (f *Filter) MatchEnvelope(envelope *Envelope) bool {
- return f.PoW <= 0 || envelope.pow >= f.PoW
-}
-
-// IsPubKeyEqual checks that two public keys are equal
-func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool {
- if !ValidatePublicKey(a) {
- return false
- } else if !ValidatePublicKey(b) {
- return false
- }
- // the curve is always the same, just compare the points
- return a.X.Cmp(b.X) == 0 && a.Y.Cmp(b.Y) == 0
-}
diff --git a/whisper/whisperv6/filter_test.go b/whisper/whisperv6/filter_test.go
deleted file mode 100644
index 55f505291977..000000000000
--- a/whisper/whisperv6/filter_test.go
+++ /dev/null
@@ -1,825 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "math/big"
- mrand "math/rand"
- "testing"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
-)
-
-var seed int64
-
-// InitSingleTest should be called in the beginning of every
-// test, which uses RNG, in order to make the tests
-// reproduciblity independent of their sequence.
-func InitSingleTest() {
- seed = time.Now().Unix()
- mrand.Seed(seed)
-}
-
-type FilterTestCase struct {
- f *Filter
- id string
- alive bool
- msgCnt int
-}
-
-func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
- var f Filter
- f.Messages = make(map[common.Hash]*ReceivedMessage)
-
- const topicNum = 8
- f.Topics = make([][]byte, topicNum)
- for i := 0; i < topicNum; i++ {
- f.Topics[i] = make([]byte, 4)
- mrand.Read(f.Topics[i])
- f.Topics[i][0] = 0x01
- }
-
- key, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("generateFilter 1 failed with seed %d.", seed)
- return nil, err
- }
- f.Src = &key.PublicKey
-
- if symmetric {
- f.KeySym = make([]byte, aesKeyLength)
- mrand.Read(f.KeySym)
- f.SymKeyHash = crypto.Keccak256Hash(f.KeySym)
- } else {
- f.KeyAsym, err = crypto.GenerateKey()
- if err != nil {
- t.Fatalf("generateFilter 2 failed with seed %d.", seed)
- return nil, err
- }
- }
-
- // AcceptP2P & PoW are not set
- return &f, nil
-}
-
-func generateTestCases(t *testing.T, SizeTestFilters int) []FilterTestCase {
- cases := make([]FilterTestCase, SizeTestFilters)
- for i := 0; i < SizeTestFilters; i++ {
- f, _ := generateFilter(t, true)
- cases[i].f = f
- cases[i].alive = mrand.Int()&int(1) == 0
- }
- return cases
-}
-
-func TestInstallFilters(t *testing.T) {
- InitSingleTest()
-
- const SizeTestFilters = 256
- w := New(&Config{})
- filters := NewFilters(w)
- tst := generateTestCases(t, SizeTestFilters)
-
- var err error
- var j string
- for i := 0; i < SizeTestFilters; i++ {
- j, err = filters.Install(tst[i].f)
- if err != nil {
- t.Fatalf("seed %d: failed to install filter: %s", seed, err)
- }
- tst[i].id = j
- if len(j) != keyIDSize*2 {
- t.Fatalf("seed %d: wrong filter id size [%d]", seed, len(j))
- }
- }
-
- for _, testCase := range tst {
- if !testCase.alive {
- filters.Uninstall(testCase.id)
- }
- }
-
- for i, testCase := range tst {
- fil := filters.Get(testCase.id)
- exist := fil != nil
- if exist != testCase.alive {
- t.Fatalf("seed %d: failed alive: %d, %v, %v", seed, i, exist, testCase.alive)
- }
- if exist && fil.PoW != testCase.f.PoW {
- t.Fatalf("seed %d: failed Get: %d, %v, %v", seed, i, exist, testCase.alive)
- }
- }
-}
-
-func TestInstallSymKeyGeneratesHash(t *testing.T) {
- InitSingleTest()
-
- w := New(&Config{})
- filters := NewFilters(w)
- filter, _ := generateFilter(t, true)
-
- // save the current SymKeyHash for comparison
- initialSymKeyHash := filter.SymKeyHash
-
- // ensure the SymKeyHash is invalid, for Install to recreate it
- var invalid common.Hash
- filter.SymKeyHash = invalid
-
- _, err := filters.Install(filter)
-
- if err != nil {
- t.Fatalf("Error installing the filter: %s", err)
- }
-
- for i, b := range filter.SymKeyHash {
- if b != initialSymKeyHash[i] {
- t.Fatalf("The filter's symmetric key hash was not properly generated by Install")
- }
- }
-}
-
-func TestInstallIdenticalFilters(t *testing.T) {
- InitSingleTest()
-
- w := New(&Config{})
- filters := NewFilters(w)
- filter1, _ := generateFilter(t, true)
-
- // Copy the first filter since some of its fields
- // are randomly gnerated.
- filter2 := &Filter{
- KeySym: filter1.KeySym,
- Topics: filter1.Topics,
- PoW: filter1.PoW,
- AllowP2P: filter1.AllowP2P,
- Messages: make(map[common.Hash]*ReceivedMessage),
- }
-
- _, err := filters.Install(filter1)
-
- if err != nil {
- t.Fatalf("Error installing the first filter with seed %d: %s", seed, err)
- }
-
- _, err = filters.Install(filter2)
-
- if err != nil {
- t.Fatalf("Error installing the second filter with seed %d: %s", seed, err)
- }
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("Error generating message parameters with seed %d: %s", seed, err)
- }
-
- params.KeySym = filter1.KeySym
- params.Topic = BytesToTopic(filter1.Topics[0])
-
- filter1.Src = ¶ms.Src.PublicKey
- filter2.Src = ¶ms.Src.PublicKey
-
- sentMessage, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := sentMessage.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- msg := env.Open(filter1)
- if msg == nil {
- t.Fatalf("failed to Open with filter1")
- }
-
- if !filter1.MatchEnvelope(env) {
- t.Fatalf("failed matching with the first filter")
- }
-
- if !filter2.MatchEnvelope(env) {
- t.Fatalf("failed matching with the first filter")
- }
-
- if !filter1.MatchMessage(msg) {
- t.Fatalf("failed matching with the second filter")
- }
-
- if !filter2.MatchMessage(msg) {
- t.Fatalf("failed matching with the second filter")
- }
-}
-
-func TestInstallFilterWithSymAndAsymKeys(t *testing.T) {
- InitSingleTest()
-
- w := New(&Config{})
- filters := NewFilters(w)
- filter1, _ := generateFilter(t, true)
-
- asymKey, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("Unable to create asymetric keys: %v", err)
- }
-
- // Copy the first filter since some of its fields
- // are randomly gnerated.
- filter := &Filter{
- KeySym: filter1.KeySym,
- KeyAsym: asymKey,
- Topics: filter1.Topics,
- PoW: filter1.PoW,
- AllowP2P: filter1.AllowP2P,
- Messages: make(map[common.Hash]*ReceivedMessage),
- }
-
- _, err = filters.Install(filter)
-
- if err == nil {
- t.Fatalf("Error detecting that a filter had both an asymmetric and symmetric key, with seed %d", seed)
- }
-}
-
-func TestComparePubKey(t *testing.T) {
- InitSingleTest()
-
- key1, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed to generate first key with seed %d: %s.", seed, err)
- }
- key2, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed to generate second key with seed %d: %s.", seed, err)
- }
- if IsPubKeyEqual(&key1.PublicKey, &key2.PublicKey) {
- t.Fatalf("public keys are equal, seed %d.", seed)
- }
-
- // generate key3 == key1
- mrand.Seed(seed)
- key3, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed to generate third key with seed %d: %s.", seed, err)
- }
- if IsPubKeyEqual(&key1.PublicKey, &key3.PublicKey) {
- t.Fatalf("key1 == key3, seed %d.", seed)
- }
-}
-
-func TestMatchEnvelope(t *testing.T) {
- InitSingleTest()
-
- fsym, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateFilter with seed %d: %s.", seed, err)
- }
-
- fasym, err := generateFilter(t, false)
- if err != nil {
- t.Fatalf("failed generateFilter() with seed %d: %s.", seed, err)
- }
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- params.Topic[0] = 0xFF // topic mismatch
-
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- if _, err = msg.Wrap(params); err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- // encrypt symmetrically
- i := mrand.Int() % 4
- fsym.Topics[i] = params.Topic[:]
- fasym.Topics[i] = params.Topic[:]
- msg, err = NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap() with seed %d: %s.", seed, err)
- }
-
- // symmetric + matching topic: match
- match := fsym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope() symmetric with seed %d.", seed)
- }
-
- // symmetric + matching topic + insufficient PoW: mismatch
- fsym.PoW = env.PoW() + 1.0
- match = fsym.MatchEnvelope(env)
- if match {
- t.Fatalf("failed MatchEnvelope(symmetric + matching topic + insufficient PoW) asymmetric with seed %d.", seed)
- }
-
- // symmetric + matching topic + sufficient PoW: match
- fsym.PoW = env.PoW() / 2
- match = fsym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(symmetric + matching topic + sufficient PoW) with seed %d.", seed)
- }
-
- // symmetric + topics are nil (wildcard): match
- prevTopics := fsym.Topics
- fsym.Topics = nil
- match = fsym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(symmetric + topics are nil) with seed %d.", seed)
- }
- fsym.Topics = prevTopics
-
- // encrypt asymmetrically
- key, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- params.KeySym = nil
- params.Dst = &key.PublicKey
- msg, err = NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err = msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap() with seed %d: %s.", seed, err)
- }
-
- // encryption method mismatch
- match = fsym.MatchEnvelope(env)
- if match {
- t.Fatalf("failed MatchEnvelope(encryption method mismatch) with seed %d.", seed)
- }
-
- // asymmetric + mismatching topic: mismatch
- match = fasym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(asymmetric + mismatching topic) with seed %d.", seed)
- }
-
- // asymmetric + matching topic: match
- fasym.Topics[i] = fasym.Topics[i+1]
- match = fasym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(asymmetric + matching topic) with seed %d.", seed)
- }
-
- // asymmetric + filter without topic (wildcard): match
- fasym.Topics = nil
- match = fasym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(asymmetric + filter without topic) with seed %d.", seed)
- }
-
- // asymmetric + insufficient PoW: mismatch
- fasym.PoW = env.PoW() + 1.0
- match = fasym.MatchEnvelope(env)
- if match {
- t.Fatalf("failed MatchEnvelope(asymmetric + insufficient PoW) with seed %d.", seed)
- }
-
- // asymmetric + sufficient PoW: match
- fasym.PoW = env.PoW() / 2
- match = fasym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(asymmetric + sufficient PoW) with seed %d.", seed)
- }
-
- // filter without topic + envelope without topic: match
- env.Topic = TopicType{}
- match = fasym.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope(filter without topic + envelope without topic) with seed %d.", seed)
- }
-
- // filter with topic + envelope without topic: mismatch
- fasym.Topics = fsym.Topics
- match = fasym.MatchEnvelope(env)
- if !match {
- // topic mismatch should have no affect, as topics are handled by topic matchers
- t.Fatalf("failed MatchEnvelope(filter without topic + envelope without topic) with seed %d.", seed)
- }
-}
-
-func TestMatchMessageSym(t *testing.T) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- f, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateFilter with seed %d: %s.", seed, err)
- }
-
- const index = 1
- params.KeySym = f.KeySym
- params.Topic = BytesToTopic(f.Topics[index])
-
- sentMessage, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := sentMessage.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- msg := env.Open(f)
- if msg == nil {
- t.Fatalf("failed Open with seed %d.", seed)
- }
-
- // Src: match
- *f.Src.X = *params.Src.PublicKey.X
- *f.Src.Y = *params.Src.PublicKey.Y
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(src match) with seed %d.", seed)
- }
-
- // insufficient PoW: mismatch
- f.PoW = msg.PoW + 1.0
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(insufficient PoW) with seed %d.", seed)
- }
-
- // sufficient PoW: match
- f.PoW = msg.PoW / 2
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(sufficient PoW) with seed %d.", seed)
- }
-
- // topic mismatch
- f.Topics[index][0]++
- if !f.MatchMessage(msg) {
- // topic mismatch should have no affect, as topics are handled by topic matchers
- t.Fatalf("failed MatchEnvelope(topic mismatch) with seed %d.", seed)
- }
- f.Topics[index][0]--
-
- // key mismatch
- f.SymKeyHash[0]++
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(key mismatch) with seed %d.", seed)
- }
- f.SymKeyHash[0]--
-
- // Src absent: match
- f.Src = nil
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(src absent) with seed %d.", seed)
- }
-
- // key hash mismatch
- h := f.SymKeyHash
- f.SymKeyHash = common.Hash{}
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(key hash mismatch) with seed %d.", seed)
- }
- f.SymKeyHash = h
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(key hash match) with seed %d.", seed)
- }
-
- // encryption method mismatch
- f.KeySym = nil
- f.KeyAsym, err = crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(encryption method mismatch) with seed %d.", seed)
- }
-}
-
-func TestMatchMessageAsym(t *testing.T) {
- InitSingleTest()
-
- f, err := generateFilter(t, false)
- if err != nil {
- t.Fatalf("failed generateFilter with seed %d: %s.", seed, err)
- }
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- const index = 1
- params.Topic = BytesToTopic(f.Topics[index])
- params.Dst = &f.KeyAsym.PublicKey
- keySymOrig := params.KeySym
- params.KeySym = nil
-
- sentMessage, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := sentMessage.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- msg := env.Open(f)
- if msg == nil {
- t.Fatalf("failed to open with seed %d.", seed)
- }
-
- // Src: match
- *f.Src.X = *params.Src.PublicKey.X
- *f.Src.Y = *params.Src.PublicKey.Y
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchMessage(src match) with seed %d.", seed)
- }
-
- // insufficient PoW: mismatch
- f.PoW = msg.PoW + 1.0
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(insufficient PoW) with seed %d.", seed)
- }
-
- // sufficient PoW: match
- f.PoW = msg.PoW / 2
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(sufficient PoW) with seed %d.", seed)
- }
-
- // topic mismatch
- f.Topics[index][0]++
- if !f.MatchMessage(msg) {
- // topic mismatch should have no affect, as topics are handled by topic matchers
- t.Fatalf("failed MatchEnvelope(topic mismatch) with seed %d.", seed)
- }
- f.Topics[index][0]--
-
- // key mismatch
- prev := *f.KeyAsym.PublicKey.X
- zero := *big.NewInt(0)
- *f.KeyAsym.PublicKey.X = zero
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(key mismatch) with seed %d.", seed)
- }
- *f.KeyAsym.PublicKey.X = prev
-
- // Src absent: match
- f.Src = nil
- if !f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(src absent) with seed %d.", seed)
- }
-
- // encryption method mismatch
- f.KeySym = keySymOrig
- f.KeyAsym = nil
- if f.MatchMessage(msg) {
- t.Fatalf("failed MatchEnvelope(encryption method mismatch) with seed %d.", seed)
- }
-}
-
-func cloneFilter(orig *Filter) *Filter {
- var clone Filter
- clone.Messages = make(map[common.Hash]*ReceivedMessage)
- clone.Src = orig.Src
- clone.KeyAsym = orig.KeyAsym
- clone.KeySym = orig.KeySym
- clone.Topics = orig.Topics
- clone.PoW = orig.PoW
- clone.AllowP2P = orig.AllowP2P
- clone.SymKeyHash = orig.SymKeyHash
- return &clone
-}
-
-func generateCompatibeEnvelope(t *testing.T, f *Filter) *Envelope {
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- return nil
- }
-
- params.KeySym = f.KeySym
- params.Topic = BytesToTopic(f.Topics[2])
- sentMessage, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := sentMessage.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- return nil
- }
- return env
-}
-
-func TestWatchers(t *testing.T) {
- InitSingleTest()
-
- const NumFilters = 16
- const NumMessages = 256
- var i int
- var j uint32
- var e *Envelope
- var x, firstID string
- var err error
-
- w := New(&Config{})
- filters := NewFilters(w)
- tst := generateTestCases(t, NumFilters)
- for i = 0; i < NumFilters; i++ {
- tst[i].f.Src = nil
- x, err = filters.Install(tst[i].f)
- if err != nil {
- t.Fatalf("failed to install filter with seed %d: %s.", seed, err)
- }
- tst[i].id = x
- if len(firstID) == 0 {
- firstID = x
- }
- }
-
- lastID := x
-
- var envelopes [NumMessages]*Envelope
- for i = 0; i < NumMessages; i++ {
- j = mrand.Uint32() % NumFilters
- e = generateCompatibeEnvelope(t, tst[j].f)
- envelopes[i] = e
- tst[j].msgCnt++
- }
-
- for i = 0; i < NumMessages; i++ {
- filters.NotifyWatchers(envelopes[i], false)
- }
-
- var total int
- var mail []*ReceivedMessage
- var count [NumFilters]int
-
- for i = 0; i < NumFilters; i++ {
- mail = tst[i].f.Retrieve()
- count[i] = len(mail)
- total += len(mail)
- }
-
- if total != NumMessages {
- t.Fatalf("failed with seed %d: total = %d, want: %d.", seed, total, NumMessages)
- }
-
- for i = 0; i < NumFilters; i++ {
- mail = tst[i].f.Retrieve()
- if len(mail) != 0 {
- t.Fatalf("failed with seed %d: i = %d.", seed, i)
- }
-
- if tst[i].msgCnt != count[i] {
- t.Fatalf("failed with seed %d: count[%d]: get %d, want %d.", seed, i, tst[i].msgCnt, count[i])
- }
- }
-
- // another round with a cloned filter
-
- clone := cloneFilter(tst[0].f)
- filters.Uninstall(lastID)
- total = 0
- last := NumFilters - 1
- tst[last].f = clone
- filters.Install(clone)
- for i = 0; i < NumFilters; i++ {
- tst[i].msgCnt = 0
- count[i] = 0
- }
-
- // make sure that the first watcher receives at least one message
- e = generateCompatibeEnvelope(t, tst[0].f)
- envelopes[0] = e
- tst[0].msgCnt++
- for i = 1; i < NumMessages; i++ {
- j = mrand.Uint32() % NumFilters
- e = generateCompatibeEnvelope(t, tst[j].f)
- envelopes[i] = e
- tst[j].msgCnt++
- }
-
- for i = 0; i < NumMessages; i++ {
- filters.NotifyWatchers(envelopes[i], false)
- }
-
- for i = 0; i < NumFilters; i++ {
- mail = tst[i].f.Retrieve()
- count[i] = len(mail)
- total += len(mail)
- }
-
- combined := tst[0].msgCnt + tst[last].msgCnt
- if total != NumMessages+count[0] {
- t.Fatalf("failed with seed %d: total = %d, count[0] = %d.", seed, total, count[0])
- }
-
- if combined != count[0] {
- t.Fatalf("failed with seed %d: combined = %d, count[0] = %d.", seed, combined, count[0])
- }
-
- if combined != count[last] {
- t.Fatalf("failed with seed %d: combined = %d, count[last] = %d.", seed, combined, count[last])
- }
-
- for i = 1; i < NumFilters-1; i++ {
- mail = tst[i].f.Retrieve()
- if len(mail) != 0 {
- t.Fatalf("failed with seed %d: i = %d.", seed, i)
- }
-
- if tst[i].msgCnt != count[i] {
- t.Fatalf("failed with seed %d: i = %d, get %d, want %d.", seed, i, tst[i].msgCnt, count[i])
- }
- }
-
- // test AcceptP2P
-
- total = 0
- filters.NotifyWatchers(envelopes[0], true)
-
- for i = 0; i < NumFilters; i++ {
- mail = tst[i].f.Retrieve()
- total += len(mail)
- }
-
- if total != 0 {
- t.Fatalf("failed with seed %d: total: got %d, want 0.", seed, total)
- }
-
- f := filters.Get(firstID)
- if f == nil {
- t.Fatalf("failed to get the filter with seed %d.", seed)
- }
- f.AllowP2P = true
- total = 0
- filters.NotifyWatchers(envelopes[0], true)
-
- for i = 0; i < NumFilters; i++ {
- mail = tst[i].f.Retrieve()
- total += len(mail)
- }
-
- if total != 1 {
- t.Fatalf("failed with seed %d: total: got %d, want 1.", seed, total)
- }
-}
-
-func TestVariableTopics(t *testing.T) {
- InitSingleTest()
-
- const lastTopicByte = 3
- var match bool
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- f, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateFilter with seed %d: %s.", seed, err)
- }
-
- for i := 0; i < 4; i++ {
- env.Topic = BytesToTopic(f.Topics[i])
- match = f.MatchEnvelope(env)
- if !match {
- t.Fatalf("failed MatchEnvelope symmetric with seed %d, step %d.", seed, i)
- }
-
- f.Topics[i][lastTopicByte]++
- match = f.MatchEnvelope(env)
- if !match {
- // topic mismatch should have no affect, as topics are handled by topic matchers
- t.Fatalf("MatchEnvelope symmetric with seed %d, step %d.", seed, i)
- }
- }
-}
diff --git a/whisper/whisperv6/gen_criteria_json.go b/whisper/whisperv6/gen_criteria_json.go
deleted file mode 100644
index 1a428d6df730..000000000000
--- a/whisper/whisperv6/gen_criteria_json.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package whisperv6
-
-import (
- "encoding/json"
-
- "github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-var _ = (*criteriaOverride)(nil)
-
-// MarshalJSON marshals type Criteria to a json string
-func (c Criteria) MarshalJSON() ([]byte, error) {
- type Criteria struct {
- SymKeyID string `json:"symKeyID"`
- PrivateKeyID string `json:"privateKeyID"`
- Sig hexutil.Bytes `json:"sig"`
- MinPow float64 `json:"minPow"`
- Topics []TopicType `json:"topics"`
- AllowP2P bool `json:"allowP2P"`
- }
- var enc Criteria
- enc.SymKeyID = c.SymKeyID
- enc.PrivateKeyID = c.PrivateKeyID
- enc.Sig = c.Sig
- enc.MinPow = c.MinPow
- enc.Topics = c.Topics
- enc.AllowP2P = c.AllowP2P
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals type Criteria to a json string
-func (c *Criteria) UnmarshalJSON(input []byte) error {
- type Criteria struct {
- SymKeyID *string `json:"symKeyID"`
- PrivateKeyID *string `json:"privateKeyID"`
- Sig *hexutil.Bytes `json:"sig"`
- MinPow *float64 `json:"minPow"`
- Topics []TopicType `json:"topics"`
- AllowP2P *bool `json:"allowP2P"`
- }
- var dec Criteria
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.SymKeyID != nil {
- c.SymKeyID = *dec.SymKeyID
- }
- if dec.PrivateKeyID != nil {
- c.PrivateKeyID = *dec.PrivateKeyID
- }
- if dec.Sig != nil {
- c.Sig = *dec.Sig
- }
- if dec.MinPow != nil {
- c.MinPow = *dec.MinPow
- }
- if dec.Topics != nil {
- c.Topics = dec.Topics
- }
- if dec.AllowP2P != nil {
- c.AllowP2P = *dec.AllowP2P
- }
- return nil
-}
diff --git a/whisper/whisperv6/gen_message_json.go b/whisper/whisperv6/gen_message_json.go
deleted file mode 100644
index 6218f5df6ed9..000000000000
--- a/whisper/whisperv6/gen_message_json.go
+++ /dev/null
@@ -1,84 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package whisperv6
-
-import (
- "encoding/json"
-
- "github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-var _ = (*messageOverride)(nil)
-
-// MarshalJSON marshals type Message to a json string
-func (m Message) MarshalJSON() ([]byte, error) {
- type Message struct {
- Sig hexutil.Bytes `json:"sig,omitempty"`
- TTL uint32 `json:"ttl"`
- Timestamp uint32 `json:"timestamp"`
- Topic TopicType `json:"topic"`
- Payload hexutil.Bytes `json:"payload"`
- Padding hexutil.Bytes `json:"padding"`
- PoW float64 `json:"pow"`
- Hash hexutil.Bytes `json:"hash"`
- Dst hexutil.Bytes `json:"recipientPublicKey,omitempty"`
- }
- var enc Message
- enc.Sig = m.Sig
- enc.TTL = m.TTL
- enc.Timestamp = m.Timestamp
- enc.Topic = m.Topic
- enc.Payload = m.Payload
- enc.Padding = m.Padding
- enc.PoW = m.PoW
- enc.Hash = m.Hash
- enc.Dst = m.Dst
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals type Message to a json string
-func (m *Message) UnmarshalJSON(input []byte) error {
- type Message struct {
- Sig *hexutil.Bytes `json:"sig,omitempty"`
- TTL *uint32 `json:"ttl"`
- Timestamp *uint32 `json:"timestamp"`
- Topic *TopicType `json:"topic"`
- Payload *hexutil.Bytes `json:"payload"`
- Padding *hexutil.Bytes `json:"padding"`
- PoW *float64 `json:"pow"`
- Hash *hexutil.Bytes `json:"hash"`
- Dst *hexutil.Bytes `json:"recipientPublicKey,omitempty"`
- }
- var dec Message
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.Sig != nil {
- m.Sig = *dec.Sig
- }
- if dec.TTL != nil {
- m.TTL = *dec.TTL
- }
- if dec.Timestamp != nil {
- m.Timestamp = *dec.Timestamp
- }
- if dec.Topic != nil {
- m.Topic = *dec.Topic
- }
- if dec.Payload != nil {
- m.Payload = *dec.Payload
- }
- if dec.Padding != nil {
- m.Padding = *dec.Padding
- }
- if dec.PoW != nil {
- m.PoW = *dec.PoW
- }
- if dec.Hash != nil {
- m.Hash = *dec.Hash
- }
- if dec.Dst != nil {
- m.Dst = *dec.Dst
- }
- return nil
-}
diff --git a/whisper/whisperv6/gen_newmessage_json.go b/whisper/whisperv6/gen_newmessage_json.go
deleted file mode 100644
index 75a1279ae3ac..000000000000
--- a/whisper/whisperv6/gen_newmessage_json.go
+++ /dev/null
@@ -1,90 +0,0 @@
-// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
-
-package whisperv6
-
-import (
- "encoding/json"
-
- "github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-var _ = (*newMessageOverride)(nil)
-
-// MarshalJSON marshals type NewMessage to a json string
-func (n NewMessage) MarshalJSON() ([]byte, error) {
- type NewMessage struct {
- SymKeyID string `json:"symKeyID"`
- PublicKey hexutil.Bytes `json:"pubKey"`
- Sig string `json:"sig"`
- TTL uint32 `json:"ttl"`
- Topic TopicType `json:"topic"`
- Payload hexutil.Bytes `json:"payload"`
- Padding hexutil.Bytes `json:"padding"`
- PowTime uint32 `json:"powTime"`
- PowTarget float64 `json:"powTarget"`
- TargetPeer string `json:"targetPeer"`
- }
- var enc NewMessage
- enc.SymKeyID = n.SymKeyID
- enc.PublicKey = n.PublicKey
- enc.Sig = n.Sig
- enc.TTL = n.TTL
- enc.Topic = n.Topic
- enc.Payload = n.Payload
- enc.Padding = n.Padding
- enc.PowTime = n.PowTime
- enc.PowTarget = n.PowTarget
- enc.TargetPeer = n.TargetPeer
- return json.Marshal(&enc)
-}
-
-// UnmarshalJSON unmarshals type NewMessage to a json string
-func (n *NewMessage) UnmarshalJSON(input []byte) error {
- type NewMessage struct {
- SymKeyID *string `json:"symKeyID"`
- PublicKey *hexutil.Bytes `json:"pubKey"`
- Sig *string `json:"sig"`
- TTL *uint32 `json:"ttl"`
- Topic *TopicType `json:"topic"`
- Payload *hexutil.Bytes `json:"payload"`
- Padding *hexutil.Bytes `json:"padding"`
- PowTime *uint32 `json:"powTime"`
- PowTarget *float64 `json:"powTarget"`
- TargetPeer *string `json:"targetPeer"`
- }
- var dec NewMessage
- if err := json.Unmarshal(input, &dec); err != nil {
- return err
- }
- if dec.SymKeyID != nil {
- n.SymKeyID = *dec.SymKeyID
- }
- if dec.PublicKey != nil {
- n.PublicKey = *dec.PublicKey
- }
- if dec.Sig != nil {
- n.Sig = *dec.Sig
- }
- if dec.TTL != nil {
- n.TTL = *dec.TTL
- }
- if dec.Topic != nil {
- n.Topic = *dec.Topic
- }
- if dec.Payload != nil {
- n.Payload = *dec.Payload
- }
- if dec.Padding != nil {
- n.Padding = *dec.Padding
- }
- if dec.PowTime != nil {
- n.PowTime = *dec.PowTime
- }
- if dec.PowTarget != nil {
- n.PowTarget = *dec.PowTarget
- }
- if dec.TargetPeer != nil {
- n.TargetPeer = *dec.TargetPeer
- }
- return nil
-}
diff --git a/whisper/whisperv6/message.go b/whisper/whisperv6/message.go
deleted file mode 100644
index 2d4e86244109..000000000000
--- a/whisper/whisperv6/message.go
+++ /dev/null
@@ -1,355 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Contains the Whisper protocol Message element.
-
-package whisperv6
-
-import (
- "crypto/aes"
- "crypto/cipher"
- "crypto/ecdsa"
- crand "crypto/rand"
- "encoding/binary"
- "errors"
- mrand "math/rand"
- "strconv"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/crypto/ecies"
- "github.com/ethereum/go-ethereum/log"
-)
-
-// MessageParams specifies the exact way a message should be wrapped
-// into an Envelope.
-type MessageParams struct {
- TTL uint32
- Src *ecdsa.PrivateKey
- Dst *ecdsa.PublicKey
- KeySym []byte
- Topic TopicType
- WorkTime uint32
- PoW float64
- Payload []byte
- Padding []byte
-}
-
-// SentMessage represents an end-user data packet to transmit through the
-// Whisper protocol. These are wrapped into Envelopes that need not be
-// understood by intermediate nodes, just forwarded.
-type sentMessage struct {
- Raw []byte
-}
-
-// ReceivedMessage represents a data packet to be received through the
-// Whisper protocol and successfully decrypted.
-type ReceivedMessage struct {
- Raw []byte
-
- Payload []byte
- Padding []byte
- Signature []byte
- Salt []byte
-
- PoW float64 // Proof of work as described in the Whisper spec
- Sent uint32 // Time when the message was posted into the network
- TTL uint32 // Maximum time to live allowed for the message
- Src *ecdsa.PublicKey // Message recipient (identity used to decode the message)
- Dst *ecdsa.PublicKey // Message recipient (identity used to decode the message)
- Topic TopicType
-
- SymKeyHash common.Hash // The Keccak256Hash of the key
- EnvelopeHash common.Hash // Message envelope hash to act as a unique id
-}
-
-func isMessageSigned(flags byte) bool {
- return (flags & signatureFlag) != 0
-}
-
-func (msg *ReceivedMessage) isSymmetricEncryption() bool {
- return msg.SymKeyHash != common.Hash{}
-}
-
-func (msg *ReceivedMessage) isAsymmetricEncryption() bool {
- return msg.Dst != nil
-}
-
-// NewSentMessage creates and initializes a non-signed, non-encrypted Whisper message.
-func NewSentMessage(params *MessageParams) (*sentMessage, error) {
- const payloadSizeFieldMaxSize = 4
- msg := sentMessage{}
- msg.Raw = make([]byte, 1,
- flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
- msg.Raw[0] = 0 // set all the flags to zero
- msg.addPayloadSizeField(params.Payload)
- msg.Raw = append(msg.Raw, params.Payload...)
- err := msg.appendPadding(params)
- return &msg, err
-}
-
-// addPayloadSizeField appends the auxiliary field containing the size of payload
-func (msg *sentMessage) addPayloadSizeField(payload []byte) {
- fieldSize := getSizeOfPayloadSizeField(payload)
- field := make([]byte, 4)
- binary.LittleEndian.PutUint32(field, uint32(len(payload)))
- field = field[:fieldSize]
- msg.Raw = append(msg.Raw, field...)
- msg.Raw[0] |= byte(fieldSize)
-}
-
-// getSizeOfPayloadSizeField returns the number of bytes necessary to encode the size of payload
-func getSizeOfPayloadSizeField(payload []byte) int {
- s := 1
- for i := len(payload); i >= 256; i /= 256 {
- s++
- }
- return s
-}
-
-// appendPadding appends the padding specified in params.
-// If no padding is provided in params, then random padding is generated.
-func (msg *sentMessage) appendPadding(params *MessageParams) error {
- if len(params.Padding) != 0 {
- // padding data was provided by the Dapp, just use it as is
- msg.Raw = append(msg.Raw, params.Padding...)
- return nil
- }
-
- rawSize := flagsLength + getSizeOfPayloadSizeField(params.Payload) + len(params.Payload)
- if params.Src != nil {
- rawSize += signatureLength
- }
- odd := rawSize % padSizeLimit
- paddingSize := padSizeLimit - odd
- pad := make([]byte, paddingSize)
- _, err := crand.Read(pad)
- if err != nil {
- return err
- }
- if !validateDataIntegrity(pad, paddingSize) {
- return errors.New("failed to generate random padding of size " + strconv.Itoa(paddingSize))
- }
- msg.Raw = append(msg.Raw, pad...)
- return nil
-}
-
-// sign calculates and sets the cryptographic signature for the message,
-// also setting the sign flag.
-func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error {
- if isMessageSigned(msg.Raw[0]) {
- // this should not happen, but no reason to panic
- log.Error("failed to sign the message: already signed")
- return nil
- }
-
- msg.Raw[0] |= signatureFlag // it is important to set this flag before signing
- hash := crypto.Keccak256(msg.Raw)
- signature, err := crypto.Sign(hash, key)
- if err != nil {
- msg.Raw[0] &= (0xFF ^ signatureFlag) // clear the flag
- return err
- }
- msg.Raw = append(msg.Raw, signature...)
- return nil
-}
-
-// encryptAsymmetric encrypts a message with a public key.
-func (msg *sentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
- if !ValidatePublicKey(key) {
- return errors.New("invalid public key provided for asymmetric encryption")
- }
- encrypted, err := ecies.Encrypt(crand.Reader, ecies.ImportECDSAPublic(key), msg.Raw, nil, nil)
- if err == nil {
- msg.Raw = encrypted
- }
- return err
-}
-
-// encryptSymmetric encrypts a message with a topic key, using AES-GCM-256.
-// nonce size should be 12 bytes (see cipher.gcmStandardNonceSize).
-func (msg *sentMessage) encryptSymmetric(key []byte) (err error) {
- if !validateDataIntegrity(key, aesKeyLength) {
- return errors.New("invalid key provided for symmetric encryption, size: " + strconv.Itoa(len(key)))
- }
- block, err := aes.NewCipher(key)
- if err != nil {
- return err
- }
- aesgcm, err := cipher.NewGCM(block)
- if err != nil {
- return err
- }
- salt, err := generateSecureRandomData(aesNonceLength) // never use more than 2^32 random nonces with a given key
- if err != nil {
- return err
- }
- encrypted := aesgcm.Seal(nil, salt, msg.Raw, nil)
- msg.Raw = append(encrypted, salt...)
- return nil
-}
-
-// generateSecureRandomData generates random data where extra security is required.
-// The purpose of this function is to prevent some bugs in software or in hardware
-// from delivering not-very-random data. This is especially useful for AES nonce,
-// where true randomness does not really matter, but it is very important to have
-// a unique nonce for every message.
-func generateSecureRandomData(length int) ([]byte, error) {
- x := make([]byte, length)
- y := make([]byte, length)
- res := make([]byte, length)
-
- _, err := crand.Read(x)
- if err != nil {
- return nil, err
- } else if !validateDataIntegrity(x, length) {
- return nil, errors.New("crypto/rand failed to generate secure random data")
- }
- _, err = mrand.Read(y)
- if err != nil {
- return nil, err
- } else if !validateDataIntegrity(y, length) {
- return nil, errors.New("math/rand failed to generate secure random data")
- }
- for i := 0; i < length; i++ {
- res[i] = x[i] ^ y[i]
- }
- if !validateDataIntegrity(res, length) {
- return nil, errors.New("failed to generate secure random data")
- }
- return res, nil
-}
-
-// Wrap bundles the message into an Envelope to transmit over the network.
-func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err error) {
- if options.TTL == 0 {
- options.TTL = DefaultTTL
- }
- if options.Src != nil {
- if err = msg.sign(options.Src); err != nil {
- return nil, err
- }
- }
- if options.Dst != nil {
- err = msg.encryptAsymmetric(options.Dst)
- } else if options.KeySym != nil {
- err = msg.encryptSymmetric(options.KeySym)
- } else {
- err = errors.New("unable to encrypt the message: neither symmetric nor assymmetric key provided")
- }
- if err != nil {
- return nil, err
- }
-
- envelope = NewEnvelope(options.TTL, options.Topic, msg)
- if err = envelope.Seal(options); err != nil {
- return nil, err
- }
- return envelope, nil
-}
-
-// decryptSymmetric decrypts a message with a topic key, using AES-GCM-256.
-// nonce size should be 12 bytes (see cipher.gcmStandardNonceSize).
-func (msg *ReceivedMessage) decryptSymmetric(key []byte) error {
- // symmetric messages are expected to contain the 12-byte nonce at the end of the payload
- if len(msg.Raw) < aesNonceLength {
- return errors.New("missing salt or invalid payload in symmetric message")
- }
- salt := msg.Raw[len(msg.Raw)-aesNonceLength:]
-
- block, err := aes.NewCipher(key)
- if err != nil {
- return err
- }
- aesgcm, err := cipher.NewGCM(block)
- if err != nil {
- return err
- }
- decrypted, err := aesgcm.Open(nil, salt, msg.Raw[:len(msg.Raw)-aesNonceLength], nil)
- if err != nil {
- return err
- }
- msg.Raw = decrypted
- msg.Salt = salt
- return nil
-}
-
-// decryptAsymmetric decrypts an encrypted payload with a private key.
-func (msg *ReceivedMessage) decryptAsymmetric(key *ecdsa.PrivateKey) error {
- decrypted, err := ecies.ImportECDSA(key).Decrypt(msg.Raw, nil, nil)
- if err == nil {
- msg.Raw = decrypted
- }
- return err
-}
-
-// ValidateAndParse checks the message validity and extracts the fields in case of success.
-func (msg *ReceivedMessage) ValidateAndParse() bool {
- end := len(msg.Raw)
- if end < 1 {
- return false
- }
-
- if isMessageSigned(msg.Raw[0]) {
- end -= signatureLength
- if end <= 1 {
- return false
- }
- msg.Signature = msg.Raw[end : end+signatureLength]
- msg.Src = msg.SigToPubKey()
- if msg.Src == nil {
- return false
- }
- }
-
- beg := 1
- payloadSize := 0
- sizeOfPayloadSizeField := int(msg.Raw[0] & SizeMask) // number of bytes indicating the size of payload
- if sizeOfPayloadSizeField != 0 {
- payloadSize = int(bytesToUintLittleEndian(msg.Raw[beg : beg+sizeOfPayloadSizeField]))
- if payloadSize+1 > end {
- return false
- }
- beg += sizeOfPayloadSizeField
- msg.Payload = msg.Raw[beg : beg+payloadSize]
- }
-
- beg += payloadSize
- msg.Padding = msg.Raw[beg:end]
- return true
-}
-
-// SigToPubKey returns the public key associated to the message's
-// signature.
-func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey {
- defer func() { recover() }() // in case of invalid signature
-
- pub, err := crypto.SigToPub(msg.hash(), msg.Signature)
- if err != nil {
- log.Error("failed to recover public key from signature", "err", err)
- return nil
- }
- return pub
-}
-
-// hash calculates the SHA3 checksum of the message flags, payload size field, payload and padding.
-func (msg *ReceivedMessage) hash() []byte {
- if isMessageSigned(msg.Raw[0]) {
- sz := len(msg.Raw) - signatureLength
- return crypto.Keccak256(msg.Raw[:sz])
- }
- return crypto.Keccak256(msg.Raw)
-}
diff --git a/whisper/whisperv6/message_test.go b/whisper/whisperv6/message_test.go
deleted file mode 100644
index ece6d732cc13..000000000000
--- a/whisper/whisperv6/message_test.go
+++ /dev/null
@@ -1,471 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "bytes"
- "crypto/aes"
- "crypto/cipher"
- mrand "math/rand"
- "testing"
-
- "github.com/ethereum/go-ethereum/common/hexutil"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/rlp"
-)
-
-func generateMessageParams() (*MessageParams, error) {
- // set all the parameters except p.Dst and p.Padding
-
- buf := make([]byte, 4)
- mrand.Read(buf)
- sz := mrand.Intn(400)
-
- var p MessageParams
- p.PoW = 0.001
- p.WorkTime = 1
- p.TTL = uint32(mrand.Intn(1024))
- p.Payload = make([]byte, sz)
- p.KeySym = make([]byte, aesKeyLength)
- mrand.Read(p.Payload)
- mrand.Read(p.KeySym)
- p.Topic = BytesToTopic(buf)
-
- var err error
- p.Src, err = crypto.GenerateKey()
- if err != nil {
- return nil, err
- }
-
- return &p, nil
-}
-
-func singleMessageTest(t *testing.T, symmetric bool) {
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- key, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
-
- if !symmetric {
- params.KeySym = nil
- params.Dst = &key.PublicKey
- }
-
- text := make([]byte, 0, 512)
- text = append(text, params.Payload...)
-
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- var decrypted *ReceivedMessage
- if symmetric {
- decrypted, err = env.OpenSymmetric(params.KeySym)
- } else {
- decrypted, err = env.OpenAsymmetric(key)
- }
-
- if err != nil {
- t.Fatalf("failed to encrypt with seed %d: %s.", seed, err)
- }
-
- if !decrypted.ValidateAndParse() {
- t.Fatalf("failed to validate with seed %d, symmetric = %v.", seed, symmetric)
- }
-
- if !bytes.Equal(text, decrypted.Payload) {
- t.Fatalf("failed with seed %d: compare payload.", seed)
- }
- if !isMessageSigned(decrypted.Raw[0]) {
- t.Fatalf("failed with seed %d: unsigned.", seed)
- }
- if len(decrypted.Signature) != signatureLength {
- t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
- }
- if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) {
- t.Fatalf("failed with seed %d: signature mismatch.", seed)
- }
-}
-
-func TestMessageEncryption(t *testing.T) {
- InitSingleTest()
-
- var symmetric bool
- for i := 0; i < 256; i++ {
- singleMessageTest(t, symmetric)
- symmetric = !symmetric
- }
-}
-
-func TestMessageWrap(t *testing.T) {
- seed = int64(1777444222)
- mrand.Seed(seed)
- target := 128.0
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.TTL = 1
- params.WorkTime = 12
- params.PoW = target
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- pow := env.PoW()
- if pow < target {
- t.Fatalf("failed Wrap with seed %d: pow < target (%f vs. %f).", seed, pow, target)
- }
-
- // set PoW target too high, expect error
- msg2, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.TTL = 1000000
- params.WorkTime = 1
- params.PoW = 10000000.0
- _, err = msg2.Wrap(params)
- if err == nil {
- t.Fatalf("unexpectedly reached the PoW target with seed %d.", seed)
- }
-}
-
-func TestMessageSeal(t *testing.T) {
- // this test depends on deterministic choice of seed (1976726903)
- seed = int64(1976726903)
- mrand.Seed(seed)
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.TTL = 1
-
- env := NewEnvelope(params.TTL, params.Topic, msg)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- env.Expiry = uint32(seed) // make it deterministic
- target := 32.0
- params.WorkTime = 4
- params.PoW = target
- env.Seal(params)
-
- env.calculatePoW(0)
- pow := env.PoW()
- if pow < target {
- t.Fatalf("failed Wrap with seed %d: pow < target (%f vs. %f).", seed, pow, target)
- }
-
- params.WorkTime = 1
- params.PoW = 1000000000.0
- env.Seal(params)
- env.calculatePoW(0)
- pow = env.PoW()
- if pow < 2*target {
- t.Fatalf("failed Wrap with seed %d: pow too small %f.", seed, pow)
- }
-}
-
-func TestEnvelopeOpen(t *testing.T) {
- InitSingleTest()
-
- var symmetric bool
- for i := 0; i < 32; i++ {
- singleEnvelopeOpenTest(t, symmetric)
- symmetric = !symmetric
- }
-}
-
-func singleEnvelopeOpenTest(t *testing.T, symmetric bool) {
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- key, err := crypto.GenerateKey()
- if err != nil {
- t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
- }
-
- if !symmetric {
- params.KeySym = nil
- params.Dst = &key.PublicKey
- }
-
- text := make([]byte, 0, 512)
- text = append(text, params.Payload...)
-
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- var f Filter
- if symmetric {
- f = Filter{KeySym: params.KeySym}
- } else {
- f = Filter{KeyAsym: key}
- }
- decrypted := env.Open(&f)
- if decrypted == nil {
- t.Fatalf("failed to open with seed %d.", seed)
- }
-
- if !bytes.Equal(text, decrypted.Payload) {
- t.Fatalf("failed with seed %d: compare payload.", seed)
- }
- if !isMessageSigned(decrypted.Raw[0]) {
- t.Fatalf("failed with seed %d: unsigned.", seed)
- }
- if len(decrypted.Signature) != signatureLength {
- t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
- }
- if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) {
- t.Fatalf("failed with seed %d: signature mismatch.", seed)
- }
- if decrypted.isAsymmetricEncryption() == symmetric {
- t.Fatalf("failed with seed %d: asymmetric %v vs. %v.", seed, decrypted.isAsymmetricEncryption(), symmetric)
- }
- if decrypted.isSymmetricEncryption() != symmetric {
- t.Fatalf("failed with seed %d: symmetric %v vs. %v.", seed, decrypted.isSymmetricEncryption(), symmetric)
- }
- if !symmetric {
- if decrypted.Dst == nil {
- t.Fatalf("failed with seed %d: dst is nil.", seed)
- }
- if !IsPubKeyEqual(decrypted.Dst, &key.PublicKey) {
- t.Fatalf("failed with seed %d: Dst.", seed)
- }
- }
-}
-
-func TestEncryptWithZeroKey(t *testing.T) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.KeySym = make([]byte, aesKeyLength)
- _, err = msg.Wrap(params)
- if err == nil {
- t.Fatalf("wrapped with zero key, seed: %d.", seed)
- }
-
- params, err = generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, err = NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.KeySym = make([]byte, 0)
- _, err = msg.Wrap(params)
- if err == nil {
- t.Fatalf("wrapped with empty key, seed: %d.", seed)
- }
-
- params, err = generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, err = NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- params.KeySym = nil
- _, err = msg.Wrap(params)
- if err == nil {
- t.Fatalf("wrapped with nil key, seed: %d.", seed)
- }
-}
-
-func TestRlpEncode(t *testing.T) {
- InitSingleTest()
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("wrapped with zero key, seed: %d.", seed)
- }
-
- raw, err := rlp.EncodeToBytes(env)
- if err != nil {
- t.Fatalf("RLP encode failed: %s.", err)
- }
-
- var decoded Envelope
- rlp.DecodeBytes(raw, &decoded)
- if err != nil {
- t.Fatalf("RLP decode failed: %s.", err)
- }
-
- he := env.Hash()
- hd := decoded.Hash()
-
- if he != hd {
- t.Fatalf("Hashes are not equal: %x vs. %x", he, hd)
- }
-}
-
-func singlePaddingTest(t *testing.T, padSize int) {
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d and sz=%d: %s.", seed, padSize, err)
- }
- params.Padding = make([]byte, padSize)
- params.PoW = 0.0000000001
- pad := make([]byte, padSize)
- _, err = mrand.Read(pad)
- if err != nil {
- t.Fatalf("padding is not generated (seed %d): %s", seed, err)
- }
- n := copy(params.Padding, pad)
- if n != padSize {
- t.Fatalf("padding is not copied (seed %d): %s", seed, err)
- }
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed to wrap, seed: %d and sz=%d.", seed, padSize)
- }
- f := Filter{KeySym: params.KeySym}
- decrypted := env.Open(&f)
- if decrypted == nil {
- t.Fatalf("failed to open, seed and sz=%d: %d.", seed, padSize)
- }
- if !bytes.Equal(pad, decrypted.Padding) {
- t.Fatalf("padding is not retireved as expected with seed %d and sz=%d:\n[%x]\n[%x].", seed, padSize, pad, decrypted.Padding)
- }
-}
-
-func TestPadding(t *testing.T) {
- InitSingleTest()
-
- for i := 1; i < 260; i++ {
- singlePaddingTest(t, i)
- }
-
- lim := 256 * 256
- for i := lim - 5; i < lim+2; i++ {
- singlePaddingTest(t, i)
- }
-
- for i := 0; i < 256; i++ {
- n := mrand.Intn(256*254) + 256
- singlePaddingTest(t, n)
- }
-
- for i := 0; i < 256; i++ {
- n := mrand.Intn(256*1024) + 256*256
- singlePaddingTest(t, n)
- }
-}
-
-func TestPaddingAppendedToSymMessagesWithSignature(t *testing.T) {
- params := &MessageParams{
- Payload: make([]byte, 246),
- KeySym: make([]byte, aesKeyLength),
- }
-
- pSrc, err := crypto.GenerateKey()
-
- if err != nil {
- t.Fatalf("Error creating the signature key %v", err)
- return
- }
- params.Src = pSrc
-
- // Simulate a message with a payload just under 256 so that
- // payload + flag + signature > 256. Check that the result
- // is padded on the next 256 boundary.
- msg := sentMessage{}
- const payloadSizeFieldMinSize = 1
- msg.Raw = make([]byte, flagsLength+payloadSizeFieldMinSize+len(params.Payload))
-
- err = msg.appendPadding(params)
-
- if err != nil {
- t.Fatalf("Error appending padding to message %v", err)
- return
- }
-
- if len(msg.Raw) != 512-signatureLength {
- t.Errorf("Invalid size %d != 512", len(msg.Raw))
- }
-}
-
-func TestAesNonce(t *testing.T) {
- key := hexutil.MustDecode("0x03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31")
- block, err := aes.NewCipher(key)
- if err != nil {
- t.Fatalf("NewCipher failed: %s", err)
- }
- aesgcm, err := cipher.NewGCM(block)
- if err != nil {
- t.Fatalf("NewGCM failed: %s", err)
- }
- // This is the most important single test in this package.
- // If it fails, whisper will not be working.
- if aesgcm.NonceSize() != aesNonceLength {
- t.Fatalf("Nonce size is wrong. This is a critical error. Apparently AES nonce size have changed in the new version of AES GCM package. Whisper will not be working until this problem is resolved.")
- }
-}
diff --git a/whisper/whisperv6/peer.go b/whisper/whisperv6/peer.go
deleted file mode 100644
index 68fa7c8cba78..000000000000
--- a/whisper/whisperv6/peer.go
+++ /dev/null
@@ -1,268 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "fmt"
- "math"
- "sync"
- "time"
-
- mapset "github.com/deckarep/golang-set"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/rlp"
-)
-
-// Peer represents a whisper protocol peer connection.
-type Peer struct {
- host *Whisper
- peer *p2p.Peer
- ws p2p.MsgReadWriter
-
- trusted bool
- powRequirement float64
- bloomMu sync.Mutex
- bloomFilter []byte
- fullNode bool
-
- known mapset.Set // Messages already known by the peer to avoid wasting bandwidth
-
- quit chan struct{}
-
- wg sync.WaitGroup
-}
-
-// newPeer creates a new whisper peer object, but does not run the handshake itself.
-func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
- return &Peer{
- host: host,
- peer: remote,
- ws: rw,
- trusted: false,
- powRequirement: 0.0,
- known: mapset.NewSet(),
- quit: make(chan struct{}),
- bloomFilter: MakeFullNodeBloom(),
- fullNode: true,
- }
-}
-
-// start initiates the peer updater, periodically broadcasting the whisper packets
-// into the network.
-func (peer *Peer) start() {
- peer.wg.Add(1)
- go peer.update()
- log.Trace("start", "peer", peer.ID())
-}
-
-// stop terminates the peer updater, stopping message forwarding to it.
-func (peer *Peer) stop() {
- close(peer.quit)
- peer.wg.Wait()
- log.Trace("stop", "peer", peer.ID())
-}
-
-// handshake sends the protocol initiation status message to the remote peer and
-// verifies the remote status too.
-func (peer *Peer) handshake() error {
- // Send the handshake status message asynchronously
- errc := make(chan error, 1)
- isLightNode := peer.host.LightClientMode()
- isRestrictedLightNodeConnection := peer.host.LightClientModeConnectionRestricted()
- peer.wg.Add(1)
- go func() {
- defer peer.wg.Done()
- pow := peer.host.MinPow()
- powConverted := math.Float64bits(pow)
- bloom := peer.host.BloomFilter()
-
- errc <- p2p.SendItems(peer.ws, statusCode, ProtocolVersion, powConverted, bloom, isLightNode)
- }()
-
- // Fetch the remote status packet and verify protocol match
- packet, err := peer.ws.ReadMsg()
- if err != nil {
- return err
- }
- if packet.Code != statusCode {
- return fmt.Errorf("peer [%x] sent packet %x before status packet", peer.ID(), packet.Code)
- }
- s := rlp.NewStream(packet.Payload, uint64(packet.Size))
- _, err = s.List()
- if err != nil {
- return fmt.Errorf("peer [%x] sent bad status message: %v", peer.ID(), err)
- }
- peerVersion, err := s.Uint()
- if err != nil {
- return fmt.Errorf("peer [%x] sent bad status message (unable to decode version): %v", peer.ID(), err)
- }
- if peerVersion != ProtocolVersion {
- return fmt.Errorf("peer [%x]: protocol version mismatch %d != %d", peer.ID(), peerVersion, ProtocolVersion)
- }
-
- // only version is mandatory, subsequent parameters are optional
- powRaw, err := s.Uint()
- if err == nil {
- pow := math.Float64frombits(powRaw)
- if math.IsInf(pow, 0) || math.IsNaN(pow) || pow < 0.0 {
- return fmt.Errorf("peer [%x] sent bad status message: invalid pow", peer.ID())
- }
- peer.powRequirement = pow
-
- var bloom []byte
- err = s.Decode(&bloom)
- if err == nil {
- sz := len(bloom)
- if sz != BloomFilterSize && sz != 0 {
- return fmt.Errorf("peer [%x] sent bad status message: wrong bloom filter size %d", peer.ID(), sz)
- }
- peer.setBloomFilter(bloom)
- }
- }
-
- isRemotePeerLightNode, _ := s.Bool()
- if isRemotePeerLightNode && isLightNode && isRestrictedLightNodeConnection {
- return fmt.Errorf("peer [%x] is useless: two light client communication restricted", peer.ID())
- }
-
- if err := <-errc; err != nil {
- return fmt.Errorf("peer [%x] failed to send status packet: %v", peer.ID(), err)
- }
- return nil
-}
-
-// update executes periodic operations on the peer, including message transmission
-// and expiration.
-func (peer *Peer) update() {
- defer peer.wg.Done()
- // Start the tickers for the updates
- expire := time.NewTicker(expirationCycle)
- defer expire.Stop()
- transmit := time.NewTicker(transmissionCycle)
- defer transmit.Stop()
-
- // Loop and transmit until termination is requested
- for {
- select {
- case <-expire.C:
- peer.expire()
-
- case <-transmit.C:
- if err := peer.broadcast(); err != nil {
- log.Trace("broadcast failed", "reason", err, "peer", peer.ID())
- return
- }
-
- case <-peer.quit:
- return
- }
- }
-}
-
-// mark marks an envelope known to the peer so that it won't be sent back.
-func (peer *Peer) mark(envelope *Envelope) {
- peer.known.Add(envelope.Hash())
-}
-
-// marked checks if an envelope is already known to the remote peer.
-func (peer *Peer) marked(envelope *Envelope) bool {
- return peer.known.Contains(envelope.Hash())
-}
-
-// expire iterates over all the known envelopes in the host and removes all
-// expired (unknown) ones from the known list.
-func (peer *Peer) expire() {
- unmark := make(map[common.Hash]struct{})
- peer.known.Each(func(v interface{}) bool {
- if !peer.host.isEnvelopeCached(v.(common.Hash)) {
- unmark[v.(common.Hash)] = struct{}{}
- }
- return true
- })
- // Dump all known but no longer cached
- for hash := range unmark {
- peer.known.Remove(hash)
- }
-}
-
-// broadcast iterates over the collection of envelopes and transmits yet unknown
-// ones over the network.
-func (peer *Peer) broadcast() error {
- envelopes := peer.host.Envelopes()
- bundle := make([]*Envelope, 0, len(envelopes))
- for _, envelope := range envelopes {
- if !peer.marked(envelope) && envelope.PoW() >= peer.powRequirement && peer.bloomMatch(envelope) {
- bundle = append(bundle, envelope)
- }
- }
-
- if len(bundle) > 0 {
- // transmit the batch of envelopes
- if err := p2p.Send(peer.ws, messagesCode, bundle); err != nil {
- return err
- }
-
- // mark envelopes only if they were successfully sent
- for _, e := range bundle {
- peer.mark(e)
- }
-
- log.Trace("broadcast", "num. messages", len(bundle))
- }
- return nil
-}
-
-// ID returns a peer's id
-func (peer *Peer) ID() []byte {
- id := peer.peer.ID()
- return id[:]
-}
-
-func (peer *Peer) notifyAboutPowRequirementChange(pow float64) error {
- i := math.Float64bits(pow)
- return p2p.Send(peer.ws, powRequirementCode, i)
-}
-
-func (peer *Peer) notifyAboutBloomFilterChange(bloom []byte) error {
- return p2p.Send(peer.ws, bloomFilterExCode, bloom)
-}
-
-func (peer *Peer) bloomMatch(env *Envelope) bool {
- peer.bloomMu.Lock()
- defer peer.bloomMu.Unlock()
- return peer.fullNode || BloomFilterMatch(peer.bloomFilter, env.Bloom())
-}
-
-func (peer *Peer) setBloomFilter(bloom []byte) {
- peer.bloomMu.Lock()
- defer peer.bloomMu.Unlock()
- peer.bloomFilter = bloom
- peer.fullNode = isFullNode(bloom)
- if peer.fullNode && peer.bloomFilter == nil {
- peer.bloomFilter = MakeFullNodeBloom()
- }
-}
-
-func MakeFullNodeBloom() []byte {
- bloom := make([]byte, BloomFilterSize)
- for i := 0; i < BloomFilterSize; i++ {
- bloom[i] = 0xFF
- }
- return bloom
-}
diff --git a/whisper/whisperv6/topic.go b/whisper/whisperv6/topic.go
deleted file mode 100644
index ee255f785da8..000000000000
--- a/whisper/whisperv6/topic.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Contains the Whisper protocol Topic element.
-
-package whisperv6
-
-import (
- "github.com/ethereum/go-ethereum/common/hexutil"
-)
-
-// TopicType represents a cryptographically secure, probabilistic partial
-// classifications of a message, determined as the first (left) 4 bytes of the
-// SHA3 hash of some arbitrary data given by the original author of the message.
-type TopicType [TopicLength]byte
-
-// BytesToTopic converts from the byte array representation of a topic
-// into the TopicType type.
-func BytesToTopic(b []byte) (t TopicType) {
- sz := TopicLength
- if x := len(b); x < TopicLength {
- sz = x
- }
- for i := 0; i < sz; i++ {
- t[i] = b[i]
- }
- return t
-}
-
-// String converts a topic byte array to a string representation.
-func (t *TopicType) String() string {
- return hexutil.Encode(t[:])
-}
-
-// MarshalText returns the hex representation of t.
-func (t TopicType) MarshalText() ([]byte, error) {
- return hexutil.Bytes(t[:]).MarshalText()
-}
-
-// UnmarshalText parses a hex representation to a topic.
-func (t *TopicType) UnmarshalText(input []byte) error {
- return hexutil.UnmarshalFixedText("Topic", input, t[:])
-}
diff --git a/whisper/whisperv6/topic_test.go b/whisper/whisperv6/topic_test.go
deleted file mode 100644
index 454afe0de17d..000000000000
--- a/whisper/whisperv6/topic_test.go
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "encoding/json"
- "testing"
-)
-
-var topicStringTests = []struct {
- topic TopicType
- str string
-}{
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, str: "0x00000000"},
- {topic: TopicType{0x00, 0x7f, 0x80, 0xff}, str: "0x007f80ff"},
- {topic: TopicType{0xff, 0x80, 0x7f, 0x00}, str: "0xff807f00"},
- {topic: TopicType{0xf2, 0x6e, 0x77, 0x79}, str: "0xf26e7779"},
-}
-
-func TestTopicString(t *testing.T) {
- for i, tst := range topicStringTests {
- s := tst.topic.String()
- if s != tst.str {
- t.Fatalf("failed test %d: have %s, want %s.", i, s, tst.str)
- }
- }
-}
-
-var bytesToTopicTests = []struct {
- data []byte
- topic TopicType
-}{
- {topic: TopicType{0x8f, 0x9a, 0x2b, 0x7d}, data: []byte{0x8f, 0x9a, 0x2b, 0x7d}},
- {topic: TopicType{0x00, 0x7f, 0x80, 0xff}, data: []byte{0x00, 0x7f, 0x80, 0xff}},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte{0x00, 0x00, 0x00, 0x00}},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte{0x00, 0x00, 0x00}},
- {topic: TopicType{0x01, 0x00, 0x00, 0x00}, data: []byte{0x01}},
- {topic: TopicType{0x00, 0xfe, 0x00, 0x00}, data: []byte{0x00, 0xfe}},
- {topic: TopicType{0xea, 0x1d, 0x43, 0x00}, data: []byte{0xea, 0x1d, 0x43}},
- {topic: TopicType{0x6f, 0x3c, 0xb0, 0xdd}, data: []byte{0x6f, 0x3c, 0xb0, 0xdd, 0x0f, 0x00, 0x90}},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte{}},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: nil},
-}
-
-var unmarshalTestsGood = []struct {
- topic TopicType
- data []byte
-}{
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0x00000000"`)},
- {topic: TopicType{0x00, 0x7f, 0x80, 0xff}, data: []byte(`"0x007f80ff"`)},
- {topic: TopicType{0xff, 0x80, 0x7f, 0x00}, data: []byte(`"0xff807f00"`)},
- {topic: TopicType{0xf2, 0x6e, 0x77, 0x79}, data: []byte(`"0xf26e7779"`)},
-}
-
-var unmarshalTestsBad = []struct {
- topic TopicType
- data []byte
-}{
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0x000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0x0000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0x000000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0x0000000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"000000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"0000000000"`)},
- {topic: TopicType{0x00, 0x00, 0x00, 0x00}, data: []byte(`"abcdefg0"`)},
-}
-
-var unmarshalTestsUgly = []struct {
- topic TopicType
- data []byte
-}{
- {topic: TopicType{0x01, 0x00, 0x00, 0x00}, data: []byte(`"0x00000001"`)},
-}
-
-func TestBytesToTopic(t *testing.T) {
- for i, tst := range bytesToTopicTests {
- top := BytesToTopic(tst.data)
- if top != tst.topic {
- t.Fatalf("failed test %d: have %v, want %v.", i, t, tst.topic)
- }
- }
-}
-
-func TestUnmarshalTestsGood(t *testing.T) {
- for i, tst := range unmarshalTestsGood {
- var top TopicType
- err := json.Unmarshal(tst.data, &top)
- if err != nil {
- t.Errorf("failed test %d. input: %v. err: %v", i, tst.data, err)
- } else if top != tst.topic {
- t.Errorf("failed test %d: have %v, want %v.", i, t, tst.topic)
- }
- }
-}
-
-func TestUnmarshalTestsBad(t *testing.T) {
- // in this test UnmarshalJSON() is supposed to fail
- for i, tst := range unmarshalTestsBad {
- var top TopicType
- err := json.Unmarshal(tst.data, &top)
- if err == nil {
- t.Fatalf("failed test %d. input: %v.", i, tst.data)
- }
- }
-}
-
-func TestUnmarshalTestsUgly(t *testing.T) {
- // in this test UnmarshalJSON() is NOT supposed to fail, but result should be wrong
- for i, tst := range unmarshalTestsUgly {
- var top TopicType
- err := json.Unmarshal(tst.data, &top)
- if err != nil {
- t.Errorf("failed test %d. input: %v.", i, tst.data)
- } else if top == tst.topic {
- t.Errorf("failed test %d: have %v, want %v.", i, top, tst.topic)
- }
- }
-}
diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go
deleted file mode 100644
index 8fe648a7a7f6..000000000000
--- a/whisper/whisperv6/whisper.go
+++ /dev/null
@@ -1,1094 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "bytes"
- "crypto/ecdsa"
- "crypto/sha256"
- "fmt"
- "math"
- "runtime"
- "sync"
- "time"
-
- mapset "github.com/deckarep/golang-set"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/p2p"
- "github.com/ethereum/go-ethereum/rlp"
- "github.com/ethereum/go-ethereum/rpc"
- "github.com/syndtr/goleveldb/leveldb/errors"
- "golang.org/x/crypto/pbkdf2"
- "golang.org/x/sync/syncmap"
-)
-
-// Statistics holds several message-related counter for analytics
-// purposes.
-type Statistics struct {
- messagesCleared int
- memoryCleared int
- memoryUsed int
- cycles int
- totalMessagesCleared int
-}
-
-const (
- maxMsgSizeIdx = iota // Maximal message length allowed by the whisper node
- overflowIdx // Indicator of message queue overflow
- minPowIdx // Minimal PoW required by the whisper node
- minPowToleranceIdx // Minimal PoW tolerated by the whisper node for a limited time
- bloomFilterIdx // Bloom filter for topics of interest for this node
- bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time
- lightClientModeIdx // Light client mode. (does not forward any messages)
- restrictConnectionBetweenLightClientsIdx // Restrict connection between two light clients
-)
-
-// Whisper represents a dark communication interface through the Ethereum
-// network, using its very own P2P communication layer.
-type Whisper struct {
- protocol p2p.Protocol // Protocol description and parameters
- filters *Filters // Message filters installed with Subscribe function
-
- privateKeys map[string]*ecdsa.PrivateKey // Private key storage
- symKeys map[string][]byte // Symmetric key storage
- keyMu sync.RWMutex // Mutex associated with key storages
-
- poolMu sync.RWMutex // Mutex to sync the message and expiration pools
- envelopes map[common.Hash]*Envelope // Pool of envelopes currently tracked by this node
- expirations map[uint32]mapset.Set // Message expiration pool
-
- peerMu sync.RWMutex // Mutex to sync the active peer set
- peers map[*Peer]struct{} // Set of currently active peers
-
- messageQueue chan *Envelope // Message queue for normal whisper messages
- p2pMsgQueue chan *Envelope // Message queue for peer-to-peer messages (not to be forwarded any further)
- quit chan struct{} // Channel used for graceful exit
-
- settings syncmap.Map // holds configuration settings that can be dynamically changed
-
- syncAllowance int // maximum time in seconds allowed to process the whisper-related messages
-
- statsMu sync.Mutex // guard stats
- stats Statistics // Statistics of whisper node
-
- mailServer MailServer // MailServer interface
-
- wg sync.WaitGroup
-}
-
-// New creates a Whisper client ready to communicate through the Ethereum P2P network.
-func New(cfg *Config) *Whisper {
- if cfg == nil {
- cfg = &DefaultConfig
- }
-
- whisper := &Whisper{
- privateKeys: make(map[string]*ecdsa.PrivateKey),
- symKeys: make(map[string][]byte),
- envelopes: make(map[common.Hash]*Envelope),
- expirations: make(map[uint32]mapset.Set),
- peers: make(map[*Peer]struct{}),
- messageQueue: make(chan *Envelope, messageQueueLimit),
- p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
- quit: make(chan struct{}),
- syncAllowance: DefaultSyncAllowance,
- }
-
- whisper.filters = NewFilters(whisper)
-
- whisper.settings.Store(minPowIdx, cfg.MinimumAcceptedPOW)
- whisper.settings.Store(maxMsgSizeIdx, cfg.MaxMessageSize)
- whisper.settings.Store(overflowIdx, false)
- whisper.settings.Store(restrictConnectionBetweenLightClientsIdx, cfg.RestrictConnectionBetweenLightClients)
-
- // p2p whisper sub protocol handler
- whisper.protocol = p2p.Protocol{
- Name: ProtocolName,
- Version: uint(ProtocolVersion),
- Length: NumberOfMessageCodes,
- Run: whisper.HandlePeer,
- NodeInfo: func() interface{} {
- return map[string]interface{}{
- "version": ProtocolVersionStr,
- "maxMessageSize": whisper.MaxMessageSize(),
- "minimumPoW": whisper.MinPow(),
- }
- },
- }
-
- return whisper
-}
-
-// MinPow returns the PoW value required by this node.
-func (whisper *Whisper) MinPow() float64 {
- val, exist := whisper.settings.Load(minPowIdx)
- if !exist || val == nil {
- return DefaultMinimumPoW
- }
- v, ok := val.(float64)
- if !ok {
- log.Error("Error loading minPowIdx, using default")
- return DefaultMinimumPoW
- }
- return v
-}
-
-// MinPowTolerance returns the value of minimum PoW which is tolerated for a limited
-// time after PoW was changed. If sufficient time have elapsed or no change of PoW
-// have ever occurred, the return value will be the same as return value of MinPow().
-func (whisper *Whisper) MinPowTolerance() float64 {
- val, exist := whisper.settings.Load(minPowToleranceIdx)
- if !exist || val == nil {
- return DefaultMinimumPoW
- }
- return val.(float64)
-}
-
-// BloomFilter returns the aggregated bloom filter for all the topics of interest.
-// The nodes are required to send only messages that match the advertised bloom filter.
-// If a message does not match the bloom, it will tantamount to spam, and the peer will
-// be disconnected.
-func (whisper *Whisper) BloomFilter() []byte {
- val, exist := whisper.settings.Load(bloomFilterIdx)
- if !exist || val == nil {
- return nil
- }
- return val.([]byte)
-}
-
-// BloomFilterTolerance returns the bloom filter which is tolerated for a limited
-// time after new bloom was advertised to the peers. If sufficient time have elapsed
-// or no change of bloom filter have ever occurred, the return value will be the same
-// as return value of BloomFilter().
-func (whisper *Whisper) BloomFilterTolerance() []byte {
- val, exist := whisper.settings.Load(bloomFilterToleranceIdx)
- if !exist || val == nil {
- return nil
- }
- return val.([]byte)
-}
-
-// MaxMessageSize returns the maximum accepted message size.
-func (whisper *Whisper) MaxMessageSize() uint32 {
- val, _ := whisper.settings.Load(maxMsgSizeIdx)
- return val.(uint32)
-}
-
-// Overflow returns an indication if the message queue is full.
-func (whisper *Whisper) Overflow() bool {
- val, _ := whisper.settings.Load(overflowIdx)
- return val.(bool)
-}
-
-// APIs returns the RPC descriptors the Whisper implementation offers
-func (whisper *Whisper) APIs() []rpc.API {
- return []rpc.API{
- {
- Namespace: ProtocolName,
- Version: ProtocolVersionStr,
- Service: NewPublicWhisperAPI(whisper),
- Public: true,
- },
- }
-}
-
-// RegisterServer registers MailServer interface.
-// MailServer will process all the incoming messages with p2pRequestCode.
-func (whisper *Whisper) RegisterServer(server MailServer) {
- whisper.mailServer = server
-}
-
-// Protocols returns the whisper sub-protocols ran by this particular client.
-func (whisper *Whisper) Protocols() []p2p.Protocol {
- return []p2p.Protocol{whisper.protocol}
-}
-
-// Version returns the whisper sub-protocols version number.
-func (whisper *Whisper) Version() uint {
- return whisper.protocol.Version
-}
-
-// SetMaxMessageSize sets the maximal message size allowed by this node
-func (whisper *Whisper) SetMaxMessageSize(size uint32) error {
- if size > MaxMessageSize {
- return fmt.Errorf("message size too large [%d>%d]", size, MaxMessageSize)
- }
- whisper.settings.Store(maxMsgSizeIdx, size)
- return nil
-}
-
-// SetBloomFilter sets the new bloom filter
-func (whisper *Whisper) SetBloomFilter(bloom []byte) error {
- if len(bloom) != BloomFilterSize {
- return fmt.Errorf("invalid bloom filter size: %d", len(bloom))
- }
-
- b := make([]byte, BloomFilterSize)
- copy(b, bloom)
-
- whisper.settings.Store(bloomFilterIdx, b)
- whisper.notifyPeersAboutBloomFilterChange(b)
-
- whisper.wg.Add(1)
- go func() {
- // allow some time before all the peers have processed the notification
- defer whisper.wg.Done()
- ticker := time.NewTicker(time.Duration(whisper.syncAllowance) * time.Second)
- defer ticker.Stop()
-
- <-ticker.C
- whisper.settings.Store(bloomFilterToleranceIdx, b)
- }()
-
- return nil
-}
-
-// SetMinimumPoW sets the minimal PoW required by this node
-func (whisper *Whisper) SetMinimumPoW(val float64) error {
- if val < 0.0 {
- return fmt.Errorf("invalid PoW: %f", val)
- }
-
- whisper.settings.Store(minPowIdx, val)
- whisper.notifyPeersAboutPowRequirementChange(val)
-
- whisper.wg.Add(1)
- go func() {
- defer whisper.wg.Done()
- // allow some time before all the peers have processed the notification
- ticker := time.NewTicker(time.Duration(whisper.syncAllowance) * time.Second)
- defer ticker.Stop()
-
- <-ticker.C
- whisper.settings.Store(minPowToleranceIdx, val)
- }()
-
- return nil
-}
-
-// SetMinimumPowTest sets the minimal PoW in test environment
-func (whisper *Whisper) SetMinimumPowTest(val float64) {
- whisper.settings.Store(minPowIdx, val)
- whisper.notifyPeersAboutPowRequirementChange(val)
- whisper.settings.Store(minPowToleranceIdx, val)
-}
-
-//SetLightClientMode makes node light client (does not forward any messages)
-func (whisper *Whisper) SetLightClientMode(v bool) {
- whisper.settings.Store(lightClientModeIdx, v)
-}
-
-//LightClientMode indicates is this node is light client (does not forward any messages)
-func (whisper *Whisper) LightClientMode() bool {
- val, exist := whisper.settings.Load(lightClientModeIdx)
- if !exist || val == nil {
- return false
- }
- v, ok := val.(bool)
- return v && ok
-}
-
-//LightClientModeConnectionRestricted indicates that connection to light client in light client mode not allowed
-func (whisper *Whisper) LightClientModeConnectionRestricted() bool {
- val, exist := whisper.settings.Load(restrictConnectionBetweenLightClientsIdx)
- if !exist || val == nil {
- return false
- }
- v, ok := val.(bool)
- return v && ok
-}
-
-func (whisper *Whisper) notifyPeersAboutPowRequirementChange(pow float64) {
- arr := whisper.getPeers()
- for _, p := range arr {
- err := p.notifyAboutPowRequirementChange(pow)
- if err != nil {
- // allow one retry
- err = p.notifyAboutPowRequirementChange(pow)
- }
- if err != nil {
- log.Warn("failed to notify peer about new pow requirement", "peer", p.ID(), "error", err)
- }
- }
-}
-
-func (whisper *Whisper) notifyPeersAboutBloomFilterChange(bloom []byte) {
- arr := whisper.getPeers()
- for _, p := range arr {
- err := p.notifyAboutBloomFilterChange(bloom)
- if err != nil {
- // allow one retry
- err = p.notifyAboutBloomFilterChange(bloom)
- }
- if err != nil {
- log.Warn("failed to notify peer about new bloom filter", "peer", p.ID(), "error", err)
- }
- }
-}
-
-func (whisper *Whisper) getPeers() []*Peer {
- arr := make([]*Peer, len(whisper.peers))
- i := 0
- whisper.peerMu.Lock()
- defer whisper.peerMu.Unlock()
- for p := range whisper.peers {
- arr[i] = p
- i++
- }
- return arr
-}
-
-// getPeer retrieves peer by ID
-func (whisper *Whisper) getPeer(peerID []byte) (*Peer, error) {
- whisper.peerMu.Lock()
- defer whisper.peerMu.Unlock()
- for p := range whisper.peers {
- id := p.peer.ID()
- if bytes.Equal(peerID, id[:]) {
- return p, nil
- }
- }
- return nil, fmt.Errorf("could not find peer with ID: %x", peerID)
-}
-
-// AllowP2PMessagesFromPeer marks specific peer trusted,
-// which will allow it to send historic (expired) messages.
-func (whisper *Whisper) AllowP2PMessagesFromPeer(peerID []byte) error {
- p, err := whisper.getPeer(peerID)
- if err != nil {
- return err
- }
- p.trusted = true
- return nil
-}
-
-// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
-// which is known to implement MailServer interface, and is supposed to process this
-// request and respond with a number of peer-to-peer messages (possibly expired),
-// which are not supposed to be forwarded any further.
-// The whisper protocol is agnostic of the format and contents of envelope.
-func (whisper *Whisper) RequestHistoricMessages(peerID []byte, envelope *Envelope) error {
- p, err := whisper.getPeer(peerID)
- if err != nil {
- return err
- }
- p.trusted = true
- return p2p.Send(p.ws, p2pRequestCode, envelope)
-}
-
-// SendP2PMessage sends a peer-to-peer message to a specific peer.
-func (whisper *Whisper) SendP2PMessage(peerID []byte, envelope *Envelope) error {
- p, err := whisper.getPeer(peerID)
- if err != nil {
- return err
- }
- return whisper.SendP2PDirect(p, envelope)
-}
-
-// SendP2PDirect sends a peer-to-peer message to a specific peer.
-func (whisper *Whisper) SendP2PDirect(peer *Peer, envelope *Envelope) error {
- return p2p.Send(peer.ws, p2pMessageCode, envelope)
-}
-
-// NewKeyPair generates a new cryptographic identity for the client, and injects
-// it into the known identities for message decryption. Returns ID of the new key pair.
-func (whisper *Whisper) NewKeyPair() (string, error) {
- key, err := crypto.GenerateKey()
- if err != nil || !validatePrivateKey(key) {
- key, err = crypto.GenerateKey() // retry once
- }
- if err != nil {
- return "", err
- }
- if !validatePrivateKey(key) {
- return "", fmt.Errorf("failed to generate valid key")
- }
-
- id, err := GenerateRandomID()
- if err != nil {
- return "", fmt.Errorf("failed to generate ID: %s", err)
- }
-
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
-
- if whisper.privateKeys[id] != nil {
- return "", fmt.Errorf("failed to generate unique ID")
- }
- whisper.privateKeys[id] = key
- return id, nil
-}
-
-// DeleteKeyPair deletes the specified key if it exists.
-func (whisper *Whisper) DeleteKeyPair(key string) bool {
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
-
- if whisper.privateKeys[key] != nil {
- delete(whisper.privateKeys, key)
- return true
- }
- return false
-}
-
-// AddKeyPair imports a asymmetric private key and returns it identifier.
-func (whisper *Whisper) AddKeyPair(key *ecdsa.PrivateKey) (string, error) {
- id, err := GenerateRandomID()
- if err != nil {
- return "", fmt.Errorf("failed to generate ID: %s", err)
- }
-
- whisper.keyMu.Lock()
- whisper.privateKeys[id] = key
- whisper.keyMu.Unlock()
-
- return id, nil
-}
-
-// HasKeyPair checks if the whisper node is configured with the private key
-// of the specified public pair.
-func (whisper *Whisper) HasKeyPair(id string) bool {
- whisper.keyMu.RLock()
- defer whisper.keyMu.RUnlock()
- return whisper.privateKeys[id] != nil
-}
-
-// GetPrivateKey retrieves the private key of the specified identity.
-func (whisper *Whisper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) {
- whisper.keyMu.RLock()
- defer whisper.keyMu.RUnlock()
- key := whisper.privateKeys[id]
- if key == nil {
- return nil, fmt.Errorf("invalid id")
- }
- return key, nil
-}
-
-// GenerateSymKey generates a random symmetric key and stores it under id,
-// which is then returned. Will be used in the future for session key exchange.
-func (whisper *Whisper) GenerateSymKey() (string, error) {
- key, err := generateSecureRandomData(aesKeyLength)
- if err != nil {
- return "", err
- } else if !validateDataIntegrity(key, aesKeyLength) {
- return "", fmt.Errorf("error in GenerateSymKey: crypto/rand failed to generate random data")
- }
-
- id, err := GenerateRandomID()
- if err != nil {
- return "", fmt.Errorf("failed to generate ID: %s", err)
- }
-
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
-
- if whisper.symKeys[id] != nil {
- return "", fmt.Errorf("failed to generate unique ID")
- }
- whisper.symKeys[id] = key
- return id, nil
-}
-
-// AddSymKeyDirect stores the key, and returns its id.
-func (whisper *Whisper) AddSymKeyDirect(key []byte) (string, error) {
- if len(key) != aesKeyLength {
- return "", fmt.Errorf("wrong key size: %d", len(key))
- }
-
- id, err := GenerateRandomID()
- if err != nil {
- return "", fmt.Errorf("failed to generate ID: %s", err)
- }
-
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
-
- if whisper.symKeys[id] != nil {
- return "", fmt.Errorf("failed to generate unique ID")
- }
- whisper.symKeys[id] = key
- return id, nil
-}
-
-// AddSymKeyFromPassword generates the key from password, stores it, and returns its id.
-func (whisper *Whisper) AddSymKeyFromPassword(password string) (string, error) {
- id, err := GenerateRandomID()
- if err != nil {
- return "", fmt.Errorf("failed to generate ID: %s", err)
- }
- if whisper.HasSymKey(id) {
- return "", fmt.Errorf("failed to generate unique ID")
- }
-
- // kdf should run no less than 0.1 seconds on an average computer,
- // because it's an once in a session experience
- derived := pbkdf2.Key([]byte(password), nil, 65356, aesKeyLength, sha256.New)
- if err != nil {
- return "", err
- }
-
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
-
- // double check is necessary, because deriveKeyMaterial() is very slow
- if whisper.symKeys[id] != nil {
- return "", fmt.Errorf("critical error: failed to generate unique ID")
- }
- whisper.symKeys[id] = derived
- return id, nil
-}
-
-// HasSymKey returns true if there is a key associated with the given id.
-// Otherwise returns false.
-func (whisper *Whisper) HasSymKey(id string) bool {
- whisper.keyMu.RLock()
- defer whisper.keyMu.RUnlock()
- return whisper.symKeys[id] != nil
-}
-
-// DeleteSymKey deletes the key associated with the name string if it exists.
-func (whisper *Whisper) DeleteSymKey(id string) bool {
- whisper.keyMu.Lock()
- defer whisper.keyMu.Unlock()
- if whisper.symKeys[id] != nil {
- delete(whisper.symKeys, id)
- return true
- }
- return false
-}
-
-// GetSymKey returns the symmetric key associated with the given id.
-func (whisper *Whisper) GetSymKey(id string) ([]byte, error) {
- whisper.keyMu.RLock()
- defer whisper.keyMu.RUnlock()
- if whisper.symKeys[id] != nil {
- return whisper.symKeys[id], nil
- }
- return nil, fmt.Errorf("non-existent key ID")
-}
-
-// Subscribe installs a new message handler used for filtering, decrypting
-// and subsequent storing of incoming messages.
-func (whisper *Whisper) Subscribe(f *Filter) (string, error) {
- s, err := whisper.filters.Install(f)
- if err == nil {
- whisper.updateBloomFilter(f)
- }
- return s, err
-}
-
-// updateBloomFilter recalculates the new value of bloom filter,
-// and informs the peers if necessary.
-func (whisper *Whisper) updateBloomFilter(f *Filter) {
- aggregate := make([]byte, BloomFilterSize)
- for _, t := range f.Topics {
- top := BytesToTopic(t)
- b := TopicToBloom(top)
- aggregate = addBloom(aggregate, b)
- }
-
- if !BloomFilterMatch(whisper.BloomFilter(), aggregate) {
- // existing bloom filter must be updated
- aggregate = addBloom(whisper.BloomFilter(), aggregate)
- whisper.SetBloomFilter(aggregate)
- }
-}
-
-// GetFilter returns the filter by id.
-func (whisper *Whisper) GetFilter(id string) *Filter {
- return whisper.filters.Get(id)
-}
-
-// Unsubscribe removes an installed message handler.
-func (whisper *Whisper) Unsubscribe(id string) error {
- ok := whisper.filters.Uninstall(id)
- if !ok {
- return fmt.Errorf("Unsubscribe: Invalid ID")
- }
- return nil
-}
-
-// Send injects a message into the whisper send queue, to be distributed in the
-// network in the coming cycles.
-func (whisper *Whisper) Send(envelope *Envelope) error {
- ok, err := whisper.add(envelope, false)
- if err == nil && !ok {
- return fmt.Errorf("failed to add envelope")
- }
- return err
-}
-
-// Start implements node.Service, starting the background data propagation thread
-// of the Whisper protocol.
-func (whisper *Whisper) Start(*p2p.Server) error {
- log.Info("started whisper v." + ProtocolVersionStr)
- whisper.wg.Add(1)
- go whisper.update()
-
- numCPU := runtime.NumCPU()
- for i := 0; i < numCPU; i++ {
- whisper.wg.Add(1)
- go whisper.processQueue()
- }
-
- return nil
-}
-
-// Stop implements node.Service, stopping the background data propagation thread
-// of the Whisper protocol.
-func (whisper *Whisper) Stop() error {
- close(whisper.quit)
- whisper.wg.Wait()
- log.Info("whisper stopped")
- return nil
-}
-
-// HandlePeer is called by the underlying P2P layer when the whisper sub-protocol
-// connection is negotiated.
-func (whisper *Whisper) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
- // Create the new peer and start tracking it
- whisperPeer := newPeer(whisper, peer, rw)
-
- whisper.peerMu.Lock()
- whisper.peers[whisperPeer] = struct{}{}
- whisper.peerMu.Unlock()
-
- defer func() {
- whisper.peerMu.Lock()
- delete(whisper.peers, whisperPeer)
- whisper.peerMu.Unlock()
- }()
-
- // Run the peer handshake and state updates
- if err := whisperPeer.handshake(); err != nil {
- return err
- }
- whisperPeer.start()
- defer whisperPeer.stop()
-
- return whisper.runMessageLoop(whisperPeer, rw)
-}
-
-// runMessageLoop reads and processes inbound messages directly to merge into client-global state.
-func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
- for {
- // fetch the next packet
- packet, err := rw.ReadMsg()
- if err != nil {
- log.Info("message loop", "peer", p.peer.ID(), "err", err)
- return err
- }
- if packet.Size > whisper.MaxMessageSize() {
- log.Warn("oversized message received", "peer", p.peer.ID())
- return errors.New("oversized message received")
- }
-
- switch packet.Code {
- case statusCode:
- // this should not happen, but no need to panic; just ignore this message.
- log.Warn("unxepected status message received", "peer", p.peer.ID())
- case messagesCode:
- // decode the contained envelopes
- var envelopes []*Envelope
- if err := packet.Decode(&envelopes); err != nil {
- log.Warn("failed to decode envelopes, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid envelopes")
- }
-
- trouble := false
- for _, env := range envelopes {
- cached, err := whisper.add(env, whisper.LightClientMode())
- if err != nil {
- trouble = true
- log.Error("bad envelope received, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- }
- if cached {
- p.mark(env)
- }
- }
-
- if trouble {
- return errors.New("invalid envelope")
- }
- case powRequirementCode:
- s := rlp.NewStream(packet.Payload, uint64(packet.Size))
- i, err := s.Uint()
- if err != nil {
- log.Warn("failed to decode powRequirementCode message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid powRequirementCode message")
- }
- f := math.Float64frombits(i)
- if math.IsInf(f, 0) || math.IsNaN(f) || f < 0.0 {
- log.Warn("invalid value in powRequirementCode message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid value in powRequirementCode message")
- }
- p.powRequirement = f
- case bloomFilterExCode:
- var bloom []byte
- err := packet.Decode(&bloom)
- if err == nil && len(bloom) != BloomFilterSize {
- err = fmt.Errorf("wrong bloom filter size %d", len(bloom))
- }
-
- if err != nil {
- log.Warn("failed to decode bloom filter exchange message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid bloom filter exchange message")
- }
- p.setBloomFilter(bloom)
- case p2pMessageCode:
- // peer-to-peer message, sent directly to peer bypassing PoW checks, etc.
- // this message is not supposed to be forwarded to other peers, and
- // therefore might not satisfy the PoW, expiry and other requirements.
- // these messages are only accepted from the trusted peer.
- if p.trusted {
- var envelope Envelope
- if err := packet.Decode(&envelope); err != nil {
- log.Warn("failed to decode direct message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid direct message")
- }
- whisper.postEvent(&envelope, true)
- }
- case p2pRequestCode:
- // Must be processed if mail server is implemented. Otherwise ignore.
- if whisper.mailServer != nil {
- var request Envelope
- if err := packet.Decode(&request); err != nil {
- log.Warn("failed to decode p2p request message, peer will be disconnected", "peer", p.peer.ID(), "err", err)
- return errors.New("invalid p2p request")
- }
- whisper.mailServer.DeliverMail(p, &request)
- }
- default:
- // New message types might be implemented in the future versions of Whisper.
- // For forward compatibility, just ignore.
- }
-
- packet.Discard()
- }
-}
-
-// add inserts a new envelope into the message pool to be distributed within the
-// whisper network. It also inserts the envelope into the expiration pool at the
-// appropriate time-stamp. In case of error, connection should be dropped.
-// param isP2P indicates whether the message is peer-to-peer (should not be forwarded).
-func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
- now := uint32(time.Now().Unix())
- sent := envelope.Expiry - envelope.TTL
-
- if sent > now {
- if sent-DefaultSyncAllowance > now {
- return false, fmt.Errorf("envelope created in the future [%x]", envelope.Hash())
- }
- // recalculate PoW, adjusted for the time difference, plus one second for latency
- envelope.calculatePoW(sent - now + 1)
- }
-
- if envelope.Expiry < now {
- if envelope.Expiry+DefaultSyncAllowance*2 < now {
- return false, fmt.Errorf("very old message")
- }
- log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
- return false, nil // drop envelope without error
- }
-
- if uint32(envelope.size()) > whisper.MaxMessageSize() {
- return false, fmt.Errorf("huge messages are not allowed [%x]", envelope.Hash())
- }
-
- if envelope.PoW() < whisper.MinPow() {
- // maybe the value was recently changed, and the peers did not adjust yet.
- // in this case the previous value is retrieved by MinPowTolerance()
- // for a short period of peer synchronization.
- if envelope.PoW() < whisper.MinPowTolerance() {
- return false, fmt.Errorf("envelope with low PoW received: PoW=%f, hash=[%v]", envelope.PoW(), envelope.Hash().Hex())
- }
- }
-
- if !BloomFilterMatch(whisper.BloomFilter(), envelope.Bloom()) {
- // maybe the value was recently changed, and the peers did not adjust yet.
- // in this case the previous value is retrieved by BloomFilterTolerance()
- // for a short period of peer synchronization.
- if !BloomFilterMatch(whisper.BloomFilterTolerance(), envelope.Bloom()) {
- return false, fmt.Errorf("envelope does not match bloom filter, hash=[%v], bloom: \n%x \n%x \n%x",
- envelope.Hash().Hex(), whisper.BloomFilter(), envelope.Bloom(), envelope.Topic)
- }
- }
-
- hash := envelope.Hash()
-
- whisper.poolMu.Lock()
- _, alreadyCached := whisper.envelopes[hash]
- if !alreadyCached {
- whisper.envelopes[hash] = envelope
- if whisper.expirations[envelope.Expiry] == nil {
- whisper.expirations[envelope.Expiry] = mapset.NewThreadUnsafeSet()
- }
- if !whisper.expirations[envelope.Expiry].Contains(hash) {
- whisper.expirations[envelope.Expiry].Add(hash)
- }
- }
- whisper.poolMu.Unlock()
-
- if alreadyCached {
- log.Trace("whisper envelope already cached", "hash", envelope.Hash().Hex())
- } else {
- log.Trace("cached whisper envelope", "hash", envelope.Hash().Hex())
- whisper.statsMu.Lock()
- whisper.stats.memoryUsed += envelope.size()
- whisper.statsMu.Unlock()
- whisper.postEvent(envelope, isP2P) // notify the local node about the new message
- if whisper.mailServer != nil {
- whisper.mailServer.Archive(envelope)
- }
- }
- return true, nil
-}
-
-// postEvent queues the message for further processing.
-func (whisper *Whisper) postEvent(envelope *Envelope, isP2P bool) {
- if isP2P {
- whisper.p2pMsgQueue <- envelope
- } else {
- whisper.checkOverflow()
- whisper.messageQueue <- envelope
- }
-}
-
-// checkOverflow checks if message queue overflow occurs and reports it if necessary.
-func (whisper *Whisper) checkOverflow() {
- queueSize := len(whisper.messageQueue)
-
- if queueSize == messageQueueLimit {
- if !whisper.Overflow() {
- whisper.settings.Store(overflowIdx, true)
- log.Warn("message queue overflow")
- }
- } else if queueSize <= messageQueueLimit/2 {
- if whisper.Overflow() {
- whisper.settings.Store(overflowIdx, false)
- log.Warn("message queue overflow fixed (back to normal)")
- }
- }
-}
-
-// processQueue delivers the messages to the watchers during the lifetime of the whisper node.
-func (whisper *Whisper) processQueue() {
- defer whisper.wg.Done()
- var e *Envelope
- for {
- select {
- case <-whisper.quit:
- return
-
- case e = <-whisper.messageQueue:
- whisper.filters.NotifyWatchers(e, false)
-
- case e = <-whisper.p2pMsgQueue:
- whisper.filters.NotifyWatchers(e, true)
- }
- }
-}
-
-// update loops until the lifetime of the whisper node, updating its internal
-// state by expiring stale messages from the pool.
-func (whisper *Whisper) update() {
- defer whisper.wg.Done()
- // Start a ticker to check for expirations
- expire := time.NewTicker(expirationCycle)
- defer expire.Stop()
-
- // Repeat updates until termination is requested
- for {
- select {
- case <-expire.C:
- whisper.expire()
-
- case <-whisper.quit:
- return
- }
- }
-}
-
-// expire iterates over all the expiration timestamps, removing all stale
-// messages from the pools.
-func (whisper *Whisper) expire() {
- whisper.poolMu.Lock()
- defer whisper.poolMu.Unlock()
-
- whisper.statsMu.Lock()
- defer whisper.statsMu.Unlock()
- whisper.stats.reset()
- now := uint32(time.Now().Unix())
- for expiry, hashSet := range whisper.expirations {
- if expiry < now {
- // Dump all expired messages and remove timestamp
- hashSet.Each(func(v interface{}) bool {
- sz := whisper.envelopes[v.(common.Hash)].size()
- delete(whisper.envelopes, v.(common.Hash))
- whisper.stats.messagesCleared++
- whisper.stats.memoryCleared += sz
- whisper.stats.memoryUsed -= sz
- return false
- })
- whisper.expirations[expiry].Clear()
- delete(whisper.expirations, expiry)
- }
- }
-}
-
-// Stats returns the whisper node statistics.
-func (whisper *Whisper) Stats() Statistics {
- whisper.statsMu.Lock()
- defer whisper.statsMu.Unlock()
-
- return whisper.stats
-}
-
-// Envelopes retrieves all the messages currently pooled by the node.
-func (whisper *Whisper) Envelopes() []*Envelope {
- whisper.poolMu.RLock()
- defer whisper.poolMu.RUnlock()
-
- all := make([]*Envelope, 0, len(whisper.envelopes))
- for _, envelope := range whisper.envelopes {
- all = append(all, envelope)
- }
- return all
-}
-
-// isEnvelopeCached checks if envelope with specific hash has already been received and cached.
-func (whisper *Whisper) isEnvelopeCached(hash common.Hash) bool {
- whisper.poolMu.Lock()
- defer whisper.poolMu.Unlock()
-
- _, exist := whisper.envelopes[hash]
- return exist
-}
-
-// reset resets the node's statistics after each expiry cycle.
-func (s *Statistics) reset() {
- s.cycles++
- s.totalMessagesCleared += s.messagesCleared
-
- s.memoryCleared = 0
- s.messagesCleared = 0
-}
-
-// ValidatePublicKey checks the format of the given public key.
-func ValidatePublicKey(k *ecdsa.PublicKey) bool {
- return k != nil && k.X != nil && k.Y != nil && k.X.Sign() != 0 && k.Y.Sign() != 0
-}
-
-// validatePrivateKey checks the format of the given private key.
-func validatePrivateKey(k *ecdsa.PrivateKey) bool {
- if k == nil || k.D == nil || k.D.Sign() == 0 {
- return false
- }
- return ValidatePublicKey(&k.PublicKey)
-}
-
-// validateDataIntegrity returns false if the data have the wrong or contains all zeros,
-// which is the simplest and the most common bug.
-func validateDataIntegrity(k []byte, expectedSize int) bool {
- if len(k) != expectedSize {
- return false
- }
- if expectedSize > 3 && containsOnlyZeros(k) {
- return false
- }
- return true
-}
-
-// containsOnlyZeros checks if the data contain only zeros.
-func containsOnlyZeros(data []byte) bool {
- for _, b := range data {
- if b != 0 {
- return false
- }
- }
- return true
-}
-
-// bytesToUintLittleEndian converts the slice to 64-bit unsigned integer.
-func bytesToUintLittleEndian(b []byte) (res uint64) {
- mul := uint64(1)
- for i := 0; i < len(b); i++ {
- res += uint64(b[i]) * mul
- mul *= 256
- }
- return res
-}
-
-// BytesToUintBigEndian converts the slice to 64-bit unsigned integer.
-func BytesToUintBigEndian(b []byte) (res uint64) {
- for i := 0; i < len(b); i++ {
- res *= 256
- res += uint64(b[i])
- }
- return res
-}
-
-// GenerateRandomID generates a random string, which is then returned to be used as a key id
-func GenerateRandomID() (id string, err error) {
- buf, err := generateSecureRandomData(keyIDSize)
- if err != nil {
- return "", err
- }
- if !validateDataIntegrity(buf, keyIDSize) {
- return "", fmt.Errorf("error in generateRandomID: crypto/rand failed to generate random data")
- }
- id = common.Bytes2Hex(buf)
- return id, err
-}
-
-func isFullNode(bloom []byte) bool {
- if bloom == nil {
- return true
- }
- for _, b := range bloom {
- if b != 255 {
- return false
- }
- }
- return true
-}
-
-func BloomFilterMatch(filter, sample []byte) bool {
- if filter == nil {
- return true
- }
-
- for i := 0; i < BloomFilterSize; i++ {
- f := filter[i]
- s := sample[i]
- if (f | s) != f {
- return false
- }
- }
-
- return true
-}
-
-func addBloom(a, b []byte) []byte {
- c := make([]byte, BloomFilterSize)
- for i := 0; i < BloomFilterSize; i++ {
- c[i] = a[i] | b[i]
- }
- return c
-}
diff --git a/whisper/whisperv6/whisper_test.go b/whisper/whisperv6/whisper_test.go
deleted file mode 100644
index ba2db975d14b..000000000000
--- a/whisper/whisperv6/whisper_test.go
+++ /dev/null
@@ -1,898 +0,0 @@
-// Copyright 2016 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package whisperv6
-
-import (
- "bytes"
- "crypto/ecdsa"
- "crypto/sha256"
- mrand "math/rand"
- "testing"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "golang.org/x/crypto/pbkdf2"
-)
-
-func TestWhisperBasic(t *testing.T) {
- w := New(&DefaultConfig)
- p := w.Protocols()
- shh := p[0]
- if shh.Name != ProtocolName {
- t.Fatalf("failed Protocol Name: %v.", shh.Name)
- }
- if uint64(shh.Version) != ProtocolVersion {
- t.Fatalf("failed Protocol Version: %v.", shh.Version)
- }
- if shh.Length != NumberOfMessageCodes {
- t.Fatalf("failed Protocol Length: %v.", shh.Length)
- }
- if shh.Run == nil {
- t.Fatal("failed shh.Run.")
- }
- if uint64(w.Version()) != ProtocolVersion {
- t.Fatalf("failed whisper Version: %v.", shh.Version)
- }
- if w.GetFilter("non-existent") != nil {
- t.Fatal("failed GetFilter.")
- }
-
- peerID := make([]byte, 64)
- mrand.Read(peerID)
- peer, _ := w.getPeer(peerID)
- if peer != nil {
- t.Fatal("found peer for random key.")
- }
- if err := w.AllowP2PMessagesFromPeer(peerID); err == nil {
- t.Fatal("failed MarkPeerTrusted.")
- }
- exist := w.HasSymKey("non-existing")
- if exist {
- t.Fatal("failed HasSymKey.")
- }
- key, err := w.GetSymKey("non-existing")
- if err == nil {
- t.Fatalf("failed GetSymKey(non-existing): false positive. key=%v", key)
- }
- if key != nil {
- t.Fatalf("failed GetSymKey: false positive. key=%v", key)
- }
- mail := w.Envelopes()
- if len(mail) != 0 {
- t.Fatalf("failed w.Envelopes(). length=%d", len(mail))
- }
-
- derived := pbkdf2.Key(peerID, nil, 65356, aesKeyLength, sha256.New)
- if !validateDataIntegrity(derived, aesKeyLength) {
- t.Fatalf("failed validateSymmetricKey with param = %v.", derived)
- }
- if containsOnlyZeros(derived) {
- t.Fatalf("failed containsOnlyZeros with param = %v.", derived)
- }
-
- buf := []byte{0xFF, 0xE5, 0x80, 0x2, 0}
- le := bytesToUintLittleEndian(buf)
- be := BytesToUintBigEndian(buf)
- if le != uint64(0x280e5ff) {
- t.Fatalf("failed bytesToIntLittleEndian: %d.", le)
- }
- if be != uint64(0xffe5800200) {
- t.Fatalf("failed BytesToIntBigEndian: %d.", be)
- }
-
- id, err := w.NewKeyPair()
- if err != nil {
- t.Fatalf("failed to generate new key pair: %v.", err)
- }
- pk, err := w.GetPrivateKey(id)
- if err != nil {
- t.Fatalf("failed to retrieve new key pair: %v.", err)
- }
- if !validatePrivateKey(pk) {
- t.Fatalf("failed validatePrivateKey: %v.", pk)
- }
- if !ValidatePublicKey(&pk.PublicKey) {
- t.Fatalf("failed ValidatePublicKey: %v.", pk)
- }
-}
-
-func TestWhisperAsymmetricKeyImport(t *testing.T) {
- var (
- w = New(&DefaultConfig)
- privateKeys []*ecdsa.PrivateKey
- )
-
- for i := 0; i < 50; i++ {
- id, err := w.NewKeyPair()
- if err != nil {
- t.Fatalf("could not generate key: %v", err)
- }
-
- pk, err := w.GetPrivateKey(id)
- if err != nil {
- t.Fatalf("could not export private key: %v", err)
- }
-
- privateKeys = append(privateKeys, pk)
-
- if !w.DeleteKeyPair(id) {
- t.Fatal("could not delete private key")
- }
- }
-
- for _, pk := range privateKeys {
- if _, err := w.AddKeyPair(pk); err != nil {
- t.Fatalf("could not import private key: %v", err)
- }
- }
-}
-
-func TestWhisperIdentityManagement(t *testing.T) {
- w := New(&DefaultConfig)
- id1, err := w.NewKeyPair()
- if err != nil {
- t.Fatalf("failed to generate new key pair: %s.", err)
- }
- id2, err := w.NewKeyPair()
- if err != nil {
- t.Fatalf("failed to generate new key pair: %s.", err)
- }
- pk1, err := w.GetPrivateKey(id1)
- if err != nil {
- t.Fatalf("failed to retrieve the key pair: %s.", err)
- }
- pk2, err := w.GetPrivateKey(id2)
- if err != nil {
- t.Fatalf("failed to retrieve the key pair: %s.", err)
- }
-
- if !w.HasKeyPair(id1) {
- t.Fatal("failed HasIdentity(pk1).")
- }
- if !w.HasKeyPair(id2) {
- t.Fatal("failed HasIdentity(pk2).")
- }
- if pk1 == nil {
- t.Fatal("failed GetIdentity(pk1).")
- }
- if pk2 == nil {
- t.Fatal("failed GetIdentity(pk2).")
- }
-
- if !validatePrivateKey(pk1) {
- t.Fatal("pk1 is invalid.")
- }
- if !validatePrivateKey(pk2) {
- t.Fatal("pk2 is invalid.")
- }
-
- // Delete one identity
- done := w.DeleteKeyPair(id1)
- if !done {
- t.Fatal("failed to delete id1.")
- }
- pk1, err = w.GetPrivateKey(id1)
- if err == nil {
- t.Fatalf("retrieve the key pair: false positive. key=%v", pk1)
- }
- pk2, err = w.GetPrivateKey(id2)
- if err != nil {
- t.Fatalf("failed to retrieve the key pair: %s.", err)
- }
- if w.HasKeyPair(id1) {
- t.Fatal("failed DeleteIdentity(pub1): still exist.")
- }
- if !w.HasKeyPair(id2) {
- t.Fatal("failed DeleteIdentity(pub1): pub2 does not exist.")
- }
- if pk1 != nil {
- t.Fatal("failed DeleteIdentity(pub1): first key still exist.")
- }
- if pk2 == nil {
- t.Fatal("failed DeleteIdentity(pub1): second key does not exist.")
- }
-
- // Delete again non-existing identity
- done = w.DeleteKeyPair(id1)
- if done {
- t.Fatal("delete id1: false positive.")
- }
- pk1, err = w.GetPrivateKey(id1)
- if err == nil {
- t.Fatalf("retrieve the key pair: false positive. key=%v", pk1)
- }
- pk2, err = w.GetPrivateKey(id2)
- if err != nil {
- t.Fatalf("failed to retrieve the key pair: %s.", err)
- }
- if w.HasKeyPair(id1) {
- t.Fatal("failed delete non-existing identity: exist.")
- }
- if !w.HasKeyPair(id2) {
- t.Fatal("failed delete non-existing identity: pub2 does not exist.")
- }
- if pk1 != nil {
- t.Fatalf("failed delete non-existing identity: first key exist. key=%v", pk1)
- }
- if pk2 == nil {
- t.Fatal("failed delete non-existing identity: second key does not exist.")
- }
-
- // Delete second identity
- done = w.DeleteKeyPair(id2)
- if !done {
- t.Fatal("failed to delete id2.")
- }
- pk1, err = w.GetPrivateKey(id1)
- if err == nil {
- t.Fatalf("retrieve the key pair: false positive. key=%v", pk1)
- }
- pk2, err = w.GetPrivateKey(id2)
- if err == nil {
- t.Fatalf("retrieve the key pair: false positive. key=%v", pk2)
- }
- if w.HasKeyPair(id1) {
- t.Fatal("failed delete second identity: first identity exist.")
- }
- if w.HasKeyPair(id2) {
- t.Fatal("failed delete second identity: still exist.")
- }
- if pk1 != nil {
- t.Fatalf("failed delete second identity: first key exist. key=%v", pk1)
- }
- if pk2 != nil {
- t.Fatalf("failed delete second identity: second key exist. key=%v", pk2)
- }
-}
-
-func TestWhisperSymKeyManagement(t *testing.T) {
- InitSingleTest()
-
- var (
- k1, k2 []byte
- w = New(&DefaultConfig)
- id2 = string("arbitrary-string-2")
- )
- id1, err := w.GenerateSymKey()
- if err != nil {
- t.Fatalf("failed GenerateSymKey with seed %d: %s.", seed, err)
- }
-
- k1, err = w.GetSymKey(id1)
- if err != nil {
- t.Fatalf("failed GetSymKey(id1). err=%v", err)
- }
- k2, err = w.GetSymKey(id2)
- if err == nil {
- t.Fatalf("failed GetSymKey(id2): false positive. key=%v", k2)
- }
- if !w.HasSymKey(id1) {
- t.Fatal("failed HasSymKey(id1).")
- }
- if w.HasSymKey(id2) {
- t.Fatal("failed HasSymKey(id2): false positive.")
- }
- if k1 == nil {
- t.Fatal("first key does not exist.")
- }
- if k2 != nil {
- t.Fatalf("second key still exist. key=%v", k2)
- }
-
- // add existing id, nothing should change
- randomKey := make([]byte, aesKeyLength)
- mrand.Read(randomKey)
- id1, err = w.AddSymKeyDirect(randomKey)
- if err != nil {
- t.Fatalf("failed AddSymKey with seed %d: %s.", seed, err)
- }
-
- k1, err = w.GetSymKey(id1)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id1). err=%v", err)
- }
- k2, err = w.GetSymKey(id2)
- if err == nil {
- t.Fatalf("failed w.GetSymKey(id2): false positive. key=%v", k2)
- }
- if !w.HasSymKey(id1) {
- t.Fatal("failed w.HasSymKey(id1).")
- }
- if w.HasSymKey(id2) {
- t.Fatal("failed w.HasSymKey(id2): false positive.")
- }
- if k1 == nil {
- t.Fatal("first key does not exist.")
- }
- if !bytes.Equal(k1, randomKey) {
- t.Fatal("k1 != randomKey.")
- }
- if k2 != nil {
- t.Fatalf("second key already exist. key=%v", k2)
- }
-
- id2, err = w.AddSymKeyDirect(randomKey)
- if err != nil {
- t.Fatalf("failed AddSymKey(id2) with seed %d: %s.", seed, err)
- }
- k1, err = w.GetSymKey(id1)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id1). err=%v", err)
- }
- k2, err = w.GetSymKey(id2)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id2). err=%v", err)
- }
- if !w.HasSymKey(id1) {
- t.Fatal("HasSymKey(id1) failed.")
- }
- if !w.HasSymKey(id2) {
- t.Fatal("HasSymKey(id2) failed.")
- }
- if k1 == nil {
- t.Fatal("k1 does not exist.")
- }
- if k2 == nil {
- t.Fatal("k2 does not exist.")
- }
- if !bytes.Equal(k1, k2) {
- t.Fatal("k1 != k2.")
- }
- if !bytes.Equal(k1, randomKey) {
- t.Fatal("k1 != randomKey.")
- }
- if len(k1) != aesKeyLength {
- t.Fatalf("wrong length of k1. length=%d", len(k1))
- }
- if len(k2) != aesKeyLength {
- t.Fatalf("wrong length of k2. length=%d", len(k2))
- }
-
- w.DeleteSymKey(id1)
- k1, err = w.GetSymKey(id1)
- if err == nil {
- t.Fatalf("failed w.GetSymKey(id1): false positive.")
- }
- if k1 != nil {
- t.Fatalf("failed GetSymKey(id1): false positive. key=%v", k1)
- }
- k2, err = w.GetSymKey(id2)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id2). err=%v", err)
- }
- if w.HasSymKey(id1) {
- t.Fatal("failed to delete first key: still exist.")
- }
- if !w.HasSymKey(id2) {
- t.Fatal("failed to delete first key: second key does not exist.")
- }
- if k2 == nil {
- t.Fatal("failed to delete first key: second key is nil.")
- }
-
- w.DeleteSymKey(id1)
- w.DeleteSymKey(id2)
- k1, err = w.GetSymKey(id1)
- if err == nil {
- t.Fatalf("failed w.GetSymKey(id1): false positive. key=%v", k1)
- }
- k2, err = w.GetSymKey(id2)
- if err == nil {
- t.Fatalf("failed w.GetSymKey(id2): false positive. key=%v", k2)
- }
- if k1 != nil || k2 != nil {
- t.Fatal("k1 or k2 is not nil")
- }
- if w.HasSymKey(id1) {
- t.Fatal("failed to delete second key: first key exist.")
- }
- if w.HasSymKey(id2) {
- t.Fatal("failed to delete second key: still exist.")
- }
- if k1 != nil {
- t.Fatal("failed to delete second key: first key is not nil.")
- }
- if k2 != nil {
- t.Fatal("failed to delete second key: second key is not nil.")
- }
-
- randomKey = make([]byte, aesKeyLength+1)
- mrand.Read(randomKey)
- _, err = w.AddSymKeyDirect(randomKey)
- if err == nil {
- t.Fatalf("added the key with wrong size, seed %d.", seed)
- }
-
- const password = "arbitrary data here"
- id1, err = w.AddSymKeyFromPassword(password)
- if err != nil {
- t.Fatalf("failed AddSymKeyFromPassword(id1) with seed %d: %s.", seed, err)
- }
- id2, err = w.AddSymKeyFromPassword(password)
- if err != nil {
- t.Fatalf("failed AddSymKeyFromPassword(id2) with seed %d: %s.", seed, err)
- }
- k1, err = w.GetSymKey(id1)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id1). err=%v", err)
- }
- k2, err = w.GetSymKey(id2)
- if err != nil {
- t.Fatalf("failed w.GetSymKey(id2). err=%v", err)
- }
- if !w.HasSymKey(id1) {
- t.Fatal("HasSymKey(id1) failed.")
- }
- if !w.HasSymKey(id2) {
- t.Fatal("HasSymKey(id2) failed.")
- }
- if !validateDataIntegrity(k2, aesKeyLength) {
- t.Fatal("key validation failed.")
- }
- if !bytes.Equal(k1, k2) {
- t.Fatal("k1 != k2.")
- }
-}
-
-func TestExpiry(t *testing.T) {
- InitSingleTest()
-
- w := New(&DefaultConfig)
- w.SetMinimumPowTest(0.0000001)
- defer w.SetMinimumPowTest(DefaultMinimumPoW)
- w.Start(nil)
- defer w.Stop()
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- params.TTL = 1
-
- messagesCount := 5
-
- // Send a few messages one after another. Due to low PoW and expiration buckets
- // with one second resolution, it covers a case when there are multiple items
- // in a single expiration bucket.
- for i := 0; i < messagesCount; i++ {
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- err = w.Send(env)
- if err != nil {
- t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
- }
- }
-
- // wait till received or timeout
- var received, expired bool
- ticker := time.NewTicker(100 * time.Millisecond)
- defer ticker.Stop()
- for j := 0; j < 20; j++ {
- <-ticker.C
- if len(w.Envelopes()) == messagesCount {
- received = true
- break
- }
- }
-
- if !received {
- t.Fatalf("did not receive the sent envelope, seed: %d.", seed)
- }
-
- // wait till expired or timeout
- for j := 0; j < 20; j++ {
- <-ticker.C
- if len(w.Envelopes()) == 0 {
- expired = true
- break
- }
- }
-
- if !expired {
- t.Fatalf("expire failed, seed: %d.", seed)
- }
-}
-
-func TestCustomization(t *testing.T) {
- InitSingleTest()
-
- w := New(&DefaultConfig)
- defer w.SetMinimumPowTest(DefaultMinimumPoW)
- defer w.SetMaxMessageSize(DefaultMaxMessageSize)
- w.Start(nil)
- defer w.Stop()
-
- const smallPoW = 0.00001
-
- f, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- params.KeySym = f.KeySym
- params.Topic = BytesToTopic(f.Topics[2])
- params.PoW = smallPoW
- params.TTL = 3600 * 24 // one day
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- err = w.Send(env)
- if err == nil {
- t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed)
- }
-
- w.SetMinimumPowTest(smallPoW / 2)
- err = w.Send(env)
- if err != nil {
- t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
- }
-
- params.TTL++
- msg, err = NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err = msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
- w.SetMaxMessageSize(uint32(env.size() - 1))
- err = w.Send(env)
- if err == nil {
- t.Fatalf("successfully sent oversized envelope (seed %d): false positive.", seed)
- }
-
- w.SetMaxMessageSize(DefaultMaxMessageSize)
- err = w.Send(env)
- if err != nil {
- t.Fatalf("failed to send second envelope with seed %d: %s.", seed, err)
- }
-
- // wait till received or timeout
- var received bool
- ticker := time.NewTicker(100 * time.Millisecond)
- defer ticker.Stop()
- for j := 0; j < 20; j++ {
- <-ticker.C
- if len(w.Envelopes()) > 1 {
- received = true
- break
- }
- }
-
- if !received {
- t.Fatalf("did not receive the sent envelope, seed: %d.", seed)
- }
-
- // check w.messages()
- _, err = w.Subscribe(f)
- if err != nil {
- t.Fatalf("failed subscribe with seed %d: %s.", seed, err)
- }
- <-ticker.C
- mail := f.Retrieve()
- if len(mail) > 0 {
- t.Fatalf("received premature mail. mail=%v", mail)
- }
-}
-
-func TestSymmetricSendCycle(t *testing.T) {
- InitSingleTest()
-
- w := New(&DefaultConfig)
- defer w.SetMinimumPowTest(DefaultMinimumPoW)
- defer w.SetMaxMessageSize(DefaultMaxMessageSize)
- w.Start(nil)
- defer w.Stop()
-
- filter1, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- filter1.PoW = DefaultMinimumPoW
-
- // Copy the first filter since some of its fields
- // are randomly gnerated.
- filter2 := &Filter{
- KeySym: filter1.KeySym,
- Topics: filter1.Topics,
- PoW: filter1.PoW,
- AllowP2P: filter1.AllowP2P,
- Messages: make(map[common.Hash]*ReceivedMessage),
- }
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- filter1.Src = ¶ms.Src.PublicKey
- filter2.Src = ¶ms.Src.PublicKey
-
- params.KeySym = filter1.KeySym
- params.Topic = BytesToTopic(filter1.Topics[2])
- params.PoW = filter1.PoW
- params.WorkTime = 10
- params.TTL = 50
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- _, err = w.Subscribe(filter1)
- if err != nil {
- t.Fatalf("failed subscribe 1 with seed %d: %s.", seed, err)
- }
-
- _, err = w.Subscribe(filter2)
- if err != nil {
- t.Fatalf("failed subscribe 2 with seed %d: %s.", seed, err)
- }
-
- err = w.Send(env)
- if err != nil {
- t.Fatalf("Failed sending envelope with PoW %.06f (seed %d): %s", env.PoW(), seed, err)
- }
-
- // wait till received or timeout
- var received bool
- ticker := time.NewTicker(10 * time.Millisecond)
- defer ticker.Stop()
- for j := 0; j < 200; j++ {
- <-ticker.C
- if len(w.Envelopes()) > 0 {
- received = true
- break
- }
- }
-
- if !received {
- t.Fatalf("did not receive the sent envelope, seed: %d.", seed)
- }
-
- // check w.messages()
- <-ticker.C
- mail1 := filter1.Retrieve()
- mail2 := filter2.Retrieve()
- if len(mail2) == 0 {
- t.Fatal("did not receive any email for filter 2.")
- }
- if len(mail1) == 0 {
- t.Fatal("did not receive any email for filter 1.")
- }
-
-}
-
-func TestSymmetricSendWithoutAKey(t *testing.T) {
- InitSingleTest()
-
- w := New(&DefaultConfig)
- defer w.SetMinimumPowTest(DefaultMinimumPoW)
- defer w.SetMaxMessageSize(DefaultMaxMessageSize)
- w.Start(nil)
- defer w.Stop()
-
- filter, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- filter.PoW = DefaultMinimumPoW
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- filter.Src = nil
-
- params.KeySym = filter.KeySym
- params.Topic = BytesToTopic(filter.Topics[2])
- params.PoW = filter.PoW
- params.WorkTime = 10
- params.TTL = 50
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- _, err = w.Subscribe(filter)
- if err != nil {
- t.Fatalf("failed subscribe 1 with seed %d: %s.", seed, err)
- }
-
- err = w.Send(env)
- if err != nil {
- t.Fatalf("Failed sending envelope with PoW %.06f (seed %d): %s", env.PoW(), seed, err)
- }
-
- // wait till received or timeout
- var received bool
- ticker := time.NewTicker(10 * time.Millisecond)
- defer ticker.Stop()
- for j := 0; j < 200; j++ {
- <-ticker.C
- if len(w.Envelopes()) > 0 {
- received = true
- break
- }
- }
-
- if !received {
- t.Fatalf("did not receive the sent envelope, seed: %d.", seed)
- }
-
- // check w.messages()
- <-ticker.C
- mail := filter.Retrieve()
- if len(mail) == 0 {
- t.Fatal("did not receive message in spite of not setting a public key")
- }
-}
-
-func TestSymmetricSendKeyMismatch(t *testing.T) {
- InitSingleTest()
-
- w := New(&DefaultConfig)
- defer w.SetMinimumPowTest(DefaultMinimumPoW)
- defer w.SetMaxMessageSize(DefaultMaxMessageSize)
- w.Start(nil)
- defer w.Stop()
-
- filter, err := generateFilter(t, true)
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
- filter.PoW = DefaultMinimumPoW
-
- params, err := generateMessageParams()
- if err != nil {
- t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
- }
-
- params.KeySym = filter.KeySym
- params.Topic = BytesToTopic(filter.Topics[2])
- params.PoW = filter.PoW
- params.WorkTime = 10
- params.TTL = 50
- msg, err := NewSentMessage(params)
- if err != nil {
- t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
- }
- env, err := msg.Wrap(params)
- if err != nil {
- t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
- }
-
- _, err = w.Subscribe(filter)
- if err != nil {
- t.Fatalf("failed subscribe 1 with seed %d: %s.", seed, err)
- }
-
- err = w.Send(env)
- if err != nil {
- t.Fatalf("Failed sending envelope with PoW %.06f (seed %d): %s", env.PoW(), seed, err)
- }
-
- // wait till received or timeout
- var received bool
- ticker := time.NewTicker(10 * time.Millisecond)
- defer ticker.Stop()
- for j := 0; j < 200; j++ {
- <-ticker.C
- if len(w.Envelopes()) > 0 {
- received = true
- break
- }
- }
-
- if !received {
- t.Fatalf("did not receive the sent envelope, seed: %d.", seed)
- }
-
- // check w.messages()
- <-ticker.C
- mail := filter.Retrieve()
- if len(mail) > 0 {
- t.Fatalf("received a message when keys weren't matching. message=%v", mail)
- }
-}
-
-func TestBloom(t *testing.T) {
- topic := TopicType{0, 0, 255, 6}
- b := TopicToBloom(topic)
- x := make([]byte, BloomFilterSize)
- x[0] = byte(1)
- x[32] = byte(1)
- x[BloomFilterSize-1] = byte(128)
- if !BloomFilterMatch(x, b) || !BloomFilterMatch(b, x) {
- t.Fatal("bloom filter does not match the mask")
- }
-
- _, err := mrand.Read(b)
- if err != nil {
- t.Fatalf("math rand error. err=%v", err)
- }
- _, err = mrand.Read(x)
- if err != nil {
- t.Fatalf("math rand error. err=%v", err)
- }
- if !BloomFilterMatch(b, b) {
- t.Fatal("bloom filter does not match self")
- }
- x = addBloom(x, b)
- if !BloomFilterMatch(x, b) {
- t.Fatal("bloom filter does not match combined bloom")
- }
- if !isFullNode(nil) {
- t.Fatal("isFullNode did not recognize nil as full node")
- }
- x[17] = 254
- if isFullNode(x) {
- t.Fatal("isFullNode false positive")
- }
- for i := 0; i < BloomFilterSize; i++ {
- b[i] = byte(255)
- }
- if !isFullNode(b) {
- t.Fatal("isFullNode false negative")
- }
- if BloomFilterMatch(x, b) {
- t.Fatal("bloomFilterMatch false positive")
- }
- if !BloomFilterMatch(b, x) {
- t.Fatal("bloomFilterMatch false negative")
- }
-
- w := New(&DefaultConfig)
- f := w.BloomFilter()
- if f != nil {
- t.Fatal("wrong bloom on creation")
- }
- err = w.SetBloomFilter(x)
- if err != nil {
- t.Fatalf("failed to set bloom filter: %s", err)
- }
- f = w.BloomFilter()
- if !BloomFilterMatch(f, x) || !BloomFilterMatch(x, f) {
- t.Fatal("retireved wrong bloom filter")
- }
-}