dchat: add p2p.get_info() method to rpc

This commit is contained in:
lunar-mining
2023-12-09 14:53:15 +01:00
parent fb97d433ea
commit 369f894fb7
2 changed files with 12 additions and 3 deletions

View File

@@ -53,7 +53,7 @@ const CONFIG_FILE_CONTENTS: &str = include_str!("../dchat_config.toml");
#[serde(default)]
#[structopt(name = "dchat", about = cli_desc!())]
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_listen: Url,
@@ -130,7 +130,7 @@ async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
// ANCHOR_end: dnet
// 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 rpc_connections = Mutex::new(HashSet::new());
let dchat = Arc::new(Dchat::new(p2p.clone(), msgs.clone(), rpc_connections, dnet_sub));

View File

@@ -18,11 +18,13 @@
use async_trait::async_trait;
use darkfi::system::StoppableTaskPtr;
use darkfi::net::P2pPtr;
use log::debug;
use std::collections::HashSet;
use smol::lock::MutexGuard;
use std::collections::HashSet;
use darkfi::rpc::{
p2p_method::HandlerP2p,
jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResponse, JsonResult},
server::RequestHandler,
util::JsonValue,
@@ -40,6 +42,7 @@ impl RequestHandler for Dchat {
"send" => self.send(req.id, req.params).await,
"recv" => self.recv(req.id).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.subscribe_events" => self.dnet_subscribe_events(req.id, req.params).await,
_ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(),
@@ -114,3 +117,9 @@ impl Dchat {
self.dnet_sub.clone().into()
}
}
impl HandlerP2p for Dchat {
fn p2p(&self) -> P2pPtr {
self.p2p.clone()
}
}