add logs
This commit is contained in:
parent
2adb0ae8b1
commit
a6c8cbf96a
1 changed files with 8 additions and 2 deletions
|
@ -6,7 +6,7 @@ use axum::{extract::State, routing, Json, Router};
|
|||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tracing::debug;
|
||||
use tracing::{trace, debug};
|
||||
|
||||
use super::things::Error;
|
||||
|
||||
|
@ -31,13 +31,16 @@ async fn message(
|
|||
Json(request): Json<Request>,
|
||||
) -> Response<Json<RPCResponse>> {
|
||||
// FIXME (security): hostname must be validated!
|
||||
trace!("receive message from {}", request.contact.host);
|
||||
let response = match request.info {
|
||||
RPCRequest::Ping => {
|
||||
trace!("receive Ping");
|
||||
let mut router = state.p2p.router.lock().await;
|
||||
router.update(request.contact);
|
||||
RPCResponse::Ok
|
||||
}
|
||||
RPCRequest::Announce(node_ids) => {
|
||||
trace!("receive Announce (ids={:?})", node_ids);
|
||||
let mut map = state.p2p.map.lock().await;
|
||||
for node_id in node_ids {
|
||||
map.entry(node_id)
|
||||
|
@ -47,11 +50,13 @@ async fn message(
|
|||
RPCResponse::Ok
|
||||
}
|
||||
RPCRequest::FindNode(node_id) => {
|
||||
trace!("receive FindNode (id={})", node_id);
|
||||
let router = state.p2p.router.lock().await;
|
||||
let contacts = router.find_closest(&node_id, 20);
|
||||
RPCResponse::FindNode(contacts)
|
||||
}
|
||||
RPCRequest::FindValue(node_id) => {
|
||||
trace!("receive FindValue (id={})", node_id);
|
||||
let map = state.p2p.map.lock().await;
|
||||
if let Some(value) = map.get(&node_id) {
|
||||
RPCResponse::FindValue(value.clone())
|
||||
|
@ -61,7 +66,8 @@ async fn message(
|
|||
RPCResponse::FindNode(contacts)
|
||||
}
|
||||
}
|
||||
RPCRequest::Subscribe(_node_id) => {
|
||||
RPCRequest::Subscribe(node_ids) => {
|
||||
trace!("receive Subscribe (id={:?})", node_ids);
|
||||
todo!()
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue