whipser: remove some warnings and fix formatting

This commit is contained in:
Guillaume Ballet 2018-03-02 23:16:34 +01:00
parent b92195e2b6
commit b226d5dd41
6 changed files with 26 additions and 12 deletions

View file

@ -20,22 +20,27 @@ import (
"github.com/ethereum/go-ethereum/p2p"
)
// DevP2PWhisperServer implements WhisperServer with a DevP2P backend
type DevP2PWhisperServer struct {
Server *p2p.Server
}
// Start starts the server
func (server *DevP2PWhisperServer) Start() error {
return server.Server.Start()
}
// Stop stops the server
func (server *DevP2PWhisperServer) Stop() {
server.Server.Stop()
}
// PeerCount returns the peer count for the node
func (server *DevP2PWhisperServer) PeerCount() int {
return server.Server.PeerCount()
}
// Enode returns the enode address of the node
func (server *DevP2PWhisperServer) Enode() string {
return server.Server.NodeInfo().Enode
}

View file

@ -17,17 +17,18 @@
package whisperv6
import (
"context"
"bytes"
"context"
"encoding/binary"
"fmt"
"math"
"github.com/ethereum/go-ethereum/p2p"
libp2p "github.com/libp2p/go-libp2p"
crypto "github.com/libp2p/go-libp2p-crypto"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
crypto "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer"
)
// LibP2PStream is a wrapper used to implement the MsgReadWriter
@ -112,20 +113,24 @@ func (stream *LibP2PStream) WriteMsg(msg p2p.Msg) error {
return nil
}
// LibP2PPeer implements Peer for libp2p
type LibP2PPeer struct {
PeerBase
id peer.ID
}
// ID returns the id of the peer
func (p *LibP2PPeer) ID() string {
return p.id.String()
}
// LibP2PWhisperServer implements WhisperServer for libp2p.
type LibP2PWhisperServer struct {
Host host.Host
}
// Start starts the server
func (server *LibP2PWhisperServer) Start() error {
return nil
}
@ -145,6 +150,8 @@ func (server *LibP2PWhisperServer) Enode() string {
return server.Host.Addrs()[0].String()
}
// NewLibP2PWhisperServer creates a new WhisperServer with
// a libp2p backend.
func NewLibP2PWhisperServer() (WhisperServer, error) {
priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 384)
opts := []libp2p.Option{

View file

@ -17,10 +17,10 @@
package whisperv6
import (
"io/ioutil"
"bytes"
"context"
"encoding/binary"
"io/ioutil"
"math"
"math/rand"
"testing"

View file

@ -56,6 +56,8 @@ const (
bloomFilterToleranceIdx // Bloom filter tolerated by the whisper node for a limited time
)
// WhisperServer abstracts a server, which could be either DevP2p-based
// or libp2p-based.
type WhisperServer interface {
Start() error
Stop()

View file

@ -17,10 +17,10 @@
package whisperv6
import (
"fmt"
"bytes"
"crypto/ecdsa"
"crypto/sha256"
"fmt"
mrand "math/rand"
"testing"
"time"