fmt
This commit is contained in:
parent
48b18293a5
commit
8a5d89885a
3 changed files with 8 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wstunnel"
|
name = "wstunnel"
|
||||||
version = "7.8.1"
|
version = "7.8.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/erebe/wstunnel.git"
|
repository = "https://github.com/erebe/wstunnel.git"
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::{JwtTunnelConfig, JWT_DECODE};
|
use super::{JwtTunnelConfig, JWT_DECODE};
|
||||||
use crate::{tcp, tls, LocalProtocol, WsServerConfig, udp};
|
use crate::{tcp, tls, udp, LocalProtocol, WsServerConfig};
|
||||||
use hyper::server::conn::Http;
|
use hyper::server::conn::Http;
|
||||||
use hyper::service::service_fn;
|
use hyper::service::service_fn;
|
||||||
use hyper::{http, Body, Request, Response, StatusCode};
|
use hyper::{http, Body, Request, Response, StatusCode};
|
||||||
use jsonwebtoken::TokenData;
|
use jsonwebtoken::TokenData;
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio::net::{TcpListener};
|
use tokio::net::TcpListener;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tracing::{error, info, span, warn, Instrument, Level, Span};
|
use tracing::{error, info, span, warn, Instrument, Level, Span};
|
||||||
use url::Host;
|
use url::Host;
|
||||||
|
|
20
src/udp.rs
20
src/udp.rs
|
@ -9,17 +9,17 @@ use std::io;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||||
|
|
||||||
|
use log::warn;
|
||||||
use std::pin::{pin, Pin};
|
use std::pin::{pin, Pin};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::task::{ready, Poll};
|
use std::task::{ready, Poll};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use log::warn;
|
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
use tokio::sync::futures::Notified;
|
use tokio::sync::futures::Notified;
|
||||||
|
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
use tokio::time::{Sleep, timeout};
|
use tokio::time::{timeout, Sleep};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
use url::Host;
|
use url::Host;
|
||||||
|
|
||||||
|
@ -248,11 +248,7 @@ impl AsyncWrite for MyUdpSocket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(
|
pub async fn connect(host: &Host<String>, port: u16, connect_timeout: Duration) -> anyhow::Result<MyUdpSocket> {
|
||||||
host: &Host<String>,
|
|
||||||
port: u16,
|
|
||||||
connect_timeout: Duration,
|
|
||||||
) -> anyhow::Result<MyUdpSocket> {
|
|
||||||
info!("Opening UDP connection to {}:{}", host, port);
|
info!("Opening UDP connection to {}:{}", host, port);
|
||||||
|
|
||||||
let socket_addrs: Vec<SocketAddr> = match host {
|
let socket_addrs: Vec<SocketAddr> = match host {
|
||||||
|
@ -264,7 +260,6 @@ pub async fn connect(
|
||||||
Host::Ipv6(ip) => vec![SocketAddr::V6(SocketAddrV6::new(*ip, port, 0, 0))],
|
Host::Ipv6(ip) => vec![SocketAddr::V6(SocketAddrV6::new(*ip, port, 0, 0))],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let mut cnx = None;
|
let mut cnx = None;
|
||||||
let mut last_err = None;
|
let mut last_err = None;
|
||||||
for addr in socket_addrs {
|
for addr in socket_addrs {
|
||||||
|
@ -280,7 +275,7 @@ pub async fn connect(
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("cannot bind udp socket {:?}", err);
|
warn!("cannot bind udp socket {:?}", err);
|
||||||
continue;
|
continue;
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match timeout(connect_timeout, socket.connect(addr)).await {
|
match timeout(connect_timeout, socket.connect(addr)).await {
|
||||||
|
@ -304,12 +299,7 @@ pub async fn connect(
|
||||||
if let Some(cnx) = cnx {
|
if let Some(cnx) = cnx {
|
||||||
Ok(MyUdpSocket::new(Arc::new(cnx)))
|
Ok(MyUdpSocket::new(Arc::new(cnx)))
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!(
|
Err(anyhow!("Cannot connect to udp peer {}:{} reason {:?}", host, port, last_err))
|
||||||
"Cannot connect to udp peer {}:{} reason {:?}",
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
last_err
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue