mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 16:02:32 +00:00
Fix MPTP UDP inbound
This commit is contained in:
1 parent
50d0be1806
commit
fa8999181e
7 files changed
+24
-29
No files matched your search
+3
-3
@@ -121,13 +121,13 @@ outbound-failover = ["lru_time_cache"]
|
||||
outbound-static= []
|
||||
outbound-tryall = []
|
||||
outbound-chain = []
|
||||
outbound-vless = ["uuid", "hex"]
|
||||
outbound-vless = ["hex"]
|
||||
outbound-reality = ["reality", "reality-rustls", "webpki-roots", "rustls-pemfile", "hex", "base64"]
|
||||
outbound-amux= ["tokio-util"]
|
||||
outbound-quic = ["rustls", "webpki-roots-old", "rustls-pemfile-old"]
|
||||
outbound-mptp = []
|
||||
outbound-select = ["directories", "axum/query"]
|
||||
outbound-vmess = ["lz_fnv", "cfb-mode", "hmac", "sha2", "aes", "aes-gcm", "sha3", "digest", "uuid", "md-5", "tokio-util", "byteorder", "crc32fast"]
|
||||
outbound-vmess = ["lz_fnv", "cfb-mode", "hmac", "sha2", "aes", "aes-gcm", "sha3", "digest", "md-5", "tokio-util", "byteorder", "crc32fast"]
|
||||
|
||||
# Inbounds
|
||||
inbound-trojan = ["sha2", "hex"]
|
||||
@@ -164,6 +164,7 @@ rand = "0.8"
|
||||
socket2 = "0.5"
|
||||
async-recursion = "1.1"
|
||||
parking_lot = "0.12"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
||||
# DNS
|
||||
hickory-proto = { version = "0.24", default-features = false }
|
||||
@@ -245,7 +246,6 @@ aes = { version = "0.8", optional = true }
|
||||
aes-gcm = { version = "0.10", optional = true }
|
||||
sha3 = { version = "0.10", optional = true }
|
||||
digest = { version = "0.10", optional = true }
|
||||
uuid = { version = "1", features = ["v4"], optional = true }
|
||||
byteorder = { version = "1", optional = true }
|
||||
crc32fast = { version = "1", optional = true }
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ impl NatManager {
|
||||
let mut sess = sess.cloned().unwrap_or_else(|| Session {
|
||||
network: Network::Udp,
|
||||
source: dgram_src.address,
|
||||
stream_id: dgram_src.stream_id,
|
||||
destination: pkt.dst_addr.clone(),
|
||||
inbound_tag: inbound_tag.to_string(),
|
||||
process_name: dgram_src.process_name.clone(),
|
||||
|
||||
@@ -7,7 +7,7 @@ use futures::{
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use crate::{proxy::*, session::Session};
|
||||
use crate::{proxy::*, session::Session, session::StreamId};
|
||||
|
||||
use super::MuxAcceptor;
|
||||
use super::MuxSession;
|
||||
@@ -33,7 +33,7 @@ impl Stream for Incoming {
|
||||
Poll::Ready(
|
||||
ready!(Pin::new(&mut self.acceptor).poll_next(cx)).map(|stream| {
|
||||
let mut sess = self.sess.clone();
|
||||
sess.stream_id = Some(stream.id().into());
|
||||
sess.stream_id = Some(StreamId::U64(stream.id().into()));
|
||||
AnyBaseInboundTransport::Stream(Box::new(stream), sess)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -713,37 +713,20 @@ impl MuxConnector {
|
||||
if self.max_recv_bytes > 0
|
||||
&& self.recv_bytes_counter.load(Ordering::Relaxed) >= self.max_recv_bytes
|
||||
{
|
||||
debug!(
|
||||
"exceeding allowed received bytes ({}): {}",
|
||||
self.session_id, self.max_recv_bytes
|
||||
);
|
||||
return None;
|
||||
}
|
||||
if self.max_lifetime > 0
|
||||
&& Instant::now().duration_since(self.started_at).as_secs() >= self.max_lifetime
|
||||
{
|
||||
debug!(
|
||||
"exceeding allowed lifetime ({}): {}s",
|
||||
self.session_id, self.max_lifetime
|
||||
);
|
||||
return None;
|
||||
}
|
||||
if self.total_accepted >= self.max_accepts {
|
||||
if self.streams.lock().await.is_empty() {
|
||||
self.done.store(true, Ordering::Relaxed);
|
||||
}
|
||||
debug!(
|
||||
"exceeding allowed accpets ({}): {}",
|
||||
self.session_id, self.max_accepts
|
||||
);
|
||||
return None;
|
||||
}
|
||||
if self.streams.lock().await.len() >= self.concurrency {
|
||||
trace!(
|
||||
"exceeding allowed concurrency ({}): {}",
|
||||
self.session_id,
|
||||
self.concurrency
|
||||
);
|
||||
return None;
|
||||
}
|
||||
let frame_write_tx = self.frame_write_tx.clone();
|
||||
|
||||
@@ -16,7 +16,7 @@ use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
proxy::{AnyInboundTransport, AnyStream, InboundStreamHandler, InboundTransport},
|
||||
session::{DatagramSource, Session, SocksAddr},
|
||||
session::{DatagramSource, Session, SocksAddr, StreamId},
|
||||
};
|
||||
|
||||
struct PrefixedStream<S> {
|
||||
@@ -207,9 +207,7 @@ impl InboundStreamHandler for Handler {
|
||||
}
|
||||
|
||||
if req.cmd == CMD_UDP {
|
||||
let mut stream_id_bytes = [0u8; 8];
|
||||
stream_id_bytes.copy_from_slice(&req.cid.as_bytes()[..8]);
|
||||
let stream_id = u64::from_le_bytes(stream_id_bytes);
|
||||
let stream_id = StreamId::Uuid(req.cid);
|
||||
let dgram_src = DatagramSource::new(sess.source, Some(stream_id));
|
||||
let mptp_datagram =
|
||||
MptpDatagram::new_with_source(tracked_stream, dgram_src);
|
||||
|
||||
@@ -13,7 +13,7 @@ use rustls_pemfile::{certs, pkcs8_private_keys, rsa_private_keys};
|
||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||
use tracing::{debug, trace, warn};
|
||||
|
||||
use crate::{proxy::*, session::Session};
|
||||
use crate::{proxy::*, session::Session, session::StreamId};
|
||||
|
||||
use super::QuicProxyStream;
|
||||
|
||||
@@ -31,7 +31,7 @@ impl Stream for Incoming {
|
||||
source,
|
||||
..Default::default()
|
||||
};
|
||||
sess.stream_id = Some(send.id().index());
|
||||
sess.stream_id = Some(StreamId::U64(send.id().index()));
|
||||
Poll::Ready(Some(AnyBaseInboundTransport::Stream(
|
||||
Box::new(QuicProxyStream { recv, send }),
|
||||
sess,
|
||||
|
||||
+14
-1
@@ -24,7 +24,20 @@ impl std::fmt::Display for Network {
|
||||
}
|
||||
}
|
||||
|
||||
pub type StreamId = u64;
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub enum StreamId {
|
||||
U64(u64),
|
||||
Uuid(uuid::Uuid),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for StreamId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::U64(id) => write!(f, "{}", id),
|
||||
Self::Uuid(id) => write!(f, "{}", id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||
pub struct DatagramSource {
|
||||
|
||||
Reference in new issue
Block a user