fud: get_info() added

This commit is contained in:
aggstam
2022-08-22 18:41:45 +03:00
parent c46c4d7cf4
commit f51ec32f69
2 changed files with 11 additions and 1 deletions

View File

@@ -320,6 +320,15 @@ impl Fud {
}
}
}
// RPCAPI:
// Retrieves P2P network information.
// --> {"jsonrpc": "2.0", "method": "get_info", "params": [], "id": 42}
// <-- {"jsonrpc": "2.0", result": {"nodeID": [], "nodeinfo": [], "id": 42}
async fn get_info(&self, id: Value, _params: &[Value]) -> JsonResult {
let resp = self.dht.read().await.p2p.get_info().await;
JsonResponse::new(resp, id).into()
}
}
#[async_trait]
@@ -335,6 +344,7 @@ impl RequestHandler for Fud {
Some("list") => return self.list(req.id, params).await,
Some("sync") => return self.sync(req.id, params).await,
Some("get") => return self.get(req.id, params).await,
Some("get_info") => return self.get_info(req.id, params).await,
Some(_) | None => return JsonError::new(MethodNotFound, None, req.id).into(),
}
}

View File

@@ -41,7 +41,7 @@ pub struct Dht {
/// Network lookup map, containing nodes that holds each key
pub lookup: FxHashMap<blake3::Hash, HashSet<blake3::Hash>>,
/// P2P network pointer
p2p: P2pPtr,
pub p2p: P2pPtr,
/// Channel to receive responses from P2P
p2p_recv_channel: async_channel::Receiver<KeyResponse>,
/// Stop signal channel to terminate background processes