mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 03:49:29 -04:00
Add heartbeat (an empty packet, wich is 100 bytes long) in p3disc every 4 seconds
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1929 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e6c8e57927
commit
6b9392fcae
7 changed files with 249 additions and 38 deletions
|
@ -26,6 +26,7 @@
|
|||
#include "pqi/pqi.h"
|
||||
#include "pqi/pqiperson.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
#include "services/p3disc.h"
|
||||
|
||||
const int pqipersonzone = 82371;
|
||||
#include "util/rsdebug.h"
|
||||
|
@ -100,10 +101,24 @@ int pqiperson::status()
|
|||
return -1;
|
||||
}
|
||||
|
||||
int pqiperson::receiveHeartbeat()
|
||||
{
|
||||
pqioutput(PQL_DEBUG_ALERT, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId());
|
||||
lastHeartbeatReceived = time(NULL);
|
||||
}
|
||||
|
||||
// tick......
|
||||
int pqiperson::tick()
|
||||
{
|
||||
int activeTick = 0;
|
||||
//if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset.
|
||||
if (active &&
|
||||
lastHeartbeatReceived != 0 &&
|
||||
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 3) {
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::tick() No heartbeat from the peer, assume connection is dead.");
|
||||
this->reset();
|
||||
}
|
||||
|
||||
int activeTick = 0;
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
@ -218,6 +233,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
|||
"CONNECT_SUCCESS->marking so! (resetting others)");
|
||||
// mark as active.
|
||||
active = true;
|
||||
lastHeartbeatReceived = 0;
|
||||
activepqi = pqi;
|
||||
inConnectAttempt = false;
|
||||
|
||||
|
@ -297,6 +313,7 @@ int pqiperson::reset()
|
|||
|
||||
activepqi = NULL;
|
||||
active = false;
|
||||
lastHeartbeatReceived = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ static const int CONNECT_UNREACHABLE = 3;
|
|||
static const int CONNECT_FIREWALLED = 4;
|
||||
static const int CONNECT_FAILED = 5;
|
||||
|
||||
static const int HEARTBEAT_REPEAT_TIME = 4;
|
||||
|
||||
#include "pqi/pqistreamer.h"
|
||||
|
||||
class pqiconnect: public pqistreamer, public NetInterface
|
||||
|
@ -105,7 +107,7 @@ int reset();
|
|||
int listen();
|
||||
int stoplistening();
|
||||
int connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout);
|
||||
|
||||
int receiveHeartbeat();
|
||||
// add in connection method.
|
||||
int addChildInterface(uint32_t type, pqiconnect *pqi);
|
||||
|
||||
|
@ -132,6 +134,7 @@ pqiconnect *getKid(uint32_t type);
|
|||
pqiconnect *activepqi;
|
||||
bool inConnectAttempt;
|
||||
int waittimes;
|
||||
time_t lastHeartbeatReceived;//use to track connection failure
|
||||
|
||||
private: /* Helper functions */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue