mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
dchat: add p2p.get_info() method to rpc
This commit is contained in:
@@ -53,7 +53,7 @@ const CONFIG_FILE_CONTENTS: &str = include_str!("../dchat_config.toml");
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[structopt(name = "dchat", about = cli_desc!())]
|
#[structopt(name = "dchat", about = cli_desc!())]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[structopt(long, default_value = "tcp://127.0.0.1:55054")]
|
#[structopt(long, default_value = "tcp://127.0.0.1:51054")]
|
||||||
/// RPC server listen address
|
/// RPC server listen address
|
||||||
rpc_listen: Url,
|
rpc_listen: Url,
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
|
|||||||
// ANCHOR_end: dnet
|
// ANCHOR_end: dnet
|
||||||
|
|
||||||
// ANCHOR: rpc
|
// ANCHOR: rpc
|
||||||
info!("Starting JSON-RPC server");
|
info!("Starting JSON-RPC server on port {}", args.rpc_listen);
|
||||||
let msgs: DchatMsgsBuffer = Arc::new(Mutex::new(vec![DchatMsg { msg: String::new() }]));
|
let msgs: DchatMsgsBuffer = Arc::new(Mutex::new(vec![DchatMsg { msg: String::new() }]));
|
||||||
let rpc_connections = Mutex::new(HashSet::new());
|
let rpc_connections = Mutex::new(HashSet::new());
|
||||||
let dchat = Arc::new(Dchat::new(p2p.clone(), msgs.clone(), rpc_connections, dnet_sub));
|
let dchat = Arc::new(Dchat::new(p2p.clone(), msgs.clone(), rpc_connections, dnet_sub));
|
||||||
|
|||||||
@@ -18,11 +18,13 @@
|
|||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use darkfi::system::StoppableTaskPtr;
|
use darkfi::system::StoppableTaskPtr;
|
||||||
|
use darkfi::net::P2pPtr;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::collections::HashSet;
|
|
||||||
use smol::lock::MutexGuard;
|
use smol::lock::MutexGuard;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use darkfi::rpc::{
|
use darkfi::rpc::{
|
||||||
|
p2p_method::HandlerP2p,
|
||||||
jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResponse, JsonResult},
|
jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResponse, JsonResult},
|
||||||
server::RequestHandler,
|
server::RequestHandler,
|
||||||
util::JsonValue,
|
util::JsonValue,
|
||||||
@@ -40,6 +42,7 @@ impl RequestHandler for Dchat {
|
|||||||
"send" => self.send(req.id, req.params).await,
|
"send" => self.send(req.id, req.params).await,
|
||||||
"recv" => self.recv(req.id).await,
|
"recv" => self.recv(req.id).await,
|
||||||
"ping" => self.pong(req.id, req.params).await,
|
"ping" => self.pong(req.id, req.params).await,
|
||||||
|
"p2p.get_info" => self.p2p_get_info(req.id, req.params).await,
|
||||||
"dnet.switch" => self.dnet_switch(req.id, req.params).await,
|
"dnet.switch" => self.dnet_switch(req.id, req.params).await,
|
||||||
"dnet.subscribe_events" => self.dnet_subscribe_events(req.id, req.params).await,
|
"dnet.subscribe_events" => self.dnet_subscribe_events(req.id, req.params).await,
|
||||||
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
|
||||||
@@ -114,3 +117,9 @@ impl Dchat {
|
|||||||
self.dnet_sub.clone().into()
|
self.dnet_sub.clone().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HandlerP2p for Dchat {
|
||||||
|
fn p2p(&self) -> P2pPtr {
|
||||||
|
self.p2p.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user