diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go index 988c50ce3d..99c0bab563 100644 --- a/cmd/wnode/main.go +++ b/cmd/wnode/main.go @@ -53,7 +53,7 @@ const entropySize = 32 // singletons var ( - server *p2p.Server + server WhisperServer shh *whisper.Whisper done chan struct{} mailServer mailserver.WMailServer @@ -104,6 +104,8 @@ var ( 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") + + useLibP2P = flag.Bool("libp2p", false, "Use libp2p as the protocol layer") ) func main() { @@ -274,17 +276,21 @@ func initialize() { mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW) } - 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, + if *useLibP2P { + server = NewLibP2PWhisperServer() + } else { + server = &p2p.Server{ + Config: p2p.Config{ + PrivateKey: nodeid, + MaxPeers: maxPeers, + Name: common.MakeName("wnode", "6.1"), + Protocols: shh.Protocols(), + ListenAddr: *argIP, + NAT: nat.Any(), + BootstrapNodes: peers, + StaticNodes: peers, + TrustedNodes: peers, + }, }, } } @@ -614,6 +620,7 @@ func messageLoop() { 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. diff --git a/whisper/whisperv6/devp2p_glue.go b/whisper/whisperv6/devp2p_glue.go new file mode 100644 index 0000000000..9ac46d238b --- /dev/null +++ b/whisper/whisperv6/devp2p_glue.go @@ -0,0 +1,29 @@ +// 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 ( + "github.com/ethereum/go-ethereum/p2p" +) + +type DevP2PWhisperServer struct { + server *p2p.Server +} + +func (server *DevP2PWhisperServer) Start() error { + return server.Start() +} \ No newline at end of file diff --git a/whisper/whisperv6/libp2p_glue.go b/whisper/whisperv6/libp2p_glue.go index 753c41d23f..9e46d4e7c3 100644 --- a/whisper/whisperv6/libp2p_glue.go +++ b/whisper/whisperv6/libp2p_glue.go @@ -107,3 +107,14 @@ func (stream *LibP2PStream) WriteMsg(msg p2p.Msg) error { return nil } + +type LibP2PWhisperServer struct { +} + +func (server *LibP2PWhisperServer) Start() error { + return nil +} + +func NewLibP2PWhisperServer() WhisperServer { + return &LibP2PWhisperServer{} +} \ No newline at end of file diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index 5c873ca049..0574ddde4c 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -56,6 +56,10 @@ const ( bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time ) +type WhisperServer interface { + Start() error +} + // Whisper represents a dark communication interface through the Ethereum // network, using its very own P2P communication layer. type Whisper struct { @@ -597,7 +601,7 @@ func (whisper *Whisper) Send(envelope *Envelope) error { // Start implements node.Service, starting the background data propagation thread // of the Whisper protocol. -func (whisper *Whisper) Start(*p2p.Server) error { +func (whisper *Whisper) Start(WhisperServer) error { log.Info("started whisper v." + ProtocolVersionStr) go whisper.update()