diff --git a/src/lib.rs b/src/lib.rs index 8a7d996..ad23844 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,10 @@ -use std::{collections::HashSet, future::Future, net::SocketAddr, pin::Pin, sync::Arc}; +use std::{ + collections::HashSet, + future::Future, + net::{IpAddr, SocketAddr}, + pin::Pin, + sync::Arc, +}; use anyhow::{Context, Result}; use askama::Template; @@ -18,7 +24,7 @@ async fn routes() -> Router { #[derive(Clone)] pub struct AppState { view_count: Arc>, - seen_ips: Arc>>, + seen_ips: Arc>>, } impl AppState { @@ -40,7 +46,7 @@ impl AppState { } } - async fn increment(&self, ip: SocketAddr) -> u32 { + async fn increment(&self, ip: IpAddr) -> u32 { if self.seen_ips.read().await.contains(&ip) { let view_count = self.view_count.read().await; return *view_count; @@ -99,8 +105,9 @@ async fn write_count(new_count: u32) -> anyhow::Result<()> { #[axum::debug_handler] pub async fn home( State(state): State, - ConnectInfo(ip): ConnectInfo, + ConnectInfo(addr): ConnectInfo, ) -> HomeTemplate { + let ip = addr.ip(); tracing::info!(ip = ip.to_string()); let view_count = state.increment(ip).await;