Skip to content

Commit

Permalink
Implement AddPeer/RemovePeer on eth-node
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pombeiro committed Dec 19, 2019
1 parent 41a6502 commit 7f11030
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions eth-node/bridge/geth/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions eth-node/bridge/nimbus/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 2 additions & 0 deletions eth-node/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions services/shhext/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/status-im/status-go/eth-node/bridge/geth/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/status-im/status-go/eth-node/types/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f11030

Please sign in to comment.