Compliance: Server-side anti-proxy for trail authorization
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "Buffer.h"
|
||||
#define XXH_INLINE_ALL
|
||||
#include "common/xxhash.h"
|
||||
#include "common/LANChecker.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <common/ikcp.h>
|
||||
#include <atomic>
|
||||
@@ -378,6 +379,14 @@ public:
|
||||
std::atomic<int> IoRefCount{0}; // I/O 处理引用计数
|
||||
std::atomic<bool> IsRemoved{false}; // 标记是否已被标记为移除
|
||||
|
||||
// 内核测得的纯网络 RTT(μs),由 IOCPServer 的 RTT 轮询线程通过
|
||||
// WSAIoctl(SIO_TCP_INFO) 周期性写入;任何线程可通过 GetRttUs() 安全读取。
|
||||
// m_LastRttSampleMs == 0 表示从未成功采样过(OS 不支持或连接太短未轮询到)。
|
||||
std::atomic<uint32_t> m_RttUs{0};
|
||||
std::atomic<uint64_t> m_LastRttSampleMs{0};
|
||||
// 试用版反代理逐连接检测器。仅由 IOCPServer 的 RTT 轮询线程访问,免锁。
|
||||
TcpRttBreachDetector m_RttDetector;
|
||||
|
||||
// 子连接身份校验:客户端发 TOKEN_CONN_AUTH 通过验证后置位。
|
||||
// 主连接(走 TOKEN_LOGIN 流程)不参与此机制。当前阶段宽容(未通过也接受),
|
||||
// 仅作为标记供后续命令处理 / 未来收紧策略使用。
|
||||
@@ -517,9 +526,28 @@ public:
|
||||
IoRefCount.store(0, std::memory_order_release);
|
||||
// 复用对象池时清空校验状态
|
||||
m_bAuthenticated.store(false, std::memory_order_release);
|
||||
// 复用对象池时重置 RTT 相关状态,避免上一个连接的数据污染
|
||||
m_RttUs.store(0, std::memory_order_release);
|
||||
m_LastRttSampleMs.store(0, std::memory_order_release);
|
||||
m_RttDetector.Reset();
|
||||
}
|
||||
void SetAuthenticated(bool v) { m_bAuthenticated.store(v, std::memory_order_release); }
|
||||
bool IsAuthenticated() const { return m_bAuthenticated.load(std::memory_order_acquire); }
|
||||
|
||||
// 由 RTT 轮询线程写入。rttUs 为内核测得的纯网络 RTT(微秒)。
|
||||
void SetRttUs(uint32_t rttUs)
|
||||
{
|
||||
m_RttUs.store(rttUs, std::memory_order_release);
|
||||
m_LastRttSampleMs.store((uint64_t)GetTickCount64(), std::memory_order_release);
|
||||
}
|
||||
uint32_t GetRttUs() const { return m_RttUs.load(std::memory_order_acquire); }
|
||||
// 供 UI 展示用:μs → ms;样本超过 10 秒未更新(连接刚断/未轮询到)视为不可用,返回 -1。
|
||||
int GetRttMsForDisplay() const
|
||||
{
|
||||
uint64_t last = m_LastRttSampleMs.load(std::memory_order_acquire);
|
||||
if (last == 0 || (uint64_t)GetTickCount64() - last > 10000) return -1;
|
||||
return (int)((m_RttUs.load(std::memory_order_acquire) + 500) / 1000);
|
||||
}
|
||||
uint64_t GetAliveTime()const
|
||||
{
|
||||
return time(0) - OnlineTime;
|
||||
|
||||
Reference in New Issue
Block a user