Добавить опциональную авторизацию клиента и динамические лимиты трафика

Сервер получает флаги --require-auth/--backend-url (по умолчанию выключено,
поведение уже развёрнутых нод не меняется). Auth-кадр хендшейка расширен с
"session_id:leg_id" до "session_id:leg_id:token"; при включённом
--require-auth сервер валидирует токен через новый AuthValidator
(BackendClient к netrunner-backend, с кешем на 60с).

Muxer теперь ведёт монотонный учёт трафика сессии (переживает реконнект
ног — раньше total_bytes мог занижаться после переподключения) и раз в ~30с
отчитывается бэкенду; при превышении лимита сессия разрывается. Токен
клиента прокидывается через EngineConfig/TunnelConfig до Tauri-плагина
(desktop.rs + Android Kotlin-плагин).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 00:31:03 +07:00
parent 99a9eee908
commit 40ddb0a0f6
14 changed files with 440 additions and 25 deletions
+3 -1
View File
@@ -120,6 +120,7 @@ impl SessionManager {
killswitch_enabled: bool,
excluded_apps: Vec<String>,
excluded_domains: Vec<String>,
auth_token: Option<String>,
) -> Arc<Session> {
netrunner_logger::Logger::init(None, false);
netrunner_logger::Logger::global().set_level("error");
@@ -136,7 +137,8 @@ impl SessionManager {
.with_killswitch(killswitch_enabled)
.with_excluded_apps(excluded_apps)
.with_excluded_domains(excluded_domains)
.with_decoy_sni(sni);
.with_decoy_sni(sni)
.with_auth_token(auth_token);
#[cfg(any(target_os = "android", target_os = "ios"))]
{
+12
View File
@@ -775,6 +775,11 @@ pub struct EngineConfig {
/// приходить динамически со списком серверов (вместе с их собственным
/// `--decoy-host`), чтобы клиент и сервер не расходились в выборе decoy-хоста.
pub decoy_sni: String,
/// Bearer-токен клиента (JWT, выданный `netrunner-backend` при логине) —
/// отправляется серверу в auth-кадре. `None`, если сервер не запущен с
/// `--require-auth` или приложение ещё не залогинено (Ghost Protocol seed
/// генерируется/логинится в фоне почти сразу, см. `netrunner-app/src/lib/api.ts`).
pub auth_token: Option<String>,
}
impl EngineConfig {
@@ -791,6 +796,7 @@ impl EngineConfig {
excluded_apps: Vec::new(),
excluded_domains: Vec::new(),
decoy_sni: netrunner_core::net::DEFAULT_DECOY_HOST.to_string(),
auth_token: None,
}
}
@@ -799,6 +805,11 @@ impl EngineConfig {
self
}
pub fn with_auth_token(mut self, auth_token: Option<String>) -> Self {
self.auth_token = auth_token;
self
}
pub fn with_cache_path(mut self, path: impl Into<String>) -> Self {
self.cache_path = path.into();
self
@@ -901,6 +912,7 @@ impl EngineBuilder {
let muxer = ClientHandler::connect(
&self.config.remote_address,
self.config.decoy_sni.clone(),
self.config.auth_token.clone(),
rx_for_client_handler,
tx_for_client_handler,
)
+2 -1
View File
@@ -17,7 +17,8 @@ interface SessionManager {
string cache_path,
boolean killswitch_enabled,
sequence<string> excluded_apps,
sequence<string> excluded_domains
sequence<string> excluded_domains,
string? auth_token
);
VpnTrafficStats get_traffic_stats();
};