Implement AddPeer/RemovePeer on eth-node
This commit is contained in:
parent
41a6502340
commit
7f11030896
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue