We don't want the debugging to fail, actually.
This commit is contained in:
parent
cf8fd948fc
commit
4a2624b76a
1 changed files with 20 additions and 9 deletions
|
@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use bytes::IntoBuf;
|
use bytes::IntoBuf;
|
||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
|
use futures_util::future::*;
|
||||||
use hyper::server::conn::AddrStream;
|
use hyper::server::conn::AddrStream;
|
||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use hyper::{Body, Method, Request, Response, Server, StatusCode};
|
use hyper::{Body, Method, Request, Response, Server, StatusCode};
|
||||||
|
@ -14,12 +15,16 @@ use crate::error::Error;
|
||||||
use crate::proto::Message;
|
use crate::proto::Message;
|
||||||
use crate::server::Garage;
|
use crate::server::Garage;
|
||||||
|
|
||||||
fn debug_serialize<T: Serialize>(x: T) -> Result<String, Error> {
|
fn debug_serialize<T: Serialize>(x: T) -> String {
|
||||||
let ss = serde_json::to_string(&x)?;
|
match serde_json::to_string(&x) {
|
||||||
|
Ok(ss) => {
|
||||||
if ss.len() > 100 {
|
if ss.len() > 100 {
|
||||||
Ok(ss[..100].to_string())
|
ss[..100].to_string()
|
||||||
} else {
|
} else {
|
||||||
Ok(ss)
|
ss
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => format!("<JSON serialization error: {}>", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,19 +52,22 @@ async fn handler(
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"RPC from {}: {} ({} bytes)",
|
"RPC from {}: {} ({} bytes)",
|
||||||
addr,
|
addr,
|
||||||
debug_serialize(&msg)?,
|
debug_serialize(&msg),
|
||||||
whole_body.len()
|
whole_body.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
let sys = garage.system.clone();
|
let sys = garage.system.clone();
|
||||||
let resp = err_to_msg(match &msg {
|
let resp = err_to_msg(match &msg {
|
||||||
Message::Ping(ping) => sys.handle_ping(&addr, ping).await,
|
Message::Ping(ping) => sys.handle_ping(&addr, ping).await,
|
||||||
|
|
||||||
Message::PullStatus => sys.handle_pull_status().await,
|
Message::PullStatus => sys.handle_pull_status().await,
|
||||||
Message::PullConfig => sys.handle_pull_config().await,
|
Message::PullConfig => sys.handle_pull_config().await,
|
||||||
Message::AdvertiseNodesUp(adv) => sys.handle_advertise_nodes_up(adv).await,
|
Message::AdvertiseNodesUp(adv) => sys.handle_advertise_nodes_up(adv).await,
|
||||||
Message::AdvertiseConfig(adv) => sys.handle_advertise_config(adv).await,
|
Message::AdvertiseConfig(adv) => sys.handle_advertise_config(adv).await,
|
||||||
|
|
||||||
Message::PutBlock(m) => write_block(garage, &m.hash, &m.data).await,
|
Message::PutBlock(m) => write_block(garage, &m.hash, &m.data).await,
|
||||||
Message::GetBlock(h) => read_block(garage, &h).await,
|
Message::GetBlock(h) => read_block(garage, &h).await,
|
||||||
|
|
||||||
Message::TableRPC(table, msg) => {
|
Message::TableRPC(table, msg) => {
|
||||||
if let Some(rpc_handler) = garage.table_rpc_handlers.get(table) {
|
if let Some(rpc_handler) = garage.table_rpc_handlers.get(table) {
|
||||||
rpc_handler
|
rpc_handler
|
||||||
|
@ -74,7 +82,7 @@ async fn handler(
|
||||||
_ => Ok(Message::Error(format!("Unexpected message: {:?}", msg))),
|
_ => Ok(Message::Error(format!("Unexpected message: {:?}", msg))),
|
||||||
});
|
});
|
||||||
|
|
||||||
eprintln!("reply to {}: {}", addr, debug_serialize(&resp)?);
|
eprintln!("reply to {}: {}", addr, debug_serialize(&resp));
|
||||||
|
|
||||||
Ok(Response::new(Body::from(rmp_to_vec_all_named(&resp)?)))
|
Ok(Response::new(Body::from(rmp_to_vec_all_named(&resp)?)))
|
||||||
}
|
}
|
||||||
|
@ -91,7 +99,10 @@ pub async fn run_rpc_server(
|
||||||
async move {
|
async move {
|
||||||
Ok::<_, Error>(service_fn(move |req: Request<Body>| {
|
Ok::<_, Error>(service_fn(move |req: Request<Body>| {
|
||||||
let garage = garage.clone();
|
let garage = garage.clone();
|
||||||
handler(garage, req, client_addr)
|
handler(garage, req, client_addr).map_err(|e| {
|
||||||
|
eprintln!("RPC handler error: {}", e);
|
||||||
|
e
|
||||||
|
})
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue