diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2018-08-06 19:30:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-06 19:30:04 +0800 |
commit | c4df67461f6e0d35389e0dabd5a932a991e3a42d (patch) | |
tree | c4baaa02385b397f9b872bb4ac8a0a36c7bfeb6a /node | |
parent | 941018b570aef77f1a47197a88e7a0b533b718f7 (diff) | |
parent | 6209545083f656f2dccbe4561644a757ff6443b5 (diff) | |
download | go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar.gz go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar.bz2 go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar.lz go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar.xz go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.tar.zst go-tangerine-c4df67461f6e0d35389e0dabd5a932a991e3a42d.zip |
Merge pull request #16333 from shazow/addremovetrustedpeer
rpc: Add admin_addTrustedPeer and admin_removeTrustedPeer.
Diffstat (limited to 'node')
-rw-r--r-- | node/api.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/node/api.go b/node/api.go index f44c99153..2656c2120 100644 --- a/node/api.go +++ b/node/api.go @@ -59,7 +59,7 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) { return true, nil } -// RemovePeer disconnects from a a remote node if the connection exists +// RemovePeer disconnects from 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() @@ -75,6 +75,37 @@ func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error) { return true, nil } +// AddTrustedPeer allows a remote node to always connect, even if slots are full +func (api *PrivateAdminAPI) AddTrustedPeer(url string) (bool, error) { + // Make sure the server is running, fail otherwise + server := api.node.Server() + if server == nil { + return false, ErrNodeStopped + } + node, err := discover.ParseNode(url) + if err != nil { + return false, fmt.Errorf("invalid enode: %v", err) + } + server.AddTrustedPeer(node) + return true, nil +} + +// RemoveTrustedPeer removes a remote node from the trusted peer set, but it +// does not disconnect it automatically. +func (api *PrivateAdminAPI) RemoveTrustedPeer(url string) (bool, error) { + // Make sure the server is running, fail otherwise + server := api.node.Server() + if server == nil { + return false, ErrNodeStopped + } + node, err := discover.ParseNode(url) + if err != nil { + return false, fmt.Errorf("invalid enode: %v", err) + } + server.RemoveTrustedPeer(node) + return true, nil +} + // PeerEvents creates an RPC subscription which receives peer events from the // node's p2p.Server func (api *PrivateAdminAPI) PeerEvents(ctx context.Context) (*rpc.Subscription, error) { |