mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
bump version to v2.5.0 (#1715)
This commit is contained in:
@@ -432,7 +432,7 @@ impl StunNatTypeDetectResult {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_pat(&self) -> bool {
|
||||
fn is_no_pat(&self) -> bool {
|
||||
for resp in self.stun_resps.iter() {
|
||||
if resp.mapped_socket_addr.map(|x| x.port()) == Some(self.source_addr.port()) {
|
||||
return true;
|
||||
@@ -470,7 +470,7 @@ impl StunNatTypeDetectResult {
|
||||
if self.has_ip_changed_resp() {
|
||||
if self.is_open_internet() {
|
||||
NatType::OpenInternet
|
||||
} else if self.is_pat() {
|
||||
} else if self.is_no_pat() {
|
||||
NatType::NoPat
|
||||
} else {
|
||||
NatType::FullCone
|
||||
@@ -522,7 +522,7 @@ impl StunNatTypeDetectResult {
|
||||
}
|
||||
|
||||
if self.is_cone() {
|
||||
if self.is_pat() {
|
||||
if self.is_no_pat() {
|
||||
NatType::NoPat
|
||||
} else {
|
||||
NatType::FullCone
|
||||
@@ -802,8 +802,6 @@ impl TcpStunClient {
|
||||
|
||||
#[tracing::instrument(ret, level = Level::TRACE)]
|
||||
pub async fn bind_request(self) -> Result<BindRequestResponse, Error> {
|
||||
let mut tids = vec![];
|
||||
|
||||
let mut stream = self.connect().await?;
|
||||
let local_addr = stream.local_addr()?;
|
||||
let stun_host = self.stun_server;
|
||||
@@ -814,14 +812,13 @@ impl TcpStunClient {
|
||||
let msg = encoder
|
||||
.encode_into_bytes(message.clone())
|
||||
.with_context(|| "encode tcp stun message")?;
|
||||
tids.push(tid);
|
||||
tokio::time::timeout(self.io_timeout, stream.write_all(msg.as_slice())).await??;
|
||||
|
||||
let now = Instant::now();
|
||||
let msg = Self::tcp_read_stun_message(&mut stream, self.io_timeout).await?;
|
||||
if msg.class() != MessageClass::SuccessResponse
|
||||
|| msg.method() != BINDING
|
||||
|| !tids.contains(&tid_to_u32(&msg.transaction_id()))
|
||||
|| tid_to_u32(&msg.transaction_id()) != tid
|
||||
{
|
||||
return Err(Error::MessageDecodeError(
|
||||
"unexpected stun response".to_string(),
|
||||
|
||||
@@ -24,7 +24,6 @@ use crate::{
|
||||
rpc_types::{self, controller::BaseController},
|
||||
},
|
||||
tunnel::{
|
||||
common::setup_sokcet2,
|
||||
tcp::{TcpTunnelConnector, TcpTunnelListener},
|
||||
TunnelConnector as _, TunnelListener as _,
|
||||
},
|
||||
@@ -73,36 +72,6 @@ async fn select_local_port(peer_mgr: &Arc<PeerManager>, is_v6: bool) -> Result<u
|
||||
Ok(port)
|
||||
}
|
||||
|
||||
async fn send_syn_from_port(
|
||||
peer_mgr: &Arc<PeerManager>,
|
||||
local_port: u16,
|
||||
dst: SocketAddr,
|
||||
) -> Result<(), Error> {
|
||||
let bind_addr = bind_addr_for_port(local_port, dst.is_ipv6());
|
||||
tracing::debug!(?bind_addr, ?dst, "tcp hole punch send syn");
|
||||
let _g = peer_mgr.get_global_ctx().net_ns.guard();
|
||||
|
||||
let socket2_socket = socket2::Socket::new(
|
||||
socket2::Domain::for_address(dst),
|
||||
socket2::Type::STREAM,
|
||||
Some(socket2::Protocol::TCP),
|
||||
)?;
|
||||
setup_sokcet2(&socket2_socket, &bind_addr)?;
|
||||
let socket = tokio::net::TcpSocket::from_std_stream(socket2_socket.into());
|
||||
match tokio::time::timeout(Duration::from_millis(600), socket.connect(dst)).await {
|
||||
Ok(Ok(_stream)) => {
|
||||
tracing::trace!(?bind_addr, ?dst, "tcp hole punch syn connect succeeded");
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
tracing::trace!(?bind_addr, ?dst, ?e, "tcp hole punch syn connect failed");
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::trace!(?bind_addr, ?dst, ?e, "tcp hole punch syn connect timeout");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// tcp support simultaneous connect, so initiator and server can both use connect.
|
||||
async fn try_connect_to_remote(
|
||||
peer_mgr: Arc<PeerManager>,
|
||||
@@ -576,8 +545,13 @@ impl TcpHolePunchConnector {
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<(), Error> {
|
||||
if self.peer_mgr.get_global_ctx().get_flags().disable_p2p {
|
||||
tracing::debug!("tcp hole punch disabled by disable_p2p");
|
||||
let flags = self.peer_mgr.get_global_ctx().get_flags();
|
||||
if flags.disable_p2p || flags.disable_tcp_hole_punching {
|
||||
tracing::debug!(
|
||||
"tcp hole punch disabled by disable_p2p(={}) or disable_tcp_hole_punching(={});",
|
||||
flags.disable_p2p,
|
||||
flags.disable_tcp_hole_punching
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,12 @@ fn get_or_create_worker(interface_name: &str) -> io::Result<Arc<InterfaceWorker>
|
||||
let interface = interfaces
|
||||
.into_iter()
|
||||
.find(|iface| iface.name == interface_name)
|
||||
.expect("Network interface not found");
|
||||
.ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("Network interface '{}' not found", interface_name),
|
||||
)
|
||||
})?;
|
||||
|
||||
let worker = InterfaceWorker::new(interface)?;
|
||||
INTERFACE_MANAGERS.insert(interface_name.to_string(), Arc::downgrade(&worker));
|
||||
|
||||
Reference in New Issue
Block a user