Merge pull request #321 from ethcore/network-rpc-cont-2
JSON RPC - getconnectioncount method
This commit is contained in:
commit
a9c897ec7b
|
@ -13,6 +13,7 @@ pub trait NetworkApi : Send + Sync + 'static {
|
|||
fn connect(&self, socket_addr: SocketAddr);
|
||||
fn node_info(&self, node_addr: IpAddr) -> Result<NodeInfo, p2p::NodeTableError>;
|
||||
fn nodes_info(&self) -> Vec<NodeInfo>;
|
||||
fn connection_count(&self) -> usize;
|
||||
}
|
||||
|
||||
impl<T> NetworkRpc for NetworkClient<T> where T: NetworkApi {
|
||||
|
@ -49,6 +50,10 @@ impl<T> NetworkRpc for NetworkClient<T> where T: NetworkApi {
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn connection_count(&self) -> Result<usize, Error> {
|
||||
Ok(self.api.connection_count())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NetworkClient<T: NetworkApi> {
|
||||
|
@ -120,4 +125,8 @@ impl NetworkApi for NetworkClientCore {
|
|||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn connection_count(&self) -> usize {
|
||||
self.p2p.connections().count()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,5 +16,9 @@ build_rpc_trait! {
|
|||
/// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "id":"1", "method": "getaddednodeinfo", "params": [true, "192.168.0.201"] }' -H 'content-type: application/json;' http://127.0.0.1:8332/
|
||||
#[rpc(name = "getaddednodeinfo")]
|
||||
fn node_info(&self, bool, Trailing<String>) -> Result<Vec<NodeInfo>, Error>;
|
||||
/// Query node(s) info
|
||||
/// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "id":"1", "method": "getconnectioncount", "params": [] }' -H 'content-type: application/json;' http://127.0.0.1:8332/
|
||||
#[rpc(name = "getconnectioncount")]
|
||||
fn connection_count(&self) -> Result<usize, Error>;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue