aboutsummaryrefslogtreecommitdiffstats
path: root/node/api.go
diff options
context:
space:
mode:
authorAndrey Petrov <andrey.petrov@shazow.net>2018-02-26 04:39:29 +0800
committerAndrey Petrov <andrey.petrov@shazow.net>2018-06-22 00:21:48 +0800
commit2a75fe3308faf4d77054e00b55566c9f18591572 (patch)
treeaf1cfa253ac07beb778f75bfb155125290efc291 /node/api.go
parentd926bf2c7e3182d694c15829a37a0ca7331cd03c (diff)
downloaddexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar.gz
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar.bz2
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar.lz
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar.xz
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.tar.zst
dexon-2a75fe3308faf4d77054e00b55566c9f18591572.zip
rpc: Add admin_addTrustedPeer and admin_removeTrustedPeer.
These RPC calls are analogous to Parity's parity_addReservedPeer and parity_removeReservedPeer. They are useful for adjusting the trusted peer set during runtime, without requiring restarting the server.
Diffstat (limited to 'node/api.go')
-rw-r--r--node/api.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/node/api.go b/node/api.go
index 989d3884a..e5f388463 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) {