Set user's hostname to their IP address
Diff
src/client.rs | 4 +++-
src/connection.rs | 13 ++++++++++++-
src/main.rs | 2 +-
3 files changed, 15 insertions(+), 4 deletions(-)
@@ -66,7 +66,7 @@
ctx.run_interval(Duration::from_secs(30), |this, ctx| {
let _span = info_span!(parent: &this.span, "ping").entered();
if Instant::now().duration_since(this.last_active) > Duration::from_secs(120) {
if Instant::now().duration_since(this.last_active) >= Duration::from_secs(120) {
this.server_leave_reason = Some("Ping timeout: 120 seconds".to_string());
ctx.stop();
}
@@ -78,6 +78,8 @@
});
});
ctx.spawn(
self.persistence
.send(FetchUserChannels {
@@ -1,5 +1,6 @@
use std::{
io::{Error, ErrorKind},
net::SocketAddr,
str::FromStr,
};
@@ -30,6 +31,7 @@
#[derive(Default)]
pub struct ConnectionRequest {
host: Option<SocketAddr>,
nick: Option<String>,
user: Option<String>,
mode: Option<String>,
@@ -38,6 +40,7 @@
#[derive(Clone)]
pub struct InitiatedConnection {
pub host: SocketAddr,
pub nick: String,
pub user: String,
pub mode: String,
@@ -51,7 +54,7 @@
Prefix::Nickname(
self.nick.to_string(),
self.user.to_string(),
"my-host".to_string(),
self.host.ip().to_string(),
)
}
}
@@ -61,6 +64,7 @@
fn try_from(value: ConnectionRequest) -> Result<Self, Self::Error> {
let ConnectionRequest {
host: Some(host),
nick: Some(nick),
user: Some(user),
mode: Some(mode),
@@ -70,6 +74,7 @@
};
Ok(Self {
host,
nick,
user,
mode,
@@ -85,9 +90,13 @@
pub async fn negotiate_client_connection(
s: &mut MessageStream,
write: &mut tokio_util::codec::FramedWrite<WriteHalf<TcpStream>, IrcCodec>,
host: SocketAddr,
database: sqlx::Pool<sqlx::Any>,
) -> Result<Option<InitiatedConnection>, ProtocolError> {
let mut request = ConnectionRequest::default();
let mut request = ConnectionRequest {
host: Some(host),
..ConnectionRequest::default()
};
let mut capabilities_requested = false;
@@ -147,7 +147,7 @@
let Some(connection) = connection::negotiate_client_connection(&mut read, &mut write, database).await.unwrap() else {
let Some(connection) = connection::negotiate_client_connection(&mut read, &mut write, addr, database).await.unwrap() else {
error!("Failed to fully handshake with client, dropping connection");
return;
};