General debugging:

* Improved debugging messages for p3linkmgr & p3netmgr, switched on debugging.
 * added ids to p3bitdht peers.
 * added datatypes to RsDht peers data structure, and translate the data.
 * add const to PeerConnectStateBox::connectState().
 * cleaned up p3LinkMgr::locked_ConnectAttempt_AddDynDNS() a bit.
 * filled in friend data types in p3LinkMgr (allows connections now!)
 * added printConnectState() in p3LinkMgr



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4421 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-10 18:19:46 +00:00
parent 59abce2d48
commit b2e25680ac
8 changed files with 322 additions and 163 deletions

View File

@ -185,7 +185,7 @@ void PeerConnectStateBox::stateMsg(std::ostream &out, std::string msg, uint32_t
out << std::endl;
}
std::string PeerConnectStateBox::connectState()
std::string PeerConnectStateBox::connectState() const
{
std::string str = StateAsString(mState);
std::ostringstream out;

View File

@ -85,7 +85,7 @@ class PeerConnectStateBox
bool shouldUseProxyPort(uint32_t netmode, uint32_t nattype);
std::string connectState();
std::string connectState() const;
std::string mPeerId;

View File

@ -179,6 +179,35 @@ void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDeta
status.mDhtId = out.str();
status.mRsId = details.mRsId;
status.mDhtState = details.mDhtState;
status.mConnectState = details.mConnectLogic.connectState();
status.mPeerReqState = details.mPeerReqState;
status.mPeerConnectState = details.mPeerConnectState;
switch(details.mPeerConnectMode)
{
default:
case BITDHT_CONNECT_MODE_DIRECT:
status.mPeerConnectMode = RSDHT_TOU_MODE_DIRECT;
break;
case BITDHT_CONNECT_MODE_PROXY:
status.mPeerConnectMode = RSDHT_TOU_MODE_PROXY;
break;
case BITDHT_CONNECT_MODE_RELAY:
status.mPeerConnectMode = RSDHT_TOU_MODE_RELAY;
break;
}
//status.mPeerConnectProxyId = details.mPeerConnectProxyId;
std::ostringstream out2;
bdStdPrintId(out2, &(details.mPeerConnectProxyId));
status.mPeerConnectProxyId = out2.str();
status.mCbPeerMsg = details.mPeerCbMsg;
return;
}

View File

@ -21,6 +21,7 @@
#define PEERNET_CONNECT_TIMEOUT 45
#define DEBUG_BITDHT 1
#if 0
int p3BitDht::add_peer(std::string id)

View File

@ -33,6 +33,7 @@
#include <openssl/sha.h>
#define DEBUG_BITDHT 1
/******************************************************************************************
********************************* Existing Interface *************************************
@ -181,6 +182,8 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const std::string pid, int type
/* what do we need to reset? */
dpd->mPeerType = type;
dpd->mDhtId.id = id;
dpd->mRsId = pid;
return dpd;
}
@ -274,7 +277,7 @@ bool p3BitDht::havePeerTranslation_locked(const std::string &pid)
#ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::havePeerTranslation_locked() Found NodeId: ";
bdStdPrintNodeId(std::cerr, id);
bdStdPrintNodeId(std::cerr, &(it->second));
std::cerr << std::endl;
#endif

View File

@ -51,11 +51,11 @@ const int p3connectzone = 3431;
/****
* #define CONN_DEBUG 1
* #define CONN_DEBUG_RESET 1
* #define CONN_DEBUG_TICK 1
* #define LINKMGR_DEBUG 1
***/
#define LINKMGR_DEBUG 1
/****
* #define P3CONNMGR_NO_TCP_CONNECTIONS 1
***/
@ -151,7 +151,7 @@ p3LinkMgr::p3LinkMgr(p3PeerMgr *peerMgr, p3NetMgr *netMgr)
mBannedIpList.push_back(bip);
}
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr() Startup" << std::endl;
#endif
@ -321,7 +321,7 @@ void p3LinkMgr::tick()
bool p3LinkMgr::shutdown() /* blocking shutdown call */
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::shutdown() NOOP";
std::cerr << std::endl;
#endif
@ -338,7 +338,7 @@ void p3LinkMgr::statusTick()
* etc.
*/
#ifdef CONN_DEBUG_TICK
#ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick()" << std::endl;
#endif
std::list<std::string> retryIds;
@ -362,7 +362,7 @@ void p3LinkMgr::statusTick()
if ((it->second.state & RS_PEER_S_ONLINE) &&
(it->second.lastavailable < oldavail))
{
#ifdef CONN_DEBUG_TICK
#ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick() ONLINE TIMEOUT for: ";
std::cerr << it->first;
std::cerr << std::endl;
@ -381,7 +381,7 @@ void p3LinkMgr::statusTick()
for(it2 = retryIds.begin(); it2 != retryIds.end(); it2++)
{
#ifdef CONN_DEBUG_TICK
#ifdef LINKMGR_DEBUG_TICK
std::cerr << "p3LinkMgr::statusTick() RETRY TIMEOUT for: ";
std::cerr << *it2;
std::cerr << std::endl;
@ -442,7 +442,7 @@ void p3LinkMgr::tickMonitors()
if (mStatusChanged)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::tickMonitors() StatusChanged! List:" << std::endl;
#endif
/* assemble list */
@ -462,7 +462,7 @@ void p3LinkMgr::tickMonitors()
actionList.push_back(peer);
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "Friend: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
if (peer.state & RS_PEER_S_FRIEND)
std::cerr << " S:RS_PEER_S_FRIEND";
@ -512,7 +512,7 @@ void p3LinkMgr::tickMonitors()
/* reset action */
it->second.actions = 0;
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "Other: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
if (peer.state & RS_PEER_S_FRIEND)
std::cerr << " S:RS_PEER_S_FRIEND";
@ -554,7 +554,7 @@ void p3LinkMgr::tickMonitors()
if (doStatusChange)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "Sending to " << clients.size() << " monitorClients" << std::endl;
#endif
@ -598,7 +598,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
it = mFriendList.find(id);
if (it == mFriendList.end())
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() FAILED Not in FriendList! id: " << id << std::endl;
#endif
@ -607,7 +607,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
if (it->second.connAddrs.size() < 1)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() FAILED No ConnectAddresses id: " << id << std::endl;
#endif
return false;
@ -616,7 +616,7 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() Already FLAGGED as connected!!!!" << std::endl;
std::cerr << "p3LinkMgr::connectAttempt() But allowing anyway!!!" << std::endl;
#endif
@ -633,13 +633,13 @@ bool p3LinkMgr::connectAttempt(const std::string &id, struct sockaddr_in &addr,
type = it->second.currentConnAddrAttempt.type;
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::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 << " type: " << type << std::endl;
#endif
if (addr.sin_addr.s_addr == 0 || addr.sin_port == 0) {
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectAttempt() WARNING: address or port is null" << std::endl;
std::cerr << " type: " << type << std::endl;
#endif
@ -676,7 +676,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
if (id == getOwnId())
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::connectResult() Failed, connecting to own id: ");
#endif
return false;
@ -686,7 +686,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
it = mFriendList.find(id);
if (it == mFriendList.end())
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Failed, missing Friend " << " id: " << id << std::endl;
#endif
return false;
@ -696,7 +696,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
{
/* update address (should also come through from DISC) */
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Connect!: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl;
#endif
@ -730,7 +730,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
== remote_peer_address.sin_port))
{
updatePeerAddr = true;
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() adding current peer address in list." << std::endl;
#endif
}
@ -746,7 +746,7 @@ bool p3LinkMgr::connectResult(const std::string &id, bool success, uint32_t flag
{
it->second.inConnAttempt = false;
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::connectResult() Disconnect/Fail: id: " << id << std::endl;
std::cerr << " Success: " << success << " flags: " << flags << std::endl;
#endif
@ -829,7 +829,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
addrs.printAddrs(out);
rslog(RSL_WARNING, p3connectzone, out.str());
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << out.str();
#endif
}
@ -844,17 +844,17 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
if (it == mOthersList.end())
{
/* not found - ignore */
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Peer Not Found - Ignore" << std::endl;
#endif
return;
}
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Peer is in mOthersList" << std::endl;
#endif
}
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Current Peer State:" << std::endl;
printConnectState(std::cerr, it->second);
std::cerr << std::endl;
@ -865,6 +865,10 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
/* if source is DHT */
if (source == RS_CB_DHT)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From DHT:";
std::cerr << std::endl;
#endif
/* DHT can tell us about
* 1) connect type (UDP/TCP/etc)
* 2) local/external address
@ -879,6 +883,10 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
}
else if (source == RS_CB_DISC)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From DISC:";
std::cerr << std::endl;
#endif
/* DISC can tell us about
* 1) connect type (UDP/TCP/etc)
* 2) local/external addresses
@ -903,6 +911,10 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
* 2) connect address
* -> update all!
*/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Update From PERSON:";
std::cerr << std::endl;
#endif
it->second.source = RS_CB_PERSON;
it->second.peer = details;
@ -990,7 +1002,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
if (!isFriend)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() NOT FRIEND " << " id: " << id << std::endl;
#endif
@ -1003,7 +1015,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() PEER ONLINE ALREADY " << " id: " << id << std::endl;
#endif
{
@ -1024,7 +1036,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
mPeerMgr -> setNetworkMode(id, peerNetMode);
}
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus()" << " id: " << id;
std::cerr << " type: " << type << " flags: " << flags;
std::cerr << " source: " << source << std::endl;
@ -1048,7 +1060,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
#else
#endif // P3CONNMGR_NO_AUTO_CONNECTION
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerStatus() Resulting Peer State:" << std::endl;
printConnectState(std::cerr, it->second);
std::cerr << std::endl;
@ -1059,7 +1071,7 @@ void p3LinkMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " source: " << source << std::endl;
#endif
@ -1073,19 +1085,23 @@ void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
/******************** TCP PART *****************************/
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() Try TCP first" << std::endl;
#endif
if (source == RS_CB_DHT)
{
std::cerr << "p3LinkMgr::peerConnectRequest() source DHT ==> retryConnectUDP()" << std::endl;
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::peerConnectRequest() source DHT ==> retryConnectUDP()";
std::cerr << std::endl;
#endif
retryConnectUDP(id, raddr);
return;
}
else
{ // IS THIS USED???
std::cerr << "p3LinkMgr::peerConnectRequest() source OTHER ==> retryConnect()" << std::endl;
std::cerr << "p3LinkMgr::peerConnectRequest() ERROR source OTHER ==> retryConnect()" << std::endl;
std::cerr << std::endl;
retryConnect(id);
return;
@ -1099,7 +1115,7 @@ void p3LinkMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
bool p3LinkMgr::retryConnect(const std::string &id)
{
/* push all available addresses onto the connect addr stack */
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnect() id: " << id << std::endl;
#endif
@ -1119,12 +1135,12 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
/* push all available addresses onto the connect addr stack */
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
#endif
if (id == getOwnId()) {
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectUDP() Failed, connecting to own id: ");
#endif
return false;
@ -1134,7 +1150,7 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer is not Friend" << std::endl;
#endif
return false;
@ -1143,15 +1159,15 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Already Connected" << std::endl;
#endif
if (it->second.connecttype & RS_NET_CONN_TUNNEL) {
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
#endif
} else {
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectUDP() Peer Connected no more connection attempts" << std::endl;
#endif
return false;
@ -1161,7 +1177,7 @@ bool p3LinkMgr::retryConnectUDP(const std::string &id, struct sockaddr_in &rUd
/* Explicit Request to start the UDP connection */
if (isValidNet(&(rUdpAddr.sin_addr)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "Adding udp connection attempt: ";
std::cerr << "Addr: " << rs_inet_ntoa(rUdpAddr.sin_addr);
std::cerr << ":" << ntohs(rUdpAddr.sin_port);
@ -1197,13 +1213,13 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
- check address age. don't add old ones
*/
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() id: " << id << std::endl;
#endif
if (id == getOwnId())
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
rslog(RSL_WARNING, p3connectzone, "p3LinkMgr::retryConnectTCP() Failed, connecting to own id: ");
#endif
return false;
@ -1213,7 +1229,7 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer is not Friend" << std::endl;
#endif
return false;
@ -1222,18 +1238,18 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Already Connected" << std::endl;
#endif
if (it->second.connecttype & RS_NET_CONN_TUNNEL)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
#endif
}
else
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Peer Connected no more connection attempts" << std::endl;
#endif
return false;
@ -1241,6 +1257,10 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
}
} /****** END of LOCKED ******/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::retryConnectTCP() Getting Address from PeerMgr for : " << id;
std::cerr << std::endl;
#endif
/* If we reach here, must retry .... extract the required info from p3PeerMgr */
struct sockaddr_in lAddr;
@ -1272,6 +1292,16 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
/* finish it off */
return locked_ConnectAttempt_Complete(&(it->second));
}
else
{
std::cerr << "p3LinkMgr::retryConnectTCP() ERROR failed to find friend data : " << id;
std::cerr << std::endl;
}
}
else
{
std::cerr << "p3LinkMgr::retryConnectTCP() ERROR failed to addresses from PeerMgr for: " << id;
std::cerr << std::endl;
}
return false;
@ -1283,7 +1313,7 @@ bool p3LinkMgr::retryConnectTCP(const std::string &id)
bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr(";
std::cerr << rs_inet_ntoa(addr->sin_addr);
std::cerr << ":" << ntohs(addr->sin_port);
@ -1296,7 +1326,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
*/
if (age > MAX_TCP_ADDR_AGE)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - TOO OLD";
std::cerr << std::endl;
#endif
@ -1311,7 +1341,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
/* if invalid - quick rejection */
if (!isValid)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - INVALID";
std::cerr << std::endl;
#endif
@ -1326,7 +1356,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
{
if (it->s_addr == addr->sin_addr.s_addr)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - ON BANNED IPLIST";
std::cerr << std::endl;
#endif
@ -1340,7 +1370,7 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
*/
if (isExternal)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - EXTERNAL";
std::cerr << std::endl;
#endif
@ -1360,14 +1390,14 @@ bool p3LinkMgr::locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_
if (sameNet(&(mLocalAddress.sin_addr), &(addr->sin_addr)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET";
std::cerr << std::endl;
#endif
return true;
}
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_CheckPotentialAddr() REJECTING - PRIVATE & !sameNET";
std::cerr << std::endl;
#endif
@ -1380,11 +1410,16 @@ 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)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses()";
std::cerr << std::endl;
#endif
// Just push all the addresses onto the stack.
/* try "current addresses" first */
if ((localAddr) && (locked_CheckPotentialAddr(localAddr, 0)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Current Local Addr: " << rs_inet_ntoa(localAddr->sin_addr);
std::cerr << ":" << ntohs(localAddr->sin_port);
@ -1402,7 +1437,8 @@ void p3LinkMgr::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer,
if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0)))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_CurrentAddresses() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Current Ext Addr: " << rs_inet_ntoa(serverAddr->sin_addr);
std::cerr << ":" << ntohs(serverAddr->sin_port);
@ -1427,13 +1463,18 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
std::list<pqiIpAddress>::const_iterator ait;
time_t now = time(NULL);
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses()";
std::cerr << std::endl;
#endif
for(ait = ipAddrs.mLocal.mAddrs.begin();
ait != ipAddrs.mLocal.mAddrs.end(); ait++)
{
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Local Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr);
std::cerr << ":" << ntohs(ait->mAddr.sin_port);
@ -1457,7 +1498,8 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
if (locked_CheckPotentialAddr(&(ait->mAddr), now - ait->mSeenTime))
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Ext Addr: " << rs_inet_ntoa(ait->mAddr.sin_addr);
std::cerr << ":" << ntohs(ait->mAddr.sin_port);
@ -1479,39 +1521,51 @@ void p3LinkMgr::locked_ConnectAttempt_HistoricalAddresses(peerConnectState *pee
void p3LinkMgr::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t port)
{
/* try dyndns address too */
if (!dyndns.empty())
struct in_addr addr;
if (!dyndns.empty() && port)
{
struct in_addr addr;
#ifdef CONN_DEBUG
std::cerr << "Looking up DynDNS address" << std::endl;
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() Looking up DynDNS address: " << dyndns << std::endl;
#endif
if (port)
if(mDNSResolver->getIPAddressFromString(dyndns, addr))
{
if(mDNSResolver->getIPAddressFromString(dyndns, addr))
{
#ifdef CONN_DEBUG
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "DynDNS Addr: " << rs_inet_ntoa(addr);
std::cerr << ":" << ntohs(port);
std::cerr << std::endl;
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "DynDNS Addr: " << rs_inet_ntoa(addr);
std::cerr << ":" << ntohs(port);
std::cerr << std::endl;
#endif
peerConnectAddress pca;
pca.addr.sin_family = AF_INET;
pca.addr.sin_addr.s_addr = addr.s_addr;
pca.addr.sin_port = htons(port);
pca.type = RS_NET_CONN_TCP_EXTERNAL;
//for the delay, we add a random time and some more time when the friend list is big
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
peerConnectAddress pca;
pca.addr.sin_family = AF_INET;
pca.addr.sin_addr.s_addr = addr.s_addr;
pca.addr.sin_port = htons(port);
pca.type = RS_NET_CONN_TCP_EXTERNAL;
//for the delay, we add a random time and some more time when the friend list is big
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
/* check address validity */
if (locked_CheckPotentialAddr(&(pca.addr), 0))
{
addAddressIfUnique(peer->connAddrs, pca);
}
/* check address validity */
if (locked_CheckPotentialAddr(&(pca.addr), 0))
{
addAddressIfUnique(peer->connAddrs, pca);
}
}
else
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() DNSResolver hasn't found addr yet";
std::cerr << std::endl;
#endif
}
}
else
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_AddDynDNS() Address(" << dyndns << ") or Port(" << port << ") NULL ignoring";
std::cerr << std::endl;
#endif
}
}
@ -1520,7 +1574,7 @@ void p3LinkMgr::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
{
if (!(peer->state & RS_PEER_S_CONNECTED) && mAllowTunnelConnection)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "Adding TUNNEL Connection Attempt";
std::cerr << std::endl;
#endif
@ -1541,6 +1595,10 @@ bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, pee
/* iterate through the list, and make sure it isn't already
* in the list
*/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Checking Address: " << rs_inet_ntoa(pca.addr.sin_addr);
std::cerr << std::endl;
#endif
std::list<peerConnectAddress>::iterator it;
for(it = addrList.begin(); it != addrList.end(); it++)
@ -1549,11 +1607,20 @@ bool p3LinkMgr::addAddressIfUnique(std::list<peerConnectAddress> &addrList, pee
(pca.addr.sin_port == it->addr.sin_port) &&
(pca.type == it->type))
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Discarding Duplicate Address";
std::cerr << std::endl;
#endif
/* already */
return false;
}
}
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addAddressIfUnique() Adding New Address";
std::cerr << std::endl;
#endif
addrList.push_back(pca);
return true;
@ -1571,7 +1638,7 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
if (peer->inConnAttempt)
{
/* -> it'll automatically use the addresses we added */
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Already in CONNECT ATTEMPT";
std::cerr << std::endl;
std::cerr << "p3LinkMgr::locked_ConnectAttempt_Complete() Remaining ConnAddr Count: " << peer->connAddrs.size();
@ -1583,13 +1650,13 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
/* start a connection attempt */
if (peer->connAddrs.size() > 0)
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::ostringstream out;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() Started CONNECT ATTEMPT! " ;
out << std::endl;
out << std::endl;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() ConnAddr Count: " << peer->connAddrs.size();
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
std::cerr << out.str() << std::endl;
std::cerr << out.str() << std::endl;
#endif
@ -1599,11 +1666,11 @@ bool p3LinkMgr::locked_ConnectAttempt_Complete(peerConnectState *peer)
}
else
{
#ifdef CONN_DEBUG
#ifdef LINKMGR_DEBUG
std::ostringstream out;
out << "p3LinkMgr::locked_ConnectAttempt_Complete() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! ";
rslog(RSL_DEBUG_ALERT, p3connectzone, out.str());
std::cerr << out.str() << std::endl;
std::cerr << out.str() << std::endl;
#endif
return false;
}
@ -1620,6 +1687,11 @@ int p3LinkMgr::addFriend(const std::string &id, bool isVisible)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::addFriend(" << id << "," << isVisible << ")";
std::cerr << std::endl;
#endif
std::map<std::string, peerConnectState>::iterator it;
it = mFriendList.find(id);
@ -1632,6 +1704,10 @@ int p3LinkMgr::addFriend(const std::string &id, bool isVisible)
peerConnectState pcs;
pcs.dhtVisible = isVisible;
pcs.id = id;
pcs.name = "Dummy Id Name";
pcs.state = RS_PEER_S_FRIEND;
pcs.actions = RS_PEER_NEW;
mFriendList[id] = pcs;
}
@ -1646,6 +1722,11 @@ int p3LinkMgr::removeFriend(const std::string &id)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgr::removeFriend(" << id << ")";
std::cerr << std::endl;
#endif
std::map<std::string, peerConnectState>::iterator it;
it = mFriendList.find(id);
@ -1663,5 +1744,31 @@ int p3LinkMgr::removeFriend(const std::string &id)
void printConnectState(std::ostream &out, peerConnectState &peer)
{
out << "Friend: " << peer.name << " Id: " << peer.id << " State: " << peer.state;
if (peer.state & RS_PEER_S_FRIEND)
out << " S:RS_PEER_S_FRIEND";
if (peer.state & RS_PEER_S_ONLINE)
out << " S:RS_PEER_S_ONLINE";
if (peer.state & RS_PEER_S_CONNECTED)
out << " S:RS_PEER_S_CONNECTED";
out << " Actions: " << peer.actions;
if (peer.actions & RS_PEER_NEW)
out << " A:RS_PEER_NEW";
if (peer.actions & RS_PEER_MOVED)
out << " A:RS_PEER_MOVED";
if (peer.actions & RS_PEER_CONNECTED)
out << " A:RS_PEER_CONNECTED";
if (peer.actions & RS_PEER_DISCONNECTED)
out << " A:RS_PEER_DISCONNECTED";
if (peer.actions & RS_PEER_CONNECT_REQ)
out << " A:RS_PEER_CONNECT_REQ";
out << std::endl;
return;
}

View File

@ -68,11 +68,13 @@ const uint32_t MAX_NETWORK_INIT = 70; /* timeout before network reset */
const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
/****
* #define CONN_DEBUG 1
* #define CONN_DEBUG_RESET 1
* #define CONN_DEBUG_TICK 1
* #define NETMGR_DEBUG 1
* #define NETMGR_DEBUG_RESET 1
* #define NETMGR_DEBUG_TICK 1
***/
#define NETMGR_DEBUG_RESET 1
pqiNetStatus::pqiNetStatus()
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
mUpnpOk(false), mDhtOk(false), mResetReq(false)
@ -126,7 +128,7 @@ p3NetMgr::p3NetMgr()
}
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr() Startup" << std::endl;
#endif
@ -245,7 +247,7 @@ uint32_t p3NetMgr::getConnectModes()
void p3NetMgr::netReset()
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() Called" << std::endl;
#endif
@ -254,19 +256,19 @@ void p3NetMgr::netReset()
// Will initiate a new call for determining the external ip.
if (mUseExtAddrFinder)
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() restarting AddrFinder" << std::endl;
#endif
mExtAddrFinder->reset() ;
}
else
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() ExtAddrFinder Disabled" << std::endl;
#endif
}
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() resetting NetStatus" << std::endl;
#endif
@ -284,14 +286,14 @@ void p3NetMgr::netReset()
struct sockaddr_in iaddr = mLocalAddr;
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() resetting listeners" << std::endl;
#endif
std::list<pqiNetListener *>::const_iterator it;
for(it = mNetListeners.begin(); it != mNetListeners.end(); it++)
{
(*it)->resetListener(iaddr);
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() reset listener" << std::endl;
#endif
}
@ -303,7 +305,7 @@ void p3NetMgr::netReset()
netStatusReset_locked();
}
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netReset() done" << std::endl;
#endif
}
@ -319,7 +321,7 @@ void p3NetMgr::netStatusReset_locked()
bool p3NetMgr::shutdown() /* blocking shutdown call */
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::shutdown()";
std::cerr << std::endl;
#endif
@ -350,7 +352,7 @@ void p3NetMgr::netStartup()
/* StunInit gets a list of peers, and asks the DHT to find them...
* This is needed for all systems so startup straight away
*/
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup()" << std::endl;
#endif
@ -365,7 +367,7 @@ void p3NetMgr::netStartup()
mNetInitTS = time(NULL);
netStatusReset_locked();
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() resetting mNetInitTS / Status" << std::endl;
#endif
mNetMode &= ~(RS_NET_MODE_ACTUAL);
@ -374,7 +376,7 @@ void p3NetMgr::netStartup()
{
case RS_NET_MODE_TRY_EXT: /* v similar to UDP */
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_EXT mode";
std::cerr << std::endl;
#endif
@ -383,7 +385,7 @@ void p3NetMgr::netStartup()
break;
case RS_NET_MODE_TRY_UDP:
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_UDP mode";
std::cerr << std::endl;
#endif
@ -393,13 +395,13 @@ void p3NetMgr::netStartup()
default: // Fall through.
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() UNKNOWN mode";
std::cerr << std::endl;
#endif
case RS_NET_MODE_TRY_UPNP:
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::netStartup() TRY_UPNP mode";
std::cerr << std::endl;
#endif
@ -423,7 +425,7 @@ void p3NetMgr::tick()
void p3NetMgr::netTick()
{
#ifdef CONN_DEBUG_TICK
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::netTick()" << std::endl;
#endif
@ -447,14 +449,14 @@ void p3NetMgr::netTick()
{
case RS_NET_NEEDS_RESET:
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: NEEDS_RESET" << std::endl;
#endif
netReset();
break;
case RS_NET_UNKNOWN:
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UNKNOWN" << std::endl;
#endif
@ -463,7 +465,7 @@ void p3NetMgr::netTick()
*/
if (age < STARTUP_DELAY)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() Delaying Startup" << std::endl;
#endif
}
@ -475,14 +477,14 @@ void p3NetMgr::netTick()
break;
case RS_NET_UPNP_INIT:
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UPNP_INIT" << std::endl;
#endif
netUpnpInit();
break;
case RS_NET_UPNP_SETUP:
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: UPNP_SETUP" << std::endl;
#endif
netUpnpCheck();
@ -490,14 +492,14 @@ void p3NetMgr::netTick()
case RS_NET_EXT_SETUP:
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: EXT_SETUP" << std::endl;
#endif
netExtCheck();
break;
case RS_NET_DONE:
#ifdef CONN_DEBUG_TICK
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::netTick() STATUS: DONE" << std::endl;
#endif
@ -506,7 +508,7 @@ void p3NetMgr::netTick()
case RS_NET_LOOPBACK:
//don't do a shutdown because a client in a computer without local network might be usefull for debug.
//shutdown();
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netTick() STATUS: RS_NET_LOOPBACK" << std::endl;
#endif
default:
@ -519,7 +521,7 @@ void p3NetMgr::netTick()
void p3NetMgr::netDhtInit()
{
#if defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netDhtInit()" << std::endl;
#endif
@ -535,7 +537,7 @@ void p3NetMgr::netDhtInit()
void p3NetMgr::netUpnpInit()
{
#if defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpInit()" << std::endl;
#endif
uint16_t eport, iport;
@ -565,7 +567,7 @@ void p3NetMgr::netUpnpCheck()
time_t delta = time(NULL) - mNetInitTS;
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() age: " << delta << std::endl;
#endif
@ -577,7 +579,7 @@ void p3NetMgr::netUpnpCheck()
if (((upnpState == 0) && (delta > (time_t)MAX_UPNP_INIT)) ||
((upnpState > 0) && (delta > (time_t)MAX_UPNP_COMPLETE)))
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() ";
std::cerr << "Upnp Check failed." << std::endl;
#endif
@ -592,7 +594,7 @@ void p3NetMgr::netUpnpCheck()
}
else if ((upnpState > 0) && netAssistExtAddress(extAddr))
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() ";
std::cerr << "Upnp Check success state: " << upnpState << std::endl;
#endif
@ -605,7 +607,7 @@ void p3NetMgr::netUpnpCheck()
*/
if (isValidNet(&(extAddr.sin_addr)))
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() ";
std::cerr << "UpnpAddr: " << rs_inet_ntoa(extAddr.sin_addr);
std::cerr << ":" << ntohs(extAddr.sin_port);
@ -624,7 +626,7 @@ void p3NetMgr::netUpnpCheck()
}
else
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUpnpCheck() ";
std::cerr << "Upnp Check Continues: status: " << upnpState << std::endl;
#endif
@ -635,7 +637,7 @@ void p3NetMgr::netUpnpCheck()
void p3NetMgr::netExtCheck()
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck()" << std::endl;
#endif
{
@ -648,14 +650,14 @@ void p3NetMgr::netExtCheck()
/* (1) UPnP -> which handles itself */
if (!mNetFlags.mExtAddrOk)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Not Ok" << std::endl;
#endif
/* net Assist */
if (netAssistExtAddress(tmpip))
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl;
#endif
if (isValidNet(&(tmpip.sin_addr)))
@ -668,7 +670,7 @@ void p3NetMgr::netExtCheck()
}
else
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
#endif
}
@ -682,18 +684,18 @@ void p3NetMgr::netExtCheck()
/* ExtAddrFinder */
if (mUseExtAddrFinder)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() checking ExtAddrFinder" << std::endl;
#endif
bool extFinderOk = mExtAddrFinder->hasValidIP(&(tmpip.sin_addr));
if (extFinderOk)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
#endif
/* best guess at port */
tmpip.sin_port = mNetFlags.mLocalAddr.sin_port;
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() ";
std::cerr << "ExtAddr: " << rs_inet_ntoa(tmpip.sin_addr);
std::cerr << ":" << ntohs(tmpip.sin_port);
@ -718,7 +720,7 @@ void p3NetMgr::netExtCheck()
if (mNetFlags.mExtAddrOk)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() ";
std::cerr << "ExtAddr: " << rs_inet_ntoa(mNetFlags.mExtAddr.sin_addr);
std::cerr << ":" << ntohs(mNetFlags.mExtAddr.sin_port);
@ -728,13 +730,13 @@ void p3NetMgr::netExtCheck()
mExtAddr = mNetFlags.mExtAddr;
mNetStatus = RS_NET_DONE;
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Ok: RS_NET_DONE" << std::endl;
#endif
if (!mNetFlags.mExtAddrStableOk)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netUdpCheck() UDP Unstable :( ";
std::cerr << std::endl;
std::cerr << "p3NetMgr::netUdpCheck() We are unreachable";
@ -772,7 +774,7 @@ void p3NetMgr::netExtCheck()
if (mNetFlags.mExtAddrOk)
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() setting netAssistSetAddress()" << std::endl;
#endif
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
@ -789,7 +791,7 @@ void p3NetMgr::netExtCheck()
/* flag unreachables! */
if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk))
{
#if defined(CONN_DEBUG_TICK) || defined(CONN_DEBUG_RESET)
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgr::netExtCheck() Ext Unstable - Unreachable Check" << std::endl;
#endif
}
@ -813,7 +815,7 @@ bool p3NetMgr::checkNetAddress()
/* if we don't have a valid address - reset */
if (!validAddr)
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::checkNetAddress() no Valid Network Address, resetting network." << std::endl;
std::cerr << std::endl;
#endif
@ -830,7 +832,7 @@ bool p3NetMgr::checkNetAddress()
oldAddr = mLocalAddr;
addrChanged = (prefAddr.s_addr != mLocalAddr.sin_addr.s_addr);
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress()";
std::cerr << std::endl;
std::cerr << "Current Local: " << rs_inet_ntoa(mLocalAddr.sin_addr);
@ -840,7 +842,7 @@ bool p3NetMgr::checkNetAddress()
std::cerr << std::endl;
#endif
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
if (addrChanged)
{
std::cerr << "p3NetMgr::checkNetAddress() Address Changed!";
@ -859,7 +861,7 @@ bool p3NetMgr::checkNetAddress()
if(isLoopbackNet(&(mLocalAddr.sin_addr)))
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() laddr: Loopback" << std::endl;
#endif
mNetFlags.mLocalAddrOk = false;
@ -867,14 +869,14 @@ bool p3NetMgr::checkNetAddress()
}
else if (!isValidNet(&mLocalAddr.sin_addr))
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() laddr: invalid" << std::endl;
#endif
mNetFlags.mLocalAddrOk = false;
}
else
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress() laddr okay" << std::endl;
#endif
mNetFlags.mLocalAddrOk = true;
@ -884,7 +886,7 @@ bool p3NetMgr::checkNetAddress()
int port = ntohs(mLocalAddr.sin_port);
if ((port < PQI_MIN_PORT) || (port > PQI_MAX_PORT))
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::checkNetAddress() Correcting Port to DEFAULT" << std::endl;
#endif
// Generate a default port from SSL id. The port will always be the
@ -910,7 +912,7 @@ bool p3NetMgr::checkNetAddress()
mLocalAddr.sin_family = AF_INET;
mExtAddr.sin_family = AF_INET;
#ifdef CONN_DEBUG_TICK
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgr::checkNetAddress() Final Local Address: " << rs_inet_ntoa(mLocalAddr.sin_addr);
std::cerr << ":" << ntohs(mLocalAddr.sin_port) << std::endl;
std::cerr << std::endl;
@ -920,7 +922,7 @@ bool p3NetMgr::checkNetAddress()
if (addrChanged)
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::checkNetAddress() local address changed, resetting network." << std::endl;
std::cerr << std::endl;
#endif
@ -963,7 +965,7 @@ bool p3NetMgr::setLocalAddress(struct sockaddr_in addr)
if (changed)
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setLocalAddress() Calling NetReset" << std::endl;
#endif
netReset();
@ -987,7 +989,7 @@ bool p3NetMgr::setExtAddress(struct sockaddr_in addr)
if (changed)
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setExtAddress() Calling NetReset" << std::endl;
#endif
netReset();
@ -1004,7 +1006,7 @@ bool p3NetMgr::setNetworkMode(uint32_t netMode)
oldNetMode = mNetMode;
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::setNetworkMode()";
std::cerr << " Existing netMode: " << mNetMode;
std::cerr << " Input netMode: " << netMode;
@ -1030,7 +1032,7 @@ bool p3NetMgr::setNetworkMode(uint32_t netMode)
if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL))
{
#ifdef CONN_DEBUG_RESET
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgr::setNetworkMode() Calling NetReset" << std::endl;
#endif
netReset();
@ -1150,7 +1152,7 @@ void p3NetMgr::addNetAssistConnect(uint32_t id, pqiNetAssistConnect *dht)
bool p3NetMgr::enableNetAssistConnect(bool on)
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::enableNetAssistConnect(" << on << ")";
std::cerr << std::endl;
#endif
@ -1170,7 +1172,7 @@ bool p3NetMgr::netAssistConnectEnabled()
{
if ((it->second)->getEnabled())
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectEnabled() YES";
std::cerr << std::endl;
#endif
@ -1179,7 +1181,7 @@ bool p3NetMgr::netAssistConnectEnabled()
}
}
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectEnabled() NO";
std::cerr << std::endl;
#endif
@ -1195,7 +1197,7 @@ bool p3NetMgr::netAssistConnectActive()
if ((it->second)->getActive())
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectActive() ACTIVE";
std::cerr << std::endl;
#endif
@ -1204,7 +1206,7 @@ bool p3NetMgr::netAssistConnectActive()
}
}
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectActive() INACTIVE";
std::cerr << std::endl;
#endif
@ -1220,7 +1222,7 @@ bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
if (((it->second)->getActive()) && ((it->second)->getNetworkStats(netsize, localnetsize)))
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectStats(";
std::cerr << netsize << ", " << localnetsize << ")";
std::cerr << std::endl;
@ -1230,7 +1232,7 @@ bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
}
}
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectStats() INACTIVE";
std::cerr << std::endl;
#endif
@ -1240,7 +1242,7 @@ bool p3NetMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
bool p3NetMgr::netAssistConnectShutdown()
{
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr::netAssistConnectShutdown()";
std::cerr << std::endl;
#endif
@ -1364,7 +1366,7 @@ void p3NetMgr::setIPServersEnabled(bool b)
mUseExtAddrFinder = b;
}
#ifdef CONN_DEBUG
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgr: setIPServers to " << b << std::endl ;
#endif

View File

@ -96,6 +96,23 @@ class RsDhtNetPeer
std::string mRsId;
uint32_t mDhtState;
//connectLogic.
std::string mConnectState;
// connect Status
uint32_t mPeerConnectState;
// connect mode
uint32_t mPeerConnectMode;
std::string mPeerConnectProxyId;
// Req Status.
uint32_t mPeerReqState;
// Peer Cb Mgs.
std::string mCbPeerMsg;
};
class RsDhtRelayEnd