mirror of
https://github.com/orbien-org/orbien.git
synced 2026-09-22 00:01:31 +00:00
chore: cargo fmt
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use super::model::{
|
||||
ApiResponse, ClientInfo, Page, TunnelInfo, TunnelTrafficPoint, TunnelTrafficResp, SystemConfig,
|
||||
SystemInfo, SystemStatus,
|
||||
ApiResponse, ClientInfo, Page, SystemConfig, SystemInfo, SystemStatus, TunnelInfo,
|
||||
TunnelTrafficPoint, TunnelTrafficResp,
|
||||
};
|
||||
use super::DashState;
|
||||
use crate::metrics::{TunnelTrafficHistory, TrafficWindow};
|
||||
use crate::metrics::{TrafficWindow, TunnelTrafficHistory};
|
||||
use axum::body::Body;
|
||||
use axum::extract::{Path, Query, State};
|
||||
use axum::http::{header, HeaderMap, HeaderValue, Request, StatusCode};
|
||||
@@ -241,7 +241,11 @@ async fn get_client(
|
||||
) -> Result<Json<ApiResponse<ClientInfo>>, StatusCode> {
|
||||
let session_id = urlencoding_decode(&session_id);
|
||||
let snap = state.svc.dashboard_snapshot().await;
|
||||
match snap.clients.into_iter().find(|c| c.session_id == session_id) {
|
||||
match snap
|
||||
.clients
|
||||
.into_iter()
|
||||
.find(|c| c.session_id == session_id)
|
||||
{
|
||||
Some(c) => Ok(Json(ApiResponse::ok(c))),
|
||||
None => Err(StatusCode::NOT_FOUND),
|
||||
}
|
||||
@@ -305,7 +309,11 @@ async fn tunnel_traffic(
|
||||
Query(q): Query<TrafficQuery>,
|
||||
) -> Result<Json<ApiResponse<TunnelTrafficResp>>, StatusCode> {
|
||||
let name = urlencoding_decode(&name);
|
||||
match state.svc.metrics().tunnel_traffic(&name, traffic_window(&q)) {
|
||||
match state
|
||||
.svc
|
||||
.metrics()
|
||||
.tunnel_traffic(&name, traffic_window(&q))
|
||||
{
|
||||
Some(hist) => Ok(Json(ApiResponse::ok(traffic_resp(hist)))),
|
||||
None => Err(StatusCode::NOT_FOUND),
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,8 +2,8 @@ mod access;
|
||||
mod control;
|
||||
mod dashboard;
|
||||
mod metrics;
|
||||
mod tunnel;
|
||||
mod service;
|
||||
mod tunnel;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
|
||||
@@ -149,7 +149,11 @@ impl MemMetrics {
|
||||
g.tunnels.get(name).map(|p| to_tunnel_snapshot(name, p))
|
||||
}
|
||||
|
||||
pub fn tunnel_traffic(&self, name: &str, window: TrafficWindow) -> Option<TunnelTrafficHistory> {
|
||||
pub fn tunnel_traffic(
|
||||
&self,
|
||||
name: &str,
|
||||
window: TrafficWindow,
|
||||
) -> Option<TunnelTrafficHistory> {
|
||||
let g = self.state.lock().expect("metrics lock");
|
||||
let p = g.tunnels.get(name)?;
|
||||
Some(match window {
|
||||
|
||||
@@ -4,7 +4,7 @@ mod hour_counter;
|
||||
mod mem;
|
||||
mod traits;
|
||||
|
||||
pub use mem::{MemMetrics, TunnelTrafficHistory, TrafficWindow};
|
||||
pub use mem::{MemMetrics, TrafficWindow, TunnelTrafficHistory};
|
||||
pub use traits::ServerMetrics;
|
||||
|
||||
pub const RESERVE_DAYS: usize = 7;
|
||||
|
||||
@@ -73,7 +73,10 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn run_kcp(self: Arc<Self>, mut listener: kcp_tokio::KcpListener) -> Result<()> {
|
||||
pub(super) async fn run_kcp(
|
||||
self: Arc<Self>,
|
||||
mut listener: kcp_tokio::KcpListener,
|
||||
) -> Result<()> {
|
||||
loop {
|
||||
let (stream, peer) = transport::accept_kcp(&mut listener).await?;
|
||||
tracing::debug!(%peer, transport = "kcp", "incoming connection");
|
||||
|
||||
@@ -99,9 +99,7 @@ impl Service {
|
||||
let gw = Arc::clone(gw);
|
||||
let access = Arc::clone(&this.access);
|
||||
let shutdown = Arc::clone(&gw_shutdown);
|
||||
set.spawn(
|
||||
async move { run_http_gw_listener(bind, port, gw, access, shutdown).await },
|
||||
);
|
||||
set.spawn(async move { run_http_gw_listener(bind, port, gw, access, shutdown).await });
|
||||
}
|
||||
|
||||
if let Some(ref gw) = this.https_gw {
|
||||
@@ -110,9 +108,7 @@ impl Service {
|
||||
let gw = Arc::clone(gw);
|
||||
let access = Arc::clone(&this.access);
|
||||
let shutdown = Arc::clone(&gw_shutdown);
|
||||
set.spawn(async move {
|
||||
run_https_gw_listener(bind, port, gw, access, shutdown).await
|
||||
});
|
||||
set.spawn(async move { run_https_gw_listener(bind, port, gw, access, shutdown).await });
|
||||
}
|
||||
|
||||
if this.cfg.quic_enabled() {
|
||||
|
||||
@@ -152,7 +152,10 @@ impl Service {
|
||||
c.push_data_conn(stream).await;
|
||||
Ok(())
|
||||
}
|
||||
None => Err(anyhow!("unknown session_id for data conn: {}", nw.session_id)),
|
||||
None => Err(anyhow!(
|
||||
"unknown session_id for data conn: {}",
|
||||
nw.session_id
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,10 +121,7 @@ pub fn normalize_host(host: &str) -> String {
|
||||
.to_ascii_lowercase()
|
||||
}
|
||||
|
||||
pub fn build_domains(
|
||||
domains: &[String],
|
||||
root_domain: &str,
|
||||
) -> anyhow::Result<Vec<String>> {
|
||||
pub fn build_domains(domains: &[String], root_domain: &str) -> anyhow::Result<Vec<String>> {
|
||||
let root = normalize_host(root_domain);
|
||||
let entries: Vec<String> = domains
|
||||
.iter()
|
||||
|
||||
+15
-16
@@ -1,6 +1,6 @@
|
||||
use super::gw::{
|
||||
build_domains, expand_locations, normalize_host, route_basic_auth_ok, route_user_from_headers,
|
||||
HttpRoute, HttpGw,
|
||||
HttpGw, HttpRoute,
|
||||
};
|
||||
use crate::access::{prepare_ingress, AccessPolicy};
|
||||
use crate::control::Control;
|
||||
@@ -42,21 +42,20 @@ impl HttpTunnel {
|
||||
|
||||
for domain in &domains {
|
||||
for location in &locations {
|
||||
gw
|
||||
.register(
|
||||
domain,
|
||||
HttpRoute {
|
||||
tunnel_name: name.clone(),
|
||||
control: Arc::downgrade(&control),
|
||||
location: location.clone(),
|
||||
host_header_rewrite: rewrite.clone(),
|
||||
basic_auth_user: basic_auth_user.clone(),
|
||||
basic_auth_password: basic_auth_password.clone(),
|
||||
route_by_http_user: route_by_http_user.clone(),
|
||||
limiter: limiter.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
gw.register(
|
||||
domain,
|
||||
HttpRoute {
|
||||
tunnel_name: name.clone(),
|
||||
control: Arc::downgrade(&control),
|
||||
location: location.clone(),
|
||||
host_header_rewrite: rewrite.clone(),
|
||||
basic_auth_user: basic_auth_user.clone(),
|
||||
basic_auth_password: basic_auth_password.clone(),
|
||||
route_by_http_user: route_by_http_user.clone(),
|
||||
limiter: limiter.clone(),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
mod gw;
|
||||
mod http;
|
||||
mod https;
|
||||
mod manager;
|
||||
mod tcp;
|
||||
mod udp;
|
||||
mod gw;
|
||||
|
||||
pub use gw::HttpGw;
|
||||
pub use http::{run_http_gw_listener, HttpTunnel};
|
||||
pub use https::{run_https_gw_listener, HttpsTunnel, HttpsGw};
|
||||
pub use manager::{format_local_addr, TunnelManager, TunnelSummary, RegisteredTunnel};
|
||||
pub use https::{run_https_gw_listener, HttpsGw, HttpsTunnel};
|
||||
pub use manager::{format_local_addr, RegisteredTunnel, TunnelManager, TunnelSummary};
|
||||
pub use tcp::TcpTunnel;
|
||||
pub use udp::UdpTunnel;
|
||||
pub use gw::HttpGw;
|
||||
|
||||
Reference in New Issue
Block a user