aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-10 23:43:35 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-10 23:43:35 +0200
commit4a2624b76afff714a70ee7a9e4ffd97c54c7ecc4 (patch)
tree5c97b36f01782439f74154ee3f08174e7d1efa28 /src
parentcf8fd948fc4bb6a9f48100ebf89df3752371805d (diff)
downloadgarage-4a2624b76afff714a70ee7a9e4ffd97c54c7ecc4.tar.gz
garage-4a2624b76afff714a70ee7a9e4ffd97c54c7ecc4.zip
We don't want the debugging to fail, actually.
Diffstat (limited to 'src')
-rw-r--r--src/rpc_server.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/rpc_server.rs b/src/rpc_server.rs
index 9eeac5f3..cbcfac79 100644
--- a/src/rpc_server.rs
+++ b/src/rpc_server.rs
@@ -3,6 +3,7 @@ use std::sync::Arc;
use bytes::IntoBuf;
use futures::future::Future;
+use futures_util::future::*;
use hyper::server::conn::AddrStream;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Method, Request, Response, Server, StatusCode};
@@ -14,12 +15,16 @@ use crate::error::Error;
use crate::proto::Message;
use crate::server::Garage;
-fn debug_serialize<T: Serialize>(x: T) -> Result<String, Error> {
- let ss = serde_json::to_string(&x)?;
- if ss.len() > 100 {
- Ok(ss[..100].to_string())
- } else {
- Ok(ss)
+fn debug_serialize<T: Serialize>(x: T) -> String {
+ match serde_json::to_string(&x) {
+ Ok(ss) => {
+ if ss.len() > 100 {
+ ss[..100].to_string()
+ } else {
+ ss
+ }
+ }
+ Err(e) => format!("<JSON serialization error: {}>", e),
}
}
@@ -47,19 +52,22 @@ async fn handler(
eprintln!(
"RPC from {}: {} ({} bytes)",
addr,
- debug_serialize(&msg)?,
+ debug_serialize(&msg),
whole_body.len()
);
let sys = garage.system.clone();
let resp = err_to_msg(match &msg {
Message::Ping(ping) => sys.handle_ping(&addr, ping).await,
+
Message::PullStatus => sys.handle_pull_status().await,
Message::PullConfig => sys.handle_pull_config().await,
Message::AdvertiseNodesUp(adv) => sys.handle_advertise_nodes_up(adv).await,
Message::AdvertiseConfig(adv) => sys.handle_advertise_config(adv).await,
+
Message::PutBlock(m) => write_block(garage, &m.hash, &m.data).await,
Message::GetBlock(h) => read_block(garage, &h).await,
+
Message::TableRPC(table, msg) => {
if let Some(rpc_handler) = garage.table_rpc_handlers.get(table) {
rpc_handler
@@ -74,7 +82,7 @@ async fn handler(
_ => 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)?)))
}
@@ -91,7 +99,10 @@ pub async fn run_rpc_server(
async move {
Ok::<_, Error>(service_fn(move |req: Request<Body>| {
let garage = garage.clone();
- handler(garage, req, client_addr)
+ handler(garage, req, client_addr).map_err(|e| {
+ eprintln!("RPC handler error: {}", e);
+ e
+ })
}))
}
});