diff --git a/src/db.rs b/src/db.rs index 3fa8d5d..e0eb17d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,8 @@ use std::{error::Error, net::IpAddr}; +use json::JsonValue; use log::warn; -use tokio_postgres::{Client, Row}; +use tokio_postgres::{Client, Row, Statement}; const ENDPOINT_TABLE: &str = "endpoints"; const HOSTS_RELATION_TABLE: &str = "hosts"; diff --git a/src/health.rs b/src/health.rs index 82fc7eb..83cfbc3 100644 --- a/src/health.rs +++ b/src/health.rs @@ -26,7 +26,7 @@ pub async fn check(db: &mut BoxyDatabase) { continue; } }; - + let io = TokioIo::new(stream); let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await.unwrap(); diff --git a/src/main.rs b/src/main.rs index 42b6a58..671a19f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,11 +16,11 @@ use matchers::api::ApiMatcher; use server::Server; use services::{ controller::ControllerService, - matcher::Matcher, + matcher::{Matcher, MatcherService}, }; use tokio::{ sync::Mutex, - time::{self}, + time::{self, interval}, }; use tokio_postgres::NoTls; diff --git a/src/matchers/api.rs b/src/matchers/api.rs index da62e4b..c8c108a 100644 --- a/src/matchers/api.rs +++ b/src/matchers/api.rs @@ -1,11 +1,13 @@ -use std::{net::IpAddr, sync::Arc}; +use std::{net::IpAddr, pin::Pin, sync::Arc}; use async_trait::async_trait; use base64::{Engine, prelude::BASE64_STANDARD}; +use http::request::Parts; use http_body_util::BodyExt; use hyper::{ - Request, StatusCode, - body::Incoming, + Method, Request, StatusCode, + body::{self, Incoming}, + service::Service, }; use json::JsonValue; use log::{debug, error, warn}; @@ -13,10 +15,10 @@ use tokio::{net::TcpStream, sync::Mutex}; use crate::{ config::{Client, Config}, - db::BoxyDatabase, + db::{BoxyDatabase, Endpoint}, routes::api::{AddHost, RegisterEndpoint, RemoveHost}, - server::{GeneralResponse, custom_resp}, - services::matcher::Matcher, + server::{GeneralResponse, TcpIntercept, custom_resp, default_response, json_to_vec}, + services::matcher::{Matcher, MatcherService}, }; #[derive(Debug, Clone)] diff --git a/src/routes/api.rs b/src/routes/api.rs index 8461fb4..d137093 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -1,9 +1,12 @@ use async_trait::async_trait; +use base64::{Engine, prelude::BASE64_STANDARD}; use http::request::Parts; +use http_body_util::BodyExt; use hyper::{Method, StatusCode}; -use log::error; +use log::{debug, error, warn}; use crate::{ + config::Client, db::Endpoint, matchers::api::ApiMatcher, server::{custom_resp, json_to_vec}, diff --git a/src/services.rs b/src/services.rs index a2b6a6c..381d0dc 100644 --- a/src/services.rs +++ b/src/services.rs @@ -1,3 +1,3 @@ pub mod controller; -pub mod matcher; pub mod proxy; +pub mod matcher; diff --git a/src/services/matcher.rs b/src/services/matcher.rs index 3618f93..fbcb074 100644 --- a/src/services/matcher.rs +++ b/src/services/matcher.rs @@ -1,11 +1,22 @@ -use std::{pin::Pin, sync::Arc}; +use std::{net::IpAddr, pin::Pin, sync::Arc}; use async_trait::async_trait; +use base64::{Engine, prelude::BASE64_STANDARD}; use http::request::Parts; -use hyper::{Request, StatusCode, body::Incoming, service::Service}; -use tokio::net::TcpStream; +use http_body_util::BodyExt; +use hyper::{ + Method, Request, StatusCode, + body::{self, Incoming}, + service::Service, +}; +use log::{debug, error, warn}; +use tokio::{net::TcpStream, sync::Mutex}; -use crate::server::{GeneralResponse, TcpIntercept, custom_resp, default_response}; +use crate::{ + config::{Client, Config}, + db::{BoxyDatabase, Endpoint}, + server::{GeneralResponse, TcpIntercept, custom_resp, default_response, json_to_vec}, +}; // The routes itself #[async_trait] @@ -36,11 +47,9 @@ pub trait Matcher: Clone + Send + Sync + 'static { } // Do something with TCP stream - #[allow(unused_variables)] fn stream(&mut self, stream: &TcpStream) {} // Body parser - made universal for api server cause lazy - #[allow(unused_variables)] async fn body(&mut self, body: Incoming) -> Option> { None }