mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-24 15:05:35 -04:00
Addition of a new Automatic DHT Bootstrap system. This will need to be tweaked as the numbers of users increase.
* hashed keys are posted to specific DHT entries, to create a series of bootstrap lists. * these are fetched as needed to bootstrap new clients. * Modified Bootstrap monitor program. Created a minimal backup bootstrap list (temporary) Added "-e" option to commandline to force 'external port' mode Bugfix for multiple connection methods, could kill an active connection. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@397 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
22aff3aa60
commit
247e583a35
8 changed files with 783 additions and 104 deletions
libretroshare/src/dht
|
@ -129,31 +129,6 @@ virtual void peerStatus(std::string id,
|
|||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t type, uint32_t mode, uint32_t source)
|
||||
{
|
||||
|
||||
{
|
||||
RsStackMutex stack(peerMtx); /**** LOCK MUTEX ***/
|
||||
|
||||
std::map<std::string, StunDetails>::iterator it;
|
||||
it = peerMap.find(id);
|
||||
if (it == peerMap.end())
|
||||
{
|
||||
std::cerr << "peerStatus() for unknown Peer id: " << id;
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
it->second.laddr = laddr;
|
||||
it->second.raddr = raddr;
|
||||
it->second.type = type;
|
||||
it->second.mode = mode;
|
||||
it->second.source= source;
|
||||
|
||||
it->second.lastStatus = time(NULL);
|
||||
|
||||
it->second.stunAttempts++; /* as we are about to try! */
|
||||
}
|
||||
|
||||
printPeerStatus();
|
||||
stunPeer(id, raddr);
|
||||
}
|
||||
|
||||
void printPeerStatus()
|
||||
|
@ -165,7 +140,7 @@ void printPeerStatus()
|
|||
std::cerr << "BootstrapStatus: " << timestr;
|
||||
std::cerr << "BootstrapStatus: " << peerMap.size() << " Peers";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "BootstrapStatus: ID ---------- DHT ENTRY ---";
|
||||
std::cerr << "BootstrapStatus: ID --------------------- DHT ENTRY ---";
|
||||
std::cerr << " EXT PORT -- STUN OK -- %AVAIL -- LAST DHT TS";
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
@ -173,7 +148,7 @@ void printPeerStatus()
|
|||
|
||||
for(it = peerMap.begin(); it != peerMap.end(); it++)
|
||||
{
|
||||
std::cerr << it->first;
|
||||
std::cerr << RsUtil::BinToHex(it->first);
|
||||
|
||||
bool dhtActive = (time(NULL) - it->second.lastStatus < 1900);
|
||||
bool stunActive = (time(NULL) - it->second.lastStunResult < 1900);
|
||||
|
@ -228,7 +203,8 @@ void printPeerStatus()
|
|||
|
||||
void stunPeer(std::string id, struct sockaddr_in peeraddr)
|
||||
{
|
||||
std::cerr << "Should Stun Peer: " << id;
|
||||
std::cerr << "stunPeer: 0x" << RsUtil::BinToHex(id);
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* launch a publishThread */
|
||||
|
@ -256,6 +232,27 @@ virtual void peerConnectRequest(std::string id,
|
|||
|
||||
virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags)
|
||||
{
|
||||
addPeer(id);
|
||||
{
|
||||
RsStackMutex stack(peerMtx); /**** LOCK MUTEX ***/
|
||||
|
||||
std::map<std::string, StunDetails>::iterator it;
|
||||
it = peerMap.find(id);
|
||||
if (it == peerMap.end())
|
||||
{
|
||||
std::cerr << "peerStatus() for unknown Peer id: 0x" << RsUtil::BinToHex(id);
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
it->second.raddr = raddr;
|
||||
it->second.type = type;
|
||||
it->second.lastStatus = time(NULL);
|
||||
|
||||
it->second.stunAttempts++; /* as we are about to try! */
|
||||
}
|
||||
|
||||
printPeerStatus();
|
||||
stunPeer(id, raddr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -268,11 +265,11 @@ virtual void stunSuccess(std::string id, struct sockaddr_in toaddr, struct so
|
|||
it = peerMap.find(id);
|
||||
if (it == peerMap.end())
|
||||
{
|
||||
std::cerr << "stunSuccess() for unknown Peer id: " << id;
|
||||
std::cerr << "stunSuccess() for unknown Peer id: 0x" << RsUtil::BinToHex(id);
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cerr << "stunSuccess() for id: " << id;
|
||||
std::cerr << "stunSuccess() for id: 0x" << RsUtil::BinToHex(id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
it->second.lastStunResult = time(NULL);
|
||||
|
@ -374,13 +371,6 @@ int main(int argc, char **argv)
|
|||
ownId = "dummyOwnId";
|
||||
}
|
||||
|
||||
if (peerIds.size() < 1)
|
||||
{
|
||||
std::cerr << "No PeerIds, loading bootstrap Ids";
|
||||
std::cerr << std::endl;
|
||||
loadBootStrapIds(peerIds);
|
||||
}
|
||||
|
||||
pqiConnectCbStun cbStun;
|
||||
OpenDHTMgr dhtTester(ownId, &cbStun, ".");
|
||||
|
||||
|
@ -401,15 +391,6 @@ int main(int argc, char **argv)
|
|||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.setDhtOn(true);
|
||||
|
||||
std::cerr << "Adding a List of Peers" << std::endl;
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = peerIds.begin(); it != peerIds.end(); it++)
|
||||
{
|
||||
cbStun.addPeer(*it);
|
||||
dhtTester.findPeer(*it);
|
||||
}
|
||||
|
||||
|
||||
/* wait loop */
|
||||
while(1)
|
||||
{
|
||||
|
@ -426,35 +407,6 @@ int main(int argc, char **argv)
|
|||
};
|
||||
|
||||
|
||||
void loadBootStrapIds(std::list<std::string> &peerIds)
|
||||
{
|
||||
std::string id;
|
||||
|
||||
// Two Defaults for The Initial Release.
|
||||
id = "7ad672ea4d4af8560d5230aff3c88b59";
|
||||
peerIds.push_back(id);
|
||||
|
||||
id = "8ad7c08e7778e0289de04843bf57a6ae";
|
||||
peerIds.push_back(id);
|
||||
|
||||
// Donated by public.
|
||||
id = "8523688347027884059506005618ae74"; /* tm */
|
||||
peerIds.push_back(id);
|
||||
|
||||
id = "1bd15b320269fa1561ceb1162fd042f0"; /* cp */
|
||||
peerIds.push_back(id);
|
||||
|
||||
id = "2cf2361f2afcd6d871159714bbbfc502"; /* cc */
|
||||
peerIds.push_back(id);
|
||||
|
||||
id = "128646cdf761970376a62c52c372c931"; /* rf */
|
||||
peerIds.push_back(id);
|
||||
|
||||
id = "86d5d94474a4b8ac4386686eff31aeb9"; /* bn */
|
||||
peerIds.push_back(id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool stunPeer(struct sockaddr_in toaddr, struct sockaddr_in &ansaddr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue