remove lib.rs
in binaries
This commit is contained in:
parent
e2a704408b
commit
8274dae7c3
@ -1,5 +1,5 @@
|
|||||||
use super::Connection;
|
use super::Connection;
|
||||||
use crate::{utils::UdpRelayMode, Error};
|
use crate::{error::Error, utils::UdpRelayMode};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use quinn::{RecvStream, SendStream, VarInt};
|
use quinn::{RecvStream, SendStream, VarInt};
|
||||||
use register_count::Register;
|
use register_count::Register;
|
||||||
@ -7,7 +7,7 @@ use std::sync::atomic::Ordering;
|
|||||||
use tuic_quinn::Task;
|
use tuic_quinn::Task;
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub(super) async fn accept_uni_stream(&self) -> Result<(RecvStream, Register), Error> {
|
pub async fn accept_uni_stream(&self) -> Result<(RecvStream, Register), Error> {
|
||||||
let max = self.max_concurrent_uni_streams.load(Ordering::Relaxed);
|
let max = self.max_concurrent_uni_streams.load(Ordering::Relaxed);
|
||||||
|
|
||||||
if self.remote_uni_stream_cnt.count() as u32 == max {
|
if self.remote_uni_stream_cnt.count() as u32 == max {
|
||||||
@ -23,9 +23,7 @@ impl Connection {
|
|||||||
Ok((recv, reg))
|
Ok((recv, reg))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn accept_bi_stream(
|
pub async fn accept_bi_stream(&self) -> Result<(SendStream, RecvStream, Register), Error> {
|
||||||
&self,
|
|
||||||
) -> Result<(SendStream, RecvStream, Register), Error> {
|
|
||||||
let max = self.max_concurrent_bi_streams.load(Ordering::Relaxed);
|
let max = self.max_concurrent_bi_streams.load(Ordering::Relaxed);
|
||||||
|
|
||||||
if self.remote_bi_stream_cnt.count() as u32 == max {
|
if self.remote_bi_stream_cnt.count() as u32 == max {
|
||||||
@ -41,11 +39,11 @@ impl Connection {
|
|||||||
Ok((send, recv, reg))
|
Ok((send, recv, reg))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn accept_datagram(&self) -> Result<Bytes, Error> {
|
pub async fn accept_datagram(&self) -> Result<Bytes, Error> {
|
||||||
Ok(self.conn.read_datagram().await?)
|
Ok(self.conn.read_datagram().await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
|
pub async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
|
||||||
log::debug!("[relay] incoming unidirectional stream");
|
log::debug!("[relay] incoming unidirectional stream");
|
||||||
|
|
||||||
let res = match self.model.accept_uni_stream(recv).await {
|
let res = match self.model.accept_uni_stream(recv).await {
|
||||||
@ -65,7 +63,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_bi_stream(self, send: SendStream, recv: RecvStream, _reg: Register) {
|
pub async fn handle_bi_stream(self, send: SendStream, recv: RecvStream, _reg: Register) {
|
||||||
log::debug!("[relay] incoming bidirectional stream");
|
log::debug!("[relay] incoming bidirectional stream");
|
||||||
|
|
||||||
let res = match self.model.accept_bi_stream(send, recv).await {
|
let res = match self.model.accept_bi_stream(send, recv).await {
|
||||||
@ -78,7 +76,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_datagram(self, dg: Bytes) {
|
pub async fn handle_datagram(self, dg: Bytes) {
|
||||||
log::debug!("[relay] incoming datagram");
|
log::debug!("[relay] incoming datagram");
|
||||||
|
|
||||||
let res = match self.model.accept_datagram(dg) {
|
let res = match self.model.accept_datagram(dg) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::Connection;
|
use super::Connection;
|
||||||
use crate::{socks5::UDP_SESSIONS as SOCKS5_UDP_SESSIONS, utils::UdpRelayMode, Error};
|
use crate::{error::Error, socks5::UDP_SESSIONS as SOCKS5_UDP_SESSIONS, utils::UdpRelayMode};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use socks5_proto::Address as Socks5Address;
|
use socks5_proto::Address as Socks5Address;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -8,7 +8,7 @@ use tuic::Address;
|
|||||||
use tuic_quinn::{Connect, Packet};
|
use tuic_quinn::{Connect, Packet};
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub(super) async fn authenticate(self) {
|
pub async fn authenticate(self) {
|
||||||
log::debug!("[relay] [authenticate] sending authentication");
|
log::debug!("[relay] [authenticate] sending authentication");
|
||||||
|
|
||||||
match self
|
match self
|
||||||
@ -74,7 +74,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn heartbeat(self, heartbeat: Duration) {
|
pub async fn heartbeat(self, heartbeat: Duration) {
|
||||||
loop {
|
loop {
|
||||||
time::sleep(heartbeat).await;
|
time::sleep(heartbeat).await;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_packet(pkt: Packet) {
|
pub async fn handle_packet(pkt: Packet) {
|
||||||
let assoc_id = pkt.assoc_id();
|
let assoc_id = pkt.assoc_id();
|
||||||
let pkt_id = pkt.pkt_id();
|
let pkt_id = pkt.pkt_id();
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::Relay,
|
config::Relay,
|
||||||
|
error::Error,
|
||||||
utils::{self, CongestionControl, ServerAddr, UdpRelayMode},
|
utils::{self, CongestionControl, ServerAddr, UdpRelayMode},
|
||||||
Error,
|
|
||||||
};
|
};
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
@ -32,7 +32,7 @@ static ENDPOINT: OnceCell<Mutex<Endpoint>> = OnceCell::new();
|
|||||||
static CONNECTION: AsyncOnceCell<AsyncMutex<Connection>> = AsyncOnceCell::const_new();
|
static CONNECTION: AsyncOnceCell<AsyncMutex<Connection>> = AsyncOnceCell::const_new();
|
||||||
static TIMEOUT: AtomicCell<Duration> = AtomicCell::new(Duration::from_secs(0));
|
static TIMEOUT: AtomicCell<Duration> = AtomicCell::new(Duration::from_secs(0));
|
||||||
|
|
||||||
pub(crate) const ERROR_CODE: VarInt = VarInt::from_u32(0);
|
pub const ERROR_CODE: VarInt = VarInt::from_u32(0);
|
||||||
const DEFAULT_CONCURRENT_STREAMS: u32 = 32;
|
const DEFAULT_CONCURRENT_STREAMS: u32 = 32;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
mod config;
|
|
||||||
mod connection;
|
|
||||||
mod error;
|
|
||||||
mod socks5;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
pub use crate::{
|
|
||||||
config::{Config, ConfigError},
|
|
||||||
connection::Connection,
|
|
||||||
error::Error,
|
|
||||||
socks5::Server as Socks5Server,
|
|
||||||
utils::{CongestionControl, ServerAddr, UdpRelayMode},
|
|
||||||
};
|
|
@ -1,6 +1,16 @@
|
|||||||
|
use crate::{
|
||||||
|
config::{Config, ConfigError},
|
||||||
|
connection::Connection,
|
||||||
|
socks5::Server as Socks5Server,
|
||||||
|
};
|
||||||
use env_logger::Builder as LoggerBuilder;
|
use env_logger::Builder as LoggerBuilder;
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
use tuic_client::{Config, ConfigError, Connection, Socks5Server};
|
|
||||||
|
mod config;
|
||||||
|
mod connection;
|
||||||
|
mod error;
|
||||||
|
mod socks5;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -10,7 +10,7 @@ use tokio_util::compat::FuturesAsyncReadCompatExt;
|
|||||||
use tuic::Address as TuicAddress;
|
use tuic::Address as TuicAddress;
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub(super) async fn handle_associate(
|
pub async fn handle_associate(
|
||||||
assoc: Associate<associate::NeedReply>,
|
assoc: Associate<associate::NeedReply>,
|
||||||
assoc_id: u16,
|
assoc_id: u16,
|
||||||
dual_stack: Option<bool>,
|
dual_stack: Option<bool>,
|
||||||
@ -127,7 +127,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_bind(bind: Bind<bind::NeedFirstReply>) {
|
pub async fn handle_bind(bind: Bind<bind::NeedFirstReply>) {
|
||||||
let peer_addr = bind.peer_addr().unwrap();
|
let peer_addr = bind.peer_addr().unwrap();
|
||||||
log::warn!("[socks5] [{peer_addr}] [bind] command not supported");
|
log::warn!("[socks5] [{peer_addr}] [bind] command not supported");
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_connect(conn: Connect<connect::NeedReply>, addr: Address) {
|
pub async fn handle_connect(conn: Connect<connect::NeedReply>, addr: Address) {
|
||||||
let peer_addr = conn.peer_addr().unwrap();
|
let peer_addr = conn.peer_addr().unwrap();
|
||||||
let target_addr = match addr {
|
let target_addr = match addr {
|
||||||
Address::DomainAddress(domain, port) => TuicAddress::DomainAddress(domain, port),
|
Address::DomainAddress(domain, port) => TuicAddress::DomainAddress(domain, port),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{config::Local, Error};
|
use crate::{config::Local, error::Error};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
|
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
|
||||||
@ -19,7 +19,7 @@ use tokio::net::TcpListener;
|
|||||||
mod handle_task;
|
mod handle_task;
|
||||||
mod udp_session;
|
mod udp_session;
|
||||||
|
|
||||||
pub(crate) use self::udp_session::UDP_SESSIONS;
|
pub use self::udp_session::UDP_SESSIONS;
|
||||||
|
|
||||||
static SERVER: OnceCell<Server> = OnceCell::new();
|
static SERVER: OnceCell<Server> = OnceCell::new();
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::Error;
|
use crate::error::Error;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@ -13,17 +13,17 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
pub(crate) static UDP_SESSIONS: OnceCell<Mutex<HashMap<u16, UdpSession>>> = OnceCell::new();
|
pub static UDP_SESSIONS: OnceCell<Mutex<HashMap<u16, UdpSession>>> = OnceCell::new();
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct UdpSession {
|
pub struct UdpSession {
|
||||||
socket: Arc<AssociatedUdpSocket>,
|
socket: Arc<AssociatedUdpSocket>,
|
||||||
assoc_id: u16,
|
assoc_id: u16,
|
||||||
ctrl_addr: SocketAddr,
|
ctrl_addr: SocketAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UdpSession {
|
impl UdpSession {
|
||||||
pub(super) fn new(
|
pub fn new(
|
||||||
assoc_id: u16,
|
assoc_id: u16,
|
||||||
ctrl_addr: SocketAddr,
|
ctrl_addr: SocketAddr,
|
||||||
local_ip: IpAddr,
|
local_ip: IpAddr,
|
||||||
@ -72,7 +72,7 @@ impl UdpSession {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn send(&self, pkt: Bytes, src_addr: Address) -> Result<(), Error> {
|
pub async fn send(&self, pkt: Bytes, src_addr: Address) -> Result<(), Error> {
|
||||||
let src_addr_display = src_addr.to_string();
|
let src_addr_display = src_addr.to_string();
|
||||||
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
@ -96,7 +96,7 @@ impl UdpSession {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn recv(&self) -> Result<(Bytes, Address), Error> {
|
pub async fn recv(&self) -> Result<(Bytes, Address), Error> {
|
||||||
let (pkt, frag, dst_addr, src_addr) = self.socket.recv_from().await?;
|
let (pkt, frag, dst_addr, src_addr) = self.socket.recv_from().await?;
|
||||||
|
|
||||||
if let Ok(connected_addr) = self.socket.peer_addr() {
|
if let Ok(connected_addr) = self.socket.peer_addr() {
|
||||||
@ -126,7 +126,7 @@ impl UdpSession {
|
|||||||
Ok((pkt, dst_addr))
|
Ok((pkt, dst_addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn local_addr(&self) -> Result<SocketAddr, IoError> {
|
pub fn local_addr(&self) -> Result<SocketAddr, IoError> {
|
||||||
self.socket.local_addr()
|
self.socket.local_addr()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::Error;
|
use crate::error::Error;
|
||||||
use rustls::{Certificate, RootCertStore};
|
use rustls::{Certificate, RootCertStore};
|
||||||
use rustls_pemfile::Item;
|
use rustls_pemfile::Item;
|
||||||
use std::{
|
use std::{
|
||||||
@ -10,10 +10,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tokio::net;
|
use tokio::net;
|
||||||
|
|
||||||
pub(crate) fn load_certs(
|
pub fn load_certs(paths: Vec<PathBuf>, disable_native: bool) -> Result<RootCertStore, Error> {
|
||||||
paths: Vec<PathBuf>,
|
|
||||||
disable_native: bool,
|
|
||||||
) -> Result<RootCertStore, Error> {
|
|
||||||
let mut certs = RootCertStore::empty();
|
let mut certs = RootCertStore::empty();
|
||||||
|
|
||||||
for path in &paths {
|
for path in &paths {
|
||||||
|
@ -10,7 +10,7 @@ use std::{
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) struct Authenticated(Arc<AuthenticatedInner>);
|
pub struct Authenticated(Arc<AuthenticatedInner>);
|
||||||
|
|
||||||
struct AuthenticatedInner {
|
struct AuthenticatedInner {
|
||||||
uuid: AtomicCell<Option<Uuid>>,
|
uuid: AtomicCell<Option<Uuid>>,
|
||||||
@ -18,14 +18,14 @@ struct AuthenticatedInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Authenticated {
|
impl Authenticated {
|
||||||
pub(super) fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(Arc::new(AuthenticatedInner {
|
Self(Arc::new(AuthenticatedInner {
|
||||||
uuid: AtomicCell::new(None),
|
uuid: AtomicCell::new(None),
|
||||||
broadcast: Mutex::new(Vec::new()),
|
broadcast: Mutex::new(Vec::new()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn set(&self, uuid: Uuid) {
|
pub fn set(&self, uuid: Uuid) {
|
||||||
self.0.uuid.store(Some(uuid));
|
self.0.uuid.store(Some(uuid));
|
||||||
|
|
||||||
for waker in self.0.broadcast.lock().drain(..) {
|
for waker in self.0.broadcast.lock().drain(..) {
|
||||||
@ -33,7 +33,7 @@ impl Authenticated {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get(&self) -> Option<Uuid> {
|
pub fn get(&self) -> Option<Uuid> {
|
||||||
self.0.uuid.load()
|
self.0.uuid.load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::Connection;
|
use super::Connection;
|
||||||
use crate::{Error, UdpRelayMode};
|
use crate::{error::Error, utils::UdpRelayMode};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use quinn::{RecvStream, SendStream, VarInt};
|
use quinn::{RecvStream, SendStream, VarInt};
|
||||||
use register_count::Register;
|
use register_count::Register;
|
||||||
@ -8,7 +8,7 @@ use tokio::time;
|
|||||||
use tuic_quinn::Task;
|
use tuic_quinn::Task;
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub(crate) async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
|
pub async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] incoming unidirectional stream",
|
"[{id:#010x}] [{addr}] [{user}] incoming unidirectional stream",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
@ -69,11 +69,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn handle_bi_stream(
|
pub async fn handle_bi_stream(self, (send, recv): (SendStream, RecvStream), _reg: Register) {
|
||||||
self,
|
|
||||||
(send, recv): (SendStream, RecvStream),
|
|
||||||
_reg: Register,
|
|
||||||
) {
|
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] incoming bidirectional stream",
|
"[{id:#010x}] [{addr}] [{user}] incoming bidirectional stream",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
@ -122,7 +118,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn handle_datagram(self, dg: Bytes) {
|
pub async fn handle_datagram(self, dg: Bytes) {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] incoming datagram",
|
"[{id:#010x}] [{addr}] [{user}] incoming datagram",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::{UdpSession, ERROR_CODE};
|
use super::{Connection, UdpSession, ERROR_CODE};
|
||||||
use crate::{Connection, Error, UdpRelayMode};
|
use crate::{error::Error, utils::UdpRelayMode};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use std::{
|
use std::{
|
||||||
collections::hash_map::Entry,
|
collections::hash_map::Entry,
|
||||||
@ -15,7 +15,7 @@ use tuic::Address;
|
|||||||
use tuic_quinn::{Authenticate, Connect, Packet};
|
use tuic_quinn::{Authenticate, Connect, Packet};
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub(super) async fn handle_authenticate(&self, auth: Authenticate) {
|
pub async fn handle_authenticate(&self, auth: Authenticate) {
|
||||||
log::info!(
|
log::info!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] [authenticate] {auth_uuid}",
|
"[{id:#010x}] [{addr}] [{user}] [authenticate] {auth_uuid}",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
@ -25,7 +25,7 @@ impl Connection {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_connect(&self, conn: Connect) {
|
pub async fn handle_connect(&self, conn: Connect) {
|
||||||
let target_addr = conn.addr().to_string();
|
let target_addr = conn.addr().to_string();
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
@ -79,7 +79,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_packet(&self, pkt: Packet, mode: UdpRelayMode) {
|
pub async fn handle_packet(&self, pkt: Packet, mode: UdpRelayMode) {
|
||||||
let assoc_id = pkt.assoc_id();
|
let assoc_id = pkt.assoc_id();
|
||||||
let pkt_id = pkt.pkt_id();
|
let pkt_id = pkt.pkt_id();
|
||||||
let frag_id = pkt.frag_id();
|
let frag_id = pkt.frag_id();
|
||||||
@ -151,7 +151,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_dissociate(&self, assoc_id: u16) {
|
pub async fn handle_dissociate(&self, assoc_id: u16) {
|
||||||
log::info!(
|
log::info!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] [dissociate] [{assoc_id:#06x}]",
|
"[{id:#010x}] [{addr}] [{user}] [dissociate] [{assoc_id:#06x}]",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
@ -164,7 +164,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn handle_heartbeat(&self) {
|
pub async fn handle_heartbeat(&self) {
|
||||||
log::info!(
|
log::info!(
|
||||||
"[{id:#010x}] [{addr}] [{user}] [heartbeat]",
|
"[{id:#010x}] [{addr}] [{user}] [heartbeat]",
|
||||||
id = self.id(),
|
id = self.id(),
|
||||||
@ -173,7 +173,7 @@ impl Connection {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn relay_packet(self, pkt: Bytes, addr: Address, assoc_id: u16) {
|
pub async fn relay_packet(self, pkt: Bytes, addr: Address, assoc_id: u16) {
|
||||||
let addr_display = addr.to_string();
|
let addr_display = addr.to_string();
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use self::{authenticated::Authenticated, udp_session::UdpSession};
|
use self::{authenticated::Authenticated, udp_session::UdpSession};
|
||||||
use crate::{Error, UdpRelayMode};
|
use crate::{error::Error, utils::UdpRelayMode};
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use quinn::{Connecting, Connection as QuinnConnection, VarInt};
|
use quinn::{Connecting, Connection as QuinnConnection, VarInt};
|
||||||
@ -18,8 +18,8 @@ mod handle_stream;
|
|||||||
mod handle_task;
|
mod handle_task;
|
||||||
mod udp_session;
|
mod udp_session;
|
||||||
|
|
||||||
pub(crate) const ERROR_CODE: VarInt = VarInt::from_u32(0);
|
pub const ERROR_CODE: VarInt = VarInt::from_u32(0);
|
||||||
pub(crate) const DEFAULT_CONCURRENT_STREAMS: u32 = 32;
|
pub const DEFAULT_CONCURRENT_STREAMS: u32 = 32;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::{Connection, Error};
|
use super::Connection;
|
||||||
|
use crate::error::Error;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
|
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
|
||||||
@ -14,7 +15,7 @@ use tokio::{
|
|||||||
use tuic::Address;
|
use tuic::Address;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(super) struct UdpSession(Arc<UdpSessionInner>);
|
pub struct UdpSession(Arc<UdpSessionInner>);
|
||||||
|
|
||||||
struct UdpSessionInner {
|
struct UdpSessionInner {
|
||||||
assoc_id: u16,
|
assoc_id: u16,
|
||||||
@ -26,7 +27,7 @@ struct UdpSessionInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UdpSession {
|
impl UdpSession {
|
||||||
pub(super) fn new(
|
pub fn new(
|
||||||
conn: Connection,
|
conn: Connection,
|
||||||
assoc_id: u16,
|
assoc_id: u16,
|
||||||
udp_relay_ipv6: bool,
|
udp_relay_ipv6: bool,
|
||||||
@ -125,7 +126,7 @@ impl UdpSession {
|
|||||||
Ok(session)
|
Ok(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn send(&self, pkt: Bytes, addr: SocketAddr) -> Result<(), Error> {
|
pub async fn send(&self, pkt: Bytes, addr: SocketAddr) -> Result<(), Error> {
|
||||||
let socket = match addr {
|
let socket = match addr {
|
||||||
SocketAddr::V4(_) => &self.0.socket_v4,
|
SocketAddr::V4(_) => &self.0.socket_v4,
|
||||||
SocketAddr::V6(_) => self
|
SocketAddr::V6(_) => self
|
||||||
@ -160,7 +161,7 @@ impl UdpSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn close(&self) {
|
pub fn close(&self) {
|
||||||
let _ = self.0.close.lock().take().unwrap().send(());
|
let _ = self.0.close.lock().take().unwrap().send(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ pub enum Error {
|
|||||||
Model(#[from] ModelError),
|
Model(#[from] ModelError),
|
||||||
#[error("duplicated authentication")]
|
#[error("duplicated authentication")]
|
||||||
DuplicatedAuth,
|
DuplicatedAuth,
|
||||||
#[error("token length too short")]
|
|
||||||
ExportKeyingMaterial,
|
|
||||||
#[error("authentication failed: {0}")]
|
#[error("authentication failed: {0}")]
|
||||||
AuthFailed(Uuid),
|
AuthFailed(Uuid),
|
||||||
#[error("received packet from unexpected source")]
|
#[error("received packet from unexpected source")]
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
mod config;
|
|
||||||
mod connection;
|
|
||||||
mod error;
|
|
||||||
mod server;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
pub use crate::{
|
|
||||||
config::{Config, ConfigError},
|
|
||||||
connection::Connection,
|
|
||||||
error::Error,
|
|
||||||
server::Server,
|
|
||||||
utils::{CongestionControl, UdpRelayMode},
|
|
||||||
};
|
|
@ -1,6 +1,15 @@
|
|||||||
|
use crate::{
|
||||||
|
config::{Config, ConfigError},
|
||||||
|
server::Server,
|
||||||
|
};
|
||||||
use env_logger::Builder as LoggerBuilder;
|
use env_logger::Builder as LoggerBuilder;
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
use tuic_server::{Config, ConfigError, Server};
|
|
||||||
|
mod config;
|
||||||
|
mod connection;
|
||||||
|
mod error;
|
||||||
|
mod server;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::Config, connection::DEFAULT_CONCURRENT_STREAMS, utils, CongestionControl, Connection,
|
config::Config,
|
||||||
Error,
|
connection::{Connection, DEFAULT_CONCURRENT_STREAMS},
|
||||||
|
error::Error,
|
||||||
|
utils::{self, CongestionControl},
|
||||||
};
|
};
|
||||||
use quinn::{
|
use quinn::{
|
||||||
congestion::{BbrConfig, CubicConfig, NewRenoConfig},
|
congestion::{BbrConfig, CubicConfig, NewRenoConfig},
|
||||||
|
@ -8,7 +8,7 @@ use std::{
|
|||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn load_certs(path: PathBuf) -> Result<Vec<Certificate>, IoError> {
|
pub fn load_certs(path: PathBuf) -> Result<Vec<Certificate>, IoError> {
|
||||||
let mut file = BufReader::new(File::open(&path)?);
|
let mut file = BufReader::new(File::open(&path)?);
|
||||||
let mut certs = Vec::new();
|
let mut certs = Vec::new();
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ pub(crate) fn load_certs(path: PathBuf) -> Result<Vec<Certificate>, IoError> {
|
|||||||
Ok(certs)
|
Ok(certs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_priv_key(path: PathBuf) -> Result<PrivateKey, IoError> {
|
pub fn load_priv_key(path: PathBuf) -> Result<PrivateKey, IoError> {
|
||||||
let mut file = BufReader::new(File::open(&path)?);
|
let mut file = BufReader::new(File::open(&path)?);
|
||||||
let mut priv_key = None;
|
let mut priv_key = None;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user