#1138 Fixed reconnect.
This commit is contained in:
parent
df91a85128
commit
5678d15841
4 changed files with 43 additions and 28 deletions
|
@ -42,7 +42,8 @@ xmrig::BaseClient::BaseClient(int id, IClientListener *listener) :
|
||||||
m_retries(5),
|
m_retries(5),
|
||||||
m_failures(0),
|
m_failures(0),
|
||||||
m_state(UnconnectedState),
|
m_state(UnconnectedState),
|
||||||
m_retryPause(5000)
|
m_retryPause(5000),
|
||||||
|
m_enabled(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,8 @@ protected:
|
||||||
HostLookupState,
|
HostLookupState,
|
||||||
ConnectingState,
|
ConnectingState,
|
||||||
ConnectedState,
|
ConnectedState,
|
||||||
ClosingState
|
ClosingState,
|
||||||
|
ReconnectingState
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
|
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
|
||||||
|
|
|
@ -70,21 +70,15 @@ static const char *states[] = {
|
||||||
"host-lookup",
|
"host-lookup",
|
||||||
"connecting",
|
"connecting",
|
||||||
"connected",
|
"connected",
|
||||||
"closing"
|
"closing",
|
||||||
|
"reconnecting"
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||||
BaseClient(id, listener),
|
BaseClient(id, listener),
|
||||||
m_agent(agent),
|
m_agent(agent)
|
||||||
m_tls(nullptr),
|
|
||||||
m_expire(0),
|
|
||||||
m_jobs(0),
|
|
||||||
m_keepAlive(0),
|
|
||||||
m_key(0),
|
|
||||||
m_stream(nullptr),
|
|
||||||
m_socket(nullptr)
|
|
||||||
{
|
{
|
||||||
m_key = m_storage.add(this);
|
m_key = m_storage.add(this);
|
||||||
m_dns = new Dns(this);
|
m_dns = new Dns(this);
|
||||||
|
@ -238,8 +232,12 @@ void xmrig::Client::tick(uint64_t now)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_expire && now > m_expire && m_state == ConnectingState) {
|
if (m_state == ReconnectingState && m_expire && now > m_expire) {
|
||||||
connect();
|
return connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_state == ConnectingState && m_expire && now > m_expire) {
|
||||||
|
return reconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +447,6 @@ int xmrig::Client::resolve(const String &host)
|
||||||
{
|
{
|
||||||
setState(HostLookupState);
|
setState(HostLookupState);
|
||||||
|
|
||||||
m_expire = 0;
|
|
||||||
m_recvBuf.reset();
|
m_recvBuf.reset();
|
||||||
|
|
||||||
if (m_failures == -1) {
|
if (m_failures == -1) {
|
||||||
|
@ -814,12 +811,10 @@ void xmrig::Client::reconnect()
|
||||||
return m_listener->onClose(this, -1);
|
return m_listener->onClose(this, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(ConnectingState);
|
setState(ReconnectingState);
|
||||||
|
|
||||||
m_failures++;
|
m_failures++;
|
||||||
m_listener->onClose(this, static_cast<int>(m_failures));
|
m_listener->onClose(this, static_cast<int>(m_failures));
|
||||||
|
|
||||||
m_expire = Chrono::steadyMSecs() + m_retryPause;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -831,6 +826,23 @@ void xmrig::Client::setState(SocketState state)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case HostLookupState:
|
||||||
|
m_expire = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ConnectingState:
|
||||||
|
m_expire = Chrono::steadyMSecs() + kConnectTimeout;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ReconnectingState:
|
||||||
|
m_expire = Chrono::steadyMSecs() + m_retryPause;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_state = state;
|
m_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,12 +56,13 @@ class JobResult;
|
||||||
class Client : public BaseClient, public IDnsListener, public ILineListener
|
class Client : public BaseClient, public IDnsListener, public ILineListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
constexpr static int kResponseTimeout = 20 * 1000;
|
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||||
|
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_TLS
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
constexpr static int kInputBufferSize = 1024 * 16;
|
constexpr static size_t kInputBufferSize = 1024 * 16;
|
||||||
# else
|
# else
|
||||||
constexpr static int kInputBufferSize = 1024 * 2;
|
constexpr static size_t kInputBufferSize = 1024 * 2;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
Client(int id, const char *agent, IClientListener *listener);
|
Client(int id, const char *agent, IClientListener *listener);
|
||||||
|
@ -122,19 +123,19 @@ private:
|
||||||
|
|
||||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||||
|
|
||||||
char m_sendBuf[2048];
|
char m_sendBuf[2048] = { 0 };
|
||||||
const char *m_agent;
|
const char *m_agent;
|
||||||
Dns *m_dns;
|
Dns *m_dns;
|
||||||
RecvBuf<kInputBufferSize> m_recvBuf;
|
RecvBuf<kInputBufferSize> m_recvBuf;
|
||||||
std::bitset<EXT_MAX> m_extensions;
|
std::bitset<EXT_MAX> m_extensions;
|
||||||
String m_rpcId;
|
String m_rpcId;
|
||||||
Tls *m_tls;
|
Tls *m_tls = nullptr;
|
||||||
uint64_t m_expire;
|
uint64_t m_expire = 0;
|
||||||
uint64_t m_jobs;
|
uint64_t m_jobs = 0;
|
||||||
uint64_t m_keepAlive;
|
uint64_t m_keepAlive = 0;
|
||||||
uintptr_t m_key;
|
uintptr_t m_key = 0;
|
||||||
uv_stream_t *m_stream;
|
uv_stream_t *m_stream = nullptr;
|
||||||
uv_tcp_t *m_socket;
|
uv_tcp_t *m_socket = nullptr;
|
||||||
|
|
||||||
static Storage<Client> m_storage;
|
static Storage<Client> m_storage;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue