mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-03 11:00:14 -05: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
@ -23,7 +23,8 @@
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -542,8 +543,8 @@ void CacheStore::locked_storeCacheEntry(const CacheData &data)
|
||||
*
|
||||
********************************* CacheStrapper ********************************/
|
||||
|
||||
CacheStrapper::CacheStrapper(p3ConnectMgr *cm)
|
||||
:p3Config(CONFIG_TYPE_CACHE), mConnMgr(cm), csMtx("CacheStrapper")
|
||||
CacheStrapper::CacheStrapper(p3LinkMgr *lm)
|
||||
:p3Config(CONFIG_TYPE_CACHE), mLinkMgr(lm), csMtx("CacheStrapper")
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -595,7 +596,7 @@ void CacheStrapper::refreshCache(const CacheData &data)
|
||||
std::list<std::string> ids;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
mConnMgr->getOnlineList(ids);
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
RsStackMutex stack(csMtx); /******* LOCK STACK MUTEX *********/
|
||||
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(mConnMgr->getOwnId(), data));
|
||||
mCacheUpdates.push_back(std::make_pair(mLinkMgr->getOwnId(), data));
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
@ -688,7 +689,7 @@ void CacheStrapper::listCaches(std::ostream &out)
|
||||
{
|
||||
/* can overwrite for more control! */
|
||||
std::map<uint16_t, CachePair>::iterator it;
|
||||
out << "CacheStrapper::listCaches() [" << mConnMgr->getOwnId();
|
||||
out << "CacheStrapper::listCaches() [" << mLinkMgr->getOwnId();
|
||||
out << "] " << " Total Caches: " << caches.size();
|
||||
out << std::endl;
|
||||
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> ownCaches;
|
||||
std::list<CacheData> remoteCaches;
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
std::map<uint16_t, CachePair>::iterator it;
|
||||
for(it = caches.begin(); it != caches.end(); it++)
|
||||
@ -861,11 +862,11 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
#endif
|
||||
std::list<CacheData> ownCaches;
|
||||
std::list<CacheData> remoteCaches;
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
peerConnectState ownState;
|
||||
mConnMgr->getOwnNetStatus(ownState);
|
||||
std::string ownName = ownState.name+" ("+ownState.location+")";
|
||||
//peerConnectState ownState;
|
||||
//mPeerMgr->getOwnNetStatus(ownState);
|
||||
//std::string ownName = ownState.name+" ("+ownState.location+")";
|
||||
|
||||
std::map<std::string, std::list<std::string> > saveFiles;
|
||||
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;
|
||||
|
||||
#if 0
|
||||
if(cd.pid == ownId)
|
||||
{
|
||||
cd.pname = ownName;
|
||||
@ -892,9 +894,10 @@ bool CacheStrapper::loadList(std::list<RsItem *>& load)
|
||||
else
|
||||
{
|
||||
peerConnectState pca;
|
||||
mConnMgr->getFriendNetStatus(rscc->pid, pca);
|
||||
mPeerMgr->getFriendNetStatus(rscc->pid, pca);
|
||||
cd.pname = pca.name+" ("+pca.location+")";
|
||||
}
|
||||
#endif
|
||||
|
||||
cd.cid.type = rscc->cachetypeid;
|
||||
cd.cid.subid = rscc->cachesubid;
|
||||
|
@ -92,7 +92,7 @@ class CacheData
|
||||
public:
|
||||
|
||||
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
|
||||
std::string path; /// file system path where physical cache data is located
|
||||
std::string name;
|
||||
@ -408,6 +408,9 @@ bool operator<(const CachePair &a, const CachePair &b);
|
||||
* CacheStrapper: maintains a set of CacheSources, and CacheStores,
|
||||
* queries and updates as new information arrives.
|
||||
*/
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
class CacheStrapper: public pqiMonitor, public p3Config
|
||||
{
|
||||
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...)
|
||||
* @return
|
||||
*/
|
||||
CacheStrapper(p3ConnectMgr *cm);
|
||||
CacheStrapper(p3LinkMgr *lm);
|
||||
virtual ~CacheStrapper() { return; }
|
||||
|
||||
/************* from pqiMonitor *******************/
|
||||
@ -489,7 +492,7 @@ virtual bool loadList(std::list<RsItem *>& load);
|
||||
private:
|
||||
|
||||
/* these are static - so shouldn't need mutex */
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
std::map<uint16_t, CachePair> caches;
|
||||
|
||||
|
@ -424,7 +424,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
fi.root->row = 0;
|
||||
fi.root->name = data.pname ;
|
||||
fi.root->name = data.pid; // XXX Hack here - TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -24,12 +24,12 @@
|
||||
#include "dbase/fistore.h"
|
||||
#include "retroshare/rsexpr.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
|
||||
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),
|
||||
localId(ownid), localindex(NULL), cb(cb_in),mConnMgr(cnmgr)
|
||||
localId(ownid), localindex(NULL), cb(cb_in),mPeerMgr(cnmgr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -83,7 +83,7 @@ int FileIndexStore::loadCache(const CacheData &data)
|
||||
|
||||
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
|
||||
// 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;
|
||||
#endif
|
||||
/* set the name */
|
||||
finew->root->name = data.pname;
|
||||
finew->root->name = data.pid; // HACK HERE TODO XXX. name;
|
||||
|
||||
if (local)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class p3ConnectMgr ;
|
||||
class p3PeerMgr ;
|
||||
|
||||
#include "dbase/findex.h"
|
||||
#include "dbase/cachestrapper.h"
|
||||
@ -65,7 +65,7 @@ class FileIndexStore: public CacheStore
|
||||
{
|
||||
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 functions overloaded by cache implementor */
|
||||
@ -96,7 +96,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
|
||||
FileIndex *localindex;
|
||||
|
||||
NotifyBase *cb;
|
||||
p3ConnectMgr *mConnMgr ;
|
||||
p3PeerMgr *mPeerMgr ;
|
||||
};
|
||||
|
||||
|
||||
|
@ -27,7 +27,9 @@
|
||||
#include "dht/p3bitdht.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/udpstunner.h"
|
||||
|
@ -52,7 +52,7 @@
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
@ -1150,7 +1150,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
(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 */
|
||||
}
|
||||
@ -1245,7 +1245,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
|
||||
std::cerr << "ftController::FileRequest() adding peer: " << *it;
|
||||
std::cerr << std::endl;
|
||||
#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 */
|
||||
@ -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)
|
||||
{
|
||||
if (id == mConnMgr->getOwnId())
|
||||
if (id == mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::setPeerState() is Self";
|
||||
|
@ -30,9 +30,9 @@
|
||||
|
||||
//#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)
|
||||
:FileIndexStore(cs, cft, cb_in,cnmgr, ownid, cachedir)
|
||||
:FileIndexStore(cs, cft, cb_in, pm, ownid, cachedir)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -366,8 +366,8 @@ void ftFiMonitor::setSharedDirectories(const std::list<SharedDirInfo>& dirList)
|
||||
|
||||
|
||||
|
||||
ftCacheStrapper::ftCacheStrapper(p3ConnectMgr *cm)
|
||||
:CacheStrapper(cm)
|
||||
ftCacheStrapper::ftCacheStrapper(p3LinkMgr *lm)
|
||||
:CacheStrapper(lm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -33,7 +33,9 @@
|
||||
* So they work in the ft world.
|
||||
*/
|
||||
|
||||
class p3ConnectMgr ;
|
||||
class p3LinkMgr ;
|
||||
class p3PeerMgr ;
|
||||
|
||||
|
||||
#include "ft/ftsearch.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
@ -46,8 +48,7 @@ class p3ConnectMgr ;
|
||||
class ftFiStore: public FileIndexStore, public ftSearch
|
||||
{
|
||||
public:
|
||||
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
|
||||
p3ConnectMgr *,
|
||||
ftFiStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in, p3PeerMgr *pm,
|
||||
RsPeerId ownid, std::string cachedir);
|
||||
|
||||
/* overloaded search function */
|
||||
@ -89,7 +90,7 @@ virtual bool loadList(std::list<RsItem *>& load);
|
||||
class ftCacheStrapper: public CacheStrapper, public ftSearch
|
||||
{
|
||||
public:
|
||||
ftCacheStrapper(p3ConnectMgr *cm);
|
||||
ftCacheStrapper(p3LinkMgr *cm);
|
||||
|
||||
/* overloaded search function */
|
||||
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 "pqi/pqi.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
|
||||
@ -57,15 +57,15 @@ const int ftserverzone = 29539;
|
||||
***/
|
||||
|
||||
/* Setup */
|
||||
ftServer::ftServer(p3ConnectMgr *connMgr)
|
||||
ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
|
||||
: mP3iface(NULL),
|
||||
mConnMgr(connMgr),
|
||||
mLinkMgr(lm), mPeerMgr(pm),
|
||||
mCacheStrapper(NULL),
|
||||
mFiStore(NULL), mFiMon(NULL),
|
||||
mFtController(NULL), mFtExtra(NULL),
|
||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
||||
{
|
||||
mCacheStrapper = new ftCacheStrapper(connMgr);
|
||||
mCacheStrapper = new ftCacheStrapper(lm);
|
||||
}
|
||||
|
||||
void ftServer::setConfigDirectory(std::string path)
|
||||
@ -101,8 +101,8 @@ void ftServer::addConfigComponents(p3ConfigMgr *mgr)
|
||||
std::string ftServer::OwnId()
|
||||
{
|
||||
std::string ownId;
|
||||
if (mConnMgr)
|
||||
ownId = mConnMgr->getOwnId();
|
||||
if (mLinkMgr)
|
||||
ownId = mLinkMgr->getOwnId();
|
||||
return ownId;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||
/* setup FiStore/Monitor */
|
||||
std::string localcachedir = mConfigPath + "/cache/local";
|
||||
std::string remotecachedir = mConfigPath + "/cache/remote";
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
/* search/extras List */
|
||||
mFtExtra = new ftExtraList();
|
||||
@ -131,7 +131,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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(mFiStore, RS_FILE_HINTS_REMOTE);
|
||||
|
||||
mConnMgr->addMonitor(mFtController);
|
||||
mConnMgr->addMonitor(mCacheStrapper);
|
||||
mLinkMgr->addMonitor(mFtController);
|
||||
mLinkMgr->addMonitor(mCacheStrapper);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1052,9 +1052,6 @@ bool ftServer::handleCacheData()
|
||||
/* these go to the CacheStrapper! */
|
||||
CacheData data;
|
||||
data.pid = ci->PeerId();
|
||||
peerConnectState pca;
|
||||
mConnMgr->getFriendNetStatus(ci->PeerId(), pca);
|
||||
data.pname = pca.name;
|
||||
data.cid = CacheId(ci->cacheType, ci->cacheSubId);
|
||||
data.path = ci->file.path;
|
||||
data.name = ci->file.name;
|
||||
|
@ -69,6 +69,9 @@ class p3turtle;
|
||||
|
||||
class ftDwlQueue;
|
||||
|
||||
class p3PeerMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||
{
|
||||
|
||||
@ -78,7 +81,7 @@ class ftServer: public RsFiles, public ftDataSend, public RsThread
|
||||
/******************** Setup ************************************/
|
||||
/***************************************************************/
|
||||
|
||||
ftServer(p3ConnectMgr *connMgr);
|
||||
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||
|
||||
/* Assign important variables */
|
||||
void setConfigDirectory(std::string path);
|
||||
@ -264,9 +267,11 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||
* as each component is protected independently.
|
||||
*/
|
||||
|
||||
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
||||
p3ConnectMgr *mConnMgr;
|
||||
P3Interface *mP3iface; /* XXX THIS NEEDS PROTECTION */
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
ftCacheStrapper *mCacheStrapper;
|
||||
ftFiStore *mFiStore;
|
||||
ftFiMonitor *mFiMon;
|
||||
|
@ -331,7 +331,9 @@ HEADERS += pqi/authssl.h \
|
||||
pqi/authgpg.h \
|
||||
pqi/cleanupxpgp.h \
|
||||
pqi/p3cfgmgr.h \
|
||||
pqi/p3connmgr.h \
|
||||
pqi/p3peermgr.h \
|
||||
pqi/p3linkmgr.h \
|
||||
pqi/p3netmgr.h \
|
||||
pqi/p3dhtmgr.h \
|
||||
pqi/p3notify.h \
|
||||
pqi/p3upnpmgr.h \
|
||||
@ -360,7 +362,8 @@ HEADERS += pqi/authssl.h \
|
||||
pqi/pqissludp.h \
|
||||
pqi/pqistore.h \
|
||||
pqi/pqistreamer.h \
|
||||
pqi/sslfns.h
|
||||
pqi/sslfns.h \
|
||||
pqi/pqinetstatebox.h
|
||||
|
||||
HEADERS += rsserver/p3discovery.h \
|
||||
rsserver/p3face.h \
|
||||
@ -452,7 +455,9 @@ SOURCES += pqi/authgpg.cc \
|
||||
pqi/authssl.cc \
|
||||
pqi/cleanupxpgp.cc \
|
||||
pqi/p3cfgmgr.cc \
|
||||
pqi/p3connmgr.cc \
|
||||
pqi/p3peermgr.cc \
|
||||
pqi/p3linkmgr.cc \
|
||||
pqi/p3netmgr.cc \
|
||||
pqi/p3dhtmgr.cc \
|
||||
pqi/p3notify.cc \
|
||||
pqi/pqiarchive.cc \
|
||||
@ -473,7 +478,8 @@ SOURCES += pqi/authgpg.cc \
|
||||
pqi/pqissludp.cc \
|
||||
pqi/pqistore.cc \
|
||||
pqi/pqistreamer.cc \
|
||||
pqi/sslfns.cc
|
||||
pqi/sslfns.cc \
|
||||
pqi/pqinetstatebox.cc
|
||||
|
||||
SOURCES += rsserver/p3discovery.cc \
|
||||
rsserver/p3face-config.cc \
|
||||
|
@ -34,7 +34,6 @@
|
||||
|
||||
#include "pqinetwork.h"
|
||||
#include "authgpg.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
|
@ -29,7 +29,8 @@
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||
#include "tcponudp/tou.h"
|
||||
@ -87,19 +90,17 @@ peerAddrInfo::peerAddrInfo()
|
||||
|
||||
peerConnectState::peerConnectState()
|
||||
:id("unknown"),
|
||||
gpg_id("unknown"),
|
||||
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD),
|
||||
lastcontact(0),
|
||||
connecttype(0),
|
||||
lastavailable(0),
|
||||
lastattempt(0),
|
||||
name(""), location(""),
|
||||
name(""),
|
||||
state(0), actions(0),
|
||||
source(0),
|
||||
inConnAttempt(0)
|
||||
{
|
||||
sockaddr_clear(¤tlocaladdr);
|
||||
sockaddr_clear(¤tserveraddr);
|
||||
//sockaddr_clear(¤tlocaladdr);
|
||||
//sockaddr_clear(¤tserveraddr);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -108,12 +109,7 @@ std::string textPeerConnectState(peerConnectState &state)
|
||||
{
|
||||
std::ostringstream out;
|
||||
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();
|
||||
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 */
|
||||
mOwnState.id = AuthSSL::getAuthSSL()->OwnId();
|
||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
mOwnState.name = AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||
mOwnState.netMode = RS_NET_MODE_UDP;
|
||||
|
||||
// user decided.
|
||||
//mOwnState.netMode |= RS_NET_MODE_TRY_UPNP;
|
||||
|
||||
mAllowTunnelConnection = false;
|
||||
mDNSResolver = new DNSResolver;
|
||||
mDNSResolver = new DNSResolver();
|
||||
mRetryPeriod = MIN_RETRY_PERIOD;
|
||||
|
||||
lastGroupId = 1;
|
||||
@ -163,20 +167,8 @@ p3LinkMgr::p3LinkMgr()
|
||||
|
||||
void p3LinkMgr::setTunnelConnection(bool b)
|
||||
{
|
||||
bool changed = false;
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
if (mAllowTunnelConnection != b)
|
||||
changed = true;
|
||||
|
||||
mAllowTunnelConnection = b;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
mAllowTunnelConnection = b;
|
||||
}
|
||||
|
||||
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 */
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::shutdown()";
|
||||
std::cerr << "p3LinkMgr::shutdown() NOOP";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
mNetStatus = RS_NET_UNKNOWN;
|
||||
mNetInitTS = time(NULL);
|
||||
netStatusReset_locked();
|
||||
}
|
||||
netAssistFirewallShutdown();
|
||||
netAssistConnectShutdown();
|
||||
|
||||
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_true = false ;
|
||||
bool updatePeerAddr = false;
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called Connect!: id: " + id);
|
||||
if (success) {
|
||||
if (success)
|
||||
{
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with SUCCESS.");
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with FAILED.");
|
||||
}
|
||||
|
||||
if (id == getOwnId()) {
|
||||
if (id == getOwnId())
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Failed, connecting to own id: ");
|
||||
#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
|
||||
//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) &&
|
||||
(it->second.currentConnAddrAttempt.addr.sin_addr.s_addr
|
||||
== remote_peer_address.sin_addr.s_addr) &&
|
||||
(it->second.currentConnAddrAttempt.addr.sin_port
|
||||
== remote_peer_address.sin_port))
|
||||
{
|
||||
pqiIpAddress raddr;
|
||||
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;
|
||||
}
|
||||
{
|
||||
updatePeerAddr = true;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::connectResult() adding current peer address in list." << std::endl;
|
||||
it->second.ipAddrs.printAddrs(std::cerr);
|
||||
#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)
|
||||
netAssistFriend(id,true) ;
|
||||
if(should_netAssistFriend_false)
|
||||
@ -682,7 +729,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
bool isFriend = true;
|
||||
bool newAddrs;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
@ -691,9 +737,15 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
details.found = true;
|
||||
details.addrs = addrs;
|
||||
details.ts = now;
|
||||
|
||||
bool updateNetConfig = (source == RS_CB_PERSON);
|
||||
uint32_t peerVisibility = 0;
|
||||
uint32_t peerNetMode = 0;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
uint32_t ownNetMode = mNetMgr->getNetworkMode();
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
{
|
||||
/* Log */
|
||||
@ -752,9 +804,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
it->second.state |= RS_PEER_S_ONLINE;
|
||||
it->second.lastavailable = now;
|
||||
|
||||
/* if we are recieving these - the dht is definitely up.
|
||||
*/
|
||||
mNetFlags.mDhtOk = true;
|
||||
}
|
||||
else if (source == RS_CB_DISC)
|
||||
{
|
||||
@ -774,8 +823,6 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
mStatusChanged = true;
|
||||
}
|
||||
|
||||
/* not updating VIS status??? */
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
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!)
|
||||
* 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)
|
||||
{
|
||||
it->second.netMode = RS_NET_MODE_EXT;
|
||||
peerNetMode = RS_NET_MODE_EXT;
|
||||
}
|
||||
else if (flags & RS_NET_FLAGS_STABLE_UDP)
|
||||
{
|
||||
it->second.netMode = RS_NET_MODE_UDP;
|
||||
peerNetMode = RS_NET_MODE_UDP;
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.netMode = RS_NET_MODE_UNREACHABLE;
|
||||
peerNetMode = RS_NET_MODE_UNREACHABLE;
|
||||
}
|
||||
|
||||
|
||||
/* always update VIS status */
|
||||
if (flags & RS_NET_FLAGS_USE_DISC)
|
||||
{
|
||||
it->second.visState &= (~RS_VIS_STATE_NODISC);
|
||||
peerVisibility &= (~RS_VIS_STATE_NODISC);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.visState |= RS_VIS_STATE_NODISC;
|
||||
peerVisibility |= RS_VIS_STATE_NODISC;
|
||||
}
|
||||
|
||||
if (flags & RS_NET_FLAGS_USE_DHT)
|
||||
{
|
||||
it->second.visState &= (~RS_VIS_STATE_NODHT);
|
||||
peerVisibility &= (~RS_VIS_STATE_NODHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second.visState |= RS_VIS_STATE_NODHT;
|
||||
peerVisibility |= RS_VIS_STATE_NODHT;
|
||||
}
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* 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) ||
|
||||
(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;
|
||||
}
|
||||
}
|
||||
else if (mOwnState.netMode & RS_NET_MODE_UNREACHABLE)
|
||||
else if (ownNetMode & RS_NET_MODE_UNREACHABLE)
|
||||
{
|
||||
if (details.type & RS_NET_CONN_TCP_EXTERNAL)
|
||||
{
|
||||
@ -890,8 +942,15 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
||||
return;
|
||||
}
|
||||
|
||||
newAddrs = it->second.ipAddrs.updateAddrs(addrs);
|
||||
|
||||
} /****** STACK UNLOCK MUTEX *******/
|
||||
|
||||
bool newAddrs = mPeerMgr->updateAddressList(id, addrs);
|
||||
if (updateNetConfig)
|
||||
{
|
||||
mPeerMgr -> setVisState(id, peerVisibility);
|
||||
mPeerMgr -> setNetworkMode(id, peerNetMode);
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::peerStatus()" << " id: " << id;
|
||||
@ -1056,68 +1115,101 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
|
||||
|
||||
bool p3LinkMgr::retryConnectTCP(const std::string &id)
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* push all available addresses onto the connect addr stack...
|
||||
* with the following exceptions:
|
||||
* - check local address, see if it is the same network as us
|
||||
- check address age. don't add old ones
|
||||
*/
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
|
||||
#endif
|
||||
|
||||
if (id == getOwnId()) {
|
||||
#ifdef CONN_DEBUG
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: ");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* look up the id */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
/* Check if we should retry first */
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
/* push all available addresses onto the connect addr stack...
|
||||
* with the following exceptions:
|
||||
* - check local address, see if it is the same network as us
|
||||
- check address age. don't add old ones
|
||||
*/
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer is not Friend" << std::endl;
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
|
||||
if (id == getOwnId())
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: ");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* look up the id */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer is not Friend" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* if already connected -> done */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl;
|
||||
#endif
|
||||
if (it->second.connecttype & RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /****** END of LOCKED ******/
|
||||
|
||||
/* If we reach here, must retry .... extract the required info from p3PeerMgr */
|
||||
|
||||
struct sockaddr_in lAddr;
|
||||
struct sockaddr_in eAddr;
|
||||
pqiIpAddrSet histAddrs;
|
||||
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 */
|
||||
return locked_ConnectAttempt_Complete(&(it->second));
|
||||
}
|
||||
}
|
||||
|
||||
/* if already connected -> done */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl;
|
||||
#endif
|
||||
if (it->second.connecttype & RS_NET_CONN_TUNNEL) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
/* UDP automatically searches -> no need to push start */
|
||||
|
||||
locked_ConnectAttempt_CurrentAddresses(&(it->second));
|
||||
locked_ConnectAttempt_HistoricalAddresses(&(it->second));
|
||||
locked_ConnectAttempt_AddDynDNS(&(it->second));
|
||||
locked_ConnectAttempt_AddTunnel(&(it->second));
|
||||
|
||||
/* finish it off */
|
||||
return locked_ConnectAttempt_Complete(&(it->second));
|
||||
}
|
||||
|
||||
|
||||
#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
|
||||
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 << rs_inet_ntoa(mOwnState.currentlocaladdr.sin_addr);
|
||||
std::cerr << rs_inet_ntoa(mLocalAddress.sin_addr);
|
||||
std::cerr << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (sameNet(&(mOwnState.currentlocaladdr.sin_addr), &(addr->sin_addr)))
|
||||
if (sameNet(&(mLocalAddress.sin_addr), &(addr->sin_addr)))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
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.
|
||||
/* try "current addresses" first */
|
||||
if (locked_CheckPotentialAddr(&(peer->currentlocaladdr), 0))
|
||||
if ((localAddr) && (locked_CheckPotentialAddr(localAddr, 0)))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding tcp connection attempt: ";
|
||||
std::cerr << "Current Local Addr: " << rs_inet_ntoa(peer->currentlocaladdr.sin_addr);
|
||||
std::cerr << ":" << ntohs(peer->currentlocaladdr.sin_port);
|
||||
std::cerr << "Current Local Addr: " << rs_inet_ntoa(localAddr->sin_addr);
|
||||
std::cerr << ":" << ntohs(localAddr->sin_port);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.addr = peer->currentlocaladdr;
|
||||
pca.addr = *localAddr;
|
||||
pca.type = RS_NET_CONN_TCP_LOCAL;
|
||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||
pca.ts = time(NULL);
|
||||
@ -1236,16 +1328,16 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer)
|
||||
addAddressIfUnique(peer->connAddrs, pca);
|
||||
}
|
||||
|
||||
if (locked_CheckPotentialAddr(&(peer->currentserveraddr), 0))
|
||||
if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0)))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding tcp connection attempt: ";
|
||||
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(peer->currentserveraddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(peer->currentserveraddr.sin_port);
|
||||
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(serverAddr->sin_addr);
|
||||
std::cerr << ":" << ntohs(serverAddr->sin_port);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.addr = peer->currentserveraddr;
|
||||
pca.addr = *serverAddr;
|
||||
pca.type = RS_NET_CONN_TCP_EXTERNAL;
|
||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||
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 */
|
||||
/* try local addresses first */
|
||||
std::list<pqiIpAddress>::iterator ait;
|
||||
std::list<pqiIpAddress>::const_iterator ait;
|
||||
time_t now = time(NULL);
|
||||
|
||||
for(ait = peer->ipAddrs.mLocal.mAddrs.begin();
|
||||
ait != peer->ipAddrs.mLocal.mAddrs.end(); ait++)
|
||||
for(ait = ipAddrs.mLocal.mAddrs.begin();
|
||||
ait != ipAddrs.mLocal.mAddrs.end(); ait++)
|
||||
{
|
||||
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();
|
||||
ait != peer->ipAddrs.mExt.mAddrs.end(); ait++)
|
||||
for(ait = ipAddrs.mExt.mAddrs.begin();
|
||||
ait != ipAddrs.mExt.mAddrs.end(); ait++)
|
||||
{
|
||||
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 */
|
||||
if (!peer->dyndns.empty())
|
||||
if (!dyndns.empty())
|
||||
{
|
||||
struct in_addr addr;
|
||||
u_short port = peer->currentserveraddr.sin_port ? peer->currentserveraddr.sin_port : peer->currentlocaladdr.sin_port;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Looking up DynDNS address" << std::endl;
|
||||
#endif
|
||||
if (port)
|
||||
{
|
||||
if(mDNSResolver->getIPAddressFromString (std::string(peer->dyndns.c_str()), addr))
|
||||
if(mDNSResolver->getIPAddressFromString(dyndns, addr))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding tcp connection attempt: ";
|
||||
@ -1335,7 +1426,7 @@ void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer)
|
||||
peerConnectAddress pca;
|
||||
pca.addr.sin_family = AF_INET;
|
||||
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;
|
||||
//for the delay, we add a random time and some more time when the friend list is big
|
||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||
@ -1355,21 +1446,21 @@ void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer)
|
||||
|
||||
void p3LinkMgr::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
|
||||
{
|
||||
if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection)
|
||||
{
|
||||
if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding TUNNEL Connection Attempt";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.type = RS_NET_CONN_TUNNEL;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
peerConnectAddress pca;
|
||||
pca.type = RS_NET_CONN_TUNNEL;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
|
||||
sockaddr_clear(&pca.addr);
|
||||
sockaddr_clear(&pca.addr);
|
||||
|
||||
addAddressIfUnique(peer->connAddrs, pca);
|
||||
}
|
||||
addAddressIfUnique(peer->connAddrs, pca);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1403,44 +1494,45 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
|
||||
|
||||
/* flag as last attempt to prevent loop */
|
||||
//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 */
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Remaining ConnAddr Count: " << peer->connAddrs.size();
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Remaining ConnAddr Count: " << peer->connAddrs.size();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/* start a connection attempt */
|
||||
if (peer->connAddrs.size() > 0)
|
||||
if (peer->connAddrs.size() > 0)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
|
||||
#ifdef CONN_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
|
||||
out << std::endl;
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() ConnAddr Count: " << peer->connAddrs.size();
|
||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() ConnAddr Count: " << peer->connAddrs.size();
|
||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||
std::cerr << out.str() << std::endl;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
peer->actions |= RS_PEER_CONNECT_REQ;
|
||||
mStatusChanged = true;
|
||||
peer->actions |= RS_PEER_CONNECT_REQ;
|
||||
mStatusChanged = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
|
||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||
#ifdef CONN_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
|
||||
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
|
||||
std::cerr << out.str() << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
@ -40,43 +40,6 @@
|
||||
class ExtAddrFinder ;
|
||||
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 ... */
|
||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||
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_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! */
|
||||
|
||||
class peerAddrInfo
|
||||
@ -137,7 +91,7 @@ class peerConnectState
|
||||
//std::string gpg_id;
|
||||
|
||||
//uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
||||
uint32_t visState; /* STD, GRAY, DARK */
|
||||
//uint32_t visState; /* STD, GRAY, DARK */
|
||||
|
||||
//struct sockaddr_in localaddr, serveraddr;
|
||||
|
||||
@ -146,19 +100,21 @@ class peerConnectState
|
||||
//struct sockaddr_in currentserveraddr; /* Mandatory */
|
||||
//std::string dyndns;
|
||||
|
||||
//time_t lastcontact;
|
||||
|
||||
/* list of addresses from various sources */
|
||||
//pqiIpAddrSet ipAddrs;
|
||||
|
||||
/***** Below here not stored permanently *****/
|
||||
|
||||
time_t lastcontact;
|
||||
|
||||
uint32_t connecttype; // RS_NET_CONN_TCP_ALL / RS_NET_CONN_UDP_ALL
|
||||
time_t lastavailable;
|
||||
time_t lastattempt;
|
||||
|
||||
std::string name;
|
||||
std::string location;
|
||||
|
||||
//std::string location;
|
||||
|
||||
uint32_t state;
|
||||
uint32_t actions;
|
||||
@ -180,6 +136,9 @@ class p3tunnel;
|
||||
class RsPeerGroupItem;
|
||||
class RsGroupInfo;
|
||||
|
||||
class p3PeerMgr;
|
||||
class p3NetMgr;
|
||||
|
||||
std::string textPeerConnectState(peerConnectState &state);
|
||||
|
||||
|
||||
@ -187,17 +146,17 @@ class p3LinkMgr: public pqiConnectCb
|
||||
{
|
||||
public:
|
||||
|
||||
p3LinkMgr();
|
||||
p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr);
|
||||
|
||||
void tick();
|
||||
|
||||
/*************** Setup ***************************/
|
||||
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||
void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
|
||||
//void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||
//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 ****************/
|
||||
bool shutdown(); /* blocking shutdown call */
|
||||
@ -207,20 +166,21 @@ bool retryConnect(const std::string &id);
|
||||
void setTunnelConnection(bool b);
|
||||
bool getTunnelConnection();
|
||||
|
||||
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
||||
bool setLocalAddress(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 updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
||||
//void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
||||
//bool setLocalAddress(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 updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
|
||||
|
||||
bool setNetworkMode(const std::string &id, uint32_t netMode);
|
||||
bool setVisState(const std::string &id, uint32_t visState);
|
||||
//bool setNetworkMode(const std::string &id, uint32_t netMode);
|
||||
//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 */
|
||||
bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
||||
uint32_t visState = RS_VIS_STATE_STD , time_t lastContact = 0);
|
||||
bool addFriend(const std::string &ssl_id);
|
||||
//, 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);
|
||||
|
||||
@ -230,12 +190,16 @@ bool removeFriend(const std::string &ssl_id);
|
||||
const std::string getOwnId();
|
||||
bool getOwnNetStatus(peerConnectState &state);
|
||||
|
||||
struct sockaddr_in getLocalAddress();
|
||||
|
||||
bool isOnline(const std::string &ssl_id);
|
||||
bool getFriendNetStatus(const std::string &id, peerConnectState &state);
|
||||
bool getOthersNetStatus(const std::string &id, peerConnectState &state);
|
||||
|
||||
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 *****************/
|
||||
@ -286,20 +250,18 @@ bool retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr);
|
||||
/* connect attempts TCP */
|
||||
bool retryConnectTCP(const std::string &id);
|
||||
|
||||
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer);
|
||||
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer);
|
||||
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer);
|
||||
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr);
|
||||
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
|
||||
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
|
||||
void locked_ConnectAttempt_AddTunnel(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,
|
||||
peerConnectAddress &pca);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
// These should have there own Mutex Protection,
|
||||
//p3tunnel *mP3tunnel;
|
||||
@ -307,6 +269,8 @@ private:
|
||||
|
||||
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3NetMgr *mNetMgr;
|
||||
|
||||
RsMutex mLinkMtx; /* protects below */
|
||||
|
||||
@ -314,6 +278,8 @@ private:
|
||||
|
||||
bool mStatusChanged;
|
||||
|
||||
struct sockaddr_in mLocalAddress;
|
||||
|
||||
std::list<pqiMonitor *> clients;
|
||||
|
||||
bool mAllowTunnelConnection;
|
||||
@ -322,7 +288,7 @@ private:
|
||||
//bool mUpnpAddrValid, mStunAddrValid;
|
||||
//struct sockaddr_in mUpnpExtAddr;
|
||||
|
||||
peerConnectState mOwnState;
|
||||
//peerConnectState mOwnState;
|
||||
|
||||
std::map<std::string, peerConnectState> mFriendList;
|
||||
std::map<std::string, peerConnectState> mOthersList;
|
||||
|
@ -25,11 +25,12 @@
|
||||
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsrandom.h"
|
||||
|
||||
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||
//#include "tcponudp/tou.h"
|
||||
#include "util/extaddrfinder.h"
|
||||
#include "util/dnsresolver.h"
|
||||
|
||||
@ -106,8 +107,8 @@ void pqiNetStatus::print(std::ostream &out)
|
||||
}
|
||||
|
||||
|
||||
p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
||||
:mPeerMgr(peerMgr), mNetMtx("p3NetMgr"),
|
||||
p3NetMgr::p3NetMgr()
|
||||
:mPeerMgr(NULL), mLinkMgr(NULL), mNetMtx("p3NetMgr"),
|
||||
mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false)
|
||||
{
|
||||
|
||||
@ -122,6 +123,7 @@ p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
||||
|
||||
mNetFlags = pqiNetStatus();
|
||||
mOldNetFlags = pqiNetStatus();
|
||||
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
@ -133,71 +135,21 @@ p3NetMgr::p3NetMgr(p3PeerMgr *peerMgr)
|
||||
return;
|
||||
}
|
||||
|
||||
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)
|
||||
void p3NetMgr::setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
mUseExtAddrFinder = b;
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3NetMgr: setIPServers to " << b << std::endl ;
|
||||
#endif
|
||||
|
||||
mPeerMgr = peerMgr;
|
||||
mLinkMgr = linkMgr;
|
||||
}
|
||||
|
||||
void p3NetMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
||||
void p3NetMgr::setDhtMgr(p3DhtMgr *dhtMgr)
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
/* only change TRY flags */
|
||||
mDhtMgr = dhtMgr;
|
||||
}
|
||||
|
||||
#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));
|
||||
}
|
||||
}
|
||||
void p3NetMgr::setStunners(p3Stunner *dhtStunner, p3Stunner *proxyStunner)
|
||||
{
|
||||
mDhtStunner = dhtStunner;
|
||||
mProxyStunner = proxyStunner;
|
||||
}
|
||||
|
||||
|
||||
@ -266,25 +218,6 @@ void p3NetMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
||||
|
||||
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
|
||||
std::cerr << "p3NetMgr::netReset() Called" << std::endl;
|
||||
#endif
|
||||
@ -310,7 +243,6 @@ void p3NetMgr::netReset()
|
||||
std::cerr << "p3NetMgr::netReset() resetting NetStatus" << std::endl;
|
||||
#endif
|
||||
|
||||
/* reset udp network - handled by tou_init! */
|
||||
/* reset tcp network - if necessary */
|
||||
{
|
||||
/* 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()
|
||||
{
|
||||
//std::cerr << "p3NetMgr::netStatusReset()" << std::endl;;
|
||||
@ -364,6 +289,33 @@ void p3NetMgr::netStatusReset_locked()
|
||||
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()
|
||||
{
|
||||
/* startup stuff */
|
||||
@ -376,7 +328,6 @@ void p3NetMgr::netStartup()
|
||||
#endif
|
||||
|
||||
netDhtInit();
|
||||
netUdpInit();
|
||||
|
||||
/* decide which net setup mode we're going into
|
||||
*/
|
||||
@ -439,23 +390,7 @@ void p3NetMgr::tick()
|
||||
netTick();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#define STARTUP_DELAY 5
|
||||
|
||||
|
||||
void p3NetMgr::netTick()
|
||||
@ -472,13 +407,15 @@ void p3NetMgr::netTick()
|
||||
checkNetAddress() ;
|
||||
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;
|
||||
time_t age = time(NULL) - mNetInitTS;
|
||||
netStatus = mNetStatus;
|
||||
age = time(NULL) - mNetInitTS;
|
||||
|
||||
mNetMtx.unlock(); /* UNLOCK MUTEX */
|
||||
/* start tcp network - if necessary */
|
||||
}
|
||||
|
||||
switch(netStatus)
|
||||
{
|
||||
@ -498,7 +435,6 @@ void p3NetMgr::netTick()
|
||||
/* add a small delay to stop restarting straight after a RESET
|
||||
* This is so can we shutdown cleanly
|
||||
*/
|
||||
#define STARTUP_DELAY 5
|
||||
if (age < STARTUP_DELAY)
|
||||
{
|
||||
#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;
|
||||
#endif
|
||||
netExtCheck();
|
||||
//netDhtInit();
|
||||
break;
|
||||
|
||||
case RS_NET_DONE:
|
||||
@ -835,103 +770,9 @@ void p3NetMgr::netExtCheck()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3NetMgr::networkConsistencyCheck()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
/**********************************************************************************************
|
||||
************************************** Interfaces *****************************************
|
||||
**********************************************************************************************/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
******************** Interfaces ***********************************
|
||||
**********************************************************************
|
||||
**********************************************************************/
|
||||
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 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)
|
||||
{
|
||||
@ -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/p3peermgr.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
class ExtAddrFinder ;
|
||||
@ -80,12 +78,22 @@ class pqiNetStatus
|
||||
}
|
||||
};
|
||||
|
||||
class p3PeerMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
class rsUdpStack;
|
||||
class UdpStunner;
|
||||
class p3BitDht;
|
||||
class UdpRelayReceiver;
|
||||
|
||||
|
||||
class p3NetMgr
|
||||
{
|
||||
public:
|
||||
|
||||
p3NetMgr(p3PeerMgr *peerMgr);
|
||||
p3NetMgr();
|
||||
|
||||
void setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
|
||||
|
||||
void tick();
|
||||
|
||||
@ -181,8 +189,6 @@ void netUnreachableCheck();
|
||||
void networkConsistencyCheck();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
// These should have there own Mutex Protection,
|
||||
ExtAddrFinder *mExtAddrFinder ;
|
||||
@ -193,7 +199,21 @@ private:
|
||||
|
||||
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 */
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "pqi/authssl.h"
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||
//#include "tcponudp/tou.h"
|
||||
@ -73,11 +75,10 @@ void printConnectState(std::ostream &out, peerState &peer);
|
||||
peerState::peerState()
|
||||
:id("unknown"),
|
||||
gpg_id("unknown"),
|
||||
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD),
|
||||
lastcontact(0)
|
||||
netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD), lastcontact(0)
|
||||
{
|
||||
sockaddr_clear(¤tlocaladdr);
|
||||
sockaddr_clear(¤tserveraddr);
|
||||
sockaddr_clear(&localaddr);
|
||||
sockaddr_clear(&serveraddr);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -88,10 +89,10 @@ std::string textPeerConnectState(peerState &state)
|
||||
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;
|
||||
out << "laddr: " << rs_inet_ntoa(state.localaddr.sin_addr)
|
||||
<< ":" << ntohs(state.localaddr.sin_port) << std::endl;
|
||||
out << "eaddr: " << rs_inet_ntoa(state.serveraddr.sin_addr)
|
||||
<< ":" << ntohs(state.serveraddr.sin_port) << std::endl;
|
||||
|
||||
std::string output = out.str();
|
||||
return output;
|
||||
@ -127,30 +128,52 @@ p3PeerMgr::p3PeerMgr()
|
||||
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 *******/
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3PeerMgr::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 << "p3PeerMgr::setOwnNetworkMode() :";
|
||||
std::cerr << " Existing netMode: " << mOwnState.netMode;
|
||||
std::cerr << " Input netMode: " << netMode;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mOwnState.netMode = (netMode & RS_NET_MODE_ACTUAL);
|
||||
mOwnState.visState = visState;
|
||||
|
||||
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
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,
|
||||
@ -606,20 +563,20 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
|
||||
bool changed = false;
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
if (mOwnState.currentlocaladdr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
||||
mOwnState.currentlocaladdr.sin_port != addr.sin_port)
|
||||
if (mOwnState.localaddr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
||||
mOwnState.localaddr.sin_port != addr.sin_port)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
||||
mOwnState.currentlocaladdr = addr;
|
||||
mOwnState.localaddr = addr;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
mNetMgr->netReset();
|
||||
mNetMgr->setLocalAddress(addr);
|
||||
|
||||
#ifdef CONN_DEBUG_RESET
|
||||
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->second.currentlocaladdr = addr;
|
||||
it->second.localaddr = addr;
|
||||
|
||||
#if 0
|
||||
//update ip address list
|
||||
@ -662,10 +619,12 @@ bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
|
||||
{
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
mOwnState.currentserveraddr = addr;
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
mOwnState.serveraddr = addr;
|
||||
}
|
||||
|
||||
mNetMgr->netExtReset();
|
||||
mNetMgr->setExtAddress(addr);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -685,7 +644,7 @@ bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
|
||||
}
|
||||
|
||||
/* "it" points to peer */
|
||||
it->second.currentserveraddr = addr;
|
||||
it->second.serveraddr = addr;
|
||||
|
||||
#if 0
|
||||
//update ip address list
|
||||
@ -774,19 +733,58 @@ bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &
|
||||
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)
|
||||
{
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
uint32_t visState;
|
||||
uint32_t oldNetMode;
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
visState = mOwnState.visState;
|
||||
oldNetMode = mOwnState.netMode;
|
||||
}
|
||||
|
||||
setOwnNetConfig(netMode, visState);
|
||||
setOwnNetworkMode(netMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -835,12 +833,7 @@ bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState)
|
||||
{
|
||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||
{
|
||||
uint32_t netMode;
|
||||
{
|
||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||
netMode = mOwnState.netMode;
|
||||
}
|
||||
setOwnNetConfig(netMode, visState);
|
||||
setOwnVisState(visState);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -873,11 +866,11 @@ bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState)
|
||||
if(dht_state)
|
||||
{
|
||||
/* hidden from DHT world */
|
||||
netAssistFriend(id, false);
|
||||
mLinkMgr->setFriendVisibility(id, false);
|
||||
}
|
||||
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 */
|
||||
cleanup = false;
|
||||
bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
|
||||
bool allowTunnelConnection = mLinkMgr->getTunnelConnection();
|
||||
|
||||
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
|
||||
|
||||
@ -939,8 +934,8 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
item->visState = mOwnState.visState;
|
||||
item->lastContact = mOwnState.lastcontact;
|
||||
|
||||
item->currentlocaladdr = mOwnState.currentlocaladdr;
|
||||
item->currentremoteaddr = mOwnState.currentserveraddr;
|
||||
item->currentlocaladdr = mOwnState.localaddr;
|
||||
item->currentremoteaddr = mOwnState.serveraddr;
|
||||
item->dyndns = mOwnState.dyndns;
|
||||
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||
@ -962,16 +957,16 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
item->clear();
|
||||
|
||||
item->pid = it->first;
|
||||
item->gpg_id = (it->second).gpg_id;
|
||||
item->location = (it->second).location;
|
||||
item->netMode = (it->second).netMode;
|
||||
item->gpg_id = (it->second).gpg_id;
|
||||
item->location = (it->second).location;
|
||||
item->netMode = (it->second).netMode;
|
||||
item->visState = (it->second).visState;
|
||||
item->lastContact = (it->second).lastcontact;
|
||||
item->currentlocaladdr = (it->second).currentlocaladdr;
|
||||
item->currentremoteaddr = (it->second).currentserveraddr;
|
||||
item->dyndns = (it->second).dyndns;
|
||||
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||
item->currentlocaladdr = (it->second).localaddr;
|
||||
item->currentremoteaddr = (it->second).serveraddr;
|
||||
item->dyndns = (it->second).dyndns;
|
||||
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||
|
||||
saveData.push_back(item);
|
||||
saveCleanupList.push_back(item);
|
||||
@ -988,7 +983,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "USE_EXTR_IP_FINDER" ;
|
||||
kv.value = (mUseExtAddrFinder)?"TRUE":"FALSE" ;
|
||||
kv.value = (useExtAddrFinder)?"TRUE":"FALSE" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
@ -1003,7 +998,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
||||
|
||||
RsTlvKeyValue kv2;
|
||||
kv2.key = "ALLOW_TUNNEL_CONNECTION" ;
|
||||
kv2.value = (mAllowTunnelConnection)?"TRUE":"FALSE" ;
|
||||
kv2.value = (allowTunnelConnection)?"TRUE":"FALSE" ;
|
||||
vitem2->tlvkvs.pairs.push_back(kv2) ;
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
@ -1040,6 +1035,10 @@ void p3PeerMgr::saveDone()
|
||||
bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||
{
|
||||
|
||||
// DEFAULTS.
|
||||
bool useExtAddrFinder = true;
|
||||
bool allowTunnelConnection = true;
|
||||
|
||||
if (load.size() == 0) {
|
||||
std::cerr << "p3PeerMgr::loadList() list is empty, it may be a configuration problem." << std::endl;
|
||||
return false;
|
||||
@ -1066,9 +1065,11 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* add ownConfig */
|
||||
setOwnNetConfig(pitem->netMode, pitem->visState);
|
||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||
setOwnNetworkMode(pitem->netMode);
|
||||
setOwnVisState(pitem->visState);
|
||||
|
||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1078,18 +1079,20 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* ************* */
|
||||
addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, pitem->lastContact);
|
||||
setLocation(pitem->pid, pitem->location);
|
||||
}
|
||||
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
setDynDNS (pitem->pid, pitem->dyndns);
|
||||
addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, pitem->lastContact);
|
||||
setLocation(pitem->pid, pitem->location);
|
||||
}
|
||||
|
||||
setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
setDynDNS (pitem->pid, pitem->dyndns);
|
||||
|
||||
/* convert addresses */
|
||||
pqiIpAddrSet addrs;
|
||||
addrs.mLocal.extractFromTlv(pitem->localAddrList);
|
||||
addrs.mExt.extractFromTlv(pitem->extAddrList);
|
||||
updateAddressList(pitem->pid, addrs);
|
||||
|
||||
updateAddressList(pitem->pid, addrs);
|
||||
|
||||
delete(*it);
|
||||
|
||||
@ -1109,11 +1112,11 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||
if(kit->key == "USE_EXTR_IP_FINDER") {
|
||||
mUseExtAddrFinder = (kit->value == "TRUE");
|
||||
std::cerr << "setting use_extr_addr_finder to " << mUseExtAddrFinder << std::endl ;
|
||||
useExtAddrFinder = (kit->value == "TRUE");
|
||||
std::cerr << "setting use_extr_addr_finder to " << useExtAddrFinder << std::endl ;
|
||||
} else if (kit->key == "ALLOW_TUNNEL_CONNECTION") {
|
||||
mAllowTunnelConnection = (kit->value == "TRUE");
|
||||
std::cerr << "setting allow_tunnel_connection to " << mAllowTunnelConnection << std::endl ;
|
||||
allowTunnelConnection = (kit->value == "TRUE");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
void printConnectState(std::ostream &out, peerState &peer)
|
||||
{
|
||||
@ -1227,6 +1234,8 @@ void printConnectState(std::ostream &out, peerState &peer)
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
|
@ -70,8 +70,6 @@ const uint32_t RS_NET_MODE_UDP = 0x0004;
|
||||
const uint32_t RS_NET_MODE_UNREACHABLE = 0x0008;
|
||||
|
||||
|
||||
|
||||
|
||||
/* flags of peerStatus */
|
||||
const uint32_t RS_NET_FLAGS_USE_DISC = 0x0001;
|
||||
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_TRUSTS_ME = 0x0020;
|
||||
|
||||
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */
|
||||
|
||||
class peerState
|
||||
{
|
||||
public:
|
||||
@ -93,41 +89,17 @@ class peerState
|
||||
uint32_t netMode; /* EXT / UPNP / UDP / INVALID */
|
||||
uint32_t visState; /* STD, GRAY, DARK */
|
||||
|
||||
struct sockaddr_in localaddr, serveraddr;
|
||||
struct sockaddr_in localaddr;
|
||||
struct sockaddr_in serveraddr;
|
||||
std::string dyndns;
|
||||
|
||||
//used to store current ip (for config and connection management)
|
||||
struct sockaddr_in currentlocaladdr; /* Mandatory */
|
||||
struct sockaddr_in currentserveraddr; /* Mandatory */
|
||||
std::string dyndns;
|
||||
|
||||
time_t lastcontact;
|
||||
time_t lastcontact;
|
||||
|
||||
/* list of addresses from various sources */
|
||||
pqiIpAddrSet ipAddrs;
|
||||
|
||||
/***** Below here not stored permanently *****/
|
||||
|
||||
std::string name;
|
||||
std::string location;
|
||||
|
||||
//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;
|
||||
|
||||
std::string name;
|
||||
|
||||
};
|
||||
|
||||
@ -136,23 +108,32 @@ class RsGroupInfo;
|
||||
|
||||
std::string textPeerState(peerState &state);
|
||||
|
||||
class p3LinkMgr;
|
||||
class p3NetMgr;
|
||||
|
||||
class p3PeerMgr: public pqiConnectCb, public p3Config
|
||||
|
||||
class p3PeerMgr: public p3Config
|
||||
{
|
||||
public:
|
||||
|
||||
p3PeerMgr();
|
||||
|
||||
void setManagers(p3LinkMgr *linkMgr, p3NetMgr *netMgr);
|
||||
|
||||
|
||||
void tick();
|
||||
|
||||
/*************** External Control ****************/
|
||||
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 setExtAddress(const std::string &id, struct sockaddr_in addr);
|
||||
bool setDynDNS(const std::string &id, const std::string &dyndns);
|
||||
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 setVisState(const std::string &id, uint32_t visState);
|
||||
@ -214,6 +195,12 @@ void tickMonitors();
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
/*****************************************************************/
|
||||
|
||||
/* other important managers */
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
p3NetMgr *mNetMgr;
|
||||
|
||||
|
||||
private:
|
||||
RsMutex mPeerMtx; /* protects below */
|
||||
|
||||
|
@ -84,7 +84,7 @@ uint32_t state;
|
||||
uint32_t actions;
|
||||
};
|
||||
|
||||
class p3ConnectMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
/*!
|
||||
* This class should be implemented
|
||||
@ -96,13 +96,13 @@ class p3ConnectMgr;
|
||||
class pqiMonitor
|
||||
{
|
||||
public:
|
||||
pqiMonitor() :mConnMgr(NULL) { return; }
|
||||
pqiMonitor() :mLinkMgr(NULL) { return; }
|
||||
virtual ~pqiMonitor() { return; }
|
||||
|
||||
/*!
|
||||
* 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
|
||||
@ -124,7 +124,7 @@ virtual void statusChanged() {};
|
||||
//virtual void peerStatus(std::string id, uint32_t mode) = 0;
|
||||
|
||||
protected:
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -654,7 +654,7 @@ bool getPreferredInterface(struct in_addr &prefAddr) // returns best addr.
|
||||
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
|
||||
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)
|
||||
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.
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
#include <sstream>
|
||||
@ -185,11 +185,10 @@ int pqipersongrp::init_listener()
|
||||
{
|
||||
/* extract details from
|
||||
*/
|
||||
peerConnectState state;
|
||||
mConnMgr->getOwnNetStatus(state);
|
||||
|
||||
struct sockaddr_in laddr = mLinkMgr->getLocalAddress();
|
||||
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
pqil = createListener(state.currentlocaladdr);
|
||||
pqil = createListener(laddr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -325,19 +324,19 @@ void pqipersongrp::statusChanged()
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
/* get address from p3connmgr */
|
||||
if (!mConnMgr) {
|
||||
if (!mLinkMgr) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* check for active connections and start waiting id's */
|
||||
std::list<std::string> peers;
|
||||
mConnMgr->getFriendList(peers);
|
||||
mLinkMgr->getFriendList(peers);
|
||||
|
||||
/* count connection attempts */
|
||||
std::list<std::string>::iterator peer;
|
||||
for (peer = peers.begin(); peer != peers.end(); peer++) {
|
||||
peerConnectState state;
|
||||
if (mConnMgr->getFriendNetStatus(*peer, state) == false) {
|
||||
if (mLinkMgr->getFriendNetStatus(*peer, state) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -485,7 +484,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||
#endif
|
||||
|
||||
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
if (id == mConnMgr->getOwnId()) {
|
||||
if (id == mLinkMgr->getOwnId()) {
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << "pqipersongrp::connectPeer() Failed, connecting to own id." << std::endl;
|
||||
#endif
|
||||
@ -503,7 +502,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||
|
||||
|
||||
/* get address from p3connmgr */
|
||||
if (!mConnMgr)
|
||||
if (!mLinkMgr)
|
||||
return 0;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
@ -539,7 +538,7 @@ int pqipersongrp::connectPeer(std::string id
|
||||
uint32_t timeout;
|
||||
uint32_t type;
|
||||
|
||||
if (!mConnMgr->connectAttempt(id, addr, delay, period, type))
|
||||
if (!mLinkMgr->connectAttempt(id, addr, delay, period, type))
|
||||
{
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::connectPeer() No Net Address";
|
||||
@ -621,10 +620,10 @@ bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success
|
||||
}
|
||||
|
||||
|
||||
if (mConnMgr)
|
||||
mConnMgr->connectResult(id, success, type, raddr);
|
||||
if (mLinkMgr)
|
||||
mLinkMgr->connectResult(id, success, type, raddr);
|
||||
|
||||
return (NULL != mConnMgr);
|
||||
return (NULL != mLinkMgr);
|
||||
}
|
||||
|
||||
/******************************** DUMMY Specific features ***************************/
|
||||
|
@ -42,6 +42,8 @@
|
||||
|
||||
#include "pqi/pqissllistener.h"
|
||||
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
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()),
|
||||
waiting(WAITING_NOT), active(false), certvalid(false),
|
||||
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),
|
||||
sameLAN(false), n_read_zero(0), mReadZeroTS(0),
|
||||
mConnectDelay(0), mConnectTS(0),
|
||||
mConnectTimeout(0), mTimeoutTS(0), mConnMgr(cm)
|
||||
mConnectTimeout(0), mTimeoutTS(0), mLinkMgr(lm)
|
||||
|
||||
{
|
||||
/* 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 */
|
||||
|
||||
peerConnectState details;
|
||||
mConnMgr->getOwnNetStatus(details);
|
||||
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(details.currentlocaladdr.sin_addr));
|
||||
struct sockaddr_in localaddr = mLinkMgr->getLocalAddress();
|
||||
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(localaddr.sin_addr));
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
@ -1317,7 +1318,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
|
||||
out << std::endl;
|
||||
out << "\t\tchecking for same LAN";
|
||||
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 << "\t remoteaddr: " << rs_inet_ntoa(remote_addr.sin_addr);
|
||||
out << std::endl;
|
||||
|
@ -37,9 +37,6 @@
|
||||
#include <map>
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
|
||||
#define WAITING_NOT 0
|
||||
@ -85,12 +82,13 @@ class pqissl;
|
||||
class cert;
|
||||
|
||||
class pqissllistener;
|
||||
class p3LinkMgr;
|
||||
|
||||
class pqissl: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqissl(pqissllistener *l, PQInterface *parent,
|
||||
p3ConnectMgr *cm);
|
||||
p3LinkMgr *lm);
|
||||
virtual ~pqissl();
|
||||
|
||||
// NetInterface
|
||||
@ -200,7 +198,7 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||
uint32_t mConnectTimeout;
|
||||
time_t mTimeoutTS;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
private:
|
||||
// ssl only fns.
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/sslfns.h"
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
@ -56,8 +58,8 @@ const int pqissllistenzone = 49787;
|
||||
*/
|
||||
|
||||
|
||||
pqissllistenbase::pqissllistenbase(struct sockaddr_in addr, p3ConnectMgr *cm)
|
||||
:laddr(addr), active(false), mConnMgr(cm)
|
||||
pqissllistenbase::pqissllistenbase(struct sockaddr_in addr, p3PeerMgr *pm)
|
||||
:laddr(addr), active(false), mPeerMgr(pm)
|
||||
|
||||
{
|
||||
if (!(AuthSSL::getAuthSSL()-> active())) {
|
||||
@ -562,8 +564,8 @@ int pqissllistenbase::continueaccepts()
|
||||
*
|
||||
*/
|
||||
|
||||
pqissllistener::pqissllistener(struct sockaddr_in addr, p3ConnectMgr *cm)
|
||||
:pqissllistenbase(addr, cm)
|
||||
pqissllistener::pqissllistener(struct sockaddr_in addr, p3PeerMgr *lm)
|
||||
:pqissllistenbase(addr, lm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -729,8 +731,8 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
AuthSSL::getAuthSSL()->CheckCertificate(newPeerId, peercert);
|
||||
|
||||
/* now need to get GPG id too */
|
||||
std::string pgpid = getX509CNString(peercert->cert_info->issuer);
|
||||
mConnMgr->addFriend(newPeerId, pgpid);
|
||||
std::string pgpid = getX509CNString(peercert->cert_info->issuer);
|
||||
mPeerMgr->addFriend(newPeerId, pgpid);
|
||||
|
||||
X509_free(peercert);
|
||||
return -1;
|
||||
|
@ -45,13 +45,14 @@
|
||||
*/
|
||||
|
||||
class pqissl;
|
||||
class p3PeerMgr;
|
||||
|
||||
class pqissllistenbase: public pqilistener
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
pqissllistenbase(struct sockaddr_in addr, p3ConnectMgr *cm);
|
||||
pqissllistenbase(struct sockaddr_in addr, p3PeerMgr *pm);
|
||||
virtual ~pqissllistenbase();
|
||||
|
||||
/*************************************/
|
||||
@ -88,7 +89,7 @@ int Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_in *inaddr);
|
||||
|
||||
protected:
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3PeerMgr *mPeerMgr;
|
||||
|
||||
};
|
||||
|
||||
@ -97,7 +98,7 @@ class pqissllistener: public pqissllistenbase
|
||||
{
|
||||
public:
|
||||
|
||||
pqissllistener(struct sockaddr_in addr, p3ConnectMgr *cm);
|
||||
pqissllistener(struct sockaddr_in addr, p3PeerMgr *pm);
|
||||
virtual ~pqissllistener();
|
||||
|
||||
int addlistenaddr(std::string id, pqissl *acc);
|
||||
|
@ -53,7 +53,7 @@ const int pqipersongrpzone = 354;
|
||||
|
||||
pqilistener * pqisslpersongrp::createListener(struct sockaddr_in laddr)
|
||||
{
|
||||
pqilistener *listener = new pqissllistener(laddr, mConnMgr);
|
||||
pqilistener *listener = new pqissllistener(laddr, mPeerMgr);
|
||||
return listener;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||
}
|
||||
|
||||
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 ....
|
||||
* Needs:
|
||||
@ -85,7 +85,7 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
||||
|
||||
#ifndef PQI_DISABLE_TUNNEL
|
||||
pqissltunnel *pqitun = new pqissltunnel(pqip, mConnMgr);
|
||||
pqissltunnel *pqitun = new pqissltunnel(pqip, mLinkMgr);
|
||||
|
||||
RsSerialiser *rss3 = new RsSerialiser();
|
||||
rss3->addSerialType(new RsFileItemSerialiser());
|
||||
@ -96,18 +96,18 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||
#endif
|
||||
|
||||
#ifndef PQI_DISABLE_UDP
|
||||
pqissludp *pqius = new pqissludp(pqip, mConnMgr);
|
||||
pqissludp *pqius = new pqissludp(pqip, mLinkMgr);
|
||||
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
||||
#endif
|
||||
|
||||
return pqip;
|
||||
|
@ -30,11 +30,13 @@
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
class p3PeerMgr;
|
||||
|
||||
class pqisslpersongrp: public pqipersongrp
|
||||
{
|
||||
public:
|
||||
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags)
|
||||
:pqipersongrp(pol, flags) { return; }
|
||||
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags, p3PeerMgr *pm)
|
||||
:pqipersongrp(pol, flags), mPeerMgr(pm) { return; }
|
||||
|
||||
protected:
|
||||
|
||||
@ -42,6 +44,10 @@ class pqisslpersongrp: public pqipersongrp
|
||||
virtual pqilistener *createListener(struct sockaddr_in laddr);
|
||||
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
|
||||
private:
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "pqi/pqissltunnel.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
//#include "services/p3tunnel.h"
|
||||
|
||||
@ -90,8 +91,8 @@ const int pqisslzone = 37714;
|
||||
*
|
||||
*/
|
||||
|
||||
pqissltunnel::pqissltunnel(PQInterface *parent, p3ConnectMgr *cm, p3tunnel *p3t)
|
||||
:NetBinInterface(parent, parent->PeerId()), mConnMgr(cm)
|
||||
pqissltunnel::pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t)
|
||||
:NetBinInterface(parent, parent->PeerId()), mLinkMgr(cm)
|
||||
{
|
||||
active = false;
|
||||
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;
|
||||
#endif
|
||||
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)) {
|
||||
@ -378,7 +379,7 @@ void pqissltunnel::spam_handshake()
|
||||
std::cerr << "pqissltunnel::spam_handshake() starting to spam handshake tunnel packet." << std::endl;
|
||||
#endif
|
||||
std::list<std::string> peers;
|
||||
mConnMgr->getOnlineList(peers);
|
||||
mLinkMgr->getOnlineList(peers);
|
||||
std::list<std::string>::iterator it = peers.begin();
|
||||
while (it != peers.end()) {
|
||||
//send a handshake to the destination through the relay
|
||||
@ -424,14 +425,14 @@ void pqissltunnel::IncommingHanshakePacket(std::string incRelayPeerId) {
|
||||
last_packet_time = time(NULL);
|
||||
|
||||
std::string message = "pqissltunnel::IncommingHanshakePacket() mConnMgr->isOnline(parent()->PeerId() : ";
|
||||
if (mConnMgr->isOnline(parent()->PeerId())) {
|
||||
if (mLinkMgr->isOnline(parent()->PeerId())) {
|
||||
message += "true";
|
||||
} else {
|
||||
message += "false";
|
||||
}
|
||||
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
|
||||
return;
|
||||
}
|
||||
@ -549,7 +550,7 @@ bool pqissltunnel::moretoread()
|
||||
|
||||
bool pqissltunnel::cansend()
|
||||
{
|
||||
if (!mConnMgr->isOnline(relayPeerId)) {
|
||||
if (!mLinkMgr->isOnline(relayPeerId)) {
|
||||
reset();
|
||||
return false;
|
||||
}
|
||||
|
@ -36,8 +36,6 @@
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
@ -66,6 +64,8 @@ class cert;
|
||||
|
||||
class pqissltunnellistener;
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
struct data_with_length {
|
||||
int length;
|
||||
void *data;
|
||||
@ -74,7 +74,7 @@ struct data_with_length {
|
||||
class pqissltunnel: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqissltunnel(PQInterface *parent, p3ConnectMgr *cm, p3tunnel *p3t);
|
||||
pqissltunnel(PQInterface *parent, p3LinkMgr *cm, p3tunnel *p3t);
|
||||
virtual ~pqissltunnel();
|
||||
|
||||
// NetInterface
|
||||
@ -129,7 +129,7 @@ private:
|
||||
/* Need Certificate specific functions here! */
|
||||
time_t mConnectTS;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
p3tunnel *mP3tunnel;
|
||||
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
const int pqissludpzone = 3144;
|
||||
|
||||
/* 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 **************************************/
|
||||
|
||||
pqissludp::pqissludp(PQInterface *parent, p3ConnectMgr *cm)
|
||||
:pqissl(NULL, parent, cm), tou_bio(NULL),
|
||||
pqissludp::pqissludp(PQInterface *parent, p3LinkMgr *lm)
|
||||
:pqissl(NULL, parent, lm), tou_bio(NULL),
|
||||
listen_checktime(0), mConnectPeriod(PQI_SSLUDP_DEF_CONN_PERIOD)
|
||||
{
|
||||
sockaddr_clear(&remote_addr);
|
||||
@ -129,7 +131,7 @@ int pqissludp::Initiate_Connection()
|
||||
"pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
|
||||
|
||||
/* decide if we're active or passive */
|
||||
if (PeerId() < mConnMgr->getOwnId())
|
||||
if (PeerId() < mLinkMgr->getOwnId())
|
||||
{
|
||||
sslmode = PQISSL_ACTIVE;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class cert;
|
||||
class pqissludp: public pqissl
|
||||
{
|
||||
public:
|
||||
pqissludp(PQInterface *parent, p3ConnectMgr *cm);
|
||||
pqissludp(PQInterface *parent, p3LinkMgr *lm);
|
||||
|
||||
virtual ~pqissludp();
|
||||
|
||||
|
@ -39,11 +39,38 @@ extern RsDht *rsDht;
|
||||
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
|
||||
|
||||
|
||||
#define RS_DHT_NETSTART_NETWORKMODE 0x0001
|
||||
#define RS_DHT_NETSTART_NATTYPE 0x0002
|
||||
#define RS_DHT_NETSTART_NATHOLE 0x0003
|
||||
#define RS_DHT_NETSTART_CONNECTMODES 0x0004
|
||||
#define RS_DHT_NETSTART_NETSTATE 0x0005
|
||||
#define RSDHT_NETSTART_NETWORKMODE 0x0001
|
||||
#define RSDHT_NETSTART_NATTYPE 0x0002
|
||||
#define RSDHT_NETSTART_NATHOLE 0x0003
|
||||
#define RSDHT_NETSTART_CONNECTMODES 0x0004
|
||||
#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
|
||||
{
|
||||
@ -68,6 +95,7 @@ class RsDhtNetPeer
|
||||
std::string mDhtId;
|
||||
std::string mRsId;
|
||||
|
||||
uint32_t mDhtState;
|
||||
};
|
||||
|
||||
class RsDhtRelayEnd
|
||||
|
@ -38,6 +38,9 @@ const int p3facemsgzone = 11453;
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
|
||||
/****************************************/
|
||||
/* RsIface Config */
|
||||
@ -106,18 +109,18 @@ int RsServer::UpdateAllConfig()
|
||||
|
||||
config.ownId = AuthSSL::getAuthSSL()->OwnId();
|
||||
config.ownName = AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||
peerConnectState pstate;
|
||||
mConnMgr->getOwnNetStatus(pstate);
|
||||
peerState pstate;
|
||||
mPeerMgr->getOwnNetStatus(pstate);
|
||||
|
||||
/* ports */
|
||||
config.localAddr = rs_inet_ntoa(pstate.currentlocaladdr.sin_addr);
|
||||
config.localPort = ntohs(pstate.currentlocaladdr.sin_port);
|
||||
config.localAddr = rs_inet_ntoa(pstate.localaddr.sin_addr);
|
||||
config.localPort = ntohs(pstate.localaddr.sin_port);
|
||||
|
||||
config.firewalled = true;
|
||||
config.forwardPort = true;
|
||||
|
||||
config.extAddr = rs_inet_ntoa(pstate.currentserveraddr.sin_addr);
|
||||
config.extPort = ntohs(pstate.currentserveraddr.sin_port);
|
||||
config.extAddr = rs_inet_ntoa(pstate.serveraddr.sin_addr);
|
||||
config.extPort = ntohs(pstate.serveraddr.sin_port);
|
||||
|
||||
/* data rates */
|
||||
config.maxDownloadDataRate = (int) pqih -> getMaxRate(true); /* kb */
|
||||
@ -128,7 +131,7 @@ int RsServer::UpdateAllConfig()
|
||||
/* update network configuration */
|
||||
|
||||
pqiNetStatus status;
|
||||
mConnMgr->getNetStatus(status);
|
||||
mNetMgr->getNetStatus(status);
|
||||
|
||||
config.netLocalOk = status.mLocalAddrOk;
|
||||
config.netUpnpOk = status.mUpnpOk;
|
||||
@ -141,10 +144,10 @@ int RsServer::UpdateAllConfig()
|
||||
|
||||
/* update DHT/UPnP config */
|
||||
|
||||
config.uPnPState = mConnMgr->getUPnPState();
|
||||
config.uPnPActive = mConnMgr->getUPnPEnabled();
|
||||
config.uPnPState = mNetMgr->getUPnPState();
|
||||
config.uPnPActive = mNetMgr->getUPnPEnabled();
|
||||
config.DHTPeers = 20;
|
||||
config.DHTActive = mConnMgr->getDHTEnabled();
|
||||
config.DHTActive = mNetMgr->getDHTEnabled();
|
||||
|
||||
/* Notify of Changes */
|
||||
// iface.setChanged(RsIface::Config);
|
||||
@ -175,7 +178,7 @@ void RsServer::rsGlobalShutDown()
|
||||
// TODO: cache should also clean up old files
|
||||
|
||||
ConfigFinalSave(); // save configuration before exit
|
||||
mConnMgr->shutdown(); /* Handles UPnP */
|
||||
mNetMgr->shutdown(); /* Handles UPnP */
|
||||
|
||||
join();
|
||||
ftserver->StopThreads();
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
|
||||
/****
|
||||
#define DEBUG_TICK 1
|
||||
****/
|
||||
@ -44,7 +49,9 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
||||
{
|
||||
ftserver = NULL;
|
||||
|
||||
mConnMgr = NULL;
|
||||
mPeerMgr = NULL;
|
||||
mLinkMgr = NULL;
|
||||
mNetMgr = NULL;
|
||||
|
||||
pqih = NULL;
|
||||
|
||||
@ -144,8 +151,10 @@ void RsServer::run()
|
||||
|
||||
unlockRsCore();
|
||||
|
||||
/* tick the connection Manager */
|
||||
mConnMgr->tick();
|
||||
/* tick the Managers */
|
||||
mPeerMgr->tick();
|
||||
mLinkMgr->tick();
|
||||
mNetMgr->tick();
|
||||
/******************************** RUN SERVER *****************/
|
||||
|
||||
/* adjust tick rate depending on whether there is more.
|
||||
|
@ -31,7 +31,6 @@
|
||||
//#include "pqi/pqissl.h"
|
||||
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
@ -46,6 +45,11 @@
|
||||
#include "services/p3channels.h"
|
||||
#include "services/p3forums.h"
|
||||
|
||||
class p3PeerMgr;
|
||||
class p3LinkMgr;
|
||||
class p3NetMgr;
|
||||
|
||||
|
||||
/* The Main Interface Class - for controlling the server */
|
||||
|
||||
/* The init functions are actually Defined in p3face-startup.cc
|
||||
@ -150,7 +154,9 @@ class RsServer: public RsControl, public RsThread
|
||||
//filedexserver *server;
|
||||
ftServer *ftserver;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
p3NetMgr *mNetMgr;
|
||||
|
||||
pqipersongrp *pqih;
|
||||
|
||||
|
@ -25,7 +25,11 @@
|
||||
|
||||
#include "rsserver/p3peers.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/authgpg.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
@ -123,8 +127,8 @@ std::string RsPeerLastConnectString(uint32_t lastConnect)
|
||||
}
|
||||
|
||||
|
||||
p3Peers::p3Peers(p3ConnectMgr *cm)
|
||||
:mConnMgr(cm)
|
||||
p3Peers::p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm)
|
||||
:mLinkMgr(lm), mPeerMgr(pm), mNetMgr(nm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -176,7 +180,7 @@ bool p3Peers::getOnlineList(std::list<std::string> &ids)
|
||||
#endif
|
||||
|
||||
/* get from mConnectMgr */
|
||||
mConnMgr->getOnlineList(ids);
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -187,7 +191,7 @@ bool p3Peers::getFriendList(std::list<std::string> &ids)
|
||||
#endif
|
||||
|
||||
/* get from mConnectMgr */
|
||||
mConnMgr->getFriendList(ids);
|
||||
mLinkMgr->getFriendList(ids);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -208,9 +212,15 @@ bool p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineC
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
||||
#endif
|
||||
|
||||
/* get from mConnectMgr */
|
||||
return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
|
||||
// This is no longer accurate!
|
||||
*pnFriendCount = mLinkMgr->getFriendCount();
|
||||
*pnOnlineCount = mLinkMgr->getOnlineCount();
|
||||
|
||||
/* get from mConnectMgr */
|
||||
//return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool p3Peers::isOnline(const std::string &id)
|
||||
@ -221,7 +231,7 @@ bool p3Peers::isOnline(const std::string &id)
|
||||
|
||||
/* get from mConnectMgr */
|
||||
peerConnectState state;
|
||||
if (mConnMgr->getFriendNetStatus(id, state) &&
|
||||
if (mLinkMgr->getFriendNetStatus(id, state) &&
|
||||
(state.state & RS_PEER_S_CONNECTED))
|
||||
{
|
||||
return true;
|
||||
@ -236,23 +246,9 @@ bool p3Peers::isFriend(const std::string &ssl_id)
|
||||
#endif
|
||||
|
||||
/* 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)
|
||||
{
|
||||
@ -261,8 +257,8 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
#endif
|
||||
//first, check if it's a gpg or a ssl id.
|
||||
std::string sOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||
peerConnectState pcs;
|
||||
if (id != sOwnId && !mConnMgr->getFriendNetStatus(id, pcs)) {
|
||||
peerState ps;
|
||||
if (id != sOwnId && !mPeerMgr->getFriendNetStatus(id, ps)) {
|
||||
//assume is not SSL, because every ssl_id has got a friend correspondance in mConnMgr
|
||||
#ifdef P3PEERS_DEBUG
|
||||
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
|
||||
|
||||
if (id == sOwnId) {
|
||||
mConnMgr->getOwnNetStatus(pcs);
|
||||
pcs.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
mPeerMgr->getOwnNetStatus(ps);
|
||||
ps.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
this->getGPGDetails(pcs.gpg_id, d);
|
||||
this->getGPGDetails(ps.gpg_id, d);
|
||||
d.isOnlyGPGdetail = false;
|
||||
|
||||
//get the ssl details
|
||||
d.id = id;
|
||||
d.location = pcs.location;
|
||||
d.location = ps.location;
|
||||
|
||||
/* generate */
|
||||
d.authcode = "AUTHCODE";
|
||||
|
||||
/* fill from pcs */
|
||||
|
||||
d.localAddr = rs_inet_ntoa(pcs.currentlocaladdr.sin_addr);
|
||||
d.localPort = ntohs(pcs.currentlocaladdr.sin_port);
|
||||
d.extAddr = rs_inet_ntoa(pcs.currentserveraddr.sin_addr);
|
||||
d.extPort = ntohs(pcs.currentserveraddr.sin_port);
|
||||
d.dyndns = pcs.dyndns;
|
||||
d.lastConnect = pcs.lastcontact;
|
||||
d.localAddr = rs_inet_ntoa(ps.localaddr.sin_addr);
|
||||
d.localPort = ntohs(ps.localaddr.sin_port);
|
||||
d.extAddr = rs_inet_ntoa(ps.serveraddr.sin_addr);
|
||||
d.extPort = ntohs(ps.serveraddr.sin_port);
|
||||
d.dyndns = ps.dyndns;
|
||||
d.lastConnect = ps.lastcontact;
|
||||
d.connectPeriod = 0;
|
||||
|
||||
|
||||
std::list<pqiIpAddress>::iterator it;
|
||||
for(it = pcs.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != pcs.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
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());
|
||||
}
|
||||
for(it = pcs.ipAddrs.mExt.mAddrs.begin();
|
||||
it != pcs.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin();
|
||||
it != ps.ipAddrs.mExt.mAddrs.end(); it++)
|
||||
{
|
||||
std::ostringstream toto;
|
||||
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());
|
||||
}
|
||||
|
||||
/* Translate */
|
||||
|
||||
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;
|
||||
|
||||
switch(pcs.netMode & RS_NET_MODE_ACTUAL)
|
||||
switch(ps.netMode & RS_NET_MODE_ACTUAL)
|
||||
{
|
||||
case RS_NET_MODE_EXT:
|
||||
d.netMode = RS_NETMODE_EXT;
|
||||
@ -347,12 +332,13 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
d.netMode = RS_NETMODE_UNREACHABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pcs.netMode & RS_NET_MODE_TRY_EXT)
|
||||
|
||||
|
||||
if (ps.netMode & RS_NET_MODE_TRY_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;
|
||||
}
|
||||
@ -360,17 +346,44 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
||||
{
|
||||
d.tryNetMode = RS_NETMODE_UDP;
|
||||
}
|
||||
|
||||
|
||||
d.visState = 0;
|
||||
if (!(pcs.visState & RS_VIS_STATE_NODISC))
|
||||
if (!(ps.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* 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 */
|
||||
@ -443,8 +456,8 @@ std::string p3Peers::getPeerName(const std::string &ssl_or_gpg_id)
|
||||
if (ssl_or_gpg_id == AuthSSL::getAuthSSL()->OwnId()) {
|
||||
return AuthGPG::getAuthGPG()->getGPGOwnName();
|
||||
}
|
||||
peerConnectState pcs;
|
||||
if (mConnMgr->getFriendNetStatus(ssl_or_gpg_id, pcs)) {
|
||||
peerState pcs;
|
||||
if (mPeerMgr->getFriendNetStatus(ssl_or_gpg_id, pcs)) {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getPeerName() got a ssl id. Name is : " << pcs.name << std::endl;
|
||||
#endif
|
||||
@ -507,14 +520,14 @@ bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::s
|
||||
}
|
||||
//let's roll throush the friends
|
||||
std::list<std::string> friendsIds;
|
||||
mConnMgr->getFriendList(friendsIds);
|
||||
peerConnectState pcs;
|
||||
mLinkMgr->getFriendList(friendsIds);
|
||||
peerState pcs;
|
||||
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
||||
#endif
|
||||
if (mConnMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
||||
if (mPeerMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
||||
#endif
|
||||
@ -528,16 +541,16 @@ bool p3Peers::cleanUnusedLocations()
|
||||
{
|
||||
// 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 ;
|
||||
|
||||
mConnMgr->getFriendList(friendSSLIds);
|
||||
mLinkMgr->getFriendList(friendSSLIds);
|
||||
|
||||
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) ;
|
||||
}
|
||||
|
||||
@ -549,20 +562,20 @@ bool p3Peers::cleanUnusedLocations()
|
||||
|
||||
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() ;
|
||||
|
||||
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 ;
|
||||
|
||||
// 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))
|
||||
{
|
||||
locations_to_remove.push_back((*itloc).id) ;
|
||||
@ -570,7 +583,7 @@ bool p3Peers::cleanUnusedLocations()
|
||||
|
||||
std::cerr << " Removing dummy location: " << (*itloc).id << std::endl ;
|
||||
|
||||
std::list<peerConnectState>::iterator tmp(itloc) ;
|
||||
std::list<peerState>::iterator tmp(itloc) ;
|
||||
++tmp ;
|
||||
locations_list.erase(itloc) ;
|
||||
itloc=tmp ;
|
||||
@ -578,7 +591,7 @@ bool p3Peers::cleanUnusedLocations()
|
||||
else
|
||||
++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)
|
||||
{
|
||||
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()) {
|
||||
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
}
|
||||
peerConnectState pcs;
|
||||
if (mConnMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mConnMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
||||
peerState pcs;
|
||||
if (mPeerMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mPeerMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
||||
return pcs.gpg_id;
|
||||
} else {
|
||||
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 == "") {
|
||||
return addDummyFriend(gpg_id);
|
||||
} 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
|
||||
std::string dummy_ssl_id = "dummy"+ gpg_id;
|
||||
//check if this gpg_id already got a dummy friend
|
||||
if (!mConnMgr->isFriend(dummy_ssl_id)) {
|
||||
return mConnMgr->addFriend(dummy_ssl_id, gpg_id);
|
||||
if (!mPeerMgr->isFriend(dummy_ssl_id)) {
|
||||
return mPeerMgr->addFriend(dummy_ssl_id, gpg_id);
|
||||
} else {
|
||||
#ifdef P3PEERS_DEBUG
|
||||
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);
|
||||
|
||||
//will remove if it's a ssl id
|
||||
mConnMgr->removeFriend(ssl_or_gpgid);
|
||||
mPeerMgr->removeFriend(ssl_or_gpgid);
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -718,16 +731,16 @@ bool p3Peers::connectAttempt(const std::string &id)
|
||||
std::cerr << "p3Peers::connectAttempt() " << id << std::endl;
|
||||
#endif
|
||||
|
||||
return mConnMgr->retryConnect(id);
|
||||
return mLinkMgr->retryConnect(id);
|
||||
}
|
||||
|
||||
void p3Peers::getIPServersList(std::list<std::string>& ip_servers)
|
||||
{
|
||||
mConnMgr->getIPServersList(ip_servers) ;
|
||||
mNetMgr->getIPServersList(ip_servers) ;
|
||||
}
|
||||
void p3Peers::allowServerIPDetermination(bool b)
|
||||
{
|
||||
mConnMgr->setIPServersEnabled(b) ;
|
||||
mNetMgr->setIPServersEnabled(b) ;
|
||||
}
|
||||
|
||||
void p3Peers::allowTunnelConnection(bool b)
|
||||
@ -735,12 +748,12 @@ void p3Peers::allowTunnelConnection(bool b)
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
||||
#endif
|
||||
mConnMgr->setTunnelConnection(b) ;
|
||||
mLinkMgr->setTunnelConnection(b) ;
|
||||
}
|
||||
|
||||
bool p3Peers::getAllowServerIPDetermination()
|
||||
{
|
||||
return mConnMgr->getIPServersEnabled() ;
|
||||
return mNetMgr->getIPServersEnabled() ;
|
||||
}
|
||||
|
||||
bool p3Peers::getAllowTunnelConnection()
|
||||
@ -748,7 +761,7 @@ bool p3Peers::getAllowTunnelConnection()
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
||||
#endif
|
||||
return mConnMgr->getTunnelConnection() ;
|
||||
return mLinkMgr->getTunnelConnection() ;
|
||||
}
|
||||
|
||||
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
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
return mConnMgr->setLocalAddress(id, addr);
|
||||
return mPeerMgr->setLocalAddress(id, addr);
|
||||
}
|
||||
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;
|
||||
#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)
|
||||
{
|
||||
@ -804,7 +817,7 @@ bool p3Peers::setExtAddress(const std::string &id, const std::string &addr_str,
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
return mConnMgr->setExtAddress(id, addr);
|
||||
return mPeerMgr->setExtAddress(id, addr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -814,7 +827,7 @@ bool p3Peers::setDynDNS(const std::string &id, const std::string &dyndns)
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setDynDNS() called with id: " << id << " dyndns: " << dyndns <<std::endl;
|
||||
#endif
|
||||
return mConnMgr->setDynDNS(id, dyndns);
|
||||
return mPeerMgr->setDynDNS(id, dyndns);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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))
|
||||
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;
|
||||
this->getSSLChildListOfGPGId(gpg_id, sslFriends);
|
||||
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);
|
||||
}
|
||||
@ -1253,7 +1266,7 @@ bool p3Peers::addGroup(RsGroupInfo &groupInfo)
|
||||
std::cerr << "p3Peers::addGroup()" << std::endl;
|
||||
#endif
|
||||
|
||||
return mConnMgr->addGroup(groupInfo);
|
||||
return mPeerMgr->addGroup(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;
|
||||
#endif
|
||||
|
||||
return mConnMgr->editGroup(groupId, groupInfo);
|
||||
return mPeerMgr->editGroup(groupId, groupInfo);
|
||||
}
|
||||
|
||||
bool p3Peers::removeGroup(const std::string &groupId)
|
||||
@ -1271,7 +1284,7 @@ bool p3Peers::removeGroup(const std::string &groupId)
|
||||
std::cerr << "p3Peers::removeGroup()" << std::endl;
|
||||
#endif
|
||||
|
||||
return mConnMgr->removeGroup(groupId);
|
||||
return mPeerMgr->removeGroup(groupId);
|
||||
}
|
||||
|
||||
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;
|
||||
#endif
|
||||
|
||||
return mConnMgr->getGroupInfo(groupId, groupInfo);
|
||||
return mPeerMgr->getGroupInfo(groupId, groupInfo);
|
||||
}
|
||||
|
||||
bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||
@ -1289,7 +1302,7 @@ bool p3Peers::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
|
||||
std::cerr << "p3Peers::getGroupInfoList()" << std::endl;
|
||||
#endif
|
||||
|
||||
return mConnMgr->getGroupInfoList(groupInfoList);
|
||||
return mPeerMgr->getGroupInfoList(groupInfoList);
|
||||
}
|
||||
|
||||
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;
|
||||
#endif
|
||||
|
||||
return mConnMgr->assignPeersToGroup(groupId, peerIds, assign);
|
||||
return mPeerMgr->assignPeersToGroup(groupId, peerIds, assign);
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,13 +27,16 @@
|
||||
*/
|
||||
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
class p3LinkMgr;
|
||||
class p3PeerMgr;
|
||||
class p3NetMgr;
|
||||
|
||||
|
||||
class p3Peers: public RsPeers
|
||||
{
|
||||
public:
|
||||
|
||||
p3Peers(p3ConnectMgr *cm);
|
||||
p3Peers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm);
|
||||
virtual ~p3Peers() { return; }
|
||||
|
||||
/* Updates ... */
|
||||
@ -115,7 +118,10 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std:
|
||||
|
||||
private:
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3NetMgr *mNetMgr;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1735,9 +1735,15 @@ RsTurtle *rsTurtle = NULL ;
|
||||
|
||||
#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/rsudpstack.h"
|
||||
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
#include "dht/p3bitdht.h"
|
||||
#include "udp/udpstack.h"
|
||||
@ -1823,8 +1829,12 @@ int RsServer::StartupRetroShare()
|
||||
/* Setup Notify Early - So we can use it. */
|
||||
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
|
||||
// std::list<std::string> sslIds;
|
||||
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
|
||||
@ -1899,7 +1909,7 @@ int RsServer::StartupRetroShare()
|
||||
mUdpStack->addReceiver(mDhtStunner);
|
||||
|
||||
// NEXT BITDHT.
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mConnMgr, mUdpStack, bootstrapfile);
|
||||
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mUdpStack, bootstrapfile);
|
||||
/* install external Pointer for Interface */
|
||||
rsDht = mBitDht;
|
||||
|
||||
@ -1956,20 +1966,21 @@ int RsServer::StartupRetroShare()
|
||||
//pqih = new pqipersongrpDummy(none, flags);
|
||||
|
||||
/****** New Ft Server **** !!! */
|
||||
ftserver = new ftServer(mConnMgr);
|
||||
ftserver->setP3Interface(pqih);
|
||||
ftserver = new ftServer(mLinkMgr);
|
||||
ftserver->setP3Interface(pqih);
|
||||
ftserver->setConfigDirectory(RsInitConfig::configDir);
|
||||
|
||||
ftserver->SetupFtServer(&(getNotify()));
|
||||
CacheStrapper *mCacheStrapper = ftserver->getCacheStrapper();
|
||||
CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer();
|
||||
|
||||
/* setup any extra bits (Default Paths) */
|
||||
ftserver->setPartialsDirectory(emergencyPartialsDir);
|
||||
ftserver->setDownloadDirectory(emergencySaveDir);
|
||||
/* setup any extra bits (Default Paths) */
|
||||
ftserver->setPartialsDirectory(emergencyPartialsDir);
|
||||
ftserver->setDownloadDirectory(emergencySaveDir);
|
||||
|
||||
/* This should be set by config ... there is no default */
|
||||
//ftserver->setSharedDirectories(fileList);
|
||||
//ftserver->setSharedDirectories(fileList);
|
||||
|
||||
rsFiles = ftserver;
|
||||
|
||||
|
||||
@ -2013,11 +2024,11 @@ int RsServer::StartupRetroShare()
|
||||
mPluginsManager->loadPlugins(plugins_directories) ;
|
||||
|
||||
/* create Services */
|
||||
ad = new p3disc(mConnMgr, pqih);
|
||||
ad = new p3disc(mLinkMgr, pqih);
|
||||
#ifndef MINIMAL_LIBRS
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
mStatusSrv = new p3StatusService(mConnMgr);
|
||||
msgSrv = new p3MsgService(mLinkMgr);
|
||||
chatSrv = new p3ChatService(mLinkMgr);
|
||||
mStatusSrv = new p3StatusService(mLinkMgr);
|
||||
#endif // MINIMAL_LIBRS
|
||||
|
||||
#ifndef PQI_DISABLE_TUNNEL
|
||||
@ -2026,7 +2037,7 @@ int RsServer::StartupRetroShare()
|
||||
mConnMgr->setP3tunnel(tn);
|
||||
#endif
|
||||
|
||||
p3turtle *tr = new p3turtle(mConnMgr,ftserver) ;
|
||||
p3turtle *tr = new p3turtle(mLinkMgr,ftserver) ;
|
||||
rsTurtle = tr ;
|
||||
pqih -> addService(tr);
|
||||
ftserver->connectToTurtleRouter(tr) ;
|
||||
@ -2064,7 +2075,7 @@ int RsServer::StartupRetroShare()
|
||||
mPluginsManager->registerCacheServices() ;
|
||||
|
||||
#ifndef RS_RELEASE
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
|
||||
pqih -> addService(gameLauncher);
|
||||
|
||||
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
|
||||
@ -2079,26 +2090,26 @@ int RsServer::StartupRetroShare()
|
||||
/**************************************************************************/
|
||||
|
||||
#ifdef RS_USE_BITDHT
|
||||
mConnMgr->addNetAssistConnect(1, mBitDht);
|
||||
mConnMgr->addNetListener(mUdpStack);
|
||||
mNetMgr->addNetAssistConnect(1, mBitDht);
|
||||
mNetMgr->addNetListener(mUdpStack);
|
||||
#endif
|
||||
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||
mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||
|
||||
/**************************************************************************/
|
||||
/* need to Monitor too! */
|
||||
mConnMgr->addMonitor(pqih);
|
||||
mConnMgr->addMonitor(mCacheStrapper);
|
||||
mConnMgr->addMonitor(ad);
|
||||
mLinkMgr->addMonitor(pqih);
|
||||
mLinkMgr->addMonitor(mCacheStrapper);
|
||||
mLinkMgr->addMonitor(ad);
|
||||
#ifndef MINIMAL_LIBRS
|
||||
mConnMgr->addMonitor(msgSrv);
|
||||
mConnMgr->addMonitor(mStatusSrv);
|
||||
mConnMgr->addMonitor(chatSrv);
|
||||
mLinkMgr->addMonitor(msgSrv);
|
||||
mLinkMgr->addMonitor(mStatusSrv);
|
||||
mLinkMgr->addMonitor(chatSrv);
|
||||
#endif // MINIMAL_LIBRS
|
||||
|
||||
/* must also add the controller as a Monitor...
|
||||
* 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/pqinotify.h"
|
||||
#include "pqi/pqistore.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "services/p3chatservice.h"
|
||||
|
||||
@ -41,8 +42,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mConnMgr(cm)
|
||||
p3ChatService::p3ChatService(p3LinkMgr *lm)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm)
|
||||
{
|
||||
addSerialType(new RsChatSerialiser());
|
||||
|
||||
@ -72,10 +73,10 @@ int p3ChatService::sendPublicChat(std::wstring &msg)
|
||||
|
||||
std::list<std::string> ids;
|
||||
std::list<std::string>::iterator it;
|
||||
mConnMgr->getOnlineList(ids);
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
/* add in own id -> so get reflection */
|
||||
ids.push_back(mConnMgr->getOwnId());
|
||||
ids.push_back(mLinkMgr->getOwnId());
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendChat()";
|
||||
@ -156,7 +157,7 @@ class p3ChatService::AvatarInfo
|
||||
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
|
||||
{
|
||||
std::list<std::string> ids;
|
||||
mConnMgr->getOnlineList(ids);
|
||||
mLinkMgr->getOnlineList(ids);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
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->message = msg;
|
||||
|
||||
if (!mConnMgr->isOnline(id)) {
|
||||
if (!mLinkMgr->isOnline(id)) {
|
||||
/* peer is offline, add to outgoing list */
|
||||
{
|
||||
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)
|
||||
it->second._own_is_new = true ;
|
||||
|
||||
mConnMgr->getOnlineList(onlineList);
|
||||
mLinkMgr->getOnlineList(onlineList);
|
||||
}
|
||||
|
||||
rsicontrol->getNotify().notifyOwnStatusMessageChanged() ;
|
||||
@ -1022,7 +1023,7 @@ bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
|
||||
if(_own_avatar != NULL)
|
||||
{
|
||||
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
|
||||
ci->PeerId(mConnMgr->getOwnId());
|
||||
ci->PeerId(mLinkMgr->getOwnId());
|
||||
|
||||
list.push_back(ci) ;
|
||||
}
|
||||
|
@ -32,9 +32,10 @@
|
||||
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "retroshare/rsmsgs.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
//!The basic Chat service.
|
||||
/**
|
||||
*
|
||||
@ -45,7 +46,7 @@
|
||||
class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
p3ChatService(p3ConnectMgr *cm);
|
||||
p3ChatService(p3LinkMgr *cm);
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
/*!
|
||||
@ -199,7 +200,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
|
||||
RsChatAvatarItem *makeOwnAvatarItem() ;
|
||||
RsChatStatusItem *makeOwnCustomStateStringItem() ;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
std::list<RsChatMsgItem *> publicList;
|
||||
std::list<RsChatMsgItem *> privateIncomingList;
|
||||
|
@ -29,9 +29,11 @@
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "services/p3disc.h"
|
||||
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/authgpg.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include <iostream>
|
||||
#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),
|
||||
p3Config(CONFIG_TYPE_P3DISC),
|
||||
mConnMgr(cm),
|
||||
mPeerMgr(pm), mLinkMgr(lm),
|
||||
mPqiPersonGrp(pqih), mDiscMtx("p3disc")
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -114,7 +116,7 @@ int p3disc::tick()
|
||||
#endif
|
||||
lastSentHeartbeatTime = time(NULL);
|
||||
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) {
|
||||
sendHeartbeat(*pit);
|
||||
}
|
||||
@ -132,8 +134,8 @@ int p3disc::handleIncoming()
|
||||
#endif
|
||||
|
||||
// if off discard item.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC))
|
||||
{
|
||||
while(NULL != (item = recvItem()))
|
||||
{
|
||||
@ -288,8 +290,8 @@ void p3disc::sendAllInfoToJustConnectedPeer(const std::string &id)
|
||||
/* send them a list of all friend's details */
|
||||
for(friendIdsIt = friendIds.begin(); friendIdsIt != friendIds.end(); friendIdsIt++) {
|
||||
/* get details */
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getFriendNetStatus(*friendIdsIt, detail)) {
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getFriendNetStatus(*friendIdsIt, detail)) {
|
||||
/* major error! */
|
||||
continue;
|
||||
}
|
||||
@ -368,8 +370,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
|
||||
|
||||
// if off discard item.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||
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,
|
||||
{ // 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.
|
||||
peerConnectState detail;
|
||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||
peerState detail;
|
||||
if (!mPeerMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -430,8 +432,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
rsPeerNetItem.netMode = detail.netMode;
|
||||
rsPeerNetItem.visState = detail.visState;
|
||||
rsPeerNetItem.lastContact = detail.lastcontact;
|
||||
rsPeerNetItem.currentlocaladdr = detail.currentlocaladdr;
|
||||
rsPeerNetItem.currentremoteaddr = detail.currentserveraddr;
|
||||
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
||||
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
||||
rsPeerNetItem.dyndns = detail.dyndns;
|
||||
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
||||
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
||||
@ -452,8 +454,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
//send own details
|
||||
if (about == rsPeers->getGPGOwnId())
|
||||
{
|
||||
peerConnectState detail;
|
||||
if (mConnMgr->getOwnNetStatus(detail))
|
||||
peerState detail;
|
||||
if (mPeerMgr->getOwnNetStatus(detail))
|
||||
{
|
||||
shouldWeSendGPGKey = true;
|
||||
RsPeerNetItem rsPeerNetItem ;
|
||||
@ -464,8 +466,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
||||
rsPeerNetItem.netMode = detail.netMode;
|
||||
rsPeerNetItem.visState = detail.visState;
|
||||
rsPeerNetItem.lastContact = time(NULL);
|
||||
rsPeerNetItem.currentlocaladdr = detail.currentlocaladdr;
|
||||
rsPeerNetItem.currentremoteaddr = detail.currentserveraddr;
|
||||
rsPeerNetItem.currentlocaladdr = detail.localaddr;
|
||||
rsPeerNetItem.currentremoteaddr = detail.serveraddr;
|
||||
rsPeerNetItem.dyndns = detail.dyndns;
|
||||
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList);
|
||||
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList);
|
||||
@ -534,8 +536,8 @@ void p3disc::askInfoToAllPeers(std::string about)
|
||||
#endif
|
||||
|
||||
|
||||
peerConnectState connectState;
|
||||
if (!mConnMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
peerState connectState;
|
||||
if (!mPeerMgr->getFriendNetStatus(about, connectState)) // || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
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 (!mConnMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
if (!mPeerMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::askInfoToAllPeers() no gpg id found" << std::endl;
|
||||
#endif
|
||||
@ -644,7 +646,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
||||
#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;
|
||||
|
||||
// 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 << " -> location: " << pitem->location << std::endl;
|
||||
#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,
|
||||
// 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
|
||||
// peer is the primary source of his own IPs.
|
||||
|
||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
||||
mPeerMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||
mPeerMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||
//pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||
mPeerMgr->setVisState(pitem->pid, pitem->visState);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -706,9 +708,9 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
#endif
|
||||
// allways update address list and dns, except if it's ours
|
||||
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
|
||||
else
|
||||
@ -817,7 +819,7 @@ AuthGPGOperation *p3disc::getGPGOperation()
|
||||
while (!sendIdList.empty()) {
|
||||
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();
|
||||
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
|
||||
@ -80,7 +81,7 @@ class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthG
|
||||
public:
|
||||
|
||||
|
||||
p3disc(p3ConnectMgr *cm, pqipersongrp *persGrp);
|
||||
p3disc(p3PeerMgr *pm, p3LinkMgr *lm, pqipersongrp *persGrp);
|
||||
|
||||
/************* from pqiMonitor *******************/
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
@ -141,9 +142,11 @@ int idServers();
|
||||
|
||||
private:
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
pqipersongrp *mPqiPersonGrp;
|
||||
time_t lastSentHeartbeatTime;
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
pqipersongrp *mPqiPersonGrp;
|
||||
time_t lastSentHeartbeatTime;
|
||||
|
||||
/* data */
|
||||
RsMutex mDiscMtx;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "services/p3gamelauncher.h"
|
||||
#include "services/p3gameservice.h"
|
||||
#include "util/rsdebug.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
@ -109,9 +109,9 @@ const uint32_t RS_GAME_MSG_REJECT = 6; /* ANY -> ANY */
|
||||
|
||||
const int p3gamezone = 1745;
|
||||
|
||||
p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
|
||||
p3GameLauncher::p3GameLauncher(p3LinkMgr *lm)
|
||||
:p3Service(RS_SERVICE_TYPE_GAME_LAUNCHER),
|
||||
mConnMgr(connMgr)
|
||||
mLinkMgr(lm)
|
||||
{
|
||||
#ifdef GAME_DEBUG
|
||||
std::cerr << "p3GameLauncher::p3GameLauncher()";
|
||||
@ -119,7 +119,7 @@ p3GameLauncher::p3GameLauncher(p3ConnectMgr *connMgr)
|
||||
#endif
|
||||
|
||||
addSerialType(new RsGameSerialiser());
|
||||
mOwnId = mConnMgr->getOwnId();
|
||||
mOwnId = mLinkMgr->getOwnId();
|
||||
}
|
||||
|
||||
int p3GameLauncher::tick()
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "serialiser/rsgameitems.h"
|
||||
#include "retroshare/rsgame.h"
|
||||
|
||||
class p3ConnectMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
|
||||
class gameAvail
|
||||
@ -76,7 +76,7 @@ class p3GameService;
|
||||
class p3GameLauncher: public p3Service, public RsGameLauncher
|
||||
{
|
||||
public:
|
||||
p3GameLauncher(p3ConnectMgr *connMgr);
|
||||
p3GameLauncher(p3LinkMgr *lm);
|
||||
|
||||
/***** EXTERNAL RsGameLauncher Interface *******/
|
||||
/* server commands */
|
||||
@ -144,7 +144,7 @@ bool checkGameProperties(uint16_t serviceId, uint16_t players);
|
||||
std::map<uint16_t, p3GameService *> gameList;
|
||||
std::map<std::string, gameStatus> gamesCurrent;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
std::string mOwnId;
|
||||
};
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include "pqi/pqibin.h"
|
||||
#include "pqi/pqiarchive.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
#include "services/p3msgservice.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),
|
||||
mConnMgr(cm), mMsgMtx("p3MsgService"), msgChanged(1), mMsgUniqueId(1)
|
||||
mLinkMgr(lm), mMsgMtx("p3MsgService"), msgChanged(1), mMsgUniqueId(1)
|
||||
{
|
||||
addSerialType(new RsMsgSerialiser());
|
||||
|
||||
/* Initialize standard tag types */
|
||||
if(cm)
|
||||
if(lm)
|
||||
initStandardTagTypes();
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ void p3MsgService::processMsg(RsMsgItem *mi)
|
||||
|
||||
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/
|
||||
|
||||
if (mi -> PeerId() == mConnMgr->getOwnId())
|
||||
if (mi -> PeerId() == mLinkMgr->getOwnId())
|
||||
{
|
||||
/* from the loopback device */
|
||||
mi -> msgFlags |= RS_MSG_FLAGS_OUTGOING;
|
||||
@ -207,7 +207,7 @@ int p3MsgService::checkOutgoingMessages()
|
||||
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> toErase;
|
||||
@ -225,7 +225,7 @@ int p3MsgService::checkOutgoingMessages()
|
||||
peerConnectState pstate;
|
||||
bool toSend = false;
|
||||
|
||||
if (mConnMgr->getFriendNetStatus(pid, pstate))
|
||||
if (mLinkMgr->getFriendNetStatus(pid, pstate))
|
||||
{
|
||||
if (pstate.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
@ -353,7 +353,7 @@ static void getStandardTagTypes(MsgTagType &tags)
|
||||
void p3MsgService::initStandardTagTypes()
|
||||
{
|
||||
bool bChanged = false;
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
MsgTagType tags;
|
||||
getStandardTagTypes(tags);
|
||||
@ -507,7 +507,7 @@ void p3MsgService::loadWelcomeMsg()
|
||||
/* Load Welcome Message */
|
||||
RsMsgItem *msg = new RsMsgItem();
|
||||
|
||||
//msg -> PeerId(mConnMgr->getOwnId());
|
||||
//msg -> PeerId(mLinkMgr->getOwnId());
|
||||
|
||||
msg -> sendTime = time(NULL);
|
||||
msg -> recvTime = time(NULL);
|
||||
@ -796,7 +796,7 @@ bool p3MsgService::setMsgParentId(uint32_t msgId, uint32_t msgParentId)
|
||||
{
|
||||
if (msgParentId) {
|
||||
RsMsgParentId* msp = new RsMsgParentId();
|
||||
msp->PeerId (mConnMgr->getOwnId());
|
||||
msp->PeerId (mLinkMgr->getOwnId());
|
||||
msp->msgId = msgId;
|
||||
msp->msgParentId = msgParentId;
|
||||
mParentId.insert(std::pair<uint32_t, RsMsgParentId*>(msgId, msp));
|
||||
@ -842,7 +842,7 @@ int p3MsgService::sendMessage(RsMsgItem *item)
|
||||
/* STORE MsgID */
|
||||
msgOutgoing[item->msgId] = item;
|
||||
|
||||
if (item->PeerId() != mConnMgr->getOwnId()) {
|
||||
if (item->PeerId() != mLinkMgr->getOwnId()) {
|
||||
/* not to the loopback device */
|
||||
RsMsgSrcId* msi = new RsMsgSrcId();
|
||||
msi->msgId = item->msgId;
|
||||
@ -891,7 +891,7 @@ bool p3MsgService::MessageSend(MessageInfo &info)
|
||||
}
|
||||
|
||||
/* send to ourselves as well */
|
||||
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
||||
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
|
||||
if (msg)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
||||
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
|
||||
if (msg)
|
||||
{
|
||||
uint32_t msgId = 0;
|
||||
@ -992,7 +992,7 @@ bool p3MsgService::setMessageTagType(uint32_t tagId, std::string& text, uint32
|
||||
|
||||
/* new tag */
|
||||
RsMsgTagType* tagType = new RsMsgTagType();
|
||||
tagType->PeerId (mConnMgr->getOwnId());
|
||||
tagType->PeerId (mLinkMgr->getOwnId());
|
||||
tagType->rgb_color = rgb_color;
|
||||
tagType->tagId = tagId;
|
||||
tagType->text = text;
|
||||
@ -1136,7 +1136,7 @@ bool p3MsgService::setMessageTag(const std::string &msgId, uint32_t tagId, bool
|
||||
if (set) {
|
||||
/* new msg */
|
||||
RsMsgTags* tag = new RsMsgTags();
|
||||
tag->PeerId (mConnMgr->getOwnId());
|
||||
tag->PeerId (mLinkMgr->getOwnId());
|
||||
|
||||
tag->msgId = mid;
|
||||
tag->tagIds.push_back(tagId);
|
||||
@ -1280,7 +1280,7 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
|
||||
/* translate flags, if we sent it... outgoing */
|
||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
||||
|| (msg->PeerId() == mLinkMgr->getOwnId()))
|
||||
{
|
||||
mi.msgflags |= RS_MSG_OUTGOING;
|
||||
}
|
||||
@ -1379,7 +1379,7 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
||||
|
||||
/* translate flags, if we sent it... outgoing */
|
||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
||||
|| (msg->PeerId() == mLinkMgr->getOwnId()))
|
||||
{
|
||||
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) */
|
||||
if (to == mConnMgr->getOwnId())
|
||||
if (to == mLinkMgr->getOwnId())
|
||||
{
|
||||
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
||||
{
|
||||
|
@ -43,12 +43,12 @@
|
||||
#include "serialiser/rsmsgitems.h"
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
class p3ConnectMgr;
|
||||
class p3LinkMgr;
|
||||
|
||||
class p3MsgService: public p3Service, public p3Config, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
p3MsgService(p3ConnectMgr *cm);
|
||||
p3MsgService(p3LinkMgr *lm);
|
||||
|
||||
/* External Interface */
|
||||
bool MsgsChanged(); /* should update display */
|
||||
@ -113,7 +113,7 @@ RsMsgItem *initMIRsMsg(MessageInfo &info, std::string to);
|
||||
|
||||
void initStandardTagTypes();
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
/* Mutex Required for stuff below */
|
||||
|
||||
|
@ -27,8 +27,10 @@
|
||||
#include "services/p3portservice.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
|
||||
p3PortService::p3PortService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_PORT), mConnMgr(cm), mEnabled(false)
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
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
|
||||
* which are handled in the RsServiceSerialiser
|
||||
|
@ -59,13 +59,14 @@
|
||||
|
||||
#include "serialiser/rsbaseitems.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
|
||||
|
||||
class p3PortService: public p3Service
|
||||
{
|
||||
public:
|
||||
p3PortService(p3ConnectMgr *cm);
|
||||
p3PortService(p3LinkMgr *lm);
|
||||
|
||||
/* example setup functions */
|
||||
bool enablePortForwarding(uint32_t port, std::string peerId);
|
||||
@ -75,7 +76,7 @@ virtual int tick();
|
||||
|
||||
private:
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
bool mEnabled;
|
||||
bool mPeerOnline;
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||
{
|
||||
out << "StatusInfo: " << std::endl;
|
||||
@ -43,8 +45,8 @@ std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||
|
||||
RsStatus *rsStatus = NULL;
|
||||
|
||||
p3StatusService::p3StatusService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mConnMgr(cm), mStatusMtx("p3StatusService")
|
||||
p3StatusService::p3StatusService(p3LinkMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mLinkMgr(cm), mStatusMtx("p3StatusService")
|
||||
{
|
||||
addSerialType(new RsStatusSerialiser());
|
||||
|
||||
@ -61,7 +63,7 @@ bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
|
||||
#endif
|
||||
|
||||
std::map<std::string, StatusInfo>::iterator it;
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
it = mStatusInfoMap.find(ownId);
|
||||
@ -128,7 +130,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
|
||||
statusInfo.id = mConnMgr->getOwnId();
|
||||
statusInfo.id = mLinkMgr->getOwnId();
|
||||
statusInfo.status = status;
|
||||
|
||||
// don't save inactive status
|
||||
@ -148,7 +150,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
||||
}
|
||||
|
||||
if (id.empty()) {
|
||||
mConnMgr->getOnlineList(onlineList);
|
||||
mLinkMgr->getOnlineList(onlineList);
|
||||
} else {
|
||||
onlineList.push_back(id);
|
||||
}
|
||||
@ -257,11 +259,11 @@ bool p3StatusService::saveList(bool& cleanup, std::list<RsItem*>& ilist){
|
||||
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
it = mStatusInfoMap.find(mConnMgr->getOwnId());
|
||||
it = mStatusInfoMap.find(mLinkMgr->getOwnId());
|
||||
|
||||
if(it == mStatusInfoMap.end()){
|
||||
std::cerr << "p3StatusService::saveList() :" << "Did not find your status"
|
||||
<< mConnMgr->getOwnId() << std::endl;
|
||||
<< mLinkMgr->getOwnId() << std::endl;
|
||||
delete own_status;
|
||||
return false;
|
||||
}
|
||||
@ -295,14 +297,14 @@ bool p3StatusService::loadList(std::list<RsItem*>& load){
|
||||
|
||||
if(own_status != NULL){
|
||||
|
||||
own_info.id = mConnMgr->getOwnId();
|
||||
own_info.id = mLinkMgr->getOwnId();
|
||||
own_info.status = own_status->status;
|
||||
own_info.time_stamp = own_status->sendTime;
|
||||
delete own_status;
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,10 @@
|
||||
#include "serialiser/rsstatusitems.h"
|
||||
#include "retroshare/rsstatus.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
|
||||
/*!
|
||||
@ -45,7 +48,7 @@ class p3StatusService: public p3Service, public p3Config, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
p3StatusService(p3ConnectMgr* );
|
||||
p3StatusService(p3LinkMgr *lm);
|
||||
virtual ~p3StatusService();
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
@ -90,7 +93,7 @@ virtual bool loadList(std::list<RsItem*>& load);
|
||||
|
||||
virtual void receiveStatusQueue();
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
std::map<std::string, StatusInfo> mStatusInfoMap;
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "retroshare/rsfiles.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/pqinotify.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_ALLOWED_SR_IN_CACHE = 120 ; /// maximum number of search requests allowed in cache. That makes 2 per sec.
|
||||
|
||||
p3turtle::p3turtle(p3ConnectMgr *cm,ftServer *fs)
|
||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm), mTurtleMtx("p3turtle")
|
||||
p3turtle::p3turtle(p3LinkMgr *lm,ftServer *fs)
|
||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mLinkMgr(lm), mTurtleMtx("p3turtle")
|
||||
{
|
||||
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 ;
|
||||
#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 tunnel id from the file hash
|
||||
// - 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 ;
|
||||
}
|
||||
}
|
||||
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
|
||||
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
|
||||
// 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 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(item->PeerId() != mConnMgr->getOwnId())
|
||||
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
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)
|
||||
{
|
||||
std::list<std::string> onlineIds ;
|
||||
mConnMgr->getOnlineList(onlineIds);
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Looking for online peers" << std::endl ;
|
||||
#endif
|
||||
@ -846,7 +846,7 @@ void p3turtle::handleSearchResult(RsTurtleSearchResultItem *item)
|
||||
|
||||
++(item->depth) ; // increase depth
|
||||
|
||||
if(it->second.origin == mConnMgr->getOwnId())
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
returnSearchResult(item) ; // Yes, so send upward.
|
||||
else
|
||||
{ // 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.
|
||||
|
||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT && tunnel.local_src != mConnMgr->getOwnId())
|
||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT && tunnel.local_src != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Forwarding generic item to peer " << tunnel.local_src << std::endl ;
|
||||
@ -919,7 +919,7 @@ void p3turtle::routeGenericTunnelItem(RsTurtleGenericTunnelItem *item)
|
||||
return ;
|
||||
}
|
||||
|
||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER && tunnel.local_dst != mConnMgr->getOwnId())
|
||||
if(direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER && tunnel.local_dst != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
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 ;
|
||||
item->tunnel_id = tunnel_id ;
|
||||
|
||||
std::string ownid = mConnMgr->getOwnId() ;
|
||||
std::string ownid = mLinkMgr->getOwnId() ;
|
||||
|
||||
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->compressed_map = cmap ;
|
||||
|
||||
std::string ownid = mConnMgr->getOwnId() ;
|
||||
std::string ownid = mLinkMgr->getOwnId() ;
|
||||
|
||||
if(tunnel.local_src == ownid)
|
||||
{
|
||||
@ -1491,9 +1491,9 @@ bool p3turtle::isOnline(const std::string& peer_id) const
|
||||
TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||
{
|
||||
#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
|
||||
while(mConnMgr->getOwnId() == "")
|
||||
while(mLinkMgr->getOwnId() == "")
|
||||
{
|
||||
std::cerr << "... waiting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
@ -1517,7 +1517,7 @@ TurtleRequestId p3turtle::diggTunnel(const TurtleFileHash& hash)
|
||||
//
|
||||
RsTurtleOpenTunnelItem *item = new RsTurtleOpenTunnelItem ;
|
||||
|
||||
item->PeerId(mConnMgr->getOwnId()) ;
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->file_hash = hash ;
|
||||
item->request_id = id ;
|
||||
item->partial_tunnel_id = generatePersonalFilePrint(hash,true) ;
|
||||
@ -1651,7 +1651,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
bool found = false ;
|
||||
FileInfo info ;
|
||||
|
||||
if(item->PeerId() != mConnMgr->getOwnId())
|
||||
if(item->PeerId() != mLinkMgr->getOwnId())
|
||||
{
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Request not from us. Performing local search" << std::endl ;
|
||||
@ -1681,7 +1681,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
TurtleTunnel tt ;
|
||||
tt.local_src = item->PeerId() ;
|
||||
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.transfered_bytes = 0 ;
|
||||
tt.speed_Bps = 0.0f ;
|
||||
@ -1712,7 +1712,7 @@ void p3turtle::handleTunnelRequest(RsTurtleOpenTunnelItem *item)
|
||||
if(item->depth < TURTLE_MAX_SEARCH_DEPTH || random_bypass)
|
||||
{
|
||||
std::list<std::string> onlineIds ;
|
||||
mConnMgr->getOnlineList(onlineIds);
|
||||
mLinkMgr->getOnlineList(onlineIds);
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << " Forwarding tunnel request: Looking for online peers" << std::endl ;
|
||||
#endif
|
||||
@ -1804,7 +1804,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item)
|
||||
|
||||
// Is this result's target actually ours ?
|
||||
|
||||
if(it->second.origin == mConnMgr->getOwnId())
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
{
|
||||
#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;
|
||||
@ -1949,9 +1949,9 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||
RsTurtleStringSearchRequestItem *item = new RsTurtleStringSearchRequestItem ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "performing search. OwnId = " << mConnMgr->getOwnId() << std::endl ;
|
||||
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||
#endif
|
||||
while(mConnMgr->getOwnId() == "")
|
||||
while(mLinkMgr->getOwnId() == "")
|
||||
{
|
||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
@ -1961,7 +1961,7 @@ TurtleRequestId p3turtle::turtleSearch(const std::string& string_to_match)
|
||||
#endif
|
||||
}
|
||||
|
||||
item->PeerId(mConnMgr->getOwnId()) ;
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->match_string = string_to_match ;
|
||||
item->request_id = id ;
|
||||
item->depth = 0 ;
|
||||
@ -1985,9 +1985,9 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||
RsTurtleRegExpSearchRequestItem *item = new RsTurtleRegExpSearchRequestItem ;
|
||||
|
||||
#ifdef P3TURTLE_DEBUG
|
||||
std::cerr << "performing search. OwnId = " << mConnMgr->getOwnId() << std::endl ;
|
||||
std::cerr << "performing search. OwnId = " << mLinkMgr->getOwnId() << std::endl ;
|
||||
#endif
|
||||
while(mConnMgr->getOwnId() == "")
|
||||
while(mLinkMgr->getOwnId() == "")
|
||||
{
|
||||
std::cerr << "... waitting for connect manager to form own id." << std::endl ;
|
||||
#ifdef WIN32
|
||||
@ -1997,7 +1997,7 @@ TurtleRequestId p3turtle::turtleSearch(const LinearizedExpression& expr)
|
||||
#endif
|
||||
}
|
||||
|
||||
item->PeerId(mConnMgr->getOwnId()) ;
|
||||
item->PeerId(mLinkMgr->getOwnId()) ;
|
||||
item->expr = expr ;
|
||||
item->request_id = id ;
|
||||
item->depth = 0 ;
|
||||
|
@ -153,7 +153,7 @@
|
||||
//#define TUNNEL_STATISTICS
|
||||
|
||||
class ftServer ;
|
||||
class p3ConnectMgr;
|
||||
class p3LinkMgr;
|
||||
class ftDataMultiplex;
|
||||
class RsSerialiser;
|
||||
|
||||
@ -214,7 +214,7 @@ class TurtleFileHashInfo
|
||||
class p3turtle: public p3Service, /*public pqiMonitor,*/ public RsTurtle,/* public ftSearch */ public p3Config
|
||||
{
|
||||
public:
|
||||
p3turtle(p3ConnectMgr *cm,ftServer *m);
|
||||
p3turtle(p3LinkMgr *lm,ftServer *m);
|
||||
|
||||
// Lauches a search request through the pipes, and immediately returns
|
||||
// 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 --------------------------------//
|
||||
|
||||
/* data */
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
ftServer *_ft_server ;
|
||||
ftController *_ft_controller ;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user