node: Set socket options for inbounds too
We were only setting socket options for outbound connections.
This commit is contained in:
parent
3403a66d0f
commit
90deb20405
|
|
@ -546,7 +546,14 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let session = accept::<G>(remote.clone().into(), connection, self.signer.clone());
|
let session =
|
||||||
|
match accept::<G>(remote.clone().into(), connection, self.signer.clone()) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!(target: "wire", "Error creating session for {ip}: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
let transport = match NetTransport::with_session(session, Link::Inbound) {
|
let transport = match NetTransport::with_session(session, Link::Inbound) {
|
||||||
Ok(transport) => transport,
|
Ok(transport) => transport,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -1141,21 +1148,13 @@ pub fn dial<G: Signer + Ecdh<Pk = NodeId>>(
|
||||||
// `socket2` library not supporting non-blocking connect with timeout.
|
// `socket2` library not supporting non-blocking connect with timeout.
|
||||||
let connection = net::TcpStream::connect_nonblocking(inet_addr, DEFAULT_DIAL_TIMEOUT)?;
|
let connection = net::TcpStream::connect_nonblocking(inet_addr, DEFAULT_DIAL_TIMEOUT)?;
|
||||||
|
|
||||||
connection.set_read_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;
|
session::<G>(
|
||||||
connection.set_write_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;
|
|
||||||
|
|
||||||
// There are issues with setting TCP_NODELAY on WSL. Not a big deal.
|
|
||||||
if let Err(e) = connection.set_nodelay(true) {
|
|
||||||
log::warn!(target: "wire", "Unable to set TCP_NODELAY on fd {}: {e}", connection.as_raw_fd());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(session::<G>(
|
|
||||||
remote_addr,
|
remote_addr,
|
||||||
Some(remote_id),
|
Some(remote_id),
|
||||||
connection,
|
connection,
|
||||||
force_proxy,
|
force_proxy,
|
||||||
signer,
|
signer,
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept a new connection.
|
/// Accept a new connection.
|
||||||
|
|
@ -1163,7 +1162,7 @@ pub fn accept<G: Signer + Ecdh<Pk = NodeId>>(
|
||||||
remote_addr: NetAddr<HostName>,
|
remote_addr: NetAddr<HostName>,
|
||||||
connection: net::TcpStream,
|
connection: net::TcpStream,
|
||||||
signer: G,
|
signer: G,
|
||||||
) -> WireSession<G> {
|
) -> io::Result<WireSession<G>> {
|
||||||
session::<G>(remote_addr, None, connection, false, signer)
|
session::<G>(remote_addr, None, connection, false, signer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1174,7 +1173,14 @@ fn session<G: Signer + Ecdh<Pk = NodeId>>(
|
||||||
connection: net::TcpStream,
|
connection: net::TcpStream,
|
||||||
force_proxy: bool,
|
force_proxy: bool,
|
||||||
signer: G,
|
signer: G,
|
||||||
) -> WireSession<G> {
|
) -> io::Result<WireSession<G>> {
|
||||||
|
// There are issues with setting TCP_NODELAY on WSL. Not a big deal.
|
||||||
|
if let Err(e) = connection.set_nodelay(true) {
|
||||||
|
log::warn!(target: "wire", "Unable to set TCP_NODELAY on fd {}: {e}", connection.as_raw_fd());
|
||||||
|
}
|
||||||
|
connection.set_read_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;
|
||||||
|
connection.set_write_timeout(Some(DEFAULT_CONNECTION_TIMEOUT))?;
|
||||||
|
|
||||||
let socks5 = socks5::Socks5::with(remote_addr, force_proxy);
|
let socks5 = socks5::Socks5::with(remote_addr, force_proxy);
|
||||||
let proxy = Socks5Session::with(connection, socks5);
|
let proxy = Socks5Session::with(connection, socks5);
|
||||||
let pair = G::generate_keypair();
|
let pair = G::generate_keypair();
|
||||||
|
|
@ -1184,14 +1190,13 @@ fn session<G: Signer + Ecdh<Pk = NodeId>>(
|
||||||
re: None,
|
re: None,
|
||||||
rs: remote_id,
|
rs: remote_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let noise = NoiseState::initialize::<{ Sha256::OUTPUT_LEN }>(
|
let noise = NoiseState::initialize::<{ Sha256::OUTPUT_LEN }>(
|
||||||
NOISE_XK,
|
NOISE_XK,
|
||||||
remote_id.is_some(),
|
remote_id.is_some(),
|
||||||
&[],
|
&[],
|
||||||
keyset,
|
keyset,
|
||||||
);
|
);
|
||||||
WireSession::with(proxy, noise)
|
Ok(WireSession::with(proxy, noise))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue