Skip to content

Commit 4a35f55

Browse files
committed
fixup! Add VssService and base service setup.
1 parent 18e605e commit 4a35f55

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

rust/server/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! Hosts VSS http-server implementation.
2+
//!
3+
//! VSS is an open-source project designed to offer a server-side cloud storage solution specifically
4+
//! tailored for noncustodial Lightning supporting mobile wallets. Its primary objective is to
5+
//! simplify the development process for Lightning wallets by providing a secure means to store
6+
//! and manage the essential state required for Lightning Network (LN) operations.
7+
8+
#![deny(rustdoc::broken_intra_doc_links)]
9+
#![deny(rustdoc::private_intra_doc_links)]
10+
#![deny(missing_docs)]
11+
112
use std::net::SocketAddr;
213

314
use tokio::net::TcpListener;

rust/server/src/vss_service.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use http_body_util::{BodyExt, Full};
22
use hyper::body::{Bytes, Incoming};
33
use hyper::service::Service;
4-
use hyper::{Error, Request, Response, StatusCode};
4+
use hyper::{Request, Response, StatusCode};
55
use std::collections::HashMap;
66

77
use prost::Message;
@@ -94,7 +94,6 @@ async fn handle_request<
9494
store: Arc<dyn KvStore>, authorizer: Arc<dyn Authorizer>, request: Request<Incoming>,
9595
handler: F,
9696
) -> Result<<VssService as Service<Request<Incoming>>>::Response, hyper::Error> {
97-
// TODO: we should bound the amount of data we read to avoid allocating too much memory.
9897
let (parts, body) = request.into_parts();
9998
let headers_map = parts
10099
.headers
@@ -104,17 +103,17 @@ async fn handle_request<
104103

105104
let user_token = match authorizer.verify(&headers_map).await {
106105
Ok(auth_response) => auth_response.user_token,
107-
Err(e) => return build_error_response(e),
106+
Err(e) => return Ok(build_error_response(e)),
108107
};
109-
108+
// TODO: we should bound the amount of data we read to avoid allocating too much memory.
110109
let bytes = body.collect().await?.to_bytes();
111110
match T::decode(bytes) {
112111
Ok(request) => match handler(store.clone(), user_token, request).await {
113112
Ok(response) => Ok(Response::builder()
114113
.body(Full::new(Bytes::from(response.encode_to_vec())))
115114
// unwrap safety: body only errors when previous chained calls failed.
116115
.unwrap()),
117-
Err(e) => build_error_response(e),
116+
Err(e) => Ok(build_error_response(e)),
118117
},
119118
Err(_) => Ok(Response::builder()
120119
.status(StatusCode::BAD_REQUEST)
@@ -124,7 +123,7 @@ async fn handle_request<
124123
}
125124
}
126125

127-
fn build_error_response(e: VssError) -> Result<Response<Full<Bytes>>, Error> {
126+
fn build_error_response(e: VssError) -> Response<Full<Bytes>> {
128127
let error_response = match e {
129128
VssError::NoSuchKeyError(msg) => ErrorResponse {
130129
error_code: ErrorCode::NoSuchKeyException.into(),
@@ -146,9 +145,9 @@ fn build_error_response(e: VssError) -> Result<Response<Full<Bytes>>, Error> {
146145
message: "Unknown Server Error occurred.".to_string(),
147146
},
148147
};
149-
Ok(Response::builder()
148+
Response::builder()
150149
.status(StatusCode::INTERNAL_SERVER_ERROR)
151150
.body(Full::new(Bytes::from(error_response.encode_to_vec())))
152151
// unwrap safety: body only errors when previous chained calls failed.
153-
.unwrap())
152+
.unwrap()
154153
}

0 commit comments

Comments
 (0)