mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-19 22:40:36 -04:00
Incremental DHT improvement - support in libretroshare.
- Added missing Mutex protection in p3BitDht. - Added p3BitDht::addKnownPeer() to communicate with libbitdht. - Disabled placeholder versions (addFriend/AddFriendOfFriend) - Added netAssistKnownPeer() libretroshare interface. - Added calls to netAssistKnownPeer() from p3disc and p3NetMgr. - Check for NULL ptr in p3NetMgr before calling p3PeerMgr. - Added FIX to maintain MANUAL FORWARD port (untested!) - Removed some compiler warnings. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4681 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4cd7523947
commit
7b0a33c318
12 changed files with 254 additions and 74 deletions
|
@ -177,9 +177,10 @@ virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
|
|||
virtual bool findPeer(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);
|
||||
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_in &addr, uint32_t flags);
|
||||
//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 */
|
||||
virtual void ConnectionFeedback(std::string pid, int state);
|
||||
|
|
|
@ -60,67 +60,73 @@ bool p3BitDht::findPeer(std::string pid)
|
|||
std::cerr << "p3BitDht::findPeer(" << pid << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
bdNodeId nid;
|
||||
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
if (!dpd)
|
||||
{
|
||||
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND);
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
if (!dpd)
|
||||
{
|
||||
/* ERROR */
|
||||
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND);
|
||||
if (!dpd)
|
||||
{
|
||||
/* ERROR */
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() ERROR installing InternalPeer";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3BitDht::findPeer() ERROR installing InternalPeer";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* new entry... what do we need to set? */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* new entry... what do we need to set? */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
|
||||
|
||||
#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!";
|
||||
std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* flag as searching */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING;
|
||||
/* old entry */
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING";
|
||||
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;
|
||||
|
||||
nid = dpd->mDhtId.id;
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::findPeer() calling AddFindNode() with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &nid);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3BitDht::findPeer() calling AddFindNode() with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &nid);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* add in peer */
|
||||
mUdpBitDht->addFindNode(&nid, BITDHT_QFLAGS_DO_IDLE | BITDHT_QFLAGS_UPDATES);
|
||||
|
||||
|
@ -134,29 +140,36 @@ bool p3BitDht::dropPeer(std::string pid)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
bdNodeId nid;
|
||||
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
if (!dpd)
|
||||
{
|
||||
/* ERROR */
|
||||
std::cerr << "p3BitDht::dropPeer(" << pid << ") HACK TO INCLUDE FRIEND AS NON-ACTIVE PEER";
|
||||
std::cerr << std::endl;
|
||||
|
||||
addFriend(pid);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* flag as searching */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
|
||||
|
||||
bdNodeId nid = dpd->mDhtId.id;
|
||||
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
||||
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
|
||||
if (!dpd)
|
||||
{
|
||||
/* ERROR */
|
||||
std::cerr << "p3BitDht::dropPeer(" << pid << ") HACK TO INCLUDE FRIEND AS NON-ACTIVE PEER";
|
||||
std::cerr << std::endl;
|
||||
|
||||
//addFriend(pid);
|
||||
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* flag as searching */
|
||||
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE;
|
||||
|
||||
nid = dpd->mDhtId.id;
|
||||
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "p3BitDht::dropPeer() calling removeFindNode() with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &nid);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3BitDht::dropPeer() calling removeFindNode() with pid => NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, &nid);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* remove in peer */
|
||||
mUdpBitDht->removeFindNode(&nid);
|
||||
|
||||
|
@ -170,6 +183,84 @@ bool p3BitDht::dropPeer(std::string pid)
|
|||
********************************* Basic Peer Details *************************************
|
||||
******************************************************************************************/
|
||||
|
||||
int p3BitDht::addKnownPeer(const std::string &pid, const struct sockaddr_in &addr, uint32_t flags)
|
||||
{
|
||||
|
||||
int p3type = 0;
|
||||
int bdflags = 0;
|
||||
bdId id;
|
||||
bool isOwnId = false;
|
||||
|
||||
switch(flags & NETASSIST_KNOWN_PEER_TYPE_MASK)
|
||||
{
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
case NETASSIST_KNOWN_PEER_WHITELIST:
|
||||
p3type = RSDHT_PEERTYPE_OTHER;
|
||||
bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST;
|
||||
|
||||
break;
|
||||
case NETASSIST_KNOWN_PEER_FOF:
|
||||
p3type = RSDHT_PEERTYPE_FOF;
|
||||
bdflags = BITDHT_PEER_STATUS_DHT_FOF;
|
||||
|
||||
break;
|
||||
case NETASSIST_KNOWN_PEER_FRIEND:
|
||||
p3type = RSDHT_PEERTYPE_FRIEND;
|
||||
bdflags = BITDHT_PEER_STATUS_DHT_FRIEND;
|
||||
|
||||
break;
|
||||
case NETASSIST_KNOWN_PEER_RELAY:
|
||||
p3type = RSDHT_PEERTYPE_OTHER;
|
||||
bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER;
|
||||
|
||||
break;
|
||||
case NETASSIST_KNOWN_PEER_SELF:
|
||||
p3type = RSDHT_PEERTYPE_OTHER;
|
||||
bdflags = BITDHT_PEER_STATUS_DHT_SELF;
|
||||
isOwnId = true;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (flags & NETASSIST_KNOWN_PEER_ONLINE)
|
||||
{
|
||||
bdflags |= BD_FRIEND_ENTRY_ONLINE;
|
||||
}
|
||||
|
||||
if (!isOwnId)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
DhtPeerDetails *dpd = addInternalPeer_locked(pid, p3type);
|
||||
|
||||
|
||||
if (bdflags & BD_FRIEND_ENTRY_ONLINE)
|
||||
{
|
||||
/* can we update the address? */
|
||||
//dpd->mDhtId.addr = addr;
|
||||
}
|
||||
|
||||
|
||||
id.id = dpd->mDhtId.id;
|
||||
id.addr = addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// shouldn't use own id without mutex - but it is static!
|
||||
id.id = mOwnDhtId;
|
||||
id.addr = addr;
|
||||
}
|
||||
|
||||
mUdpBitDht->updateKnownPeer(&id, 0, bdflags);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
int p3BitDht::addFriend(const std::string pid)
|
||||
{
|
||||
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
|
||||
|
@ -192,6 +283,7 @@ int p3BitDht::addOther(const std::string pid)
|
|||
|
||||
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_OTHER));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int p3BitDht::removePeer(const std::string pid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue