mirror of https://github.com/rapiz1/rathole.git
fix: set keepalive for noise
This commit is contained in:
parent
d409a839b4
commit
ae20ecf477
|
@ -1,11 +1,15 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use super::Transport;
|
use super::Transport;
|
||||||
use crate::config::{NoiseConfig, TransportConfig};
|
use crate::{
|
||||||
|
config::{NoiseConfig, TransportConfig},
|
||||||
|
helper::set_tcp_keepalive,
|
||||||
|
};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use snowstorm::{Builder, NoiseParams, NoiseStream};
|
use snowstorm::{Builder, NoiseParams, NoiseStream};
|
||||||
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
|
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
pub struct NoiseTransport {
|
pub struct NoiseTransport {
|
||||||
config: NoiseConfig,
|
config: NoiseConfig,
|
||||||
|
@ -76,6 +80,12 @@ impl Transport for NoiseTransport {
|
||||||
|
|
||||||
async fn connect(&self, addr: &str) -> Result<Self::Stream> {
|
async fn connect(&self, addr: &str) -> Result<Self::Stream> {
|
||||||
let conn = TcpStream::connect(addr).await?;
|
let conn = TcpStream::connect(addr).await?;
|
||||||
|
if let Err(e) = set_tcp_keepalive(&conn) {
|
||||||
|
error!(
|
||||||
|
"Failed to set TCP keepalive. The connection maybe unstable: {:?}",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
let conn = NoiseStream::handshake(conn, self.builder().build_initiator()?).await?;
|
let conn = NoiseStream::handshake(conn, self.builder().build_initiator()?).await?;
|
||||||
return Ok(conn);
|
return Ok(conn);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue