|
| 1 | +use crate::types::portal::FindNodesInfo; |
| 2 | +use crate::types::portal::{ |
| 3 | + AcceptInfo, ContentInfo, DataRadius, PaginateLocalContentInfo, PongInfo, TraceContentInfo, |
| 4 | +}; |
| 5 | +use crate::{NodeId, RoutingTableInfo}; |
| 6 | +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; |
| 7 | +use trin_types::content_key::BeaconContentKey; |
| 8 | +use trin_types::content_value::{BeaconContentValue, PossibleBeaconContentValue}; |
| 9 | +use trin_types::enr::Enr; |
| 10 | + |
| 11 | +/// Portal Beacon JSON-RPC endpoints |
| 12 | +#[rpc(client, server, namespace = "portal")] |
| 13 | +pub trait BeaconNetworkApi { |
| 14 | + /// Returns meta information about overlay routing table. |
| 15 | + #[method(name = "beaconRoutingTableInfo")] |
| 16 | + async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>; |
| 17 | + |
| 18 | + /// Returns the node data radios |
| 19 | + #[method(name = "beaconRadius")] |
| 20 | + async fn radius(&self) -> RpcResult<DataRadius>; |
| 21 | + |
| 22 | + /// Write an Ethereum Node Record to the overlay routing table. |
| 23 | + #[method(name = "beaconAddEnr")] |
| 24 | + async fn add_enr(&self, enr: Enr) -> RpcResult<bool>; |
| 25 | + |
| 26 | + /// Fetch the latest ENR associated with the given node ID. |
| 27 | + #[method(name = "beaconGetEnr")] |
| 28 | + async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>; |
| 29 | + |
| 30 | + /// Delete Node ID from the overlay routing table. |
| 31 | + #[method(name = "beaconDeleteEnr")] |
| 32 | + async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>; |
| 33 | + |
| 34 | + /// Fetch the ENR representation associated with the given Node ID. |
| 35 | + #[method(name = "beaconLookupEnr")] |
| 36 | + async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>; |
| 37 | + |
| 38 | + /// Send a PING message to the designated node and wait for a PONG response |
| 39 | + #[method(name = "beaconPing")] |
| 40 | + async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>; |
| 41 | + |
| 42 | + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the designated |
| 43 | + /// peer and wait for a response |
| 44 | + #[method(name = "beaconFindNodes")] |
| 45 | + async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>; |
| 46 | + |
| 47 | + /// Lookup a target node within in the network |
| 48 | + #[method(name = "beaconRecursiveFindNodes")] |
| 49 | + async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>; |
| 50 | + |
| 51 | + /// Send FINDCONTENT message to get the content with a content key. |
| 52 | + #[method(name = "beaconFindContent")] |
| 53 | + async fn find_content(&self, enr: Enr, content_key: BeaconContentKey) |
| 54 | + -> RpcResult<ContentInfo>; |
| 55 | + |
| 56 | + /// Lookup a target content key in the network |
| 57 | + #[method(name = "beaconRecursiveFindContent")] |
| 58 | + async fn recursive_find_content( |
| 59 | + &self, |
| 60 | + content_key: BeaconContentKey, |
| 61 | + ) -> RpcResult<PossibleBeaconContentValue>; |
| 62 | + |
| 63 | + /// Lookup a target content key in the network. Return tracing info. |
| 64 | + #[method(name = "beaconTraceRecursiveFindContent")] |
| 65 | + async fn trace_recursive_find_content( |
| 66 | + &self, |
| 67 | + content_key: BeaconContentKey, |
| 68 | + ) -> RpcResult<TraceContentInfo>; |
| 69 | + |
| 70 | + /// Pagination of local content keys |
| 71 | + #[method(name = "beaconPaginateLocalContentKeys")] |
| 72 | + async fn paginate_local_content_keys( |
| 73 | + &self, |
| 74 | + offset: u64, |
| 75 | + limit: u64, |
| 76 | + ) -> RpcResult<PaginateLocalContentInfo>; |
| 77 | + |
| 78 | + /// Send the provided content value to interested peers. Clients may choose to send to some or all peers. |
| 79 | + /// Return the number of peers that the content was gossiped to. |
| 80 | + #[method(name = "beaconGossip")] |
| 81 | + async fn gossip( |
| 82 | + &self, |
| 83 | + content_key: BeaconContentKey, |
| 84 | + content_value: BeaconContentValue, |
| 85 | + ) -> RpcResult<u32>; |
| 86 | + |
| 87 | + /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. |
| 88 | + /// Returns the content keys bitlist upon successful content transmission or empty bitlist receive. |
| 89 | + #[method(name = "beaconOffer")] |
| 90 | + async fn offer( |
| 91 | + &self, |
| 92 | + enr: Enr, |
| 93 | + content_key: BeaconContentKey, |
| 94 | + content_value: Option<BeaconContentValue>, |
| 95 | + ) -> RpcResult<AcceptInfo>; |
| 96 | + |
| 97 | + /// Store content key with a content data to the local database. |
| 98 | + #[method(name = "beaconStore")] |
| 99 | + async fn store( |
| 100 | + &self, |
| 101 | + content_key: BeaconContentKey, |
| 102 | + content_value: BeaconContentValue, |
| 103 | + ) -> RpcResult<bool>; |
| 104 | + |
| 105 | + /// Get a content from the local database |
| 106 | + #[method(name = "beaconLocalContent")] |
| 107 | + async fn local_content( |
| 108 | + &self, |
| 109 | + content_key: BeaconContentKey, |
| 110 | + ) -> RpcResult<PossibleBeaconContentValue>; |
| 111 | +} |
0 commit comments