(Re-)Implement backoff timer for login fails

This commit is contained in:
phl0 2018-10-22 23:29:12 +02:00
parent 1746ec7998
commit 6b61a2d6cc
No known key found for this signature in database
GPG key ID: 48EA1E640798CA9A
3 changed files with 15 additions and 7 deletions

View file

@ -234,7 +234,7 @@ int CDAPNETGateway::run()
return 1;
}
m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, false, debug);
m_dapnetNetwork = new CDAPNETNetwork(dapnetAddress, dapnetPort, callsign, dapnetAuthKey, VERSION, false, 1, debug);
ret = m_dapnetNetwork->open();
if (!ret) {
m_pocsagNetwork->close();

View file

@ -29,12 +29,13 @@
const unsigned int BUFFER_LENGTH = 200U;
CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug) :
CDAPNETNetwork::CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedIn, int failCount, bool debug) :
m_socket(address, port),
m_callsign(callsign),
m_authKey(authKey),
m_version(version),
m_loggedin(false),
m_loggedIn(false),
m_failCount(failCount),
m_debug(debug),
m_message(NULL),
m_schedule(NULL)
@ -94,8 +95,8 @@ bool CDAPNETNetwork::read()
LogWarning("An error has been reported by DAPNET");
} else if (buffer[0U] == '2') {
// First time sync paket indicated successful login
if (!m_loggedin) {
m_loggedin = true;
if (!m_loggedIn) {
m_loggedIn = true;
LogMessage("Logged into the DAPNET network");
}
// Time synchronisation
@ -267,7 +268,13 @@ bool CDAPNETNetwork::parseFailedLogin(unsigned char* data)
char* p = ::strtok((char*)data + 2U, "\r\n");
assert(p != NULL);
const unsigned int backoff[] = {2000u, 4000u, 8000u, 10000u, 20000u, 60000u, 120000u, 240000u, 480000u, 600000u};
LogMessage("Login failed: %s", p);
CThread::sleep(backoff[m_failCount]);
if (m_failCount < 9)
m_failCount++;
return write((unsigned char*)"+\r\n");
}

View file

@ -28,7 +28,7 @@
class CDAPNETNetwork {
public:
CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedin, bool debug);
CDAPNETNetwork(const std::string& address, unsigned int port, const std::string& callsign, const std::string& authKey, const char* version, bool loggedIn, int failCount, bool debug);
~CDAPNETNetwork();
bool open();
@ -48,7 +48,8 @@ private:
std::string m_callsign;
std::string m_authKey;
const char* m_version;
bool m_loggedin;
bool m_loggedIn;
int m_failCount;
bool m_debug;
CPOCSAGMessage* m_message;
bool* m_schedule;