-
Notifications
You must be signed in to change notification settings - Fork 135
feat: add getaddednodeinfo rpc #1114
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
Open
jaoleal
wants to merge
4
commits into
getfloresta:master
Choose a base branch
from
jaoleal:rpc/getaddednodeinfo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1f10d37
feat(wire): add GetAddedNodeInfo request and response plumbing
jaoleal 486eec4
feat(rpc): add getaddednodeinfo to server-side handler
jaoleal 44e98c8
feat(rpc): add rpc client command and CLI binding for getaddednodeinfo
jaoleal 71aadb4
test(rpc): add getaddednodeinfo integration test
jaoleal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,8 @@ use crate::node_context::NodeContext; | |||||
| use crate::node_context::PeerId; | ||||||
| use crate::node_handle::NodeResponse; | ||||||
| use crate::node_handle::UserRequest; | ||||||
| use crate::node_interface::AddedNodeAddress; | ||||||
| use crate::node_interface::AddedNodeInfo; | ||||||
| use crate::node_interface::PeerInfo; | ||||||
| use crate::p2p_wire::error::WireError; | ||||||
| use crate::p2p_wire::peer::PeerMessages; | ||||||
|
|
@@ -849,6 +851,45 @@ where | |||||
| }) | ||||||
| } | ||||||
|
|
||||||
| pub(crate) fn handle_get_added_node_info( | ||||||
| &self, | ||||||
| node: Option<BitcoinSocketAddr>, | ||||||
| ) -> Vec<AddedNodeInfo> { | ||||||
| self.added_peers | ||||||
| .iter() | ||||||
| .filter_map(|added| { | ||||||
| // If a node filter is specified, skip entries that don't match | ||||||
| if let Some(filter) = &node { | ||||||
| if &added.address != filter { | ||||||
| return None; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| let connected = self.peers.values().any(|peer| { | ||||||
| peer.address.as_bitcoin_socket_addr() == &added.address | ||||||
|
Member
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.
Suggested change
|
||||||
| && peer.state == PeerStatus::Ready | ||||||
| }); | ||||||
|
|
||||||
| let addr_str = added.address.to_string(); | ||||||
|
|
||||||
| let addresses = if connected { | ||||||
| vec![AddedNodeAddress { | ||||||
| address: addr_str.clone(), | ||||||
| connected: "outbound".to_string(), | ||||||
| }] | ||||||
| } else { | ||||||
| vec![] | ||||||
| }; | ||||||
|
|
||||||
| Some(AddedNodeInfo { | ||||||
| addednode: addr_str, | ||||||
| connected, | ||||||
| addresses, | ||||||
| }) | ||||||
| }) | ||||||
| .collect() | ||||||
| } | ||||||
|
|
||||||
| // === ADDNODE === | ||||||
|
|
||||||
| /// Handles addnode-RPC `Add` requests, adding a new peer to the `added_peers` list. This means | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,33 @@ pub enum UserRequest { | |
|
|
||
| /// Return address manager statistics. | ||
| GetAddrManInfo, | ||
|
|
||
| /// Return information about manually added nodes, optionally filtered by address. | ||
| GetAddedNodeInfo(Option<BitcoinSocketAddr>), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize)] | ||
| /// Information about a manually added node (via `addnode`). | ||
| pub struct AddedNodeInfo { | ||
| /// The address of the added node in "ip:port" format. | ||
| pub addednode: String, | ||
|
Member
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.
|
||
|
|
||
| /// Whether we are currently connected to this node. | ||
| pub connected: bool, | ||
|
|
||
| /// Connection details. Only populated when `connected` is true. | ||
| #[serde(skip_serializing_if = "Vec::is_empty")] | ||
| pub addresses: Vec<AddedNodeAddress>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize)] | ||
| /// Address information for a connected added node. | ||
| pub struct AddedNodeAddress { | ||
| /// The peer address in "ip:port" format. | ||
| pub address: String, | ||
|
|
||
| /// The connection direction: "outbound" (Floresta does not accept inbound). | ||
| pub connected: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize)] | ||
|
|
@@ -213,6 +240,12 @@ pub trait NetworkMethods { | |
| /// about a single peer. | ||
| fn get_peer_info(&self) -> impl Future<Output = Result<Vec<PeerInfo>, Self::Error>>; | ||
|
|
||
| /// Information about all manually added nodes possibly filtering by a given one. | ||
| fn get_added_node_info( | ||
| &self, | ||
| node: Option<BitcoinSocketAddr>, | ||
| ) -> impl Future<Output = Result<Vec<AddedNodeInfo>, Self::Error>>; | ||
|
|
||
| /// Returns the number of peers currently connected to the node | ||
| fn get_connection_count(&self) -> impl Future<Output = Result<usize, Self::Error>>; | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.