Nothing ever works and i want to die

Fortune for datse's current commit: Future blessing − 末吉
simple
Avril 3 years ago
parent e69bb356fb
commit 2cd0f81155
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,11 +1,14 @@
//! Server for datse
use super::*;
use web::ban::BanKind;
/// Configuration for the server.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Config
{
pub trust_x_forwarded_for: bool,
pub static_bans: Vec<BanKind>,
}
impl Config
@ -17,6 +20,7 @@ impl Config
{
Self {
trust_x_forwarded_for: false,
static_bans: Vec::new(),
}
}
}

@ -52,7 +52,7 @@ impl ClientInfo
#[derive(Debug, Clone)]
pub struct Banlist(Arc<RwLock<BTreeSet<BanKind>>>);
type OpaqueFuture<'a, T> = impl Future<Output = T> + 'a;
//type OpaqueFuture<'a, T> = impl Future<Output = T> + 'a;
impl Banlist
{
@ -85,7 +85,8 @@ impl Banlist
///
/// # Lifetime
/// The filter holds a weak reference to this list. If the list is dropped, then the filter will panic.
pub fn filter(&self) -> impl Fn(ClientInfo) -> OpaqueFuture<'static, Result<ClientInfo, warp::reject::Rejection>> + Clone + 'static
//TODO: How do we make this just return `impl Filter`? We need it to take the client_info as param...
pub fn filter(&self) -> impl Fn(ClientInfo) -> futures::future::BoxFuture<'static, Result<ClientInfo, warp::reject::Rejection>> + Clone + 'static
{
let refer = Arc::downgrade(&self.0);
move |client_info: ClientInfo| {
@ -101,7 +102,8 @@ impl Banlist
}
Ok(client_info)
}
}
//XXX: This doesn't seem good
}.boxed()
}
}

@ -45,10 +45,12 @@ fn routing<'a>() -> impl warp::Filter<Error = warp::reject::Rejection> + Clone +
auth.or(push).or(get)
}
pub async fn serve(cfg: impl Into<Config>) -> eyre::Result<()>
pub async fn serve(cfg: Config) -> eyre::Result<()>
{
let cfg = cfg.into();
let bans = ban::Banlist::new();
let bans: ban::Banlist = cfg.static_bans.iter().collect();
//TODO: Create state
// Filter: Extract the client IP from the remote address of the connection of the X-Forwarded-For header if it is trusted in `cfg`.
let client_ip = warp::addr::remote()
.and(warp::header("X-Forwarded-For"))
@ -57,10 +59,15 @@ pub async fn serve(cfg: impl Into<Config>) -> eyre::Result<()>
.and_then(|req: Result<source::ClientInfo, _>| async move { req.map_err(warp::reject::custom) })
// Enforce banlist
.and_then(bans.filter());
//.and_then(|req: source::ClientInfo| async move { Result::<_, std::convert::Infallible>::Ok(req) });
let r = warp::path("api").and(routing());
let filter = warp::path("api")
//how the FUCK do we insert shit into this????????????????????????
.and(routing());
warp::serve(client_ip).bind_with_graceful_shutdown(([127,0,0,1], 8001), tokio::signal::ctrl_c()).await;
Ok(())
}

@ -70,3 +70,11 @@ pub struct ClientInfo
{
pub ip_addr: IpAddr
}
impl fmt::Display for ClientInfo
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "ip: {}", self.ip_addr)
}
}

Loading…
Cancel
Save