mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-28 02:41:36 -05:00
Merge pull request #2199 from hunbernd/fix/brokenbdboot
Fix: DHT cannot bootstrap if bdboot.txt is corrupted.
This commit is contained in:
commit
3864304ca9
@ -64,8 +64,8 @@
|
|||||||
#define QUERY_UPDATE_PERIOD 8 // under refresh period - so it'll happen at the MAX_REFRESH_PERIOD
|
#define QUERY_UPDATE_PERIOD 8 // under refresh period - so it'll happen at the MAX_REFRESH_PERIOD
|
||||||
|
|
||||||
|
|
||||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, const std::string& filterfile,bdDhtFunctions *fns)
|
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, std::string bootfilebak, const std::string& filterfile, bdDhtFunctions *fns)
|
||||||
:bdNode(id, dhtVersion, bootfile, filterfile, fns, this)
|
:bdNode(id, dhtVersion, bootfile, bootfilebak,filterfile, fns, this)
|
||||||
{
|
{
|
||||||
mMode = BITDHT_MGR_STATE_OFF;
|
mMode = BITDHT_MGR_STATE_OFF;
|
||||||
mDhtFns = fns;
|
mDhtFns = fns;
|
||||||
|
@ -90,7 +90,7 @@ class bdQueryPeer
|
|||||||
class bdNodeManager: public bdNode, public BitDhtInterface
|
class bdNodeManager: public bdNode, public BitDhtInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, const std::string &filterfile, bdDhtFunctions *fns);
|
bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, std::string bootfilebak, const std::string &filterfile, bdDhtFunctions *fns);
|
||||||
|
|
||||||
|
|
||||||
void iteration();
|
void iteration();
|
||||||
|
@ -67,12 +67,12 @@
|
|||||||
|
|
||||||
#define HISTORY_PERIOD 60
|
#define HISTORY_PERIOD 60
|
||||||
|
|
||||||
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, const std::string& bootfile, const std::string& filterfile, bdDhtFunctions *fns, bdNodeManager *manager)
|
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, const std::string& bootfile, const std::string &bootfilebak, const std::string& filterfile, bdDhtFunctions *fns, bdNodeManager *manager)
|
||||||
:mNodeSpace(ownId, fns),
|
:mNodeSpace(ownId, fns),
|
||||||
mFilterPeers(filterfile,ownId, BITDHT_FILTER_REASON_OWNID, fns, manager),
|
mFilterPeers(filterfile,ownId, BITDHT_FILTER_REASON_OWNID, fns, manager),
|
||||||
mQueryMgr(NULL),
|
mQueryMgr(NULL),
|
||||||
mConnMgr(NULL),
|
mConnMgr(NULL),
|
||||||
mOwnId(*ownId), mDhtVersion(dhtVersion), mStore(bootfile, fns), mFns(fns),
|
mOwnId(*ownId), mDhtVersion(dhtVersion), mStore(bootfile, bootfilebak, fns), mFns(fns),
|
||||||
mFriendList(ownId), mHistory(HISTORY_PERIOD)
|
mFriendList(ownId), mHistory(HISTORY_PERIOD)
|
||||||
{
|
{
|
||||||
init(); /* (uses this pointers) stuff it - do it here! */
|
init(); /* (uses this pointers) stuff it - do it here! */
|
||||||
|
@ -117,7 +117,7 @@ class bdNode: public bdNodePublisher
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bdNode(bdNodeId *id, std::string dhtVersion, const std::string& bootfile, const std::string& filterfile,
|
bdNode(bdNodeId *id, std::string dhtVersion, const std::string& bootfile, const std::string& bootfilebak, const std::string& filterfile,
|
||||||
bdDhtFunctions *fns, bdNodeManager* manager);
|
bdDhtFunctions *fns, bdNodeManager* manager);
|
||||||
|
|
||||||
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
//#define DEBUG_STORE 1
|
//#define DEBUG_STORE 1
|
||||||
|
|
||||||
bdStore::bdStore(std::string file, bdDhtFunctions *fns)
|
bdStore::bdStore(std::string file, std::string backupfile, bdDhtFunctions *fns)
|
||||||
:mFns(fns)
|
:mFns(fns)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_STORE
|
#ifdef DEBUG_STORE
|
||||||
@ -39,6 +39,7 @@ bdStore::bdStore(std::string file, bdDhtFunctions *fns)
|
|||||||
|
|
||||||
/* read data from file */
|
/* read data from file */
|
||||||
mStoreFile = file;
|
mStoreFile = file;
|
||||||
|
mStoreFileBak = backupfile;
|
||||||
|
|
||||||
reloadFromStore();
|
reloadFromStore();
|
||||||
}
|
}
|
||||||
@ -51,13 +52,25 @@ int bdStore::clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bdStore::reloadFromStore()
|
int bdStore::reloadFromStore()
|
||||||
|
{
|
||||||
|
int result = reloadFromStore(mStoreFile);
|
||||||
|
if( result != 0 && store.size() > 0){
|
||||||
|
return result;
|
||||||
|
} else if(mStoreFileBak != "") { //Nothing loaded, try the backup file
|
||||||
|
return reloadFromStore(mStoreFileBak);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int bdStore::reloadFromStore(std::string file)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
FILE *fd = fopen(mStoreFile.c_str(), "r");
|
FILE *fd = fopen(file.c_str(), "r");
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to Open File: %s ... No Peers\n", mStoreFile.c_str());
|
fprintf(stderr, "Failed to Open File: %s ... No Peers\n", file.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,10 +30,11 @@ class bdStore
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bdStore(std::string file, bdDhtFunctions *fns);
|
bdStore(std::string file, std::string backupfile, bdDhtFunctions *fns);
|
||||||
|
|
||||||
int reloadFromStore(); /* for restarts */
|
int reloadFromStore(); /* for restarts */
|
||||||
int filterIpList(const std::list<struct sockaddr_in> &filteredIPs);
|
int reloadFromStore(std::string file);
|
||||||
|
int filterIpList(const std::list<struct sockaddr_in> &filteredIPs);
|
||||||
int clear();
|
int clear();
|
||||||
|
|
||||||
int getPeer(bdPeer *peer);
|
int getPeer(bdPeer *peer);
|
||||||
@ -43,6 +44,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string mStoreFile;
|
std::string mStoreFile;
|
||||||
|
std::string mStoreFileBak;
|
||||||
std::list<bdPeer> store;
|
std::list<bdPeer> store;
|
||||||
int mIndex;
|
int mIndex;
|
||||||
bdDhtFunctions *mFns;
|
bdDhtFunctions *mFns;
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
/*************************************/
|
/*************************************/
|
||||||
|
|
||||||
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, const std::string& filteredipfile, bdDhtFunctions *fns)
|
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, std::string bootstrapfilebak, const std::string& filteredipfile, bdDhtFunctions *fns)
|
||||||
:UdpSubReceiver(pub), dhtMtx(true)//, mFns(fns)
|
:UdpSubReceiver(pub), dhtMtx(true)//, mFns(fns)
|
||||||
{
|
{
|
||||||
std::string usedVersion;
|
std::string usedVersion;
|
||||||
@ -72,7 +72,7 @@ UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, st
|
|||||||
|
|
||||||
/* setup nodeManager */
|
/* setup nodeManager */
|
||||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||||
mBitDhtManager = new bdNodeManager(id, usedVersion, bootstrapfile, filteredipfile, fns);
|
mBitDhtManager = new bdNodeManager(id, usedVersion, bootstrapfile, bootstrapfilebak, filteredipfile, fns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class UdpBitDht: public UdpSubReceiver, public bdThread, public BitDhtInterface
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string dhtVersion, std::string bootstrapfile, const std::string& filteredipfile,bdDhtFunctions *fns);
|
UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string dhtVersion, std::string bootstrapfile, std::string bootstrapfilebak, const std::string& filteredipfile,bdDhtFunctions *fns);
|
||||||
virtual ~UdpBitDht();
|
virtual ~UdpBitDht();
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::
|
|||||||
|
|
||||||
|
|
||||||
p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||||
UdpStack *udpstack, std::string bootstrapfile,const std::string& filteredipfile)
|
UdpStack *udpstack, std::string bootstrapfile, std::string bootstrapfilebak, const std::string& filteredipfile)
|
||||||
:p3Config(), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
|
:p3Config(), pqiNetAssistConnect(id, cb), mNetMgr(nm), dhtMtx("p3BitDht")
|
||||||
{
|
{
|
||||||
#ifdef RS_USE_DHT_STUNNER
|
#ifdef RS_USE_DHT_STUNNER
|
||||||
@ -163,7 +163,7 @@ p3BitDht::p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* create dht */
|
/* create dht */
|
||||||
mUdpBitDht = new UdpBitDht(udpstack, &mOwnDhtId, dhtVersion, bootstrapfile, filteredipfile,mDhtFns);
|
mUdpBitDht = new UdpBitDht(udpstack, &mOwnDhtId, dhtVersion, bootstrapfile, bootstrapfilebak, filteredipfile,mDhtFns);
|
||||||
udpstack->addReceiver(mUdpBitDht);
|
udpstack->addReceiver(mUdpBitDht);
|
||||||
|
|
||||||
/* setup callback to here */
|
/* setup callback to here */
|
||||||
|
@ -141,7 +141,7 @@ class p3BitDht: public p3Config, public pqiNetAssistConnect, public RsDht
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
p3BitDht(const RsPeerId& id, pqiConnectCb *cb, p3NetMgr *nm,
|
||||||
UdpStack *udpstack, std::string bootstrapfile, const std::string &filteredipfile);
|
UdpStack *udpstack, std::string bootstrapfile, std::string bootstrapfilebak, const std::string &filteredipfile);
|
||||||
|
|
||||||
|
|
||||||
virtual ~p3BitDht();
|
virtual ~p3BitDht();
|
||||||
|
@ -989,6 +989,13 @@ int RsServer::StartupRetroShare()
|
|||||||
bootstrapfile += "/";
|
bootstrapfile += "/";
|
||||||
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
|
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||||
|
|
||||||
|
std::string installfile = "";
|
||||||
|
#ifndef __ANDROID__
|
||||||
|
installfile = RsAccounts::systemDataDirectory();
|
||||||
|
installfile += "/";
|
||||||
|
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string filteredipfile = RsAccounts::AccountDirectory();
|
std::string filteredipfile = RsAccounts::AccountDirectory();
|
||||||
if (filteredipfile != "")
|
if (filteredipfile != "")
|
||||||
filteredipfile += "/";
|
filteredipfile += "/";
|
||||||
@ -1029,10 +1036,6 @@ int RsServer::StartupRetroShare()
|
|||||||
bdbootRF.close();
|
bdbootRF.close();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::string installfile = RsAccounts::systemDataDirectory();
|
|
||||||
installfile += "/";
|
|
||||||
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
|
||||||
|
|
||||||
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
||||||
if ((installfile != "") && (RsDirUtil::checkFile(installfile,tmp_size)))
|
if ((installfile != "") && (RsDirUtil::checkFile(installfile,tmp_size)))
|
||||||
{
|
{
|
||||||
@ -1080,7 +1083,7 @@ int RsServer::StartupRetroShare()
|
|||||||
// NEXT BITDHT.
|
// NEXT BITDHT.
|
||||||
|
|
||||||
|
|
||||||
mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, filteredipfile);
|
mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile, installfile, filteredipfile);
|
||||||
|
|
||||||
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
|
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
|
||||||
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
|
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user