fix dns-resolver cmd line parsing
This commit is contained in:
parent
817571c907
commit
bffd2470e7
3 changed files with 16 additions and 5 deletions
|
@ -852,7 +852,13 @@ async fn main() {
|
||||||
_ => panic!("invalid protocol for dns resolver"),
|
_ => panic!("invalid protocol for dns resolver"),
|
||||||
};
|
};
|
||||||
let sock = match resolver.host().unwrap() {
|
let sock = match resolver.host().unwrap() {
|
||||||
Host::Domain(_) => panic!("Dns resolver must be an ip address"),
|
Host::Domain(host) => match Host::parse(host) {
|
||||||
|
Ok(Host::Ipv4(ip)) => SocketAddr::V4(SocketAddrV4::new(ip, port)),
|
||||||
|
Ok(Host::Ipv6(ip)) => SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)),
|
||||||
|
Ok(Host::Domain(_)) | Err(_) => {
|
||||||
|
panic!("Dns resolver must be an ip address, got {}", host)
|
||||||
|
}
|
||||||
|
},
|
||||||
Host::Ipv4(ip) => SocketAddr::V4(SocketAddrV4::new(ip, port)),
|
Host::Ipv4(ip) => SocketAddr::V4(SocketAddrV4::new(ip, port)),
|
||||||
Host::Ipv6(ip) => SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)),
|
Host::Ipv6(ip) => SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0)),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::cmp::max;
|
|
||||||
use fastwebsockets::{Frame, OpCode, Payload, WebSocketError, WebSocketRead, WebSocketWrite};
|
use fastwebsockets::{Frame, OpCode, Payload, WebSocketError, WebSocketRead, WebSocketWrite};
|
||||||
use futures_util::{pin_mut, FutureExt};
|
use futures_util::{pin_mut, FutureExt};
|
||||||
use hyper::upgrade::Upgraded;
|
use hyper::upgrade::Upgraded;
|
||||||
|
@ -23,7 +22,7 @@ pub(super) async fn propagate_read(
|
||||||
});
|
});
|
||||||
|
|
||||||
static MAX_PACKET_LENGTH: usize = 64 * 1024;
|
static MAX_PACKET_LENGTH: usize = 64 * 1024;
|
||||||
let mut buffer = vec![0u8; MAX_PACKET_LENGTH * 1];
|
let mut buffer = vec![0u8; MAX_PACKET_LENGTH];
|
||||||
|
|
||||||
// We do our own pin_mut! to avoid shadowing timeout and be able to reset it, on next loop iteration
|
// We do our own pin_mut! to avoid shadowing timeout and be able to reset it, on next loop iteration
|
||||||
// We reuse the future to avoid creating a timer in the tight loop
|
// We reuse the future to avoid creating a timer in the tight loop
|
||||||
|
@ -77,7 +76,13 @@ pub(super) async fn propagate_read(
|
||||||
let new_size = buffer.capacity() + (buffer.capacity() / 4); // grow buffer by 1.25 %
|
let new_size = buffer.capacity() + (buffer.capacity() / 4); // grow buffer by 1.25 %
|
||||||
buffer.reserve_exact(new_size);
|
buffer.reserve_exact(new_size);
|
||||||
buffer.resize(buffer.capacity(), 0);
|
buffer.resize(buffer.capacity(), 0);
|
||||||
//info!("Buffer {} Mb {} {} {}", buffer.capacity() as f64 / 1024.0 / 1024.0, new_size, buffer.as_slice().len(), buffer.capacity())
|
trace!(
|
||||||
|
"Buffer {} Mb {} {} {}",
|
||||||
|
buffer.capacity() as f64 / 1024.0 / 1024.0,
|
||||||
|
new_size,
|
||||||
|
buffer.as_slice().len(),
|
||||||
|
buffer.capacity()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ async fn server_upgrade(server_config: Arc<WsServerConfig>, mut req: Request<Inc
|
||||||
|
|
||||||
if protocol == LocalProtocol::ReverseSocks5 {
|
if protocol == LocalProtocol::ReverseSocks5 {
|
||||||
let Ok(header_val) = HeaderValue::from_str(
|
let Ok(header_val) = HeaderValue::from_str(
|
||||||
&base64::engine::general_purpose::STANDARD.encode(format!("fake://{}:{}", dest, port)),
|
&base64::engine::general_purpose::STANDARD.encode(format!("https://{}:{}", dest, port)),
|
||||||
) else {
|
) else {
|
||||||
error!("Bad headervalue for reverse socks5: {} {}", dest, port);
|
error!("Bad headervalue for reverse socks5: {} {}", dest, port);
|
||||||
return http::Response::builder()
|
return http::Response::builder()
|
||||||
|
|
Loading…
Reference in a new issue