[mio] 修复指定通道类型无效的问题
This commit is contained in:
@@ -73,6 +73,9 @@ pub struct ContextInner {
|
||||
}
|
||||
|
||||
impl ContextInner {
|
||||
pub fn use_channel_type(&self) -> UseChannelType {
|
||||
self.route_table.use_channel_type
|
||||
}
|
||||
pub fn is_stop(&self) -> bool {
|
||||
!self.state.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
+14
-15
@@ -14,7 +14,7 @@ use tun::device::IFace;
|
||||
use crate::channel::context::Context;
|
||||
use crate::channel::idle::Idle;
|
||||
use crate::channel::punch::{NatInfo, Punch};
|
||||
use crate::channel::{init_channel, init_context, Route, RouteKey, UseChannelType};
|
||||
use crate::channel::{init_channel, init_context, Route, RouteKey};
|
||||
use crate::cipher::Cipher;
|
||||
#[cfg(feature = "server_encrypt")]
|
||||
use crate::cipher::RsaCipher;
|
||||
@@ -136,7 +136,8 @@ impl Vnt {
|
||||
let (punch_sender, punch_receiver) = sync_channel(3);
|
||||
let peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>> =
|
||||
Arc::new(RwLock::new(HashMap::with_capacity(16)));
|
||||
let down_counter = U64Adder::with_capacity(config.ports.as_ref().map(|v| v.len()).unwrap_or_default() + 8);
|
||||
let down_counter =
|
||||
U64Adder::with_capacity(config.ports.as_ref().map(|v| v.len()).unwrap_or_default() + 8);
|
||||
let down_count_watcher = down_counter.watch();
|
||||
let handler = RecvDataHandler::new(
|
||||
#[cfg(feature = "server_encrypt")]
|
||||
@@ -149,7 +150,6 @@ impl Vnt {
|
||||
config_info.clone(),
|
||||
nat_test.clone(),
|
||||
callback.clone(),
|
||||
config.use_channel_type,
|
||||
punch_sender,
|
||||
peer_nat_info_map.clone(),
|
||||
external_route.clone(),
|
||||
@@ -198,8 +198,7 @@ impl Vnt {
|
||||
let nat_test = nat_test.clone();
|
||||
let device_list = device_list.clone();
|
||||
let current_device = current_device.clone();
|
||||
let use_channel_type = config.use_channel_type;
|
||||
if !use_channel_type.is_only_relay() {
|
||||
if !config.use_channel_type.is_only_relay() {
|
||||
// 定时nat探测
|
||||
maintain::retrieve_nat_type(
|
||||
&scheduler,
|
||||
@@ -222,7 +221,6 @@ impl Vnt {
|
||||
config_info,
|
||||
punch,
|
||||
callback,
|
||||
use_channel_type,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -253,7 +251,6 @@ pub fn start<Call: VntCallback>(
|
||||
config_info: BaseConfigInfo,
|
||||
punch: Punch,
|
||||
callback: Call,
|
||||
use_channel_type: UseChannelType,
|
||||
) {
|
||||
// 定时心跳
|
||||
maintain::heartbeat(
|
||||
@@ -275,13 +272,15 @@ pub fn start<Call: VntCallback>(
|
||||
callback,
|
||||
);
|
||||
// 定时客户端中继检测
|
||||
maintain::client_relay(
|
||||
&scheduler,
|
||||
context.clone(),
|
||||
current_device.clone(),
|
||||
device_list.clone(),
|
||||
client_cipher.clone(),
|
||||
);
|
||||
if !context.use_channel_type().is_only_p2p() {
|
||||
maintain::client_relay(
|
||||
&scheduler,
|
||||
context.clone(),
|
||||
current_device.clone(),
|
||||
device_list.clone(),
|
||||
client_cipher.clone(),
|
||||
);
|
||||
}
|
||||
// 定时地址探测
|
||||
maintain::addr_request(
|
||||
&scheduler,
|
||||
@@ -290,7 +289,7 @@ pub fn start<Call: VntCallback>(
|
||||
server_cipher.clone(),
|
||||
config_info.clone(),
|
||||
);
|
||||
if !use_channel_type.is_only_relay() {
|
||||
if !context.use_channel_type().is_only_relay() {
|
||||
// 定时打洞
|
||||
maintain::punch(
|
||||
&scheduler,
|
||||
|
||||
@@ -15,7 +15,7 @@ use tun::Device;
|
||||
|
||||
use crate::channel::context::Context;
|
||||
use crate::channel::punch::NatInfo;
|
||||
use crate::channel::{Route, RouteKey, UseChannelType};
|
||||
use crate::channel::{Route, RouteKey};
|
||||
use crate::cipher::Cipher;
|
||||
use crate::external_route::AllowExternalRoute;
|
||||
use crate::handle::recv_data::PacketHandler;
|
||||
@@ -35,7 +35,6 @@ use crate::protocol::{
|
||||
pub struct ClientPacketHandler {
|
||||
device: Arc<Device>,
|
||||
client_cipher: Cipher,
|
||||
use_channel_type: UseChannelType,
|
||||
punch_sender: SyncSender<(Ipv4Addr, NatInfo)>,
|
||||
peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>>,
|
||||
nat_test: NatTest,
|
||||
@@ -48,7 +47,6 @@ impl ClientPacketHandler {
|
||||
pub fn new(
|
||||
device: Arc<Device>,
|
||||
client_cipher: Cipher,
|
||||
use_channel_type: UseChannelType,
|
||||
punch_sender: SyncSender<(Ipv4Addr, NatInfo)>,
|
||||
peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>>,
|
||||
nat_test: NatTest,
|
||||
@@ -58,7 +56,6 @@ impl ClientPacketHandler {
|
||||
Self {
|
||||
device,
|
||||
client_cipher,
|
||||
use_channel_type,
|
||||
punch_sender,
|
||||
peer_nat_info_map,
|
||||
nat_test,
|
||||
@@ -189,7 +186,7 @@ impl ClientPacketHandler {
|
||||
context.route_table.add_route(source, route);
|
||||
}
|
||||
ControlPacket::PunchRequest => {
|
||||
if self.use_channel_type.is_only_relay() {
|
||||
if context.use_channel_type().is_only_relay() {
|
||||
return Ok(());
|
||||
}
|
||||
//回应
|
||||
@@ -203,7 +200,7 @@ impl ClientPacketHandler {
|
||||
context.route_table.add_route_if_absent(source, route);
|
||||
}
|
||||
ControlPacket::PunchResponse => {
|
||||
if self.use_channel_type.is_only_relay() {
|
||||
if context.use_channel_type().is_only_relay() {
|
||||
return Ok(());
|
||||
}
|
||||
let route = Route::from(route_key, 1, 199);
|
||||
@@ -237,7 +234,7 @@ impl ClientPacketHandler {
|
||||
net_packet: NetPacket<&mut [u8]>,
|
||||
route_key: RouteKey,
|
||||
) -> io::Result<()> {
|
||||
if self.use_channel_type.is_only_relay() {
|
||||
if context.use_channel_type().is_only_relay() {
|
||||
return Ok(());
|
||||
}
|
||||
let source = net_packet.source();
|
||||
|
||||
@@ -12,7 +12,7 @@ use tun::Device;
|
||||
use crate::channel::context::Context;
|
||||
use crate::channel::handler::RecvChannelHandler;
|
||||
use crate::channel::punch::NatInfo;
|
||||
use crate::channel::{RouteKey, UseChannelType};
|
||||
use crate::channel::RouteKey;
|
||||
use crate::cipher::Cipher;
|
||||
#[cfg(feature = "server_encrypt")]
|
||||
use crate::cipher::RsaCipher;
|
||||
@@ -60,7 +60,6 @@ impl<Call: VntCallback> RecvDataHandler<Call> {
|
||||
config_info: BaseConfigInfo,
|
||||
nat_test: NatTest,
|
||||
callback: Call,
|
||||
use_channel_type: UseChannelType,
|
||||
punch_sender: SyncSender<(Ipv4Addr, NatInfo)>,
|
||||
peer_nat_info_map: Arc<RwLock<HashMap<Ipv4Addr, NatInfo>>>,
|
||||
external_route: ExternalRoute,
|
||||
@@ -83,7 +82,6 @@ impl<Call: VntCallback> RecvDataHandler<Call> {
|
||||
let client = ClientPacketHandler::new(
|
||||
device.clone(),
|
||||
client_cipher,
|
||||
use_channel_type,
|
||||
punch_sender,
|
||||
peer_nat_info_map,
|
||||
nat_test,
|
||||
|
||||
@@ -151,7 +151,9 @@ pub fn base_handle(
|
||||
client_cipher.encrypt_ipv4(&mut net_packet)?;
|
||||
//优先发到直连到地址
|
||||
if context.send_by_id(net_packet.buffer(), &dest_ip).is_err() {
|
||||
context.send_default(net_packet.buffer(), current_device.connect_server)?;
|
||||
if !context.use_channel_type().is_only_p2p() {
|
||||
context.send_default(net_packet.buffer(), current_device.connect_server)?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user