Merge branch 'main' into feat/renew-ui

This commit is contained in:
m1m1sha 2024-10-08 19:14:35 +08:00 committed by GitHub
commit 3bcc30807a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 51 additions and 26 deletions

View File

@ -542,7 +542,7 @@ declare global {
// for type re-export // for type re-export
declare global { declare global {
// @ts-ignore // @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
import('vue') import('vue')
// @ts-ignore // @ts-ignore
export type { DependencyType } from './components/ui/auto-form/interface' export type { DependencyType } from './components/ui/auto-form/interface'
@ -840,11 +840,8 @@ declare module 'vue' {
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']> readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']> readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
readonly onWatcherCleanup: UnwrapRef<typeof import('vue')['onWatcherCleanup']> readonly onWatcherCleanup: UnwrapRef<typeof import('vue')['onWatcherCleanup']>
readonly parseNetworkStrConfig: UnwrapRef<typeof import('./composables/instance')['parseNetworkStrConfig']> readonly parseNetworkConfig: UnwrapRef<typeof import('./composables/network')['parseNetworkConfig']>
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']> readonly prepareVpnService: UnwrapRef<typeof import('./composables/mobile_vpn')['prepareVpnService']>
readonly pkg: UnwrapRef<typeof import('./composables/utils')['pkg']>
readonly platformIsMobile: UnwrapRef<typeof import('./composables/mobile')['platformIsMobile']>
readonly prepareVpnService: UnwrapRef<typeof import('./composables/mobileVpn')['prepareVpnService']>
readonly provide: UnwrapRef<typeof import('vue')['provide']> readonly provide: UnwrapRef<typeof import('vue')['provide']>
readonly provideDependencies: UnwrapRef<typeof import('./components/ui/auto-form/dependencies')['provideDependencies']> readonly provideDependencies: UnwrapRef<typeof import('./components/ui/auto-form/dependencies')['provideDependencies']>
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']> readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>

View File

@ -46,8 +46,8 @@ impl WindowsBuild {
fn download_protoc() -> PathBuf { fn download_protoc() -> PathBuf {
println!("cargo:info=use exist protoc: {:?}", "k"); println!("cargo:info=use exist protoc: {:?}", "k");
let out_dir = Self::get_cargo_target_dir().unwrap(); let out_dir = Self::get_cargo_target_dir().unwrap().join("protobuf");
let fname = out_dir.join("protoc"); let fname = out_dir.join("bin/protoc.exe");
if fname.exists() { if fname.exists() {
println!("cargo:info=use exist protoc: {:?}", fname); println!("cargo:info=use exist protoc: {:?}", fname);
return fname; return fname;
@ -65,10 +65,7 @@ impl WindowsBuild {
.map(zip::ZipArchive::new) .map(zip::ZipArchive::new)
.unwrap() .unwrap()
.unwrap(); .unwrap();
let protoc_zipped_file = content.by_name("bin/protoc.exe").unwrap(); content.extract(out_dir).unwrap();
let mut content = protoc_zipped_file;
copy(&mut content, &mut File::create(&fname).unwrap()).unwrap();
fname fname
} }

View File

@ -14,7 +14,7 @@ use zerocopy::FromBytes as _;
use crate::{ use crate::{
common::{ common::{
error::Error, global_ctx::ArcGlobalCtx, join_joinset_background, netns::NetNS, error::Error, global_ctx::ArcGlobalCtx, join_joinset_background, netns::NetNS,
stun::StunInfoCollectorTrait as _, stun::StunInfoCollectorTrait as _, PeerId,
}, },
defer, defer,
peers::peer_manager::PeerManager, peers::peer_manager::PeerManager,
@ -158,11 +158,17 @@ impl UdpNatType {
unreachable!("invalid nat type"); unreachable!("invalid nat type");
} }
pub(crate) fn can_punch_hole_as_client(&self, other: Self) -> bool { pub(crate) fn can_punch_hole_as_client(
!matches!( &self,
self.get_punch_hole_method(other), other: Self,
UdpPunchClientMethod::None my_peer_id: PeerId,
) dst_peer_id: PeerId,
) -> bool {
match self.get_punch_hole_method(other) {
UdpPunchClientMethod::None => false,
UdpPunchClientMethod::ConeToCone | UdpPunchClientMethod::SymToCone => true,
UdpPunchClientMethod::EasySymToEasySym => my_peer_id < dst_peer_id,
}
} }
} }

View File

@ -1,9 +1,11 @@
use std::sync::Arc; use std::sync::Arc;
use anyhow::Error; use anyhow::{Context, Error};
use both_easy_sym::{PunchBothEasySymHoleClient, PunchBothEasySymHoleServer}; use both_easy_sym::{PunchBothEasySymHoleClient, PunchBothEasySymHoleServer};
use common::{PunchHoleServerCommon, UdpNatType, UdpPunchClientMethod}; use common::{PunchHoleServerCommon, UdpNatType, UdpPunchClientMethod};
use cone::{PunchConeHoleClient, PunchConeHoleServer}; use cone::{PunchConeHoleClient, PunchConeHoleServer};
use dashmap::DashMap;
use once_cell::sync::Lazy;
use sym_to_cone::{PunchSymToConeHoleClient, PunchSymToConeHoleServer}; use sym_to_cone::{PunchSymToConeHoleClient, PunchSymToConeHoleServer};
use tokio::{sync::Mutex, task::JoinHandle}; use tokio::{sync::Mutex, task::JoinHandle};
@ -32,6 +34,17 @@ pub(crate) mod common;
pub(crate) mod cone; pub(crate) mod cone;
pub(crate) mod sym_to_cone; pub(crate) mod sym_to_cone;
// sym punch should be serialized
static SYM_PUNCH_LOCK: Lazy<DashMap<PeerId, Arc<Mutex<()>>>> = Lazy::new(|| DashMap::new());
fn get_sym_punch_lock(peer_id: PeerId) -> Arc<Mutex<()>> {
SYM_PUNCH_LOCK
.entry(peer_id)
.or_insert_with(|| Arc::new(Mutex::new(())))
.value()
.clone()
}
struct UdpHolePunchServer { struct UdpHolePunchServer {
common: Arc<PunchHoleServerCommon>, common: Arc<PunchHoleServerCommon>,
cone_server: PunchConeHoleServer, cone_server: PunchConeHoleServer,
@ -112,6 +125,9 @@ impl UdpHolePunchRpc for UdpHolePunchServer {
_ctrl: Self::Controller, _ctrl: Self::Controller,
input: SendPunchPacketBothEasySymRequest, input: SendPunchPacketBothEasySymRequest,
) -> rpc_types::error::Result<SendPunchPacketBothEasySymResponse> { ) -> rpc_types::error::Result<SendPunchPacketBothEasySymResponse> {
let _locked = get_sym_punch_lock(self.common.get_peer_mgr().my_peer_id())
.try_lock_owned()
.with_context(|| "sym punch lock is busy")?;
self.both_easy_sym_server self.both_easy_sym_server
.send_punch_packet_both_easy_sym(input) .send_punch_packet_both_easy_sym(input)
.await .await
@ -154,9 +170,6 @@ struct UdpHoePunchConnectorData {
sym_to_cone_client: PunchSymToConeHoleClient, sym_to_cone_client: PunchSymToConeHoleClient,
both_easy_sym_client: PunchBothEasySymHoleClient, both_easy_sym_client: PunchBothEasySymHoleClient,
peer_mgr: Arc<PeerManager>, peer_mgr: Arc<PeerManager>,
// sym punch should be serialized
sym_punch_lock: Mutex<()>,
} }
impl UdpHoePunchConnectorData { impl UdpHoePunchConnectorData {
@ -170,7 +183,6 @@ impl UdpHoePunchConnectorData {
sym_to_cone_client, sym_to_cone_client,
both_easy_sym_client, both_easy_sym_client,
peer_mgr, peer_mgr,
sym_punch_lock: Mutex::new(()),
}) })
} }
@ -212,7 +224,9 @@ impl UdpHoePunchConnectorData {
backoff.sleep_for_next_backoff().await; backoff.sleep_for_next_backoff().await;
let ret = { let ret = {
let _lock = self.sym_punch_lock.lock().await; let _lock = get_sym_punch_lock(self.peer_mgr.my_peer_id())
.lock_owned()
.await;
self.sym_to_cone_client self.sym_to_cone_client
.do_hole_punching( .do_hole_punching(
task_info.dst_peer_id, task_info.dst_peer_id,
@ -251,7 +265,9 @@ impl UdpHoePunchConnectorData {
let mut is_busy = false; let mut is_busy = false;
let ret = { let ret = {
let _lock = self.sym_punch_lock.lock().await; let _lock = get_sym_punch_lock(self.peer_mgr.my_peer_id())
.lock_owned()
.await;
self.both_easy_sym_client self.both_easy_sym_client
.do_hole_punching( .do_hole_punching(
task_info.dst_peer_id, task_info.dst_peer_id,
@ -325,6 +341,8 @@ impl PeerTaskLauncher for UdpHolePunchPeerTaskLauncher {
return peers_to_connect; return peers_to_connect;
} }
let my_peer_id = data.peer_mgr.my_peer_id();
// collect peer list from peer manager and do some filter: // collect peer list from peer manager and do some filter:
// 1. peers without direct conns; // 1. peers without direct conns;
// 2. peers is full cone (any restricted type); // 2. peers is full cone (any restricted type);
@ -353,7 +371,7 @@ impl PeerTaskLauncher for UdpHolePunchPeerTaskLauncher {
continue; continue;
} }
if !my_nat_type.can_punch_hole_as_client(peer_nat_type) { if !my_nat_type.can_punch_hole_as_client(peer_nat_type, my_peer_id, peer_id) {
continue; continue;
} }

View File

@ -441,6 +441,7 @@ pub mod tests {
}; };
#[tokio::test] #[tokio::test]
#[serial_test::serial(hole_punch)]
async fn hole_punching_symmetric_only_random() { async fn hole_punching_symmetric_only_random() {
let p_a = create_mock_peer_manager_with_mock_stun(NatType::Symmetric).await; let p_a = create_mock_peer_manager_with_mock_stun(NatType::Symmetric).await;
let p_b = create_mock_peer_manager_with_mock_stun(NatType::PortRestricted).await; let p_b = create_mock_peer_manager_with_mock_stun(NatType::PortRestricted).await;

View File

@ -55,6 +55,12 @@ if ! command -v unzip >/dev/null 2>&1; then
exit 1 exit 1
fi fi
# check if curl is installed
if ! command -v curl >/dev/null 2>&1; then
echo -e "\r\n${RED_COLOR}Error: curl is not installed${RES}\r\n"
exit 1
fi
echo -e "\r\n${RED_COLOR}----------------------NOTICE----------------------${RES}\r\n" echo -e "\r\n${RED_COLOR}----------------------NOTICE----------------------${RES}\r\n"
echo " This is a temporary script to install EasyTier " echo " This is a temporary script to install EasyTier "
echo " EasyTier requires a dedicated empty folder to install" echo " EasyTier requires a dedicated empty folder to install"