修改结构体名称
This commit is contained in:
@@ -16,11 +16,11 @@ use crate::channel::{Route, RouteKey, UseChannelType, DEFAULT_RT};
|
|||||||
|
|
||||||
/// 传输通道上下文,持有udp socket、tcp socket和路由信息
|
/// 传输通道上下文,持有udp socket、tcp socket和路由信息
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Context {
|
pub struct ChannelContext {
|
||||||
inner: Arc<ContextInner>,
|
inner: Arc<ContextInner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl ChannelContext {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
main_udp_socket: Vec<UdpSocket>,
|
main_udp_socket: Vec<UdpSocket>,
|
||||||
use_channel_type: UseChannelType,
|
use_channel_type: UseChannelType,
|
||||||
@@ -63,7 +63,7 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Context {
|
impl Deref for ChannelContext {
|
||||||
type Target = ContextInner;
|
type Target = ContextInner;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::RouteKey;
|
use crate::channel::RouteKey;
|
||||||
|
|
||||||
pub trait RecvChannelHandler: Clone + Send + 'static {
|
pub trait RecvChannelHandler: Clone + Send + 'static {
|
||||||
fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &Context);
|
fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &ChannelContext);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::Route;
|
use crate::channel::Route;
|
||||||
|
|
||||||
pub struct Idle {
|
pub struct Idle {
|
||||||
read_idle: Duration,
|
read_idle: Duration,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Idle {
|
impl Idle {
|
||||||
pub fn new(read_idle: Duration, context: Context) -> Self {
|
pub fn new(read_idle: Duration, context: ChannelContext) -> Self {
|
||||||
Self { read_idle, context }
|
Self { read_idle, context }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::io;
|
|||||||
use std::net::{SocketAddr, UdpSocket};
|
use std::net::{SocketAddr, UdpSocket};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::handler::RecvChannelHandler;
|
use crate::channel::handler::RecvChannelHandler;
|
||||||
use crate::channel::sender::AcceptSocketSender;
|
use crate::channel::sender::AcceptSocketSender;
|
||||||
use crate::channel::tcp_channel::tcp_listen;
|
use crate::channel::tcp_channel::tcp_listen;
|
||||||
@@ -151,7 +151,7 @@ pub fn init_context(
|
|||||||
is_tcp: bool,
|
is_tcp: bool,
|
||||||
packet_loss_rate: Option<f64>,
|
packet_loss_rate: Option<f64>,
|
||||||
packet_delay: u32,
|
packet_delay: u32,
|
||||||
) -> io::Result<(Context, mio::net::TcpListener)> {
|
) -> io::Result<(ChannelContext, mio::net::TcpListener)> {
|
||||||
assert!(!ports.is_empty(), "not channel");
|
assert!(!ports.is_empty(), "not channel");
|
||||||
let mut udps = Vec::with_capacity(ports.len());
|
let mut udps = Vec::with_capacity(ports.len());
|
||||||
//检查系统是否支持ipv6
|
//检查系统是否支持ipv6
|
||||||
@@ -191,7 +191,7 @@ pub fn init_context(
|
|||||||
let main_channel: UdpSocket = socket.into();
|
let main_channel: UdpSocket = socket.into();
|
||||||
udps.push(main_channel);
|
udps.push(main_channel);
|
||||||
}
|
}
|
||||||
let context = Context::new(
|
let context = ChannelContext::new(
|
||||||
udps,
|
udps,
|
||||||
use_channel_type,
|
use_channel_type,
|
||||||
first_latency,
|
first_latency,
|
||||||
@@ -242,7 +242,7 @@ pub fn init_context(
|
|||||||
|
|
||||||
pub fn init_channel<H>(
|
pub fn init_channel<H>(
|
||||||
tcp_listener: mio::net::TcpListener,
|
tcp_listener: mio::net::TcpListener,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
recv_handler: H,
|
recv_handler: H,
|
||||||
) -> io::Result<(
|
) -> io::Result<(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use mio::net::TcpStream;
|
|||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::sender::AcceptSocketSender;
|
use crate::channel::sender::AcceptSocketSender;
|
||||||
use crate::external_route::ExternalRoute;
|
use crate::external_route::ExternalRoute;
|
||||||
use crate::nat::NatTest;
|
use crate::nat::NatTest;
|
||||||
@@ -181,7 +181,7 @@ impl NatInfo {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Punch {
|
pub struct Punch {
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
port_vec: Vec<u16>,
|
port_vec: Vec<u16>,
|
||||||
port_index: HashMap<Ipv4Addr, usize>,
|
port_index: HashMap<Ipv4Addr, usize>,
|
||||||
punch_model: PunchModel,
|
punch_model: PunchModel,
|
||||||
@@ -193,7 +193,7 @@ pub struct Punch {
|
|||||||
|
|
||||||
impl Punch {
|
impl Punch {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
punch_model: PunchModel,
|
punch_model: PunchModel,
|
||||||
is_tcp: bool,
|
is_tcp: bool,
|
||||||
tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use mio::Token;
|
use mio::Token;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::notify::{AcceptNotify, WritableNotify};
|
use crate::channel::notify::{AcceptNotify, WritableNotify};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ChannelSender {
|
pub struct ChannelSender {
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelSender {
|
impl ChannelSender {
|
||||||
pub fn new(context: Context) -> Self {
|
pub fn new(context: ChannelContext) -> Self {
|
||||||
Self { context }
|
Self { context }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for ChannelSender {
|
impl Deref for ChannelSender {
|
||||||
type Target = Context;
|
type Target = ChannelContext;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.context
|
&self.context
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use std::{io, thread};
|
|||||||
use mio::net::{TcpListener, TcpStream};
|
use mio::net::{TcpListener, TcpStream};
|
||||||
use mio::{Events, Interest, Poll, Registry, Token, Waker};
|
use mio::{Events, Interest, Poll, Registry, Token, Waker};
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::handler::RecvChannelHandler;
|
use crate::channel::handler::RecvChannelHandler;
|
||||||
use crate::channel::notify::{AcceptNotify, WritableNotify};
|
use crate::channel::notify::{AcceptNotify, WritableNotify};
|
||||||
use crate::channel::sender::{AcceptSocketSender, PacketSender};
|
use crate::channel::sender::{AcceptSocketSender, PacketSender};
|
||||||
@@ -30,7 +30,7 @@ pub fn tcp_listen<H>(
|
|||||||
tcp_server: TcpListener,
|
tcp_server: TcpListener,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
recv_handler: H,
|
recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>>
|
) -> io::Result<AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -74,7 +74,7 @@ fn tcp_listen0<H>(
|
|||||||
accept_notify: AcceptNotify,
|
accept_notify: AcceptNotify,
|
||||||
accept_tcp_receiver: Receiver<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
accept_tcp_receiver: Receiver<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
||||||
mut recv_handler: H,
|
mut recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -158,7 +158,7 @@ where
|
|||||||
fn init_writable_handler(
|
fn init_writable_handler(
|
||||||
receiver: Receiver<(TcpStream, Token, SocketAddr, Option<Vec<u8>>)>,
|
receiver: Receiver<(TcpStream, Token, SocketAddr, Option<Vec<u8>>)>,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<WritableNotify> {
|
) -> io::Result<WritableNotify> {
|
||||||
let poll = Poll::new()?;
|
let poll = Poll::new()?;
|
||||||
let writable_notify = WritableNotify::new(Waker::new(poll.registry(), NOTIFY)?);
|
let writable_notify = WritableNotify::new(Waker::new(poll.registry(), NOTIFY)?);
|
||||||
@@ -190,7 +190,7 @@ fn tcp_writable_listen(
|
|||||||
receiver: Receiver<(TcpStream, Token, SocketAddr, Option<Vec<u8>>)>,
|
receiver: Receiver<(TcpStream, Token, SocketAddr, Option<Vec<u8>>)>,
|
||||||
mut poll: Poll,
|
mut poll: Poll,
|
||||||
writable_notify: WritableNotify,
|
writable_notify: WritableNotify,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut events = Events::with_capacity(1024);
|
let mut events = Events::with_capacity(1024);
|
||||||
let mut write_map: HashMap<
|
let mut write_map: HashMap<
|
||||||
@@ -338,7 +338,7 @@ fn readable_handle<H>(
|
|||||||
token: &Token,
|
token: &Token,
|
||||||
map: &mut HashMap<Token, (RouteKey, TcpStream, Box<[u8; BUFFER_SIZE]>, usize)>,
|
map: &mut HashMap<Token, (RouteKey, TcpStream, Box<[u8; BUFFER_SIZE]>, usize)>,
|
||||||
recv_handler: &mut H,
|
recv_handler: &mut H,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -447,7 +447,7 @@ fn closed_handle_w(
|
|||||||
Option<(Vec<u8>, usize)>,
|
Option<(Vec<u8>, usize)>,
|
||||||
),
|
),
|
||||||
>,
|
>,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
) {
|
) {
|
||||||
if let Some((tcp, addr, _, _)) = map.remove(token) {
|
if let Some((tcp, addr, _, _)) = map.remove(token) {
|
||||||
context.tcp_map.write().remove(&addr);
|
context.tcp_map.write().remove(&addr);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use mio::event::Source;
|
|||||||
use mio::net::UdpSocket;
|
use mio::net::UdpSocket;
|
||||||
use mio::{Events, Interest, Poll, Token, Waker};
|
use mio::{Events, Interest, Poll, Token, Waker};
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::handler::RecvChannelHandler;
|
use crate::channel::handler::RecvChannelHandler;
|
||||||
use crate::channel::notify::AcceptNotify;
|
use crate::channel::notify::AcceptNotify;
|
||||||
use crate::channel::sender::AcceptSocketSender;
|
use crate::channel::sender::AcceptSocketSender;
|
||||||
@@ -16,7 +16,7 @@ use crate::util::StopManager;
|
|||||||
pub fn udp_listen<H>(
|
pub fn udp_listen<H>(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
recv_handler: H,
|
recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<AcceptSocketSender<Option<Vec<UdpSocket>>>>
|
) -> io::Result<AcceptSocketSender<Option<Vec<UdpSocket>>>>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -30,7 +30,7 @@ const NOTIFY: Token = Token(0);
|
|||||||
fn sub_udp_listen<H>(
|
fn sub_udp_listen<H>(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
recv_handler: H,
|
recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<AcceptSocketSender<Option<Vec<UdpSocket>>>>
|
) -> io::Result<AcceptSocketSender<Option<Vec<UdpSocket>>>>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -61,7 +61,7 @@ where
|
|||||||
fn sub_udp_listen0<H>(
|
fn sub_udp_listen0<H>(
|
||||||
mut poll: Poll,
|
mut poll: Poll,
|
||||||
mut recv_handler: H,
|
mut recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
accept_notify: AcceptNotify,
|
accept_notify: AcceptNotify,
|
||||||
accept_receiver: Receiver<Option<Vec<UdpSocket>>>,
|
accept_receiver: Receiver<Option<Vec<UdpSocket>>>,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
@@ -205,7 +205,7 @@ where
|
|||||||
fn main_udp_listen<H>(
|
fn main_udp_listen<H>(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
recv_handler: H,
|
recv_handler: H,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
@@ -231,7 +231,11 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_udp_listen0<H>(mut poll: Poll, mut recv_handler: H, context: Context) -> io::Result<()>
|
pub fn main_udp_listen0<H>(
|
||||||
|
mut poll: Poll,
|
||||||
|
mut recv_handler: H,
|
||||||
|
context: ChannelContext,
|
||||||
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: RecvChannelHandler,
|
H: RecvChannelHandler,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use rsa::signature::digest::Digest;
|
|||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
use tun::device::IFace;
|
use tun::device::IFace;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::idle::Idle;
|
use crate::channel::idle::Idle;
|
||||||
use crate::channel::punch::{NatInfo, Punch};
|
use crate::channel::punch::{NatInfo, Punch};
|
||||||
use crate::channel::{init_channel, init_context, Route, RouteKey};
|
use crate::channel::{init_channel, init_context, Route, RouteKey};
|
||||||
@@ -40,7 +40,7 @@ pub struct Vnt {
|
|||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>>,
|
peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>>,
|
||||||
down_count_watcher: WatchU64Adder,
|
down_count_watcher: WatchU64Adder,
|
||||||
up_count_watcher: WatchSingleU64Adder,
|
up_count_watcher: WatchSingleU64Adder,
|
||||||
@@ -282,7 +282,7 @@ impl Vnt {
|
|||||||
|
|
||||||
pub fn start<Call: VntCallback>(
|
pub fn start<Call: VntCallback>(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
#[cfg(feature = "server_encrypt")]
|
#[cfg(feature = "server_encrypt")]
|
||||||
use crate::cipher::RsaCipher;
|
use crate::cipher::RsaCipher;
|
||||||
use crate::handle::{GATEWAY_IP, SELF_IP};
|
use crate::handle::{GATEWAY_IP, SELF_IP};
|
||||||
@@ -37,7 +37,7 @@ impl Handshake {
|
|||||||
rsa_cipher,
|
rsa_cipher,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn send(&self, context: &Context, secret: bool, addr: SocketAddr) -> io::Result<()> {
|
pub fn send(&self, context: &ChannelContext, secret: bool, addr: SocketAddr) -> io::Result<()> {
|
||||||
let last = self.time.load();
|
let last = self.time.load();
|
||||||
//短时间不重复发送
|
//短时间不重复发送
|
||||||
if last.elapsed() < Duration::from_secs(3) {
|
if last.elapsed() < Duration::from_secs(3) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::handle::{BaseConfigInfo, CurrentDeviceInfo};
|
use crate::handle::{BaseConfigInfo, CurrentDeviceInfo};
|
||||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||||
@@ -12,7 +12,7 @@ use crate::util::Scheduler;
|
|||||||
|
|
||||||
pub fn addr_request(
|
pub fn addr_request(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
server_cipher: Cipher,
|
server_cipher: Cipher,
|
||||||
_config: BaseConfigInfo,
|
_config: BaseConfigInfo,
|
||||||
@@ -26,7 +26,7 @@ pub fn addr_request(
|
|||||||
}
|
}
|
||||||
pub fn pub_address_request(
|
pub fn pub_address_request(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
server_cipher: Cipher,
|
server_cipher: Cipher,
|
||||||
) {
|
) {
|
||||||
@@ -41,7 +41,7 @@ pub fn pub_address_request(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn addr_request0(
|
pub fn addr_request0(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &AtomicCell<CurrentDeviceInfo>,
|
current_device: &AtomicCell<CurrentDeviceInfo>,
|
||||||
server_cipher: &Cipher,
|
server_cipher: &Cipher,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||||
@@ -18,7 +18,7 @@ use crate::util::Scheduler;
|
|||||||
/// 定时发送心跳包
|
/// 定时发送心跳包
|
||||||
pub fn heartbeat(
|
pub fn heartbeat(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
client_cipher: Cipher,
|
client_cipher: Cipher,
|
||||||
@@ -48,7 +48,7 @@ pub fn heartbeat(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn heartbeat0(
|
fn heartbeat0(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
||||||
client_cipher: &Cipher,
|
client_cipher: &Cipher,
|
||||||
@@ -125,7 +125,7 @@ fn heartbeat0(
|
|||||||
/// 客户端中继路径探测,延迟启动
|
/// 客户端中继路径探测,延迟启动
|
||||||
pub fn client_relay(
|
pub fn client_relay(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
client_cipher: Cipher,
|
client_cipher: Cipher,
|
||||||
@@ -141,7 +141,7 @@ pub fn client_relay(
|
|||||||
/// 客户端中继路径探测,每30秒探测一次
|
/// 客户端中继路径探测,每30秒探测一次
|
||||||
fn client_relay_(
|
fn client_relay_(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
client_cipher: Cipher,
|
client_cipher: Cipher,
|
||||||
@@ -163,7 +163,7 @@ fn client_relay_(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn client_relay0(
|
fn client_relay0(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
||||||
client_cipher: &Cipher,
|
client_cipher: &Cipher,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::time::Duration;
|
|||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use mio::net::TcpStream;
|
use mio::net::TcpStream;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::idle::{Idle, IdleType};
|
use crate::channel::idle::{Idle, IdleType};
|
||||||
use crate::channel::sender::AcceptSocketSender;
|
use crate::channel::sender::AcceptSocketSender;
|
||||||
use crate::handle::callback::{ConnectInfo, ErrorType};
|
use crate::handle::callback::{ConnectInfo, ErrorType};
|
||||||
@@ -18,7 +18,7 @@ use crate::{ErrorInfo, VntCallback};
|
|||||||
pub fn idle_route<Call: VntCallback>(
|
pub fn idle_route<Call: VntCallback>(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
idle: Idle,
|
idle: Idle,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
call: Call,
|
call: Call,
|
||||||
) {
|
) {
|
||||||
@@ -33,7 +33,7 @@ pub fn idle_route<Call: VntCallback>(
|
|||||||
|
|
||||||
pub fn idle_gateway<Call: VntCallback>(
|
pub fn idle_gateway<Call: VntCallback>(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
config: BaseConfigInfo,
|
config: BaseConfigInfo,
|
||||||
tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
tcp_socket_sender: AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
||||||
@@ -68,7 +68,7 @@ pub fn idle_gateway<Call: VntCallback>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn idle_gateway0<Call: VntCallback>(
|
fn idle_gateway0<Call: VntCallback>(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &AtomicCell<CurrentDeviceInfo>,
|
current_device: &AtomicCell<CurrentDeviceInfo>,
|
||||||
config: &BaseConfigInfo,
|
config: &BaseConfigInfo,
|
||||||
tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
||||||
@@ -95,7 +95,7 @@ fn idle_gateway0<Call: VntCallback>(
|
|||||||
|
|
||||||
fn idle_route0<Call: VntCallback>(
|
fn idle_route0<Call: VntCallback>(
|
||||||
idle: &Idle,
|
idle: &Idle,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &AtomicCell<CurrentDeviceInfo>,
|
current_device: &AtomicCell<CurrentDeviceInfo>,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
) -> Duration {
|
) -> Duration {
|
||||||
@@ -117,7 +117,7 @@ fn idle_route0<Call: VntCallback>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_gateway_channel<Call: VntCallback>(
|
fn check_gateway_channel<Call: VntCallback>(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device_info: &AtomicCell<CurrentDeviceInfo>,
|
current_device_info: &AtomicCell<CurrentDeviceInfo>,
|
||||||
config: &BaseConfigInfo,
|
config: &BaseConfigInfo,
|
||||||
tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
tcp_socket_sender: &AcceptSocketSender<(TcpStream, SocketAddr, Option<Vec<u8>>)>,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use parking_lot::Mutex;
|
|||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::punch::{NatInfo, NatType, Punch};
|
use crate::channel::punch::{NatInfo, NatType, Punch};
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||||
@@ -86,7 +86,7 @@ pub fn punch_channel() -> (PunchSender, PunchReceiver) {
|
|||||||
|
|
||||||
pub fn punch(
|
pub fn punch(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
@@ -166,7 +166,7 @@ fn punch_start(
|
|||||||
/// 定时发起打洞请求
|
/// 定时发起打洞请求
|
||||||
fn punch_request(
|
fn punch_request(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
@@ -214,7 +214,7 @@ fn punch_request(
|
|||||||
|
|
||||||
/// 随机对需要打洞的客户端发起打洞请求
|
/// 随机对需要打洞的客户端发起打洞请求
|
||||||
fn punch0(
|
fn punch0(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
nat_test: &NatTest,
|
nat_test: &NatTest,
|
||||||
device_list: &Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
device_list: &Arc<Mutex<(u16, Vec<PeerDeviceInfo>)>>,
|
||||||
current_device: CurrentDeviceInfo,
|
current_device: CurrentDeviceInfo,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::sender::AcceptSocketSender;
|
use crate::channel::sender::AcceptSocketSender;
|
||||||
use crate::nat;
|
use crate::nat;
|
||||||
use crate::nat::NatTest;
|
use crate::nat::NatTest;
|
||||||
@@ -10,7 +10,7 @@ use crate::util::Scheduler;
|
|||||||
/// 10分钟探测一次nat
|
/// 10分钟探测一次nat
|
||||||
pub fn retrieve_nat_type(
|
pub fn retrieve_nat_type(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
udp_socket_sender: AcceptSocketSender<Option<Vec<mio::net::UdpSocket>>>,
|
udp_socket_sender: AcceptSocketSender<Option<Vec<mio::net::UdpSocket>>>,
|
||||||
) {
|
) {
|
||||||
@@ -21,7 +21,7 @@ pub fn retrieve_nat_type(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_nat_type0(
|
fn retrieve_nat_type0(
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
nat_test: NatTest,
|
nat_test: NatTest,
|
||||||
udp_socket_sender: AcceptSocketSender<Option<Vec<mio::net::UdpSocket>>>,
|
udp_socket_sender: AcceptSocketSender<Option<Vec<mio::net::UdpSocket>>>,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::handle::CurrentDeviceInfo;
|
use crate::handle::CurrentDeviceInfo;
|
||||||
use crate::proto::message::{ClientStatusInfo, PunchNatType, RouteItem};
|
use crate::proto::message::{ClientStatusInfo, PunchNatType, RouteItem};
|
||||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||||
@@ -13,7 +13,7 @@ use std::time::Duration;
|
|||||||
/// 上报状态给服务器
|
/// 上报状态给服务器
|
||||||
pub fn up_status(
|
pub fn up_status(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
down_count_watcher: WatchU64Adder,
|
down_count_watcher: WatchU64Adder,
|
||||||
up_count_watcher: WatchSingleU64Adder,
|
up_count_watcher: WatchSingleU64Adder,
|
||||||
@@ -31,7 +31,7 @@ pub fn up_status(
|
|||||||
|
|
||||||
fn up_status0(
|
fn up_status0(
|
||||||
scheduler: &Scheduler,
|
scheduler: &Scheduler,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device_info: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
down_count_watcher: WatchU64Adder,
|
down_count_watcher: WatchU64Adder,
|
||||||
up_count_watcher: WatchSingleU64Adder,
|
up_count_watcher: WatchSingleU64Adder,
|
||||||
@@ -59,7 +59,7 @@ fn up_status0(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn send_up_status_packet(
|
fn send_up_status_packet(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device_info: &AtomicCell<CurrentDeviceInfo>,
|
current_device_info: &AtomicCell<CurrentDeviceInfo>,
|
||||||
down_count_watcher: &WatchU64Adder,
|
down_count_watcher: &WatchU64Adder,
|
||||||
up_count_watcher: &WatchSingleU64Adder,
|
up_count_watcher: &WatchSingleU64Adder,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use packet::icmp::{icmp, Kind};
|
|||||||
use packet::ip::ipv4;
|
use packet::ip::ipv4;
|
||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::punch::NatInfo;
|
use crate::channel::punch::NatInfo;
|
||||||
use crate::channel::{Route, RouteKey};
|
use crate::channel::{Route, RouteKey};
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
@@ -71,7 +71,7 @@ impl PacketHandler for ClientPacketHandler {
|
|||||||
&self,
|
&self,
|
||||||
mut net_packet: NetPacket<&mut [u8]>,
|
mut net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
self.client_cipher.decrypt_ipv4(&mut net_packet)?;
|
self.client_cipher.decrypt_ipv4(&mut net_packet)?;
|
||||||
@@ -100,7 +100,7 @@ impl ClientPacketHandler {
|
|||||||
fn ip_turn(
|
fn ip_turn(
|
||||||
&self,
|
&self,
|
||||||
mut net_packet: NetPacket<&mut [u8]>,
|
mut net_packet: NetPacket<&mut [u8]>,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
@@ -186,7 +186,7 @@ impl ClientPacketHandler {
|
|||||||
}
|
}
|
||||||
fn control(
|
fn control(
|
||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
mut net_packet: NetPacket<&mut [u8]>,
|
mut net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
@@ -274,7 +274,7 @@ impl ClientPacketHandler {
|
|||||||
}
|
}
|
||||||
fn other_turn(
|
fn other_turn(
|
||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
net_packet: NetPacket<&mut [u8]>,
|
net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::{io, thread};
|
|||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::handler::RecvChannelHandler;
|
use crate::channel::handler::RecvChannelHandler;
|
||||||
use crate::channel::punch::NatInfo;
|
use crate::channel::punch::NatInfo;
|
||||||
use crate::channel::RouteKey;
|
use crate::channel::RouteKey;
|
||||||
@@ -42,7 +42,7 @@ pub struct RecvDataHandler<Call> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Call: VntCallback> RecvChannelHandler for RecvDataHandler<Call> {
|
impl<Call: VntCallback> RecvChannelHandler for RecvDataHandler<Call> {
|
||||||
fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &Context) {
|
fn handle(&mut self, buf: &mut [u8], route_key: RouteKey, context: &ChannelContext) {
|
||||||
if let Err(e) = self.handle0(buf, route_key, context) {
|
if let Err(e) = self.handle0(buf, route_key, context) {
|
||||||
log::error!("[{}]-{:?}", thread::current().name().unwrap_or(""), e);
|
log::error!("[{}]-{:?}", thread::current().name().unwrap_or(""), e);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ impl<Call: VntCallback> RecvDataHandler<Call> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
// 统计流量
|
// 统计流量
|
||||||
self.counter.add(buf.len() as _);
|
self.counter.add(buf.len() as _);
|
||||||
@@ -145,7 +145,7 @@ pub trait PacketHandler {
|
|||||||
&self,
|
&self,
|
||||||
net_packet: NetPacket<&mut [u8]>,
|
net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
) -> io::Result<()>;
|
) -> io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use packet::icmp::{icmp, Kind};
|
|||||||
use packet::ip::ipv4;
|
use packet::ip::ipv4;
|
||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::{Route, RouteKey};
|
use crate::channel::{Route, RouteKey};
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
#[cfg(feature = "server_encrypt")]
|
#[cfg(feature = "server_encrypt")]
|
||||||
@@ -95,7 +95,7 @@ impl<Call: VntCallback> PacketHandler for ServerPacketHandler<Call> {
|
|||||||
&self,
|
&self,
|
||||||
mut net_packet: NetPacket<&mut [u8]>,
|
mut net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
context
|
context
|
||||||
@@ -248,7 +248,7 @@ impl<Call: VntCallback> PacketHandler for ServerPacketHandler<Call> {
|
|||||||
impl<Call: VntCallback> ServerPacketHandler<Call> {
|
impl<Call: VntCallback> ServerPacketHandler<Call> {
|
||||||
fn service(
|
fn service(
|
||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
net_packet: NetPacket<&mut [u8]>,
|
net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
@@ -435,7 +435,11 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
|
|||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
fn register(&self, current_device: &CurrentDeviceInfo, context: &Context) -> io::Result<()> {
|
fn register(
|
||||||
|
&self,
|
||||||
|
current_device: &CurrentDeviceInfo,
|
||||||
|
context: &ChannelContext,
|
||||||
|
) -> io::Result<()> {
|
||||||
if current_device.status.online() {
|
if current_device.status.online() {
|
||||||
log::info!("已连接的不需要注册,{:?}", self.config_info);
|
log::info!("已连接的不需要注册,{:?}", self.config_info);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -468,7 +472,7 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
|
|||||||
}
|
}
|
||||||
fn error(
|
fn error(
|
||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
_current_device: &CurrentDeviceInfo,
|
_current_device: &CurrentDeviceInfo,
|
||||||
net_packet: NetPacket<&mut [u8]>,
|
net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
@@ -518,7 +522,7 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
|
|||||||
}
|
}
|
||||||
fn control(
|
fn control(
|
||||||
&self,
|
&self,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
net_packet: NetPacket<&mut [u8]>,
|
net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::channel::RouteKey;
|
use crate::channel::RouteKey;
|
||||||
use crate::handle::recv_data::PacketHandler;
|
use crate::handle::recv_data::PacketHandler;
|
||||||
use crate::handle::CurrentDeviceInfo;
|
use crate::handle::CurrentDeviceInfo;
|
||||||
@@ -19,7 +19,7 @@ impl PacketHandler for TurnPacketHandler {
|
|||||||
&self,
|
&self,
|
||||||
mut net_packet: NetPacket<&mut [u8]>,
|
mut net_packet: NetPacket<&mut [u8]>,
|
||||||
route_key: RouteKey,
|
route_key: RouteKey,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
_current_device: &CurrentDeviceInfo,
|
_current_device: &CurrentDeviceInfo,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
// ttl减一
|
// ttl减一
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use parking_lot::Mutex;
|
|||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
use packet::ip::ipv4::protocol::Protocol;
|
use packet::ip::ipv4::protocol::Protocol;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::external_route::ExternalRoute;
|
use crate::external_route::ExternalRoute;
|
||||||
use crate::handle::{check_dest, CurrentDeviceInfo, PeerDeviceInfo};
|
use crate::handle::{check_dest, CurrentDeviceInfo, PeerDeviceInfo};
|
||||||
@@ -22,7 +22,7 @@ pub mod tun_handler;
|
|||||||
|
|
||||||
fn broadcast(
|
fn broadcast(
|
||||||
server_cipher: &Cipher,
|
server_cipher: &Cipher,
|
||||||
sender: &Context,
|
sender: &ChannelContext,
|
||||||
net_packet: &mut NetPacket<&mut [u8]>,
|
net_packet: &mut NetPacket<&mut [u8]>,
|
||||||
current_device: &CurrentDeviceInfo,
|
current_device: &CurrentDeviceInfo,
|
||||||
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
device_list: &Mutex<(u16, Vec<PeerDeviceInfo>)>,
|
||||||
@@ -108,7 +108,7 @@ fn broadcast(
|
|||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn base_handle(
|
pub fn base_handle(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
data_len: usize, //数据总长度=12+ip包长度
|
data_len: usize, //数据总长度=12+ip包长度
|
||||||
current_device: CurrentDeviceInfo,
|
current_device: CurrentDeviceInfo,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use packet::ip::ipv4::packet::IpV4Packet;
|
|||||||
use tun::device::IFace;
|
use tun::device::IFace;
|
||||||
use tun::Device;
|
use tun::Device;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::external_route::ExternalRoute;
|
use crate::external_route::ExternalRoute;
|
||||||
use crate::handle::tun_tap::channel_group::{channel_group, GroupSyncSender};
|
use crate::handle::tun_tap::channel_group::{channel_group, GroupSyncSender};
|
||||||
@@ -38,7 +38,7 @@ fn icmp(device_writer: &Device, mut ipv4_packet: IpV4Packet<&mut [u8]>) -> io::R
|
|||||||
|
|
||||||
/// 接收tun数据,并且转发到udp上
|
/// 接收tun数据,并且转发到udp上
|
||||||
fn handle(
|
fn handle(
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
data: &mut [u8],
|
data: &mut [u8],
|
||||||
len: usize,
|
len: usize,
|
||||||
device_writer: &Device,
|
device_writer: &Device,
|
||||||
@@ -75,7 +75,7 @@ fn handle(
|
|||||||
|
|
||||||
pub fn start(
|
pub fn start(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
ip_route: ExternalRoute,
|
ip_route: ExternalRoute,
|
||||||
@@ -179,7 +179,7 @@ pub fn start(
|
|||||||
|
|
||||||
fn start_simple(
|
fn start_simple(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
ip_route: ExternalRoute,
|
ip_route: ExternalRoute,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use packet::icmp::icmp;
|
|||||||
use packet::icmp::icmp::HeaderOther;
|
use packet::icmp::icmp::HeaderOther;
|
||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::handle::CurrentDeviceInfo;
|
use crate::handle::CurrentDeviceInfo;
|
||||||
use crate::ip_proxy::ProxyHandler;
|
use crate::ip_proxy::ProxyHandler;
|
||||||
@@ -28,7 +28,7 @@ pub struct IcmpProxy {
|
|||||||
|
|
||||||
impl IcmpProxy {
|
impl IcmpProxy {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
client_cipher: Cipher,
|
client_cipher: Cipher,
|
||||||
@@ -86,7 +86,7 @@ fn icmp_proxy(
|
|||||||
mut icmp_socket: UdpSocket,
|
mut icmp_socket: UdpSocket,
|
||||||
// 对端-> 真实来源
|
// 对端-> 真实来源
|
||||||
nat_map: Arc<Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>>,
|
nat_map: Arc<Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>>,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
client_cipher: Cipher,
|
client_cipher: Cipher,
|
||||||
@@ -130,7 +130,7 @@ fn readable_handle(
|
|||||||
icmp_socket: &UdpSocket,
|
icmp_socket: &UdpSocket,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
nat_map: &Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>,
|
nat_map: &Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &AtomicCell<CurrentDeviceInfo>,
|
current_device: &AtomicCell<CurrentDeviceInfo>,
|
||||||
client_cipher: &Cipher,
|
client_cipher: &Cipher,
|
||||||
) {
|
) {
|
||||||
@@ -181,7 +181,7 @@ fn recv_handle(
|
|||||||
data_len: usize,
|
data_len: usize,
|
||||||
peer_ip: Ipv4Addr,
|
peer_ip: Ipv4Addr,
|
||||||
nat_map: &Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>,
|
nat_map: &Mutex<HashMap<(Ipv4Addr, u16, u16), Ipv4Addr>>,
|
||||||
context: &Context,
|
context: &ChannelContext,
|
||||||
current_device: &AtomicCell<CurrentDeviceInfo>,
|
current_device: &AtomicCell<CurrentDeviceInfo>,
|
||||||
client_cipher: &Cipher,
|
client_cipher: &Cipher,
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crossbeam_utils::atomic::AtomicCell;
|
|||||||
use packet::ip::ipv4;
|
use packet::ip::ipv4;
|
||||||
use packet::ip::ipv4::packet::IpV4Packet;
|
use packet::ip::ipv4::packet::IpV4Packet;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::handle::CurrentDeviceInfo;
|
use crate::handle::CurrentDeviceInfo;
|
||||||
use crate::ip_proxy::icmp_proxy::IcmpProxy;
|
use crate::ip_proxy::icmp_proxy::IcmpProxy;
|
||||||
@@ -37,7 +37,7 @@ pub struct IpProxyMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_proxy(
|
pub fn init_proxy(
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
scheduler: Scheduler,
|
scheduler: Scheduler,
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use parking_lot::Mutex;
|
|||||||
|
|
||||||
use tun::Device;
|
use tun::Device;
|
||||||
|
|
||||||
use crate::channel::context::Context;
|
use crate::channel::context::ChannelContext;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::external_route::ExternalRoute;
|
use crate::external_route::ExternalRoute;
|
||||||
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||||
@@ -70,7 +70,7 @@ pub struct TunDeviceHelper {
|
|||||||
|
|
||||||
struct TunDeviceHelperInner {
|
struct TunDeviceHelperInner {
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
ip_route: ExternalRoute,
|
ip_route: ExternalRoute,
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
@@ -85,7 +85,7 @@ struct TunDeviceHelperInner {
|
|||||||
impl TunDeviceHelper {
|
impl TunDeviceHelper {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
stop_manager: StopManager,
|
stop_manager: StopManager,
|
||||||
context: Context,
|
context: ChannelContext,
|
||||||
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
|
||||||
ip_route: ExternalRoute,
|
ip_route: ExternalRoute,
|
||||||
#[cfg(feature = "ip_proxy")] ip_proxy_map: Option<IpProxyMap>,
|
#[cfg(feature = "ip_proxy")] ip_proxy_map: Option<IpProxyMap>,
|
||||||
|
|||||||
Reference in New Issue
Block a user