Removed Lots of Debug, and fixed a couple of bugs.

* Increased Timeout Periods for UDP connections - this was stopping half of them from succeeding.
 * The other bug (Heartbeat / stream issues) has not been solved.
 * Fixed up initialisation of p3BitDht data. 
 * add DropPeers() as NON-ACTIVE (this allows peers which aren't VISIBLE to still try and connect)
 * export AddFriends/FOF/Others to LinkMgr to allow further SSL IDs to be added to p3BitDht.
 * Export UDP Addresses to DhtWindow.
 * switch off lots of debugging.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4469 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-19 00:06:09 +00:00
parent e7049cc483
commit cc9df9a80f
13 changed files with 370 additions and 190 deletions

View File

@ -34,6 +34,7 @@
/** /**
* *
* #define TESTING_PERIODS 1 * #define TESTING_PERIODS 1
* #define DEBUG_CONNECTBOX 1
* *
**/ **/
@ -315,6 +316,7 @@ uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, uint32_t netmode, uint3
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
#ifdef DEBUG_CONNECTBOX
std::cerr << "PeerConnectStateBox::connectCb("; std::cerr << "PeerConnectStateBox::connectCb(";
if (cbtype == CSB_CONNECT_DIRECT) if (cbtype == CSB_CONNECT_DIRECT)
{ {
@ -326,14 +328,17 @@ uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, uint32_t netmode, uint3
} }
std::cerr << "," << NetStateAsString(netstate) << ")"; std::cerr << "," << NetStateAsString(netstate) << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
if (netstate != mNetState) if (netstate != mNetState)
{ {
#ifdef DEBUG_CONNECTBOX
std::cerr << "PeerConnectStateBox::connectCb() WARNING Changing NetState from: "; std::cerr << "PeerConnectStateBox::connectCb() WARNING Changing NetState from: ";
std::cerr << " from: " << NetStateAsString(mNetState); std::cerr << " from: " << NetStateAsString(mNetState);
std::cerr << " to: " << NetStateAsString(netstate); std::cerr << " to: " << NetStateAsString(netstate);
std::cerr << " for peer: " << mPeerId; std::cerr << " for peer: " << mPeerId;
std::cerr << std::endl; std::cerr << std::endl;
#endif
mNetState = netstate; mNetState = netstate;
} }
@ -521,7 +526,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
if (mNextAttemptTS > now) if (mNextAttemptTS > now)
{ {
/* same state */ /* same state */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too soon, no action", 0); stateMsg(std::cerr, "too soon, no action", 0);
#endif
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
break; break;
} }
@ -562,13 +569,17 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
/* starting up the connection */ /* starting up the connection */
if (mState != CSB_NETSTATE_FIREWALLED) if (mState != CSB_NETSTATE_FIREWALLED)
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "not Firewalled => PROXY_ATTEMPT", 0); stateMsg(std::cerr, "not Firewalled => PROXY_ATTEMPT", 0);
#endif
mState = CSB_PROXY_ATTEMPT; mState = CSB_PROXY_ATTEMPT;
retval = CSB_ACTION_PROXY_CONN | proxyPortMode; retval = CSB_ACTION_PROXY_CONN | proxyPortMode;
} }
else else
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "Firewalled => RELAY_ATTEMPT", 0); stateMsg(std::cerr, "Firewalled => RELAY_ATTEMPT", 0);
#endif
mState = CSB_RELAY_ATTEMPT; mState = CSB_RELAY_ATTEMPT;
retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT; retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT;
@ -587,7 +598,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
if (mNextAttemptTS > now) if (mNextAttemptTS > now)
{ {
/* same state */ /* same state */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too soon, no action", 0); stateMsg(std::cerr, "too soon, no action", 0);
#endif
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
} }
else if ((mNoAttempts >= MAX_PROXY_ATTEMPTS) || else if ((mNoAttempts >= MAX_PROXY_ATTEMPTS) ||
@ -595,7 +608,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
{ {
/* if too many attempts */ /* if too many attempts */
/* switch to RELAY attempt */ /* switch to RELAY attempt */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too many PROXY => RELAY_ATTEMPT", 0); stateMsg(std::cerr, "too many PROXY => RELAY_ATTEMPT", 0);
#endif
mState = CSB_RELAY_ATTEMPT; mState = CSB_RELAY_ATTEMPT;
retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT; retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT;
mStateTS = now; mStateTS = now;
@ -605,7 +620,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
else else
{ {
/* try again */ /* try again */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "PROXY_ATTEMPT try again", 0); stateMsg(std::cerr, "PROXY_ATTEMPT try again", 0);
#endif
mState = CSB_PROXY_ATTEMPT; mState = CSB_PROXY_ATTEMPT;
retval = CSB_ACTION_PROXY_CONN | proxyPortMode; retval = CSB_ACTION_PROXY_CONN | proxyPortMode;
mStateTS = now; mStateTS = now;
@ -621,12 +638,16 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
if (mNextAttemptTS > now) if (mNextAttemptTS > now)
{ {
/* same state */ /* same state */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too soon, no action", 0); stateMsg(std::cerr, "too soon, no action", 0);
#endif
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
} }
else else
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "timeout => RELAY_ATTEMPT", 0); stateMsg(std::cerr, "timeout => RELAY_ATTEMPT", 0);
#endif
/* switch to RELAY attempt */ /* switch to RELAY attempt */
mState = CSB_RELAY_ATTEMPT; mState = CSB_RELAY_ATTEMPT;
retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT; retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT;
@ -643,7 +664,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
if (mNextAttemptTS > now) if (mNextAttemptTS > now)
{ {
/* same state */ /* same state */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too soon, no action", 0); stateMsg(std::cerr, "too soon, no action", 0);
#endif
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
} }
else if ((mNoAttempts >= MAX_RELAY_ATTEMPTS) || else if ((mNoAttempts >= MAX_RELAY_ATTEMPTS) ||
@ -651,7 +674,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
{ {
/* if too many attempts */ /* if too many attempts */
/* switch to RELAY attempt */ /* switch to RELAY attempt */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "too many RELAY => FAILED_WAIT", 0); stateMsg(std::cerr, "too many RELAY => FAILED_WAIT", 0);
#endif
mState = CSB_FAILED_WAIT; mState = CSB_FAILED_WAIT;
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
mStateTS = now; mStateTS = now;
@ -662,7 +687,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
else else
{ {
/* try again */ /* try again */
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "RELAY_ATTEMPT try again", 0); stateMsg(std::cerr, "RELAY_ATTEMPT try again", 0);
#endif
mState = CSB_RELAY_ATTEMPT; mState = CSB_RELAY_ATTEMPT;
retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT; retval = CSB_ACTION_RELAY_CONN | CSB_ACTION_DHT_PORT;
mStateTS = now; mStateTS = now;
@ -673,7 +700,9 @@ uint32_t PeerConnectStateBox::connectCb_unreachable()
case CSB_CONNECTED: case CSB_CONNECTED:
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "connected => no action", 0); stateMsg(std::cerr, "connected => no action", 0);
#endif
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
} }
break; break;
@ -762,7 +791,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
mAttemptLength = 0; mAttemptLength = 0;
} }
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "=> CONNECTED", update); stateMsg(std::cerr, "=> CONNECTED", update);
#endif
mState = CSB_CONNECTED; mState = CSB_CONNECTED;
mStateTS = now; mStateTS = now;
@ -779,7 +810,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
} }
else else
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "=> START", update); stateMsg(std::cerr, "=> START", update);
#endif
/* move to START state */ /* move to START state */
mState = CSB_START; mState = CSB_START;
mStateTS = now; mStateTS = now;
@ -828,7 +861,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
/* if AUTH_DENIED ... => FAILED_WAIT */ /* if AUTH_DENIED ... => FAILED_WAIT */
case CSB_UPDATE_AUTH_DENIED: case CSB_UPDATE_AUTH_DENIED:
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "=> FAILED WAIT", update); stateMsg(std::cerr, "=> FAILED WAIT", update);
#endif
mState = CSB_FAILED_WAIT; mState = CSB_FAILED_WAIT;
mStateTS = now; mStateTS = now;
mAttemptLength = now - mStateTS; mAttemptLength = now - mStateTS;
@ -840,7 +875,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
/* if standard FAIL => stay where we are */ /* if standard FAIL => stay where we are */
case CSB_UPDATE_RETRY_ATTEMPT: case CSB_UPDATE_RETRY_ATTEMPT:
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "RETRY FAIL => switch to wait state", update); stateMsg(std::cerr, "RETRY FAIL => switch to wait state", update);
#endif
mAttemptLength = now - mStateTS; mAttemptLength = now - mStateTS;
switch(mState) switch(mState)
{ {
@ -860,7 +897,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
mNextAttemptTS = now + RSRandom::random_u32() % RELAY_MAX_WAIT_TIME; mNextAttemptTS = now + RSRandom::random_u32() % RELAY_MAX_WAIT_TIME;
break; break;
default: default:
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "RETRY FAIL, but unusual state", update); stateMsg(std::cerr, "RETRY FAIL, but unusual state", update);
#endif
break; break;
} }
@ -869,7 +908,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
/* if standard FAIL => stay where we are */ /* if standard FAIL => stay where we are */
case CSB_UPDATE_FAILED_ATTEMPT: case CSB_UPDATE_FAILED_ATTEMPT:
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "STANDARD FAIL => switch to wait state", update); stateMsg(std::cerr, "STANDARD FAIL => switch to wait state", update);
#endif
mNoFailedAttempts++; mNoFailedAttempts++;
mAttemptLength = now - mStateTS; mAttemptLength = now - mStateTS;
switch(mState) switch(mState)
@ -890,7 +931,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
mNextAttemptTS = now + RSRandom::random_u32() % RELAY_MAX_WAIT_TIME; mNextAttemptTS = now + RSRandom::random_u32() % RELAY_MAX_WAIT_TIME;
break; break;
default: default:
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "STANDARD FAIL, but unusual state", update); stateMsg(std::cerr, "STANDARD FAIL, but unusual state", update);
#endif
break; break;
} }
@ -906,14 +949,18 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
{ {
if (mNetState == CSB_NETSTATE_FORWARD) if (mNetState == CSB_NETSTATE_FORWARD)
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "as FORWARDED => REVERSE_WAIT", update); stateMsg(std::cerr, "as FORWARDED => REVERSE_WAIT", update);
#endif
mState = CSB_REVERSE_WAIT; mState = CSB_REVERSE_WAIT;
mStateTS = now; mStateTS = now;
mNextAttemptTS = now + REVERSE_WAIT_TIME; mNextAttemptTS = now + REVERSE_WAIT_TIME;
} }
else else
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "as !FORWARDED => RELAY_ATTEMPT", update); stateMsg(std::cerr, "as !FORWARDED => RELAY_ATTEMPT", update);
#endif
mState = CSB_RELAY_WAIT; mState = CSB_RELAY_WAIT;
mNoAttempts = 0; mNoAttempts = 0;
mStateTS = now; mStateTS = now;
@ -923,7 +970,9 @@ uint32_t PeerConnectStateBox::updateCb(uint32_t update)
} }
else else
{ {
#ifdef DEBUG_CONNECTBOX
stateMsg(std::cerr, "MODE UNAVAIL => FAILED_WAIT", update); stateMsg(std::cerr, "MODE UNAVAIL => FAILED_WAIT", update);
#endif
mState = CSB_FAILED_WAIT; mState = CSB_FAILED_WAIT;
mStateTS = now; mStateTS = now;
mNextAttemptTS = now + FAILED_WAIT_TIME; mNextAttemptTS = now + FAILED_WAIT_TIME;
@ -982,10 +1031,12 @@ bool PeerConnectStateBox::getProxyPortChoice()
{ {
time_t now = time(NULL); time_t now = time(NULL);
#ifdef DEBUG_CONNECTBOX
std::cerr << "PeerConnectStateBox::getProxyPortChoice() Using ConnectLogic Info from: "; std::cerr << "PeerConnectStateBox::getProxyPortChoice() Using ConnectLogic Info from: ";
std::cerr << now-mProxyPortTS << " ago. Flags: " << mProxyPortFlags; std::cerr << now-mProxyPortTS << " ago. Flags: " << mProxyPortFlags;
std::cerr << " UseProxyPort? " << mProxyPortChoice; std::cerr << " UseProxyPort? " << mProxyPortChoice;
std::cerr << std::endl; std::cerr << std::endl;
#endif
return mProxyPortChoice; return mProxyPortChoice;
} }

View File

@ -46,6 +46,8 @@ class DhtPeerDetails
{ {
public: public:
DhtPeerDetails();
uint32_t mPeerType; uint32_t mPeerType;
bdId mDhtId; bdId mDhtId;
@ -145,6 +147,8 @@ virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies);
//virtual int getNetFailedPeer(std::string peerId, PeerStatus &status); //virtual int getNetFailedPeer(std::string peerId, PeerStatus &status);
virtual std::string getUdpAddressString();
/*********************************************************************************************** /***********************************************************************************************
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) ********* ********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/ ************************************************************************************************/
@ -173,6 +177,10 @@ virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
virtual bool findPeer(std::string id); virtual bool findPeer(std::string id);
virtual bool dropPeer(std::string id); virtual bool dropPeer(std::string id);
virtual int addFriend(const std::string pid);
virtual int addFriendOfFriend(const std::string pid);
virtual int addOther(const std::string pid);
/* feedback on success failure of Connections */ /* feedback on success failure of Connections */
virtual void ConnectionFeedback(std::string pid, int state); virtual void ConnectionFeedback(std::string pid, int state);
@ -243,9 +251,9 @@ void ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely);
//bool findPeer(std::string pid) //bool findPeer(std::string pid)
//bool dropPeer(std::string pid); //bool dropPeer(std::string pid);
int addFriend(const std::string pid); //int addFriend(const std::string pid);
int addFriendOfFriend(const std::string pid); //int addFriendOfFriend(const std::string pid);
int addOther(const std::string pid); //int addOther(const std::string pid);
int removePeer(const std::string pid); int removePeer(const std::string pid);
private: private:

View File

@ -27,6 +27,7 @@
#include "dht/p3bitdht.h" #include "dht/p3bitdht.h"
#include "tcponudp/udprelay.h" #include "tcponudp/udprelay.h"
#include "tcponudp/udpstunner.h"
#include "bitdht/bdstddht.h" #include "bitdht/bdstddht.h"
#include <sstream> #include <sstream>
@ -146,6 +147,53 @@ int p3BitDht::getNetFailedPeer(std::string peerId, PeerStatus &status)
} }
#endif #endif
std::string p3BitDht::getUdpAddressString()
{
std::ostringstream out;
struct sockaddr_in extAddr;
uint8_t extStable;
if (mDhtStunner->externalAddr(extAddr, extStable))
{
out << " DhtExtAddr: " << inet_ntoa(extAddr.sin_addr);
out << ":" << ntohs(extAddr.sin_port);
if (extStable)
{
out << " (Stable) ";
}
else
{
out << " (Unstable) ";
}
}
else
{
out << " DhtExtAddr: Unknown ";
}
if (mProxyStunner->externalAddr(extAddr, extStable))
{
out << " ProxyExtAddr: " << inet_ntoa(extAddr.sin_addr);
out << ":" << ntohs(extAddr.sin_port);
if (extStable)
{
out << " (Stable) ";
}
else
{
out << " (Unstable) ";
}
}
else
{
out << " ProxyExtAddr: Unknown ";
}
return out.str();
}
/*********************************************************************************************** /***********************************************************************************************
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) ********* ********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/ ************************************************************************************************/
@ -179,6 +227,8 @@ void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDeta
status.mDhtId = out.str(); status.mDhtId = out.str();
status.mRsId = details.mRsId; status.mRsId = details.mRsId;
status.mPeerType = details.mPeerType;
status.mDhtState = details.mDhtState; status.mDhtState = details.mDhtState;
status.mConnectState = details.mConnectLogic.connectState(); status.mConnectState = details.mConnectLogic.connectState();

File diff suppressed because it is too large Load Diff

View File

@ -53,6 +53,7 @@
*/ */
#define USE_OLD_DHT_INTERFACE 1 #define USE_OLD_DHT_INTERFACE 1
bool p3BitDht::findPeer(std::string pid) bool p3BitDht::findPeer(std::string pid)
{ {
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
@ -77,42 +78,6 @@ bool p3BitDht::findPeer(std::string pid)
/* new entry... what do we need to set? */ /* new entry... what do we need to set? */
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING; dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
/* NEW INIT FROM peernet */
//bdsockaddr_clear(&(dpd->mDhtAddr));
//dpd->mDhtStatusMsg = "Just Added";
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
dpd->mDhtUpdateTS = time(NULL);
dpd->mPeerReqStatusMsg = "Just Added";
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED;
dpd->mPeerReqMode = 0;
//dpd->mPeerReqProxyId;
dpd->mPeerReqTS = time(NULL);
dpd->mExclusiveProxyLock = false;
dpd->mPeerCbMsg = "No CB Yet";
dpd->mPeerCbMode = 0;
dpd->mPeerCbPoint = 0;
//dpd->mPeerCbProxyId = 0;
//dpd->mPeerCbDestId = 0;
dpd->mPeerCbTS = 0;
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED;
dpd->mPeerConnectMsg = "Disconnected";
//dpd->mPeerConnectFd = 0;
dpd->mPeerConnectMode = 0;
//dpd->mPeerConnectProxyId;
dpd->mPeerConnectPoint = 0;
dpd->mPeerConnectUdpTS = 0;
dpd->mPeerConnectTS = 0;
dpd->mPeerConnectClosedTS = 0;
bdsockaddr_clear(&(dpd->mPeerConnectAddr));
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: "; std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
@ -174,6 +139,10 @@ bool p3BitDht::dropPeer(std::string pid)
if (!dpd) if (!dpd)
{ {
/* ERROR */ /* ERROR */
std::cerr << "p3BitDht::dropPeer(" << pid << ") HACK TO INCLUDE FRIEND AS NON-ACTIVE PEER";
std::cerr << std::endl;
addFriend(pid);
return false; return false;
} }
@ -257,12 +226,15 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, int type
DhtPeerDetails newdpd; DhtPeerDetails newdpd;
mPeers[id] = newdpd; mPeers[id] = newdpd;
dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY);
dpd->mDhtId.id = id;
dpd->mRsId = pid;
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
} }
/* what do we need to reset? */ /* what do we need to reset? */
dpd->mPeerType = type; dpd->mPeerType = type;
dpd->mDhtId.id = id;
dpd->mRsId = pid;
return dpd; return dpd;
} }
@ -541,3 +513,42 @@ int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
return 1; return 1;
} }
/******************** Conversion Functions **************************/
DhtPeerDetails::DhtPeerDetails()
{
mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
mDhtState = RSDHT_PEERDHT_SEARCHING;
mDhtUpdateTS = time(NULL);
mPeerReqStatusMsg = "Just Added";
mPeerReqState = RSDHT_PEERREQ_STOPPED;
mPeerReqMode = 0;
//mPeerReqProxyId;
mPeerReqTS = time(NULL);
mExclusiveProxyLock = false;
mPeerCbMsg = "No CB Yet";
mPeerCbMode = 0;
mPeerCbPoint = 0;
//mPeerCbProxyId = 0;
//mPeerCbDestId = 0;
mPeerCbTS = 0;
mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED;
mPeerConnectMsg = "Disconnected";
mPeerConnectMode = 0;
//dpd->mPeerConnectProxyId;
mPeerConnectPoint = 0;
mPeerConnectUdpTS = 0;
mPeerConnectTS = 0;
mPeerConnectClosedTS = 0;
bdsockaddr_clear(&(mPeerConnectAddr));
}

View File

@ -67,11 +67,13 @@ const int p3connectzone = 3431;
* #define P3CONNMGR_NO_AUTO_CONNECTION 1 * #define P3CONNMGR_NO_AUTO_CONNECTION 1
***/ ***/
#define P3CONNMGR_NO_TCP_CONNECTIONS 1
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 3; /* 2 Seconds? is it be enough! */ const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 3; /* 2 Seconds? is it be enough! */
const uint32_t P3CONNMGR_UDP_DEFAULT_DELAY = 3; /* 2 Seconds? is it be enough! */ const uint32_t P3CONNMGR_UDP_DEFAULT_DELAY = 3; /* 2 Seconds? is it be enough! */
const uint32_t P3CONNMGR_TCP_DEFAULT_PERIOD = 10; const uint32_t P3CONNMGR_TCP_DEFAULT_PERIOD = 10;
const uint32_t P3CONNMGR_UDP_DEFAULT_PERIOD = 40; const uint32_t P3CONNMGR_UDP_DEFAULT_PERIOD = 30; // this represents how long it stays at the default TTL (4), before rising.
#define MAX_AVAIL_PERIOD 230 //times a peer stay in available state when not connected #define MAX_AVAIL_PERIOD 230 //times a peer stay in available state when not connected
#define MIN_RETRY_PERIOD 140 #define MIN_RETRY_PERIOD 140
@ -1205,8 +1207,12 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in rad
if (source == RS_CB_DHT) if (source == RS_CB_DHT)
{ {
if (flags & RS_CB_FLAG_MODE_TCP) if (flags & RS_CB_FLAG_MODE_TCP)
{ {
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says Online ==> so try TCP"; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says Online ==> so try TCP";
std::cerr << std::endl; std::cerr << std::endl;
@ -1235,6 +1241,9 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in rad
} }
retryConnect(id); retryConnect(id);
#endif
} }
else else
{ {

View File

@ -58,6 +58,7 @@ const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
//const uint32_t RS_NET_CONN_PEER = 0x0200; /* all UDP */ //const uint32_t RS_NET_CONN_PEER = 0x0200; /* all UDP */
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */ const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
const uint32_t RS_UDP_STD_TIMEOUT_PERIOD = 80; /* 80 secs, allows UDP TTL to get to 40! - Plenty of time (30+80) = 110 secs */
class peerAddrInfo class peerAddrInfo
{ {

View File

@ -75,8 +75,6 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
* #define NETMGR_DEBUG_STATEBOX 1 * #define NETMGR_DEBUG_STATEBOX 1
***/ ***/
#define NETMGR_DEBUG_STATEBOX 1
pqiNetStatus::pqiNetStatus() pqiNetStatus::pqiNetStatus()
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false), :mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
mUpnpOk(false), mDhtOk(false), mResetReq(false) mUpnpOk(false), mDhtOk(false), mResetReq(false)

View File

@ -114,10 +114,17 @@ class pqiNetAssistConnect: public pqiNetAssist
virtual int tick() = 0; /* for internal accounting */ virtual int tick() = 0; /* for internal accounting */
/* add / remove peers */ /* add / remove peers */
virtual bool findPeer(std::string id) = 0; virtual bool findPeer(std::string id) = 0;
virtual bool dropPeer(std::string id) = 0; virtual bool dropPeer(std::string id) = 0;
/* add non-active peers (can still toggle active/non-active via above) */
virtual int addFriend(const std::string pid) = 0;
virtual int addFriendOfFriend(const std::string pid) = 0;
virtual int addOther(const std::string pid) = 0;
virtual void ConnectionFeedback(std::string pid, int mode) = 0; virtual void ConnectionFeedback(std::string pid, int mode) = 0;
/* extract current peer status */ /* extract current peer status */

View File

@ -192,8 +192,8 @@ bool pqihandler::RemoveSearchModule(SearchModule *mod)
// dummy output check // dummy output check
int pqihandler::locked_checkOutgoingRsItem(RsItem *item, int global) int pqihandler::locked_checkOutgoingRsItem(RsItem *item, int global)
{ {
pqioutput(PQL_WARNING, pqihandlerzone, //pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "pqihandler::checkOutgoingPQItem() NULL fn");
"pqihandler::checkOutgoingPQItem() NULL fn");
return 1; return 1;
} }

View File

@ -102,7 +102,8 @@ int pqiperson::status()
int pqiperson::receiveHeartbeat() int pqiperson::receiveHeartbeat()
{ {
pqioutput(PQL_DEBUG_ALERT, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId()); //pqioutput(PQL_DEBUG_ALERT, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId());
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::receiveHeartbeat() from peer : " + PeerId());
lastHeartbeatReceived = time(NULL); lastHeartbeatReceived = time(NULL);
return true ; return true ;
@ -112,11 +113,14 @@ int pqiperson::receiveHeartbeat()
int pqiperson::tick() int pqiperson::tick()
{ {
//if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset. //if lastHeartbeatReceived is 0, it might be not activated so don't do a net reset.
if (active && if (active && (lastHeartbeatReceived != 0) &&
lastHeartbeatReceived != 0 && (time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5) { {
pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::tick() No heartbeat from the peer, assume connection is dead."); std::ostringstream out;
this->reset(); out << "pqiperson::tick() No heartbeat from the peer, assume connection is dead. LastHeartbeat was: ";
out << time(NULL) - lastHeartbeatReceived << " secs ago";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
this->reset();
} }
int activeTick = 0; int activeTick = 0;

View File

@ -587,7 +587,7 @@ int pqipersongrp::connectPeer(std::string id
else if (type & RS_NET_CONN_UDP_ALL) else if (type & RS_NET_CONN_UDP_ALL)
{ {
ptype = PQI_CONNECT_UDP; ptype = PQI_CONNECT_UDP;
timeout = period * 2; timeout = period + RS_UDP_STD_TIMEOUT_PERIOD; // Split of UNCERTAINTY + TIME FOR TTL to RISE to Connection.
#ifdef PGRP_DEBUG #ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout; std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout;
std::cerr << std::endl; std::cerr << std::endl;

View File

@ -95,6 +95,8 @@ class RsDhtNetPeer
std::string mDhtId; std::string mDhtId;
std::string mRsId; std::string mRsId;
uint32_t mPeerType;
uint32_t mDhtState; uint32_t mDhtState;
//connectLogic. //connectLogic.
@ -164,9 +166,10 @@ virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies) = 0;
//virtual int getNetFailedPeer(std::string peerId, PeerStatus &status); //virtual int getNetFailedPeer(std::string peerId, PeerStatus &status);
virtual std::string getUdpAddressString() = 0;
#if 0 #if 0
virtual std::string getPeerStatusString(); virtual std::string getPeerStatusString();
virtual std::string getPeerAddressString();
virtual std::string getDhtStatusString(); virtual std::string getDhtStatusString();
virtual int get_dht_queries(std::map<bdNodeId, bdQueryStatus> &queries); virtual int get_dht_queries(std::map<bdNodeId, bdQueryStatus> &queries);