diff options
author | Felix Lange <fjl@twurst.com> | 2016-07-29 18:34:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-29 18:34:28 +0800 |
commit | b8ba80bff70bedb59385e35f11de18679f3b4967 (patch) | |
tree | 41031b7d529ce302f45770c63ec5827a99d4bd5b /node | |
parent | 8ec6ccc54d1da7bbaa87bd0b489b1778ea729c90 (diff) | |
parent | 4c3da0f2e1063ccb32933faff4601d5f5e0f987c (diff) | |
download | go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar.gz go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar.bz2 go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar.lz go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar.xz go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.tar.zst go-tangerine-b8ba80bff70bedb59385e35f11de18679f3b4967.zip |
Merge pull request #2740 from Firescar96/removepeer
node, p2p, internal: Add ability to remove peers via admin interface
Diffstat (limited to 'node')
-rw-r--r-- | node/api.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/node/api.go b/node/api.go index 9b2be9c2e..3523874ab 100644 --- a/node/api.go +++ b/node/api.go @@ -58,6 +58,22 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) { return true, nil } +// RemovePeer disconnects from a a remote node if the connection exists +func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error) { + // Make sure the server is running, fail otherwise + server := api.node.Server() + if server == nil { + return false, ErrNodeStopped + } + // Try to remove the url as a static peer and return + node, err := discover.ParseNode(url) + if err != nil { + return false, fmt.Errorf("invalid enode: %v", err) + } + server.RemovePeer(node) + return true, nil +} + // StartRPC starts the HTTP RPC API server. func (api *PrivateAdminAPI) StartRPC(host *string, port *rpc.HexNumber, cors *string, apis *string) (bool, error) { api.node.lock.Lock() |