-
Notifications
You must be signed in to change notification settings - Fork 115
rpc: implement getaddednodeinfo #915
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # `getaddednodeinfo` | ||
|
|
||
| Returns information about the given added node, or all added nodes. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Synopsis | ||
|
|
||
| ```bash | ||
| floresta-cli getaddednodeinfo [node] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| floresta-cli getaddednodeinfo | ||
| floresta-cli getaddednodeinfo 192.168.0.1:8333 | ||
| ``` | ||
|
|
||
| ## Arguments | ||
|
|
||
| `node` - (string, optional) If provided, return information about this specific node. Can be an `ip:port` or just an `ip`. | ||
|
|
||
| ## Returns | ||
|
|
||
| ### Ok response | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "addednode": "192.168.0.1:8333", | ||
| "connected": true, | ||
| "addresses": [ | ||
| { | ||
| "address": "192.168.0.1:8333", | ||
| "connected": "outbound" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| - `addednode` - (string) The node address in `ip:port` format, as provided to `addnode`. | ||
| - `connected` - (boolean) Whether the node is currently connected. | ||
| - `addresses` - (json array) A list of addresses with connection direction info. Empty when not connected. | ||
| - `address` - (string) The address in `ip:port` format. | ||
| - `connected` - (string) Connection direction: `"outbound"` when connected. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Only nodes added via `addnode add` are listed. Nodes connected with `addnode onetry` are not included. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this information is wrong based on the code I saw. It would be useful to demonstrate this in the Python test, since this is a rule for this RPC that must be followed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @moisesPompilio thanks for your feedbacks... the way @jaoleal opened a PR with this implementation there and we decided to use that...your reviews there too will be highly appreciated... |
||
| - The `addresses` array is empty when `connected` is `false`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
|
||
| """ | ||
| floresta_cli_getaddednodeinfo.py | ||
|
|
||
| This functional test cli utility to interact with a Floresta node with `getaddednodeinfo` | ||
| """ | ||
|
|
||
| from test_framework import FlorestaTestFramework | ||
| from test_framework.node import NodeType | ||
|
|
||
|
|
||
| class GetAddedNodeInfoTest(FlorestaTestFramework): | ||
| """ | ||
| Test `getaddednodeinfo` by adding a bitcoind peer via `addnode add`, | ||
| then verifying the result of `getaddednodeinfo` contains the peer. | ||
| """ | ||
|
|
||
| def set_test_params(self): | ||
| """ | ||
| Setup florestad and bitcoind nodes | ||
| """ | ||
| self.florestad = self.add_node_default_args(variant=NodeType.FLORESTAD) | ||
| self.bitcoind = self.add_node_extra_args( | ||
| variant=NodeType.BITCOIND, | ||
| extra_args=["-v2transport=0"], | ||
| ) | ||
|
|
||
| def run_test(self): | ||
| """ | ||
| Test getaddednodeinfo returns correct info before and after adding a peer | ||
| """ | ||
| self.run_node(self.florestad) | ||
| self.run_node(self.bitcoind) | ||
|
|
||
| # Before adding any node, the list should be empty | ||
| result = self.florestad.rpc.get_addednodeinfo() | ||
| self.assertIsSome(result) | ||
| self.assertEqual(len(result), 0) | ||
|
|
||
| # Add bitcoind as a persistent peer | ||
| self.connect_nodes(self.florestad, self.bitcoind, "add", v2transport=False) | ||
| self.wait_for_peers_connections(self.florestad, self.bitcoind, True) | ||
|
|
||
| # getaddednodeinfo should now return one entry | ||
| result = self.florestad.rpc.get_addednodeinfo() | ||
| self.assertIsSome(result) | ||
| self.assertEqual(len(result), 1) | ||
| self.assertTrue(result[0]["connected"]) | ||
| self.assertEqual(len(result[0]["addresses"]), 1) | ||
| self.assertEqual(result[0]["addresses"][0]["connected"], "outbound") | ||
|
|
||
| # Query by specific node address | ||
| node_addr = result[0]["addednode"] | ||
| filtered = self.florestad.rpc.get_addednodeinfo(node_addr) | ||
| self.assertIsSome(filtered) | ||
| self.assertEqual(len(filtered), 1) | ||
| self.assertEqual(filtered[0]["addednode"], node_addr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| GetAddedNodeInfoTest().main() |

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.
floresta’s RPCs need to be as close as possible to the core standard, so here it’s just the ip from core without the port
https://bitcoincore.org/en/doc/30.0.0/rpc/network/getaddednodeinfo/
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.
thanks...this will be addressed on PR #916