mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-31 11:12:36 +01:00
stream table ip fixed
This commit is contained in:
@@ -14,6 +14,7 @@ use std::sync::Arc;
|
||||
use arc_swap::ArcSwapOption;
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
|
||||
use tokio::sync::RwLock;
|
||||
use crate::auth::Fingerprint;
|
||||
use crate::utils::GeoIp;
|
||||
|
||||
const USER_GC_TTL: u64 = 900; // 15 Min
|
||||
@@ -331,11 +332,11 @@ impl ActiveUserManager {
|
||||
Self::get_active_connections(&self.user).await
|
||||
}
|
||||
|
||||
pub async fn add_connection(&self, username: &str, max_connections: u32, addr: &str, provider: &str, stream_channel: StreamChannel, user_agent: Cow<'_, str>) -> UserConnectionGuard {
|
||||
pub async fn add_connection(&self, username: &str, max_connections: u32, fingerprint: &Fingerprint, provider: &str, stream_channel: StreamChannel, user_agent: Cow<'_, str>) -> UserConnectionGuard {
|
||||
let country = {
|
||||
let geoip = self.geo_ip.load();
|
||||
if let Some(geoip_db) = (*geoip).as_ref() {
|
||||
geoip_db.lookup(&strip_port(addr))
|
||||
geoip_db.lookup(&strip_port(&fingerprint.client_ip))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -343,7 +344,8 @@ impl ActiveUserManager {
|
||||
|
||||
let stream_info = StreamInfo::new(
|
||||
username,
|
||||
addr,
|
||||
&fingerprint.addr,
|
||||
&fingerprint.client_ip,
|
||||
provider,
|
||||
stream_channel,
|
||||
user_agent.to_string(),
|
||||
@@ -364,7 +366,7 @@ impl ActiveUserManager {
|
||||
|
||||
{
|
||||
let mut user_by_addr = self.user_by_addr.write().await;
|
||||
user_by_addr.insert(addr.to_string(), username.to_string());
|
||||
user_by_addr.insert(fingerprint.addr.to_string(), username.to_string());
|
||||
}
|
||||
|
||||
if let Err(err) = self.connection_change_tx.send(ActiveUserConnectionChange::Connected(stream_info)) {
|
||||
@@ -372,7 +374,7 @@ impl ActiveUserManager {
|
||||
}
|
||||
self.log_active_user().await;
|
||||
|
||||
UserConnectionGuard::new(Arc::new(self.clone_inner()), addr, self.release_sender())
|
||||
UserConnectionGuard::new(Arc::new(self.clone_inner()), &fingerprint.addr, self.release_sender())
|
||||
}
|
||||
|
||||
fn is_log_user_enabled(&self) -> bool {
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::task::{Poll};
|
||||
use axum::http::header::USER_AGENT;
|
||||
use axum::http::HeaderMap;
|
||||
use futures::task::AtomicWaker;
|
||||
use crate::auth::Fingerprint;
|
||||
|
||||
const INNER_STREAM: u8 = 0_u8;
|
||||
const GRACE_BLOCK_STREAM: u8 = 1_u8;
|
||||
@@ -40,7 +41,7 @@ impl ActiveClientStream {
|
||||
app_state: &AppState,
|
||||
user: &ProxyUserCredentials,
|
||||
connection_permission: UserConnectionPermission,
|
||||
addr: &str,
|
||||
fingerprint: &Fingerprint,
|
||||
stream_channel: StreamChannel,
|
||||
req_headers: &HeaderMap) -> Self {
|
||||
if connection_permission == UserConnectionPermission::Exhausted {
|
||||
@@ -51,11 +52,11 @@ impl ActiveClientStream {
|
||||
let provider_name = stream_details.provider_name.as_ref().map_or_else(String::new, ToString::to_string);
|
||||
|
||||
let user_agent = req_headers.get(USER_AGENT).map(|h| String::from_utf8_lossy(h.as_bytes())).unwrap_or_default();
|
||||
let user_connection_guard = Some(app_state.active_users.add_connection(username, user.max_connections, addr, &provider_name, stream_channel, user_agent).await);
|
||||
let user_connection_guard = Some(app_state.active_users.add_connection(username, user.max_connections, fingerprint, &provider_name, stream_channel, user_agent).await);
|
||||
let cfg = &app_state.app_config;
|
||||
let waker = Some(Arc::new(AtomicWaker::new()));
|
||||
let waker_clone = waker.clone();
|
||||
let grace_stop_flag = Self::stream_grace_period(app_state, &stream_details, grant_user_grace_period, user, addr, waker_clone.clone());
|
||||
let grace_stop_flag = Self::stream_grace_period(app_state, &stream_details, grant_user_grace_period, user, &fingerprint.addr, waker_clone.clone());
|
||||
let custom_response = cfg.custom_stream_response.load();
|
||||
let custom_video = custom_response.as_ref()
|
||||
.map_or((None, None), |c|
|
||||
|
||||
Reference in New Issue
Block a user