mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-30 09:56:14 -05:00
Bugfixes galore!
* Split p3bitdht_peers.cc debugging in two. Hid Id Translation debug (that code is fine) * Added initialisation of p3bitdht peer data structure (using values from peernet). * Added BITDHT_QFLAGS_UPDATES flag. * Added Tick() interface to NetAssistConnect interface, tick it from p3NetMgr. * FIXED OLD BUG: netAssistFriend was not being called from p3LinkMgr::connectResult() this meant all peers where being searched for. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4423 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d6e2d959be
commit
f7ff55237e
@ -154,6 +154,7 @@ virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies);
|
||||
void start(); /* starts up the bitdht thread */
|
||||
|
||||
/* pqiNetAssist - external interface functions */
|
||||
virtual int tick();
|
||||
virtual void enable(bool on);
|
||||
virtual void shutdown(); /* blocking call */
|
||||
virtual void restart();
|
||||
@ -196,7 +197,7 @@ int ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
||||
|
||||
int OnlinePeerCallback_locked(const bdId *id, uint32_t status, DhtPeerDetails *dpd);
|
||||
int UnreachablePeerCallback_locked(const bdId *id, uint32_t status, DhtPeerDetails *dpd);
|
||||
int tick();
|
||||
//int tick();
|
||||
int minuteTick();
|
||||
int doActions();
|
||||
int checkProxyAllowed(const bdId *srcId, const bdId *destId, int mode);
|
||||
|
@ -33,6 +33,13 @@
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
/***
|
||||
*
|
||||
* #define DEBUG_BITDHT 1
|
||||
* #define DEBUG_BITDHT_TRANSLATE 1
|
||||
*
|
||||
**/
|
||||
|
||||
#define DEBUG_BITDHT 1
|
||||
|
||||
/******************************************************************************************
|
||||
@ -62,12 +69,84 @@ bool p3BitDht::findPeer(std::string pid)
|
||||
if (!dpd)
|
||||
{
|
||||
/* ERROR */
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() ERROR installing InternalPeer";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* flag as searching */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
|
||||
/* new entry... what do we need to set? */
|
||||
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->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
|
||||
std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* old entry */
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() Reactivating DhtPeer with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (dpd->mDhtState != RSDHT_PEERDHT_NOT_ACTIVE)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() WARNING DhtState is Already Active!";
|
||||
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* flag as searching */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bdNodeId nid = dpd->mDhtId.id;
|
||||
|
||||
@ -78,7 +157,7 @@ bool p3BitDht::findPeer(std::string pid)
|
||||
#endif
|
||||
|
||||
/* add in peer */
|
||||
mUdpBitDht->addFindNode(&nid, BITDHT_QFLAGS_DO_IDLE);
|
||||
mUdpBitDht->addFindNode(&nid, BITDHT_QFLAGS_DO_IDLE | BITDHT_QFLAGS_UPDATES);
|
||||
|
||||
return true ;
|
||||
}
|
||||
@ -258,7 +337,7 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const std::string &pid)
|
||||
|
||||
bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::havePeerTranslation_locked() for : " << pid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -267,7 +346,7 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
it = mTransToNodeId.find(pid);
|
||||
if (it == mTransToNodeId.end())
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::havePeerTranslation_locked() failed Missing translation";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -275,7 +354,7 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::havePeerTranslation_locked() Found NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(it->second));
|
||||
std::cerr << std::endl;
|
||||
@ -287,7 +366,7 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
|
||||
|
||||
int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupNodeId_locked() for : " << pid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -296,7 +375,7 @@ int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
it = mTransToNodeId.find(pid);
|
||||
if (it == mTransToNodeId.end())
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupNodeId_locked() failed";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -306,7 +385,7 @@ int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
*id = it->second;
|
||||
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupNodeId_locked() Found NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
@ -318,7 +397,7 @@ int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
|
||||
|
||||
int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupRsId_locked() for : ";
|
||||
bdStdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
@ -328,7 +407,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
nit = mTransToRsId.find(*id);
|
||||
if (nit == mTransToRsId.end())
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupRsId_locked() failed";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -338,7 +417,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
pid = nit->second;
|
||||
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::lookupRsId_locked() Found Matching RsId: " << pid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -348,7 +427,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
|
||||
|
||||
int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -356,7 +435,7 @@ int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
bdNodeId nid;
|
||||
calculateNodeId(pid, &nid);
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::storeTranslation_locked() Converts to NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(nid));
|
||||
std::cerr << std::endl;
|
||||
@ -365,7 +444,7 @@ int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
mTransToNodeId[pid] = nid;
|
||||
mTransToRsId[nid] = pid;
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::storeTranslation_locked() Success";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -376,7 +455,7 @@ int p3BitDht::storeTranslation_locked(const std::string pid)
|
||||
int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::removeTranslation_locked(" << pid << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -393,7 +472,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
|
||||
bdNodeId nid = it->second;
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::removeTranslation_locked() Found Translation: NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(nid));
|
||||
std::cerr << std::endl;
|
||||
@ -413,7 +492,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
|
||||
mTransToNodeId.erase(it);
|
||||
mTransToRsId.erase(nit);
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::removeTranslation_locked() SUCCESS";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -433,7 +512,7 @@ const uint8_t rs_dht_version_data[RS_DHT_VERSION_LEN] = "RS_VERSION_0.5.1";
|
||||
int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
|
||||
{
|
||||
/* generate node id from pid */
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << "p3BitDht::calculateNodeId() " << pid;
|
||||
#endif
|
||||
|
||||
@ -454,7 +533,7 @@ int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
|
||||
}
|
||||
delete sha_ctx;
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
#ifdef DEBUG_BITDHT_TRANSLATE
|
||||
std::cerr << " => ";
|
||||
bdStdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
|
@ -659,8 +659,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
|
||||
|
||||
bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address)
|
||||
{
|
||||
bool should_netAssistFriend_false = false ;
|
||||
bool should_netAssistFriend_true = false ;
|
||||
bool doDhtAssist = false ;
|
||||
bool updatePeerAddr = false;
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
@ -687,7 +686,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() Failed, missing Friend " << " id: " << id << std::endl;
|
||||
std::cerr << "p3LinkMgr::connectResult() ERROR, missing Friend " << " id: " << id << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -738,9 +737,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||
/* remove other attempts */
|
||||
it->second.inConnAttempt = false;
|
||||
it->second.connAddrs.clear();
|
||||
should_netAssistFriend_false = true ;
|
||||
mStatusChanged = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -759,8 +756,6 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||
mStatusChanged = true;
|
||||
|
||||
it->second.lastcontact = time(NULL); /* time of disconnect */
|
||||
|
||||
should_netAssistFriend_true = true ;
|
||||
}
|
||||
|
||||
if (it->second.connAddrs.size() >= 1)
|
||||
@ -768,6 +763,11 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||
it->second.actions |= RS_PEER_CONNECT_REQ;
|
||||
mStatusChanged = true;
|
||||
}
|
||||
|
||||
if (it->second.dhtVisible)
|
||||
{
|
||||
doDhtAssist = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -778,15 +778,43 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||
raddr.mSeenTime = time(NULL);
|
||||
raddr.mSrc = 0;
|
||||
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() SUCCESS and we initiated connection... Updating Address";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mPeerMgr->updateCurrentAddress(id, raddr);
|
||||
}
|
||||
|
||||
if(should_netAssistFriend_true)
|
||||
mNetMgr->netAssistFriend(id,true) ;
|
||||
if(should_netAssistFriend_false)
|
||||
mNetMgr->netAssistFriend(id,false) ;
|
||||
|
||||
return true;
|
||||
|
||||
if (success)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() SUCCESS switching off DhtAssist for friend: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* always switch it off now */
|
||||
mNetMgr->netAssistFriend(id,false) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (doDhtAssist)
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() FAIL, Enabling DhtAssist for: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mNetMgr->netAssistFriend(id,true) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef LINKMGR_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() FAIL, No DhtAssist, as No DHT visibility for: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/******************************** Feedback ...... *********************************
|
||||
|
@ -73,6 +73,7 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
|
||||
* #define NETMGR_DEBUG_TICK 1
|
||||
***/
|
||||
|
||||
#define NETMGR_DEBUG 1
|
||||
#define NETMGR_DEBUG_RESET 1
|
||||
|
||||
pqiNetStatus::pqiNetStatus()
|
||||
@ -417,6 +418,7 @@ void p3NetMgr::netStartup()
|
||||
void p3NetMgr::tick()
|
||||
{
|
||||
netTick();
|
||||
netAssistConnectTick();
|
||||
}
|
||||
|
||||
#define STARTUP_DELAY 5
|
||||
@ -1258,25 +1260,19 @@ bool p3NetMgr::netAssistConnectShutdown()
|
||||
bool p3NetMgr::netAssistFriend(std::string id, bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
std::list<pqiNetAssistConnect*> toFind ;
|
||||
std::list<pqiNetAssistConnect*> toDrop ;
|
||||
|
||||
#ifdef NETMGR_DEBUG
|
||||
std::cerr << "p3NetMgr::netAssistFriend(" << id << ", " << on << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
if (on)
|
||||
toFind.push_back(it->second) ;
|
||||
else
|
||||
toDrop.push_back(it->second) ;
|
||||
}
|
||||
if (on)
|
||||
(it->second)->findPeer(id);
|
||||
else
|
||||
(it->second)->dropPeer(id);
|
||||
}
|
||||
|
||||
for(std::list<pqiNetAssistConnect*>::const_iterator it(toFind.begin());it!=toFind.end();++it)
|
||||
(*it)->findPeer(id) ;
|
||||
for(std::list<pqiNetAssistConnect*>::const_iterator it(toDrop.begin());it!=toDrop.end();++it)
|
||||
(*it)->dropPeer(id) ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1295,6 +1291,18 @@ bool p3NetMgr::netAssistSetAddress( struct sockaddr_in &laddr,
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3NetMgr::netAssistConnectTick()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->tick();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
******************** Network State ***********************************
|
||||
|
@ -164,7 +164,7 @@ virtual bool netAssistConnectEnabled();
|
||||
virtual bool netAssistConnectActive();
|
||||
virtual bool netAssistConnectShutdown();
|
||||
virtual bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize);
|
||||
|
||||
void netAssistConnectTick();
|
||||
|
||||
/* Assist Firewall */
|
||||
bool netAssistExtAddress(struct sockaddr_in &extAddr);
|
||||
|
@ -110,6 +110,8 @@ class pqiNetAssistConnect: public pqiNetAssist
|
||||
* for the DHT, and must be non-blocking and return quickly
|
||||
*/
|
||||
|
||||
virtual int tick() = 0; /* for internal accounting */
|
||||
|
||||
/* add / remove peers */
|
||||
virtual bool findPeer(std::string id) = 0;
|
||||
virtual bool dropPeer(std::string id) = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user