Fix: throttle TLS/WS handshake failure logs
Exposed ports see a constant stream of scanners and HTTP probes. Every TLS handshake attempt logged an ioctlsocket(FIONBIO=0) failure, but WSAEINVAL is the documented result once WSAEventSelect owns the listening socket and the code already falls back to select; that line alone accounted for 6678 of the 8970 "handshake" lines in a four-day log. It is now logged only for other error codes. A failed handshake used to print three or four lines (recv EOF, AcceptSecurityContext, final status, failed-for-IP) with no per-peer dedup, and WS upgrade failures printed once per HTTP probe. ServerTlsSession now records a human-readable reason (Schannel status name for ASC failures) instead of logging per connection; IOCPServer prints one line per peer per hour with the reason and a suppressed count, for both TLS and WS. Peer close_notify is a normal shutdown and is no longer logged; MCP TLS failures now carry the same reason. Failure details are copied before the context's I/O reference is released, so the log path cannot touch a context that another thread may recycle. No handshake, crypto or connection behaviour changes. Verified with a Debug x64 build and a live probe run: six failed connections to the device port produced exactly one TLS and one WS line, with no ioctlsocket lines. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
3d2dd08be5
commit
5ee59415f9
4 files changed
+176
-19
No files matched your search
@@ -115,6 +115,10 @@ public:
|
||||
|
||||
bool Ready() const { return m_ready; }
|
||||
|
||||
// 握手失败原因(人类可读;未失败时为空)。由调用方在 Handshake* 返回 false 后输出
|
||||
// 一行汇总日志——会话内部不再逐条打印,避免公网扫描器/半截握手刷屏。
|
||||
const std::string& LastError() const { return m_lastError; }
|
||||
|
||||
private:
|
||||
void CloseHandles();
|
||||
bool SendAll(SOCKET sock, const void* data, int len);
|
||||
@@ -125,4 +129,6 @@ private:
|
||||
bool m_ready = false;
|
||||
SecPkgContext_StreamSizes m_sizes = {};
|
||||
std::vector<BYTE> m_raw; // 尚未解密 / 未消费完的 TLS 记录原始字节
|
||||
SECURITY_STATUS m_lastStatus = SEC_E_OK;
|
||||
std::string m_lastError; // 握手失败原因,供调用方汇总输出
|
||||
};
|
||||
Reference in new issue
Block a user