merge of branch v0.6-idclean 7180

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2014-03-17 20:56:06 +00:00
parent 7815efb16f
commit 0f29d28b1b
397 changed files with 6503 additions and 5702 deletions

View file

@ -81,7 +81,7 @@ virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::
};
p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
UdpStack *udpstack, std::string bootstrapfile)
:p3Config(CONFIG_TYPE_BITDHT), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
{
@ -348,7 +348,7 @@ bool p3BitDht::dropPeer(std::string pid)
/* extract current peer status */
bool p3BitDht::getPeerStatus(std::string id,
bool p3BitDht::getPeerStatus(const RsPeerId& id,
struct sockaddr_storage &/*laddr*/, struct sockaddr_storage &/*raddr*/,
uint32_t &/*type*/, uint32_t &/*mode*/)
{

View file

@ -52,7 +52,7 @@ class DhtPeerDetails
uint32_t mPeerType;
bdId mDhtId;
std::string mRsId;
RsPeerId mRsId;
/* direct from the DHT! */
uint32_t mDhtState; // One of RSDHT_PEERDHT_[...]
@ -142,7 +142,7 @@ class p3NetMgr;
class p3BitDht: public p3Config, public pqiNetAssistConnect, public RsDht
{
public:
p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
UdpStack *udpstack, std::string bootstrapfile);
@ -155,8 +155,8 @@ virtual ~p3BitDht();
virtual uint32_t getNetState(uint32_t type);
virtual int getDhtPeers(int lvl, std::list<RsDhtPeer> &peers);
virtual int getNetPeerList(std::list<std::string> &peerIds);
virtual int getNetPeerStatus(std::string peerId, RsDhtNetPeer &status);
virtual int getNetPeerList(std::list<RsPeerId> &peerIds);
virtual int getNetPeerStatus(const RsPeerId& peerId, RsDhtNetPeer &status);
virtual int getRelayEnds(std::list<RsDhtRelayEnd> &relayEnds);
virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies);
@ -194,20 +194,20 @@ virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
/* pqiNetAssistConnect - external interface functions */
/* add / remove peers */
virtual bool findPeer(std::string id);
virtual bool dropPeer(std::string id);
virtual bool findPeer(const RsPeerId& id);
virtual bool dropPeer(const RsPeerId& id);
virtual int addBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age);
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags);
virtual int addKnownPeer(const RsPeerId &pid, const struct sockaddr_storage &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);
virtual void ConnectionFeedback(const RsPeerId& pid, int state);
/* extract current peer status */
virtual bool getPeerStatus(std::string id,
virtual bool getPeerStatus(const RsPeerId& id,
struct sockaddr_storage &laddr, struct sockaddr_storage &raddr,
uint32_t &type, uint32_t &mode);
@ -255,18 +255,18 @@ int installRelayConnection(const bdId *srcId, const bdId *destId, uint32_t &ban
int removeRelayConnection(const bdId *srcId, const bdId *destId);
void monitorConnections();
void ConnectCallout(const std::string &peerId, struct sockaddr_in addr, uint32_t connectMode);
void ConnectCallout(const RsPeerId &peerId, struct sockaddr_in addr, uint32_t connectMode);
void ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in addr);
void ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay);
void ConnectCalloutRelay(const std::string &peerId, struct sockaddr_in srcaddr,
void ConnectCalloutTCPAttempt(const RsPeerId &peerId, struct sockaddr_in addr);
void ConnectCalloutDirectOrProxy(const RsPeerId &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay);
void ConnectCalloutRelay(const RsPeerId &peerId, struct sockaddr_in srcaddr,
struct sockaddr_in proxyaddr, struct sockaddr_in destaddr,
uint32_t connectMode, uint32_t bandwidth);
void Feedback_Connected(std::string pid);
void Feedback_ConnectionFailed(std::string pid);
void Feedback_ConnectionClosed(std::string pid);
void Feedback_Connected(const RsPeerId& pid);
void Feedback_ConnectionFailed(const RsPeerId& pid);
void Feedback_ConnectionClosed(const RsPeerId& pid);
void UdpConnectionFailed_locked(DhtPeerDetails *dpd);
void ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely);
@ -337,24 +337,24 @@ int pushRelayServers();
public:
int removePeer(const std::string pid);
int removePeer(const RsPeerId& pid);
// Can be used externally too.
int calculateNodeId(const std::string pid, bdNodeId *id);
int calculateNodeId(const RsPeerId& pid, bdNodeId *id);
int addKnownNode(const bdId *id, uint32_t flags);
private:
DhtPeerDetails *addInternalPeer_locked(const std::string pid, uint32_t type);
int removeInternalPeer_locked(const std::string pid);
DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, uint32_t type);
int removeInternalPeer_locked(const RsPeerId& pid);
DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type);
DhtPeerDetails *findInternalRsPeer_locked(const std::string &pid);
DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid);
bool havePeerTranslation_locked(const std::string &pid);
int lookupNodeId_locked(const std::string pid, bdNodeId *id);
int lookupRsId_locked(const bdNodeId *id, std::string &pid);
int storeTranslation_locked(const std::string pid);
int removeTranslation_locked(const std::string pid);
bool havePeerTranslation_locked(const RsPeerId &pid);
int lookupNodeId_locked(const RsPeerId& pid, bdNodeId *id);
int lookupRsId_locked(const bdNodeId *id, RsPeerId &pid);
int storeTranslation_locked(const RsPeerId& pid);
int removeTranslation_locked(const RsPeerId& pid);
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
UdpStunner *mDhtStunner;
@ -372,14 +372,14 @@ int removeTranslation_locked(const std::string pid);
p3BitDhtRelayHandler *mRelayHandler;
std::string mOwnRsId;
RsPeerId mOwnRsId;
bdNodeId mOwnDhtId;
time_t mMinuteTS;
/* translation maps */
std::map<std::string, bdNodeId> mTransToNodeId;
std::map<bdNodeId, std::string> mTransToRsId;
std::map<RsPeerId, bdNodeId> mTransToNodeId;
std::map<bdNodeId, RsPeerId> mTransToRsId;
std::map<bdNodeId, DhtPeerDetails> mPeers;
std::map<bdNodeId, DhtPeerDetails> mFailedPeers;

View file

@ -66,7 +66,7 @@ int p3BitDht::getDhtPeers(int lvl, std::list<RsDhtPeer> &peers)
return (int_peers.entries.size() > 0);
}
int p3BitDht::getNetPeerList(std::list<std::string> &peerIds)
int p3BitDht::getNetPeerList(std::list<RsPeerId> &peerIds)
{
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
std::map<bdNodeId, DhtPeerDetails>::iterator it;
@ -78,7 +78,7 @@ int p3BitDht::getNetPeerList(std::list<std::string> &peerIds)
return 1;
}
int p3BitDht::getNetPeerStatus(std::string peerId, RsDhtNetPeer &status)
int p3BitDht::getNetPeerStatus(const RsPeerId& peerId, RsDhtNetPeer &status)
{
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/

View file

@ -48,7 +48,7 @@
int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/, std::string /*info*/)
{
/* translate info */
std::string rsid;
RsPeerId rsid;
struct sockaddr_in addr = id->addr;
int outtype = PNASS_TYPE_BADPEER;
int outreason = PNASS_REASON_UNKNOWN;
@ -143,7 +143,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
#endif
mProxyStunner->addStunPeer(id->addr, "");
//mProxyStunner->addStunPeer(id->addr, NULL);
}
/* else */ // removed else until we have lots of peers.
@ -154,7 +154,7 @@ int p3BitDht::NodeCallback(const bdId *id, uint32_t peerflags)
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
#endif
mDhtStunner->addStunPeer(id->addr, "");
//mDhtStunner->addStunPeer(id->addr, NULL);
}
}
return 1;
@ -1569,7 +1569,7 @@ int p3BitDht::doActions()
std::cerr << std::endl;
#endif
std::string peerRsId;
RsPeerId peerRsId;
bool foundPeerId = false;
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
@ -1774,7 +1774,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
*/
void p3BitDht::ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in raddrv4)
void p3BitDht::ConnectCalloutTCPAttempt(const RsPeerId &peerId, struct sockaddr_in raddrv4)
{
struct sockaddr_storage raddr;
struct sockaddr_storage proxyaddr;
@ -1802,7 +1802,7 @@ void p3BitDht::ConnectCalloutTCPAttempt(const std::string &peerId, struct sockad
}
void p3BitDht::ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddrv4, uint32_t connectFlags, uint32_t delay)
void p3BitDht::ConnectCalloutDirectOrProxy(const RsPeerId &peerId, struct sockaddr_in raddrv4, uint32_t connectFlags, uint32_t delay)
{
struct sockaddr_storage raddr;
struct sockaddr_storage proxyaddr;
@ -1827,7 +1827,7 @@ void p3BitDht::ConnectCalloutDirectOrProxy(const std::string &peerId, struct soc
mConnCb->peerConnectRequest(peerId, raddr, proxyaddr, srcaddr, source, connectFlags, delay, bandwidth);
}
void p3BitDht::ConnectCalloutRelay(const std::string &peerId,
void p3BitDht::ConnectCalloutRelay(const RsPeerId &peerId,
struct sockaddr_in srcaddrv4, struct sockaddr_in proxyaddrv4, struct sockaddr_in destaddrv4,
uint32_t connectFlags, uint32_t bandwidth)
{
@ -1944,7 +1944,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
#endif
// uint32_t touConnectMode = 0;
std::string rsId;
RsPeerId rsId;
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
@ -2054,10 +2054,10 @@ int p3BitDht::installRelayConnection(const bdId *srcId, const bdId *destId, uint
int relayClass = UDP_RELAY_CLASS_GENERAL;
#ifdef DEBUG_PEERNET
std::string strId1;
RsPeerId strId1;
bdStdPrintNodeId(strId1, &(srcId->id), false);
std::string strId2;
RsPeerId strId2;
bdStdPrintNodeId(strId2, &(destId->id), false);
#endif
@ -2180,7 +2180,7 @@ void p3BitDht::monitorConnections()
void p3BitDht::Feedback_Connected(std::string pid)
void p3BitDht::Feedback_Connected(const RsPeerId& pid)
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
@ -2255,7 +2255,7 @@ void p3BitDht::Feedback_Connected(std::string pid)
ReleaseProxyExclusiveMode_locked(dpd, true);
}
void p3BitDht::Feedback_ConnectionFailed(std::string pid)
void p3BitDht::Feedback_ConnectionFailed(const RsPeerId& pid)
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
@ -2278,7 +2278,7 @@ void p3BitDht::Feedback_ConnectionFailed(std::string pid)
return UdpConnectionFailed_locked(dpd);
}
void p3BitDht::Feedback_ConnectionClosed(std::string pid)
void p3BitDht::Feedback_ConnectionClosed(const RsPeerId& pid)
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
@ -2419,7 +2419,7 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
}
void p3BitDht::ConnectionFeedback(std::string pid, int mode)
void p3BitDht::ConnectionFeedback(const RsPeerId& pid, int mode)
{
#ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::ConnectionFeedback() peer: " << pid;

View file

@ -54,7 +54,7 @@
#define USE_OLD_DHT_INTERFACE 1
bool p3BitDht::findPeer(std::string pid)
bool p3BitDht::findPeer(const RsPeerId& pid)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer(" << pid << ")";
@ -133,7 +133,7 @@ bool p3BitDht::findPeer(std::string pid)
return true ;
}
bool p3BitDht::dropPeer(std::string pid)
bool p3BitDht::dropPeer(const RsPeerId& pid)
{
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::dropPeer(" << pid << ")";
@ -216,7 +216,7 @@ int p3BitDht::addBadPeer(const struct sockaddr_storage &addr, uint32_t /*reason*
}
int p3BitDht::addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags)
int p3BitDht::addKnownPeer(const RsPeerId &pid, const struct sockaddr_storage &addr, uint32_t flags)
{
struct sockaddr_in addrv4;
@ -389,7 +389,7 @@ int p3BitDht::addOther(const std::string pid)
#endif
int p3BitDht::removePeer(const std::string pid)
int p3BitDht::removePeer(const RsPeerId& pid)
{
RsStackMutex stack(dhtMtx); /********* LOCKED *********/
@ -401,7 +401,7 @@ int p3BitDht::removePeer(const std::string pid)
********************************* Basic Peer Details *************************************
******************************************************************************************/
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, uint32_t type)
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t type)
{
/* create the data structure */
if (!havePeerTranslation_locked(pid))
@ -435,7 +435,7 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, uint32_t
}
int p3BitDht::removeInternalPeer_locked(const std::string pid)
int p3BitDht::removeInternalPeer_locked(const RsPeerId& pid)
{
bdNodeId id;
if (!lookupNodeId_locked(pid, &id))
@ -478,7 +478,7 @@ DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, uint32_
/* interface to get with alt id */
DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const std::string &pid)
DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
{
/* create the data structure */
if (!havePeerTranslation_locked(pid))
@ -502,14 +502,14 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const std::string &pid)
*************************** Fundamental Node Translation *********************************
******************************************************************************************/
bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
bool p3BitDht::havePeerTranslation_locked(const RsPeerId &pid)
{
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::havePeerTranslation_locked() for : " << pid;
std::cerr << std::endl;
#endif
std::map<std::string, bdNodeId>::iterator it;
std::map<RsPeerId, bdNodeId>::iterator it;
it = mTransToNodeId.find(pid);
if (it == mTransToNodeId.end())
{
@ -531,14 +531,14 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
}
int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
int p3BitDht::lookupNodeId_locked(const RsPeerId& pid, bdNodeId *id)
{
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::lookupNodeId_locked() for : " << pid;
std::cerr << std::endl;
#endif
std::map<std::string, bdNodeId>::iterator it;
std::map<RsPeerId, bdNodeId>::iterator it;
it = mTransToNodeId.find(pid);
if (it == mTransToNodeId.end())
{
@ -562,7 +562,7 @@ int p3BitDht::lookupNodeId_locked(const std::string pid, bdNodeId *id)
}
int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
int p3BitDht::lookupRsId_locked(const bdNodeId *id, RsPeerId&pid)
{
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::lookupRsId_locked() for : ";
@ -570,7 +570,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
std::cerr << std::endl;
#endif
std::map<bdNodeId, std::string>::iterator nit;
std::map<bdNodeId, RsPeerId>::iterator nit;
nit = mTransToRsId.find(*id);
if (nit == mTransToRsId.end())
{
@ -592,7 +592,7 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
return 1;
}
int p3BitDht::storeTranslation_locked(const std::string pid)
int p3BitDht::storeTranslation_locked(const RsPeerId& pid)
{
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")";
@ -619,7 +619,7 @@ int p3BitDht::storeTranslation_locked(const std::string pid)
return 1;
}
int p3BitDht::removeTranslation_locked(const std::string pid)
int p3BitDht::removeTranslation_locked(const RsPeerId& pid)
{
#ifdef DEBUG_BITDHT_TRANSLATE
@ -627,7 +627,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
std::cerr << std::endl;
#endif
std::map<std::string, bdNodeId>::iterator it = mTransToNodeId.find(pid);
std::map<RsPeerId, bdNodeId>::iterator it = mTransToNodeId.find(pid);
it = mTransToNodeId.find(pid);
if (it == mTransToNodeId.end())
{
@ -646,7 +646,7 @@ int p3BitDht::removeTranslation_locked(const std::string pid)
#endif
std::map<bdNodeId, std::string>::iterator nit;
std::map<bdNodeId, RsPeerId>::iterator nit;
nit = mTransToRsId.find(nid);
if (nit == mTransToRsId.end())
{
@ -676,7 +676,7 @@ const uint8_t RS_DHT_VERSION_LEN = 17;
const uint8_t rs_dht_version_data[RS_DHT_VERSION_LEN] = "RS_VERSION_0.5.1";
/******************** Conversion Functions **************************/
int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
int p3BitDht::calculateNodeId(const RsPeerId& pid, bdNodeId *id)
{
/* generate node id from pid */
#ifdef DEBUG_BITDHT_TRANSLATE
@ -691,7 +691,7 @@ int p3BitDht::calculateNodeId(const std::string pid, bdNodeId *id)
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, rs_dht_version_data, RS_DHT_VERSION_LEN);
SHA1_Update(sha_ctx, pid.c_str(), pid.length());
SHA1_Update(sha_ctx, pid.toByteArray(), RsPeerId::SIZE_IN_BYTES);
SHA1_Final(sha_hash, sha_ctx);
for(int i = 0; i < SHA_DIGEST_LENGTH && (i < BITDHT_KEY_LEN); i++)