mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 22:52:54 -04:00
Removed p3ConnectMgr. Replaced it with p3LinkMgr, p3NetMgr and p3PeerMgr.
Updated references in other classes. * Most classes need p3LinkMgr, and only use two functions: OwnId() and getOnlineList() git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4416 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
21487bfdf6
commit
f6f721a492
55 changed files with 1226 additions and 1044 deletions
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
#include "dbase/cachestrapper.h"
|
#include "dbase/cachestrapper.h"
|
||||||
#include "serialiser/rsconfigitems.h"
|
#include "serialiser/rsconfigitems.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -542,8 +543,8 @@ void CacheStore::locked_storeCacheEntry(const CacheData &data)
|
||||||
*
|
*
|
||||||
********************************* CacheStrapper ********************************/
|
********************************* CacheStrapper ********************************/
|
||||||
|
|
||||||
CacheStrapper::CacheStrapper(p3ConnectMgr *cm)
|
CacheStrapper::CacheStrapper(p3LinkMgr *lm)
|
||||||
:p3Config(CONFIG_TYPE_CACHE), mConnMgr(cm), csMtx("CacheStrapper")
|
:p3Config(CONFIG_TYPE_CACHE), mLinkMgr(lm), csMtx("CacheStrapper")
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -595,7 +596,7 @@ void CacheStrapper::refreshCache(const CacheData &data)
|
||||||
std::list<std::string> ids;
|
std::list<std::string> ids;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
|
|
||||||
mConnMgr->getOnlineList(ids);
|
mLinkMgr->getOnlineList(ids);
|
||||||
|
|
||||||
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
||||||
for(it = ids.begin(); it != ids.end(); it++)
|
for(it = ids.begin(); it != ids.end(); it++)
|
||||||
|
@ -607,7 +608,7 @@ void CacheStrapper::refreshCache(const CacheData &data)
|
||||||
mCacheUpdates.push_back(std::make_pair(*it, data));
|
mCacheUpdates.push_back(std::make_pair(*it, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
mCacheUpdates.push_back(std::make_pair(mConnMgr->getOwnId(), data));
|
mCacheUpdates.push_back(std::make_pair(mLinkMgr->getOwnId(), data));
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
}
|
}
|
||||||
|
@ -688,7 +689,7 @@ void CacheStrapper::listCaches(std::ostream &out)
|
||||||
{
|
{
|
||||||
/* can overwrite for more control! */
|
/* can overwrite for more control! */
|
||||||
std::map<uint16_t, CachePair>::iterator it;
|
std::map<uint16_t, CachePair>::iterator it;
|
||||||
out << "CacheStrapper::listCaches() [" << mConnMgr->getOwnId();
|
out << "CacheStrapper::listCaches() [" << mLinkMgr->getOwnId();
|
||||||
out << "] " << " Total Caches: " << caches.size();
|
out << "] " << " Total Caches: " << caches.size();
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
for(it = caches.begin(); it != caches.end(); it++)
|
for(it = caches.begin(); it != caches.end(); it++)
|
||||||
|
@ -781,7 +782,7 @@ bool CacheStrapper::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
std::list<CacheData>::iterator cit;
|
std::list<CacheData>::iterator cit;
|
||||||
std::list<CacheData> ownCaches;
|
std::list<CacheData> ownCaches;
|
||||||
std::list<CacheData> remoteCaches;
|
std::list<CacheData> remoteCaches;
|
||||||
std::string ownId = mConnMgr->getOwnId();
|
std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
std::map<uint16_t, CachePair>::iterator it;
|
std::map<uint16_t, CachePair>::iterator it;
|
||||||
for(it = caches.begin(); it != caches.end(); it++)
|
for(it = caches.begin(); it != caches.end(); it++)
|
||||||
|
@ -861,11 +862,11 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||||
#endif
|
#endif
|
||||||
std::list<CacheData> ownCaches;
|
std::list<CacheData> ownCaches;
|
||||||
std::list<CacheData> remoteCaches;
|
std::list<CacheData> remoteCaches;
|
||||||
std::string ownId = mConnMgr->getOwnId();
|
std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
peerConnectState ownState;
|
//peerConnectState ownState;
|
||||||
mConnMgr->getOwnNetStatus(ownState);
|
//mPeerMgr->getOwnNetStatus(ownState);
|
||||||
std::string ownName = ownState.name+" ("+ownState.location+")";
|
//std::string ownName = ownState.name+" ("+ownState.location+")";
|
||||||
|
|
||||||
std::map<std::string, std::list<std::string> > saveFiles;
|
std::map<std::string, std::list<std::string> > saveFiles;
|
||||||
std::map<std::string, std::list<std::string> >::iterator sit;
|
std::map<std::string, std::list<std::string> >::iterator sit;
|
||||||
|
@ -885,6 +886,7 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||||
|
|
||||||
cd.pid = rscc->pid;
|
cd.pid = rscc->pid;
|
||||||
|
|
||||||
|
#if 0
|
||||||
if(cd.pid == ownId)
|
if(cd.pid == ownId)
|
||||||
{
|
{
|
||||||
cd.pname = ownName;
|
cd.pname = ownName;
|
||||||
|
@ -892,9 +894,10 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
peerConnectState pca;
|
peerConnectState pca;
|
||||||
mConnMgr->getFriendNetStatus(rscc->pid, pca);
|
mPeerMgr->getFriendNetStatus(rscc->pid, pca);
|
||||||
cd.pname = pca.name+" ("+pca.location+")";
|
cd.pname = pca.name+" ("+pca.location+")";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
cd.cid.type = rscc->cachetypeid;
|
cd.cid.type = rscc->cachetypeid;
|
||||||
cd.cid.subid = rscc->cachesubid;
|
cd.cid.subid = rscc->cachesubid;
|
||||||
|
|
|
@ -92,7 +92,7 @@ class CacheData
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsPeerId pid; /// peer id
|
RsPeerId pid; /// peer id
|
||||||
std::string pname; /// peer name (can be used by cachestore)
|
/// REMOVED as a WASTE to look it up everywhere! std::string pname; /// peer name (can be used by cachestore)
|
||||||
CacheId cid; /// cache id
|
CacheId cid; /// cache id
|
||||||
std::string path; /// file system path where physical cache data is located
|
std::string path; /// file system path where physical cache data is located
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -408,6 +408,9 @@ bool operator<(const CachePair &a, const CachePair &b);
|
||||||
* CacheStrapper: maintains a set of CacheSources, and CacheStores,
|
* CacheStrapper: maintains a set of CacheSources, and CacheStores,
|
||||||
* queries and updates as new information arrives.
|
* queries and updates as new information arrives.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
class CacheStrapper: public pqiMonitor, public p3Config
|
class CacheStrapper: public pqiMonitor, public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -416,7 +419,7 @@ class CacheStrapper: public pqiMonitor, public p3Config
|
||||||
* @param cm handle used by strapper for getting peer connection information (online peers, sslids...)
|
* @param cm handle used by strapper for getting peer connection information (online peers, sslids...)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CacheStrapper(p3ConnectMgr *cm);
|
CacheStrapper(p3LinkMgr *lm);
|
||||||
virtual ~CacheStrapper() { return; }
|
virtual ~CacheStrapper() { return; }
|
||||||
|
|
||||||
/************* from pqiMonitor *******************/
|
/************* from pqiMonitor *******************/
|
||||||
|
@ -489,7 +492,7 @@ virtual bool loadList(std::list<RsItem *>& load);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* these are static - so shouldn't need mutex */
|
/* these are static - so shouldn't need mutex */
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
std::map<uint16_t, CachePair> caches;
|
std::map<uint16_t, CachePair> caches;
|
||||||
|
|
||||||
|
|
|
@ -424,7 +424,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
fi.root->row = 0;
|
fi.root->row = 0;
|
||||||
fi.root->name = data.pname ;
|
fi.root->name = data.pid; // XXX Hack here - TODO
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,12 +24,12 @@
|
||||||
#include "dbase/fistore.h"
|
#include "dbase/fistore.h"
|
||||||
#include "retroshare/rsexpr.h"
|
#include "retroshare/rsexpr.h"
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3peermgr.h"
|
||||||
|
|
||||||
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
|
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
|
||||||
NotifyBase *cb_in,p3ConnectMgr *cnmgr, RsPeerId ownid, std::string cachedir)
|
NotifyBase *cb_in,p3PeerMgr *cnmgr, RsPeerId ownid, std::string cachedir)
|
||||||
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
|
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
|
||||||
localId(ownid), localindex(NULL), cb(cb_in),mConnMgr(cnmgr)
|
localId(ownid), localindex(NULL), cb(cb_in),mPeerMgr(cnmgr)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ int FileIndexStore::loadCache(const CacheData &data)
|
||||||
|
|
||||||
FileIndex *finew = new FileIndex(data.pid);
|
FileIndex *finew = new FileIndex(data.pid);
|
||||||
|
|
||||||
if(mConnMgr->isFriend(data.pid))
|
if(mPeerMgr->isFriend(data.pid))
|
||||||
{
|
{
|
||||||
// We discard file lists from non friends. This is the place to remove file lists of deleted friends
|
// We discard file lists from non friends. This is the place to remove file lists of deleted friends
|
||||||
// from the cache. Doing this, the file list still shows in a session where we deleted a friend, but will be removed
|
// from the cache. Doing this, the file list still shows in a session where we deleted a friend, but will be removed
|
||||||
|
@ -95,7 +95,7 @@ int FileIndexStore::loadCache(const CacheData &data)
|
||||||
std::cerr << "FileIndexStore::loadCache() Succeeded!" << std::endl;
|
std::cerr << "FileIndexStore::loadCache() Succeeded!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* set the name */
|
/* set the name */
|
||||||
finew->root->name = data.pname;
|
finew->root->name = data.pid; // HACK HERE TODO XXX. name;
|
||||||
|
|
||||||
if (local)
|
if (local)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class p3ConnectMgr ;
|
class p3PeerMgr ;
|
||||||
|
|
||||||
#include "dbase/findex.h"
|
#include "dbase/findex.h"
|
||||||
#include "dbase/cachestrapper.h"
|
#include "dbase/cachestrapper.h"
|
||||||
|
@ -65,7 +65,7 @@ class FileIndexStore: public CacheStore
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3ConnectMgr *cmgr, RsPeerId ownid, std::string cachedir);
|
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3PeerMgr *pmgr, RsPeerId ownid, std::string cachedir);
|
||||||
virtual ~FileIndexStore();
|
virtual ~FileIndexStore();
|
||||||
|
|
||||||
/* virtual functions overloaded by cache implementor */
|
/* virtual functions overloaded by cache implementor */
|
||||||
|
@ -96,7 +96,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
|
||||||
FileIndex *localindex;
|
FileIndex *localindex;
|
||||||
|
|
||||||
NotifyBase *cb;
|
NotifyBase *cb;
|
||||||
p3ConnectMgr *mConnMgr ;
|
p3PeerMgr *mPeerMgr ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
#include "dht/p3bitdht.h"
|
#include "dht/p3bitdht.h"
|
||||||
|
|
||||||
#include "bitdht/bdstddht.h"
|
#include "bitdht/bdstddht.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
#include "pqi/p3linkmgr.h" // FOR FLAGS... move elsewhere
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
|
||||||
#include "tcponudp/udprelay.h"
|
#include "tcponudp/udprelay.h"
|
||||||
#include "tcponudp/udpstunner.h"
|
#include "tcponudp/udpstunner.h"
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
#include "pqi/pqinotify.h"
|
#include "pqi/pqinotify.h"
|
||||||
|
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
|
@ -1150,7 +1150,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
(dit->second)->mTransfer->addFileSource(*it);
|
(dit->second)->mTransfer->addFileSource(*it);
|
||||||
setPeerState(dit->second->mTransfer, *it, rate, mConnMgr->isOnline(*it));
|
setPeerState(dit->second->mTransfer, *it, rate, mLinkMgr->isOnline(*it));
|
||||||
|
|
||||||
IndicateConfigChanged(); /* new peer for transfer -> save */
|
IndicateConfigChanged(); /* new peer for transfer -> save */
|
||||||
}
|
}
|
||||||
|
@ -1245,7 +1245,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||||
std::cerr << "ftController::FileRequest() adding peer: " << *it;
|
std::cerr << "ftController::FileRequest() adding peer: " << *it;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(tm, *it, rate, mConnMgr->isOnline(*it));
|
setPeerState(tm, *it, rate, mLinkMgr->isOnline(*it));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add structures into the accessible data. Needs to be locked */
|
/* add structures into the accessible data. Needs to be locked */
|
||||||
|
@ -1273,7 +1273,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||||
|
|
||||||
bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online)
|
bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t maxrate, bool online)
|
||||||
{
|
{
|
||||||
if (id == mConnMgr->getOwnId())
|
if (id == mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::setPeerState() is Self";
|
std::cerr << "ftController::setPeerState() is Self";
|
||||||
|
|
|
@ -30,9 +30,9 @@
|
||||||
|
|
||||||
//#define DB_DEBUG 1
|
//#define DB_DEBUG 1
|
||||||
|
|
||||||
ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3ConnectMgr *cnmgr,
|
ftFiStore::ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,p3PeerMgr *pm,
|
||||||
RsPeerId ownid, std::string cachedir)
|
RsPeerId ownid, std::string cachedir)
|
||||||
:FileIndexStore(cs, cft, cb_in,cnmgr, ownid, cachedir)
|
:FileIndexStore(cs, cft, cb_in, pm, ownid, cachedir)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -366,8 +366,8 @@ void ftFiMonitor::setSharedDirectories(const std::list<SharedDirInfo>& dirList)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ftCacheStrapper::ftCacheStrapper(p3ConnectMgr *cm)
|
ftCacheStrapper::ftCacheStrapper(p3LinkMgr *lm)
|
||||||
:CacheStrapper(cm)
|
:CacheStrapper(lm)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@
|
||||||
* So they work in the ft world.
|
* So they work in the ft world.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class p3ConnectMgr ;
|
class p3LinkMgr ;
|
||||||
|
class p3PeerMgr ;
|
||||||
|
|
||||||
|
|
||||||
#include "ft/ftsearch.h"
|
#include "ft/ftsearch.h"
|
||||||
#include "pqi/p3cfgmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
|
@ -46,8 +48,7 @@ class p3ConnectMgr ;
|
||||||
class ftFiStore: public FileIndexStore, public ftSearch
|
class ftFiStore: public FileIndexStore, public ftSearch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in, p3PeerMgr *pm,
|
||||||
p3ConnectMgr *,
|
|
||||||
RsPeerId ownid, std::string cachedir);
|
RsPeerId ownid, std::string cachedir);
|
||||||
|
|
||||||
/* overloaded search function */
|
/* overloaded search function */
|
||||||
|
@ -89,7 +90,7 @@ virtual bool loadList(std::list<RsItem *>& load);
|
||||||
class ftCacheStrapper: public CacheStrapper, public ftSearch
|
class ftCacheStrapper: public CacheStrapper, public ftSearch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ftCacheStrapper(p3ConnectMgr *cm);
|
ftCacheStrapper(p3LinkMgr *cm);
|
||||||
|
|
||||||
/* overloaded search function */
|
/* overloaded search function */
|
||||||
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;
|
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;
|
||||||
|
|
|
@ -44,7 +44,7 @@ const int ftserverzone = 29539;
|
||||||
#include "ft/ftdbase.h"
|
#include "ft/ftdbase.h"
|
||||||
|
|
||||||
#include "pqi/pqi.h"
|
#include "pqi/pqi.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
|
|
||||||
|
@ -57,15 +57,15 @@ const int ftserverzone = 29539;
|
||||||
***/
|
***/
|
||||||
|
|
||||||
/* Setup */
|
/* Setup */
|
||||||
ftServer::ftServer(p3ConnectMgr *connMgr)
|
ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
|
||||||
: mP3iface(NULL),
|
: mP3iface(NULL),
|
||||||
mConnMgr(connMgr),
|
mLinkMgr(lm), mPeerMgr(pm),
|
||||||
mCacheStrapper(NULL),
|
mCacheStrapper(NULL),
|
||||||
mFiStore(NULL), mFiMon(NULL),
|
mFiStore(NULL), mFiMon(NULL),
|
||||||
mFtController(NULL), mFtExtra(NULL),
|
mFtController(NULL), mFtExtra(NULL),
|
||||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
||||||
{
|
{
|
||||||
mCacheStrapper = new ftCacheStrapper(connMgr);
|
mCacheStrapper = new ftCacheStrapper(lm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftServer::setConfigDirectory(std::string path)
|
void ftServer::setConfigDirectory(std::string path)
|
||||||
|
@ -101,8 +101,8 @@ void ftServer::addConfigComponents(p3ConfigMgr *mgr)
|
||||||
std::string ftServer::OwnId()
|
std::string ftServer::OwnId()
|
||||||
{
|
{
|
||||||
std::string ownId;
|
std::string ownId;
|
||||||
if (mConnMgr)
|
if (mLinkMgr)
|
||||||
ownId = mConnMgr->getOwnId();
|
ownId = mLinkMgr->getOwnId();
|
||||||
return ownId;
|
return ownId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||||
/* setup FiStore/Monitor */
|
/* setup FiStore/Monitor */
|
||||||
std::string localcachedir = mConfigPath + "/cache/local";
|
std::string localcachedir = mConfigPath + "/cache/local";
|
||||||
std::string remotecachedir = mConfigPath + "/cache/remote";
|
std::string remotecachedir = mConfigPath + "/cache/remote";
|
||||||
std::string ownId = mConnMgr->getOwnId();
|
std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
/* search/extras List */
|
/* search/extras List */
|
||||||
mFtExtra = new ftExtraList();
|
mFtExtra = new ftExtraList();
|
||||||
|
@ -131,7 +131,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||||
|
|
||||||
|
|
||||||
/* Make Cache Source/Store */
|
/* Make Cache Source/Store */
|
||||||
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb,mConnMgr, ownId, remotecachedir);
|
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb, mPeerMgr, ownId, remotecachedir);
|
||||||
mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId,mConfigPath);
|
mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId,mConfigPath);
|
||||||
|
|
||||||
/* now add the set to the cachestrapper */
|
/* now add the set to the cachestrapper */
|
||||||
|
@ -144,8 +144,8 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||||
mFtSearch->addSearchMode(mFiMon, RS_FILE_HINTS_LOCAL);
|
mFtSearch->addSearchMode(mFiMon, RS_FILE_HINTS_LOCAL);
|
||||||
mFtSearch->addSearchMode(mFiStore, RS_FILE_HINTS_REMOTE);
|
mFtSearch->addSearchMode(mFiStore, RS_FILE_HINTS_REMOTE);
|
||||||
|
|
||||||
mConnMgr->addMonitor(mFtController);
|
mLinkMgr->addMonitor(mFtController);
|
||||||
mConnMgr->addMonitor(mCacheStrapper);
|
mLinkMgr->addMonitor(mCacheStrapper);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1052,9 +1052,6 @@ bool ftServer::handleCacheData()
|
||||||
/* these go to the CacheStrapper! */
|
/* these go to the CacheStrapper! */
|
||||||
CacheData data;
|
CacheData data;
|
||||||
data.pid = ci->PeerId();
|
data.pid = ci->PeerId();
|
||||||
peerConnectState pca;
|
|
||||||
mConnMgr->getFriendNetStatus(ci->PeerId(), pca);
|
|
||||||
data.pname = pca.name;
|
|
||||||
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
|
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
|
||||||
data.path = ci->file.path;
|
data.path = ci->file.path;
|
||||||
data.name = ci->file.name;
|
data.name = ci->file.name;
|
||||||
|
|
|
@ -69,6 +69,9 @@ class p3turtle;
|
||||||
|
|
||||||
class ftDwlQueue;
|
class ftDwlQueue;
|
||||||
|
|
||||||
|
class p3PeerMgr;
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||||
/******************** Setup ************************************/
|
/******************** Setup ************************************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
ftServer(p3ConnectMgr *connMgr);
|
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||||
|
|
||||||
/* Assign important variables */
|
/* Assign important variables */
|
||||||
void setConfigDirectory(std::string path);
|
void setConfigDirectory(std::string path);
|
||||||
|
@ -265,7 +268,9 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
||||||
p3ConnectMgr *mConnMgr;
|
|
||||||
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
ftCacheStrapper *mCacheStrapper;
|
ftCacheStrapper *mCacheStrapper;
|
||||||
ftFiStore *mFiStore;
|
ftFiStore *mFiStore;
|
||||||
|
|
|
@ -331,7 +331,9 @@ HEADERS += pqi/authssl.h \
|
||||||
pqi/authgpg.h \
|
pqi/authgpg.h \
|
||||||
pqi/cleanupxpgp.h \
|
pqi/cleanupxpgp.h \
|
||||||
pqi/p3cfgmgr.h \
|
pqi/p3cfgmgr.h \
|
||||||
pqi/p3connmgr.h \
|
pqi/p3peermgr.h \
|
||||||
|
pqi/p3linkmgr.h \
|
||||||
|
pqi/p3netmgr.h \
|
||||||
pqi/p3dhtmgr.h \
|
pqi/p3dhtmgr.h \
|
||||||
pqi/p3notify.h \
|
pqi/p3notify.h \
|
||||||
pqi/p3upnpmgr.h \
|
pqi/p3upnpmgr.h \
|
||||||
|
@ -360,7 +362,8 @@ HEADERS += pqi/authssl.h \
|
||||||
pqi/pqissludp.h \
|
pqi/pqissludp.h \
|
||||||
pqi/pqistore.h \
|
pqi/pqistore.h \
|
||||||
pqi/pqistreamer.h \
|
pqi/pqistreamer.h \
|
||||||
pqi/sslfns.h
|
pqi/sslfns.h \
|
||||||
|
pqi/pqinetstatebox.h
|
||||||
|
|
||||||
HEADERS += rsserver/p3discovery.h \
|
HEADERS += rsserver/p3discovery.h \
|
||||||
rsserver/p3face.h \
|
rsserver/p3face.h \
|
||||||
|
@ -452,7 +455,9 @@ SOURCES += pqi/authgpg.cc \
|
||||||
pqi/authssl.cc \
|
pqi/authssl.cc \
|
||||||
pqi/cleanupxpgp.cc \
|
pqi/cleanupxpgp.cc \
|
||||||
pqi/p3cfgmgr.cc \
|
pqi/p3cfgmgr.cc \
|
||||||
pqi/p3connmgr.cc \
|
pqi/p3peermgr.cc \
|
||||||
|
pqi/p3linkmgr.cc \
|
||||||
|
pqi/p3netmgr.cc \
|
||||||
pqi/p3dhtmgr.cc \
|
pqi/p3dhtmgr.cc \
|
||||||
pqi/p3notify.cc \
|
pqi/p3notify.cc \
|
||||||
pqi/pqiarchive.cc \
|
pqi/pqiarchive.cc \
|
||||||
|
@ -473,7 +478,8 @@ SOURCES += pqi/authgpg.cc \
|
||||||
pqi/pqissludp.cc \
|
pqi/pqissludp.cc \
|
||||||
pqi/pqistore.cc \
|
pqi/pqistore.cc \
|
||||||
pqi/pqistreamer.cc \
|
pqi/pqistreamer.cc \
|
||||||
pqi/sslfns.cc
|
pqi/sslfns.cc \
|
||||||
|
pqi/pqinetstatebox.cc
|
||||||
|
|
||||||
SOURCES += rsserver/p3discovery.cc \
|
SOURCES += rsserver/p3discovery.cc \
|
||||||
rsserver/p3face-config.cc \
|
rsserver/p3face-config.cc \
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
#include "pqinetwork.h"
|
#include "pqinetwork.h"
|
||||||
#include "authgpg.h"
|
#include "authgpg.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
#include "serialiser/rsconfigitems.h"
|
#include "serialiser/rsconfigitems.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
#include "pqi/p3dhtmgr.h"
|
#include "pqi/p3dhtmgr.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
|
|
||||||
#include "pqi/p3linkmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||||
#include "tcponudp/tou.h"
|
#include "tcponudp/tou.h"
|
||||||
|
@ -87,19 +90,17 @@ peerAddrInfo::peerAddrInfo()
|
||||||
|
|
||||||
peerConnectState::peerConnectState()
|
peerConnectState::peerConnectState()
|
||||||
:id("unknown"),
|
:id("unknown"),
|
||||||
gpg_id("unknown"),
|
|
||||||
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD),
|
|
||||||
lastcontact(0),
|
lastcontact(0),
|
||||||
connecttype(0),
|
connecttype(0),
|
||||||
lastavailable(0),
|
lastavailable(0),
|
||||||
lastattempt(0),
|
lastattempt(0),
|
||||||
name(""), location(""),
|
name(""),
|
||||||
state(0), actions(0),
|
state(0), actions(0),
|
||||||
source(0),
|
source(0),
|
||||||
inConnAttempt(0)
|
inConnAttempt(0)
|
||||||
{
|
{
|
||||||
sockaddr_clear(¤tlocaladdr);
|
//sockaddr_clear(¤tlocaladdr);
|
||||||
sockaddr_clear(¤tserveraddr);
|
//sockaddr_clear(¤tserveraddr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -108,12 +109,7 @@ std::string textPeerConnectState(peerConnectState &state)
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "Id: " << state.id << std::endl;
|
out << "Id: " << state.id << std::endl;
|
||||||
out << "NetMode: " << state.netMode << std::endl;
|
|
||||||
out << "VisState: " << state.visState << std::endl;
|
|
||||||
out << "laddr: " << rs_inet_ntoa(state.currentlocaladdr.sin_addr)
|
|
||||||
<< ":" << ntohs(state.currentlocaladdr.sin_port) << std::endl;
|
|
||||||
out << "eaddr: " << rs_inet_ntoa(state.currentserveraddr.sin_addr)
|
|
||||||
<< ":" << ntohs(state.currentserveraddr.sin_port) << std::endl;
|
|
||||||
|
|
||||||
std::string output = out.str();
|
std::string output = out.str();
|
||||||
return output;
|
return output;
|
||||||
|
@ -121,9 +117,19 @@ std::string textPeerConnectState(peerConnectState &state)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********
|
||||||
|
* NOTES:
|
||||||
|
*
|
||||||
|
* p3LinkMgr doesn't store anything. All configuration is handled by p3PeerMgr.
|
||||||
|
*
|
||||||
|
* p3LinkMgr recvs the Discovery / Dht / Status updates.... tries the address.
|
||||||
|
* at success the address is pushed to p3PeerMgr for storage.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
p3LinkMgr::p3LinkMgr()
|
|
||||||
:mLinkMtx("p3LinkMgr"),mStatusChanged(false)
|
p3LinkMgr::p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr)
|
||||||
|
:mPeerMgr(peerMgr), mNetMgr(netMgr), mLinkMtx("p3LinkMgr"),mStatusChanged(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -131,15 +137,13 @@ p3LinkMgr::p3LinkMgr()
|
||||||
|
|
||||||
/* setup basics of own state */
|
/* setup basics of own state */
|
||||||
mOwnState.id = AuthSSL::getAuthSSL()->OwnId();
|
mOwnState.id = AuthSSL::getAuthSSL()->OwnId();
|
||||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
|
||||||
mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName();
|
mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
|
||||||
mOwnState.netMode = RS_NET_MODE_UDP;
|
|
||||||
// user decided.
|
// user decided.
|
||||||
//mOwnState.netMode |= RS_NET_MODE_TRY_UPNP;
|
//mOwnState.netMode |= RS_NET_MODE_TRY_UPNP;
|
||||||
|
|
||||||
mAllowTunnelConnection = false;
|
mAllowTunnelConnection = false;
|
||||||
mDNSResolver = new DNSResolver;
|
mDNSResolver = new DNSResolver();
|
||||||
mRetryPeriod = MIN_RETRY_PERIOD;
|
mRetryPeriod = MIN_RETRY_PERIOD;
|
||||||
|
|
||||||
lastGroupId = 1;
|
lastGroupId = 1;
|
||||||
|
@ -163,20 +167,8 @@ p3LinkMgr::p3LinkMgr()
|
||||||
|
|
||||||
void p3LinkMgr::setTunnelConnection(bool b)
|
void p3LinkMgr::setTunnelConnection(bool b)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
if (mAllowTunnelConnection != b)
|
|
||||||
changed = true;
|
|
||||||
|
|
||||||
mAllowTunnelConnection = b;
|
mAllowTunnelConnection = b;
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
|
||||||
{
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3LinkMgr::getTunnelConnection()
|
bool p3LinkMgr::getTunnelConnection()
|
||||||
|
@ -186,6 +178,65 @@ bool p3LinkMgr::getTunnelConnection()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void p3LinkMgr::getOnlineList(std::list<std::string> &ssl_peers)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||||
|
{
|
||||||
|
ssl_peers.push_back(it->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3LinkMgr::getFriendList(std::list<std::string> &ssl_peers)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||||
|
{
|
||||||
|
ssl_peers.push_back(it->first);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3LinkMgr::getFriendCount()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
return mFriendList.size();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int p3LinkMgr::getOnlineCount()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,17 +250,9 @@ void p3LinkMgr::tick()
|
||||||
bool p3LinkMgr::shutdown() /* blocking shutdown call */
|
bool p3LinkMgr::shutdown() /* blocking shutdown call */
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::shutdown()";
|
std::cerr << "p3LinkMgr::shutdown() NOOP";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
mNetStatus = RS_NET_UNKNOWN;
|
|
||||||
mNetInitTS = time(NULL);
|
|
||||||
netStatusReset_locked();
|
|
||||||
}
|
|
||||||
netAssistFirewallShutdown();
|
|
||||||
netAssistConnectShutdown();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -546,17 +589,21 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||||
{
|
{
|
||||||
bool should_netAssistFriend_false = false ;
|
bool should_netAssistFriend_false = false ;
|
||||||
bool should_netAssistFriend_true = false ;
|
bool should_netAssistFriend_true = false ;
|
||||||
|
bool updatePeerAddr = false;
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called Connect!: id: " + id);
|
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called Connect!: id: " + id);
|
||||||
if (success) {
|
if (success)
|
||||||
|
{
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with SUCCESS.");
|
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with SUCCESS.");
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with FAILED.");
|
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with FAILED.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == getOwnId()) {
|
if (id == getOwnId())
|
||||||
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Failed, connecting to own id: ");
|
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Failed, connecting to own id: ");
|
||||||
#endif
|
#endif
|
||||||
|
@ -601,29 +648,18 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||||
//used to send back to the peer it's own ext address
|
//used to send back to the peer it's own ext address
|
||||||
//it->second.currentserveraddr = remote_peer_address;
|
//it->second.currentserveraddr = remote_peer_address;
|
||||||
|
|
||||||
|
// THIS TEST IS A Bit BAD XXX, we should update their address anyway...
|
||||||
|
// This means we only update connections that we've made.. so maybe not too bad?
|
||||||
|
|
||||||
if ((it->second.inConnAttempt) &&
|
if ((it->second.inConnAttempt) &&
|
||||||
(it->second.currentConnAddrAttempt.addr.sin_addr.s_addr
|
(it->second.currentConnAddrAttempt.addr.sin_addr.s_addr
|
||||||
== remote_peer_address.sin_addr.s_addr) &&
|
== remote_peer_address.sin_addr.s_addr) &&
|
||||||
(it->second.currentConnAddrAttempt.addr.sin_port
|
(it->second.currentConnAddrAttempt.addr.sin_port
|
||||||
== remote_peer_address.sin_port))
|
== remote_peer_address.sin_port))
|
||||||
{
|
{
|
||||||
pqiIpAddress raddr;
|
updatePeerAddr = true;
|
||||||
raddr.mAddr = remote_peer_address;
|
|
||||||
raddr.mSeenTime = time(NULL);
|
|
||||||
raddr.mSrc = 0;
|
|
||||||
if (isPrivateNet(&(remote_peer_address.sin_addr)))
|
|
||||||
{
|
|
||||||
it->second.ipAddrs.updateLocalAddrs(raddr);
|
|
||||||
it->second.currentlocaladdr = remote_peer_address;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it->second.ipAddrs.updateExtAddrs(raddr);
|
|
||||||
it->second.currentserveraddr = remote_peer_address;
|
|
||||||
}
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::connectResult() adding current peer address in list." << std::endl;
|
std::cerr << "p3LinkMgr::connectResult() adding current peer address in list." << std::endl;
|
||||||
it->second.ipAddrs.printAddrs(std::cerr);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,6 +698,17 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updatePeerAddr)
|
||||||
|
{
|
||||||
|
pqiIpAddress raddr;
|
||||||
|
raddr.mAddr = remote_peer_address;
|
||||||
|
raddr.mSeenTime = time(NULL);
|
||||||
|
raddr.mSrc = 0;
|
||||||
|
|
||||||
|
mPeerMgr->updateCurrentAddress(id, raddr);
|
||||||
|
}
|
||||||
|
|
||||||
if(should_netAssistFriend_true)
|
if(should_netAssistFriend_true)
|
||||||
netAssistFriend(id,true) ;
|
netAssistFriend(id,true) ;
|
||||||
if(should_netAssistFriend_false)
|
if(should_netAssistFriend_false)
|
||||||
|
@ -682,7 +729,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
|
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
bool isFriend = true;
|
bool isFriend = true;
|
||||||
bool newAddrs;
|
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
@ -692,6 +738,12 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
details.addrs = addrs;
|
details.addrs = addrs;
|
||||||
details.ts = now;
|
details.ts = now;
|
||||||
|
|
||||||
|
bool updateNetConfig = (source == RS_CB_PERSON);
|
||||||
|
uint32_t peerVisibility = 0;
|
||||||
|
uint32_t peerNetMode = 0;
|
||||||
|
|
||||||
|
uint32_t ownNetMode = mNetMgr->getNetworkMode();
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
@ -752,9 +804,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
it->second.state |= RS_PEER_S_ONLINE;
|
it->second.state |= RS_PEER_S_ONLINE;
|
||||||
it->second.lastavailable = now;
|
it->second.lastavailable = now;
|
||||||
|
|
||||||
/* if we are recieving these - the dht is definitely up.
|
|
||||||
*/
|
|
||||||
mNetFlags.mDhtOk = true;
|
|
||||||
}
|
}
|
||||||
else if (source == RS_CB_DISC)
|
else if (source == RS_CB_DISC)
|
||||||
{
|
{
|
||||||
|
@ -774,8 +823,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
mStatusChanged = true;
|
mStatusChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not updating VIS status??? */
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
||||||
}
|
}
|
||||||
else if (source == RS_CB_PERSON)
|
else if (source == RS_CB_PERSON)
|
||||||
{
|
{
|
||||||
|
@ -793,46 +840,51 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
|
|
||||||
/* must be online to recv info (should be connected too!)
|
/* must be online to recv info (should be connected too!)
|
||||||
* but no need for action as should be connected already
|
* but no need for action as should be connected already
|
||||||
|
*
|
||||||
|
* One problem with these states... is that we will never find them via DHT
|
||||||
|
* if these flags are switched off here... If we get a connection attempt via DHT
|
||||||
|
* we should switch the DHT search back on.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
it->second.netMode &= (~RS_NET_MODE_ACTUAL); /* clear actual flags */
|
peerNetMode = 0; //it->second.netMode &= (~RS_NET_MODE_ACTUAL); /* clear actual flags */
|
||||||
if (flags & RS_NET_FLAGS_EXTERNAL_ADDR)
|
if (flags & RS_NET_FLAGS_EXTERNAL_ADDR)
|
||||||
{
|
{
|
||||||
it->second.netMode = RS_NET_MODE_EXT;
|
peerNetMode = RS_NET_MODE_EXT;
|
||||||
}
|
}
|
||||||
else if (flags & RS_NET_FLAGS_STABLE_UDP)
|
else if (flags & RS_NET_FLAGS_STABLE_UDP)
|
||||||
{
|
{
|
||||||
it->second.netMode = RS_NET_MODE_UDP;
|
peerNetMode = RS_NET_MODE_UDP;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
it->second.netMode = RS_NET_MODE_UNREACHABLE;
|
peerNetMode = RS_NET_MODE_UNREACHABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* always update VIS status */
|
/* always update VIS status */
|
||||||
if (flags & RS_NET_FLAGS_USE_DISC)
|
if (flags & RS_NET_FLAGS_USE_DISC)
|
||||||
{
|
{
|
||||||
it->second.visState &= (~RS_VIS_STATE_NODISC);
|
peerVisibility &= (~RS_VIS_STATE_NODISC);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
it->second.visState |= RS_VIS_STATE_NODISC;
|
peerVisibility |= RS_VIS_STATE_NODISC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & RS_NET_FLAGS_USE_DHT)
|
if (flags & RS_NET_FLAGS_USE_DHT)
|
||||||
{
|
{
|
||||||
it->second.visState &= (~RS_VIS_STATE_NODHT);
|
peerVisibility &= (~RS_VIS_STATE_NODHT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
it->second.visState |= RS_VIS_STATE_NODHT;
|
peerVisibility |= RS_VIS_STATE_NODHT;
|
||||||
}
|
}
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine Reachability (only advisory) */
|
/* Determine Reachability (only advisory) */
|
||||||
if (mOwnState.netMode & RS_NET_MODE_UDP)
|
if (ownNetMode & RS_NET_MODE_UDP)
|
||||||
{
|
{
|
||||||
if ((details.type & RS_NET_CONN_UDP_DHT_SYNC) ||
|
if ((details.type & RS_NET_CONN_UDP_DHT_SYNC) ||
|
||||||
(details.type & RS_NET_CONN_TCP_EXTERNAL))
|
(details.type & RS_NET_CONN_TCP_EXTERNAL))
|
||||||
|
@ -846,7 +898,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
it->second.state |= RS_PEER_S_UNREACHABLE;
|
it->second.state |= RS_PEER_S_UNREACHABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mOwnState.netMode & RS_NET_MODE_UNREACHABLE)
|
else if (ownNetMode & RS_NET_MODE_UNREACHABLE)
|
||||||
{
|
{
|
||||||
if (details.type & RS_NET_CONN_TCP_EXTERNAL)
|
if (details.type & RS_NET_CONN_TCP_EXTERNAL)
|
||||||
{
|
{
|
||||||
|
@ -890,9 +942,16 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
newAddrs = it->second.ipAddrs.updateAddrs(addrs);
|
|
||||||
} /****** STACK UNLOCK MUTEX *******/
|
} /****** STACK UNLOCK MUTEX *******/
|
||||||
|
|
||||||
|
bool newAddrs = mPeerMgr->updateAddressList(id, addrs);
|
||||||
|
if (updateNetConfig)
|
||||||
|
{
|
||||||
|
mPeerMgr -> setVisState(id, peerVisibility);
|
||||||
|
mPeerMgr -> setNetworkMode(id, peerNetMode);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::peerStatus()" << " id: " << id;
|
std::cerr << "p3LinkMgr::peerStatus()" << " id: " << id;
|
||||||
std::cerr << " type: " << type << " flags: " << flags;
|
std::cerr << " type: " << type << " flags: " << flags;
|
||||||
|
@ -1056,6 +1115,8 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
|
||||||
|
|
||||||
bool p3LinkMgr::retryConnectTCP(const std::string &id)
|
bool p3LinkMgr::retryConnectTCP(const std::string &id)
|
||||||
{
|
{
|
||||||
|
/* Check if we should retry first */
|
||||||
|
{
|
||||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
/* push all available addresses onto the connect addr stack...
|
/* push all available addresses onto the connect addr stack...
|
||||||
|
@ -1068,10 +1129,11 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
|
||||||
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
|
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (id == getOwnId()) {
|
if (id == getOwnId())
|
||||||
#ifdef CONN_DEBUG
|
{
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: ");
|
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: ");
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1091,33 +1153,63 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl;
|
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (it->second.connecttype & RS_NET_CONN_TUNNEL) {
|
if (it->second.connecttype & RS_NET_CONN_TUNNEL)
|
||||||
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
|
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} /****** END of LOCKED ******/
|
||||||
|
|
||||||
/* UDP automatically searches -> no need to push start */
|
/* If we reach here, must retry .... extract the required info from p3PeerMgr */
|
||||||
|
|
||||||
locked_ConnectAttempt_CurrentAddresses(&(it->second));
|
struct sockaddr_in lAddr;
|
||||||
locked_ConnectAttempt_HistoricalAddresses(&(it->second));
|
struct sockaddr_in eAddr;
|
||||||
locked_ConnectAttempt_AddDynDNS(&(it->second));
|
pqiIpAddrSet histAddrs;
|
||||||
locked_ConnectAttempt_AddTunnel(&(it->second));
|
std::string dyndns;
|
||||||
|
|
||||||
|
if (mPeerMgr->setConnectAddresses(id, lAddr, eAddr, histAddrs, dyndns))
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
if (mFriendList.end() != (it = mFriendList.find(id)))
|
||||||
|
{
|
||||||
|
|
||||||
|
locked_ConnectAttempt_CurrentAddresses(&(it->second), &lAddr, &eAddr);
|
||||||
|
locked_ConnectAttempt_HistoricalAddresses(&(it->second), histAddrs);
|
||||||
|
|
||||||
|
uint16_t dynPort = ntohs(eAddr.sin_port);
|
||||||
|
if (!dynPort)
|
||||||
|
dynPort = ntohs(lAddr.sin_port);
|
||||||
|
if (dynPort)
|
||||||
|
{
|
||||||
|
locked_ConnectAttempt_AddDynDNS(&(it->second), dyndns, dynPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
//locked_ConnectAttempt_AddTunnel(&(it->second));
|
||||||
|
|
||||||
/* finish it off */
|
/* finish it off */
|
||||||
return locked_ConnectAttempt_Complete(&(it->second));
|
return locked_ConnectAttempt_Complete(&(it->second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MAX_TCP_ADDR_AGE (3600 * 24 * 14) // two weeks in seconds.
|
#define MAX_TCP_ADDR_AGE (3600 * 24 * 14) // two weeks in seconds.
|
||||||
|
|
||||||
bool p3LinkMgr::locked_CheckPotentialAddr(struct sockaddr_in *addr, time_t age)
|
bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr(";
|
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr(";
|
||||||
|
@ -1190,11 +1282,11 @@ bool p3LinkMgr::locked_CheckPotentialAddr(struct sockaddr_in *addr, time_t age)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() Checking sameNet against: ";
|
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() Checking sameNet against: ";
|
||||||
std::cerr << rs_inet_ntoa(mOwnState.currentlocaladdr.sin_addr);
|
std::cerr << rs_inet_ntoa(mLocalAddress.sin_addr);
|
||||||
std::cerr << ")";
|
std::cerr << ")";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
if (sameNet(&(mOwnState.currentlocaladdr.sin_addr), &(addr->sin_addr)))
|
if (sameNet(&(mLocalAddress.sin_addr), &(addr->sin_addr)))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET";
|
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET";
|
||||||
|
@ -1214,20 +1306,20 @@ bool p3LinkMgr::locked_CheckPotentialAddr(struct sockaddr_in *addr, time_t age)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer)
|
void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr)
|
||||||
{
|
{
|
||||||
// Just push all the addresses onto the stack.
|
// Just push all the addresses onto the stack.
|
||||||
/* try "current addresses" first */
|
/* try "current addresses" first */
|
||||||
if (locked_CheckPotentialAddr(&(peer->currentlocaladdr), 0))
|
if ((localAddr) && (locked_CheckPotentialAddr(localAddr, 0)))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Adding tcp connection attempt: ";
|
std::cerr << "Adding tcp connection attempt: ";
|
||||||
std::cerr << "Current Local Addr: " << rs_inet_ntoa(peer->currentlocaladdr.sin_addr);
|
std::cerr << "Current Local Addr: " << rs_inet_ntoa(localAddr->sin_addr);
|
||||||
std::cerr << ":" << ntohs(peer->currentlocaladdr.sin_port);
|
std::cerr << ":" << ntohs(localAddr->sin_port);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
peerConnectAddress pca;
|
peerConnectAddress pca;
|
||||||
pca.addr = peer->currentlocaladdr;
|
pca.addr = *localAddr;
|
||||||
pca.type = RS_NET_CONN_TCP_LOCAL;
|
pca.type = RS_NET_CONN_TCP_LOCAL;
|
||||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||||
pca.ts = time(NULL);
|
pca.ts = time(NULL);
|
||||||
|
@ -1236,16 +1328,16 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer)
|
||||||
addAddressIfUnique(peer->connAddrs, pca);
|
addAddressIfUnique(peer->connAddrs, pca);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locked_CheckPotentialAddr(&(peer->currentserveraddr), 0))
|
if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0)))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Adding tcp connection attempt: ";
|
std::cerr << "Adding tcp connection attempt: ";
|
||||||
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(peer->currentserveraddr.sin_addr);
|
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(serverAddr->sin_addr);
|
||||||
std::cerr << ":" << ntohs(peer->currentserveraddr.sin_port);
|
std::cerr << ":" << ntohs(serverAddr->sin_port);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
peerConnectAddress pca;
|
peerConnectAddress pca;
|
||||||
pca.addr = peer->currentserveraddr;
|
pca.addr = *serverAddr;
|
||||||
pca.type = RS_NET_CONN_TCP_EXTERNAL;
|
pca.type = RS_NET_CONN_TCP_EXTERNAL;
|
||||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||||
pca.ts = time(NULL);
|
pca.ts = time(NULL);
|
||||||
|
@ -1256,15 +1348,15 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer)
|
void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs)
|
||||||
{
|
{
|
||||||
/* now try historical addresses */
|
/* now try historical addresses */
|
||||||
/* try local addresses first */
|
/* try local addresses first */
|
||||||
std::list<pqiIpAddress>::iterator ait;
|
std::list<pqiIpAddress>::const_iterator ait;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
for(ait = peer->ipAddrs.mLocal.mAddrs.begin();
|
for(ait = ipAddrs.mLocal.mAddrs.begin();
|
||||||
ait != peer->ipAddrs.mLocal.mAddrs.end(); ait++)
|
ait != ipAddrs.mLocal.mAddrs.end(); ait++)
|
||||||
{
|
{
|
||||||
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
|
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
|
||||||
{
|
{
|
||||||
|
@ -1287,8 +1379,8 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ait = peer->ipAddrs.mExt.mAddrs.begin();
|
for(ait = ipAddrs.mExt.mAddrs.begin();
|
||||||
ait != peer->ipAddrs.mExt.mAddrs.end(); ait++)
|
ait != ipAddrs.mExt.mAddrs.end(); ait++)
|
||||||
{
|
{
|
||||||
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
|
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
|
||||||
{
|
{
|
||||||
|
@ -1312,19 +1404,18 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer)
|
void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t port)
|
||||||
{
|
{
|
||||||
/* try dyndns address too */
|
/* try dyndns address too */
|
||||||
if (!peer->dyndns.empty())
|
if (!dyndns.empty())
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
u_short port = peer->currentserveraddr.sin_port ? peer->currentserveraddr.sin_port : peer->currentlocaladdr.sin_port;
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Looking up DynDNS address" << std::endl;
|
std::cerr << "Looking up DynDNS address" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (port)
|
if (port)
|
||||||
{
|
{
|
||||||
if(mDNSResolver->getIPAddressFromString (std::string(peer->dyndns.c_str()), addr))
|
if(mDNSResolver->getIPAddressFromString(dyndns, addr))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Adding tcp connection attempt: ";
|
std::cerr << "Adding tcp connection attempt: ";
|
||||||
|
@ -1335,7 +1426,7 @@ void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer)
|
||||||
peerConnectAddress pca;
|
peerConnectAddress pca;
|
||||||
pca.addr.sin_family = AF_INET;
|
pca.addr.sin_family = AF_INET;
|
||||||
pca.addr.sin_addr.s_addr = addr.s_addr;
|
pca.addr.sin_addr.s_addr = addr.s_addr;
|
||||||
pca.addr.sin_port = port;
|
pca.addr.sin_port = htons(port);
|
||||||
pca.type = RS_NET_CONN_TCP_EXTERNAL;
|
pca.type = RS_NET_CONN_TCP_EXTERNAL;
|
||||||
//for the delay, we add a random time and some more time when the friend list is big
|
//for the delay, we add a random time and some more time when the friend list is big
|
||||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||||
|
@ -1405,7 +1496,8 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||||
//add a random perturbation between 0 and 2 sec.
|
//add a random perturbation between 0 and 2 sec.
|
||||||
peer->lastattempt = time(NULL) + rand() % MAX_RANDOM_ATTEMPT_OFFSET;
|
peer->lastattempt = time(NULL) + rand() % MAX_RANDOM_ATTEMPT_OFFSET;
|
||||||
|
|
||||||
if (peer->inConnAttempt) {
|
if (peer->inConnAttempt)
|
||||||
|
{
|
||||||
/* -> it'll automatically use the addresses we added */
|
/* -> it'll automatically use the addresses we added */
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT";
|
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT";
|
||||||
|
@ -1419,7 +1511,7 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||||
/* start a connection attempt */
|
/* start a connection attempt */
|
||||||
if (peer->connAddrs.size() > 0)
|
if (peer->connAddrs.size() > 0)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
|
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
|
@ -1427,7 +1519,7 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||||
std::cerr << out.str() << std::endl;
|
std::cerr << out.str() << std::endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
peer->actions |= RS_PEER_CONNECT_REQ;
|
peer->actions |= RS_PEER_CONNECT_REQ;
|
||||||
mStatusChanged = true;
|
mStatusChanged = true;
|
||||||
|
@ -1435,12 +1527,12 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
|
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
|
||||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||||
std::cerr << out.str() << std::endl;
|
std::cerr << out.str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -40,43 +40,6 @@
|
||||||
class ExtAddrFinder ;
|
class ExtAddrFinder ;
|
||||||
class DNSResolver ;
|
class DNSResolver ;
|
||||||
|
|
||||||
/* RS_VIS_STATE_XXXX
|
|
||||||
* determines how public this peer wants to be...
|
|
||||||
*
|
|
||||||
* STD = advertise to Peers / DHT checking etc
|
|
||||||
* GRAY = share with friends / but not DHT
|
|
||||||
* DARK = hidden from all
|
|
||||||
* BROWN? = hidden from friends / but on DHT
|
|
||||||
*/
|
|
||||||
|
|
||||||
const uint32_t RS_VIS_STATE_NODISC = 0x0001;
|
|
||||||
const uint32_t RS_VIS_STATE_NODHT = 0x0002;
|
|
||||||
|
|
||||||
const uint32_t RS_VIS_STATE_STD = 0x0000;
|
|
||||||
const uint32_t RS_VIS_STATE_GRAY = RS_VIS_STATE_NODHT;
|
|
||||||
const uint32_t RS_VIS_STATE_DARK = RS_VIS_STATE_NODISC | RS_VIS_STATE_NODHT;
|
|
||||||
const uint32_t RS_VIS_STATE_BROWN = RS_VIS_STATE_NODISC;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Startup Modes (confirmed later) */
|
|
||||||
const uint32_t RS_NET_MODE_TRYMODE = 0x00f0;
|
|
||||||
|
|
||||||
const uint32_t RS_NET_MODE_TRY_EXT = 0x0010;
|
|
||||||
const uint32_t RS_NET_MODE_TRY_UPNP = 0x0020;
|
|
||||||
const uint32_t RS_NET_MODE_TRY_UDP = 0x0040;
|
|
||||||
|
|
||||||
/* Actual State */
|
|
||||||
const uint32_t RS_NET_MODE_ACTUAL = 0x000f;
|
|
||||||
|
|
||||||
const uint32_t RS_NET_MODE_UNKNOWN = 0x0000;
|
|
||||||
const uint32_t RS_NET_MODE_EXT = 0x0001;
|
|
||||||
const uint32_t RS_NET_MODE_UPNP = 0x0002;
|
|
||||||
const uint32_t RS_NET_MODE_UDP = 0x0004;
|
|
||||||
const uint32_t RS_NET_MODE_UNREACHABLE = 0x0008;
|
|
||||||
|
|
||||||
|
|
||||||
/* order of attempts ... */
|
/* order of attempts ... */
|
||||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||||
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
||||||
|
@ -94,15 +57,6 @@ const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
|
||||||
//const uint32_t RS_NET_CONN_SERVER = 0x0100; /* TCP only */
|
//const uint32_t RS_NET_CONN_SERVER = 0x0100; /* TCP only */
|
||||||
//const uint32_t RS_NET_CONN_PEER = 0x0200; /* all UDP */
|
//const uint32_t RS_NET_CONN_PEER = 0x0200; /* all UDP */
|
||||||
|
|
||||||
|
|
||||||
/* flags of peerStatus */
|
|
||||||
const uint32_t RS_NET_FLAGS_USE_DISC = 0x0001;
|
|
||||||
const uint32_t RS_NET_FLAGS_USE_DHT = 0x0002;
|
|
||||||
const uint32_t RS_NET_FLAGS_ONLINE = 0x0004;
|
|
||||||
const uint32_t RS_NET_FLAGS_EXTERNAL_ADDR = 0x0008;
|
|
||||||
const uint32_t RS_NET_FLAGS_STABLE_UDP = 0x0010;
|
|
||||||
const uint32_t RS_NET_FLAGS_TRUSTS_ME = 0x0020;
|
|
||||||
|
|
||||||
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
|
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
|
||||||
|
|
||||||
class peerAddrInfo
|
class peerAddrInfo
|
||||||
|
@ -137,7 +91,7 @@ class peerConnectState
|
||||||
//std::string gpg_id;
|
//std::string gpg_id;
|
||||||
|
|
||||||
//uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
//uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
||||||
uint32_t visState; /* STD, GRAY, DARK */
|
//uint32_t visState; /* STD, GRAY, DARK */
|
||||||
|
|
||||||
//struct sockaddr_in localaddr, serveraddr;
|
//struct sockaddr_in localaddr, serveraddr;
|
||||||
|
|
||||||
|
@ -146,19 +100,21 @@ class peerConnectState
|
||||||
//struct sockaddr_in currentserveraddr; /* Mandatory */
|
//struct sockaddr_in currentserveraddr; /* Mandatory */
|
||||||
//std::string dyndns;
|
//std::string dyndns;
|
||||||
|
|
||||||
//time_t lastcontact;
|
|
||||||
|
|
||||||
/* list of addresses from various sources */
|
/* list of addresses from various sources */
|
||||||
//pqiIpAddrSet ipAddrs;
|
//pqiIpAddrSet ipAddrs;
|
||||||
|
|
||||||
/***** Below here not stored permanently *****/
|
/***** Below here not stored permanently *****/
|
||||||
|
|
||||||
|
time_t lastcontact;
|
||||||
|
|
||||||
uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL
|
uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL
|
||||||
time_t lastavailable;
|
time_t lastavailable;
|
||||||
time_t lastattempt;
|
time_t lastattempt;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string location;
|
|
||||||
|
//std::string location;
|
||||||
|
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
uint32_t actions;
|
uint32_t actions;
|
||||||
|
@ -180,6 +136,9 @@ class p3tunnel;
|
||||||
class RsPeerGroupItem;
|
class RsPeerGroupItem;
|
||||||
class RsGroupInfo;
|
class RsGroupInfo;
|
||||||
|
|
||||||
|
class p3PeerMgr;
|
||||||
|
class p3NetMgr;
|
||||||
|
|
||||||
std::string textPeerConnectState(peerConnectState &state);
|
std::string textPeerConnectState(peerConnectState &state);
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,17 +146,17 @@ class p3LinkMgr: public pqiConnectCb
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3LinkMgr();
|
p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr);
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
/*************** Setup ***************************/
|
/*************** Setup ***************************/
|
||||||
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
//void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||||
void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
|
//void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
|
||||||
|
|
||||||
void addNetListener(pqiNetListener *listener);
|
//void addNetListener(pqiNetListener *listener);
|
||||||
|
|
||||||
bool checkNetAddress(); /* check our address is sensible */
|
//bool checkNetAddress(); /* check our address is sensible */
|
||||||
|
|
||||||
/*************** External Control ****************/
|
/*************** External Control ****************/
|
||||||
bool shutdown(); /* blocking shutdown call */
|
bool shutdown(); /* blocking shutdown call */
|
||||||
|
@ -207,20 +166,21 @@ bool retryConnect(const std::string &id);
|
||||||
void setTunnelConnection(bool b);
|
void setTunnelConnection(bool b);
|
||||||
bool getTunnelConnection();
|
bool getTunnelConnection();
|
||||||
|
|
||||||
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
//void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
||||||
bool setLocalAddress(const std::string &id, struct sockaddr_in addr);
|
//bool setLocalAddress(const std::string &id, struct sockaddr_in addr);
|
||||||
bool setExtAddress(const std::string &id, struct sockaddr_in addr);
|
//bool setExtAddress(const std::string &id, struct sockaddr_in addr);
|
||||||
bool setDynDNS(const std::string &id, const std::string &dyndns);
|
//bool setDynDNS(const std::string &id, const std::string &dyndns);
|
||||||
bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
//bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
||||||
|
|
||||||
bool setNetworkMode(const std::string &id, uint32_t netMode);
|
//bool setNetworkMode(const std::string &id, uint32_t netMode);
|
||||||
bool setVisState(const std::string &id, uint32_t visState);
|
//bool setVisState(const std::string &id, uint32_t visState);
|
||||||
|
|
||||||
bool setLocation(const std::string &pid, const std::string &location);//location is shown in the gui to differentiate ssl certs
|
//bool setLocation(const std::string &pid, const std::string &location);//location is shown in the gui to differentiate ssl certs
|
||||||
|
|
||||||
/* add/remove friends */
|
/* add/remove friends */
|
||||||
bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
bool addFriend(const std::string &ssl_id);
|
||||||
uint32_t visState = RS_VIS_STATE_STD , time_t lastContact = 0);
|
//, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||||
|
// uint32_t visState = RS_VIS_STATE_STD , time_t lastContact = 0);
|
||||||
|
|
||||||
bool removeFriend(const std::string &ssl_id);
|
bool removeFriend(const std::string &ssl_id);
|
||||||
|
|
||||||
|
@ -230,12 +190,16 @@ bool removeFriend(const std::string &ssl_id);
|
||||||
const std::string getOwnId();
|
const std::string getOwnId();
|
||||||
bool getOwnNetStatus(peerConnectState &state);
|
bool getOwnNetStatus(peerConnectState &state);
|
||||||
|
|
||||||
|
struct sockaddr_in getLocalAddress();
|
||||||
|
|
||||||
bool isOnline(const std::string &ssl_id);
|
bool isOnline(const std::string &ssl_id);
|
||||||
bool getFriendNetStatus(const std::string &id, peerConnectState &state);
|
bool getFriendNetStatus(const std::string &id, peerConnectState &state);
|
||||||
bool getOthersNetStatus(const std::string &id, peerConnectState &state);
|
bool getOthersNetStatus(const std::string &id, peerConnectState &state);
|
||||||
|
|
||||||
void getOnlineList(std::list<std::string> &ssl_peers);
|
void getOnlineList(std::list<std::string> &ssl_peers);
|
||||||
bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl);
|
void getFriendList(std::list<std::string> &ssl_peers);
|
||||||
|
int getOnlineCount();
|
||||||
|
int getFriendCount();
|
||||||
|
|
||||||
|
|
||||||
/**************** handle monitors *****************/
|
/**************** handle monitors *****************/
|
||||||
|
@ -286,20 +250,18 @@ bool retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr);
|
||||||
/* connect attempts TCP */
|
/* connect attempts TCP */
|
||||||
bool retryConnectTCP(const std::string &id);
|
bool retryConnectTCP(const std::string &id);
|
||||||
|
|
||||||
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer);
|
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr);
|
||||||
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer);
|
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
|
||||||
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer);
|
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
|
||||||
void locked_ConnectAttempt_AddTunnel(peerConnectState *peer);
|
void locked_ConnectAttempt_AddTunnel(peerConnectState *peer);
|
||||||
|
|
||||||
bool locked_ConnectAttempt_Complete(peerConnectState *peer);
|
bool locked_ConnectAttempt_Complete(peerConnectState *peer);
|
||||||
|
|
||||||
bool locked_CheckPotentialAddr(struct sockaddr_in *addr, time_t age);
|
bool locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age);
|
||||||
bool addAddressIfUnique(std::list<peerConnectAddress> &addrList,
|
bool addAddressIfUnique(std::list<peerConnectAddress> &addrList,
|
||||||
peerConnectAddress &pca);
|
peerConnectAddress &pca);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// These should have there own Mutex Protection,
|
// These should have there own Mutex Protection,
|
||||||
//p3tunnel *mP3tunnel;
|
//p3tunnel *mP3tunnel;
|
||||||
|
@ -307,6 +269,8 @@ private:
|
||||||
|
|
||||||
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
||||||
|
|
||||||
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3NetMgr *mNetMgr;
|
||||||
|
|
||||||
RsMutex mLinkMtx; /* protects below */
|
RsMutex mLinkMtx; /* protects below */
|
||||||
|
|
||||||
|
@ -314,6 +278,8 @@ private:
|
||||||
|
|
||||||
bool mStatusChanged;
|
bool mStatusChanged;
|
||||||
|
|
||||||
|
struct sockaddr_in mLocalAddress;
|
||||||
|
|
||||||
std::list<pqiMonitor *> clients;
|
std::list<pqiMonitor *> clients;
|
||||||
|
|
||||||
bool mAllowTunnelConnection;
|
bool mAllowTunnelConnection;
|
||||||
|
@ -322,7 +288,7 @@ private:
|
||||||
//bool mUpnpAddrValid, mStunAddrValid;
|
//bool mUpnpAddrValid, mStunAddrValid;
|
||||||
//struct sockaddr_in mUpnpExtAddr;
|
//struct sockaddr_in mUpnpExtAddr;
|
||||||
|
|
||||||
peerConnectState mOwnState;
|
//peerConnectState mOwnState;
|
||||||
|
|
||||||
std::map<std::string, peerConnectState> mFriendList;
|
std::map<std::string, peerConnectState> mFriendList;
|
||||||
std::map<std::string, peerConnectState> mOthersList;
|
std::map<std::string, peerConnectState> mOthersList;
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
|
|
||||||
#include "pqi/p3netmgr.h"
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "util/rsnet.h"
|
#include "util/rsnet.h"
|
||||||
#include "util/rsrandom.h"
|
#include "util/rsrandom.h"
|
||||||
|
|
||||||
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
|
||||||
//#include "tcponudp/tou.h"
|
|
||||||
#include "util/extaddrfinder.h"
|
#include "util/extaddrfinder.h"
|
||||||
#include "util/dnsresolver.h"
|
#include "util/dnsresolver.h"
|
||||||
|
|
||||||
|
@ -106,8 +107,8 @@ void pqiNetStatus::print(std::ostream &out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
p3NetMgr::p3NetMgr()
|
||||||
:mPeerMgr(peerMgr), mNetMtx("p3NetMgr"),
|
:mPeerMgr(NULL), mLinkMgr(NULL), mNetMtx("p3NetMgr"),
|
||||||
mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false)
|
mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -122,6 +123,7 @@ p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
||||||
|
|
||||||
mNetFlags = pqiNetStatus();
|
mNetFlags = pqiNetStatus();
|
||||||
mOldNetFlags = pqiNetStatus();
|
mOldNetFlags = pqiNetStatus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
|
@ -133,71 +135,21 @@ p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3NetMgr::getIPServersEnabled()
|
void p3NetMgr::setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
mPeerMgr = peerMgr;
|
||||||
return mUseExtAddrFinder;
|
mLinkMgr = linkMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3NetMgr::getIPServersList(std::list<std::string>& ip_servers)
|
void p3NetMgr::setDhtMgr(p3DhtMgr *dhtMgr)
|
||||||
{
|
{
|
||||||
mExtAddrFinder->getIPServersList(ip_servers);
|
mDhtMgr = dhtMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3NetMgr::setIPServersEnabled(bool b)
|
void p3NetMgr::setStunners(p3Stunner *dhtStunner, p3Stunner *proxyStunner)
|
||||||
{
|
{
|
||||||
{
|
mDhtStunner = dhtStunner;
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
mProxyStunner = proxyStunner;
|
||||||
mUseExtAddrFinder = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3NetMgr: setIPServers to " << b << std::endl ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void p3NetMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
/* only change TRY flags */
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3NetMgr::setOwnNetConfig()" << std::endl;
|
|
||||||
std::cerr << "Existing netMode: " << mOwnState.netMode << " vis: " << mOwnState.visState;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "Input netMode: " << netMode << " vis: " << visState;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
mNetMode &= ~(RS_NET_MODE_TRYMODE);
|
|
||||||
|
|
||||||
switch(netMode & RS_NET_MODE_ACTUAL)
|
|
||||||
{
|
|
||||||
case RS_NET_MODE_EXT:
|
|
||||||
mNetMode |= RS_NET_MODE_TRY_EXT;
|
|
||||||
break;
|
|
||||||
case RS_NET_MODE_UPNP:
|
|
||||||
mNetMode |= RS_NET_MODE_TRY_UPNP;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case RS_NET_MODE_UDP:
|
|
||||||
mNetMode |= RS_NET_MODE_TRY_UDP;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mVisState = visState;
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "Final netMode: " << mNetMode << " vis: " << mVisState;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
/* if we've started up - then tweak Dht On/Off */
|
|
||||||
if (mNetStatus != RS_NET_UNKNOWN)
|
|
||||||
{
|
|
||||||
enableNetAssistConnect(!(mVisState & RS_VIS_STATE_NODHT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,25 +218,6 @@ void p3NetMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
||||||
|
|
||||||
void p3NetMgr::netReset()
|
void p3NetMgr::netReset()
|
||||||
{
|
{
|
||||||
//don't do a net reset if the MIN_TIME_BETWEEN_NET_RESET is not reached
|
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
time_t delta = time(NULL) - mNetInitTS;
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
|
||||||
std::cerr << "p3NetMgr time since last reset : " << delta << std::endl;
|
|
||||||
#endif
|
|
||||||
if (delta < (time_t)MIN_TIME_BETWEEN_NET_RESET)
|
|
||||||
{
|
|
||||||
mNetStatus = RS_NET_NEEDS_RESET;
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
|
||||||
std::cerr << "p3NetMgr::netStartup() don't do a net reset if the MIN_TIME_BETWEEN_NET_RESET is not reached" << std::endl;
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
#ifdef CONN_DEBUG_RESET
|
||||||
std::cerr << "p3NetMgr::netReset() Called" << std::endl;
|
std::cerr << "p3NetMgr::netReset() Called" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -310,7 +243,6 @@ void p3NetMgr::netReset()
|
||||||
std::cerr << "p3NetMgr::netReset() resetting NetStatus" << std::endl;
|
std::cerr << "p3NetMgr::netReset() resetting NetStatus" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* reset udp network - handled by tou_init! */
|
|
||||||
/* reset tcp network - if necessary */
|
/* reset tcp network - if necessary */
|
||||||
{
|
{
|
||||||
/* NOTE: nNetListeners should be protected via the Mutex.
|
/* NOTE: nNetListeners should be protected via the Mutex.
|
||||||
|
@ -350,13 +282,6 @@ void p3NetMgr::netReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* to allow resets of network stuff */
|
|
||||||
void p3NetMgr::addNetListener(pqiNetListener *listener)
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
mNetListeners.push_back(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
void p3NetMgr::netStatusReset_locked()
|
void p3NetMgr::netStatusReset_locked()
|
||||||
{
|
{
|
||||||
//std::cerr << "p3NetMgr::netStatusReset()" << std::endl;;
|
//std::cerr << "p3NetMgr::netStatusReset()" << std::endl;;
|
||||||
|
@ -364,6 +289,33 @@ void p3NetMgr::netStatusReset_locked()
|
||||||
mNetFlags = pqiNetStatus();
|
mNetFlags = pqiNetStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3NetMgr::shutdown() /* blocking shutdown call */
|
||||||
|
{
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3NetMgr::shutdown()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
mNetStatus = RS_NET_UNKNOWN;
|
||||||
|
mNetInitTS = time(NULL);
|
||||||
|
netStatusReset_locked();
|
||||||
|
}
|
||||||
|
netAssistFirewallShutdown();
|
||||||
|
netAssistConnectShutdown();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void p3NetMgr::netStartup()
|
void p3NetMgr::netStartup()
|
||||||
{
|
{
|
||||||
/* startup stuff */
|
/* startup stuff */
|
||||||
|
@ -376,7 +328,6 @@ void p3NetMgr::netStartup()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
netDhtInit();
|
netDhtInit();
|
||||||
netUdpInit();
|
|
||||||
|
|
||||||
/* decide which net setup mode we're going into
|
/* decide which net setup mode we're going into
|
||||||
*/
|
*/
|
||||||
|
@ -439,23 +390,7 @@ void p3NetMgr::tick()
|
||||||
netTick();
|
netTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3NetMgr::shutdown() /* blocking shutdown call */
|
#define STARTUP_DELAY 5
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3NetMgr::shutdown()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
mNetStatus = RS_NET_UNKNOWN;
|
|
||||||
mNetInitTS = time(NULL);
|
|
||||||
netStatusReset_locked();
|
|
||||||
}
|
|
||||||
netAssistFirewallShutdown();
|
|
||||||
netAssistConnectShutdown();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void p3NetMgr::netTick()
|
void p3NetMgr::netTick()
|
||||||
|
@ -472,13 +407,15 @@ void p3NetMgr::netTick()
|
||||||
checkNetAddress() ;
|
checkNetAddress() ;
|
||||||
networkConsistencyCheck(); /* check consistency. If not consistent, do a reset inside networkConsistencyCheck() */
|
networkConsistencyCheck(); /* check consistency. If not consistent, do a reset inside networkConsistencyCheck() */
|
||||||
|
|
||||||
mNetMtx.lock(); /* LOCK MUTEX */
|
uint32_t netStatus = 0;
|
||||||
|
time_t age = 0;
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /************** LOCK MUTEX ***************/
|
||||||
|
|
||||||
uint32_t netStatus = mNetStatus;
|
netStatus = mNetStatus;
|
||||||
time_t age = time(NULL) - mNetInitTS;
|
age = time(NULL) - mNetInitTS;
|
||||||
|
|
||||||
mNetMtx.unlock(); /* UNLOCK MUTEX */
|
}
|
||||||
/* start tcp network - if necessary */
|
|
||||||
|
|
||||||
switch(netStatus)
|
switch(netStatus)
|
||||||
{
|
{
|
||||||
|
@ -498,7 +435,6 @@ void p3NetMgr::netTick()
|
||||||
/* add a small delay to stop restarting straight after a RESET
|
/* add a small delay to stop restarting straight after a RESET
|
||||||
* This is so can we shutdown cleanly
|
* This is so can we shutdown cleanly
|
||||||
*/
|
*/
|
||||||
#define STARTUP_DELAY 5
|
|
||||||
if (age < STARTUP_DELAY)
|
if (age < STARTUP_DELAY)
|
||||||
{
|
{
|
||||||
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
|
||||||
|
@ -532,7 +468,6 @@ void p3NetMgr::netTick()
|
||||||
std::cerr << "p3NetMgr::netTick() STATUS: EXT_SETUP" << std::endl;
|
std::cerr << "p3NetMgr::netTick() STATUS: EXT_SETUP" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
netExtCheck();
|
netExtCheck();
|
||||||
//netDhtInit();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_DONE:
|
case RS_NET_DONE:
|
||||||
|
@ -835,103 +770,9 @@ void p3NetMgr::netExtCheck()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************
|
||||||
void p3NetMgr::networkConsistencyCheck()
|
************************************** Interfaces *****************************************
|
||||||
{
|
**********************************************************************************************/
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
**********************************************************************
|
|
||||||
******************** External Setup **********************************
|
|
||||||
**********************************************************************
|
|
||||||
**********************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
bool p3NetMgr::setLocalAddress(struct sockaddr_in addr)
|
|
||||||
{
|
|
||||||
bool changed = false;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
if ((mLocalAddr.sin_addr.s_addr != addr.sin_addr.s_addr) ||
|
|
||||||
(mLocalAddr.sin_port != addr.sin_port))
|
|
||||||
{
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mLocalAddr = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
|
||||||
std::cerr << "p3NetMgr::setLocalAddress() Calling NetReset" << std::endl;
|
|
||||||
#endif
|
|
||||||
netReset();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool p3NetMgr::setExtAddress(struct sockaddr_in addr)
|
|
||||||
{
|
|
||||||
bool changed = false;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
if ((mExtAddr.sin_addr.s_addr != addr.sin_addr.s_addr) ||
|
|
||||||
(mExtAddr.sin_port != addr.sin_port))
|
|
||||||
{
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mExtAddr = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
|
||||||
std::cerr << "p3NetMgr::setExtAddress() Calling NetReset" << std::endl;
|
|
||||||
#endif
|
|
||||||
netReset();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool p3NetMgr::setNetworkMode(uint32_t netMode)
|
|
||||||
{
|
|
||||||
uint32_t visState;
|
|
||||||
uint32_t oldNetMode;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
visState = mVisState;
|
|
||||||
oldNetMode = mNetMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
setOwnNetConfig(netMode, visState);
|
|
||||||
|
|
||||||
if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL))
|
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
|
||||||
std::cerr << "p3NetMgr::setNetworkMode() Calling NetReset" << std::endl;
|
|
||||||
#endif
|
|
||||||
netReset();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool p3NetMgr::setVisState(uint32_t visState)
|
|
||||||
{
|
|
||||||
uint32_t netMode;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
netMode = mNetMode;
|
|
||||||
}
|
|
||||||
setOwnNetConfig(netMode, visState);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************/
|
|
||||||
|
|
||||||
bool p3NetMgr::checkNetAddress()
|
bool p3NetMgr::checkNetAddress()
|
||||||
{
|
{
|
||||||
|
@ -1067,16 +908,131 @@ bool p3NetMgr::checkNetAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************************************
|
||||||
|
************************************** Interfaces *****************************************
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
/* to allow resets of network stuff */
|
||||||
|
void p3NetMgr::addNetListener(pqiNetListener *listener)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
mNetListeners.push_back(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
bool p3NetMgr::setLocalAddress(struct sockaddr_in addr)
|
||||||
**********************************************************************
|
{
|
||||||
******************** Interfaces ***********************************
|
bool changed = false;
|
||||||
**********************************************************************
|
{
|
||||||
**********************************************************************/
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
if ((mLocalAddr.sin_addr.s_addr != addr.sin_addr.s_addr) ||
|
||||||
|
(mLocalAddr.sin_port != addr.sin_port))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mLocalAddr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
#ifdef CONN_DEBUG_RESET
|
||||||
|
std::cerr << "p3NetMgr::setLocalAddress() Calling NetReset" << std::endl;
|
||||||
|
#endif
|
||||||
|
netReset();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3NetMgr::setExtAddress(struct sockaddr_in addr)
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
if ((mExtAddr.sin_addr.s_addr != addr.sin_addr.s_addr) ||
|
||||||
|
(mExtAddr.sin_port != addr.sin_port))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mExtAddr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
#ifdef CONN_DEBUG_RESET
|
||||||
|
std::cerr << "p3NetMgr::setExtAddress() Calling NetReset" << std::endl;
|
||||||
|
#endif
|
||||||
|
netReset();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3NetMgr::setNetworkMode(uint32_t netMode)
|
||||||
|
{
|
||||||
|
uint32_t oldNetMode;
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
/* only change TRY flags */
|
||||||
|
|
||||||
|
oldNetMode = mNetMode;
|
||||||
|
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3NetMgr::setNetworkMode()";
|
||||||
|
std::cerr << " Existing netMode: " << mNetMode;
|
||||||
|
std::cerr << " Input netMode: " << netMode;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
mNetMode &= ~(RS_NET_MODE_TRYMODE);
|
||||||
|
|
||||||
|
switch(netMode & RS_NET_MODE_ACTUAL)
|
||||||
|
{
|
||||||
|
case RS_NET_MODE_EXT:
|
||||||
|
mNetMode |= RS_NET_MODE_TRY_EXT;
|
||||||
|
break;
|
||||||
|
case RS_NET_MODE_UPNP:
|
||||||
|
mNetMode |= RS_NET_MODE_TRY_UPNP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case RS_NET_MODE_UDP:
|
||||||
|
mNetMode |= RS_NET_MODE_TRY_UDP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL))
|
||||||
|
{
|
||||||
|
#ifdef CONN_DEBUG_RESET
|
||||||
|
std::cerr << "p3NetMgr::setNetworkMode() Calling NetReset" << std::endl;
|
||||||
|
#endif
|
||||||
|
netReset();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3NetMgr::setVisState(uint32_t visState)
|
||||||
|
{
|
||||||
|
uint32_t netMode;
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
mVisState = visState;
|
||||||
|
|
||||||
|
/* if we've started up - then tweak Dht On/Off */
|
||||||
|
if (mNetStatus != RS_NET_UNKNOWN)
|
||||||
|
{
|
||||||
|
enableNetAssistConnect(!(mVisState & RS_VIS_STATE_NODHT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************************************
|
||||||
|
************************************** Interfaces *****************************************
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
void p3NetMgr::addNetAssistFirewall(uint32_t id, pqiNetAssistFirewall *fwAgent)
|
void p3NetMgr::addNetAssistFirewall(uint32_t id, pqiNetAssistFirewall *fwAgent)
|
||||||
{
|
{
|
||||||
|
@ -1353,3 +1309,37 @@ void p3NetMgr::getNetStatus(pqiNetStatus &status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************************************
|
||||||
|
************************************** ExtAddrFinder *****************************************
|
||||||
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
bool p3NetMgr::getIPServersEnabled()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
return mUseExtAddrFinder;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3NetMgr::getIPServersList(std::list<std::string>& ip_servers)
|
||||||
|
{
|
||||||
|
mExtAddrFinder->getIPServersList(ip_servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3NetMgr::setIPServersEnabled(bool b)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
mUseExtAddrFinder = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3NetMgr: setIPServers to " << b << std::endl ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -35,8 +35,6 @@
|
||||||
|
|
||||||
#include "pqi/p3cfgmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
|
|
||||||
#include "pqi/p3peermgr.h"
|
|
||||||
|
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
class ExtAddrFinder ;
|
class ExtAddrFinder ;
|
||||||
|
@ -80,12 +78,22 @@ class pqiNetStatus
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class p3PeerMgr;
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
|
class rsUdpStack;
|
||||||
|
class UdpStunner;
|
||||||
|
class p3BitDht;
|
||||||
|
class UdpRelayReceiver;
|
||||||
|
|
||||||
|
|
||||||
class p3NetMgr
|
class p3NetMgr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3NetMgr(p3PeerMgr *peerMgr);
|
p3NetMgr();
|
||||||
|
|
||||||
|
void setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
|
@ -181,8 +189,6 @@ void netUnreachableCheck();
|
||||||
void networkConsistencyCheck();
|
void networkConsistencyCheck();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// These should have there own Mutex Protection,
|
// These should have there own Mutex Protection,
|
||||||
ExtAddrFinder *mExtAddrFinder ;
|
ExtAddrFinder *mExtAddrFinder ;
|
||||||
|
@ -193,7 +199,21 @@ private:
|
||||||
|
|
||||||
std::list<pqiNetListener *> mNetListeners;
|
std::list<pqiNetListener *> mNetListeners;
|
||||||
|
|
||||||
p3PeerMgr *mPeerMgr; // Feedback about Network Addresses.
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
|
/* UDP Stack - managed here */
|
||||||
|
rsUdpStack *mDhtStack;
|
||||||
|
UdpStunner *mDhtStunner;
|
||||||
|
p3BitDht *mBitDht;
|
||||||
|
UdpRelayReceiver *mRelay;
|
||||||
|
// No Pointer to UdpPeerReceiver.
|
||||||
|
|
||||||
|
// 2ND Stack.
|
||||||
|
rsUdpStack *mProxyStack;
|
||||||
|
UdpStunner *mProxyStunner;
|
||||||
|
// No Pointer to UdpPeerReceiver.
|
||||||
|
|
||||||
|
|
||||||
RsMutex mNetMtx; /* protects below */
|
RsMutex mNetMtx; /* protects below */
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
|
|
||||||
#include "pqi/p3peermgr.h"
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||||
//#include "tcponudp/tou.h"
|
//#include "tcponudp/tou.h"
|
||||||
|
@ -73,11 +75,10 @@ void printConnectState(std::ostream &out, peerState &peer);
|
||||||
peerState::peerState()
|
peerState::peerState()
|
||||||
:id("unknown"),
|
:id("unknown"),
|
||||||
gpg_id("unknown"),
|
gpg_id("unknown"),
|
||||||
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD),
|
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD), lastcontact(0)
|
||||||
lastcontact(0)
|
|
||||||
{
|
{
|
||||||
sockaddr_clear(¤tlocaladdr);
|
sockaddr_clear(&localaddr);
|
||||||
sockaddr_clear(¤tserveraddr);
|
sockaddr_clear(&serveraddr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -88,10 +89,10 @@ std::string textPeerConnectState(peerState &state)
|
||||||
out << "Id: " << state.id << std::endl;
|
out << "Id: " << state.id << std::endl;
|
||||||
out << "NetMode: " << state.netMode << std::endl;
|
out << "NetMode: " << state.netMode << std::endl;
|
||||||
out << "VisState: " << state.visState << std::endl;
|
out << "VisState: " << state.visState << std::endl;
|
||||||
out << "laddr: " << rs_inet_ntoa(state.currentlocaladdr.sin_addr)
|
out << "laddr: " << rs_inet_ntoa(state.localaddr.sin_addr)
|
||||||
<< ":" << ntohs(state.currentlocaladdr.sin_port) << std::endl;
|
<< ":" << ntohs(state.localaddr.sin_port) << std::endl;
|
||||||
out << "eaddr: " << rs_inet_ntoa(state.currentserveraddr.sin_addr)
|
out << "eaddr: " << rs_inet_ntoa(state.serveraddr.sin_addr)
|
||||||
<< ":" << ntohs(state.currentserveraddr.sin_port) << std::endl;
|
<< ":" << ntohs(state.serveraddr.sin_port) << std::endl;
|
||||||
|
|
||||||
std::string output = out.str();
|
std::string output = out.str();
|
||||||
return output;
|
return output;
|
||||||
|
@ -127,30 +128,52 @@ p3PeerMgr::p3PeerMgr()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3PeerMgr::setManagers(p3LinkMgr *linkMgr, p3NetMgr *netMgr)
|
||||||
|
{
|
||||||
|
mLinkMgr = linkMgr;
|
||||||
|
mNetMgr = netMgr;
|
||||||
|
}
|
||||||
|
|
||||||
void p3PeerMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
void p3PeerMgr::setOwnNetworkMode(uint32_t netMode)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3PeerMgr::setOwnNetConfig()" << std::endl;
|
std::cerr << "p3PeerMgr::setOwnNetworkMode() :";
|
||||||
std::cerr << "Existing netMode: " << mOwnState.netMode << " vis: " << mOwnState.visState;
|
std::cerr << " Existing netMode: " << mOwnState.netMode;
|
||||||
std::cerr << std::endl;
|
std::cerr << " Input netMode: " << netMode;
|
||||||
std::cerr << "Input netMode: " << netMode << " vis: " << visState;
|
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mOwnState.netMode = (netMode & RS_NET_MODE_ACTUAL);
|
mOwnState.netMode = (netMode & RS_NET_MODE_ACTUAL);
|
||||||
mOwnState.visState = visState;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass on Flags to NetMgr.
|
// Pass on Flags to NetMgr.
|
||||||
mNetMgr->setNetConfig((netMode & RS_NET_MODE_ACTUAL), visState);
|
mNetMgr->setOwnNetworkMode((netMode & RS_NET_MODE_ACTUAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3PeerMgr::setOwnVisState(uint32_t visState)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3PeerMgr::setOwnVisState()";
|
||||||
|
std::cerr << "Existing vis: " << mOwnState.visState;
|
||||||
|
std::cerr << "Input vis: " << visState;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mOwnState.visState = visState;
|
||||||
|
|
||||||
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass on Flags to NetMgr.
|
||||||
|
mNetMgr->setOwnVisState(visState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,72 +295,6 @@ void p3PeerMgr::getOthersList(std::list<std::string> &peers)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
bool p3PeerMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl)
|
|
||||||
{
|
|
||||||
if (ssl) {
|
|
||||||
/* count ssl id's */
|
|
||||||
|
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
|
|
||||||
if (pnFriendCount) *pnFriendCount = mFriendList.size();
|
|
||||||
if (pnOnlineCount) {
|
|
||||||
*pnOnlineCount = 0;
|
|
||||||
|
|
||||||
std::map<std::string, peerState>::iterator it;
|
|
||||||
for (it = mFriendList.begin(); it != mFriendList.end(); it++) {
|
|
||||||
if (it->second.state & RS_PEER_S_CONNECTED) {
|
|
||||||
(*pnOnlineCount)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* count gpg id's */
|
|
||||||
|
|
||||||
if (pnFriendCount) *pnFriendCount = 0;
|
|
||||||
if (pnOnlineCount) *pnOnlineCount = 0;
|
|
||||||
|
|
||||||
if (pnFriendCount || pnOnlineCount) {
|
|
||||||
std::list<std::string> gpgIds;
|
|
||||||
if (AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds) == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add own id */
|
|
||||||
gpgIds.push_back(AuthGPG::getAuthGPG()->getGPGOwnId());
|
|
||||||
|
|
||||||
std::list<std::string> gpgOnlineIds = gpgIds;
|
|
||||||
|
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
|
|
||||||
std::list<std::string>::iterator gpgIt;
|
|
||||||
|
|
||||||
/* check ssl id's */
|
|
||||||
std::map<std::string, peerState>::iterator it;
|
|
||||||
for (it = mFriendList.begin(); it != mFriendList.end(); it++) {
|
|
||||||
if (pnFriendCount && gpgIds.size()) {
|
|
||||||
gpgIt = std::find(gpgIds.begin(), gpgIds.end(), it->second.gpg_id);
|
|
||||||
if (gpgIt != gpgIds.end()) {
|
|
||||||
(*pnFriendCount)++;
|
|
||||||
gpgIds.erase(gpgIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pnOnlineCount && gpgOnlineIds.size()) {
|
|
||||||
if (it->second.state & RS_PEER_S_CONNECTED) {
|
|
||||||
gpgIt = std::find(gpgOnlineIds.begin(), gpgOnlineIds.end(), it->second.gpg_id);
|
|
||||||
if (gpgIt != gpgOnlineIds.end()) {
|
|
||||||
(*pnOnlineCount)++;
|
|
||||||
gpgOnlineIds.erase(gpgIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
* Update state,
|
* Update state,
|
||||||
|
@ -606,20 +563,20 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
if (mOwnState.currentlocaladdr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
if (mOwnState.localaddr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
||||||
mOwnState.currentlocaladdr.sin_port != addr.sin_port)
|
mOwnState.localaddr.sin_port != addr.sin_port)
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mOwnState.currentlocaladdr = addr;
|
mOwnState.localaddr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
mNetMgr->netReset();
|
mNetMgr->setLocalAddress(addr);
|
||||||
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
#ifdef CONN_DEBUG_RESET
|
||||||
std::cerr << "p3PeerMgr::setLocalAddress() Calling NetReset" << std::endl;
|
std::cerr << "p3PeerMgr::setLocalAddress() Calling NetReset" << std::endl;
|
||||||
|
@ -643,7 +600,7 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "it" points to peer */
|
/* "it" points to peer */
|
||||||
it->second.currentlocaladdr = addr;
|
it->second.localaddr = addr;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//update ip address list
|
//update ip address list
|
||||||
|
@ -661,11 +618,13 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
|
||||||
bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
|
bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
|
||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
|
{
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
mOwnState.currentserveraddr = addr;
|
mOwnState.serveraddr = addr;
|
||||||
|
}
|
||||||
|
|
||||||
mNetMgr->netExtReset();
|
mNetMgr->setExtAddress(addr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -685,7 +644,7 @@ bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "it" points to peer */
|
/* "it" points to peer */
|
||||||
it->second.currentserveraddr = addr;
|
it->second.serveraddr = addr;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//update ip address list
|
//update ip address list
|
||||||
|
@ -774,19 +733,58 @@ bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddress &addr)
|
||||||
|
{
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3PeerMgr::updateCurrentAddress() called for id : " << id << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
/* cannot be own id */
|
||||||
|
|
||||||
|
/* check if it is a friend */
|
||||||
|
std::map<std::string, peerState>::iterator it;
|
||||||
|
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||||
|
{
|
||||||
|
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||||
|
{
|
||||||
|
std::cerr << "p3PeerMgr::updateCurrentAddress() ERROR peer id not found: " << id << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPrivateNet(&(addr.mAddr.sin_addr)))
|
||||||
|
{
|
||||||
|
it->second.ipAddrs.updateLocalAddrs(addr);
|
||||||
|
it->second.localaddr = addr.mAddr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
it->second.ipAddrs.updateExtAddrs(addr);
|
||||||
|
it->second.serveraddr = addr.mAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3PeerMgr::updatedCurrentAddress() Updated Address for: " << id;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
it->second.ipAddrs.printAddrs(std::cerr);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool p3PeerMgr::setNetworkMode(const std::string &id, uint32_t netMode)
|
bool p3PeerMgr::setNetworkMode(const std::string &id, uint32_t netMode)
|
||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
uint32_t visState;
|
setOwnNetworkMode(netMode);
|
||||||
uint32_t oldNetMode;
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
visState = mOwnState.visState;
|
|
||||||
oldNetMode = mOwnState.netMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
setOwnNetConfig(netMode, visState);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -835,12 +833,7 @@ bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState)
|
||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
uint32_t netMode;
|
setOwnVisState(visState);
|
||||||
{
|
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
netMode = mOwnState.netMode;
|
|
||||||
}
|
|
||||||
setOwnNetConfig(netMode, visState);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,11 +866,11 @@ bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState)
|
||||||
if(dht_state)
|
if(dht_state)
|
||||||
{
|
{
|
||||||
/* hidden from DHT world */
|
/* hidden from DHT world */
|
||||||
netAssistFriend(id, false);
|
mLinkMgr->setFriendVisibility(id, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
netAssistFriend(id, true);
|
mLinkMgr->setFriendVisibility(id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,6 +907,8 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
{
|
{
|
||||||
/* create a list of current peers */
|
/* create a list of current peers */
|
||||||
cleanup = false;
|
cleanup = false;
|
||||||
|
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
|
||||||
|
bool allowTunnelConnection = mLinkMgr->getTunnelConnection();
|
||||||
|
|
||||||
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
|
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
|
||||||
|
|
||||||
|
@ -939,8 +934,8 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
item->visState = mOwnState.visState;
|
item->visState = mOwnState.visState;
|
||||||
item->lastContact = mOwnState.lastcontact;
|
item->lastContact = mOwnState.lastcontact;
|
||||||
|
|
||||||
item->currentlocaladdr = mOwnState.currentlocaladdr;
|
item->currentlocaladdr = mOwnState.localaddr;
|
||||||
item->currentremoteaddr = mOwnState.currentserveraddr;
|
item->currentremoteaddr = mOwnState.serveraddr;
|
||||||
item->dyndns = mOwnState.dyndns;
|
item->dyndns = mOwnState.dyndns;
|
||||||
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
|
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||||
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
|
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||||
|
@ -967,8 +962,8 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
item->netMode = (it->second).netMode;
|
item->netMode = (it->second).netMode;
|
||||||
item->visState = (it->second).visState;
|
item->visState = (it->second).visState;
|
||||||
item->lastContact = (it->second).lastcontact;
|
item->lastContact = (it->second).lastcontact;
|
||||||
item->currentlocaladdr = (it->second).currentlocaladdr;
|
item->currentlocaladdr = (it->second).localaddr;
|
||||||
item->currentremoteaddr = (it->second).currentserveraddr;
|
item->currentremoteaddr = (it->second).serveraddr;
|
||||||
item->dyndns = (it->second).dyndns;
|
item->dyndns = (it->second).dyndns;
|
||||||
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||||
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||||
|
@ -988,7 +983,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
|
|
||||||
RsTlvKeyValue kv;
|
RsTlvKeyValue kv;
|
||||||
kv.key = "USE_EXTR_IP_FINDER" ;
|
kv.key = "USE_EXTR_IP_FINDER" ;
|
||||||
kv.value = (mUseExtAddrFinder)?"TRUE":"FALSE" ;
|
kv.value = (useExtAddrFinder)?"TRUE":"FALSE" ;
|
||||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
|
@ -1003,7 +998,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||||
|
|
||||||
RsTlvKeyValue kv2;
|
RsTlvKeyValue kv2;
|
||||||
kv2.key = "ALLOW_TUNNEL_CONNECTION" ;
|
kv2.key = "ALLOW_TUNNEL_CONNECTION" ;
|
||||||
kv2.value = (mAllowTunnelConnection)?"TRUE":"FALSE" ;
|
kv2.value = (allowTunnelConnection)?"TRUE":"FALSE" ;
|
||||||
vitem2->tlvkvs.pairs.push_back(kv2) ;
|
vitem2->tlvkvs.pairs.push_back(kv2) ;
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
|
@ -1040,6 +1035,10 @@ void p3PeerMgr::saveDone()
|
||||||
bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// DEFAULTS.
|
||||||
|
bool useExtAddrFinder = true;
|
||||||
|
bool allowTunnelConnection = true;
|
||||||
|
|
||||||
if (load.size() == 0) {
|
if (load.size() == 0) {
|
||||||
std::cerr << "p3PeerMgr::loadList() list is empty, it may be a configuration problem." << std::endl;
|
std::cerr << "p3PeerMgr::loadList() list is empty, it may be a configuration problem." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
@ -1066,7 +1065,9 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* add ownConfig */
|
/* add ownConfig */
|
||||||
setOwnNetConfig(pitem->netMode, pitem->visState);
|
setOwnNetworkMode(pitem->netMode);
|
||||||
|
setOwnVisState(pitem->visState);
|
||||||
|
|
||||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||||
}
|
}
|
||||||
|
@ -1081,6 +1082,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, pitem->lastContact);
|
addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, pitem->lastContact);
|
||||||
setLocation(pitem->pid, pitem->location);
|
setLocation(pitem->pid, pitem->location);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
setDynDNS (pitem->pid, pitem->dyndns);
|
setDynDNS (pitem->pid, pitem->dyndns);
|
||||||
|
@ -1089,6 +1091,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
pqiIpAddrSet addrs;
|
pqiIpAddrSet addrs;
|
||||||
addrs.mLocal.extractFromTlv(pitem->localAddrList);
|
addrs.mLocal.extractFromTlv(pitem->localAddrList);
|
||||||
addrs.mExt.extractFromTlv(pitem->extAddrList);
|
addrs.mExt.extractFromTlv(pitem->extAddrList);
|
||||||
|
|
||||||
updateAddressList(pitem->pid, addrs);
|
updateAddressList(pitem->pid, addrs);
|
||||||
|
|
||||||
delete(*it);
|
delete(*it);
|
||||||
|
@ -1109,11 +1112,11 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
std::list<RsTlvKeyValue>::iterator kit;
|
std::list<RsTlvKeyValue>::iterator kit;
|
||||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||||
if(kit->key == "USE_EXTR_IP_FINDER") {
|
if(kit->key == "USE_EXTR_IP_FINDER") {
|
||||||
mUseExtAddrFinder = (kit->value == "TRUE");
|
useExtAddrFinder = (kit->value == "TRUE");
|
||||||
std::cerr << "setting use_extr_addr_finder to " << mUseExtAddrFinder << std::endl ;
|
std::cerr << "setting use_extr_addr_finder to " << useExtAddrFinder << std::endl ;
|
||||||
} else if (kit->key == "ALLOW_TUNNEL_CONNECTION") {
|
} else if (kit->key == "ALLOW_TUNNEL_CONNECTION") {
|
||||||
mAllowTunnelConnection = (kit->value == "TRUE");
|
allowTunnelConnection = (kit->value == "TRUE");
|
||||||
std::cerr << "setting allow_tunnel_connection to " << mAllowTunnelConnection << std::endl ;
|
std::cerr << "setting allow_tunnel_connection to " << allowTunnelConnection << std::endl ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1196,10 +1199,14 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mNetMgr->setIPServersEnabled(useExtAddrFinder);
|
||||||
|
mLinkMgr->setTunnelConnection(allowTunnelConnection);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
void printConnectState(std::ostream &out, peerState &peer)
|
void printConnectState(std::ostream &out, peerState &peer)
|
||||||
{
|
{
|
||||||
|
@ -1227,6 +1234,8 @@ void printConnectState(std::ostream &out, peerState &peer)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
|
@ -70,8 +70,6 @@ const uint32_t RS_NET_MODE_UDP = 0x0004;
|
||||||
const uint32_t RS_NET_MODE_UNREACHABLE = 0x0008;
|
const uint32_t RS_NET_MODE_UNREACHABLE = 0x0008;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* flags of peerStatus */
|
/* flags of peerStatus */
|
||||||
const uint32_t RS_NET_FLAGS_USE_DISC = 0x0001;
|
const uint32_t RS_NET_FLAGS_USE_DISC = 0x0001;
|
||||||
const uint32_t RS_NET_FLAGS_USE_DHT = 0x0002;
|
const uint32_t RS_NET_FLAGS_USE_DHT = 0x0002;
|
||||||
|
@ -80,8 +78,6 @@ const uint32_t RS_NET_FLAGS_EXTERNAL_ADDR = 0x0008;
|
||||||
const uint32_t RS_NET_FLAGS_STABLE_UDP = 0x0010;
|
const uint32_t RS_NET_FLAGS_STABLE_UDP = 0x0010;
|
||||||
const uint32_t RS_NET_FLAGS_TRUSTS_ME = 0x0020;
|
const uint32_t RS_NET_FLAGS_TRUSTS_ME = 0x0020;
|
||||||
|
|
||||||
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
|
|
||||||
|
|
||||||
class peerState
|
class peerState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -93,11 +89,8 @@ class peerState
|
||||||
uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
||||||
uint32_t visState; /* STD, GRAY, DARK */
|
uint32_t visState; /* STD, GRAY, DARK */
|
||||||
|
|
||||||
struct sockaddr_in localaddr, serveraddr;
|
struct sockaddr_in localaddr;
|
||||||
|
struct sockaddr_in serveraddr;
|
||||||
//used to store current ip (for config and connection management)
|
|
||||||
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
|
||||||
struct sockaddr_in currentserveraddr; /* Mandatory */
|
|
||||||
std::string dyndns;
|
std::string dyndns;
|
||||||
|
|
||||||
time_t lastcontact;
|
time_t lastcontact;
|
||||||
|
@ -105,29 +98,8 @@ class peerState
|
||||||
/* list of addresses from various sources */
|
/* list of addresses from various sources */
|
||||||
pqiIpAddrSet ipAddrs;
|
pqiIpAddrSet ipAddrs;
|
||||||
|
|
||||||
/***** Below here not stored permanently *****/
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
std::string location;
|
std::string location;
|
||||||
|
std::string name;
|
||||||
//uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL
|
|
||||||
//time_t lastavailable;
|
|
||||||
//time_t lastattempt;
|
|
||||||
|
|
||||||
|
|
||||||
//uint32_t state;
|
|
||||||
//uint32_t actions;
|
|
||||||
|
|
||||||
//uint32_t source; /* most current source */
|
|
||||||
//peerAddrInfo dht;
|
|
||||||
//peerAddrInfo disc;
|
|
||||||
//peerAddrInfo peer;
|
|
||||||
|
|
||||||
/* a list of connect attempts to make (in order) */
|
|
||||||
//bool inConnAttempt;
|
|
||||||
//peerConnectAddress currentConnAddrAttempt;
|
|
||||||
//std::list<peerConnectAddress> connAddrs;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,23 +108,32 @@ class RsGroupInfo;
|
||||||
|
|
||||||
std::string textPeerState(peerState &state);
|
std::string textPeerState(peerState &state);
|
||||||
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
class p3NetMgr;
|
||||||
|
|
||||||
class p3PeerMgr: public pqiConnectCb, public p3Config
|
|
||||||
|
class p3PeerMgr: public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3PeerMgr();
|
p3PeerMgr();
|
||||||
|
|
||||||
|
void setManagers(p3LinkMgr *linkMgr, p3NetMgr *netMgr);
|
||||||
|
|
||||||
|
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
/*************** External Control ****************/
|
/*************** External Control ****************/
|
||||||
bool shutdown(); /* blocking shutdown call */
|
bool shutdown(); /* blocking shutdown call */
|
||||||
|
|
||||||
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
void setOwnNetworkMode(uint32_t netMode);
|
||||||
|
void setOwnVisState(uint32_t visState);
|
||||||
|
|
||||||
bool setLocalAddress(const std::string &id, struct sockaddr_in addr);
|
bool setLocalAddress(const std::string &id, struct sockaddr_in addr);
|
||||||
bool setExtAddress(const std::string &id, struct sockaddr_in addr);
|
bool setExtAddress(const std::string &id, struct sockaddr_in addr);
|
||||||
bool setDynDNS(const std::string &id, const std::string &dyndns);
|
bool setDynDNS(const std::string &id, const std::string &dyndns);
|
||||||
bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
||||||
|
bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr);
|
||||||
|
|
||||||
bool setNetworkMode(const std::string &id, uint32_t netMode);
|
bool setNetworkMode(const std::string &id, uint32_t netMode);
|
||||||
bool setVisState(const std::string &id, uint32_t visState);
|
bool setVisState(const std::string &id, uint32_t visState);
|
||||||
|
@ -214,6 +195,12 @@ void tickMonitors();
|
||||||
virtual bool loadList(std::list<RsItem *>& load);
|
virtual bool loadList(std::list<RsItem *>& load);
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
|
/* other important managers */
|
||||||
|
|
||||||
|
p3LinkMgr *mLinkMgr;
|
||||||
|
p3NetMgr *mNetMgr;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RsMutex mPeerMtx; /* protects below */
|
RsMutex mPeerMtx; /* protects below */
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ uint32_t state;
|
||||||
uint32_t actions;
|
uint32_t actions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class p3ConnectMgr;
|
class p3LinkMgr;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This class should be implemented
|
* This class should be implemented
|
||||||
|
@ -96,13 +96,13 @@ class p3ConnectMgr;
|
||||||
class pqiMonitor
|
class pqiMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pqiMonitor() :mConnMgr(NULL) { return; }
|
pqiMonitor() :mLinkMgr(NULL) { return; }
|
||||||
virtual ~pqiMonitor() { return; }
|
virtual ~pqiMonitor() { return; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* passes a handle the retroshare connection manager
|
* passes a handle the retroshare connection manager
|
||||||
*/
|
*/
|
||||||
void setConnectionMgr(p3ConnectMgr *cm) { mConnMgr = cm; }
|
void setLinkMgr(p3LinkMgr *lm) { mLinkMgr = lm; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* this serves as a call back function for server which has
|
* this serves as a call back function for server which has
|
||||||
|
@ -124,7 +124,7 @@ virtual void statusChanged() {};
|
||||||
//virtual void peerStatus(std::string id, uint32_t mode) = 0;
|
//virtual void peerStatus(std::string id, uint32_t mode) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -654,7 +654,7 @@ bool getPreferredInterface(struct in_addr &prefAddr) // returns best addr.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sameNet(struct in_addr *addr, struct in_addr *addr2)
|
bool sameNet(const struct in_addr *addr, const struct in_addr *addr2)
|
||||||
{
|
{
|
||||||
#ifdef NET_DEBUG
|
#ifdef NET_DEBUG
|
||||||
std::cerr << "sameNet: " << rs_inet_ntoa(*addr);
|
std::cerr << "sameNet: " << rs_inet_ntoa(*addr);
|
||||||
|
|
|
@ -108,7 +108,7 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs); // returns all possib
|
||||||
|
|
||||||
// checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
|
// checks (addr1 & 255.255.255.0) == (addr2 & 255.255.255.0)
|
||||||
bool isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
|
bool isSameSubnet(struct in_addr *addr1, struct in_addr *addr2);
|
||||||
bool sameNet(struct in_addr *addr, struct in_addr *addr2);
|
bool sameNet(const struct in_addr *addr, const struct in_addr *addr2);
|
||||||
|
|
||||||
in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.
|
in_addr_t pqi_inet_netof(struct in_addr addr); // our implementation.
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -185,11 +185,10 @@ int pqipersongrp::init_listener()
|
||||||
{
|
{
|
||||||
/* extract details from
|
/* extract details from
|
||||||
*/
|
*/
|
||||||
peerConnectState state;
|
struct sockaddr_in laddr = mLinkMgr->getLocalAddress();
|
||||||
mConnMgr->getOwnNetStatus(state);
|
|
||||||
|
|
||||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||||
pqil = createListener(state.currentlocaladdr);
|
pqil = createListener(laddr);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -325,19 +324,19 @@ void pqipersongrp::statusChanged()
|
||||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||||
|
|
||||||
/* get address from p3connmgr */
|
/* get address from p3connmgr */
|
||||||
if (!mConnMgr) {
|
if (!mLinkMgr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for active connections and start waiting id's */
|
/* check for active connections and start waiting id's */
|
||||||
std::list<std::string> peers;
|
std::list<std::string> peers;
|
||||||
mConnMgr->getFriendList(peers);
|
mLinkMgr->getFriendList(peers);
|
||||||
|
|
||||||
/* count connection attempts */
|
/* count connection attempts */
|
||||||
std::list<std::string>::iterator peer;
|
std::list<std::string>::iterator peer;
|
||||||
for (peer = peers.begin(); peer != peers.end(); peer++) {
|
for (peer = peers.begin(); peer != peers.end(); peer++) {
|
||||||
peerConnectState state;
|
peerConnectState state;
|
||||||
if (mConnMgr->getFriendNetStatus(*peer, state) == false) {
|
if (mLinkMgr->getFriendNetStatus(*peer, state) == false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +484,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||||
if (id == mConnMgr->getOwnId()) {
|
if (id == mLinkMgr->getOwnId()) {
|
||||||
#ifdef PGRP_DEBUG
|
#ifdef PGRP_DEBUG
|
||||||
std::cerr << "pqipersongrp::connectPeer() Failed, connecting to own id." << std::endl;
|
std::cerr << "pqipersongrp::connectPeer() Failed, connecting to own id." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -503,7 +502,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||||
|
|
||||||
|
|
||||||
/* get address from p3connmgr */
|
/* get address from p3connmgr */
|
||||||
if (!mConnMgr)
|
if (!mLinkMgr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef WINDOWS_SYS
|
#ifdef WINDOWS_SYS
|
||||||
|
@ -539,7 +538,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||||
uint32_t timeout;
|
uint32_t timeout;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
|
|
||||||
if (!mConnMgr->connectAttempt(id, addr, delay, period, type))
|
if (!mLinkMgr->connectAttempt(id, addr, delay, period, type))
|
||||||
{
|
{
|
||||||
#ifdef PGRP_DEBUG
|
#ifdef PGRP_DEBUG
|
||||||
std::cerr << " pqipersongrp::connectPeer() No Net Address";
|
std::cerr << " pqipersongrp::connectPeer() No Net Address";
|
||||||
|
@ -621,10 +620,10 @@ bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (mConnMgr)
|
if (mLinkMgr)
|
||||||
mConnMgr->connectResult(id, success, type, raddr);
|
mLinkMgr->connectResult(id, success, type, raddr);
|
||||||
|
|
||||||
return (NULL != mConnMgr);
|
return (NULL != mLinkMgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************** DUMMY Specific features ***************************/
|
/******************************** DUMMY Specific features ***************************/
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
|
|
||||||
#include "pqi/pqissllistener.h"
|
#include "pqi/pqissllistener.h"
|
||||||
|
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
const int pqisslzone = 37714;
|
const int pqisslzone = 37714;
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
|
@ -92,7 +94,7 @@ static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3ConnectMgr *cm)
|
pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3LinkMgr *lm)
|
||||||
:NetBinInterface(parent, parent->PeerId()),
|
:NetBinInterface(parent, parent->PeerId()),
|
||||||
waiting(WAITING_NOT), active(false), certvalid(false),
|
waiting(WAITING_NOT), active(false), certvalid(false),
|
||||||
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
|
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
|
||||||
|
@ -102,7 +104,7 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3ConnectMgr *cm)
|
||||||
net_attempt(0), net_failure(0), net_unreachable(0),
|
net_attempt(0), net_failure(0), net_unreachable(0),
|
||||||
sameLAN(false), n_read_zero(0), mReadZeroTS(0),
|
sameLAN(false), n_read_zero(0), mReadZeroTS(0),
|
||||||
mConnectDelay(0), mConnectTS(0),
|
mConnectDelay(0), mConnectTS(0),
|
||||||
mConnectTimeout(0), mTimeoutTS(0), mConnMgr(cm)
|
mConnectTimeout(0), mTimeoutTS(0), mLinkMgr(lm)
|
||||||
|
|
||||||
{
|
{
|
||||||
/* set address to zero */
|
/* set address to zero */
|
||||||
|
@ -1307,9 +1309,8 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
|
||||||
|
|
||||||
/* check whether it is on the same LAN */
|
/* check whether it is on the same LAN */
|
||||||
|
|
||||||
peerConnectState details;
|
struct sockaddr_in localaddr = mLinkMgr->getLocalAddress();
|
||||||
mConnMgr->getOwnNetStatus(details);
|
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(localaddr.sin_addr));
|
||||||
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(details.currentlocaladdr.sin_addr));
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
|
@ -1317,7 +1318,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
out << "\t\tchecking for same LAN";
|
out << "\t\tchecking for same LAN";
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
out << "\t localaddr: " << rs_inet_ntoa(details.currentlocaladdr.sin_addr);
|
out << "\t localaddr: " << rs_inet_ntoa(localaddr.sin_addr);
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
out << "\t remoteaddr: " << rs_inet_ntoa(remote_addr.sin_addr);
|
out << "\t remoteaddr: " << rs_inet_ntoa(remote_addr.sin_addr);
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
|
|
|
@ -37,9 +37,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "pqi/pqi_base.h"
|
#include "pqi/pqi_base.h"
|
||||||
|
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
|
|
||||||
#define WAITING_NOT 0
|
#define WAITING_NOT 0
|
||||||
|
@ -85,12 +82,13 @@ class pqissl;
|
||||||
class cert;
|
class cert;
|
||||||
|
|
||||||
class pqissllistener;
|
class pqissllistener;
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
class pqissl: public NetBinInterface
|
class pqissl: public NetBinInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pqissl(pqissllistener *l, PQInterface *parent,
|
pqissl(pqissllistener *l, PQInterface *parent,
|
||||||
p3ConnectMgr *cm);
|
p3LinkMgr *lm);
|
||||||
virtual ~pqissl();
|
virtual ~pqissl();
|
||||||
|
|
||||||
// NetInterface
|
// NetInterface
|
||||||
|
@ -200,7 +198,7 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||||
uint32_t mConnectTimeout;
|
uint32_t mConnectTimeout;
|
||||||
time_t mTimeoutTS;
|
time_t mTimeoutTS;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ssl only fns.
|
// ssl only fns.
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
#include "pqi/sslfns.h"
|
#include "pqi/sslfns.h"
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
@ -56,8 +58,8 @@ const int pqissllistenzone = 49787;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
pqissllistenbase::pqissllistenbase(struct sockaddr_in addr, p3ConnectMgr *cm)
|
pqissllistenbase::pqissllistenbase(struct sockaddr_in addr, p3PeerMgr *pm)
|
||||||
:laddr(addr), active(false), mConnMgr(cm)
|
:laddr(addr), active(false), mPeerMgr(pm)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!(AuthSSL::getAuthSSL()-> active())) {
|
if (!(AuthSSL::getAuthSSL()-> active())) {
|
||||||
|
@ -562,8 +564,8 @@ int pqissllistenbase::continueaccepts()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pqissllistener::pqissllistener(struct sockaddr_in addr, p3ConnectMgr *cm)
|
pqissllistener::pqissllistener(struct sockaddr_in addr, p3PeerMgr *lm)
|
||||||
:pqissllistenbase(addr, cm)
|
:pqissllistenbase(addr, lm)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -730,7 +732,7 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||||
|
|
||||||
/* now need to get GPG id too */
|
/* now need to get GPG id too */
|
||||||
std::string pgpid = getX509CNString(peercert->cert_info->issuer);
|
std::string pgpid = getX509CNString(peercert->cert_info->issuer);
|
||||||
mConnMgr->addFriend(newPeerId, pgpid);
|
mPeerMgr->addFriend(newPeerId, pgpid);
|
||||||
|
|
||||||
X509_free(peercert);
|
X509_free(peercert);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -45,13 +45,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class pqissl;
|
class pqissl;
|
||||||
|
class p3PeerMgr;
|
||||||
|
|
||||||
class pqissllistenbase: public pqilistener
|
class pqissllistenbase: public pqilistener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
pqissllistenbase(struct sockaddr_in addr, p3ConnectMgr *cm);
|
pqissllistenbase(struct sockaddr_in addr, p3PeerMgr *pm);
|
||||||
virtual ~pqissllistenbase();
|
virtual ~pqissllistenbase();
|
||||||
|
|
||||||
/*************************************/
|
/*************************************/
|
||||||
|
@ -88,7 +89,7 @@ int Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_in *inaddr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3PeerMgr *mPeerMgr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ class pqissllistener: public pqissllistenbase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
pqissllistener(struct sockaddr_in addr, p3ConnectMgr *cm);
|
pqissllistener(struct sockaddr_in addr, p3PeerMgr *pm);
|
||||||
virtual ~pqissllistener();
|
virtual ~pqissllistener();
|
||||||
|
|
||||||
int addlistenaddr(std::string id, pqissl *acc);
|
int addlistenaddr(std::string id, pqissl *acc);
|
||||||
|
|
|
@ -53,7 +53,7 @@ const int pqipersongrpzone = 354;
|
||||||
|
|
||||||
pqilistener * pqisslpersongrp::createListener(struct sockaddr_in laddr)
|
pqilistener * pqisslpersongrp::createListener(struct sockaddr_in laddr)
|
||||||
{
|
{
|
||||||
pqilistener *listener = new pqissllistener(laddr, mConnMgr);
|
pqilistener *listener = new pqissllistener(laddr, mPeerMgr);
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
pqiperson *pqip = new pqiperson(id, this);
|
pqiperson *pqip = new pqiperson(id, this);
|
||||||
pqissl *pqis = new pqissl((pqissllistener *) listener, pqip, mConnMgr);
|
pqissl *pqis = new pqissl((pqissllistener *) listener, pqip, mLinkMgr);
|
||||||
|
|
||||||
/* construct the serialiser ....
|
/* construct the serialiser ....
|
||||||
* Needs:
|
* Needs:
|
||||||
|
@ -85,7 +85,7 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
||||||
|
|
||||||
#ifndef PQI_DISABLE_TUNNEL
|
#ifndef PQI_DISABLE_TUNNEL
|
||||||
pqissltunnel *pqitun = new pqissltunnel(pqip, mConnMgr);
|
pqissltunnel *pqitun = new pqissltunnel(pqip, mLinkMgr);
|
||||||
|
|
||||||
RsSerialiser *rss3 = new RsSerialiser();
|
RsSerialiser *rss3 = new RsSerialiser();
|
||||||
rss3->addSerialType(new RsFileItemSerialiser());
|
rss3->addSerialType(new RsFileItemSerialiser());
|
||||||
|
@ -96,7 +96,7 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PQI_DISABLE_UDP
|
#ifndef PQI_DISABLE_UDP
|
||||||
pqissludp *pqius = new pqissludp(pqip, mConnMgr);
|
pqissludp *pqius = new pqissludp(pqip, mLinkMgr);
|
||||||
|
|
||||||
RsSerialiser *rss2 = new RsSerialiser();
|
RsSerialiser *rss2 = new RsSerialiser();
|
||||||
rss2->addSerialType(new RsFileItemSerialiser());
|
rss2->addSerialType(new RsFileItemSerialiser());
|
||||||
|
|
|
@ -30,11 +30,13 @@
|
||||||
|
|
||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
|
|
||||||
|
class p3PeerMgr;
|
||||||
|
|
||||||
class pqisslpersongrp: public pqipersongrp
|
class pqisslpersongrp: public pqipersongrp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags)
|
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags, p3PeerMgr *pm)
|
||||||
:pqipersongrp(pol, flags) { return; }
|
:pqipersongrp(pol, flags), mPeerMgr(pm) { return; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -42,6 +44,10 @@ class pqisslpersongrp: public pqipersongrp
|
||||||
virtual pqilistener *createListener(struct sockaddr_in laddr);
|
virtual pqilistener *createListener(struct sockaddr_in laddr);
|
||||||
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
|
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
|
||||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
p3PeerMgr *mPeerMgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include "pqi/pqissltunnel.h"
|
#include "pqi/pqissltunnel.h"
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
//#include "services/p3tunnel.h"
|
//#include "services/p3tunnel.h"
|
||||||
|
|
||||||
|
@ -90,8 +91,8 @@ const int pqisslzone = 37714;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pqissltunnel::pqissltunnel(PQInterface *parent, p3ConnectMgr *cm, p3tunnel *p3t)
|
pqissltunnel::pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t)
|
||||||
:NetBinInterface(parent, parent->PeerId()), mConnMgr(cm)
|
:NetBinInterface(parent, parent->PeerId()), mLinkMgr(cm)
|
||||||
{
|
{
|
||||||
active = false;
|
active = false;
|
||||||
waiting = TUNNEL_WAITING_NOT;
|
waiting = TUNNEL_WAITING_NOT;
|
||||||
|
@ -277,7 +278,7 @@ int pqissltunnel::tick()
|
||||||
std::cerr << "pqissltunnel::tick() attempt to connect through a normal tcp or udp connection." << std::endl;
|
std::cerr << "pqissltunnel::tick() attempt to connect through a normal tcp or udp connection." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
last_normal_connection_attempt_time = time(NULL);
|
last_normal_connection_attempt_time = time(NULL);
|
||||||
mConnMgr->retryConnect(parent()->PeerId());
|
mLinkMgr->retryConnect(parent()->PeerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active && ((time(NULL) - last_ping_send_time) > TUNNEL_REPEAT_PING_TIME)) {
|
if (active && ((time(NULL) - last_ping_send_time) > TUNNEL_REPEAT_PING_TIME)) {
|
||||||
|
@ -378,7 +379,7 @@ void pqissltunnel::spam_handshake()
|
||||||
std::cerr << "pqissltunnel::spam_handshake() starting to spam handshake tunnel packet." << std::endl;
|
std::cerr << "pqissltunnel::spam_handshake() starting to spam handshake tunnel packet." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::list<std::string> peers;
|
std::list<std::string> peers;
|
||||||
mConnMgr->getOnlineList(peers);
|
mLinkMgr->getOnlineList(peers);
|
||||||
std::list<std::string>::iterator it = peers.begin();
|
std::list<std::string>::iterator it = peers.begin();
|
||||||
while (it != peers.end()) {
|
while (it != peers.end()) {
|
||||||
//send a handshake to the destination through the relay
|
//send a handshake to the destination through the relay
|
||||||
|
@ -424,14 +425,14 @@ void pqissltunnel::IncommingHanshakePacket(std::string incRelayPeerId) {
|
||||||
last_packet_time = time(NULL);
|
last_packet_time = time(NULL);
|
||||||
|
|
||||||
std::string message = "pqissltunnel::IncommingHanshakePacket() mConnMgr->isOnline(parent()->PeerId() : ";
|
std::string message = "pqissltunnel::IncommingHanshakePacket() mConnMgr->isOnline(parent()->PeerId() : ";
|
||||||
if (mConnMgr->isOnline(parent()->PeerId())) {
|
if (mLinkMgr->isOnline(parent()->PeerId())) {
|
||||||
message += "true";
|
message += "true";
|
||||||
} else {
|
} else {
|
||||||
message += "false";
|
message += "false";
|
||||||
}
|
}
|
||||||
rslog(RSL_DEBUG_BASIC, pqisslzone, message);
|
rslog(RSL_DEBUG_BASIC, pqisslzone, message);
|
||||||
|
|
||||||
if (active || mConnMgr->isOnline(parent()->PeerId())) {
|
if (active || mLinkMgr->isOnline(parent()->PeerId())) {
|
||||||
//connection is already active, or peer is already online don't do nothing
|
//connection is already active, or peer is already online don't do nothing
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +550,7 @@ bool pqissltunnel::moretoread()
|
||||||
|
|
||||||
bool pqissltunnel::cansend()
|
bool pqissltunnel::cansend()
|
||||||
{
|
{
|
||||||
if (!mConnMgr->isOnline(relayPeerId)) {
|
if (!mLinkMgr->isOnline(relayPeerId)) {
|
||||||
reset();
|
reset();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,6 @@
|
||||||
|
|
||||||
#include "pqi/pqi_base.h"
|
#include "pqi/pqi_base.h"
|
||||||
|
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
|
||||||
#include "services/p3tunnel.h"
|
#include "services/p3tunnel.h"
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
|
@ -66,6 +64,8 @@ class cert;
|
||||||
|
|
||||||
class pqissltunnellistener;
|
class pqissltunnellistener;
|
||||||
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
struct data_with_length {
|
struct data_with_length {
|
||||||
int length;
|
int length;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -74,7 +74,7 @@ struct data_with_length {
|
||||||
class pqissltunnel: public NetBinInterface
|
class pqissltunnel: public NetBinInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pqissltunnel(PQInterface *parent, p3ConnectMgr *cm, p3tunnel *p3t);
|
pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t);
|
||||||
virtual ~pqissltunnel();
|
virtual ~pqissltunnel();
|
||||||
|
|
||||||
// NetInterface
|
// NetInterface
|
||||||
|
@ -129,7 +129,7 @@ private:
|
||||||
/* Need Certificate specific functions here! */
|
/* Need Certificate specific functions here! */
|
||||||
time_t mConnectTS;
|
time_t mConnectTS;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
p3tunnel *mP3tunnel;
|
p3tunnel *mP3tunnel;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
#include "util/rsnet.h"
|
#include "util/rsnet.h"
|
||||||
|
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
const int pqissludpzone = 3144;
|
const int pqissludpzone = 3144;
|
||||||
|
|
||||||
/* a final timeout, to ensure this never blocks completely
|
/* a final timeout, to ensure this never blocks completely
|
||||||
|
@ -52,8 +54,8 @@ static const uint32_t PQI_SSLUDP_DEF_CONN_PERIOD = 300; /* 5 minutes? */
|
||||||
|
|
||||||
/********** PQI SSL UDP STUFF **************************************/
|
/********** PQI SSL UDP STUFF **************************************/
|
||||||
|
|
||||||
pqissludp::pqissludp(PQInterface *parent, p3ConnectMgr *cm)
|
pqissludp::pqissludp(PQInterface *parent, p3LinkMgr *lm)
|
||||||
:pqissl(NULL, parent, cm), tou_bio(NULL),
|
:pqissl(NULL, parent, lm), tou_bio(NULL),
|
||||||
listen_checktime(0), mConnectPeriod(PQI_SSLUDP_DEF_CONN_PERIOD)
|
listen_checktime(0), mConnectPeriod(PQI_SSLUDP_DEF_CONN_PERIOD)
|
||||||
{
|
{
|
||||||
sockaddr_clear(&remote_addr);
|
sockaddr_clear(&remote_addr);
|
||||||
|
@ -129,7 +131,7 @@ int pqissludp::Initiate_Connection()
|
||||||
"pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
|
"pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
|
||||||
|
|
||||||
/* decide if we're active or passive */
|
/* decide if we're active or passive */
|
||||||
if (PeerId() < mConnMgr->getOwnId())
|
if (PeerId() < mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
sslmode = PQISSL_ACTIVE;
|
sslmode = PQISSL_ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class cert;
|
||||||
class pqissludp: public pqissl
|
class pqissludp: public pqissl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pqissludp(PQInterface *parent, p3ConnectMgr *cm);
|
pqissludp(PQInterface *parent, p3LinkMgr *lm);
|
||||||
|
|
||||||
virtual ~pqissludp();
|
virtual ~pqissludp();
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,38 @@ extern RsDht *rsDht;
|
||||||
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
|
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
|
||||||
|
|
||||||
|
|
||||||
#define RS_DHT_NETSTART_NETWORKMODE 0x0001
|
#define RSDHT_NETSTART_NETWORKMODE 0x0001
|
||||||
#define RS_DHT_NETSTART_NATTYPE 0x0002
|
#define RSDHT_NETSTART_NATTYPE 0x0002
|
||||||
#define RS_DHT_NETSTART_NATHOLE 0x0003
|
#define RSDHT_NETSTART_NATHOLE 0x0003
|
||||||
#define RS_DHT_NETSTART_CONNECTMODES 0x0004
|
#define RSDHT_NETSTART_CONNECTMODES 0x0004
|
||||||
#define RS_DHT_NETSTART_NETSTATE 0x0005
|
#define RSDHT_NETSTART_NETSTATE 0x0005
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define RSDHT_PEERTYPE_ANY 0x0000
|
||||||
|
#define RSDHT_PEERTYPE_OTHER 0x0001
|
||||||
|
#define RSDHT_PEERTYPE_FOF 0x0002
|
||||||
|
#define RSDHT_PEERTYPE_FRIEND 0x0003
|
||||||
|
|
||||||
|
#define RSDHT_PEERDHT_NOT_ACTIVE 0x0000
|
||||||
|
#define RSDHT_PEERDHT_SEARCHING 0x0001
|
||||||
|
#define RSDHT_PEERDHT_FAILURE 0x0002
|
||||||
|
#define RSDHT_PEERDHT_OFFLINE 0x0003
|
||||||
|
#define RSDHT_PEERDHT_UNREACHABLE 0x0004
|
||||||
|
#define RSDHT_PEERDHT_ONLINE 0x0005
|
||||||
|
|
||||||
|
#define RSDHT_PEERCONN_DISCONNECTED 1
|
||||||
|
#define RSDHT_PEERCONN_UDP_STARTED 2
|
||||||
|
#define RSDHT_PEERCONN_CONNECTED 3
|
||||||
|
|
||||||
|
#define RSDHT_PEERREQ_STOPPED 1
|
||||||
|
#define RSDHT_PEERREQ_RUNNING 2
|
||||||
|
|
||||||
|
#define RSDHT_TOU_MODE_DIRECT 1
|
||||||
|
#define RSDHT_TOU_MODE_PROXY 2
|
||||||
|
#define RSDHT_TOU_MODE_RELAY 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RsDhtPeer
|
class RsDhtPeer
|
||||||
{
|
{
|
||||||
|
@ -68,6 +95,7 @@ class RsDhtNetPeer
|
||||||
std::string mDhtId;
|
std::string mDhtId;
|
||||||
std::string mRsId;
|
std::string mRsId;
|
||||||
|
|
||||||
|
uint32_t mDhtState;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsDhtRelayEnd
|
class RsDhtRelayEnd
|
||||||
|
|
|
@ -38,6 +38,9 @@ const int p3facemsgzone = 11453;
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* RsIface Config */
|
/* RsIface Config */
|
||||||
|
@ -106,18 +109,18 @@ int RsServer::UpdateAllConfig()
|
||||||
|
|
||||||
config.ownId = AuthSSL::getAuthSSL()->OwnId();
|
config.ownId = AuthSSL::getAuthSSL()->OwnId();
|
||||||
config.ownName = AuthGPG::getAuthGPG()->getGPGOwnName();
|
config.ownName = AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||||
peerConnectState pstate;
|
peerState pstate;
|
||||||
mConnMgr->getOwnNetStatus(pstate);
|
mPeerMgr->getOwnNetStatus(pstate);
|
||||||
|
|
||||||
/* ports */
|
/* ports */
|
||||||
config.localAddr = rs_inet_ntoa(pstate.currentlocaladdr.sin_addr);
|
config.localAddr = rs_inet_ntoa(pstate.localaddr.sin_addr);
|
||||||
config.localPort = ntohs(pstate.currentlocaladdr.sin_port);
|
config.localPort = ntohs(pstate.localaddr.sin_port);
|
||||||
|
|
||||||
config.firewalled = true;
|
config.firewalled = true;
|
||||||
config.forwardPort = true;
|
config.forwardPort = true;
|
||||||
|
|
||||||
config.extAddr = rs_inet_ntoa(pstate.currentserveraddr.sin_addr);
|
config.extAddr = rs_inet_ntoa(pstate.serveraddr.sin_addr);
|
||||||
config.extPort = ntohs(pstate.currentserveraddr.sin_port);
|
config.extPort = ntohs(pstate.serveraddr.sin_port);
|
||||||
|
|
||||||
/* data rates */
|
/* data rates */
|
||||||
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */
|
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */
|
||||||
|
@ -128,7 +131,7 @@ int RsServer::UpdateAllConfig()
|
||||||
/* update network configuration */
|
/* update network configuration */
|
||||||
|
|
||||||
pqiNetStatus status;
|
pqiNetStatus status;
|
||||||
mConnMgr->getNetStatus(status);
|
mNetMgr->getNetStatus(status);
|
||||||
|
|
||||||
config.netLocalOk = status.mLocalAddrOk;
|
config.netLocalOk = status.mLocalAddrOk;
|
||||||
config.netUpnpOk = status.mUpnpOk;
|
config.netUpnpOk = status.mUpnpOk;
|
||||||
|
@ -141,10 +144,10 @@ int RsServer::UpdateAllConfig()
|
||||||
|
|
||||||
/* update DHT/UPnP config */
|
/* update DHT/UPnP config */
|
||||||
|
|
||||||
config.uPnPState = mConnMgr->getUPnPState();
|
config.uPnPState = mNetMgr->getUPnPState();
|
||||||
config.uPnPActive = mConnMgr->getUPnPEnabled();
|
config.uPnPActive = mNetMgr->getUPnPEnabled();
|
||||||
config.DHTPeers = 20;
|
config.DHTPeers = 20;
|
||||||
config.DHTActive = mConnMgr->getDHTEnabled();
|
config.DHTActive = mNetMgr->getDHTEnabled();
|
||||||
|
|
||||||
/* Notify of Changes */
|
/* Notify of Changes */
|
||||||
// iface.setChanged(RsIface::Config);
|
// iface.setChanged(RsIface::Config);
|
||||||
|
@ -175,7 +178,7 @@ void RsServer::rsGlobalShutDown()
|
||||||
// TODO: cache should also clean up old files
|
// TODO: cache should also clean up old files
|
||||||
|
|
||||||
ConfigFinalSave(); // save configuration before exit
|
ConfigFinalSave(); // save configuration before exit
|
||||||
mConnMgr->shutdown(); /* Handles UPnP */
|
mNetMgr->shutdown(); /* Handles UPnP */
|
||||||
|
|
||||||
join();
|
join();
|
||||||
ftserver->StopThreads();
|
ftserver->StopThreads();
|
||||||
|
|
|
@ -35,6 +35,11 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
|
|
||||||
/****
|
/****
|
||||||
#define DEBUG_TICK 1
|
#define DEBUG_TICK 1
|
||||||
****/
|
****/
|
||||||
|
@ -44,7 +49,9 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
||||||
{
|
{
|
||||||
ftserver = NULL;
|
ftserver = NULL;
|
||||||
|
|
||||||
mConnMgr = NULL;
|
mPeerMgr = NULL;
|
||||||
|
mLinkMgr = NULL;
|
||||||
|
mNetMgr = NULL;
|
||||||
|
|
||||||
pqih = NULL;
|
pqih = NULL;
|
||||||
|
|
||||||
|
@ -144,8 +151,10 @@ void RsServer::run()
|
||||||
|
|
||||||
unlockRsCore();
|
unlockRsCore();
|
||||||
|
|
||||||
/* tick the connection Manager */
|
/* tick the Managers */
|
||||||
mConnMgr->tick();
|
mPeerMgr->tick();
|
||||||
|
mLinkMgr->tick();
|
||||||
|
mNetMgr->tick();
|
||||||
/******************************** RUN SERVER *****************/
|
/******************************** RUN SERVER *****************/
|
||||||
|
|
||||||
/* adjust tick rate depending on whether there is more.
|
/* adjust tick rate depending on whether there is more.
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
//#include "pqi/pqissl.h"
|
//#include "pqi/pqissl.h"
|
||||||
|
|
||||||
#include "pqi/p3cfgmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
|
|
||||||
#include "retroshare/rsiface.h"
|
#include "retroshare/rsiface.h"
|
||||||
|
@ -46,6 +45,11 @@
|
||||||
#include "services/p3channels.h"
|
#include "services/p3channels.h"
|
||||||
#include "services/p3forums.h"
|
#include "services/p3forums.h"
|
||||||
|
|
||||||
|
class p3PeerMgr;
|
||||||
|
class p3LinkMgr;
|
||||||
|
class p3NetMgr;
|
||||||
|
|
||||||
|
|
||||||
/* The Main Interface Class - for controlling the server */
|
/* The Main Interface Class - for controlling the server */
|
||||||
|
|
||||||
/* The init functions are actually Defined in p3face-startup.cc
|
/* The init functions are actually Defined in p3face-startup.cc
|
||||||
|
@ -150,7 +154,9 @@ class RsServer: public RsControl, public RsThread
|
||||||
//filedexserver *server;
|
//filedexserver *server;
|
||||||
ftServer *ftserver;
|
ftServer *ftserver;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3LinkMgr *mLinkMgr;
|
||||||
|
p3NetMgr *mNetMgr;
|
||||||
|
|
||||||
pqipersongrp *pqih;
|
pqipersongrp *pqih;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,11 @@
|
||||||
|
|
||||||
#include "rsserver/p3peers.h"
|
#include "rsserver/p3peers.h"
|
||||||
#include "rsserver/p3face.h"
|
#include "rsserver/p3face.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
#include "pqi/authgpg.h"
|
#include "pqi/authgpg.h"
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
|
@ -123,8 +127,8 @@ std::string RsPeerLastConnectString(uint32_t lastConnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p3Peers::p3Peers(p3ConnectMgr *cm)
|
p3Peers::p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm)
|
||||||
:mConnMgr(cm)
|
:mLinkMgr(lm), mPeerMgr(pm), mNetMgr(nm)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +180,7 @@ bool p3Peers::getOnlineList(std::list<std::string> &ids)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* get from mConnectMgr */
|
/* get from mConnectMgr */
|
||||||
mConnMgr->getOnlineList(ids);
|
mLinkMgr->getOnlineList(ids);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +191,7 @@ bool p3Peers::getFriendList(std::list<std::string> &ids)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* get from mConnectMgr */
|
/* get from mConnectMgr */
|
||||||
mConnMgr->getFriendList(ids);
|
mLinkMgr->getFriendList(ids);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +212,15 @@ bool p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineC
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
// This is no longer accurate!
|
||||||
|
*pnFriendCount = mLinkMgr->getFriendCount();
|
||||||
|
*pnOnlineCount = mLinkMgr->getOnlineCount();
|
||||||
|
|
||||||
/* get from mConnectMgr */
|
/* get from mConnectMgr */
|
||||||
return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
|
//return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::isOnline(const std::string &id)
|
bool p3Peers::isOnline(const std::string &id)
|
||||||
|
@ -221,7 +231,7 @@ bool p3Peers::isOnline(const std::string &id)
|
||||||
|
|
||||||
/* get from mConnectMgr */
|
/* get from mConnectMgr */
|
||||||
peerConnectState state;
|
peerConnectState state;
|
||||||
if (mConnMgr->getFriendNetStatus(id, state) &&
|
if (mLinkMgr->getFriendNetStatus(id, state) &&
|
||||||
(state.state & RS_PEER_S_CONNECTED))
|
(state.state & RS_PEER_S_CONNECTED))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -236,23 +246,9 @@ bool p3Peers::isFriend(const std::string &ssl_id)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* get from mConnectMgr */
|
/* get from mConnectMgr */
|
||||||
return mConnMgr->isFriend(ssl_id);
|
return mPeerMgr->isFriend(ssl_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static struct sockaddr_in getPreferredAddress( const struct sockaddr_in& addr1,time_t ts1,
|
|
||||||
const struct sockaddr_in& addr2,time_t ts2,
|
|
||||||
const struct sockaddr_in& addr3,time_t ts3)
|
|
||||||
{
|
|
||||||
time_t ts = ts1 ;
|
|
||||||
struct sockaddr_in addr = addr1 ;
|
|
||||||
|
|
||||||
if(ts2 > ts && strcmp(rs_inet_ntoa(addr2.sin_addr),"0.0.0.0")) { ts = ts2 ; addr = addr2 ; }
|
|
||||||
if(ts3 > ts && strcmp(rs_inet_ntoa(addr3.sin_addr),"0.0.0.0")) { ts = ts3 ; addr = addr3 ; }
|
|
||||||
|
|
||||||
return addr ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||||
{
|
{
|
||||||
|
@ -261,8 +257,8 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||||
#endif
|
#endif
|
||||||
//first, check if it's a gpg or a ssl id.
|
//first, check if it's a gpg or a ssl id.
|
||||||
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||||
peerConnectState pcs;
|
peerState ps;
|
||||||
if (id != sOwnId && !mConnMgr->getFriendNetStatus(id, pcs)) {
|
if (id != sOwnId && !mPeerMgr->getFriendNetStatus(id, ps)) {
|
||||||
//assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr
|
//assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getPeerDetails() got a gpg id and is returning GPG details only for id : " << id << std::endl;
|
std::cerr << "p3Peers::getPeerDetails() got a gpg id and is returning GPG details only for id : " << id << std::endl;
|
||||||
|
@ -275,62 +271,51 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (id == sOwnId) {
|
if (id == sOwnId) {
|
||||||
mConnMgr->getOwnNetStatus(pcs);
|
mPeerMgr->getOwnNetStatus(ps);
|
||||||
pcs.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
ps.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get from gpg (first), to fill in the sign and trust details */
|
/* get from gpg (first), to fill in the sign and trust details */
|
||||||
/* don't retrun now, we've got fill in the ssl and connection info */
|
/* don't retrun now, we've got fill in the ssl and connection info */
|
||||||
this->getGPGDetails(pcs.gpg_id, d);
|
this->getGPGDetails(ps.gpg_id, d);
|
||||||
d.isOnlyGPGdetail = false;
|
d.isOnlyGPGdetail = false;
|
||||||
|
|
||||||
//get the ssl details
|
//get the ssl details
|
||||||
d.id = id;
|
d.id = id;
|
||||||
d.location = pcs.location;
|
d.location = ps.location;
|
||||||
|
|
||||||
/* generate */
|
/* generate */
|
||||||
d.authcode = "AUTHCODE";
|
d.authcode = "AUTHCODE";
|
||||||
|
|
||||||
/* fill from pcs */
|
/* fill from pcs */
|
||||||
|
|
||||||
d.localAddr = rs_inet_ntoa(pcs.currentlocaladdr.sin_addr);
|
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
|
||||||
d.localPort = ntohs(pcs.currentlocaladdr.sin_port);
|
d.localPort = ntohs(ps.localaddr.sin_port);
|
||||||
d.extAddr = rs_inet_ntoa(pcs.currentserveraddr.sin_addr);
|
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
|
||||||
d.extPort = ntohs(pcs.currentserveraddr.sin_port);
|
d.extPort = ntohs(ps.serveraddr.sin_port);
|
||||||
d.dyndns = pcs.dyndns;
|
d.dyndns = ps.dyndns;
|
||||||
d.lastConnect = pcs.lastcontact;
|
d.lastConnect = ps.lastcontact;
|
||||||
d.connectPeriod = 0;
|
d.connectPeriod = 0;
|
||||||
|
|
||||||
|
|
||||||
std::list<pqiIpAddress>::iterator it;
|
std::list<pqiIpAddress>::iterator it;
|
||||||
for(it = pcs.ipAddrs.mLocal.mAddrs.begin();
|
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||||
it != pcs.ipAddrs.mLocal.mAddrs.end(); it++)
|
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||||
{
|
{
|
||||||
std::ostringstream toto;
|
std::ostringstream toto;
|
||||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||||
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
d.ipAddressList.push_back("L:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||||
}
|
}
|
||||||
for(it = pcs.ipAddrs.mExt.mAddrs.begin();
|
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||||
it != pcs.ipAddrs.mExt.mAddrs.end(); it++)
|
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||||
{
|
{
|
||||||
std::ostringstream toto;
|
std::ostringstream toto;
|
||||||
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
toto << ntohs(it->mAddr.sin_port) << " " << (time(NULL) - it->mSeenTime) << " sec";
|
||||||
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
d.ipAddressList.push_back("E:" + std::string(rs_inet_ntoa(it->mAddr.sin_addr)) + ":" + toto.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate */
|
|
||||||
|
|
||||||
d.state = 0;
|
switch(ps.netMode & RS_NET_MODE_ACTUAL)
|
||||||
if (pcs.state & RS_PEER_S_FRIEND)
|
|
||||||
d.state |= RS_PEER_STATE_FRIEND;
|
|
||||||
if (pcs.state & RS_PEER_S_ONLINE)
|
|
||||||
d.state |= RS_PEER_STATE_ONLINE;
|
|
||||||
if (pcs.state & RS_PEER_S_CONNECTED)
|
|
||||||
d.state |= RS_PEER_STATE_CONNECTED;
|
|
||||||
if (pcs.state & RS_PEER_S_UNREACHABLE)
|
|
||||||
d.state |= RS_PEER_STATE_UNREACHABLE;
|
|
||||||
|
|
||||||
switch(pcs.netMode & RS_NET_MODE_ACTUAL)
|
|
||||||
{
|
{
|
||||||
case RS_NET_MODE_EXT:
|
case RS_NET_MODE_EXT:
|
||||||
d.netMode = RS_NETMODE_EXT;
|
d.netMode = RS_NETMODE_EXT;
|
||||||
|
@ -348,11 +333,12 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pcs.netMode & RS_NET_MODE_TRY_EXT)
|
|
||||||
|
if (ps.netMode & RS_NET_MODE_TRY_EXT)
|
||||||
{
|
{
|
||||||
d.tryNetMode = RS_NETMODE_EXT;
|
d.tryNetMode = RS_NETMODE_EXT;
|
||||||
}
|
}
|
||||||
else if (pcs.netMode & RS_NET_MODE_TRY_UPNP)
|
else if (ps.netMode & RS_NET_MODE_TRY_UPNP)
|
||||||
{
|
{
|
||||||
d.tryNetMode = RS_NETMODE_UPNP;
|
d.tryNetMode = RS_NETMODE_UPNP;
|
||||||
}
|
}
|
||||||
|
@ -362,17 +348,44 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.visState = 0;
|
d.visState = 0;
|
||||||
if (!(pcs.visState & RS_VIS_STATE_NODISC))
|
if (!(ps.visState & RS_VIS_STATE_NODISC))
|
||||||
{
|
{
|
||||||
d.visState |= RS_VS_DISC_ON;
|
d.visState |= RS_VS_DISC_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pcs.visState & RS_VIS_STATE_NODHT))
|
if (!(ps.visState & RS_VIS_STATE_NODHT))
|
||||||
{
|
{
|
||||||
d.visState |= RS_VS_DHT_ON;
|
d.visState |= RS_VS_DHT_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Translate */
|
||||||
|
peerConnectState pcs;
|
||||||
|
if (!mLinkMgr->getFriendNetStatus(id, pcs))
|
||||||
|
{
|
||||||
|
std::cerr << "p3Peers::getPeerDetails() ERROR No Link Information : " << id << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef P3PEERS_DEBUG
|
||||||
|
std::cerr << "p3Peers::getPeerDetails() got a SSL id and is returning SSL and GPG details for id : " << id << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
d.state = 0;
|
||||||
|
if (pcs.state & RS_PEER_S_FRIEND)
|
||||||
|
d.state |= RS_PEER_STATE_FRIEND;
|
||||||
|
if (pcs.state & RS_PEER_S_ONLINE)
|
||||||
|
d.state |= RS_PEER_STATE_ONLINE;
|
||||||
|
if (pcs.state & RS_PEER_S_CONNECTED)
|
||||||
|
d.state |= RS_PEER_STATE_CONNECTED;
|
||||||
|
if (pcs.state & RS_PEER_S_UNREACHABLE)
|
||||||
|
d.state |= RS_PEER_STATE_UNREACHABLE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Finally determine AutoConnect Status */
|
/* Finally determine AutoConnect Status */
|
||||||
d.foundDHT = pcs.dht.found;
|
d.foundDHT = pcs.dht.found;
|
||||||
|
|
||||||
|
@ -443,8 +456,8 @@ std::string p3Peers::getPeerName(const std::string &ssl_or_gpg_id)
|
||||||
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId()) {
|
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId()) {
|
||||||
return AuthGPG::getAuthGPG()->getGPGOwnName();
|
return AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||||
}
|
}
|
||||||
peerConnectState pcs;
|
peerState pcs;
|
||||||
if (mConnMgr->getFriendNetStatus(ssl_or_gpg_id, pcs)) {
|
if (mPeerMgr->getFriendNetStatus(ssl_or_gpg_id, pcs)) {
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << pcs.name << std::endl;
|
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << pcs.name << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -507,14 +520,14 @@ bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::s
|
||||||
}
|
}
|
||||||
//let's roll throush the friends
|
//let's roll throush the friends
|
||||||
std::list<std::string> friendsIds;
|
std::list<std::string> friendsIds;
|
||||||
mConnMgr->getFriendList(friendsIds);
|
mLinkMgr->getFriendList(friendsIds);
|
||||||
peerConnectState pcs;
|
peerState pcs;
|
||||||
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++)
|
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (mConnMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
if (mPeerMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -528,16 +541,16 @@ bool p3Peers::cleanUnusedLocations()
|
||||||
{
|
{
|
||||||
// Obtain all current locations of each GPG friend.
|
// Obtain all current locations of each GPG friend.
|
||||||
//
|
//
|
||||||
std::map<std::string,std::list<peerConnectState> > friends_info ;
|
std::map<std::string,std::list<peerState> > friends_info ;
|
||||||
std::list<std::string> friendSSLIds ;
|
std::list<std::string> friendSSLIds ;
|
||||||
|
|
||||||
mConnMgr->getFriendList(friendSSLIds);
|
mLinkMgr->getFriendList(friendSSLIds);
|
||||||
|
|
||||||
for(std::list<std::string>::const_iterator it(friendSSLIds.begin());it!=friendSSLIds.end();++it)
|
for(std::list<std::string>::const_iterator it(friendSSLIds.begin());it!=friendSSLIds.end();++it)
|
||||||
{
|
{
|
||||||
peerConnectState pcs;
|
peerState pcs;
|
||||||
|
|
||||||
if(mConnMgr->getFriendNetStatus(*it, pcs))
|
if(mPeerMgr->getFriendNetStatus(*it, pcs))
|
||||||
friends_info[pcs.gpg_id].push_back(pcs) ;
|
friends_info[pcs.gpg_id].push_back(pcs) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,20 +562,20 @@ bool p3Peers::cleanUnusedLocations()
|
||||||
|
|
||||||
std::list<std::string> locations_to_remove ;
|
std::list<std::string> locations_to_remove ;
|
||||||
|
|
||||||
for(std::map<std::string,std::list<peerConnectState> >::iterator it(friends_info.begin());it!=friends_info.end();++it)
|
for(std::map<std::string,std::list<peerState> >::iterator it(friends_info.begin());it!=friends_info.end();++it)
|
||||||
{
|
{
|
||||||
std::list<peerConnectState>& locations_list(it->second) ;
|
std::list<peerState>& locations_list(it->second) ;
|
||||||
|
|
||||||
int size = locations_list.size() ;
|
int size = locations_list.size() ;
|
||||||
|
|
||||||
std::cerr << " GPG id: " << it->first << std::endl ;
|
std::cerr << " GPG id: " << it->first << std::endl ;
|
||||||
|
|
||||||
for(std::list<peerConnectState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
for(std::list<peerState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||||
std::cerr << " Location " << (*itloc).id << ", last contact " << now - (*itloc).lastcontact << " seconds ago" << std::endl ;
|
std::cerr << " Location " << (*itloc).id << ", last contact " << now - (*itloc).lastcontact << " seconds ago" << std::endl ;
|
||||||
|
|
||||||
// Remove any location that is dummy. Update the list, such that we only look into non dummy friends later.
|
// Remove any location that is dummy. Update the list, such that we only look into non dummy friends later.
|
||||||
//
|
//
|
||||||
for(std::list<peerConnectState>::iterator itloc(locations_list.begin());itloc!=locations_list.end();)
|
for(std::list<peerState>::iterator itloc(locations_list.begin());itloc!=locations_list.end();)
|
||||||
if(size > 1 && isDummyFriend((*itloc).id))
|
if(size > 1 && isDummyFriend((*itloc).id))
|
||||||
{
|
{
|
||||||
locations_to_remove.push_back((*itloc).id) ;
|
locations_to_remove.push_back((*itloc).id) ;
|
||||||
|
@ -570,7 +583,7 @@ bool p3Peers::cleanUnusedLocations()
|
||||||
|
|
||||||
std::cerr << " Removing dummy location: " << (*itloc).id << std::endl ;
|
std::cerr << " Removing dummy location: " << (*itloc).id << std::endl ;
|
||||||
|
|
||||||
std::list<peerConnectState>::iterator tmp(itloc) ;
|
std::list<peerState>::iterator tmp(itloc) ;
|
||||||
++tmp ;
|
++tmp ;
|
||||||
locations_list.erase(itloc) ;
|
locations_list.erase(itloc) ;
|
||||||
itloc=tmp ;
|
itloc=tmp ;
|
||||||
|
@ -578,7 +591,7 @@ bool p3Peers::cleanUnusedLocations()
|
||||||
else
|
else
|
||||||
++itloc ;
|
++itloc ;
|
||||||
|
|
||||||
for(std::list<peerConnectState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
for(std::list<peerState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||||
if(size > 1 && now > (*itloc).lastcontact + MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT)
|
if(size > 1 && now > (*itloc).lastcontact + MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT)
|
||||||
{
|
{
|
||||||
locations_to_remove.push_back((*itloc).id) ;
|
locations_to_remove.push_back((*itloc).id) ;
|
||||||
|
@ -628,8 +641,8 @@ std::string p3Peers::getGPGId(const std::string &sslid_or_gpgid)
|
||||||
if (sslid_or_gpgid == AuthSSL::getAuthSSL()->OwnId()) {
|
if (sslid_or_gpgid == AuthSSL::getAuthSSL()->OwnId()) {
|
||||||
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||||
}
|
}
|
||||||
peerConnectState pcs;
|
peerState pcs;
|
||||||
if (mConnMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mConnMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
if (mPeerMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mPeerMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
||||||
return pcs.gpg_id;
|
return pcs.gpg_id;
|
||||||
} else {
|
} else {
|
||||||
if ( AuthGPG::getAuthGPG()->isGPGId(sslid_or_gpgid)) {
|
if ( AuthGPG::getAuthGPG()->isGPGId(sslid_or_gpgid)) {
|
||||||
|
@ -653,7 +666,7 @@ bool p3Peers::addFriend(const std::string &id, const std::string &gpg_id)
|
||||||
if (id == gpg_id || id == "") {
|
if (id == gpg_id || id == "") {
|
||||||
return addDummyFriend(gpg_id);
|
return addDummyFriend(gpg_id);
|
||||||
} else {
|
} else {
|
||||||
return mConnMgr->addFriend(id, gpg_id);
|
return mPeerMgr->addFriend(id, gpg_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,8 +677,8 @@ bool p3Peers::addDummyFriend(const std::string &gpg_id)
|
||||||
#endif
|
#endif
|
||||||
std::string dummy_ssl_id = "dummy"+ gpg_id;
|
std::string dummy_ssl_id = "dummy"+ gpg_id;
|
||||||
//check if this gpg_id already got a dummy friend
|
//check if this gpg_id already got a dummy friend
|
||||||
if (!mConnMgr->isFriend(dummy_ssl_id)) {
|
if (!mPeerMgr->isFriend(dummy_ssl_id)) {
|
||||||
return mConnMgr->addFriend(dummy_ssl_id, gpg_id);
|
return mPeerMgr->addFriend(dummy_ssl_id, gpg_id);
|
||||||
} else {
|
} else {
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::addDummyFriend() dummy friend already exists for gpg_id : " << gpg_id << std::endl;
|
std::cerr << "p3Peers::addDummyFriend() dummy friend already exists for gpg_id : " << gpg_id << std::endl;
|
||||||
|
@ -706,7 +719,7 @@ bool p3Peers::removeFriend(const std::string &ssl_or_gpgid)
|
||||||
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(ssl_or_gpgid, false);
|
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(ssl_or_gpgid, false);
|
||||||
|
|
||||||
//will remove if it's a ssl id
|
//will remove if it's a ssl id
|
||||||
mConnMgr->removeFriend(ssl_or_gpgid);
|
mPeerMgr->removeFriend(ssl_or_gpgid);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -718,16 +731,16 @@ bool p3Peers::connectAttempt(const std::string &id)
|
||||||
std::cerr << "p3Peers::connectAttempt() " << id << std::endl;
|
std::cerr << "p3Peers::connectAttempt() " << id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->retryConnect(id);
|
return mLinkMgr->retryConnect(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3Peers::getIPServersList(std::list<std::string>& ip_servers)
|
void p3Peers::getIPServersList(std::list<std::string>& ip_servers)
|
||||||
{
|
{
|
||||||
mConnMgr->getIPServersList(ip_servers) ;
|
mNetMgr->getIPServersList(ip_servers) ;
|
||||||
}
|
}
|
||||||
void p3Peers::allowServerIPDetermination(bool b)
|
void p3Peers::allowServerIPDetermination(bool b)
|
||||||
{
|
{
|
||||||
mConnMgr->setIPServersEnabled(b) ;
|
mNetMgr->setIPServersEnabled(b) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3Peers::allowTunnelConnection(bool b)
|
void p3Peers::allowTunnelConnection(bool b)
|
||||||
|
@ -735,12 +748,12 @@ void p3Peers::allowTunnelConnection(bool b)
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mConnMgr->setTunnelConnection(b) ;
|
mLinkMgr->setTunnelConnection(b) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::getAllowServerIPDetermination()
|
bool p3Peers::getAllowServerIPDetermination()
|
||||||
{
|
{
|
||||||
return mConnMgr->getIPServersEnabled() ;
|
return mNetMgr->getIPServersEnabled() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::getAllowTunnelConnection()
|
bool p3Peers::getAllowTunnelConnection()
|
||||||
|
@ -748,7 +761,7 @@ bool p3Peers::getAllowTunnelConnection()
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return mConnMgr->getTunnelConnection() ;
|
return mLinkMgr->getTunnelConnection() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
||||||
|
@ -771,7 +784,7 @@ bool p3Peers::setLocalAddress(const std::string &id, const std::string &addr_st
|
||||||
#endif
|
#endif
|
||||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||||
{
|
{
|
||||||
return mConnMgr->setLocalAddress(id, addr);
|
return mPeerMgr->setLocalAddress(id, addr);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -782,7 +795,7 @@ bool p3Peers::setLocation(const std::string &ssl_id, const std::string &locatio
|
||||||
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
|
std::cerr << "p3Peers::setLocation() " << ssl_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->setLocation(ssl_id, location);
|
return mPeerMgr->setLocation(ssl_id, location);
|
||||||
}
|
}
|
||||||
bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str, uint16_t port)
|
||||||
{
|
{
|
||||||
|
@ -804,7 +817,7 @@ bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str,
|
||||||
#endif
|
#endif
|
||||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||||
{
|
{
|
||||||
return mConnMgr->setExtAddress(id, addr);
|
return mPeerMgr->setExtAddress(id, addr);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -814,7 +827,7 @@ bool p3Peers::setDynDNS(const std::string &id, const std::string &dyndns)
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::setDynDNS() called with id: " << id << " dyndns: " << dyndns <<std::endl;
|
std::cerr << "p3Peers::setDynDNS() called with id: " << id << " dyndns: " << dyndns <<std::endl;
|
||||||
#endif
|
#endif
|
||||||
return mConnMgr->setDynDNS(id, dyndns);
|
return mPeerMgr->setDynDNS(id, dyndns);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
|
bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
|
||||||
|
@ -843,7 +856,7 @@ bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mConnMgr->setNetworkMode(id, netMode);
|
return mPeerMgr->setNetworkMode(id, netMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -861,7 +874,7 @@ p3Peers::setVisState(const std::string &id, uint32_t extVisState)
|
||||||
if (!(extVisState & RS_VS_DISC_ON))
|
if (!(extVisState & RS_VS_DISC_ON))
|
||||||
visState |= RS_VIS_STATE_NODISC;
|
visState |= RS_VIS_STATE_NODISC;
|
||||||
|
|
||||||
return mConnMgr->setVisState(id, visState);
|
return mPeerMgr->setVisState(id, visState);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -1189,7 +1202,7 @@ bool p3Peers::setAcceptToConnectGPGCertificate(const std::string &gpg_id, bool
|
||||||
std::list<std::string> sslFriends;
|
std::list<std::string> sslFriends;
|
||||||
this->getSSLChildListOfGPGId(gpg_id, sslFriends);
|
this->getSSLChildListOfGPGId(gpg_id, sslFriends);
|
||||||
for (std::list<std::string>::iterator it = sslFriends.begin(); it != sslFriends.end(); it++) {
|
for (std::list<std::string>::iterator it = sslFriends.begin(); it != sslFriends.end(); it++) {
|
||||||
mConnMgr->removeFriend(*it);
|
mPeerMgr->removeFriend(*it);
|
||||||
}
|
}
|
||||||
return AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(gpg_id, acceptance);
|
return AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(gpg_id, acceptance);
|
||||||
}
|
}
|
||||||
|
@ -1253,7 +1266,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
|
||||||
std::cerr << "p3Peers::addGroup()" << std::endl;
|
std::cerr << "p3Peers::addGroup()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->addGroup(groupInfo);
|
return mPeerMgr->addGroup(groupInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||||
|
@ -1262,7 +1275,7 @@ bool p3Peers::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||||
std::cerr << "p3Peers::editGroup()" << std::endl;
|
std::cerr << "p3Peers::editGroup()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->editGroup(groupId, groupInfo);
|
return mPeerMgr->editGroup(groupId, groupInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::removeGroup(const std::string &groupId)
|
bool p3Peers::removeGroup(const std::string &groupId)
|
||||||
|
@ -1271,7 +1284,7 @@ bool p3Peers::removeGroup(const std::string &groupId)
|
||||||
std::cerr << "p3Peers::removeGroup()" << std::endl;
|
std::cerr << "p3Peers::removeGroup()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->removeGroup(groupId);
|
return mPeerMgr->removeGroup(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||||
|
@ -1280,7 +1293,7 @@ bool p3Peers::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
|
||||||
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
|
std::cerr << "p3Peers::getGroupInfo()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->getGroupInfo(groupId, groupInfo);
|
return mPeerMgr->getGroupInfo(groupId, groupInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||||
|
@ -1289,7 +1302,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||||
std::cerr << "p3Peers::getGroupInfoList()" << std::endl;
|
std::cerr << "p3Peers::getGroupInfoList()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->getGroupInfoList(groupInfoList);
|
return mPeerMgr->getGroupInfoList(groupInfoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Peers::assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign)
|
bool p3Peers::assignPeerToGroup(const std::string &groupId, const std::string &peerId, bool assign)
|
||||||
|
@ -1306,7 +1319,7 @@ bool p3Peers::assignPeersToGroup(const std::string &groupId, const std::list<std
|
||||||
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;
|
std::cerr << "p3Peers::assignPeersToGroup()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mConnMgr->assignPeersToGroup(groupId, peerIds, assign);
|
return mPeerMgr->assignPeersToGroup(groupId, peerIds, assign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "retroshare/rspeers.h"
|
#include "retroshare/rspeers.h"
|
||||||
#include "pqi/p3connmgr.h"
|
class p3LinkMgr;
|
||||||
|
class p3PeerMgr;
|
||||||
|
class p3NetMgr;
|
||||||
|
|
||||||
|
|
||||||
class p3Peers: public RsPeers
|
class p3Peers: public RsPeers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3Peers(p3ConnectMgr *cm);
|
p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm);
|
||||||
virtual ~p3Peers() { return; }
|
virtual ~p3Peers() { return; }
|
||||||
|
|
||||||
/* Updates ... */
|
/* Updates ... */
|
||||||
|
@ -115,7 +118,10 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3NetMgr *mNetMgr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1735,9 +1735,15 @@ RsTurtle *rsTurtle = NULL ;
|
||||||
|
|
||||||
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
#include "pqi/p3netmgr.h"
|
||||||
|
|
||||||
|
|
||||||
#include "tcponudp/tou.h"
|
#include "tcponudp/tou.h"
|
||||||
#include "tcponudp/rsudpstack.h"
|
#include "tcponudp/rsudpstack.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef RS_USE_BITDHT
|
#ifdef RS_USE_BITDHT
|
||||||
#include "dht/p3bitdht.h"
|
#include "dht/p3bitdht.h"
|
||||||
#include "udp/udpstack.h"
|
#include "udp/udpstack.h"
|
||||||
|
@ -1823,7 +1829,11 @@ int RsServer::StartupRetroShare()
|
||||||
/* Setup Notify Early - So we can use it. */
|
/* Setup Notify Early - So we can use it. */
|
||||||
rsNotify = new p3Notify();
|
rsNotify = new p3Notify();
|
||||||
|
|
||||||
mConnMgr = new p3ConnectMgr();
|
mPeerMgr = new p3PeerMgr();
|
||||||
|
mNetMgr = new p3NetMgr();
|
||||||
|
mLinkMgr = new p3LinkMgr(mPeerMgr, mNetMgr);
|
||||||
|
|
||||||
|
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
|
||||||
|
|
||||||
//load all the SSL certs as friends
|
//load all the SSL certs as friends
|
||||||
// std::list<std::string> sslIds;
|
// std::list<std::string> sslIds;
|
||||||
|
@ -1899,7 +1909,7 @@ int RsServer::StartupRetroShare()
|
||||||
mUdpStack->addReceiver(mDhtStunner);
|
mUdpStack->addReceiver(mDhtStunner);
|
||||||
|
|
||||||
// NEXT BITDHT.
|
// NEXT BITDHT.
|
||||||
p3BitDht *mBitDht = new p3BitDht(ownId, mConnMgr, mUdpStack, bootstrapfile);
|
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mUdpStack, bootstrapfile);
|
||||||
/* install external Pointer for Interface */
|
/* install external Pointer for Interface */
|
||||||
rsDht = mBitDht;
|
rsDht = mBitDht;
|
||||||
|
|
||||||
|
@ -1956,7 +1966,7 @@ int RsServer::StartupRetroShare()
|
||||||
//pqih = new pqipersongrpDummy(none, flags);
|
//pqih = new pqipersongrpDummy(none, flags);
|
||||||
|
|
||||||
/****** New Ft Server **** !!! */
|
/****** New Ft Server **** !!! */
|
||||||
ftserver = new ftServer(mConnMgr);
|
ftserver = new ftServer(mLinkMgr);
|
||||||
ftserver->setP3Interface(pqih);
|
ftserver->setP3Interface(pqih);
|
||||||
ftserver->setConfigDirectory(RsInitConfig::configDir);
|
ftserver->setConfigDirectory(RsInitConfig::configDir);
|
||||||
|
|
||||||
|
@ -1970,6 +1980,7 @@ int RsServer::StartupRetroShare()
|
||||||
|
|
||||||
/* This should be set by config ... there is no default */
|
/* This should be set by config ... there is no default */
|
||||||
//ftserver->setSharedDirectories(fileList);
|
//ftserver->setSharedDirectories(fileList);
|
||||||
|
|
||||||
rsFiles = ftserver;
|
rsFiles = ftserver;
|
||||||
|
|
||||||
|
|
||||||
|
@ -2013,11 +2024,11 @@ int RsServer::StartupRetroShare()
|
||||||
mPluginsManager->loadPlugins(plugins_directories) ;
|
mPluginsManager->loadPlugins(plugins_directories) ;
|
||||||
|
|
||||||
/* create Services */
|
/* create Services */
|
||||||
ad = new p3disc(mConnMgr, pqih);
|
ad = new p3disc(mLinkMgr, pqih);
|
||||||
#ifndef MINIMAL_LIBRS
|
#ifndef MINIMAL_LIBRS
|
||||||
msgSrv = new p3MsgService(mConnMgr);
|
msgSrv = new p3MsgService(mLinkMgr);
|
||||||
chatSrv = new p3ChatService(mConnMgr);
|
chatSrv = new p3ChatService(mLinkMgr);
|
||||||
mStatusSrv = new p3StatusService(mConnMgr);
|
mStatusSrv = new p3StatusService(mLinkMgr);
|
||||||
#endif // MINIMAL_LIBRS
|
#endif // MINIMAL_LIBRS
|
||||||
|
|
||||||
#ifndef PQI_DISABLE_TUNNEL
|
#ifndef PQI_DISABLE_TUNNEL
|
||||||
|
@ -2026,7 +2037,7 @@ int RsServer::StartupRetroShare()
|
||||||
mConnMgr->setP3tunnel(tn);
|
mConnMgr->setP3tunnel(tn);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
p3turtle *tr = new p3turtle(mConnMgr,ftserver) ;
|
p3turtle *tr = new p3turtle(mLinkMgr,ftserver) ;
|
||||||
rsTurtle = tr ;
|
rsTurtle = tr ;
|
||||||
pqih -> addService(tr);
|
pqih -> addService(tr);
|
||||||
ftserver->connectToTurtleRouter(tr) ;
|
ftserver->connectToTurtleRouter(tr) ;
|
||||||
|
@ -2064,7 +2075,7 @@ int RsServer::StartupRetroShare()
|
||||||
mPluginsManager->registerCacheServices() ;
|
mPluginsManager->registerCacheServices() ;
|
||||||
|
|
||||||
#ifndef RS_RELEASE
|
#ifndef RS_RELEASE
|
||||||
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
|
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
|
||||||
pqih -> addService(gameLauncher);
|
pqih -> addService(gameLauncher);
|
||||||
|
|
||||||
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
|
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
|
||||||
|
@ -2079,26 +2090,26 @@ int RsServer::StartupRetroShare()
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifdef RS_USE_BITDHT
|
#ifdef RS_USE_BITDHT
|
||||||
mConnMgr->addNetAssistConnect(1, mBitDht);
|
mNetMgr->addNetAssistConnect(1, mBitDht);
|
||||||
mConnMgr->addNetListener(mUdpStack);
|
mNetMgr->addNetListener(mUdpStack);
|
||||||
#endif
|
#endif
|
||||||
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
|
mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* need to Monitor too! */
|
/* need to Monitor too! */
|
||||||
mConnMgr->addMonitor(pqih);
|
mLinkMgr->addMonitor(pqih);
|
||||||
mConnMgr->addMonitor(mCacheStrapper);
|
mLinkMgr->addMonitor(mCacheStrapper);
|
||||||
mConnMgr->addMonitor(ad);
|
mLinkMgr->addMonitor(ad);
|
||||||
#ifndef MINIMAL_LIBRS
|
#ifndef MINIMAL_LIBRS
|
||||||
mConnMgr->addMonitor(msgSrv);
|
mLinkMgr->addMonitor(msgSrv);
|
||||||
mConnMgr->addMonitor(mStatusSrv);
|
mLinkMgr->addMonitor(mStatusSrv);
|
||||||
mConnMgr->addMonitor(chatSrv);
|
mLinkMgr->addMonitor(chatSrv);
|
||||||
#endif // MINIMAL_LIBRS
|
#endif // MINIMAL_LIBRS
|
||||||
|
|
||||||
/* must also add the controller as a Monitor...
|
/* must also add the controller as a Monitor...
|
||||||
* a little hack to get it to work.
|
* a little hack to get it to work.
|
||||||
*/
|
*/
|
||||||
mConnMgr->addMonitor(((ftController *) mCacheTransfer));
|
mLinkMgr->addMonitor(((ftController *) mCacheTransfer));
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "pqi/pqibin.h"
|
#include "pqi/pqibin.h"
|
||||||
#include "pqi/pqinotify.h"
|
#include "pqi/pqinotify.h"
|
||||||
#include "pqi/pqistore.h"
|
#include "pqi/pqistore.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "services/p3chatservice.h"
|
#include "services/p3chatservice.h"
|
||||||
|
|
||||||
|
@ -41,8 +42,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
p3ChatService::p3ChatService(p3LinkMgr *lm)
|
||||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mConnMgr(cm)
|
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm)
|
||||||
{
|
{
|
||||||
addSerialType(new RsChatSerialiser());
|
addSerialType(new RsChatSerialiser());
|
||||||
|
|
||||||
|
@ -72,10 +73,10 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
|
||||||
|
|
||||||
std::list<std::string> ids;
|
std::list<std::string> ids;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
mConnMgr->getOnlineList(ids);
|
mLinkMgr->getOnlineList(ids);
|
||||||
|
|
||||||
/* add in own id -> so get reflection */
|
/* add in own id -> so get reflection */
|
||||||
ids.push_back(mConnMgr->getOwnId());
|
ids.push_back(mLinkMgr->getOwnId());
|
||||||
|
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
std::cerr << "p3ChatService::sendChat()";
|
std::cerr << "p3ChatService::sendChat()";
|
||||||
|
@ -156,7 +157,7 @@ class p3ChatService::AvatarInfo
|
||||||
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
||||||
{
|
{
|
||||||
std::list<std::string> ids;
|
std::list<std::string> ids;
|
||||||
mConnMgr->getOnlineList(ids);
|
mLinkMgr->getOnlineList(ids);
|
||||||
|
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
std::cerr << "p3ChatService::sendChat(): sending group chat status string: " << status_string << std::endl ;
|
std::cerr << "p3ChatService::sendChat(): sending group chat status string: " << status_string << std::endl ;
|
||||||
|
@ -235,7 +236,7 @@ bool p3ChatService::sendPrivateChat(std::string &id, std::wstring &msg)
|
||||||
ci->recvTime = ci->sendTime;
|
ci->recvTime = ci->sendTime;
|
||||||
ci->message = msg;
|
ci->message = msg;
|
||||||
|
|
||||||
if (!mConnMgr->isOnline(id)) {
|
if (!mLinkMgr->isOnline(id)) {
|
||||||
/* peer is offline, add to outgoing list */
|
/* peer is offline, add to outgoing list */
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
@ -690,7 +691,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s)
|
||||||
for(std::map<std::string,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
|
for(std::map<std::string,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
|
||||||
it->second._own_is_new = true ;
|
it->second._own_is_new = true ;
|
||||||
|
|
||||||
mConnMgr->getOnlineList(onlineList);
|
mLinkMgr->getOnlineList(onlineList);
|
||||||
}
|
}
|
||||||
|
|
||||||
rsicontrol->getNotify().notifyOwnStatusMessageChanged() ;
|
rsicontrol->getNotify().notifyOwnStatusMessageChanged() ;
|
||||||
|
@ -1022,7 +1023,7 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
|
||||||
if(_own_avatar != NULL)
|
if(_own_avatar != NULL)
|
||||||
{
|
{
|
||||||
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
|
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
|
||||||
ci->PeerId(mConnMgr->getOwnId());
|
ci->PeerId(mLinkMgr->getOwnId());
|
||||||
|
|
||||||
list.push_back(ci) ;
|
list.push_back(ci) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,10 @@
|
||||||
|
|
||||||
#include "serialiser/rsmsgitems.h"
|
#include "serialiser/rsmsgitems.h"
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
#include "retroshare/rsmsgs.h"
|
#include "retroshare/rsmsgs.h"
|
||||||
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
//!The basic Chat service.
|
//!The basic Chat service.
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -45,7 +46,7 @@
|
||||||
class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3ChatService(p3ConnectMgr *cm);
|
p3ChatService(p3LinkMgr *cm);
|
||||||
|
|
||||||
/***** overloaded from p3Service *****/
|
/***** overloaded from p3Service *****/
|
||||||
/*!
|
/*!
|
||||||
|
@ -199,7 +200,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||||
RsChatAvatarItem *makeOwnAvatarItem() ;
|
RsChatAvatarItem *makeOwnAvatarItem() ;
|
||||||
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
std::list<RsChatMsgItem *> publicList;
|
std::list<RsChatMsgItem *> publicList;
|
||||||
std::list<RsChatMsgItem *> privateIncomingList;
|
std::list<RsChatMsgItem *> privateIncomingList;
|
||||||
|
|
|
@ -29,9 +29,11 @@
|
||||||
#include "retroshare/rspeers.h"
|
#include "retroshare/rspeers.h"
|
||||||
#include "services/p3disc.h"
|
#include "services/p3disc.h"
|
||||||
|
|
||||||
|
#include "pqi/p3peermgr.h"
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
#include "pqi/authgpg.h"
|
#include "pqi/authgpg.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -82,10 +84,10 @@ const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
|
||||||
******************************************************************************************
|
******************************************************************************************
|
||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
|
|
||||||
p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
|
p3disc::p3disc(p3PeerMgr *pm, p3LinkMgr *lm, pqipersongrp *pqih)
|
||||||
:p3Service(RS_SERVICE_TYPE_DISC),
|
:p3Service(RS_SERVICE_TYPE_DISC),
|
||||||
p3Config(CONFIG_TYPE_P3DISC),
|
p3Config(CONFIG_TYPE_P3DISC),
|
||||||
mConnMgr(cm),
|
mPeerMgr(pm), mLinkMgr(lm),
|
||||||
mPqiPersonGrp(pqih), mDiscMtx("p3disc")
|
mPqiPersonGrp(pqih), mDiscMtx("p3disc")
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
@ -114,7 +116,7 @@ int p3disc::tick()
|
||||||
#endif
|
#endif
|
||||||
lastSentHeartbeatTime = time(NULL);
|
lastSentHeartbeatTime = time(NULL);
|
||||||
std::list <std::string> peers;
|
std::list <std::string> peers;
|
||||||
mConnMgr->getOnlineList(peers);
|
mLinkMgr->getOnlineList(peers);
|
||||||
for (std::list<std::string>::const_iterator pit = peers.begin(); pit != peers.end(); ++pit) {
|
for (std::list<std::string>::const_iterator pit = peers.begin(); pit != peers.end(); ++pit) {
|
||||||
sendHeartbeat(*pit);
|
sendHeartbeat(*pit);
|
||||||
}
|
}
|
||||||
|
@ -132,8 +134,8 @@ int p3disc::handleIncoming()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// if off discard item.
|
// if off discard item.
|
||||||
peerConnectState detail;
|
peerState detail;
|
||||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
||||||
{
|
{
|
||||||
while(NULL != (item = recvItem()))
|
while(NULL != (item = recvItem()))
|
||||||
{
|
{
|
||||||
|
@ -288,8 +290,8 @@ void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
||||||
/* send them a list of all friend's details */
|
/* send them a list of all friend's details */
|
||||||
for(friendIdsIt = friendIds.begin(); friendIdsIt != friendIds.end(); friendIdsIt++) {
|
for(friendIdsIt = friendIds.begin(); friendIdsIt != friendIds.end(); friendIdsIt++) {
|
||||||
/* get details */
|
/* get details */
|
||||||
peerConnectState detail;
|
peerState detail;
|
||||||
if (!mConnMgr->getFriendNetStatus(*friendIdsIt, detail)) {
|
if (!mPeerMgr->getFriendNetStatus(*friendIdsIt, detail)) {
|
||||||
/* major error! */
|
/* major error! */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -368,8 +370,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||||
|
|
||||||
|
|
||||||
// if off discard item.
|
// if off discard item.
|
||||||
peerConnectState detail;
|
peerState detail;
|
||||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,8 +407,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||||
if(sslChilds.size() == 1 || to != *sslChildIt) // We don't send info to a peer about itself, when there are more than one ssl children,
|
if(sslChilds.size() == 1 || to != *sslChildIt) // We don't send info to a peer about itself, when there are more than one ssl children,
|
||||||
{ // but we allow sending info about peers with the same GPG id. When there is only one ssl child,
|
{ // but we allow sending info about peers with the same GPG id. When there is only one ssl child,
|
||||||
// we must send it to transfer the signers of the gpg key. The receiver is skipping the own id.
|
// we must send it to transfer the signers of the gpg key. The receiver is skipping the own id.
|
||||||
peerConnectState detail;
|
peerState detail;
|
||||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)
|
if (!mPeerMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
|
@ -430,8 +432,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||||
rsPeerNetItem.netMode = detail.netMode;
|
rsPeerNetItem.netMode = detail.netMode;
|
||||||
rsPeerNetItem.visState = detail.visState;
|
rsPeerNetItem.visState = detail.visState;
|
||||||
rsPeerNetItem.lastContact = detail.lastcontact;
|
rsPeerNetItem.lastContact = detail.lastcontact;
|
||||||
rsPeerNetItem.currentlocaladdr = detail.currentlocaladdr;
|
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
||||||
rsPeerNetItem.currentremoteaddr = detail.currentserveraddr;
|
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
||||||
rsPeerNetItem.dyndns = detail.dyndns;
|
rsPeerNetItem.dyndns = detail.dyndns;
|
||||||
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
||||||
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
||||||
|
@ -452,8 +454,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||||
//send own details
|
//send own details
|
||||||
if (about == rsPeers->getGPGOwnId())
|
if (about == rsPeers->getGPGOwnId())
|
||||||
{
|
{
|
||||||
peerConnectState detail;
|
peerState detail;
|
||||||
if (mConnMgr->getOwnNetStatus(detail))
|
if (mPeerMgr->getOwnNetStatus(detail))
|
||||||
{
|
{
|
||||||
shouldWeSendGPGKey = true;
|
shouldWeSendGPGKey = true;
|
||||||
RsPeerNetItem rsPeerNetItem ;
|
RsPeerNetItem rsPeerNetItem ;
|
||||||
|
@ -464,8 +466,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||||
rsPeerNetItem.netMode = detail.netMode;
|
rsPeerNetItem.netMode = detail.netMode;
|
||||||
rsPeerNetItem.visState = detail.visState;
|
rsPeerNetItem.visState = detail.visState;
|
||||||
rsPeerNetItem.lastContact = time(NULL);
|
rsPeerNetItem.lastContact = time(NULL);
|
||||||
rsPeerNetItem.currentlocaladdr = detail.currentlocaladdr;
|
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
||||||
rsPeerNetItem.currentremoteaddr = detail.currentserveraddr;
|
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
||||||
rsPeerNetItem.dyndns = detail.dyndns;
|
rsPeerNetItem.dyndns = detail.dyndns;
|
||||||
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
||||||
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
||||||
|
@ -534,8 +536,8 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
peerConnectState connectState;
|
peerState connectState;
|
||||||
if (!mConnMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
if (!mPeerMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
|
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
|
||||||
|
@ -551,7 +553,7 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if off discard item.
|
// if off discard item.
|
||||||
if (!mConnMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
if (!mPeerMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -644,7 +646,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
mPeerMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
||||||
RsPeerDetails storedDetails;
|
RsPeerDetails storedDetails;
|
||||||
|
|
||||||
// Update if know this peer
|
// Update if know this peer
|
||||||
|
@ -660,9 +662,9 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||||
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
||||||
std::cerr << " -> location: " << pitem->location << std::endl;
|
std::cerr << " -> location: " << pitem->location << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
mPeerMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||||
}
|
}
|
||||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
mPeerMgr->setLocation(pitem->pid, pitem->location);
|
||||||
|
|
||||||
// The info from the peer itself is ultimately trustable, so we can override some info,
|
// The info from the peer itself is ultimately trustable, so we can override some info,
|
||||||
// such as:
|
// such as:
|
||||||
|
@ -683,10 +685,10 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||||
// When the peer sends his own list of IPs, the info replaces the existing info, because the
|
// When the peer sends his own list of IPs, the info replaces the existing info, because the
|
||||||
// peer is the primary source of his own IPs.
|
// peer is the primary source of his own IPs.
|
||||||
|
|
||||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
mPeerMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
mPeerMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
//pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
mPeerMgr->setVisState(pitem->pid, pitem->visState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -706,9 +708,9 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||||
#endif
|
#endif
|
||||||
// allways update address list and dns, except if it's ours
|
// allways update address list and dns, except if it's ours
|
||||||
if (pitem->dyndns != "")
|
if (pitem->dyndns != "")
|
||||||
mConnMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
mPeerMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
||||||
|
|
||||||
mConnMgr->updateAddressList(pitem->pid, addrsFromPeer);
|
mPeerMgr->updateAddressList(pitem->pid, addrsFromPeer);
|
||||||
}
|
}
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
else
|
else
|
||||||
|
@ -817,7 +819,7 @@ AuthGPGOperation *p3disc::getGPGOperation()
|
||||||
while (!sendIdList.empty()) {
|
while (!sendIdList.empty()) {
|
||||||
std::map<std::string, std::list<std::string> >::iterator sendIdIt = sendIdList.begin();
|
std::map<std::string, std::list<std::string> >::iterator sendIdIt = sendIdList.begin();
|
||||||
|
|
||||||
if (!sendIdIt->second.empty() && mConnMgr->isOnline(sendIdIt->first)) {
|
if (!sendIdIt->second.empty() && mLinkMgr->isOnline(sendIdIt->first)) {
|
||||||
std::string gpgId = sendIdIt->second.front();
|
std::string gpgId = sendIdIt->second.front();
|
||||||
sendIdIt->second.pop_front();
|
sendIdIt->second.pop_front();
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,8 @@ class autoneighbour: public autoserver
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class p3ConnectMgr;
|
class p3PeerMgr;
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
|
|
||||||
class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthGPGService
|
class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthGPGService
|
||||||
|
@ -80,7 +81,7 @@ class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthG
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
p3disc(p3ConnectMgr *cm, pqipersongrp *persGrp);
|
p3disc(p3PeerMgr *pm, p3LinkMgr *lm, pqipersongrp *persGrp);
|
||||||
|
|
||||||
/************* from pqiMonitor *******************/
|
/************* from pqiMonitor *******************/
|
||||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||||
|
@ -141,7 +142,9 @@ int idServers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3PeerMgr *mPeerMgr;
|
||||||
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
pqipersongrp *mPqiPersonGrp;
|
pqipersongrp *mPqiPersonGrp;
|
||||||
time_t lastSentHeartbeatTime;
|
time_t lastSentHeartbeatTime;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "services/p3gamelauncher.h"
|
#include "services/p3gamelauncher.h"
|
||||||
#include "services/p3gameservice.h"
|
#include "services/p3gameservice.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
@ -109,9 +109,9 @@ const uint32_t RS_GAME_MSG_REJECT = 6; /* ANY -> ANY */
|
||||||
|
|
||||||
const int p3gamezone = 1745;
|
const int p3gamezone = 1745;
|
||||||
|
|
||||||
p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
|
p3GameLauncher::p3GameLauncher(p3LinkMgr *lm)
|
||||||
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER),
|
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER),
|
||||||
mConnMgr(connMgr)
|
mLinkMgr(lm)
|
||||||
{
|
{
|
||||||
#ifdef GAME_DEBUG
|
#ifdef GAME_DEBUG
|
||||||
std::cerr << "p3GameLauncher::p3GameLauncher()";
|
std::cerr << "p3GameLauncher::p3GameLauncher()";
|
||||||
|
@ -119,7 +119,7 @@ p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addSerialType(new RsGameSerialiser());
|
addSerialType(new RsGameSerialiser());
|
||||||
mOwnId = mConnMgr->getOwnId();
|
mOwnId = mLinkMgr->getOwnId();
|
||||||
}
|
}
|
||||||
|
|
||||||
int p3GameLauncher::tick()
|
int p3GameLauncher::tick()
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#include "serialiser/rsgameitems.h"
|
#include "serialiser/rsgameitems.h"
|
||||||
#include "retroshare/rsgame.h"
|
#include "retroshare/rsgame.h"
|
||||||
|
|
||||||
class p3ConnectMgr;
|
class p3LinkMgr;
|
||||||
|
|
||||||
|
|
||||||
class gameAvail
|
class gameAvail
|
||||||
|
@ -76,7 +76,7 @@ class p3GameService;
|
||||||
class p3GameLauncher: public p3Service, public RsGameLauncher
|
class p3GameLauncher: public p3Service, public RsGameLauncher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3GameLauncher(p3ConnectMgr *connMgr);
|
p3GameLauncher(p3LinkMgr *lm);
|
||||||
|
|
||||||
/***** EXTERNAL RsGameLauncher Interface *******/
|
/***** EXTERNAL RsGameLauncher Interface *******/
|
||||||
/* server commands */
|
/* server commands */
|
||||||
|
@ -144,7 +144,7 @@ bool checkGameProperties(uint16_t serviceId, uint16_t players);
|
||||||
std::map<uint16_t, p3GameService *> gameList;
|
std::map<uint16_t, p3GameService *> gameList;
|
||||||
std::map<std::string, gameStatus> gamesCurrent;
|
std::map<std::string, gameStatus> gamesCurrent;
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
std::string mOwnId;
|
std::string mOwnId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "pqi/pqibin.h"
|
#include "pqi/pqibin.h"
|
||||||
#include "pqi/pqiarchive.h"
|
#include "pqi/pqiarchive.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
#include "services/p3msgservice.h"
|
#include "services/p3msgservice.h"
|
||||||
#include "pqi/pqinotify.h"
|
#include "pqi/pqinotify.h"
|
||||||
|
@ -54,14 +54,14 @@ const int msgservicezone = 54319;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
p3MsgService::p3MsgService(p3ConnectMgr *cm)
|
p3MsgService::p3MsgService(p3LinkMgr *lm)
|
||||||
:p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS),
|
:p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS),
|
||||||
mConnMgr(cm), mMsgMtx("p3MsgService"), msgChanged(1), mMsgUniqueId(1)
|
mLinkMgr(lm), mMsgMtx("p3MsgService"), msgChanged(1), mMsgUniqueId(1)
|
||||||
{
|
{
|
||||||
addSerialType(new RsMsgSerialiser());
|
addSerialType(new RsMsgSerialiser());
|
||||||
|
|
||||||
/* Initialize standard tag types */
|
/* Initialize standard tag types */
|
||||||
if(cm)
|
if(lm)
|
||||||
initStandardTagTypes();
|
initStandardTagTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ void p3MsgService::processMsg(RsMsgItem *mi)
|
||||||
|
|
||||||
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/
|
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/
|
||||||
|
|
||||||
if (mi -> PeerId() == mConnMgr->getOwnId())
|
if (mi -> PeerId() == mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
/* from the loopback device */
|
/* from the loopback device */
|
||||||
mi -> msgFlags |= RS_MSG_FLAGS_OUTGOING;
|
mi -> msgFlags |= RS_MSG_FLAGS_OUTGOING;
|
||||||
|
@ -207,7 +207,7 @@ int p3MsgService::checkOutgoingMessages()
|
||||||
bool changed = false ;
|
bool changed = false ;
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::string ownId = mConnMgr->getOwnId();
|
const std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
std::list<uint32_t>::iterator it;
|
std::list<uint32_t>::iterator it;
|
||||||
std::list<uint32_t> toErase;
|
std::list<uint32_t> toErase;
|
||||||
|
@ -225,7 +225,7 @@ int p3MsgService::checkOutgoingMessages()
|
||||||
peerConnectState pstate;
|
peerConnectState pstate;
|
||||||
bool toSend = false;
|
bool toSend = false;
|
||||||
|
|
||||||
if (mConnMgr->getFriendNetStatus(pid, pstate))
|
if (mLinkMgr->getFriendNetStatus(pid, pstate))
|
||||||
{
|
{
|
||||||
if (pstate.state & RS_PEER_S_CONNECTED)
|
if (pstate.state & RS_PEER_S_CONNECTED)
|
||||||
{
|
{
|
||||||
|
@ -353,7 +353,7 @@ static void getStandardTagTypes(MsgTagType &tags)
|
||||||
void p3MsgService::initStandardTagTypes()
|
void p3MsgService::initStandardTagTypes()
|
||||||
{
|
{
|
||||||
bool bChanged = false;
|
bool bChanged = false;
|
||||||
std::string ownId = mConnMgr->getOwnId();
|
std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
MsgTagType tags;
|
MsgTagType tags;
|
||||||
getStandardTagTypes(tags);
|
getStandardTagTypes(tags);
|
||||||
|
@ -507,7 +507,7 @@ void p3MsgService::loadWelcomeMsg()
|
||||||
/* Load Welcome Message */
|
/* Load Welcome Message */
|
||||||
RsMsgItem *msg = new RsMsgItem();
|
RsMsgItem *msg = new RsMsgItem();
|
||||||
|
|
||||||
//msg -> PeerId(mConnMgr->getOwnId());
|
//msg -> PeerId(mLinkMgr->getOwnId());
|
||||||
|
|
||||||
msg -> sendTime = time(NULL);
|
msg -> sendTime = time(NULL);
|
||||||
msg -> recvTime = time(NULL);
|
msg -> recvTime = time(NULL);
|
||||||
|
@ -796,7 +796,7 @@ bool p3MsgService::setMsgParentId(uint32_t msgId, uint32_t msgParentId)
|
||||||
{
|
{
|
||||||
if (msgParentId) {
|
if (msgParentId) {
|
||||||
RsMsgParentId* msp = new RsMsgParentId();
|
RsMsgParentId* msp = new RsMsgParentId();
|
||||||
msp->PeerId (mConnMgr->getOwnId());
|
msp->PeerId (mLinkMgr->getOwnId());
|
||||||
msp->msgId = msgId;
|
msp->msgId = msgId;
|
||||||
msp->msgParentId = msgParentId;
|
msp->msgParentId = msgParentId;
|
||||||
mParentId.insert(std::pair<uint32_t, RsMsgParentId*>(msgId, msp));
|
mParentId.insert(std::pair<uint32_t, RsMsgParentId*>(msgId, msp));
|
||||||
|
@ -842,7 +842,7 @@ int p3MsgService::sendMessage(RsMsgItem *item)
|
||||||
/* STORE MsgID */
|
/* STORE MsgID */
|
||||||
msgOutgoing[item->msgId] = item;
|
msgOutgoing[item->msgId] = item;
|
||||||
|
|
||||||
if (item->PeerId() != mConnMgr->getOwnId()) {
|
if (item->PeerId() != mLinkMgr->getOwnId()) {
|
||||||
/* not to the loopback device */
|
/* not to the loopback device */
|
||||||
RsMsgSrcId* msi = new RsMsgSrcId();
|
RsMsgSrcId* msi = new RsMsgSrcId();
|
||||||
msi->msgId = item->msgId;
|
msi->msgId = item->msgId;
|
||||||
|
@ -891,7 +891,7 @@ bool p3MsgService::MessageSend(MessageInfo &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send to ourselves as well */
|
/* send to ourselves as well */
|
||||||
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
/* use processMsg to get the new msgId */
|
/* use processMsg to get the new msgId */
|
||||||
|
@ -909,7 +909,7 @@ bool p3MsgService::MessageSend(MessageInfo &info)
|
||||||
|
|
||||||
bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParentId)
|
bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParentId)
|
||||||
{
|
{
|
||||||
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
|
||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
uint32_t msgId = 0;
|
uint32_t msgId = 0;
|
||||||
|
@ -992,7 +992,7 @@ bool p3MsgService::setMessageTagType(uint32_t tagId, std::string& text, uint32
|
||||||
|
|
||||||
/* new tag */
|
/* new tag */
|
||||||
RsMsgTagType* tagType = new RsMsgTagType();
|
RsMsgTagType* tagType = new RsMsgTagType();
|
||||||
tagType->PeerId (mConnMgr->getOwnId());
|
tagType->PeerId (mLinkMgr->getOwnId());
|
||||||
tagType->rgb_color = rgb_color;
|
tagType->rgb_color = rgb_color;
|
||||||
tagType->tagId = tagId;
|
tagType->tagId = tagId;
|
||||||
tagType->text = text;
|
tagType->text = text;
|
||||||
|
@ -1136,7 +1136,7 @@ bool p3MsgService::setMessageTag(const std::string &msgId, uint32_t tagId, bool
|
||||||
if (set) {
|
if (set) {
|
||||||
/* new msg */
|
/* new msg */
|
||||||
RsMsgTags* tag = new RsMsgTags();
|
RsMsgTags* tag = new RsMsgTags();
|
||||||
tag->PeerId (mConnMgr->getOwnId());
|
tag->PeerId (mLinkMgr->getOwnId());
|
||||||
|
|
||||||
tag->msgId = mid;
|
tag->msgId = mid;
|
||||||
tag->tagIds.push_back(tagId);
|
tag->tagIds.push_back(tagId);
|
||||||
|
@ -1280,7 +1280,7 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||||
|
|
||||||
/* translate flags, if we sent it... outgoing */
|
/* translate flags, if we sent it... outgoing */
|
||||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||||
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
|| (msg->PeerId() == mLinkMgr->getOwnId()))
|
||||||
{
|
{
|
||||||
mi.msgflags |= RS_MSG_OUTGOING;
|
mi.msgflags |= RS_MSG_OUTGOING;
|
||||||
}
|
}
|
||||||
|
@ -1379,7 +1379,7 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
||||||
|
|
||||||
/* translate flags, if we sent it... outgoing */
|
/* translate flags, if we sent it... outgoing */
|
||||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||||
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
|| (msg->PeerId() == mLinkMgr->getOwnId()))
|
||||||
{
|
{
|
||||||
mis.msgflags |= RS_MSG_OUTGOING;
|
mis.msgflags |= RS_MSG_OUTGOING;
|
||||||
}
|
}
|
||||||
|
@ -1456,7 +1456,7 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, std::string to)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We don't fill in bcc (unless to ourselves) */
|
/* We don't fill in bcc (unless to ourselves) */
|
||||||
if (to == mConnMgr->getOwnId())
|
if (to == mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,12 +43,12 @@
|
||||||
#include "serialiser/rsmsgitems.h"
|
#include "serialiser/rsmsgitems.h"
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
class p3ConnectMgr;
|
class p3LinkMgr;
|
||||||
|
|
||||||
class p3MsgService: public p3Service, public p3Config, public pqiMonitor
|
class p3MsgService: public p3Service, public p3Config, public pqiMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3MsgService(p3ConnectMgr *cm);
|
p3MsgService(p3LinkMgr *lm);
|
||||||
|
|
||||||
/* External Interface */
|
/* External Interface */
|
||||||
bool MsgsChanged(); /* should update display */
|
bool MsgsChanged(); /* should update display */
|
||||||
|
@ -113,7 +113,7 @@ RsMsgItem *initMIRsMsg(MessageInfo &info, std::string to);
|
||||||
|
|
||||||
void initStandardTagTypes();
|
void initStandardTagTypes();
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
/* Mutex Required for stuff below */
|
/* Mutex Required for stuff below */
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,10 @@
|
||||||
#include "services/p3portservice.h"
|
#include "services/p3portservice.h"
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
|
|
||||||
p3PortService::p3PortService(p3ConnectMgr *cm)
|
#include "pqi/p3linkmgr.h"
|
||||||
:p3Service(RS_SERVICE_TYPE_PORT), mConnMgr(cm), mEnabled(false)
|
|
||||||
|
p3PortService::p3PortService(p3LinkMgr *lm)
|
||||||
|
:p3Service(RS_SERVICE_TYPE_PORT), mLinkMgr(lm), mEnabled(false)
|
||||||
{
|
{
|
||||||
/* For Version 1, we'll just use the very simple RsRawItem packets
|
/* For Version 1, we'll just use the very simple RsRawItem packets
|
||||||
* which are handled in the RsServiceSerialiser
|
* which are handled in the RsServiceSerialiser
|
||||||
|
|
|
@ -59,13 +59,14 @@
|
||||||
|
|
||||||
#include "serialiser/rsbaseitems.h"
|
#include "serialiser/rsbaseitems.h"
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3connmgr.h"
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
|
|
||||||
class p3PortService: public p3Service
|
class p3PortService: public p3Service
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3PortService(p3ConnectMgr *cm);
|
p3PortService(p3LinkMgr *lm);
|
||||||
|
|
||||||
/* example setup functions */
|
/* example setup functions */
|
||||||
bool enablePortForwarding(uint32_t port, std::string peerId);
|
bool enablePortForwarding(uint32_t port, std::string peerId);
|
||||||
|
@ -75,7 +76,7 @@ virtual int tick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
bool mPeerOnline;
|
bool mPeerOnline;
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "pqi/p3linkmgr.h"
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||||
{
|
{
|
||||||
out << "StatusInfo: " << std::endl;
|
out << "StatusInfo: " << std::endl;
|
||||||
|
@ -43,8 +45,8 @@ std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||||
|
|
||||||
RsStatus *rsStatus = NULL;
|
RsStatus *rsStatus = NULL;
|
||||||
|
|
||||||
p3StatusService::p3StatusService(p3ConnectMgr *cm)
|
p3StatusService::p3StatusService(p3LinkMgr *cm)
|
||||||
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mConnMgr(cm), mStatusMtx("p3StatusService")
|
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mLinkMgr(cm), mStatusMtx("p3StatusService")
|
||||||
{
|
{
|
||||||
addSerialType(new RsStatusSerialiser());
|
addSerialType(new RsStatusSerialiser());
|
||||||
|
|
||||||
|
@ -61,7 +63,7 @@ bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::map<std::string, StatusInfo>::iterator it;
|
std::map<std::string, StatusInfo>::iterator it;
|
||||||
std::string ownId = mConnMgr->getOwnId();
|
std::string ownId = mLinkMgr->getOwnId();
|
||||||
|
|
||||||
RsStackMutex stack(mStatusMtx);
|
RsStackMutex stack(mStatusMtx);
|
||||||
it = mStatusInfoMap.find(ownId);
|
it = mStatusInfoMap.find(ownId);
|
||||||
|
@ -128,7 +130,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mStatusMtx);
|
RsStackMutex stack(mStatusMtx);
|
||||||
|
|
||||||
statusInfo.id = mConnMgr->getOwnId();
|
statusInfo.id = mLinkMgr->getOwnId();
|
||||||
statusInfo.status = status;
|
statusInfo.status = status;
|
||||||
|
|
||||||
// don't save inactive status
|
// don't save inactive status
|
||||||
|
@ -148,7 +150,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id.empty()) {
|
if (id.empty()) {
|
||||||
mConnMgr->getOnlineList(onlineList);
|
mLinkMgr->getOnlineList(onlineList);
|
||||||
} else {
|
} else {
|
||||||
onlineList.push_back(id);
|
onlineList.push_back(id);
|
||||||
}
|
}
|
||||||
|
@ -257,11 +259,11 @@ bool p3StatusService::saveList(bool& cleanup, std::list<RsItem*>& ilist){
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mStatusMtx);
|
RsStackMutex stack(mStatusMtx);
|
||||||
it = mStatusInfoMap.find(mConnMgr->getOwnId());
|
it = mStatusInfoMap.find(mLinkMgr->getOwnId());
|
||||||
|
|
||||||
if(it == mStatusInfoMap.end()){
|
if(it == mStatusInfoMap.end()){
|
||||||
std::cerr << "p3StatusService::saveList() :" << "Did not find your status"
|
std::cerr << "p3StatusService::saveList() :" << "Did not find your status"
|
||||||
<< mConnMgr->getOwnId() << std::endl;
|
<< mLinkMgr->getOwnId() << std::endl;
|
||||||
delete own_status;
|
delete own_status;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -295,14 +297,14 @@ bool p3StatusService::loadList(std::list<RsItem*>& load){
|
||||||
|
|
||||||
if(own_status != NULL){
|
if(own_status != NULL){
|
||||||
|
|
||||||
own_info.id = mConnMgr->getOwnId();
|
own_info.id = mLinkMgr->getOwnId();
|
||||||
own_info.status = own_status->status;
|
own_info.status = own_status->status;
|
||||||
own_info.time_stamp = own_status->sendTime;
|
own_info.time_stamp = own_status->sendTime;
|
||||||
delete own_status;
|
delete own_status;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mStatusMtx);
|
RsStackMutex stack(mStatusMtx);
|
||||||
std::pair<std::string, StatusInfo> pr(mConnMgr->getOwnId(), own_info);
|
std::pair<std::string, StatusInfo> pr(mLinkMgr->getOwnId(), own_info);
|
||||||
mStatusInfoMap.insert(pr);
|
mStatusInfoMap.insert(pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,10 @@
|
||||||
#include "serialiser/rsstatusitems.h"
|
#include "serialiser/rsstatusitems.h"
|
||||||
#include "retroshare/rsstatus.h"
|
#include "retroshare/rsstatus.h"
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
|
#include "pqi/pqimonitor.h"
|
||||||
|
|
||||||
|
class p3LinkMgr;
|
||||||
|
|
||||||
//! handles standard status messages (busy, away, online, offline) set by user
|
//! handles standard status messages (busy, away, online, offline) set by user
|
||||||
/*!
|
/*!
|
||||||
|
@ -45,7 +48,7 @@ class p3StatusService: public p3Service, public p3Config, public pqiMonitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3StatusService(p3ConnectMgr* );
|
p3StatusService(p3LinkMgr *lm);
|
||||||
virtual ~p3StatusService();
|
virtual ~p3StatusService();
|
||||||
|
|
||||||
/***** overloaded from p3Service *****/
|
/***** overloaded from p3Service *****/
|
||||||
|
@ -90,7 +93,7 @@ virtual bool loadList(std::list<RsItem*>& load);
|
||||||
|
|
||||||
virtual void receiveStatusQueue();
|
virtual void receiveStatusQueue();
|
||||||
|
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
|
|
||||||
std::map<std::string, StatusInfo> mStatusInfoMap;
|
std::map<std::string, StatusInfo> mStatusInfoMap;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "retroshare/rsfiles.h"
|
#include "retroshare/rsfiles.h"
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3linkmgr.h"
|
||||||
#include "pqi/pqinotify.h"
|
#include "pqi/pqinotify.h"
|
||||||
|
|
||||||
#include "ft/ftserver.h"
|
#include "ft/ftserver.h"
|
||||||
|
@ -87,8 +87,8 @@ static const time_t TUNNEL_CLEANING_LAPS_TIME = 10 ; /// clean tunnels every
|
||||||
static const uint32_t MAX_TUNNEL_REQS_PER_SECOND= 1 ; /// maximum number of tunnel requests issued per second. Was 0.5 before
|
static const uint32_t MAX_TUNNEL_REQS_PER_SECOND= 1 ; /// maximum number of tunnel requests issued per second. Was 0.5 before
|
||||||
static const uint32_t MAX_ALLOWED_SR_IN_CACHE = 120 ; /// maximum number of search requests allowed in cache. That makes 2 per sec.
|
static const uint32_t MAX_ALLOWED_SR_IN_CACHE = 120 ; /// maximum number of search requests allowed in cache. That makes 2 per sec.
|
||||||
|
|
||||||
p3turtle::p3turtle(p3ConnectMgr *cm,ftServer *fs)
|
p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs)
|
||||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm), mTurtleMtx("p3turtle")
|
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mLinkMgr(lm), mTurtleMtx("p3turtle")
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<Turtl
|
||||||
std::cerr << "p3turtle: Closing tunnel " << (void*)tid << std::endl ;
|
std::cerr << "p3turtle: Closing tunnel " << (void*)tid << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(it->second.local_src == mConnMgr->getOwnId()) // this is a starting tunnel. We thus remove
|
if(it->second.local_src == mLinkMgr->getOwnId()) // this is a starting tunnel. We thus remove
|
||||||
// - the virtual peer from the vpid list
|
// - the virtual peer from the vpid list
|
||||||
// - the tunnel id from the file hash
|
// - the tunnel id from the file hash
|
||||||
// - the virtual peer from the file sources in the file transfer controller.
|
// - the virtual peer from the file sources in the file transfer controller.
|
||||||
|
@ -516,7 +516,7 @@ void p3turtle::locked_closeTunnel(TurtleTunnelId tid,std::vector<std::pair<Turtl
|
||||||
++i ;
|
++i ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(it->second.local_dst == mConnMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id
|
else if(it->second.local_dst == mLinkMgr->getOwnId()) // This is a ending tunnel. We also remove the virtual peer id
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ;
|
std::cerr << " Tunnel is a ending point. Also removing associated outgoing hash." ;
|
||||||
|
@ -625,7 +625,7 @@ uint32_t p3turtle::generatePersonalFilePrint(const TurtleFileHash& hash,bool b)
|
||||||
// The only important thing is that the saem couple (hash,SSL id) produces the same tunnel
|
// The only important thing is that the saem couple (hash,SSL id) produces the same tunnel
|
||||||
// id. The result uses a boolean to allow generating non symmetric tunnel ids.
|
// id. The result uses a boolean to allow generating non symmetric tunnel ids.
|
||||||
|
|
||||||
std::string buff(hash + mConnMgr->getOwnId()) ;
|
std::string buff(hash + mLinkMgr->getOwnId()) ;
|
||||||
uint32_t res = 0 ;
|
uint32_t res = 0 ;
|
||||||
uint32_t decal = 0 ;
|
uint32_t decal = 0 ;
|
||||||
|
|
||||||
|
@ -733,7 +733,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||||
|
|
||||||
// If it's not for us, perform a local search. If something found, forward the search result back.
|
// If it's not for us, perform a local search. If something found, forward the search result back.
|
||||||
|
|
||||||
if(item->PeerId() != mConnMgr->getOwnId())
|
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||||
|
@ -797,7 +797,7 @@ void p3turtle::handleSearchRequest(RsTurtleSearchRequestItem *item)
|
||||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
||||||
{
|
{
|
||||||
std::list<std::string> onlineIds ;
|
std::list<std::string> onlineIds ;
|
||||||
mConnMgr->getOnlineList(onlineIds);
|
mLinkMgr->getOnlineList(onlineIds);
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Looking for online peers" << std::endl ;
|
std::cerr << " Looking for online peers" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
@ -846,7 +846,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||||
|
|
||||||
++(item->depth) ; // increase depth
|
++(item->depth) ; // increase depth
|
||||||
|
|
||||||
if(it->second.origin == mConnMgr->getOwnId())
|
if(it->second.origin == mLinkMgr->getOwnId())
|
||||||
returnSearchResult(item) ; // Yes, so send upward.
|
returnSearchResult(item) ; // Yes, so send upward.
|
||||||
else
|
else
|
||||||
{ // Nope, so forward it back.
|
{ // Nope, so forward it back.
|
||||||
|
@ -906,7 +906,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
||||||
|
|
||||||
// Let's figure out whether this packet is for us or not.
|
// Let's figure out whether this packet is for us or not.
|
||||||
|
|
||||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT && tunnel.local_src != mConnMgr->getOwnId())
|
if(direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT && tunnel.local_src != mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Forwarding generic item to peer " << tunnel.local_src << std::endl ;
|
std::cerr << " Forwarding generic item to peer " << tunnel.local_src << std::endl ;
|
||||||
|
@ -919,7 +919,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER && tunnel.local_dst != mConnMgr->getOwnId())
|
if(direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER && tunnel.local_dst != mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Forwarding generic item to peer " << tunnel.local_dst << std::endl ;
|
std::cerr << " Forwarding generic item to peer " << tunnel.local_dst << std::endl ;
|
||||||
|
@ -1321,7 +1321,7 @@ void p3turtle::sendChunkMapRequest(const std::string& peerId,const std::string&
|
||||||
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
|
RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ;
|
||||||
item->tunnel_id = tunnel_id ;
|
item->tunnel_id = tunnel_id ;
|
||||||
|
|
||||||
std::string ownid = mConnMgr->getOwnId() ;
|
std::string ownid = mLinkMgr->getOwnId() ;
|
||||||
|
|
||||||
if(tunnel.local_src == ownid)
|
if(tunnel.local_src == ownid)
|
||||||
{
|
{
|
||||||
|
@ -1368,7 +1368,7 @@ void p3turtle::sendChunkMap(const std::string& peerId,const std::string& ,const
|
||||||
item->tunnel_id = tunnel_id ;
|
item->tunnel_id = tunnel_id ;
|
||||||
item->compressed_map = cmap ;
|
item->compressed_map = cmap ;
|
||||||
|
|
||||||
std::string ownid = mConnMgr->getOwnId() ;
|
std::string ownid = mLinkMgr->getOwnId() ;
|
||||||
|
|
||||||
if(tunnel.local_src == ownid)
|
if(tunnel.local_src == ownid)
|
||||||
{
|
{
|
||||||
|
@ -1491,9 +1491,9 @@ bool p3turtle::isOnline(const std::string& peer_id) const
|
||||||
TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mConnMgr->getOwnId() << " for hash=" << hash << std::endl ;
|
std::cerr << "DiggTunnel: performing tunnel request. OwnId = " << mLinkMgr->getOwnId() << " for hash=" << hash << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
while(mConnMgr->getOwnId() == "")
|
while(mLinkMgr->getOwnId() == "")
|
||||||
{
|
{
|
||||||
std::cerr << "... waiting for connect manager to form own id." << std::endl ;
|
std::cerr << "... waiting for connect manager to form own id." << std::endl ;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -1517,7 +1517,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||||
//
|
//
|
||||||
RsTurtleOpenTunnelItem *item = new RsTurtleOpenTunnelItem ;
|
RsTurtleOpenTunnelItem *item = new RsTurtleOpenTunnelItem ;
|
||||||
|
|
||||||
item->PeerId(mConnMgr->getOwnId()) ;
|
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||||
item->file_hash = hash ;
|
item->file_hash = hash ;
|
||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->partial_tunnel_id = generatePersonalFilePrint(hash,true) ;
|
item->partial_tunnel_id = generatePersonalFilePrint(hash,true) ;
|
||||||
|
@ -1651,7 +1651,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||||
bool found = false ;
|
bool found = false ;
|
||||||
FileInfo info ;
|
FileInfo info ;
|
||||||
|
|
||||||
if(item->PeerId() != mConnMgr->getOwnId())
|
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||||
|
@ -1681,7 +1681,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||||
TurtleTunnel tt ;
|
TurtleTunnel tt ;
|
||||||
tt.local_src = item->PeerId() ;
|
tt.local_src = item->PeerId() ;
|
||||||
tt.hash = item->file_hash ;
|
tt.hash = item->file_hash ;
|
||||||
tt.local_dst = mConnMgr->getOwnId() ; // this means us
|
tt.local_dst = mLinkMgr->getOwnId() ; // this means us
|
||||||
tt.time_stamp = time(NULL) ;
|
tt.time_stamp = time(NULL) ;
|
||||||
tt.transfered_bytes = 0 ;
|
tt.transfered_bytes = 0 ;
|
||||||
tt.speed_Bps = 0.0f ;
|
tt.speed_Bps = 0.0f ;
|
||||||
|
@ -1712,7 +1712,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
||||||
{
|
{
|
||||||
std::list<std::string> onlineIds ;
|
std::list<std::string> onlineIds ;
|
||||||
mConnMgr->getOnlineList(onlineIds);
|
mLinkMgr->getOnlineList(onlineIds);
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
|
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1804,7 +1804,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
||||||
|
|
||||||
// Is this result's target actually ours ?
|
// Is this result's target actually ours ?
|
||||||
|
|
||||||
if(it->second.origin == mConnMgr->getOwnId())
|
if(it->second.origin == mLinkMgr->getOwnId())
|
||||||
{
|
{
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << " Tunnel starting point. Storing id=" << (void*)item->tunnel_id << " for hash (unknown) and tunnel request id " << it->second.origin << std::endl;
|
std::cerr << " Tunnel starting point. Storing id=" << (void*)item->tunnel_id << " for hash (unknown) and tunnel request id " << it->second.origin << std::endl;
|
||||||
|
@ -1949,9 +1949,9 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||||
RsTurtleStringSearchRequestItem *item = new RsTurtleStringSearchRequestItem ;
|
RsTurtleStringSearchRequestItem *item = new RsTurtleStringSearchRequestItem ;
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "performing search. OwnId = " << mConnMgr->getOwnId() << std::endl ;
|
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
while(mConnMgr->getOwnId() == "")
|
while(mLinkMgr->getOwnId() == "")
|
||||||
{
|
{
|
||||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -1961,7 +1961,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
item->PeerId(mConnMgr->getOwnId()) ;
|
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||||
item->match_string = string_to_match ;
|
item->match_string = string_to_match ;
|
||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->depth = 0 ;
|
item->depth = 0 ;
|
||||||
|
@ -1985,9 +1985,9 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||||
RsTurtleRegExpSearchRequestItem *item = new RsTurtleRegExpSearchRequestItem ;
|
RsTurtleRegExpSearchRequestItem *item = new RsTurtleRegExpSearchRequestItem ;
|
||||||
|
|
||||||
#ifdef P3TURTLE_DEBUG
|
#ifdef P3TURTLE_DEBUG
|
||||||
std::cerr << "performing search. OwnId = " << mConnMgr->getOwnId() << std::endl ;
|
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
while(mConnMgr->getOwnId() == "")
|
while(mLinkMgr->getOwnId() == "")
|
||||||
{
|
{
|
||||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -1997,7 +1997,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
item->PeerId(mConnMgr->getOwnId()) ;
|
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||||
item->expr = expr ;
|
item->expr = expr ;
|
||||||
item->request_id = id ;
|
item->request_id = id ;
|
||||||
item->depth = 0 ;
|
item->depth = 0 ;
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
//#define TUNNEL_STATISTICS
|
//#define TUNNEL_STATISTICS
|
||||||
|
|
||||||
class ftServer ;
|
class ftServer ;
|
||||||
class p3ConnectMgr;
|
class p3LinkMgr;
|
||||||
class ftDataMultiplex;
|
class ftDataMultiplex;
|
||||||
class RsSerialiser;
|
class RsSerialiser;
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ class TurtleFileHashInfo
|
||||||
class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* public ftSearch */ public p3Config
|
class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* public ftSearch */ public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3turtle(p3ConnectMgr *cm,ftServer *m);
|
p3turtle(p3LinkMgr *lm,ftServer *m);
|
||||||
|
|
||||||
// Lauches a search request through the pipes, and immediately returns
|
// Lauches a search request through the pipes, and immediately returns
|
||||||
// the request id, which will be further used by the gui to store results
|
// the request id, which will be further used by the gui to store results
|
||||||
|
@ -371,7 +371,7 @@ class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* publ
|
||||||
//--------------------------- Local variables --------------------------------//
|
//--------------------------- Local variables --------------------------------//
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
p3ConnectMgr *mConnMgr;
|
p3LinkMgr *mLinkMgr;
|
||||||
ftServer *_ft_server ;
|
ftServer *_ft_server ;
|
||||||
ftController *_ft_controller ;
|
ftController *_ft_controller ;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue