Implement AddPeer/RemovePeer on eth-node

This commit is contained in:
Pedro Pombeiro 2019-12-12 17:06:00 +01:00 committed by Pedro Pombeiro
parent 41a6502340
commit 7f11030896
6 changed files with 72 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package gethbridge
import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode"
gethens "github.com/status-im/status-go/eth-node/bridge/geth/ens"
"github.com/status-im/status-go/eth-node/types"
enstypes "github.com/status-im/status-go/eth-node/types/ens"
@ -43,3 +44,25 @@ func (w *gethNodeWrapper) GetWhisper(ctx interface{}) (types.Whisper, error) {
return NewGethWhisperWrapper(nativeWhisper), nil
}
func (w *gethNodeWrapper) AddPeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().AddPeer(parsedNode)
return nil
}
func (w *gethNodeWrapper) RemovePeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().RemovePeer(parsedNode)
return nil
}

View File

@ -61,3 +61,17 @@ func (w *nimbusNodeWrapper) NewENSVerifier(_ *zap.Logger) enstypes.ENSVerifier {
func (w *nimbusNodeWrapper) GetWhisper(ctx interface{}) (types.Whisper, error) {
return w.w, nil
}
func (w *nimbusNodeWrapper) AddPeer(url string) error {
urlC := C.CString(url)
defer C.free(unsafe.Pointer(urlC))
if !C.nimbus_add_peer(urlC) {
return fmt.Errorf("failed to add peer: %s", url)
}
return nil
}
func (w *nimbusNodeWrapper) RemovePeer(url string) error {
panic("TODO: RemovePeer")
}

View File

@ -18,4 +18,6 @@ func (n EnodeID) String() string {
type Node interface {
NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier
GetWhisper(ctx interface{}) (Whisper, error)
AddPeer(url string) error
RemovePeer(url string) error
}

View File

@ -401,6 +401,14 @@ func (w *testNodeWrapper) GetWhisper(_ interface{}) (types.Whisper, error) {
return w.w, nil
}
func (w *testNodeWrapper) AddPeer(url string) error {
panic("not implemented")
}
func (w *testNodeWrapper) RemovePeer(url string) error {
panic("not implemented")
}
type WhisperNodeMockSuite struct {
suite.Suite

View File

@ -2,6 +2,7 @@ package gethbridge
import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode"
gethens "github.com/status-im/status-go/eth-node/bridge/geth/ens"
"github.com/status-im/status-go/eth-node/types"
enstypes "github.com/status-im/status-go/eth-node/types/ens"
@ -43,3 +44,25 @@ func (w *gethNodeWrapper) GetWhisper(ctx interface{}) (types.Whisper, error) {
return NewGethWhisperWrapper(nativeWhisper), nil
}
func (w *gethNodeWrapper) AddPeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().AddPeer(parsedNode)
return nil
}
func (w *gethNodeWrapper) RemovePeer(url string) error {
parsedNode, err := enode.ParseV4(url)
if err != nil {
return err
}
w.stack.Server().RemovePeer(parsedNode)
return nil
}

View File

@ -18,4 +18,6 @@ func (n EnodeID) String() string {
type Node interface {
NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier
GetWhisper(ctx interface{}) (Whisper, error)
AddPeer(url string) error
RemovePeer(url string) error
}