mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
whisper: update to the wnode libp2p interface
Fix the node address iinput, enable the passing of ipfs-enabled multiaddr address schemes.
This commit is contained in:
parent
b226d5dd41
commit
9483cfb1e8
2 changed files with 41 additions and 6 deletions
|
|
@ -43,6 +43,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
|
||||
"github.com/ethereum/go-ethereum/whisper/mailserver"
|
||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
|
|
@ -178,6 +180,7 @@ func initialize() {
|
|||
|
||||
done = make(chan struct{})
|
||||
var peers []*discover.Node
|
||||
var libp2pPeers []multiaddr.Multiaddr
|
||||
var err error
|
||||
|
||||
if *generateKey {
|
||||
|
|
@ -202,11 +205,24 @@ func initialize() {
|
|||
} else if *fileReader {
|
||||
*bootstrapMode = true
|
||||
} else {
|
||||
if len(*argEnode) == 0 {
|
||||
argEnode = scanLineA("Please enter the peer's enode: ")
|
||||
if *useLibP2P {
|
||||
var libp2pbootstrap *string
|
||||
for libp2pbootstrap == nil {
|
||||
libp2pbootstrap = scanLineA("Please enter the bootstrap node's addres: ")
|
||||
}
|
||||
libp2pbootaddr, err := multiaddr.NewMultiaddr(*libp2pbootstrap)
|
||||
if err != nil {
|
||||
utils.Fatalf("Error parsing the bootnode addr: %v", err)
|
||||
}
|
||||
fmt.Println(libp2pbootaddr)
|
||||
libp2pPeers = append(libp2pPeers, libp2pbootaddr)
|
||||
} else {
|
||||
if len(*argEnode) == 0 {
|
||||
argEnode = scanLineA("Please enter the peer's enode: ")
|
||||
}
|
||||
peer := discover.MustParseNode(*argEnode)
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
peer := discover.MustParseNode(*argEnode)
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
|
||||
if *mailServerMode {
|
||||
|
|
@ -281,6 +297,9 @@ func initialize() {
|
|||
if err != nil {
|
||||
utils.Fatalf("Error starting the libp2p client: %v", err)
|
||||
}
|
||||
for _, p := range libp2pPeers {
|
||||
server.(*whisper.LibP2PWhisperServer).AddPeer(p)
|
||||
}
|
||||
} else {
|
||||
server = &whisper.DevP2PWhisperServer{
|
||||
&p2p.Server{
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
host "github.com/libp2p/go-libp2p-host"
|
||||
inet "github.com/libp2p/go-libp2p-net"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
)
|
||||
|
||||
// LibP2PStream is a wrapper used to implement the MsgReadWriter
|
||||
|
|
@ -128,6 +129,8 @@ func (p *LibP2PPeer) ID() string {
|
|||
// LibP2PWhisperServer implements WhisperServer for libp2p.
|
||||
type LibP2PWhisperServer struct {
|
||||
Host host.Host
|
||||
|
||||
Peers []LibP2PPeer
|
||||
}
|
||||
|
||||
// Start starts the server
|
||||
|
|
@ -147,7 +150,20 @@ func (server *LibP2PWhisperServer) PeerCount() int {
|
|||
|
||||
// Enode returns the enode address of the node
|
||||
func (server *LibP2PWhisperServer) Enode() string {
|
||||
return server.Host.Addrs()[0].String()
|
||||
addr := server.Host.Addrs()[0]
|
||||
hostAddr, _ := ma.NewMultiaddr(fmt.Sprintf("/ipfs/%s", server.Host.ID().Pretty()))
|
||||
fullAddr := addr.Encapsulate(hostAddr)
|
||||
return fullAddr.String()
|
||||
}
|
||||
|
||||
func (server *LibP2PWhisperServer) AddPeer(addr ma.Multiaddr) *LibP2PPeer {
|
||||
fmt.Println("Adding peer: ", addr)
|
||||
pid, err := addr.ValueForProtocol(ma.P_IPFS)
|
||||
if err != nil {
|
||||
// XXX
|
||||
panic(err)
|
||||
}
|
||||
return &LibP2PPeer{id: peer.ID(pid)}
|
||||
}
|
||||
|
||||
// NewLibP2PWhisperServer creates a new WhisperServer with
|
||||
|
|
@ -163,5 +179,5 @@ func NewLibP2PWhisperServer() (WhisperServer, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("Error setting up the libp2p network: %s", err)
|
||||
}
|
||||
return &LibP2PWhisperServer{h}, nil
|
||||
return &LibP2PWhisperServer{h, []LibP2PPeer{}}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue