mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
whisper: generic server
Preparation work for enabling libp2p in wnode.
This commit is contained in:
parent
d12157254a
commit
41ac598330
4 changed files with 64 additions and 13 deletions
|
|
@ -53,7 +53,7 @@ const entropySize = 32
|
||||||
|
|
||||||
// singletons
|
// singletons
|
||||||
var (
|
var (
|
||||||
server *p2p.Server
|
server WhisperServer
|
||||||
shh *whisper.Whisper
|
shh *whisper.Whisper
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
mailServer mailserver.WMailServer
|
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)")
|
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)")
|
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")
|
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() {
|
func main() {
|
||||||
|
|
@ -274,17 +276,21 @@ func initialize() {
|
||||||
mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW)
|
mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW)
|
||||||
}
|
}
|
||||||
|
|
||||||
server = &p2p.Server{
|
if *useLibP2P {
|
||||||
Config: p2p.Config{
|
server = NewLibP2PWhisperServer()
|
||||||
PrivateKey: nodeid,
|
} else {
|
||||||
MaxPeers: maxPeers,
|
server = &p2p.Server{
|
||||||
Name: common.MakeName("wnode", "6.0"),
|
Config: p2p.Config{
|
||||||
Protocols: shh.Protocols(),
|
PrivateKey: nodeid,
|
||||||
ListenAddr: *argIP,
|
MaxPeers: maxPeers,
|
||||||
NAT: nat.Any(),
|
Name: common.MakeName("wnode", "6.1"),
|
||||||
BootstrapNodes: peers,
|
Protocols: shh.Protocols(),
|
||||||
StaticNodes: peers,
|
ListenAddr: *argIP,
|
||||||
TrustedNodes: peers,
|
NAT: nat.Any(),
|
||||||
|
BootstrapNodes: peers,
|
||||||
|
StaticNodes: peers,
|
||||||
|
TrustedNodes: peers,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -614,6 +620,7 @@ func messageLoop() {
|
||||||
printMessageInfo(msg)
|
printMessageInfo(msg)
|
||||||
reportedOnce = true
|
reportedOnce = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// All messages are saved upon specifying argSaveDir.
|
// All messages are saved upon specifying argSaveDir.
|
||||||
// fileExMode only specifies how messages are displayed on the console after they are saved.
|
// fileExMode only specifies how messages are displayed on the console after they are saved.
|
||||||
|
|
|
||||||
29
whisper/whisperv6/devp2p_glue.go
Normal file
29
whisper/whisperv6/devp2p_glue.go
Normal file
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package whisperv6
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DevP2PWhisperServer struct {
|
||||||
|
server *p2p.Server
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *DevP2PWhisperServer) Start() error {
|
||||||
|
return server.Start()
|
||||||
|
}
|
||||||
|
|
@ -107,3 +107,14 @@ func (stream *LibP2PStream) WriteMsg(msg p2p.Msg) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LibP2PWhisperServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *LibP2PWhisperServer) Start() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLibP2PWhisperServer() WhisperServer {
|
||||||
|
return &LibP2PWhisperServer{}
|
||||||
|
}
|
||||||
|
|
@ -56,6 +56,10 @@ const (
|
||||||
bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time
|
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
|
// Whisper represents a dark communication interface through the Ethereum
|
||||||
// network, using its very own P2P communication layer.
|
// network, using its very own P2P communication layer.
|
||||||
type Whisper struct {
|
type Whisper struct {
|
||||||
|
|
@ -597,7 +601,7 @@ func (whisper *Whisper) Send(envelope *Envelope) error {
|
||||||
|
|
||||||
// Start implements node.Service, starting the background data propagation thread
|
// Start implements node.Service, starting the background data propagation thread
|
||||||
// of the Whisper protocol.
|
// of the Whisper protocol.
|
||||||
func (whisper *Whisper) Start(*p2p.Server) error {
|
func (whisper *Whisper) Start(WhisperServer) error {
|
||||||
log.Info("started whisper v." + ProtocolVersionStr)
|
log.Info("started whisper v." + ProtocolVersionStr)
|
||||||
go whisper.update()
|
go whisper.update()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue