Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/defguard_core/src/grpc/gateway/client_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, net::IpAddr};
use std::{collections::HashMap, net::SocketAddr};

use chrono::{NaiveDateTime, TimeDelta, Utc};
use thiserror::Error;
Expand Down Expand Up @@ -31,8 +31,8 @@ pub struct ClientState {
pub device: Device<Id>,
pub user_id: Id,
pub username: String,
// current IP from which the client is connecting
pub endpoint: IpAddr,
// current IP & port from which the client is connecting
pub endpoint: SocketAddr,
pub latest_handshake: NaiveDateTime,
// when last stats update was received
pub latest_update: NaiveDateTime,
Expand All @@ -46,7 +46,7 @@ impl ClientState {
pub fn new(
device: Device<Id>,
user: &User<Id>,
endpoint: IpAddr,
endpoint: SocketAddr,
latest_handshake: NaiveDateTime,
total_upload: i64,
total_download: i64,
Expand All @@ -67,7 +67,7 @@ impl ClientState {
pub fn update_client_state(
&mut self,
current_device: Device<Id>,
current_endpoint: IpAddr,
current_endpoint: SocketAddr,
latest_handshake: NaiveDateTime,
upload: i64,
download: i64,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl ClientMap {
public_key: &str,
device: &Device<Id>,
user: &User<Id>,
endpoint: IpAddr,
endpoint: SocketAddr,
stats: &WireguardPeerStats,
) -> Result<(), ClientMapError> {
info!(
Expand Down Expand Up @@ -182,7 +182,7 @@ impl ClientMap {
let disconnect_event_context = GrpcRequestContext::new(
client_state.user_id,
client_state.username.clone(),
client_state.endpoint,
client_state.endpoint.ip(),
client_state.device.id,
client_state.device.name.clone(),
);
Expand Down
10 changes: 5 additions & 5 deletions crates/defguard_core/src/grpc/gateway/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod client_state;
use std::{
net::IpAddr,
net::{IpAddr, SocketAddr},
pin::Pin,
sync::{Arc, Mutex},
task::{Context, Poll},
Expand Down Expand Up @@ -755,7 +755,7 @@ impl gateway_service_server::GatewayService for GatewayServer {
// but has not connected yet
if let Some(endpoint) = &stats.endpoint {
// parse client endpoint IP
let ip_addr = endpoint.clone().parse().map_err(|err| {
let socket_addr: SocketAddr = endpoint.clone().parse().map_err(|err| {
error!("Failed to parse VPN client endpoint: {err}");
Status::new(
Code::Internal,
Expand All @@ -774,7 +774,7 @@ impl gateway_service_server::GatewayService for GatewayServer {
// update connected client state
client_state.update_client_state(
device,
ip_addr,
socket_addr,
stats.latest_handshake,
stats.upload,
stats.download,
Expand All @@ -788,15 +788,15 @@ impl gateway_service_server::GatewayService for GatewayServer {
&public_key,
&device,
&user,
ip_addr,
socket_addr,
&stats,
)?;

// emit connection event
let context = GrpcRequestContext::new(
user.id,
user.username.clone(),
ip_addr,
socket_addr.ip(),
device.id,
device.name.clone(),
);
Expand Down