-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new 'node' RPC command #341
Conversation
@dajohi Does this one address your concerns with the original PR? |
Now that getpeerinfo contains ID, disconnect should take an ID. |
@dajohi: I'd suggest it should take either address or ID. The address already works with "addr:port" to be specific enough to identify a given peer. When "addr" with no port is provided, it appends the default port for the network and attempts to remove that node. So, I think ideally the current logic would stay, but perhaps |
type NodeCmd struct { | ||
SubCmd NodeSubCmd `jsonrpcusage:"\"connect|remove|disconnect\""` | ||
Addr string | ||
ConnectSubCmd *string `jsonrpcusage:"\"perm|non-perm\""` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the default?
EDIT: Well I think your intent here is to force the caller to specify perm
or non-perm
when the connect
sub command is provided. That is fine so long as the handler code detects the missing optional parameter and returns an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the intent is to require the caller to specify perm/non-perm. The handler code in rpcserver.go
currently detects if the optional parameter is missing, and returns the appropriate error if so.
EDIT: non-perm is now temp
Can we change non-perm to temp? |
@davecgh If i have 2 connections open to ip:port, should disconnect ip:port disconnect the first, or all? |
I'd say all of them ideally. |
Recently pushed a commit changing the following:
@dajohi by "2 connections", do you mean one inbound connection and outbound connection to the same |
@Roasbeef No, I don't think that is possible. I am talking about > 1 outbound connections to same ip:port. |
|
Thanks for the updates. I'll get the latest changes reviewed. |
A couple of things:
Not necessary for this PR, but food for thought:
|
More testing and I ran into this:
That is to say it didn't remove the node by IP without a port. Also I noticed that there is no way to see the id for a perm peer that is not connected. |
Probably also related to the previous issue:
I suspect that should error out because the node already exists as a perm peer even though it's not connected yet. |
Pushed some commits fixing the following:
|
Regarding not being able to show the ID of a permanent peer that isn't currently connected. It seems that this is the current implemented behavior of case getPeerInfoMsg:
syncPeer := s.blockManager.SyncPeer()
infos := make([]*btcjson.GetPeerInfoResult, 0, state.peers.Len())
state.forAllPeers(func(p *peer) {
if !p.Connected() {
return
} |
Correct, |
I believe this is ready for merge. There are a few points brought up that can be improved upon, but what is there works properly and reads well. Please squash and rebase it. |
* Gives node operators full control of peer connectivity * RPC adds ability to disconnect all matching non-persistent peers, remove persistent peers, and connect to peers making them either temporary or persistent.
Rebased and squashed 👍 |
@@ -475,16 +491,20 @@ func (s *server) handleQuery(querymsg interface{}, state *peerState) { | |||
msg.reply <- infos | |||
|
|||
case addNodeMsg: | |||
case connectNodeMsg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this breaks the existing addNodeMsg
, delNodeMsg
cases because they are no longer being handled. It would probably make sense to keep these cases as they were for compatibility. If not, we could deprecate addnode
RPC command with a note about using node
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right. Trying to use the addnode
sub-commands, del
or add
causes the btcctl
caller to hang indefinitely waiting for a reply since the case stacking essentially made the commands into a no-op.
I agree that we should mark addnode
as deprecated and point users to the new node
command instead. But for now, 've created as a temporary PR fix: #398
This PR adds new JSON-RPC command:
node
.node
allows a node operator full control over the peers their node is connect to.A call to the new
node
RPC can take the following forms:btcctl node connect <addr> perm
(will attempt connect to a peer and mark it was permanent)btcctl node connect <addr> temp
(will attempt to connect to a peer)btcctl node disconnect <addr or ID>
(will attempt to remove an outgoing or incoming peer)btcctl node remove <addr or ID>
(will attempt to remove a permanent peer)This PR replaces #336.
This aims to fix #79 by adding a new command that can disconnect any (inbound or outbound) non-persistent peer.