mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
ircd: pass rpc_listen_addr to RpcInterface. display rpc_addr in get_info
This commit is contained in:
@@ -82,7 +82,7 @@ async fn process_user_input(
|
||||
) -> Result<()> {
|
||||
if line.is_empty() {
|
||||
warn!("Received empty line from {}. Closing connection.", peer_addr);
|
||||
return Err(Error::ChannelStopped)
|
||||
return Err(Error::ChannelStopped);
|
||||
}
|
||||
assert!(&line[(line.len() - 1)..] == "\n");
|
||||
// Remove the \n character
|
||||
@@ -92,7 +92,7 @@ async fn process_user_input(
|
||||
|
||||
if let Err(err) = connection.update(line, p2p.clone()).await {
|
||||
warn!("Connection error: {} for {}", err, peer_addr);
|
||||
return Err(Error::ChannelStopped)
|
||||
return Err(Error::ChannelStopped);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -103,14 +103,14 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
|
||||
Ok(listener) => listener,
|
||||
Err(err) => {
|
||||
error!("Bind listener failed: {}", err);
|
||||
return Err(Error::OperationFailed)
|
||||
return Err(Error::OperationFailed);
|
||||
}
|
||||
};
|
||||
let local_addr = match listener.get_ref().local_addr() {
|
||||
Ok(addr) => addr,
|
||||
Err(err) => {
|
||||
error!("Failed to get local address: {}", err);
|
||||
return Err(Error::OperationFailed)
|
||||
return Err(Error::OperationFailed);
|
||||
}
|
||||
};
|
||||
info!("Listening on {}", local_addr);
|
||||
@@ -164,7 +164,7 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
|
||||
//
|
||||
let ex2 = executor.clone();
|
||||
let ex3 = ex2.clone();
|
||||
let rpc_interface = Arc::new(JsonRpcInterface {});
|
||||
let rpc_interface = Arc::new(JsonRpcInterface { rpc_listen_addr: options.rpc_listen_addr });
|
||||
executor
|
||||
.spawn(async move { listen_and_serve(server_config, rpc_interface, ex3).await })
|
||||
.detach();
|
||||
@@ -177,7 +177,7 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
|
||||
Ok((s, a)) => (s, a),
|
||||
Err(err) => {
|
||||
error!("Error listening for connections: {}", err);
|
||||
return Err(Error::ServiceStopped)
|
||||
return Err(Error::ServiceStopped);
|
||||
}
|
||||
};
|
||||
info!("Accepted client: {}", peer_addr);
|
||||
@@ -190,13 +190,15 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
|
||||
}
|
||||
}
|
||||
|
||||
struct JsonRpcInterface {}
|
||||
struct JsonRpcInterface {
|
||||
rpc_listen_addr: SocketAddr,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl RequestHandler for JsonRpcInterface {
|
||||
async fn handle_request(&self, req: JsonRequest, _executor: Arc<Executor<'_>>) -> JsonResult {
|
||||
if req.params.as_array().is_none() {
|
||||
return JsonResult::Err(jsonerr(InvalidParams, None, req.id))
|
||||
return JsonResult::Err(jsonerr(InvalidParams, None, req.id));
|
||||
}
|
||||
|
||||
debug!(target: "RPC", "--> {}", serde_json::to_string(&req).unwrap());
|
||||
@@ -219,7 +221,7 @@ impl JsonRpcInterface {
|
||||
// <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
|
||||
async fn get_info(&self, id: Value, _params: Value) -> JsonResult {
|
||||
let resp: serde_json::Value = json!({
|
||||
"id": "127.0.0.1:6688",
|
||||
"id": self.rpc_listen_addr,
|
||||
"connections": {
|
||||
"outgoing": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user