2021-03-25 00:56:16 +01:00
|
|
|
use warp::{reply::Reply, reply::Response, Filter, Rejection};
|
2021-03-10 03:08:34 +01:00
|
|
|
|
2021-03-15 03:39:25 +01:00
|
|
|
use super::errors;
|
2021-03-12 08:55:37 +01:00
|
|
|
use super::onion_requests;
|
2021-03-10 03:08:34 +01:00
|
|
|
|
2021-03-16 01:10:22 +01:00
|
|
|
/// GET /
|
|
|
|
pub fn root() -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
|
2021-03-25 00:56:16 +01:00
|
|
|
return warp::get().and(warp::path::end()).and_then(root_html);
|
2021-03-16 01:10:22 +01:00
|
|
|
}
|
|
|
|
|
2021-03-11 06:20:49 +01:00
|
|
|
/// POST /loki/v3/lsrpc
|
2021-03-18 05:04:56 +01:00
|
|
|
pub fn lsrpc() -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
|
2021-03-11 06:20:49 +01:00
|
|
|
return warp::post()
|
2021-03-25 00:56:16 +01:00
|
|
|
.and(warp::path("loki"))
|
|
|
|
.and(warp::path("v3"))
|
|
|
|
.and(warp::path("lsrpc"))
|
2021-03-11 06:20:49 +01:00
|
|
|
.and(warp::body::content_length_limit(10 * 1024 * 1024)) // Match storage server
|
|
|
|
.and(warp::body::bytes()) // Expect bytes
|
2021-03-12 08:55:37 +01:00
|
|
|
.and_then(onion_requests::handle_onion_request)
|
2021-03-15 03:39:25 +01:00
|
|
|
// It's possible for an error to occur before we have the symmetric key needed
|
|
|
|
// to encrypt the response. In this scenario we still want to return a useful
|
|
|
|
// status code to the receiving Service Node.
|
|
|
|
.recover(into_response);
|
2021-03-11 06:20:49 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 01:10:22 +01:00
|
|
|
pub async fn root_html() -> Result<Response, Rejection> {
|
|
|
|
let body = r#"
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Root</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
2021-03-16 04:33:55 +01:00
|
|
|
This is a Session open group server.
|
2021-03-16 01:10:22 +01:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"#;
|
|
|
|
return Ok(warp::reply::html(body).into_response());
|
|
|
|
}
|
|
|
|
|
2021-03-15 03:39:25 +01:00
|
|
|
pub async fn into_response(e: Rejection) -> Result<Response, Rejection> {
|
|
|
|
return errors::into_response(e);
|
2021-03-25 00:56:16 +01:00
|
|
|
}
|