-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RPC calls for p2p module and tests for them (#52)
* feat: add RPC calls for p2p module and tests for them * fix node test * remove not needed dev-dependencies * fix dev-dependencies properly * add files to fix formatting * Address PR comments, add libp2p feature * fix feature flag and last asserts * remove not directly needed libp2p-identity * and fmt * appease clippy * run clippy for all targets * simplify ser/de of PeerId, add note about the go-jsonrpc workaround * make figuring out node ip better * remove task handle return * split libp2p and add style changes for Yannis review * fmt * fmt * fixup doc-comments, tighten feature flag * feature libp2p->p2p rename * Update rpc/tests/p2p.rs Co-authored-by: Maciej Zwoliński <mac.zwolinski@gmail.com> --------- Co-authored-by: Maciej Zwoliński <mac.zwolinski@gmail.com>
- Loading branch information
Showing
15 changed files
with
533 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,17 +1,85 @@ | ||
use celestia_types::p2p::{ | ||
AddrInfo, BandwidthStats, Connectedness, PeerId, Reachability, ResourceManagerStats, | ||
}; | ||
use jsonrpsee::proc_macros::rpc; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct AddrInfo { | ||
#[serde(rename = "ID")] | ||
pub id: String, | ||
// TODO: multiaddr | ||
#[serde(rename = "Addrs")] | ||
pub addrs: Vec<String>, | ||
} | ||
|
||
#[rpc(client)] | ||
pub trait P2P { | ||
/// BandwidthForPeer returns a Stats struct with bandwidth metrics associated with the given peer.ID. The metrics returned include all traffic sent / received for the peer, regardless of protocol. | ||
#[method(name = "p2p.BandwidthForPeer")] | ||
async fn p2p_bandwidth_for_peer(&self, peer_id: &PeerId) -> Result<BandwidthStats, Error>; | ||
|
||
/// BandwidthForProtocol returns a Stats struct with bandwidth metrics associated with the given protocol.ID. | ||
#[method(name = "p2p.BandwidthForProtocol")] | ||
async fn p2p_bandwidth_for_protocol(&self, protocol_id: &str) -> Result<BandwidthStats, Error>; | ||
|
||
/// BandwidthStats returns a Stats struct with bandwidth metrics for all data sent/received by the local peer, regardless of protocol or remote peer IDs. | ||
#[method(name = "p2p.BandwidthStats")] | ||
async fn p2p_bandwidth_stats(&self) -> Result<BandwidthStats, Error>; | ||
|
||
// This method does not report errors due to a workaround to a go-jsonrpc bug, see https://github.com/eigerco/celestia-node-rs/issues/53 | ||
/// BlockPeer adds a peer to the set of blocked peers. | ||
#[method(name = "p2p.BlockPeer")] | ||
async fn p2p_block_peer(&self, peer_id: &PeerId); | ||
|
||
// This method does not report errors due to a workaround to a go-jsonrpc bug, see https://github.com/eigerco/celestia-node-rs/issues/53 | ||
/// ClosePeer closes the connection to a given peer. | ||
#[method(name = "p2p.ClosePeer")] | ||
async fn p2p_close_peer(&self, peer_id: &PeerId); | ||
|
||
// This method does not report errors due to a workaround to a go-jsonrpc bug, see https://github.com/eigerco/celestia-node-rs/issues/53 | ||
/// Connect ensures there is a connection between this host and the peer with given peer. | ||
#[method(name = "p2p.Connect")] | ||
async fn p2p_connect(&self, address: &AddrInfo); | ||
|
||
/// Connectedness returns a state signaling connection capabilities. | ||
#[method(name = "p2p.Connectedness")] | ||
async fn p2p_connectedness(&self, peer_id: &PeerId) -> Result<Connectedness, Error>; | ||
|
||
/// Info returns address information about the host. | ||
#[method(name = "p2p.Info")] | ||
async fn p2p_info(&self) -> Result<AddrInfo, Error>; | ||
|
||
/// IsProtected returns whether the given peer is protected. | ||
#[method(name = "p2p.IsProtected")] | ||
async fn p2p_is_protected(&self, peer_id: &PeerId, tag: &str) -> Result<bool, Error>; | ||
|
||
/// ListBlockedPeers returns a list of blocked peers. | ||
#[method(name = "p2p.ListBlockedPeers")] | ||
async fn p2p_list_blocked_peers(&self) -> Result<Vec<PeerId>, Error>; | ||
|
||
/// NATStatus returns the current NAT status. | ||
#[method(name = "p2p.NATStatus")] | ||
async fn p2p_nat_status(&self) -> Result<Reachability, Error>; | ||
|
||
/// PeerInfo returns a small slice of information Peerstore has on the given peer. | ||
#[method(name = "p2p.PeerInfo")] | ||
async fn p2p_peer_info(&self, peer_id: &PeerId) -> Result<AddrInfo, Error>; | ||
|
||
/// Peers returns connected peers. | ||
#[method(name = "p2p.Peers")] | ||
async fn p2p_peers(&self) -> Result<Vec<PeerId>, Error>; | ||
|
||
// This method does not report errors due to a workaround to a go-jsonrpc bug, see https://github.com/eigerco/celestia-node-rs/issues/53 | ||
/// Protect adds a peer to the list of peers who have a bidirectional peering agreement that they are protected from being trimmed, dropped or negatively scored. | ||
#[method(name = "p2p.Protect")] | ||
async fn p2p_protect(&self, peer_id: &PeerId, tag: &str); | ||
|
||
// We might get null in response here, so Option is needed | ||
/// PubSubPeers returns the peer IDs of the peers joined on the given topic. | ||
#[method(name = "p2p.PubSubPeers")] | ||
async fn p2p_pub_sub_peers(&self, topic: &str) -> Result<Option<Vec<PeerId>>, Error>; | ||
|
||
/// ResourceState returns the state of the resource manager. | ||
#[method(name = "p2p.ResourceState")] | ||
async fn p2p_resource_state(&self) -> Result<ResourceManagerStats, Error>; | ||
|
||
// This method does not report errors due to a workaround to a go-jsonrpc bug, see https://github.com/eigerco/celestia-node-rs/issues/53 | ||
/// UnblockPeer removes a peer from the set of blocked peers. | ||
#[method(name = "p2p.UnblockPeer")] | ||
async fn p2p_unblock_peer(&self, peer_id: &PeerId); | ||
|
||
/// Unprotect removes a peer from the list of peers who have a bidirectional peering agreement that they are protected from being trimmed, dropped or negatively scored, returning a bool representing whether the given peer is protected or not. | ||
#[method(name = "p2p.Unprotect")] | ||
async fn p2p_unprotect(&self, peer_id: &PeerId, tag: &str) -> Result<bool, Error>; | ||
} |
Oops, something went wrong.