Added Virtual Interfaces for p3LinkMgr, p3NetMgr & p3PeerMgr.

Shifted real functionality to p3LinkMgrIMPL, p3NetMgrIMPL p3PeerMgrIMPL
This allows us to test most objects with dummy objects (i.e. no need for full AuthSSL/AuthGPG objects)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4441 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-13 14:22:25 +00:00
parent 85d232ff4f
commit 8d5bde1b50
9 changed files with 734 additions and 536 deletions

View File

@ -128,7 +128,7 @@ std::string textPeerConnectState(peerConnectState &state)
*/ */
p3LinkMgr::p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr) p3LinkMgrIMPL::p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr)
:mPeerMgr(peerMgr), mNetMgr(netMgr), mLinkMtx("p3LinkMgr"),mStatusChanged(false) :mPeerMgr(peerMgr), mNetMgr(netMgr), mLinkMtx("p3LinkMgr"),mStatusChanged(false)
{ {
@ -158,32 +158,32 @@ p3LinkMgr::p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr)
return; return;
} }
void p3LinkMgr::setTunnelConnection(bool b) void p3LinkMgrIMPL::setTunnelConnection(bool b)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
mAllowTunnelConnection = b; mAllowTunnelConnection = b;
} }
bool p3LinkMgr::getTunnelConnection() bool p3LinkMgrIMPL::getTunnelConnection()
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
return mAllowTunnelConnection; return mAllowTunnelConnection;
} }
bool p3LinkMgr::setLocalAddress(struct sockaddr_in addr) bool p3LinkMgrIMPL::setLocalAddress(struct sockaddr_in addr)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
mLocalAddress = addr; mLocalAddress = addr;
} }
struct sockaddr_in p3LinkMgr::getLocalAddress() struct sockaddr_in p3LinkMgrIMPL::getLocalAddress()
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
return mLocalAddress; return mLocalAddress;
} }
bool p3LinkMgr::isOnline(const std::string &ssl_id) bool p3LinkMgrIMPL::isOnline(const std::string &ssl_id)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -201,7 +201,7 @@ bool p3LinkMgr::isOnline(const std::string &ssl_id)
return false; return false;
} }
void p3LinkMgr::getOnlineList(std::list<std::string> &ssl_peers) void p3LinkMgrIMPL::getOnlineList(std::list<std::string> &ssl_peers)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -216,7 +216,7 @@ void p3LinkMgr::getOnlineList(std::list<std::string> &ssl_peers)
return; return;
} }
void p3LinkMgr::getFriendList(std::list<std::string> &ssl_peers) void p3LinkMgrIMPL::getFriendList(std::list<std::string> &ssl_peers)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -230,7 +230,7 @@ void p3LinkMgr::getFriendList(std::list<std::string> &ssl_peers)
} }
int p3LinkMgr::getFriendCount() int p3LinkMgrIMPL::getFriendCount()
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -239,7 +239,7 @@ int p3LinkMgr::getFriendCount()
} }
int p3LinkMgr::getOnlineCount() int p3LinkMgrIMPL::getOnlineCount()
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -258,7 +258,7 @@ int p3LinkMgr::getOnlineCount()
} }
bool p3LinkMgr::getFriendNetStatus(const std::string &id, peerConnectState &state) bool p3LinkMgrIMPL::getFriendNetStatus(const std::string &id, peerConnectState &state)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -275,7 +275,7 @@ bool p3LinkMgr::getFriendNetStatus(const std::string &id, peerConnectState &s
void p3LinkMgr::setFriendVisibility(const std::string &id, bool isVisible) void p3LinkMgrIMPL::setFriendVisibility(const std::string &id, bool isVisible)
{ {
/* set visibility */ /* set visibility */
{ {
@ -288,7 +288,7 @@ void p3LinkMgr::setFriendVisibility(const std::string &id, bool isVisible)
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
/* */ /* */
std::cerr << "p3LinkMgr::setFriendVisibility() ERROR peer unknown: " << id; std::cerr << "p3LinkMgrIMPL::setFriendVisibility() ERROR peer unknown: " << id;
std::cerr << std::endl; std::cerr << std::endl;
return; return;
} }
@ -313,24 +313,14 @@ void p3LinkMgr::setFriendVisibility(const std::string &id, bool isVisible)
} }
void p3LinkMgr::tick() void p3LinkMgrIMPL::tick()
{ {
statusTick(); statusTick();
tickMonitors(); tickMonitors();
} }
bool p3LinkMgr::shutdown() /* blocking shutdown call */
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::shutdown() NOOP";
std::cerr << std::endl;
#endif
return true; void p3LinkMgrIMPL::statusTick()
}
void p3LinkMgr::statusTick()
{ {
/* iterate through peers ... /* iterate through peers ...
* if been available for long time ... remove flag * if been available for long time ... remove flag
@ -339,7 +329,7 @@ void p3LinkMgr::statusTick()
*/ */
#ifdef LINKMGR_DEBUG_TICK #ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick()" << std::endl; std::cerr << "p3LinkMgrIMPL::statusTick()" << std::endl;
#endif #endif
std::list<std::string> retryIds; std::list<std::string> retryIds;
std::list<std::string>::iterator it2; std::list<std::string>::iterator it2;
@ -363,7 +353,7 @@ void p3LinkMgr::statusTick()
(it->second.lastavailable < oldavail)) (it->second.lastavailable < oldavail))
{ {
#ifdef LINKMGR_DEBUG_TICK #ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick() ONLINE TIMEOUT for: "; std::cerr << "p3LinkMgrIMPL::statusTick() ONLINE TIMEOUT for: ";
std::cerr << it->first; std::cerr << it->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -382,7 +372,7 @@ void p3LinkMgr::statusTick()
for(it2 = retryIds.begin(); it2 != retryIds.end(); it2++) for(it2 = retryIds.begin(); it2 != retryIds.end(); it2++)
{ {
#ifdef LINKMGR_DEBUG_TICK #ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick() RETRY TIMEOUT for: "; std::cerr << "p3LinkMgrIMPL::statusTick() RETRY TIMEOUT for: ";
std::cerr << *it2; std::cerr << *it2;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -399,7 +389,7 @@ void p3LinkMgr::statusTick()
* Configuration Loading / Saving. * Configuration Loading / Saving.
*/ */
void p3LinkMgr::addMonitor(pqiMonitor *mon) void p3LinkMgrIMPL::addMonitor(pqiMonitor *mon)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -415,7 +405,7 @@ void p3LinkMgr::addMonitor(pqiMonitor *mon)
return; return;
} }
void p3LinkMgr::removeMonitor(pqiMonitor *mon) void p3LinkMgrIMPL::removeMonitor(pqiMonitor *mon)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -431,7 +421,7 @@ void p3LinkMgr::removeMonitor(pqiMonitor *mon)
return; return;
} }
void p3LinkMgr::tickMonitors() void p3LinkMgrIMPL::tickMonitors()
{ {
bool doStatusChange = false; bool doStatusChange = false;
std::list<pqipeer> actionList; std::list<pqipeer> actionList;
@ -443,7 +433,7 @@ void p3LinkMgr::tickMonitors()
if (mStatusChanged) if (mStatusChanged)
{ {
#ifdef LINKMGR_DEBUG_ACTIONS #ifdef LINKMGR_DEBUG_ACTIONS
std::cerr << "p3LinkMgr::tickMonitors() StatusChanged! List:" << std::endl; std::cerr << "p3LinkMgrIMPL::tickMonitors() StatusChanged! List:" << std::endl;
#endif #endif
/* assemble list */ /* assemble list */
for(it = mFriendList.begin(); it != mFriendList.end(); it++) for(it = mFriendList.begin(); it != mFriendList.end(); it++)
@ -590,13 +580,13 @@ void p3LinkMgr::tickMonitors()
} }
const std::string p3LinkMgr::getOwnId() const std::string p3LinkMgrIMPL::getOwnId()
{ {
return AuthSSL::getAuthSSL()->OwnId(); return AuthSSL::getAuthSSL()->OwnId();
} }
bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr, bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type) uint32_t &delay, uint32_t &period, uint32_t &type)
{ {
@ -608,7 +598,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() FAILED Not in FriendList! id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() FAILED Not in FriendList! id: " << id << std::endl;
#endif #endif
return false; return false;
@ -617,7 +607,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
if (it->second.connAddrs.size() < 1) if (it->second.connAddrs.size() < 1)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() FAILED No ConnectAddresses id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() FAILED No ConnectAddresses id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -626,8 +616,8 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
if (it->second.state & RS_PEER_S_CONNECTED) if (it->second.state & RS_PEER_S_CONNECTED)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() Already FLAGGED as connected!!!!" << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() Already FLAGGED as connected!!!!" << std::endl;
std::cerr << "p3LinkMgr::connectAttempt() But allowing anyway!!!" << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() But allowing anyway!!!" << std::endl;
#endif #endif
} }
@ -643,13 +633,13 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() found an address: id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl;
std::cerr << " laddr: " << rs_inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period; std::cerr << " laddr: " << rs_inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period;
std::cerr << " type: " << type << std::endl; std::cerr << " type: " << type << std::endl;
#endif #endif
if (addr.sin_addr.s_addr == 0 || addr.sin_port == 0) { if (addr.sin_addr.s_addr == 0 || addr.sin_port == 0) {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() WARNING: address or port is null" << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() WARNING: address or port is null" << std::endl;
std::cerr << " type: " << type << std::endl; std::cerr << " type: " << type << std::endl;
#endif #endif
} }
@ -666,7 +656,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
* *
*/ */
bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address) bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address)
{ {
bool doDhtAssist = false ; bool doDhtAssist = false ;
bool updatePeerAddr = false; bool updatePeerAddr = false;
@ -675,19 +665,19 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called Connect!: id: " + id); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectResult() called Connect!: id: " + id);
if (success) if (success)
{ {
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with SUCCESS."); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectResult() called with SUCCESS.");
} else } else
{ {
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() called with FAILED."); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectResult() called with FAILED.");
} }
if (id == getOwnId()) if (id == getOwnId())
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Failed, connecting to own id: "); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectResult() Failed, connecting to own id: ");
#endif #endif
return false; return false;
} }
@ -697,7 +687,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() ERROR, missing Friend " << " id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectResult() ERROR, missing Friend " << " id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -706,16 +696,16 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
{ {
/* update address (should also come through from DISC) */ /* update address (should also come through from DISC) */
#ifdef LINKMGR_DEBUG_CONNFAIL #ifdef LINKMGR_DEBUG_CONNFAIL
std::cerr << "p3LinkMgr::connectResult() Connect!: id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectResult() Connect!: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl; std::cerr << " Success: " << success << " flags: " << flags << std::endl;
#endif #endif
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Connect!: id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectResult() Connect!: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl; std::cerr << " Success: " << success << " flags: " << flags << std::endl;
#endif #endif
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Success"); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::connectResult() Success");
/* change state */ /* change state */
it->second.state |= RS_PEER_S_CONNECTED; it->second.state |= RS_PEER_S_CONNECTED;
@ -745,7 +735,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
{ {
updatePeerAddr = true; updatePeerAddr = true;
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() adding current peer address in list." << std::endl; std::cerr << "p3LinkMgrIMPL::connectResult() adding current peer address in list." << std::endl;
#endif #endif
} }
@ -757,17 +747,17 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
else else
{ {
#ifdef LINKMGR_DEBUG_CONNFAIL #ifdef LINKMGR_DEBUG_CONNFAIL
std::cerr << "p3LinkMgr::connectResult() Disconnect/Fail: flags: " << flags << " id: " << id; std::cerr << "p3LinkMgrIMPL::connectResult() Disconnect/Fail: flags: " << flags << " id: " << id;
std::cerr << std::endl; std::cerr << std::endl;
if (it->second.inConnAttempt) if (it->second.inConnAttempt)
{ {
std::cerr << "p3LinkMgr::connectResult() Likely Connect Fail, as inConnAttempt Flag is set"; std::cerr << "p3LinkMgrIMPL::connectResult() Likely Connect Fail, as inConnAttempt Flag is set";
std::cerr << std::endl; std::cerr << std::endl;
} }
if (it->second.state & RS_PEER_S_CONNECTED) if (it->second.state & RS_PEER_S_CONNECTED)
{ {
std::cerr << "p3LinkMgr::connectResult() Likely DISCONNECT, as state set to Connected"; std::cerr << "p3LinkMgrIMPL::connectResult() Likely DISCONNECT, as state set to Connected";
std::cerr << std::endl; std::cerr << std::endl;
} }
#endif #endif
@ -775,7 +765,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
it->second.inConnAttempt = false; it->second.inConnAttempt = false;
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Disconnect/Fail: id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectResult() Disconnect/Fail: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl; std::cerr << " Success: " << success << " flags: " << flags << std::endl;
#endif #endif
@ -810,7 +800,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
raddr.mSrc = 0; raddr.mSrc = 0;
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Success and we initiated connection... Updating Address"; std::cerr << "p3LinkMgrIMPL::connectResult() Success and we initiated connection... Updating Address";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mPeerMgr->updateCurrentAddress(id, raddr); mPeerMgr->updateCurrentAddress(id, raddr);
@ -825,7 +815,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
if (success) if (success)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Success switching off DhtAssist for friend: " << id; std::cerr << "p3LinkMgrIMPL::connectResult() Success switching off DhtAssist for friend: " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* always switch it off now */ /* always switch it off now */
@ -836,7 +826,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
if (doDhtAssist) if (doDhtAssist)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Fail, Enabling DhtAssist for: " << id; std::cerr << "p3LinkMgrIMPL::connectResult() Fail, Enabling DhtAssist for: " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mNetMgr->netAssistFriend(id,true) ; mNetMgr->netAssistFriend(id,true) ;
@ -844,7 +834,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
else else
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Fail, No DhtAssist, as No DHT visibility for: " << id; std::cerr << "p3LinkMgrIMPL::connectResult() Fail, No DhtAssist, as No DHT visibility for: " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
@ -858,7 +848,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
*/ */
void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs, void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source) uint32_t type, uint32_t flags, uint32_t source)
{ {
/* HACKED UP FIX ****/ /* HACKED UP FIX ****/
@ -886,7 +876,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
{ {
/* Log */ /* Log */
std::ostringstream out; std::ostringstream out;
out << "p3LinkMgr::peerStatus()" << " id: " << id; out << "p3LinkMgrIMPL::peerStatus()" << " id: " << id;
out << " type: " << type << " flags: " << flags; out << " type: " << type << " flags: " << flags;
out << " source: " << source; out << " source: " << source;
out << std::endl; out << std::endl;
@ -909,17 +899,17 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
{ {
/* not found - ignore */ /* not found - ignore */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Peer Not Found - Ignore" << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() Peer Not Found - Ignore" << std::endl;
#endif #endif
return; return;
} }
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Peer is in mOthersList" << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() Peer is in mOthersList" << std::endl;
#endif #endif
} }
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Current Peer State:" << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() Current Peer State:" << std::endl;
printConnectState(std::cerr, it->second); printConnectState(std::cerr, it->second);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -930,7 +920,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
if (source == RS_CB_DHT) if (source == RS_CB_DHT)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From DHT:"; std::cerr << "p3LinkMgrIMPL::peerStatus() Update From DHT:";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* DHT can tell us about /* DHT can tell us about
@ -948,7 +938,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
else if (source == RS_CB_DISC) else if (source == RS_CB_DISC)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From DISC:"; std::cerr << "p3LinkMgrIMPL::peerStatus() Update From DISC:";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* DISC can tell us about /* DISC can tell us about
@ -976,7 +966,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
* -> update all! * -> update all!
*/ */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From PERSON:"; std::cerr << "p3LinkMgrIMPL::peerStatus() Update From PERSON:";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1067,11 +1057,11 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
if (!isFriend) if (!isFriend)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() NOT FRIEND " << " id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() NOT FRIEND " << " id: " << id << std::endl;
#endif #endif
{ {
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::peerStatus() NO CONNECT (not friend)"); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::peerStatus() NO CONNECT (not friend)");
} }
return; return;
} }
@ -1080,11 +1070,11 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
if (it->second.state & RS_PEER_S_CONNECTED) if (it->second.state & RS_PEER_S_CONNECTED)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() PEER ONLINE ALREADY " << " id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() PEER ONLINE ALREADY " << " id: " << id << std::endl;
#endif #endif
{ {
/* Log */ /* Log */
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::peerStatus() NO CONNECT (already connected!)"); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::peerStatus() NO CONNECT (already connected!)");
} }
return; return;
@ -1101,7 +1091,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
} }
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus()" << " id: " << id; std::cerr << "p3LinkMgrIMPL::peerStatus()" << " id: " << id;
std::cerr << " type: " << type << " flags: " << flags; std::cerr << " type: " << type << " flags: " << flags;
std::cerr << " source: " << source << std::endl; std::cerr << " source: " << source << std::endl;
std::cerr << " addrs: " << std::endl; std::cerr << " addrs: " << std::endl;
@ -1125,24 +1115,24 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
#endif // P3CONNMGR_NO_AUTO_CONNECTION #endif // P3CONNMGR_NO_AUTO_CONNECTION
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Resulting Peer State:" << std::endl; std::cerr << "p3LinkMgrIMPL::peerStatus() Resulting Peer State:" << std::endl;
printConnectState(std::cerr, it->second); printConnectState(std::cerr, it->second);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr, void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source) uint32_t source)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port); std::cerr << "p3LinkMgrIMPL::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " source: " << source << std::endl; std::cerr << " source: " << source << std::endl;
#endif #endif
{ {
/* Log */ /* Log */
std::ostringstream out; std::ostringstream out;
out << "p3LinkMgr::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr); out << "p3LinkMgrIMPL::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr);
out << ":" << ntohs(raddr.sin_port) << " source: " << source; out << ":" << ntohs(raddr.sin_port) << " source: " << source;
rslog(RSL_WARNING, p3connectzone, out.str()); rslog(RSL_WARNING, p3connectzone, out.str());
} }
@ -1150,13 +1140,13 @@ void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
/******************** TCP PART *****************************/ /******************** TCP PART *****************************/
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() Try TCP first" << std::endl; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() Try TCP first" << std::endl;
#endif #endif
if (source == RS_CB_DHT) if (source == RS_CB_DHT)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() source DHT ==> retryConnectUDP()"; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() source DHT ==> retryConnectUDP()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
retryConnectUDP(id, raddr); retryConnectUDP(id, raddr);
@ -1164,7 +1154,7 @@ void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
} }
else else
{ // IS THIS USED??? { // IS THIS USED???
std::cerr << "p3LinkMgr::peerConnectRequest() ERROR source OTHER ==> retryConnect()" << std::endl; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() ERROR source OTHER ==> retryConnect()" << std::endl;
std::cerr << std::endl; std::cerr << std::endl;
retryConnect(id); retryConnect(id);
@ -1176,11 +1166,11 @@ void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
/*******************************************************************/ /*******************************************************************/
/*******************************************************************/ /*******************************************************************/
/*************** External Control ****************/ /*************** External Control ****************/
bool p3LinkMgr::retryConnect(const std::string &id) bool p3LinkMgrIMPL::retryConnect(const std::string &id)
{ {
/* push all available addresses onto the connect addr stack */ /* push all available addresses onto the connect addr stack */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnect() id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnect() id: " << id << std::endl;
#endif #endif
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS #ifndef P3CONNMGR_NO_TCP_CONNECTIONS
@ -1194,18 +1184,18 @@ bool p3LinkMgr::retryConnect(const std::string &id)
bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr) bool p3LinkMgrIMPL::retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
/* push all available addresses onto the connect addr stack */ /* push all available addresses onto the connect addr stack */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() id: " << id << std::endl;
#endif #endif
if (id == getOwnId()) { if (id == getOwnId()) {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectUDP() Failed, connecting to own id: "); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::retryConnectUDP() Failed, connecting to own id: ");
#endif #endif
return false; return false;
} }
@ -1215,7 +1205,7 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer is not Friend" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer is not Friend" << std::endl;
#endif #endif
return false; return false;
} }
@ -1224,15 +1214,15 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
if (it->second.state & RS_PEER_S_CONNECTED) if (it->second.state & RS_PEER_S_CONNECTED)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Already Connected" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Already Connected" << std::endl;
#endif #endif
if (it->second.connecttype & RS_NET_CONN_TUNNEL) { if (it->second.connecttype & RS_NET_CONN_TUNNEL) {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
#endif #endif
} else { } else {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Connected no more connection attempts" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectUDP() Peer Connected no more connection attempts" << std::endl;
#endif #endif
return false; return false;
} }
@ -1265,7 +1255,7 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
bool p3LinkMgr::retryConnectTCP(const std::string &id) bool p3LinkMgrIMPL::retryConnectTCP(const std::string &id)
{ {
/* Check if we should retry first */ /* Check if we should retry first */
{ {
@ -1278,13 +1268,13 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
*/ */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() id: " << id << std::endl;
#endif #endif
if (id == getOwnId()) if (id == getOwnId())
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: "); rslog(RSL_WARNING, p3connectzone, "p3LinkMgrIMPL::retryConnectTCP() Failed, connecting to own id: ");
#endif #endif
return false; return false;
} }
@ -1294,7 +1284,7 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
if (mFriendList.end() == (it = mFriendList.find(id))) if (mFriendList.end() == (it = mFriendList.find(id)))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer is not Friend" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer is not Friend" << std::endl;
#endif #endif
return false; return false;
} }
@ -1303,18 +1293,18 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
if (it->second.state & RS_PEER_S_CONNECTED) if (it->second.state & RS_PEER_S_CONNECTED)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Already Connected" << std::endl;
#endif #endif
if (it->second.connecttype & RS_NET_CONN_TUNNEL) if (it->second.connecttype & RS_NET_CONN_TUNNEL)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
#endif #endif
} }
else else
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
#endif #endif
return false; return false;
} }
@ -1322,7 +1312,7 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
} /****** END of LOCKED ******/ } /****** END of LOCKED ******/
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Getting Address from PeerMgr for : " << id; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() Getting Address from PeerMgr for : " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* If we reach here, must retry .... extract the required info from p3PeerMgr */ /* If we reach here, must retry .... extract the required info from p3PeerMgr */
@ -1358,13 +1348,13 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
} }
else else
{ {
std::cerr << "p3LinkMgr::retryConnectTCP() ERROR failed to find friend data : " << id; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to find friend data : " << id;
std::cerr << std::endl; std::cerr << std::endl;
} }
} }
else else
{ {
std::cerr << "p3LinkMgr::retryConnectTCP() ERROR failed to addresses from PeerMgr for: " << id; std::cerr << "p3LinkMgrIMPL::retryConnectTCP() ERROR failed to addresses from PeerMgr for: " << id;
std::cerr << std::endl; std::cerr << std::endl;
} }
@ -1375,10 +1365,10 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
#define MAX_TCP_ADDR_AGE (3600 * 24 * 14) // two weeks in seconds. #define MAX_TCP_ADDR_AGE (3600 * 24 * 14) // two weeks in seconds.
bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age) bool p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr("; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr(";
std::cerr << rs_inet_ntoa(addr->sin_addr); std::cerr << rs_inet_ntoa(addr->sin_addr);
std::cerr << ":" << ntohs(addr->sin_port); std::cerr << ":" << ntohs(addr->sin_port);
std::cerr << ", " << age << ")"; std::cerr << ", " << age << ")";
@ -1391,7 +1381,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (age > MAX_TCP_ADDR_AGE) if (age > MAX_TCP_ADDR_AGE)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - TOO OLD"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - TOO OLD";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
@ -1406,7 +1396,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (!isValid) if (!isValid)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - INVALID"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - INVALID";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
@ -1421,7 +1411,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (it->s_addr == addr->sin_addr.s_addr) if (it->s_addr == addr->sin_addr.s_addr)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - ON BANNED IPLIST"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - ON BANNED IPLIST";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
@ -1435,7 +1425,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (isExternal) if (isExternal)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - EXTERNAL"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - EXTERNAL";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return true; return true;
@ -1447,7 +1437,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
- check net against our local address. - check net against our local address.
*/ */
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() Checking sameNet against: "; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() Checking sameNet against: ";
std::cerr << rs_inet_ntoa(mLocalAddress.sin_addr); std::cerr << rs_inet_ntoa(mLocalAddress.sin_addr);
std::cerr << ")"; std::cerr << ")";
std::cerr << std::endl; std::cerr << std::endl;
@ -1455,14 +1445,14 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (sameNet(&(mLocalAddress.sin_addr), &(addr->sin_addr))) if (sameNet(&(mLocalAddress.sin_addr), &(addr->sin_addr)))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return true; return true;
} }
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - PRIVATE & !sameNET"; std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() REJECTING - PRIVATE & !sameNET";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1472,10 +1462,10 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
} }
void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr) void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses()"; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
// Just push all the addresses onto the stack. // Just push all the addresses onto the stack.
@ -1483,7 +1473,7 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer,
if ((localAddr) && (locked_CheckPotentialAddr(localAddr, 0))) if ((localAddr) && (locked_CheckPotentialAddr(localAddr, 0)))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses() "; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses() ";
std::cerr << "Adding tcp connection attempt: "; std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Current Local Addr: " << rs_inet_ntoa(localAddr->sin_addr); std::cerr << "Current Local Addr: " << rs_inet_ntoa(localAddr->sin_addr);
std::cerr << ":" << ntohs(localAddr->sin_port); std::cerr << ":" << ntohs(localAddr->sin_port);
@ -1502,7 +1492,7 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer,
if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0))) if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0)))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses() "; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses() ";
std::cerr << "Adding tcp connection attempt: "; std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(serverAddr->sin_addr); std::cerr << "Current Ext Addr: " << rs_inet_ntoa(serverAddr->sin_addr);
std::cerr << ":" << ntohs(serverAddr->sin_port); std::cerr << ":" << ntohs(serverAddr->sin_port);
@ -1520,7 +1510,7 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer,
} }
void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs) void p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs)
{ {
/* now try historical addresses */ /* now try historical addresses */
/* try local addresses first */ /* try local addresses first */
@ -1528,7 +1518,7 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
time_t now = time(NULL); time_t now = time(NULL);
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses()"; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
for(ait = ipAddrs.mLocal.mAddrs.begin(); for(ait = ipAddrs.mLocal.mAddrs.begin();
@ -1538,7 +1528,7 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses() "; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses() ";
std::cerr << "Adding tcp connection attempt: "; std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Local Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr); std::cerr << "Local Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr);
std::cerr << ":" << ntohs(ait->mAddr.sin_port); std::cerr << ":" << ntohs(ait->mAddr.sin_port);
@ -1563,7 +1553,7 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses() "; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses() ";
std::cerr << "Adding tcp connection attempt: "; std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Ext Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr); std::cerr << "Ext Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr);
std::cerr << ":" << ntohs(ait->mAddr.sin_port); std::cerr << ":" << ntohs(ait->mAddr.sin_port);
@ -1582,19 +1572,19 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
} }
void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t port) void p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t port)
{ {
/* try dyndns address too */ /* try dyndns address too */
struct in_addr addr; struct in_addr addr;
if (!dyndns.empty() && port) if (!dyndns.empty() && port)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() Looking up DynDNS address: " << dyndns << std::endl; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS() Looking up DynDNS address: " << dyndns << std::endl;
#endif #endif
if(mDNSResolver->getIPAddressFromString(dyndns, addr)) if(mDNSResolver->getIPAddressFromString(dyndns, addr))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() "; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS() ";
std::cerr << "Adding tcp connection attempt: "; std::cerr << "Adding tcp connection attempt: ";
std::cerr << "DynDNS Addr: " << rs_inet_ntoa(addr); std::cerr << "DynDNS Addr: " << rs_inet_ntoa(addr);
std::cerr << ":" << ntohs(port); std::cerr << ":" << ntohs(port);
@ -1619,7 +1609,7 @@ void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::st
else else
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() DNSResolver hasn't found addr yet"; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS() DNSResolver hasn't found addr yet";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
@ -1627,14 +1617,14 @@ void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::st
else else
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() Address(" << dyndns << ") or Port(" << port << ") NULL ignoring"; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS() Address(" << dyndns << ") or Port(" << port << ") NULL ignoring";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
} }
void p3LinkMgr::locked_ConnectAttempt_AddTunnel(peerConnectState *peer) void p3LinkMgrIMPL::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
{ {
if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection) if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection)
{ {
@ -1654,13 +1644,13 @@ void p3LinkMgr::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
} }
bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca) bool p3LinkMgrIMPL::addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca)
{ {
/* iterate through the list, and make sure it isn't already /* iterate through the list, and make sure it isn't already
* in the list * in the list
*/ */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Checking Address: " << rs_inet_ntoa(pca.addr.sin_addr); std::cerr << "p3LinkMgrIMPL::addAddressIfUnique() Checking Address: " << rs_inet_ntoa(pca.addr.sin_addr);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1672,7 +1662,7 @@ bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, pee
(pca.type == it->type)) (pca.type == it->type))
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Discarding Duplicate Address"; std::cerr << "p3LinkMgrIMPL::addAddressIfUnique() Discarding Duplicate Address";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* already */ /* already */
@ -1681,7 +1671,7 @@ bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, pee
} }
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Adding New Address"; std::cerr << "p3LinkMgrIMPL::addAddressIfUnique() Adding New Address";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1692,7 +1682,7 @@ bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, pee
bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer) bool p3LinkMgrIMPL::locked_ConnectAttempt_Complete(peerConnectState *peer)
{ {
/* flag as last attempt to prevent loop */ /* flag as last attempt to prevent loop */
@ -1703,9 +1693,9 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
{ {
/* -> it'll automatically use the addresses we added */ /* -> it'll automatically use the addresses we added */
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT"; std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Remaining ConnAddr Count: " << peer->connAddrs.size(); std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_Complete() Remaining ConnAddr Count: " << peer->connAddrs.size();
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return true; return true;
@ -1716,9 +1706,9 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::ostringstream out; std::ostringstream out;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ; out << "p3LinkMgrIMPL::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
out << std::endl; out << std::endl;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() ConnAddr Count: " << peer->connAddrs.size(); out << "p3LinkMgrIMPL::locked_ConnectAttempt_Complete() ConnAddr Count: " << peer->connAddrs.size();
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str()); rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
std::cerr << out.str() << std::endl; std::cerr << out.str() << std::endl;
@ -1732,7 +1722,7 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::ostringstream out; std::ostringstream out;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! "; out << "p3LinkMgrIMPL::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str()); rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
std::cerr << out.str() << std::endl; std::cerr << out.str() << std::endl;
#endif #endif
@ -1746,13 +1736,13 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
************************************* Handling of Friends ************************************************* ************************************* Handling of Friends *************************************************
***********************************************************************************************************/ ***********************************************************************************************************/
int p3LinkMgr::addFriend(const std::string &id, bool isVisible) int p3LinkMgrIMPL::addFriend(const std::string &id, bool isVisible)
{ {
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addFriend(" << id << "," << isVisible << ")"; std::cerr << "p3LinkMgrIMPL::addFriend(" << id << "," << isVisible << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1761,7 +1751,7 @@ int p3LinkMgr::addFriend(const std::string &id, bool isVisible)
if (it != mFriendList.end()) if (it != mFriendList.end())
{ {
std::cerr << "p3LinkMgr::addFriend() ERROR, friend already exists : " << id; std::cerr << "p3LinkMgrIMPL::addFriend() ERROR, friend already exists : " << id;
std::cerr << std::endl; std::cerr << std::endl;
return 0; return 0;
} }
@ -1784,13 +1774,13 @@ int p3LinkMgr::addFriend(const std::string &id, bool isVisible)
} }
int p3LinkMgr::removeFriend(const std::string &id) int p3LinkMgrIMPL::removeFriend(const std::string &id)
{ {
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::removeFriend(" << id << ")"; std::cerr << "p3LinkMgrIMPL::removeFriend(" << id << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1799,7 +1789,7 @@ int p3LinkMgr::removeFriend(const std::string &id)
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
std::cerr << "p3LinkMgr::removeFriend() ERROR, friend not there : " << id; std::cerr << "p3LinkMgrIMPL::removeFriend() ERROR, friend not there : " << id;
std::cerr << std::endl; std::cerr << std::endl;
return 0; return 0;
} }
@ -1825,12 +1815,12 @@ int p3LinkMgr::removeFriend(const std::string &id)
} }
void p3LinkMgr::printPeerLists(std::ostream &out) void p3LinkMgrIMPL::printPeerLists(std::ostream &out)
{ {
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
out << "p3LinkMgr::printPeerLists() Friend List"; out << "p3LinkMgrIMPL::printPeerLists() Friend List";
out << std::endl; out << std::endl;
@ -1842,7 +1832,7 @@ void p3LinkMgr::printPeerLists(std::ostream &out)
out << std::endl; out << std::endl;
} }
out << "p3LinkMgr::printPeerLists() Others List"; out << "p3LinkMgrIMPL::printPeerLists() Others List";
out << std::endl; out << std::endl;
for(it = mOthersList.begin(); it != mOthersList.end(); it++) for(it = mOthersList.begin(); it != mOthersList.end(); it++)
{ {

View File

@ -141,102 +141,138 @@ class RsGroupInfo;
class p3PeerMgr; class p3PeerMgr;
class p3NetMgr; class p3NetMgr;
class p3PeerMgrIMPL;
class p3NetMgrIMPL;
std::string textPeerConnectState(peerConnectState &state); std::string textPeerConnectState(peerConnectState &state);
/*******
* Virtual Interface to allow testing
*
*/
class p3LinkMgr: public pqiConnectCb class p3LinkMgr: public pqiConnectCb
{ {
public: public:
p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr); p3LinkMgr() { return; }
virtual ~p3LinkMgr() { return; }
void tick();
/*************** Setup ***************************/ virtual const std::string getOwnId() = 0;
//void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *); virtual bool isOnline(const std::string &ssl_id) = 0;
//void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *); virtual void getOnlineList(std::list<std::string> &ssl_peers) = 0;
//void addNetListener(pqiNetListener *listener); /**************** handle monitors *****************/
virtual void addMonitor(pqiMonitor *mon) = 0;
virtual void removeMonitor(pqiMonitor *mon) = 0;
//bool checkNetAddress(); /* check our address is sensible */ /****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type) = 0;
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address) = 0;
virtual bool retryConnect(const std::string &id) = 0;
/*************** External Control ****************/ /* Network Addresses */
bool shutdown(); /* blocking shutdown call */ virtual bool setLocalAddress(struct sockaddr_in addr) = 0;
virtual struct sockaddr_in getLocalAddress() = 0;
bool retryConnect(const std::string &id); /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
void setTunnelConnection(bool b); virtual void getFriendList(std::list<std::string> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead.
bool getTunnelConnection(); virtual int getOnlineCount() = 0; // ONLY used by p3peers.cc
virtual int getFriendCount() = 0; // ONLY used by p3serverconfig.cc & p3peers.cc
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
void setFriendVisibility(const std::string &id, bool isVisible); virtual void setTunnelConnection(bool b) = 0; // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
virtual bool getTunnelConnection() = 0; // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
//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); /******* overloaded from pqiConnectCb *************/
//bool setVisState(const std::string &id, uint32_t visState); // THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb.
//virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
// uint32_t type, uint32_t flags, uint32_t source) = 0;
//virtual void peerConnectRequest(std::string id,
// struct sockaddr_in raddr, uint32_t source) = 0;
//bool setLocation(const std::string &pid, const std::string &location);//location is shown in the gui to differentiate ssl certs /****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/* add/remove friends */ };
int addFriend(const std::string &ssl_id, bool isVisible);
int removeFriend(const std::string &ssl_id);
void printPeerLists(std::ostream &out);
/*************** External Control ****************/
/* access to network details (called through Monitor) */
const std::string getOwnId();
bool getOwnNetStatus(peerConnectState &state);
bool setLocalAddress(struct sockaddr_in addr); class p3LinkMgrIMPL: public p3LinkMgr
struct sockaddr_in getLocalAddress(); {
public:
bool isOnline(const std::string &ssl_id); /************************************************************************************************/
bool getFriendNetStatus(const std::string &id, peerConnectState &state); /* EXTERNAL INTERFACE */
//bool getOthersNetStatus(const std::string &id, peerConnectState &state); /************************************************************************************************/
void getOnlineList(std::list<std::string> &ssl_peers); virtual const std::string getOwnId();
void getFriendList(std::list<std::string> &ssl_peers); virtual bool isOnline(const std::string &ssl_id);
int getOnlineCount(); virtual void getOnlineList(std::list<std::string> &ssl_peers);
int getFriendCount();
/**************** handle monitors *****************/ /**************** handle monitors *****************/
void addMonitor(pqiMonitor *mon); virtual void addMonitor(pqiMonitor *mon);
void removeMonitor(pqiMonitor *mon); virtual void removeMonitor(pqiMonitor *mon);
/****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type);
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address);
virtual bool retryConnect(const std::string &id);
/* Network Addresses */
virtual bool setLocalAddress(struct sockaddr_in addr);
virtual struct sockaddr_in getLocalAddress();
/******* overloaded from pqiConnectCb *************/ /******* overloaded from pqiConnectCb *************/
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source); uint32_t type, uint32_t flags, uint32_t source);
virtual void peerConnectRequest(std::string id, virtual void peerConnectRequest(std::string id,
struct sockaddr_in raddr, uint32_t source); struct sockaddr_in raddr, uint32_t source);
//virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags);
/****************** Connections *******************/
bool connectAttempt(const std::string &id, struct sockaddr_in &addr, /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
uint32_t &delay, uint32_t &period, uint32_t &type);
bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address); virtual void getFriendList(std::list<std::string> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead.
virtual int getOnlineCount(); // ONLY used by p3peers.cc
virtual int getFriendCount(); // ONLY used by p3serverconfig.cc & p3peers.cc
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); // ONLY used by p3peers.cc
virtual void setTunnelConnection(bool b); // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
virtual bool getTunnelConnection(); // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
/************************************************************************************************/
/* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */
/************************************************************************************************/
p3LinkMgrIMPL(p3PeerMgrIMPL *peerMgr, p3NetMgrIMPL *netMgr);
void tick();
/* THIS COULD BE ADDED TO INTERFACE */
void setFriendVisibility(const std::string &id, bool isVisible);
/* add/remove friends */
int addFriend(const std::string &ssl_id, bool isVisible);
int removeFriend(const std::string &ssl_id);
void printPeerLists(std::ostream &out);
protected:
/* THESE CAN PROBABLY BE REMOVED */
//bool shutdown(); /* blocking shutdown call */
//bool getOwnNetStatus(peerConnectState &state);
protected: protected:
/****************** Internal Interface *******************/ /****************** Internal Interface *******************/
//virtual bool enableNetAssistConnect(bool on);
//virtual bool netAssistConnectEnabled();
//virtual bool netAssistConnectActive();
//virtual bool netAssistConnectShutdown();
//virtual bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize);
/* Assist Connect */
//virtual bool netAssistFriend(std::string id, bool on);
//virtual bool netAssistSetAddress( struct sockaddr_in &laddr,
// struct sockaddr_in &eaddr,
// uint32_t mode);
/* Internal Functions */ /* Internal Functions */
void statusTick(); void statusTick();
@ -266,8 +302,8 @@ private:
//p3tunnel *mP3tunnel; //p3tunnel *mP3tunnel;
DNSResolver *mDNSResolver ; DNSResolver *mDNSResolver ;
p3PeerMgr *mPeerMgr; p3PeerMgrIMPL *mPeerMgr;
p3NetMgr *mNetMgr; p3NetMgrIMPL *mNetMgr;
RsMutex mLinkMtx; /* protects below */ RsMutex mLinkMtx; /* protects below */

View File

@ -111,7 +111,7 @@ void pqiNetStatus::print(std::ostream &out)
} }
p3NetMgr::p3NetMgr() p3NetMgrIMPL::p3NetMgrIMPL()
:mPeerMgr(NULL), mLinkMgr(NULL), mNetMtx("p3NetMgr"), :mPeerMgr(NULL), mLinkMgr(NULL), mNetMtx("p3NetMgr"),
mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false) mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false)
{ {
@ -142,18 +142,18 @@ p3NetMgr::p3NetMgr()
return; return;
} }
void p3NetMgr::setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr) void p3NetMgrIMPL::setManagers(p3PeerMgrIMPL *peerMgr, p3LinkMgrIMPL *linkMgr)
{ {
mPeerMgr = peerMgr; mPeerMgr = peerMgr;
mLinkMgr = linkMgr; mLinkMgr = linkMgr;
} }
//void p3NetMgr::setDhtMgr(p3DhtMgr *dhtMgr) //void p3NetMgrIMPL::setDhtMgr(p3DhtMgr *dhtMgr)
//{ //{
// mDhtMgr = dhtMgr; // mDhtMgr = dhtMgr;
//} //}
void p3NetMgr::setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun) void p3NetMgrIMPL::setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun)
{ {
mDhtStunner = dhtStun; mDhtStunner = dhtStun;
mProxyStunner = proxyStun; mProxyStunner = proxyStun;
@ -224,10 +224,10 @@ void p3NetMgr::setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun)
* - * -
*/ */
void p3NetMgr::netReset() void p3NetMgrIMPL::netReset()
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() Called" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() Called" << std::endl;
#endif #endif
shutdown(); /* blocking shutdown call */ shutdown(); /* blocking shutdown call */
@ -236,19 +236,19 @@ void p3NetMgr::netReset()
if (mUseExtAddrFinder) if (mUseExtAddrFinder)
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() restarting AddrFinder" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() restarting AddrFinder" << std::endl;
#endif #endif
mExtAddrFinder->reset() ; mExtAddrFinder->reset() ;
} }
else else
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() ExtAddrFinder Disabled" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() ExtAddrFinder Disabled" << std::endl;
#endif #endif
} }
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() resetting NetStatus" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() resetting NetStatus" << std::endl;
#endif #endif
/* reset tcp network - if necessary */ /* reset tcp network - if necessary */
@ -266,14 +266,14 @@ void p3NetMgr::netReset()
struct sockaddr_in iaddr = mLocalAddr; struct sockaddr_in iaddr = mLocalAddr;
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() resetting listeners" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() resetting listeners" << std::endl;
#endif #endif
std::list<pqiNetListener *>::const_iterator it; std::list<pqiNetListener *>::const_iterator it;
for(it = mNetListeners.begin(); it != mNetListeners.end(); it++) for(it = mNetListeners.begin(); it != mNetListeners.end(); it++)
{ {
(*it)->resetListener(iaddr); (*it)->resetListener(iaddr);
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() reset listener" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() reset listener" << std::endl;
#endif #endif
} }
} }
@ -287,23 +287,23 @@ void p3NetMgr::netReset()
updateNetStateBox_reset(); updateNetStateBox_reset();
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() done" << std::endl; std::cerr << "p3NetMgrIMPL::netReset() done" << std::endl;
#endif #endif
} }
void p3NetMgr::netStatusReset_locked() void p3NetMgrIMPL::netStatusReset_locked()
{ {
//std::cerr << "p3NetMgr::netStatusReset()" << std::endl;; //std::cerr << "p3NetMgrIMPL::netStatusReset()" << std::endl;;
mNetFlags = pqiNetStatus(); mNetFlags = pqiNetStatus();
} }
bool p3NetMgr::shutdown() /* blocking shutdown call */ bool p3NetMgrIMPL::shutdown() /* blocking shutdown call */
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::shutdown()"; std::cerr << "p3NetMgrIMPL::shutdown()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
{ {
@ -326,7 +326,7 @@ bool p3NetMgr::shutdown() /* blocking shutdown call */
void p3NetMgr::netStartup() void p3NetMgrIMPL::netStartup()
{ {
/* startup stuff */ /* startup stuff */
@ -334,7 +334,7 @@ void p3NetMgr::netStartup()
* This is needed for all systems so startup straight away * This is needed for all systems so startup straight away
*/ */
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup()" << std::endl; std::cerr << "p3NetMgrIMPL::netStartup()" << std::endl;
#endif #endif
netDhtInit(); netDhtInit();
@ -349,7 +349,7 @@ void p3NetMgr::netStartup()
netStatusReset_locked(); netStatusReset_locked();
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() resetting mNetInitTS / Status" << std::endl; std::cerr << "p3NetMgrIMPL::netStartup() resetting mNetInitTS / Status" << std::endl;
#endif #endif
mNetMode &= ~(RS_NET_MODE_ACTUAL); mNetMode &= ~(RS_NET_MODE_ACTUAL);
@ -358,7 +358,7 @@ void p3NetMgr::netStartup()
case RS_NET_MODE_TRY_EXT: /* v similar to UDP */ case RS_NET_MODE_TRY_EXT: /* v similar to UDP */
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_EXT mode"; std::cerr << "p3NetMgrIMPL::netStartup() TRY_EXT mode";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mNetMode |= RS_NET_MODE_EXT; mNetMode |= RS_NET_MODE_EXT;
@ -367,7 +367,7 @@ void p3NetMgr::netStartup()
case RS_NET_MODE_TRY_UDP: case RS_NET_MODE_TRY_UDP:
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_UDP mode"; std::cerr << "p3NetMgrIMPL::netStartup() TRY_UDP mode";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mNetMode |= RS_NET_MODE_UDP; mNetMode |= RS_NET_MODE_UDP;
@ -377,13 +377,13 @@ void p3NetMgr::netStartup()
default: // Fall through. default: // Fall through.
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() UNKNOWN mode"; std::cerr << "p3NetMgrIMPL::netStartup() UNKNOWN mode";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
case RS_NET_MODE_TRY_UPNP: case RS_NET_MODE_TRY_UPNP:
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_UPNP mode"; std::cerr << "p3NetMgrIMPL::netStartup() TRY_UPNP mode";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
/* Force it here (could be default!) */ /* Force it here (could be default!) */
@ -395,7 +395,7 @@ void p3NetMgr::netStartup()
} }
void p3NetMgr::tick() void p3NetMgrIMPL::tick()
{ {
time_t now = time(NULL); time_t now = time(NULL);
bool doSlowTick = false; bool doSlowTick = false;
@ -415,7 +415,7 @@ void p3NetMgr::tick()
} }
void p3NetMgr::slowTick() void p3NetMgrIMPL::slowTick()
{ {
netTick(); netTick();
netAssistConnectTick(); netAssistConnectTick();
@ -436,11 +436,11 @@ void p3NetMgr::slowTick()
#define STARTUP_DELAY 5 #define STARTUP_DELAY 5
void p3NetMgr::netTick() void p3NetMgrIMPL::netTick()
{ {
#ifdef NETMGR_DEBUG_TICK #ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::netTick()" << std::endl; std::cerr << "p3NetMgrIMPL::netTick()" << std::endl;
#endif #endif
// Check whether we are stuck on loopback. This happens if RS starts when // Check whether we are stuck on loopback. This happens if RS starts when
@ -464,14 +464,14 @@ void p3NetMgr::netTick()
case RS_NET_NEEDS_RESET: case RS_NET_NEEDS_RESET:
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: NEEDS_RESET" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: NEEDS_RESET" << std::endl;
#endif #endif
netReset(); netReset();
break; break;
case RS_NET_UNKNOWN: case RS_NET_UNKNOWN:
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UNKNOWN" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: UNKNOWN" << std::endl;
#endif #endif
/* add a small delay to stop restarting straight after a RESET /* add a small delay to stop restarting straight after a RESET
@ -480,7 +480,7 @@ void p3NetMgr::netTick()
if (age < STARTUP_DELAY) if (age < STARTUP_DELAY)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() Delaying Startup" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() Delaying Startup" << std::endl;
#endif #endif
} }
else else
@ -492,14 +492,14 @@ void p3NetMgr::netTick()
case RS_NET_UPNP_INIT: case RS_NET_UPNP_INIT:
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UPNP_INIT" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: UPNP_INIT" << std::endl;
#endif #endif
netUpnpInit(); netUpnpInit();
break; break;
case RS_NET_UPNP_SETUP: case RS_NET_UPNP_SETUP:
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UPNP_SETUP" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: UPNP_SETUP" << std::endl;
#endif #endif
netUpnpCheck(); netUpnpCheck();
break; break;
@ -507,14 +507,14 @@ void p3NetMgr::netTick()
case RS_NET_EXT_SETUP: case RS_NET_EXT_SETUP:
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: EXT_SETUP" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: EXT_SETUP" << std::endl;
#endif #endif
netExtCheck(); netExtCheck();
break; break;
case RS_NET_DONE: case RS_NET_DONE:
#ifdef NETMGR_DEBUG_TICK #ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::netTick() STATUS: DONE" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: DONE" << std::endl;
#endif #endif
break; break;
@ -523,7 +523,7 @@ void p3NetMgr::netTick()
//don't do a shutdown because a client in a computer without local network might be usefull for debug. //don't do a shutdown because a client in a computer without local network might be usefull for debug.
//shutdown(); //shutdown();
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: RS_NET_LOOPBACK" << std::endl; std::cerr << "p3NetMgrIMPL::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#endif #endif
default: default:
break; break;
@ -533,10 +533,10 @@ void p3NetMgr::netTick()
} }
void p3NetMgr::netDhtInit() void p3NetMgrIMPL::netDhtInit()
{ {
#if defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netDhtInit()" << std::endl; std::cerr << "p3NetMgrIMPL::netDhtInit()" << std::endl;
#endif #endif
uint32_t vs = 0; uint32_t vs = 0;
@ -549,10 +549,10 @@ void p3NetMgr::netDhtInit()
} }
void p3NetMgr::netUpnpInit() void p3NetMgrIMPL::netUpnpInit()
{ {
#if defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpInit()" << std::endl; std::cerr << "p3NetMgrIMPL::netUpnpInit()" << std::endl;
#endif #endif
uint16_t eport, iport; uint16_t eport, iport;
@ -574,7 +574,7 @@ void p3NetMgr::netUpnpInit()
enableNetAssistFirewall(true); enableNetAssistFirewall(true);
} }
void p3NetMgr::netUpnpCheck() void p3NetMgrIMPL::netUpnpCheck()
{ {
/* grab timestamp */ /* grab timestamp */
mNetMtx.lock(); /* LOCK MUTEX */ mNetMtx.lock(); /* LOCK MUTEX */
@ -582,7 +582,7 @@ void p3NetMgr::netUpnpCheck()
time_t delta = time(NULL) - mNetInitTS; time_t delta = time(NULL) - mNetInitTS;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() age: " << delta << std::endl; std::cerr << "p3NetMgrIMPL::netUpnpCheck() age: " << delta << std::endl;
#endif #endif
mNetMtx.unlock(); /* UNLOCK MUTEX */ mNetMtx.unlock(); /* UNLOCK MUTEX */
@ -594,7 +594,7 @@ void p3NetMgr::netUpnpCheck()
((upnpState > 0) && (delta > (time_t)MAX_UPNP_COMPLETE))) ((upnpState > 0) && (delta > (time_t)MAX_UPNP_COMPLETE)))
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() "; std::cerr << "p3NetMgrIMPL::netUpnpCheck() ";
std::cerr << "Upnp Check failed." << std::endl; std::cerr << "Upnp Check failed." << std::endl;
#endif #endif
/* fallback to UDP startup */ /* fallback to UDP startup */
@ -609,7 +609,7 @@ void p3NetMgr::netUpnpCheck()
else if ((upnpState > 0) && netAssistExtAddress(extAddr)) else if ((upnpState > 0) && netAssistExtAddress(extAddr))
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() "; std::cerr << "p3NetMgrIMPL::netUpnpCheck() ";
std::cerr << "Upnp Check success state: " << upnpState << std::endl; std::cerr << "Upnp Check success state: " << upnpState << std::endl;
#endif #endif
/* switch to UDP startup */ /* switch to UDP startup */
@ -622,7 +622,7 @@ void p3NetMgr::netUpnpCheck()
if (isValidNet(&(extAddr.sin_addr))) if (isValidNet(&(extAddr.sin_addr)))
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() "; std::cerr << "p3NetMgrIMPL::netUpnpCheck() ";
std::cerr << "UpnpAddr: " << rs_inet_ntoa(extAddr.sin_addr); std::cerr << "UpnpAddr: " << rs_inet_ntoa(extAddr.sin_addr);
std::cerr << ":" << ntohs(extAddr.sin_port); std::cerr << ":" << ntohs(extAddr.sin_port);
std::cerr << std::endl; std::cerr << std::endl;
@ -641,7 +641,7 @@ void p3NetMgr::netUpnpCheck()
else else
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() "; std::cerr << "p3NetMgrIMPL::netUpnpCheck() ";
std::cerr << "Upnp Check Continues: status: " << upnpState << std::endl; std::cerr << "Upnp Check Continues: status: " << upnpState << std::endl;
#endif #endif
} }
@ -649,10 +649,10 @@ void p3NetMgr::netUpnpCheck()
} }
void p3NetMgr::netExtCheck() void p3NetMgrIMPL::netExtCheck()
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck()" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck()" << std::endl;
#endif #endif
bool netSetupDone = false; bool netSetupDone = false;
@ -667,14 +667,14 @@ void p3NetMgr::netExtCheck()
if (!mNetFlags.mExtAddrOk) if (!mNetFlags.mExtAddrOk)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Not Ok" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Not Ok" << std::endl;
#endif #endif
/* net Assist */ /* net Assist */
if (netAssistExtAddress(tmpip)) if (netAssistExtAddress(tmpip))
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl;
#endif #endif
if (isValidNet(&(tmpip.sin_addr))) if (isValidNet(&(tmpip.sin_addr)))
{ {
@ -687,7 +687,7 @@ void p3NetMgr::netExtCheck()
else else
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
#endif #endif
} }
} }
@ -701,18 +701,18 @@ void p3NetMgr::netExtCheck()
if (mUseExtAddrFinder) if (mUseExtAddrFinder)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() checking ExtAddrFinder" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() checking ExtAddrFinder" << std::endl;
#endif #endif
bool extFinderOk = mExtAddrFinder->hasValidIP(&(tmpip.sin_addr)); bool extFinderOk = mExtAddrFinder->hasValidIP(&(tmpip.sin_addr));
if (extFinderOk) if (extFinderOk)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
#endif #endif
/* best guess at port */ /* best guess at port */
tmpip.sin_port = mNetFlags.mLocalAddr.sin_port; tmpip.sin_port = mNetFlags.mLocalAddr.sin_port;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() "; std::cerr << "p3NetMgrIMPL::netExtCheck() ";
std::cerr << "ExtAddr: " << rs_inet_ntoa(tmpip.sin_addr); std::cerr << "ExtAddr: " << rs_inet_ntoa(tmpip.sin_addr);
std::cerr << ":" << ntohs(tmpip.sin_port); std::cerr << ":" << ntohs(tmpip.sin_port);
std::cerr << std::endl; std::cerr << std::endl;
@ -737,7 +737,7 @@ void p3NetMgr::netExtCheck()
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() "; std::cerr << "p3NetMgrIMPL::netExtCheck() ";
std::cerr << "ExtAddr: " << rs_inet_ntoa(mNetFlags.mExtAddr.sin_addr); std::cerr << "ExtAddr: " << rs_inet_ntoa(mNetFlags.mExtAddr.sin_addr);
std::cerr << ":" << ntohs(mNetFlags.mExtAddr.sin_port); std::cerr << ":" << ntohs(mNetFlags.mExtAddr.sin_port);
std::cerr << std::endl; std::cerr << std::endl;
@ -749,7 +749,7 @@ void p3NetMgr::netExtCheck()
netSetupDone = true; netSetupDone = true;
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Ok: RS_NET_DONE" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Ok: RS_NET_DONE" << std::endl;
#endif #endif
@ -757,9 +757,9 @@ void p3NetMgr::netExtCheck()
if (!mNetFlags.mExtAddrStableOk) if (!mNetFlags.mExtAddrStableOk)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUdpCheck() UDP Unstable :( "; std::cerr << "p3NetMgrIMPL::netUdpCheck() UDP Unstable :( ";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "p3NetMgr::netUdpCheck() We are unreachable"; std::cerr << "p3NetMgrIMPL::netUdpCheck() We are unreachable";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "netMode => RS_NET_MODE_UNREACHABLE"; std::cerr << "netMode => RS_NET_MODE_UNREACHABLE";
std::cerr << std::endl; std::cerr << std::endl;
@ -796,14 +796,14 @@ void p3NetMgr::netExtCheck()
if (mNetFlags.mExtAddrOk) if (mNetFlags.mExtAddrOk)
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() setting netAssistSetAddress()" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() setting netAssistSetAddress()" << std::endl;
#endif #endif
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode); netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
} }
#if 0 #if 0
else else
{ {
std::cerr << "p3NetMgr::netExtCheck() setting ERR netAssistSetAddress(0)" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() setting ERR netAssistSetAddress(0)" << std::endl;
/* mode = 0 for error */ /* mode = 0 for error */
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode); netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
} }
@ -813,7 +813,7 @@ void p3NetMgr::netExtCheck()
if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk)) if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk))
{ {
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET) #if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Unstable - Unreachable Check" << std::endl; std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Unstable - Unreachable Check" << std::endl;
#endif #endif
} }
@ -833,7 +833,7 @@ void p3NetMgr::netExtCheck()
************************************** Interfaces ***************************************** ************************************** Interfaces *****************************************
**********************************************************************************************/ **********************************************************************************************/
bool p3NetMgr::checkNetAddress() bool p3NetMgrIMPL::checkNetAddress()
{ {
bool addrChanged = false; bool addrChanged = false;
bool validAddr = false; bool validAddr = false;
@ -847,7 +847,7 @@ bool p3NetMgr::checkNetAddress()
if (!validAddr) if (!validAddr)
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::checkNetAddress() no Valid Network Address, resetting network." << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() no Valid Network Address, resetting network." << std::endl;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
netReset(); netReset();
@ -864,7 +864,7 @@ bool p3NetMgr::checkNetAddress()
addrChanged = (prefAddr.s_addr != mLocalAddr.sin_addr.s_addr); addrChanged = (prefAddr.s_addr != mLocalAddr.sin_addr.s_addr);
#ifdef NETMGR_DEBUG_TICK #ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress()"; std::cerr << "p3NetMgrIMPL::checkNetAddress()";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Current Local: " << rs_inet_ntoa(mLocalAddr.sin_addr); std::cerr << "Current Local: " << rs_inet_ntoa(mLocalAddr.sin_addr);
std::cerr << ":" << ntohs(mLocalAddr.sin_port); std::cerr << ":" << ntohs(mLocalAddr.sin_port);
@ -876,7 +876,7 @@ bool p3NetMgr::checkNetAddress()
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
if (addrChanged) if (addrChanged)
{ {
std::cerr << "p3NetMgr::checkNetAddress() Address Changed!"; std::cerr << "p3NetMgrIMPL::checkNetAddress() Address Changed!";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "Current Local: " << rs_inet_ntoa(mLocalAddr.sin_addr); std::cerr << "Current Local: " << rs_inet_ntoa(mLocalAddr.sin_addr);
std::cerr << ":" << ntohs(mLocalAddr.sin_port); std::cerr << ":" << ntohs(mLocalAddr.sin_port);
@ -893,7 +893,7 @@ bool p3NetMgr::checkNetAddress()
if(isLoopbackNet(&(mLocalAddr.sin_addr))) if(isLoopbackNet(&(mLocalAddr.sin_addr)))
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() laddr: Loopback" << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr: Loopback" << std::endl;
#endif #endif
mNetFlags.mLocalAddrOk = false; mNetFlags.mLocalAddrOk = false;
mNetStatus = RS_NET_LOOPBACK; mNetStatus = RS_NET_LOOPBACK;
@ -901,14 +901,14 @@ bool p3NetMgr::checkNetAddress()
else if (!isValidNet(&mLocalAddr.sin_addr)) else if (!isValidNet(&mLocalAddr.sin_addr))
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() laddr: invalid" << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr: invalid" << std::endl;
#endif #endif
mNetFlags.mLocalAddrOk = false; mNetFlags.mLocalAddrOk = false;
} }
else else
{ {
#ifdef NETMGR_DEBUG_TICK #ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress() laddr okay" << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr okay" << std::endl;
#endif #endif
mNetFlags.mLocalAddrOk = true; mNetFlags.mLocalAddrOk = true;
} }
@ -918,7 +918,7 @@ bool p3NetMgr::checkNetAddress()
if ((port < PQI_MIN_PORT) || (port > PQI_MAX_PORT)) if ((port < PQI_MIN_PORT) || (port > PQI_MAX_PORT))
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() Correcting Port to DEFAULT" << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() Correcting Port to DEFAULT" << std::endl;
#endif #endif
// Generate a default port from SSL id. The port will always be the // Generate a default port from SSL id. The port will always be the
// same, but appear random from peer to peer. // same, but appear random from peer to peer.
@ -944,7 +944,7 @@ bool p3NetMgr::checkNetAddress()
mExtAddr.sin_family = AF_INET; mExtAddr.sin_family = AF_INET;
#ifdef NETMGR_DEBUG_TICK #ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress() Final Local Address: " << rs_inet_ntoa(mLocalAddr.sin_addr); std::cerr << "p3NetMgrIMPL::checkNetAddress() Final Local Address: " << rs_inet_ntoa(mLocalAddr.sin_addr);
std::cerr << ":" << ntohs(mLocalAddr.sin_port) << std::endl; std::cerr << ":" << ntohs(mLocalAddr.sin_port) << std::endl;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -954,7 +954,7 @@ bool p3NetMgr::checkNetAddress()
if (addrChanged) if (addrChanged)
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::checkNetAddress() local address changed, resetting network." << std::endl; std::cerr << "p3NetMgrIMPL::checkNetAddress() local address changed, resetting network." << std::endl;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -972,7 +972,7 @@ bool p3NetMgr::checkNetAddress()
**********************************************************************************************/ **********************************************************************************************/
/* to allow resets of network stuff */ /* to allow resets of network stuff */
void p3NetMgr::addNetListener(pqiNetListener *listener) void p3NetMgrIMPL::addNetListener(pqiNetListener *listener)
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
mNetListeners.push_back(listener); mNetListeners.push_back(listener);
@ -980,7 +980,7 @@ void p3NetMgr::addNetListener(pqiNetListener *listener)
bool p3NetMgr::setLocalAddress(struct sockaddr_in addr) bool p3NetMgrIMPL::setLocalAddress(struct sockaddr_in addr)
{ {
bool changed = false; bool changed = false;
{ {
@ -997,14 +997,14 @@ bool p3NetMgr::setLocalAddress(struct sockaddr_in addr)
if (changed) if (changed)
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setLocalAddress() Calling NetReset" << std::endl; std::cerr << "p3NetMgrIMPL::setLocalAddress() Calling NetReset" << std::endl;
#endif #endif
netReset(); netReset();
} }
return true; return true;
} }
bool p3NetMgr::setExtAddress(struct sockaddr_in addr) bool p3NetMgrIMPL::setExtAddress(struct sockaddr_in addr)
{ {
bool changed = false; bool changed = false;
{ {
@ -1021,14 +1021,14 @@ bool p3NetMgr::setExtAddress(struct sockaddr_in addr)
if (changed) if (changed)
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setExtAddress() Calling NetReset" << std::endl; std::cerr << "p3NetMgrIMPL::setExtAddress() Calling NetReset" << std::endl;
#endif #endif
netReset(); netReset();
} }
return true; return true;
} }
bool p3NetMgr::setNetworkMode(uint32_t netMode) bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
{ {
uint32_t oldNetMode; uint32_t oldNetMode;
{ {
@ -1038,7 +1038,7 @@ bool p3NetMgr::setNetworkMode(uint32_t netMode)
oldNetMode = mNetMode; oldNetMode = mNetMode;
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::setNetworkMode()"; std::cerr << "p3NetMgrIMPL::setNetworkMode()";
std::cerr << " Existing netMode: " << mNetMode; std::cerr << " Existing netMode: " << mNetMode;
std::cerr << " Input netMode: " << netMode; std::cerr << " Input netMode: " << netMode;
std::cerr << std::endl; std::cerr << std::endl;
@ -1064,7 +1064,7 @@ bool p3NetMgr::setNetworkMode(uint32_t netMode)
if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL)) if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL))
{ {
#ifdef NETMGR_DEBUG_RESET #ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setNetworkMode() Calling NetReset" << std::endl; std::cerr << "p3NetMgrIMPL::setNetworkMode() Calling NetReset" << std::endl;
#endif #endif
netReset(); netReset();
} }
@ -1072,7 +1072,7 @@ bool p3NetMgr::setNetworkMode(uint32_t netMode)
} }
bool p3NetMgr::setVisState(uint32_t visState) bool p3NetMgrIMPL::setVisState(uint32_t visState)
{ {
uint32_t netMode; uint32_t netMode;
{ {
@ -1093,13 +1093,13 @@ bool p3NetMgr::setVisState(uint32_t visState)
************************************** Interfaces ***************************************** ************************************** Interfaces *****************************************
**********************************************************************************************/ **********************************************************************************************/
void p3NetMgr::addNetAssistFirewall(uint32_t id, pqiNetAssistFirewall *fwAgent) void p3NetMgrIMPL::addNetAssistFirewall(uint32_t id, pqiNetAssistFirewall *fwAgent)
{ {
mFwAgents[id] = fwAgent; mFwAgents[id] = fwAgent;
} }
bool p3NetMgr::enableNetAssistFirewall(bool on) bool p3NetMgrIMPL::enableNetAssistFirewall(bool on)
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1110,7 +1110,7 @@ bool p3NetMgr::enableNetAssistFirewall(bool on)
} }
bool p3NetMgr::netAssistFirewallEnabled() bool p3NetMgrIMPL::netAssistFirewallEnabled()
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1123,7 +1123,7 @@ bool p3NetMgr::netAssistFirewallEnabled()
return false; return false;
} }
bool p3NetMgr::netAssistFirewallActive() bool p3NetMgrIMPL::netAssistFirewallActive()
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1136,7 +1136,7 @@ bool p3NetMgr::netAssistFirewallActive()
return false; return false;
} }
bool p3NetMgr::netAssistFirewallShutdown() bool p3NetMgrIMPL::netAssistFirewallShutdown()
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1146,7 +1146,7 @@ bool p3NetMgr::netAssistFirewallShutdown()
return true; return true;
} }
bool p3NetMgr::netAssistFirewallPorts(uint16_t iport, uint16_t eport) bool p3NetMgrIMPL::netAssistFirewallPorts(uint16_t iport, uint16_t eport)
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1158,7 +1158,7 @@ bool p3NetMgr::netAssistFirewallPorts(uint16_t iport, uint16_t eport)
} }
bool p3NetMgr::netAssistExtAddress(struct sockaddr_in &extAddr) bool p3NetMgrIMPL::netAssistExtAddress(struct sockaddr_in &extAddr)
{ {
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it; std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++) for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
@ -1175,16 +1175,16 @@ bool p3NetMgr::netAssistExtAddress(struct sockaddr_in &extAddr)
} }
void p3NetMgr::addNetAssistConnect(uint32_t id, pqiNetAssistConnect *dht) void p3NetMgrIMPL::addNetAssistConnect(uint32_t id, pqiNetAssistConnect *dht)
{ {
mDhts[id] = dht; mDhts[id] = dht;
} }
bool p3NetMgr::enableNetAssistConnect(bool on) bool p3NetMgrIMPL::enableNetAssistConnect(bool on)
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::enableNetAssistConnect(" << on << ")"; std::cerr << "p3NetMgrIMPL::enableNetAssistConnect(" << on << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1196,7 +1196,7 @@ bool p3NetMgr::enableNetAssistConnect(bool on)
return true; return true;
} }
bool p3NetMgr::netAssistConnectEnabled() bool p3NetMgrIMPL::netAssistConnectEnabled()
{ {
std::map<uint32_t, pqiNetAssistConnect *>::iterator it; std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++) for(it = mDhts.begin(); it != mDhts.end(); it++)
@ -1204,7 +1204,7 @@ bool p3NetMgr::netAssistConnectEnabled()
if ((it->second)->getEnabled()) if ((it->second)->getEnabled())
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectEnabled() YES"; std::cerr << "p3NetMgrIMPL::netAssistConnectEnabled() YES";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1213,14 +1213,14 @@ bool p3NetMgr::netAssistConnectEnabled()
} }
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectEnabled() NO"; std::cerr << "p3NetMgrIMPL::netAssistConnectEnabled() NO";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
} }
bool p3NetMgr::netAssistConnectActive() bool p3NetMgrIMPL::netAssistConnectActive()
{ {
std::map<uint32_t, pqiNetAssistConnect *>::iterator it; std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++) for(it = mDhts.begin(); it != mDhts.end(); it++)
@ -1229,7 +1229,7 @@ bool p3NetMgr::netAssistConnectActive()
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectActive() ACTIVE"; std::cerr << "p3NetMgrIMPL::netAssistConnectActive() ACTIVE";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1238,14 +1238,14 @@ bool p3NetMgr::netAssistConnectActive()
} }
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectActive() INACTIVE"; std::cerr << "p3NetMgrIMPL::netAssistConnectActive() INACTIVE";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
} }
bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize) bool p3NetMgrIMPL::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
{ {
std::map<uint32_t, pqiNetAssistConnect *>::iterator it; std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++) for(it = mDhts.begin(); it != mDhts.end(); it++)
@ -1254,7 +1254,7 @@ bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectStats("; std::cerr << "p3NetMgrIMPL::netAssistConnectStats(";
std::cerr << netsize << ", " << localnetsize << ")"; std::cerr << netsize << ", " << localnetsize << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1264,17 +1264,17 @@ bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
} }
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectStats() INACTIVE"; std::cerr << "p3NetMgrIMPL::netAssistConnectStats() INACTIVE";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false; return false;
} }
bool p3NetMgr::netAssistConnectShutdown() bool p3NetMgrIMPL::netAssistConnectShutdown()
{ {
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectShutdown()"; std::cerr << "p3NetMgrIMPL::netAssistConnectShutdown()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1286,12 +1286,12 @@ bool p3NetMgr::netAssistConnectShutdown()
return true; return true;
} }
bool p3NetMgr::netAssistFriend(std::string id, bool on) bool p3NetMgrIMPL::netAssistFriend(std::string id, bool on)
{ {
std::map<uint32_t, pqiNetAssistConnect *>::iterator it; std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
#ifdef NETMGR_DEBUG #ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistFriend(" << id << ", " << on << ")"; std::cerr << "p3NetMgrIMPL::netAssistFriend(" << id << ", " << on << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1306,7 +1306,7 @@ bool p3NetMgr::netAssistFriend(std::string id, bool on)
} }
bool p3NetMgr::netAssistSetAddress( struct sockaddr_in &laddr, bool p3NetMgrIMPL::netAssistSetAddress( struct sockaddr_in &laddr,
struct sockaddr_in &eaddr, struct sockaddr_in &eaddr,
uint32_t mode) uint32_t mode)
{ {
@ -1320,7 +1320,7 @@ bool p3NetMgr::netAssistSetAddress( struct sockaddr_in &laddr,
return true; return true;
} }
void p3NetMgr::netAssistConnectTick() void p3NetMgrIMPL::netAssistConnectTick()
{ {
std::map<uint32_t, pqiNetAssistConnect *>::iterator it; std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++) for(it = mDhts.begin(); it != mDhts.end(); it++)
@ -1338,23 +1338,23 @@ void p3NetMgr::netAssistConnectTick()
********************************************************************** **********************************************************************
**********************************************************************/ **********************************************************************/
bool p3NetMgr::getUPnPState() bool p3NetMgrIMPL::getUPnPState()
{ {
return netAssistFirewallActive(); return netAssistFirewallActive();
} }
bool p3NetMgr::getUPnPEnabled() bool p3NetMgrIMPL::getUPnPEnabled()
{ {
return netAssistFirewallEnabled(); return netAssistFirewallEnabled();
} }
bool p3NetMgr::getDHTEnabled() bool p3NetMgrIMPL::getDHTEnabled()
{ {
return netAssistConnectEnabled(); return netAssistConnectEnabled();
} }
void p3NetMgr::getNetStatus(pqiNetStatus &status) void p3NetMgrIMPL::getNetStatus(pqiNetStatus &status)
{ {
/* cannot lock local stack, then call DHT... as this can cause lock up */ /* cannot lock local stack, then call DHT... as this can cause lock up */
/* must extract data... then update mNetFlags */ /* must extract data... then update mNetFlags */
@ -1385,18 +1385,18 @@ void p3NetMgr::getNetStatus(pqiNetStatus &status)
************************************** ExtAddrFinder ***************************************** ************************************** ExtAddrFinder *****************************************
**********************************************************************************************/ **********************************************************************************************/
bool p3NetMgr::getIPServersEnabled() bool p3NetMgrIMPL::getIPServersEnabled()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mUseExtAddrFinder; return mUseExtAddrFinder;
} }
void p3NetMgr::getIPServersList(std::list<std::string>& ip_servers) void p3NetMgrIMPL::getIPServersList(std::list<std::string>& ip_servers)
{ {
mExtAddrFinder->getIPServersList(ip_servers); mExtAddrFinder->getIPServersList(ip_servers);
} }
void p3NetMgr::setIPServersEnabled(bool b) void p3NetMgrIMPL::setIPServersEnabled(bool b)
{ {
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
@ -1415,31 +1415,31 @@ void p3NetMgr::setIPServersEnabled(bool b)
************************************** NetStateBox ****************************************** ************************************** NetStateBox ******************************************
**********************************************************************************************/ **********************************************************************************************/
uint32_t p3NetMgr::getNetStateMode() uint32_t p3NetMgrIMPL::getNetStateMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetStateMode(); return mNetStateBox.getNetStateMode();
} }
uint32_t p3NetMgr::getNetworkMode() uint32_t p3NetMgrIMPL::getNetworkMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetworkMode(); return mNetStateBox.getNetworkMode();
} }
uint32_t p3NetMgr::getNatTypeMode() uint32_t p3NetMgrIMPL::getNatTypeMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatTypeMode(); return mNetStateBox.getNatTypeMode();
} }
uint32_t p3NetMgr::getNatHoleMode() uint32_t p3NetMgrIMPL::getNatHoleMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatHoleMode(); return mNetStateBox.getNatHoleMode();
} }
uint32_t p3NetMgr::getConnectModes() uint32_t p3NetMgrIMPL::getConnectModes()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getConnectModes(); return mNetStateBox.getConnectModes();
@ -1447,10 +1447,10 @@ uint32_t p3NetMgr::getConnectModes()
/* These are the regular updates from Dht / Stunners */ /* These are the regular updates from Dht / Stunners */
void p3NetMgr::updateNetStateBox_temporal() void p3NetMgrIMPL::updateNetStateBox_temporal()
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() ";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1468,7 +1468,7 @@ void p3NetMgr::updateNetStateBox_temporal()
mNetStateBox.setAddressStunDht(&tmpaddr, isstable); mNetStateBox.setAddressStunDht(&tmpaddr, isstable);
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() DhtStunner: "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() DhtStunner: ";
std::cerr << rs_inet_ntoa(tmpaddr.sin_addr) << ":" << htons(tmpaddr.sin_port); std::cerr << rs_inet_ntoa(tmpaddr.sin_addr) << ":" << htons(tmpaddr.sin_port);
std::cerr << " Stable: " << (uint32_t) isstable; std::cerr << " Stable: " << (uint32_t) isstable;
std::cerr << std::endl; std::cerr << std::endl;
@ -1487,7 +1487,7 @@ void p3NetMgr::updateNetStateBox_temporal()
mNetStateBox.setAddressStunProxy(&tmpaddr, isstable); mNetStateBox.setAddressStunProxy(&tmpaddr, isstable);
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() ProxyStunner: "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() ProxyStunner: ";
std::cerr << rs_inet_ntoa(tmpaddr.sin_addr) << ":" << htons(tmpaddr.sin_port); std::cerr << rs_inet_ntoa(tmpaddr.sin_addr) << ":" << htons(tmpaddr.sin_port);
std::cerr << " Stable: " << (uint32_t) isstable; std::cerr << " Stable: " << (uint32_t) isstable;
std::cerr << std::endl; std::cerr << std::endl;
@ -1525,7 +1525,7 @@ void p3NetMgr::updateNetStateBox_temporal()
std::string netmodestr = NetStateNetworkModeString(netMode); std::string netmodestr = NetStateNetworkModeString(netMode);
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() NetStateBox Thinking"; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() NetStateBox Thinking";
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "\tNetState: " << netstatestr; std::cerr << "\tNetState: " << netstatestr;
std::cerr << std::endl; std::cerr << std::endl;
@ -1549,7 +1549,7 @@ void p3NetMgr::updateNetStateBox_temporal()
#define NET_STUNNER_PERIOD_FAST (-1) // default of Stunner. #define NET_STUNNER_PERIOD_FAST (-1) // default of Stunner.
#define NET_STUNNER_PERIOD_SLOW (180) // 3 minutes. #define NET_STUNNER_PERIOD_SLOW (180) // 3 minutes.
void p3NetMgr::updateNatSetting() void p3NetMgrIMPL::updateNatSetting()
{ {
bool updateRefreshRate = false; bool updateRefreshRate = false;
uint32_t natType = RSNET_NATTYPE_UNKNOWN; uint32_t natType = RSNET_NATTYPE_UNKNOWN;
@ -1566,7 +1566,7 @@ void p3NetMgr::updateNatSetting()
updateRefreshRate = true; updateRefreshRate = true;
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() NatType Change!"; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() NatType Change!";
std::cerr << "\tNatType: " << NetStateNatTypeString(natType); std::cerr << "\tNatType: " << NetStateNatTypeString(natType);
std::cerr << "\tNatHole: " << NetStateNatHoleString(natHole); std::cerr << "\tNatHole: " << NetStateNatHoleString(natHole);
@ -1582,7 +1582,7 @@ void p3NetMgr::updateNatSetting()
if (updateRefreshRate) if (updateRefreshRate)
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_temporal() Updating Refresh Rate, based on changed NatType"; std::cerr << "p3NetMgrIMPL::updateNetStateBox_temporal() Updating Refresh Rate, based on changed NatType";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1615,10 +1615,10 @@ void p3NetMgr::updateNatSetting()
void p3NetMgr::updateNetStateBox_startup() void p3NetMgrIMPL::updateNetStateBox_startup()
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
{ {
@ -1632,7 +1632,7 @@ void p3NetMgr::updateNetStateBox_startup()
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << "Ext supplied from netAssistExternalAddress()"; std::cerr << "Ext supplied from netAssistExternalAddress()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1640,7 +1640,7 @@ void p3NetMgr::updateNetStateBox_startup()
if (isValidNet(&(tmpip.sin_addr))) if (isValidNet(&(tmpip.sin_addr)))
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << "netAssist Returned: " << rs_inet_ntoa(tmpip.sin_addr); std::cerr << "netAssist Returned: " << rs_inet_ntoa(tmpip.sin_addr);
std::cerr << ":" << ntohs(tmpip.sin_port); std::cerr << ":" << ntohs(tmpip.sin_port);
std::cerr << std::endl; std::cerr << std::endl;
@ -1651,7 +1651,7 @@ void p3NetMgr::updateNetStateBox_startup()
{ {
mNetStateBox.setAddressUPnP(false, &tmpip); mNetStateBox.setAddressUPnP(false, &tmpip);
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << "ERROR Bad Address supplied from netAssistExternalAddress()"; std::cerr << "ERROR Bad Address supplied from netAssistExternalAddress()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1660,7 +1660,7 @@ void p3NetMgr::updateNetStateBox_startup()
else else
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << " netAssistExtAddress() is not active"; std::cerr << " netAssistExtAddress() is not active";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1678,7 +1678,7 @@ void p3NetMgr::updateNetStateBox_startup()
tmpip.sin_port = mNetFlags.mLocalAddr.sin_port; tmpip.sin_port = mNetFlags.mLocalAddr.sin_port;
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << "ExtAddrFinder Returned: " << rs_inet_ntoa(tmpip.sin_addr); std::cerr << "ExtAddrFinder Returned: " << rs_inet_ntoa(tmpip.sin_addr);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1689,7 +1689,7 @@ void p3NetMgr::updateNetStateBox_startup()
{ {
mNetStateBox.setAddressWebIP(false, &tmpip); mNetStateBox.setAddressWebIP(false, &tmpip);
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << " ExtAddrFinder hasn't found an address yet"; std::cerr << " ExtAddrFinder hasn't found an address yet";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1698,7 +1698,7 @@ void p3NetMgr::updateNetStateBox_startup()
else else
{ {
#ifdef NETMGR_DEBUG_STATEBOX #ifdef NETMGR_DEBUG_STATEBOX
std::cerr << "p3NetMgr::updateNetStateBox_startup() "; std::cerr << "p3NetMgrIMPL::updateNetStateBox_startup() ";
std::cerr << " ExtAddrFinder is not active"; std::cerr << " ExtAddrFinder is not active";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1707,7 +1707,7 @@ void p3NetMgr::updateNetStateBox_startup()
} }
} }
void p3NetMgr::updateNetStateBox_reset() void p3NetMgrIMPL::updateNetStateBox_reset()
{ {
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/

View File

@ -84,23 +84,128 @@ class pqiNetStatus
class p3PeerMgr; class p3PeerMgr;
class p3LinkMgr; class p3LinkMgr;
class p3PeerMgrIMPL;
class p3LinkMgrIMPL;
class rsUdpStack; class rsUdpStack;
class UdpStunner; class UdpStunner;
class p3BitDht; class p3BitDht;
class UdpRelayReceiver; class UdpRelayReceiver;
/**********
* p3NetMgr Interface....
* This allows a drop-in replacement for testing.
*/
class p3NetMgr class p3NetMgr
{ {
public: public:
p3NetMgr(); p3NetMgr() { return; }
virtual ~p3NetMgr() { return; }
void setManagers(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
/*************** External Control ****************/
// Setup Network State.
virtual bool setNetworkMode(uint32_t netMode) = 0;
virtual bool setVisState(uint32_t visState) = 0;
// Switch DHT On/Off.
virtual bool netAssistFriend(std::string id, bool on) = 0;
/* Get Network State */
virtual uint32_t getNetStateMode() = 0;
virtual uint32_t getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;
/* Shut It Down! */
virtual bool shutdown() = 0; /* blocking shutdown call */
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
// THESE SHOULD BE MOVED TO p3PeerMgr (as it controls the config).
// The functional object should be transformed into a NetAssistFirewall object.
// ONLY USED by p3peers.cc & p3peermgr.cc
virtual bool getIPServersEnabled() = 0;
virtual void setIPServersEnabled(bool b) = 0;
virtual void getIPServersList(std::list<std::string>& ip_servers) = 0;
// ONLY USED by p3face-config.cc WHICH WILL BE REMOVED.
virtual void getNetStatus(pqiNetStatus &status) = 0;
virtual bool getUPnPState() = 0;
virtual bool getUPnPEnabled() = 0;
virtual bool getDHTEnabled() = 0;
/************************************************************************************************/
/************************************************************************************************/
/************************************************************************************************/
/************************************************************************************************/
};
class p3NetMgrIMPL: public p3NetMgr
{
public:
p3NetMgrIMPL();
/************************************************************************************************/
/* EXTERNAL INTERFACE */
/************************************************************************************************/
/*************** External Control ****************/
// Setup Network State.
virtual bool setNetworkMode(uint32_t netMode);
virtual bool setVisState(uint32_t visState);
// Switch DHT On/Off.
virtual bool netAssistFriend(std::string id, bool on);
/* Get Network State */
virtual uint32_t getNetStateMode();
virtual uint32_t getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();
/* Shut It Down! */
virtual bool shutdown(); /* blocking shutdown call */
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
// THESE SHOULD BE MOVED TO p3PeerMgr (as it controls the config).
// The functional object should be transformed into a NetAssistFirewall object.
// ONLY USED by p3peers.cc & p3peermgr.cc
virtual bool getIPServersEnabled();
virtual void setIPServersEnabled(bool b);
virtual void getIPServersList(std::list<std::string>& ip_servers);
// ONLY USED by p3face-config.cc WHICH WILL BE REMOVED.
virtual void getNetStatus(pqiNetStatus &status);
virtual bool getUPnPState();
virtual bool getUPnPEnabled();
virtual bool getDHTEnabled();
/************************************************************************************************/
/* Extra IMPL Functions (used by p3PeerMgr, p3NetMgr + Setup) */
/************************************************************************************************/
void setManagers(p3PeerMgrIMPL *peerMgr, p3LinkMgrIMPL *linkMgr);
void setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun); void setAddrAssist(pqiAddrAssist *dhtStun, pqiAddrAssist *proxyStun);
void tick(); void tick();
void slowTick();
// THESE MIGHT BE ADDED TO INTERFACE.
bool setLocalAddress(struct sockaddr_in addr);
bool setExtAddress(struct sockaddr_in addr);
/*************** Setup ***************************/ /*************** Setup ***************************/
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *); void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
@ -108,65 +213,41 @@ void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
void addNetListener(pqiNetListener *listener); void addNetListener(pqiNetListener *listener);
// SHOULD MAKE THIS PROTECTED.
bool checkNetAddress(); /* check our address is sensible */ bool checkNetAddress(); /* check our address is sensible */
/*************** External Control ****************/
bool shutdown(); /* blocking shutdown call */
/* a nice simple network configuration */ protected:
uint32_t getNetStateMode();
uint32_t getNetworkMode();
uint32_t getNatTypeMode();
uint32_t getNatHoleMode();
uint32_t getConnectModes();
void slowTick();
/* THESE FUNCTIONS ARE ON_LONGER EXTERNAL - CAN THEY BE REMOVED? */
//bool getDHTStats(uint32_t &netsize, uint32_t &localnetsize);
//bool getNetStatusLocalOk();
//bool getNetStatusUpnpOk();
//bool getNetStatusDhtOk();
//bool getNetStatusStunOk();
//bool getNetStatusExtraAddressCheckOk();
bool getUPnPState(); //bool getUpnpExtAddress(struct sockaddr_in &addr);
bool getUPnPEnabled(); //bool getExtFinderAddress(struct sockaddr_in &addr);
bool getDHTEnabled();
bool getDHTStats(uint32_t &netsize, uint32_t &localnetsize);
bool getIPServersEnabled(); //void setOwnNetConfig(uint32_t netMode, uint32_t visState);
void setIPServersEnabled(bool b) ;
void getIPServersList(std::list<std::string>& ip_servers) ;
bool getNetStatusLocalOk();
bool getNetStatusUpnpOk();
bool getNetStatusDhtOk();
bool getNetStatusStunOk();
bool getNetStatusExtraAddressCheckOk();
bool getUpnpExtAddress(struct sockaddr_in &addr);
bool getExtFinderAddress(struct sockaddr_in &addr);
void getNetStatus(pqiNetStatus &status);
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
bool setLocalAddress(struct sockaddr_in addr);
bool setExtAddress(struct sockaddr_in addr);
bool setNetworkMode(uint32_t netMode);
bool setVisState(uint32_t visState);
virtual bool netAssistFriend(std::string id, bool on);
/*************** External Control ****************/
/* access to network details (called through Monitor) */
protected: protected:
/****************** Internal Interface *******************/ /****************** Internal Interface *******************/
virtual bool enableNetAssistFirewall(bool on); bool enableNetAssistFirewall(bool on);
virtual bool netAssistFirewallEnabled(); bool netAssistFirewallEnabled();
virtual bool netAssistFirewallActive(); bool netAssistFirewallActive();
virtual bool netAssistFirewallShutdown(); bool netAssistFirewallShutdown();
virtual bool enableNetAssistConnect(bool on); bool enableNetAssistConnect(bool on);
virtual bool netAssistConnectEnabled(); bool netAssistConnectEnabled();
virtual bool netAssistConnectActive(); bool netAssistConnectActive();
virtual bool netAssistConnectShutdown(); bool netAssistConnectShutdown();
virtual bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize); bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize);
void netAssistConnectTick(); void netAssistConnectTick();
/* Assist Firewall */ /* Assist Firewall */
@ -174,8 +255,8 @@ bool netAssistExtAddress(struct sockaddr_in &extAddr);
bool netAssistFirewallPorts(uint16_t iport, uint16_t eport); bool netAssistFirewallPorts(uint16_t iport, uint16_t eport);
/* Assist Connect */ /* Assist Connect */
//virtual bool netAssistFriend(std::string id, bool on); //virtual bool netAssistFriend(std::string id, bool on); (PUBLIC)
virtual bool netAssistSetAddress( struct sockaddr_in &laddr, bool netAssistSetAddress( struct sockaddr_in &laddr,
struct sockaddr_in &eaddr, struct sockaddr_in &eaddr,
uint32_t mode); uint32_t mode);
@ -221,8 +302,8 @@ private:
std::list<pqiNetListener *> mNetListeners; std::list<pqiNetListener *> mNetListeners;
p3PeerMgr *mPeerMgr; p3PeerMgrIMPL *mPeerMgr;
p3LinkMgr *mLinkMgr; p3LinkMgrIMPL *mLinkMgr;
//p3BitDht *mBitDht; //p3BitDht *mBitDht;
pqiAddrAssist *mDhtStunner; pqiAddrAssist *mDhtStunner;

View File

@ -97,7 +97,7 @@ std::string textPeerConnectState(peerState &state)
} }
p3PeerMgr::p3PeerMgr() p3PeerMgrIMPL::p3PeerMgrIMPL()
:p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false) :p3Config(CONFIG_TYPE_PEERS), mPeerMtx("p3PeerMgr"), mStatusChanged(false)
{ {
@ -126,19 +126,19 @@ p3PeerMgr::p3PeerMgr()
return; return;
} }
void p3PeerMgr::setManagers(p3LinkMgr *linkMgr, p3NetMgr *netMgr) void p3PeerMgrIMPL::setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr)
{ {
mLinkMgr = linkMgr; mLinkMgr = linkMgr;
mNetMgr = netMgr; mNetMgr = netMgr;
} }
void p3PeerMgr::setOwnNetworkMode(uint32_t netMode) void p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode)
{ {
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setOwnNetworkMode() :"; std::cerr << "p3PeerMgrIMPL::setOwnNetworkMode() :";
std::cerr << " Existing netMode: " << mOwnState.netMode; std::cerr << " Existing netMode: " << mOwnState.netMode;
std::cerr << " Input netMode: " << netMode; std::cerr << " Input netMode: " << netMode;
std::cerr << std::endl; std::cerr << std::endl;
@ -153,13 +153,13 @@ void p3PeerMgr::setOwnNetworkMode(uint32_t netMode)
mNetMgr->setNetworkMode((netMode & RS_NET_MODE_ACTUAL)); mNetMgr->setNetworkMode((netMode & RS_NET_MODE_ACTUAL));
} }
void p3PeerMgr::setOwnVisState(uint32_t visState) void p3PeerMgrIMPL::setOwnVisState(uint32_t visState)
{ {
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setOwnVisState()"; std::cerr << "p3PeerMgrIMPL::setOwnVisState()";
std::cerr << "Existing vis: " << mOwnState.visState; std::cerr << "Existing vis: " << mOwnState.visState;
std::cerr << "Input vis: " << visState; std::cerr << "Input vis: " << visState;
std::cerr << std::endl; std::cerr << std::endl;
@ -175,8 +175,7 @@ void p3PeerMgr::setOwnVisState(uint32_t visState)
} }
void p3PeerMgrIMPL::tick()
void p3PeerMgr::tick()
{ {
static time_t last_friends_check = time(NULL) ; static time_t last_friends_check = time(NULL) ;
@ -186,7 +185,7 @@ void p3PeerMgr::tick()
if(now > last_friends_check + INTERVAL_BETWEEN_LOCATION_CLEANING && rsPeers != NULL) if(now > last_friends_check + INTERVAL_BETWEEN_LOCATION_CLEANING && rsPeers != NULL)
{ {
std::cerr << "p3PeerMgr::tick(): cleaning unused locations." << std::endl ; std::cerr << "p3PeerMgrIMPL::tick(): cleaning unused locations." << std::endl ;
rsPeers->cleanUnusedLocations() ; rsPeers->cleanUnusedLocations() ;
last_friends_check = now ; last_friends_check = now ;
@ -199,35 +198,34 @@ void p3PeerMgr::tick()
*/ */
const std::string p3PeerMgrIMPL::getOwnId()
const std::string p3PeerMgr::getOwnId()
{ {
return AuthSSL::getAuthSSL()->OwnId(); return AuthSSL::getAuthSSL()->OwnId();
} }
bool p3PeerMgr::getOwnNetStatus(peerState &state) bool p3PeerMgrIMPL::getOwnNetStatus(peerState &state)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
state = mOwnState; state = mOwnState;
return true; return true;
} }
bool p3PeerMgr::isFriend(const std::string &id) bool p3PeerMgrIMPL::isFriend(const std::string &id)
{ {
#ifdef PEER_DEBUG_COMMON #ifdef PEER_DEBUG_COMMON
std::cerr << "p3PeerMgr::isFriend(" << id << ") called" << std::endl; std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") called" << std::endl;
#endif #endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
bool ret = (mFriendList.end() != mFriendList.find(id)); bool ret = (mFriendList.end() != mFriendList.find(id));
#ifdef PEER_DEBUG_COMMON #ifdef PEER_DEBUG_COMMON
std::cerr << "p3PeerMgr::isFriend(" << id << ") returning : " << ret << std::endl; std::cerr << "p3PeerMgrIMPL::isFriend(" << id << ") returning : " << ret << std::endl;
#endif #endif
return ret; return ret;
} }
bool p3PeerMgr::getFriendNetStatus(const std::string &id, peerState &state) bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -244,7 +242,7 @@ bool p3PeerMgr::getFriendNetStatus(const std::string &id, peerState &state)
} }
bool p3PeerMgr::getOthersNetStatus(const std::string &id, peerState &state) bool p3PeerMgrIMPL::getOthersNetStatus(const std::string &id, peerState &state)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -260,8 +258,9 @@ bool p3PeerMgr::getOthersNetStatus(const std::string &id, peerState &state)
return true; return true;
} }
#if 0
void p3PeerMgr::getFriendList(std::list<std::string> &peers) void p3PeerMgrIMPL::getFriendList(std::list<std::string> &peers)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -274,9 +273,10 @@ void p3PeerMgr::getFriendList(std::list<std::string> &peers)
return; return;
} }
#endif
#if 0 #if 0
void p3PeerMgr::getOthersList(std::list<std::string> &peers) void p3PeerMgrIMPL::getOthersList(std::list<std::string> &peers)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -292,7 +292,7 @@ void p3PeerMgr::getOthersList(std::list<std::string> &peers)
int p3PeerMgr::getConnectAddresses(const std::string &id, int p3PeerMgrIMPL::getConnectAddresses(const std::string &id,
struct sockaddr_in &lAddr, struct sockaddr_in &eAddr, struct sockaddr_in &lAddr, struct sockaddr_in &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns) pqiIpAddrSet &histAddrs, std::string &dyndns)
{ {
@ -305,7 +305,7 @@ int p3PeerMgr::getConnectAddresses(const std::string &id,
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
/* ERROR */ /* ERROR */
std::cerr << "p3PeerMgr::getConnectAddresses() ERROR unknown Peer"; std::cerr << "p3PeerMgrIMPL::getConnectAddresses() ERROR unknown Peer";
std::cerr << std::endl; std::cerr << std::endl;
return 0; return 0;
} }
@ -320,7 +320,7 @@ int p3PeerMgr::getConnectAddresses(const std::string &id,
bool p3PeerMgr::haveOnceConnected() bool p3PeerMgrIMPL::haveOnceConnected()
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -331,7 +331,7 @@ bool p3PeerMgr::haveOnceConnected()
if (it->second.lastcontact > 0) if (it->second.lastcontact > 0)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::haveOnceConnected() lastcontact: "; std::cerr << "p3PeerMgrIMPL::haveOnceConnected() lastcontact: ";
std::cerr << time(NULL) - it->second.lastcontact << " for id: " << it->first; std::cerr << time(NULL) - it->second.lastcontact << " for id: " << it->first;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -341,7 +341,7 @@ bool p3PeerMgr::haveOnceConnected()
} }
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::haveOnceConnected() all Last Contacts = 0"; std::cerr << "p3PeerMgrIMPL::haveOnceConnected() all Last Contacts = 0";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -353,7 +353,7 @@ bool p3PeerMgr::haveOnceConnected()
/*******************************************************************/ /*******************************************************************/
/*******************************************************************/ /*******************************************************************/
bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact) bool p3PeerMgrIMPL::addFriend(const std::string &id, const std::string &gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact)
{ {
bool notifyLinkMgr = false; bool notifyLinkMgr = false;
{ {
@ -362,7 +362,7 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
if (id == AuthSSL::getAuthSSL()->OwnId()) { if (id == AuthSSL::getAuthSSL()->OwnId()) {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() cannot add own id as a friend." << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() cannot add own id as a friend." << std::endl;
#endif #endif
/* (1) already exists */ /* (1) already exists */
return false; return false;
@ -374,14 +374,14 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
*/ */
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
#endif #endif
std::map<std::string, peerState>::iterator it; std::map<std::string, peerState>::iterator it;
if (mFriendList.end() != mFriendList.find(id)) if (mFriendList.end() != mFriendList.find(id))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() Already Exists" << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() Already Exists" << std::endl;
#endif #endif
/* (1) already exists */ /* (1) already exists */
return true; return true;
@ -392,7 +392,7 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId()) if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId())
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() gpg is not accepted" << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() gpg is not accepted" << std::endl;
#endif #endif
/* no auth */ /* no auth */
return false; return false;
@ -404,7 +404,7 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
{ {
/* (2) in mOthersList -> move over */ /* (2) in mOthersList -> move over */
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() Move from Others" << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() Move from Others" << std::endl;
#endif #endif
mFriendList[id] = it->second; mFriendList[id] = it->second;
@ -426,7 +426,7 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
else else
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addFriend() Creating New Entry" << std::endl; std::cerr << "p3PeerMgrIMPL::addFriend() Creating New Entry" << std::endl;
#endif #endif
/* create a new entry */ /* create a new entry */
@ -466,12 +466,12 @@ bool p3PeerMgr::addFriend(const std::string &id, const std::string &gpg_id, uint
} }
bool p3PeerMgr::removeFriend(const std::string &id) bool p3PeerMgrIMPL::removeFriend(const std::string &id)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::removeFriend() for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::removeFriend() for id : " << id << std::endl;
std::cerr << "p3PeerMgr::removeFriend() mFriendList.size() : " << mFriendList.size() << std::endl; std::cerr << "p3PeerMgrIMPL::removeFriend() mFriendList.size() : " << mFriendList.size() << std::endl;
#endif #endif
std::list<std::string> toRemove; // This is a list of SSLIds. std::list<std::string> toRemove; // This is a list of SSLIds.
@ -487,7 +487,7 @@ bool p3PeerMgr::removeFriend(const std::string &id)
{ {
if (it->second.id == id || it->second.gpg_id == id) { if (it->second.id == id || it->second.gpg_id == id) {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::removeFriend() friend found in the list." << id << std::endl; std::cerr << "p3PeerMgrIMPL::removeFriend() friend found in the list." << id << std::endl;
#endif #endif
peerState peer = it->second; peerState peer = it->second;
@ -510,7 +510,7 @@ bool p3PeerMgr::removeFriend(const std::string &id)
} }
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::removeFriend() new mFriendList.size() : " << mFriendList.size() << std::endl; std::cerr << "p3PeerMgrIMPL::removeFriend() new mFriendList.size() : " << mFriendList.size() << std::endl;
#endif #endif
} }
@ -537,12 +537,12 @@ bool p3PeerMgr::removeFriend(const std::string &id)
} }
void p3PeerMgr::printPeerLists(std::ostream &out) void p3PeerMgrIMPL::printPeerLists(std::ostream &out)
{ {
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
out << "p3PeerMgr::printPeerLists() Friend List"; out << "p3PeerMgrIMPL::printPeerLists() Friend List";
out << std::endl; out << std::endl;
@ -554,7 +554,7 @@ void p3PeerMgr::printPeerLists(std::ostream &out)
out << std::endl; out << std::endl;
} }
out << "p3PeerMgr::printPeerLists() Others List"; out << "p3PeerMgrIMPL::printPeerLists() Others List";
out << std::endl; out << std::endl;
for(it = mOthersList.begin(); it != mOthersList.end(); it++) for(it = mOthersList.begin(); it != mOthersList.end(); it++)
{ {
@ -570,11 +570,11 @@ void p3PeerMgr::printPeerLists(std::ostream &out)
#if 0 #if 0
bool p3PeerMgr::addNeighbour(std::string id) bool p3PeerMgrIMPL::addNeighbour(std::string id)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::addNeighbour() not implemented anymore." << id << std::endl; std::cerr << "p3PeerMgrIMPL::addNeighbour() not implemented anymore." << id << std::endl;
#endif #endif
/* so three possibilities /* so three possibilities
@ -643,7 +643,7 @@ bool p3PeerMgr::addNeighbour(std::string id)
**********************************************************************/ **********************************************************************/
bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in addr) bool p3PeerMgrIMPL::setLocalAddress(const std::string &id, struct sockaddr_in addr)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -677,7 +677,7 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -699,7 +699,7 @@ bool p3PeerMgr::setLocalAddress(const std::string &id, struct sockaddr_in add
return true; return true;
} }
bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr) bool p3PeerMgrIMPL::setExtAddress(const std::string &id, struct sockaddr_in addr)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -721,7 +721,7 @@ bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -744,7 +744,7 @@ bool p3PeerMgr::setExtAddress(const std::string &id, struct sockaddr_in addr)
} }
bool p3PeerMgr::setDynDNS(const std::string &id, const std::string &dyndns) bool p3PeerMgrIMPL::setDynDNS(const std::string &id, const std::string &dyndns)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -761,7 +761,7 @@ bool p3PeerMgr::setDynDNS(const std::string &id, const std::string &dyndns)
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setDynDNS() cannot add dyn dns info : peer id not found in friend list id: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setDynDNS() cannot add dyn dns info : peer id not found in friend list id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -775,10 +775,10 @@ bool p3PeerMgr::setDynDNS(const std::string &id, const std::string &dyndns)
return true; return true;
} }
bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) bool p3PeerMgrIMPL::updateAddressList(const std::string& id, const pqiIpAddrSet &addrs)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setAddressList() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setAddressList() called for id : " << id << std::endl;
#endif #endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -797,7 +797,7 @@ bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setLocalAddress() cannot add addres info : peer id not found in friend list. id: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list. id: " << id << std::endl;
#endif #endif
return false; return false;
} }
@ -806,7 +806,7 @@ bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &
/* "it" points to peer */ /* "it" points to peer */
it->second.ipAddrs.updateAddrs(addrs); it->second.ipAddrs.updateAddrs(addrs);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setLocalAddress() Updated Address for: " << id; std::cerr << "p3PeerMgrIMPL::setLocalAddress() Updated Address for: " << id;
std::cerr << std::endl; std::cerr << std::endl;
it->second.ipAddrs.printAddrs(std::cerr); it->second.ipAddrs.printAddrs(std::cerr);
std::cerr << std::endl; std::cerr << std::endl;
@ -818,10 +818,10 @@ bool p3PeerMgr::updateAddressList(const std::string& id, const pqiIpAddrSet &
} }
bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddress &addr) bool p3PeerMgrIMPL::updateCurrentAddress(const std::string& id, const pqiIpAddress &addr)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::updateCurrentAddress() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() called for id : " << id << std::endl;
#endif #endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -834,7 +834,7 @@ bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddres
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
std::cerr << "p3PeerMgr::updateCurrentAddress() ERROR peer id not found: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() ERROR peer id not found: " << id << std::endl;
return false; return false;
} }
} }
@ -851,7 +851,7 @@ bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddres
} }
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::updatedCurrentAddress() Updated Address for: " << id; std::cerr << "p3PeerMgrIMPL::updatedCurrentAddress() Updated Address for: " << id;
std::cerr << std::endl; std::cerr << std::endl;
it->second.ipAddrs.printAddrs(std::cerr); it->second.ipAddrs.printAddrs(std::cerr);
std::cerr << std::endl; std::cerr << std::endl;
@ -863,10 +863,10 @@ bool p3PeerMgr::updateCurrentAddress(const std::string& id, const pqiIpAddres
} }
bool p3PeerMgr::updateLastContact(const std::string& id) bool p3PeerMgrIMPL::updateLastContact(const std::string& id)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::updateLastContact() called for id : " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateLastContact() called for id : " << id << std::endl;
#endif #endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -879,7 +879,7 @@ bool p3PeerMgr::updateLastContact(const std::string& id)
{ {
if (mOthersList.end() == (it = mOthersList.find(id))) if (mOthersList.end() == (it = mOthersList.find(id)))
{ {
std::cerr << "p3PeerMgr::updateLastContact() ERROR peer id not found: " << id << std::endl; std::cerr << "p3PeerMgrIMPL::updateLastContact() ERROR peer id not found: " << id << std::endl;
return false; return false;
} }
} }
@ -894,7 +894,7 @@ bool p3PeerMgr::updateLastContact(const std::string& id)
bool p3PeerMgr::setNetworkMode(const std::string &id, uint32_t netMode) bool p3PeerMgrIMPL::setNetworkMode(const std::string &id, uint32_t netMode)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -920,12 +920,12 @@ bool p3PeerMgr::setNetworkMode(const std::string &id, uint32_t netMode)
return false; return false;
} }
bool p3PeerMgr::setLocation(const std::string &id, const std::string &location) bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &location)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::setLocation() called for id : " << id << "; with location " << location << std::endl; std::cerr << "p3PeerMgrIMPL::setLocation() called for id : " << id << "; with location " << location << std::endl;
#endif #endif
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -943,7 +943,7 @@ bool p3PeerMgr::setLocation(const std::string &id, const std::string &locatio
} }
} }
bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState) bool p3PeerMgrIMPL::setVisState(const std::string &id, uint32_t visState)
{ {
if (id == AuthSSL::getAuthSSL()->OwnId()) if (id == AuthSSL::getAuthSSL()->OwnId())
{ {
@ -1007,7 +1007,7 @@ bool p3PeerMgr::setVisState(const std::string &id, uint32_t visState)
/* Key Functions to be overloaded for Full Configuration */ /* Key Functions to be overloaded for Full Configuration */
RsSerialiser *p3PeerMgr::setupSerialiser() RsSerialiser *p3PeerMgrIMPL::setupSerialiser()
{ {
RsSerialiser *rss = new RsSerialiser(); RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsPeerConfigSerialiser()); rss->addSerialType(new RsPeerConfigSerialiser());
@ -1017,7 +1017,7 @@ RsSerialiser *p3PeerMgr::setupSerialiser()
} }
bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData) bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
{ {
/* create a list of current peers */ /* create a list of current peers */
cleanup = false; cleanup = false;
@ -1055,7 +1055,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList); mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::saveList() Own Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::saveList() Own Config Item:" << std::endl;
item->print(std::cerr, 10); item->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1085,7 +1085,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
saveData.push_back(item); saveData.push_back(item);
saveCleanupList.push_back(item); saveCleanupList.push_back(item);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::saveList() Peer Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
item->print(std::cerr, 10); item->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1131,7 +1131,7 @@ bool p3PeerMgr::saveList(bool &cleanup, std::list<RsItem *>& saveData)
return true; return true;
} }
void p3PeerMgr::saveDone() void p3PeerMgrIMPL::saveDone()
{ {
/* clean up the save List */ /* clean up the save List */
std::list<RsItem *>::iterator it; std::list<RsItem *>::iterator it;
@ -1146,7 +1146,7 @@ void p3PeerMgr::saveDone()
mPeerMtx.unlock(); /****** MUTEX UNLOCKED *******/ mPeerMtx.unlock(); /****** MUTEX UNLOCKED *******/
} }
bool p3PeerMgr::loadList(std::list<RsItem *>& load) bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
{ {
// DEFAULTS. // DEFAULTS.
@ -1154,12 +1154,12 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
bool allowTunnelConnection = true; bool allowTunnelConnection = true;
if (load.size() == 0) { if (load.size() == 0) {
std::cerr << "p3PeerMgr::loadList() list is empty, it may be a configuration problem." << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl;
return false; return false;
} }
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::loadList() Item Count: " << load.size() << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() Item Count: " << load.size() << std::endl;
#endif #endif
std::string ownId = getOwnId(); std::string ownId = getOwnId();
@ -1174,7 +1174,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
if (pitem->pid == ownId) if (pitem->pid == ownId)
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::loadList() Own Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() Own Config Item:" << std::endl;
pitem->print(std::cerr, 10); pitem->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1188,7 +1188,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
else else
{ {
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::loadList() Peer Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() Peer Config Item:" << std::endl;
pitem->print(std::cerr, 10); pitem->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1219,7 +1219,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::loadList() General Variable Config Item:" << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() General Variable Config Item:" << std::endl;
vitem->print(std::cerr, 10); vitem->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1245,7 +1245,7 @@ bool p3PeerMgr::loadList(std::list<RsItem *>& load)
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::loadList() Peer group item:" << std::endl; std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl;
gitem->print(std::cerr, 10); gitem->print(std::cerr, 10);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1357,7 +1357,7 @@ void printConnectState(std::ostream &out, peerState &peer)
********************************************************************** **********************************************************************
**********************************************************************/ **********************************************************************/
bool p3PeerMgr::addGroup(RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
{ {
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -1384,7 +1384,7 @@ bool p3PeerMgr::addGroup(RsGroupInfo &groupInfo)
return true; return true;
} }
bool p3PeerMgr::editGroup(const std::string &groupId, RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
{ {
if (groupId.empty()) { if (groupId.empty()) {
return false; return false;
@ -1421,7 +1421,7 @@ bool p3PeerMgr::editGroup(const std::string &groupId, RsGroupInfo &groupInfo)
return changed; return changed;
} }
bool p3PeerMgr::removeGroup(const std::string &groupId) bool p3PeerMgrIMPL::removeGroup(const std::string &groupId)
{ {
if (groupId.empty()) { if (groupId.empty()) {
return false; return false;
@ -1459,7 +1459,7 @@ bool p3PeerMgr::removeGroup(const std::string &groupId)
return changed; return changed;
} }
bool p3PeerMgr::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
{ {
if (groupId.empty()) { if (groupId.empty()) {
return false; return false;
@ -1479,7 +1479,7 @@ bool p3PeerMgr::getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo)
return false; return false;
} }
bool p3PeerMgr::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) bool p3PeerMgrIMPL::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -1494,7 +1494,7 @@ bool p3PeerMgr::getGroupInfoList(std::list<RsGroupInfo> &groupInfoList)
} }
// groupId == "" && assign == false -> remove from all groups // groupId == "" && assign == false -> remove from all groups
bool p3PeerMgr::assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign) bool p3PeerMgrIMPL::assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign)
{ {
if (groupId.empty() && assign == true) { if (groupId.empty() && assign == true) {
return false; return false;

View File

@ -111,82 +111,173 @@ std::string textPeerState(peerState &state);
class p3LinkMgr; class p3LinkMgr;
class p3NetMgr; class p3NetMgr;
class p3LinkMgrIMPL;
class p3NetMgrIMPL;
class p3PeerMgr: public p3Config class p3PeerMgr
{ {
public: public:
p3PeerMgr(); p3PeerMgr() { return; }
virtual ~p3PeerMgr() { return; }
void setManagers(p3LinkMgr *linkMgr, p3NetMgr *netMgr); virtual 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) = 0;
virtual bool removeFriend(const std::string &ssl_id) = 0;
virtual bool isFriend(const std::string &ssl_id) = 0;
/******************** Groups **********************/
/* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo) = 0;
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool removeGroup(const std::string &groupId) = 0;
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo) = 0;
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign) = 0;
/**************** Set Net Info ****************/
/*
* These functions are used by:
* 1) p3linkmgr
* 2) p3peers - reasonable
* 3) p3disc - reasonable
*/
virtual bool setLocalAddress(const std::string &id, struct sockaddr_in addr) = 0;
virtual bool setExtAddress(const std::string &id, struct sockaddr_in addr) = 0;
virtual bool setDynDNS(const std::string &id, const std::string &dyndns) = 0;
virtual bool setNetworkMode(const std::string &id, uint32_t netMode) = 0;
virtual bool setVisState(const std::string &id, uint32_t visState) = 0;
virtual bool setLocation(const std::string &pid, const std::string &location) = 0;
virtual bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr) = 0;
virtual bool updateLastContact(const std::string& id) = 0;
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs) = 0;
/**************** Net Status Info ****************/
/*
* MUST RATIONALISE THE DATA FROM THESE FUNCTIONS
* These functions are used by:
* 1) p3face-config ... to remove!
* 2) p3peers - reasonable
* 3) p3disc - reasonable
*/
virtual bool getOwnNetStatus(peerState &state) = 0;
virtual bool getFriendNetStatus(const std::string &id, peerState &state) = 0;
virtual bool getOthersNetStatus(const std::string &id, peerState &state) = 0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
// Single Use Function... shouldn't be here. used by p3serverconfig.cc
virtual bool haveOnceConnected() = 0;
/*************************************************************************************************/
/*************************************************************************************************/
/*************************************************************************************************/
/*************************************************************************************************/
};
class p3PeerMgrIMPL: public p3PeerMgr, public p3Config
{
public:
/************************************************************************************************/
/* EXTERNAL INTERFACE */
/************************************************************************************************/
virtual 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);
virtual bool removeFriend(const std::string &ssl_id);
virtual bool isFriend(const std::string &ssl_id);
/******************** Groups **********************/
/* This is solely used by p3peers - makes sense */
virtual bool addGroup(RsGroupInfo &groupInfo);
virtual bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool removeGroup(const std::string &groupId);
virtual bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
virtual bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign);
/**************** Set Net Info ****************/
/*
* These functions are used by:
* 1) p3linkmgr
* 2) p3peers - reasonable
* 3) p3disc - reasonable
*/
virtual bool setLocalAddress(const std::string &id, struct sockaddr_in addr);
virtual bool setExtAddress(const std::string &id, struct sockaddr_in addr);
virtual bool setDynDNS(const std::string &id, const std::string &dyndns);
virtual bool setNetworkMode(const std::string &id, uint32_t netMode);
virtual bool setVisState(const std::string &id, uint32_t visState);
virtual bool setLocation(const std::string &pid, const std::string &location);
virtual bool updateCurrentAddress(const std::string& id, const pqiIpAddress &addr);
virtual bool updateLastContact(const std::string& id);
virtual bool updateAddressList(const std::string& id, const pqiIpAddrSet &addrs);
/**************** Net Status Info ****************/
/*
* MUST RATIONALISE THE DATA FROM THESE FUNCTIONS
* These functions are used by:
* 1) p3face-config ... to remove!
* 2) p3peers - reasonable
* 3) p3disc - reasonable
*/
virtual bool getOwnNetStatus(peerState &state);
virtual bool getFriendNetStatus(const std::string &id, peerState &state);
virtual bool getOthersNetStatus(const std::string &id, peerState &state);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
// Single Use Function... shouldn't be here. used by p3serverconfig.cc
virtual bool haveOnceConnected();
/************************************************************************************************/
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */
/************************************************************************************************/
p3PeerMgrIMPL();
void setManagers(p3LinkMgrIMPL *linkMgr, p3NetMgrIMPL *netMgr);
void tick(); void tick();
/*************** External Control ****************/ const std::string getOwnId();
bool shutdown(); /* blocking shutdown call */
void setOwnNetworkMode(uint32_t netMode); void setOwnNetworkMode(uint32_t netMode);
void setOwnVisState(uint32_t visState); 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 updateLastContact(const std::string& id);
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
/* 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 removeFriend(const std::string &ssl_id);
bool addNeighbour(const std::string&);
void printPeerLists(std::ostream &out);
/*************** External Control ****************/
/* access to network details (called through Monitor) */
const std::string getOwnId();
bool getOwnNetStatus(peerState &state);
bool isFriend(const std::string &ssl_id);
bool isOnline(const std::string &ssl_id);
bool getFriendNetStatus(const std::string &id, peerState &state);
bool getOthersNetStatus(const std::string &id, peerState &state);
void getOnlineList(std::list<std::string> &ssl_peers);
void getFriendList(std::list<std::string> &ssl_peers);
//void getOthersList(std::list<std::string> &peers); /deprecated
bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl);
int getConnectAddresses(const std::string &id, int getConnectAddresses(const std::string &id,
struct sockaddr_in &lAddr, struct sockaddr_in &eAddr, struct sockaddr_in &lAddr, struct sockaddr_in &eAddr,
pqiIpAddrSet &histAddrs, std::string &dyndns); pqiIpAddrSet &histAddrs, std::string &dyndns);
bool haveOnceConnected();
/**************** handle monitors *****************/
void addMonitor(pqiMonitor *mon);
void removeMonitor(pqiMonitor *mon);
/******************** Groups **********************/
bool addGroup(RsGroupInfo &groupInfo);
bool editGroup(const std::string &groupId, RsGroupInfo &groupInfo);
bool removeGroup(const std::string &groupId);
bool getGroupInfo(const std::string &groupId, RsGroupInfo &groupInfo);
bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList);
bool assignPeersToGroup(const std::string &groupId, const std::list<std::string> &peerIds, bool assign);
protected: protected:
/* Internal Functions */ /* Internal Functions */
void printPeerLists(std::ostream &out);
protected: protected:
/*****************************************************************/ /*****************************************************************/
@ -200,8 +291,8 @@ protected:
/* other important managers */ /* other important managers */
p3LinkMgr *mLinkMgr; p3LinkMgrIMPL *mLinkMgr;
p3NetMgr *mNetMgr; p3NetMgrIMPL *mNetMgr;
private: private:

View File

@ -45,9 +45,9 @@
#include "services/p3channels.h" #include "services/p3channels.h"
#include "services/p3forums.h" #include "services/p3forums.h"
class p3PeerMgr; class p3PeerMgrIMPL;
class p3LinkMgr; class p3LinkMgrIMPL;
class p3NetMgr; class p3NetMgrIMPL;
/* The Main Interface Class - for controlling the server */ /* The Main Interface Class - for controlling the server */
@ -154,9 +154,9 @@ class RsServer: public RsControl, public RsThread
//filedexserver *server; //filedexserver *server;
ftServer *ftserver; ftServer *ftserver;
p3PeerMgr *mPeerMgr; p3PeerMgrIMPL *mPeerMgr;
p3LinkMgr *mLinkMgr; p3LinkMgrIMPL *mLinkMgr;
p3NetMgr *mNetMgr; p3NetMgrIMPL *mNetMgr;
pqipersongrp *pqih; pqipersongrp *pqih;

View File

@ -1834,9 +1834,9 @@ int RsServer::StartupRetroShare()
/* Setup Notify Early - So we can use it. */ /* Setup Notify Early - So we can use it. */
rsNotify = new p3Notify(); rsNotify = new p3Notify();
mPeerMgr = new p3PeerMgr(); mPeerMgr = new p3PeerMgrIMPL();
mNetMgr = new p3NetMgr(); mNetMgr = new p3NetMgrIMPL();
mLinkMgr = new p3LinkMgr(mPeerMgr, mNetMgr); mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
mPeerMgr->setManagers(mLinkMgr, mNetMgr); mPeerMgr->setManagers(mLinkMgr, mNetMgr);
mNetMgr->setManagers(mPeerMgr, mLinkMgr); mNetMgr->setManagers(mPeerMgr, mLinkMgr);

View File

@ -225,7 +225,7 @@ int p3MsgService::checkOutgoingMessages()
peerConnectState pstate; peerConnectState pstate;
bool toSend = false; bool toSend = false;
if (mLinkMgr->getFriendNetStatus(pid, pstate)) if (mLinkMgr->isOnline(pid))
{ {
if (pstate.state & RS_PEER_S_CONNECTED) if (pstate.state & RS_PEER_S_CONNECTED)
{ {