From d36b15d526b4a4d88bc4cf59d903424f195a53ea Mon Sep 17 00:00:00 2001 From: drbob Date: Thu, 10 Jul 2008 16:29:18 +0000 Subject: [PATCH] Major cleanup of Retroshare Logging - aimed at enabling proper UDP testing. * Switched off most of std::cerr output. (expect UPnP) * moved pqi/pqidebug to util/rsdebug to allow greater usage. * added Mutexes to logging. * Downgraded many log messages to DEBUG. * New Log messages for connections, dht and udp code. * Added check for bad UDP socket. * Added check for non-firewalled scenario. * Increased Storage period from 1 Month to 6 Months for Links & Blog. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@644 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/Makefile | 2 +- libretroshare/src/pqi/authxpgp.cc | 32 ++ libretroshare/src/pqi/p3connmgr.cc | 132 +++++++- libretroshare/src/pqi/p3dhtmgr.cc | 95 +++++- libretroshare/src/pqi/pqiarchive.cc | 2 +- libretroshare/src/pqi/pqihandler.cc | 2 +- libretroshare/src/pqi/pqinetwork.cc | 2 +- libretroshare/src/pqi/pqiperson.cc | 2 +- libretroshare/src/pqi/pqipersongrp.cc | 2 +- libretroshare/src/pqi/pqiservice.cc | 34 +- libretroshare/src/pqi/pqissl.cc | 318 ++++++++++-------- libretroshare/src/pqi/pqissllistener.cc | 2 +- libretroshare/src/pqi/pqisslpersongrp.cc | 6 +- libretroshare/src/pqi/pqissludp.cc | 159 ++++----- libretroshare/src/pqi/pqistreamer.cc | 14 +- libretroshare/src/rsserver/p3face-config.cc | 2 +- libretroshare/src/rsserver/p3face-file.cc | 2 +- libretroshare/src/rsserver/p3face-msgs.cc | 8 +- libretroshare/src/rsserver/p3face-network.cc | 2 +- libretroshare/src/rsserver/p3face-people.cc | 2 +- libretroshare/src/rsserver/p3face-startup.cc | 6 +- libretroshare/src/rsserver/p3msgs.cc | 18 +- libretroshare/src/server/filedexserver.cc | 3 +- libretroshare/src/server/ftfiler.cc | 2 +- libretroshare/src/services/p3disc.cc | 2 +- libretroshare/src/services/p3gamelauncher.cc | 2 +- libretroshare/src/services/p3msgservice.cc | 6 +- libretroshare/src/services/p3service.cc | 4 +- libretroshare/src/tcponudp/tcpstream.cc | 212 ++++++++++-- libretroshare/src/tcponudp/udpsorter.cc | 19 ++ libretroshare/src/util/Makefile | 2 +- .../src/{pqi/pqidebug.cc => util/rsdebug.cc} | 67 ++-- .../src/{pqi/pqidebug.h => util/rsdebug.h} | 50 ++- 33 files changed, 867 insertions(+), 346 deletions(-) rename libretroshare/src/{pqi/pqidebug.cc => util/rsdebug.cc} (68%) rename libretroshare/src/{pqi/pqidebug.h => util/rsdebug.h} (52%) diff --git a/libretroshare/src/pqi/Makefile b/libretroshare/src/pqi/Makefile index b61b9f135..8dcbf653a 100644 --- a/libretroshare/src/pqi/Makefile +++ b/libretroshare/src/pqi/Makefile @@ -7,7 +7,7 @@ RS_TOP_DIR = .. include $(RS_TOP_DIR)/scripts/config.mk ############################################################### -BASE_OBJ = pqidebug.o pqisecurity.o pqinetwork.o +BASE_OBJ = pqisecurity.o pqinetwork.o #pqi_base.o LOOP_OBJ = pqiloopback.o diff --git a/libretroshare/src/pqi/authxpgp.cc b/libretroshare/src/pqi/authxpgp.cc index a143b8d6e..63c39e342 100644 --- a/libretroshare/src/pqi/authxpgp.cc +++ b/libretroshare/src/pqi/authxpgp.cc @@ -874,8 +874,10 @@ XPGP *AuthXPGP::loadXPGPFromFile(std::string fname, std::string hash) // load certificates from file. if (pcertfp == NULL) { +#ifdef AUTHXPGP_DEBUG std::cerr << "sslroot::loadcertificate() Bad File: " << fname; std::cerr << " Cannot be Hashed!" << std::endl; +#endif return NULL; } @@ -900,7 +902,9 @@ XPGP *AuthXPGP::loadXPGPFromFile(std::string fname, std::string hash) char inall[maxsize]; if (0 == (rbytes = fread(inall, 1, maxsize, pcertfp))) { +#ifdef AUTHXPGP_DEBUG std::cerr << "Error Reading Peer Record!" << std::endl; +#endif return NULL; } //std::cerr << "Read " << rbytes << std::endl; @@ -928,8 +932,10 @@ XPGP *AuthXPGP::loadXPGPFromFile(std::string fname, std::string hash) bool same = true; if (signlen != hash.length()) { +#ifdef AUTHXPGP_DEBUG std::cerr << "Different Length Signatures... "; std::cerr << "Cannot Load Certificate!" << std::endl; +#endif fclose(pcertfp); return NULL; } @@ -939,18 +945,24 @@ XPGP *AuthXPGP::loadXPGPFromFile(std::string fname, std::string hash) if (signature[i] != (unsigned char) hash[i]) { same = false; +#ifdef AUTHXPGP_DEBUG std::cerr << "Invalid Signature... "; std::cerr << "Cannot Load Certificate!" << std::endl; +#endif fclose(pcertfp); return NULL; } } +#ifdef AUTHXPGP_DEBUG std::cerr << "Verified Signature for: " << fname; std::cerr << std::endl; +#endif } else { +#ifdef AUTHXPGP_DEBUG std::cerr << "Not checking cert signature" << std::endl; +#endif } fseek(pcertfp, 0, SEEK_SET); /* rewind */ @@ -960,7 +972,9 @@ XPGP *AuthXPGP::loadXPGPFromFile(std::string fname, std::string hash) if (pc != NULL) { // read a certificate. +#ifdef AUTHXPGP_DEBUG std::cerr << "Loaded Certificate: " << pc -> name << std::endl; +#endif } else // (pc == NULL) { @@ -984,12 +998,16 @@ bool AuthXPGP::saveXPGPToFile(XPGP *xpgp, std::string fname, std::string &hash FILE *setfp = fopen(fname.c_str(), "wb"); if (setfp == NULL) { +#ifdef AUTHXPGP_DEBUG std::cerr << "sslroot::savecertificate() Bad File: " << fname; std::cerr << " Cannot be Written!" << std::endl; +#endif return false; } +#ifdef AUTHXPGP_DEBUG std::cerr << "Writing out Cert...:" << xpgp->name << std::endl; +#endif PEM_write_XPGP(setfp, xpgp); fclose(setfp); @@ -998,8 +1016,10 @@ bool AuthXPGP::saveXPGPToFile(XPGP *xpgp, std::string fname, std::string &hash setfp = fopen(fname.c_str(), "rb"); if (setfp == NULL) { +#ifdef AUTHXPGP_DEBUG std::cerr << "sslroot::savecertificate() Bad File: " << fname; std::cerr << " Opened for ReHash!" << std::endl; +#endif return false; } @@ -1011,10 +1031,14 @@ bool AuthXPGP::saveXPGPToFile(XPGP *xpgp, std::string fname, std::string &hash char inall[maxsize]; if (0 == (rbytes = fread(inall, 1, maxsize, setfp))) { +#ifdef AUTHXPGP_DEBUG std::cerr << "Error Writing Peer Record!" << std::endl; +#endif return -1; } +#ifdef AUTHXPGP_DEBUG std::cerr << "Read " << rbytes << std::endl; +#endif EVP_MD_CTX *mdctx = EVP_MD_CTX_create(); @@ -1033,17 +1057,25 @@ bool AuthXPGP::saveXPGPToFile(XPGP *xpgp, std::string fname, std::string &hash std::cerr << "EVP_SignFinal Failure!" << std::endl; } +#ifdef AUTHXPGP_DEBUG std::cerr << "Saved Cert: " << xpgp->name; std::cerr << std::endl; +#endif +#ifdef AUTHXPGP_DEBUG std::cerr << "Cert + Setting Signature is(" << signlen << "): "; +#endif std::string signstr; for(uint32_t i = 0; i < signlen; i++) { +#ifdef AUTHXPGP_DEBUG fprintf(stderr, "%02x", signature[i]); +#endif signstr += signature[i]; } +#ifdef AUTHXPGP_DEBUG std::cerr << std::endl; +#endif hash = signstr; fclose(setfp); diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 5c1ee87a4..7d3d1a5b3 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -25,11 +25,16 @@ #include "pqi/p3connmgr.h" #include "tcponudp/tou.h" + #include "util/rsprint.h" +#include "util/rsdebug.h" +const int p3connectzone = 3431; #include "serialiser/rsconfigitems.h" #include "pqi/pqinotify.h" +#include + /* Network setup States */ const uint32_t RS_NET_UNKNOWN = 0x0001; @@ -57,7 +62,6 @@ const uint32_t MAX_UPNP_INIT = 10; /* seconds UPnP timeout */ * #define P3CONNMGR_NO_AUTO_CONNECTION 1 ***/ - const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */ const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */ const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */ @@ -623,6 +627,13 @@ void p3ConnectMgr::netUdpCheck() } else // if (extAddrStable) { + /* Check if extAddr == intAddr (Not Firewalled) */ + if ((0 == inaddr_cmp(iaddr, extAddr)) && + isExternalNet(&(extAddr.sin_addr))) + { + mode |= RS_NET_CONN_TCP_EXTERNAL; + } + mode |= RS_NET_CONN_UDP_DHT_SYNC; } @@ -1442,6 +1453,20 @@ void p3ConnectMgr::peerStatus(std::string id, std::cerr << " source: " << source; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerStatus()"; + out << " id: " << id; + out << " laddr: " << inet_ntoa(laddr.sin_addr); + out << " lport: " << ntohs(laddr.sin_port); + out << " raddr: " << inet_ntoa(raddr.sin_addr); + out << " rport: " << ntohs(raddr.sin_port); + out << " type: " << type; + out << " flags: " << flags; + out << " source: " << source; + rslog(RSL_WARNING, p3connectzone, out.str()); + } /* look up the id */ it = mFriendList.find(id); @@ -1605,6 +1630,12 @@ void p3ConnectMgr::peerStatus(std::string id, std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerStatus() NO CONNECT (not friend)"; + rslog(RSL_WARNING, p3connectzone, out.str()); + } return; } @@ -1616,6 +1647,12 @@ void p3ConnectMgr::peerStatus(std::string id, std::cerr << " id: " << id; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerStatus() NO CONNECT (already connected!)"; + rslog(RSL_WARNING, p3connectzone, out.str()); + } return; } @@ -1680,6 +1717,20 @@ void p3ConnectMgr::peerStatus(std::string id, std::cerr << " source: " << source; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerStatus() PushBack Local TCP Address: "; + out << " id: " << id; + out << " laddr: " << inet_ntoa(pca.addr.sin_addr); + out << ":" << ntohs(pca.addr.sin_port); + out << " type: " << pca.type; + out << " delay: " << pca.delay; + out << " period: " << pca.period; + out << " ts: " << pca.ts; + out << " source: " << source; + rslog(RSL_WARNING, p3connectzone, out.str()); + } it->second.connAddrs.push_back(pca); } @@ -1712,14 +1763,28 @@ void p3ConnectMgr::peerStatus(std::string id, #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::peerStatus() ADDING TCP_REMOTE ADDR: "; std::cerr << " id: " << id; - std::cerr << " laddr: " << inet_ntoa(pca.addr.sin_addr); - std::cerr << " lport: " << ntohs(pca.addr.sin_port); + std::cerr << " raddr: " << inet_ntoa(pca.addr.sin_addr); + std::cerr << " rport: " << ntohs(pca.addr.sin_port); std::cerr << " delay: " << pca.delay; std::cerr << " period: " << pca.period; std::cerr << " type: " << pca.type; std::cerr << " source: " << source; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerStatus() PushBack Remote TCP Address: "; + out << " id: " << id; + out << " raddr: " << inet_ntoa(pca.addr.sin_addr); + out << ":" << ntohs(pca.addr.sin_port); + out << " type: " << pca.type; + out << " delay: " << pca.delay; + out << " period: " << pca.period; + out << " ts: " << pca.ts; + out << " source: " << source; + rslog(RSL_WARNING, p3connectzone, out.str()); + } it->second.connAddrs.push_back(pca); } @@ -1808,6 +1873,16 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd std::cerr << " source: " << source; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerConnectRequest()"; + out << " id: " << id; + out << " raddr: " << inet_ntoa(raddr.sin_addr); + out << ":" << ntohs(raddr.sin_port); + out << " source: " << source; + rslog(RSL_WARNING, p3connectzone, out.str()); + } /******************** TCP PART *****************************/ @@ -1910,6 +1985,20 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd pca.addr = raddr; + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::peerConnectRequest() PushBack UDP Address: "; + out << " id: " << id; + out << " raddr: " << inet_ntoa(pca.addr.sin_addr); + out << ":" << ntohs(pca.addr.sin_port); + out << " type: " << pca.type; + out << " delay: " << pca.delay; + out << " period: " << pca.period; + out << " ts: " << pca.ts; + rslog(RSL_WARNING, p3connectzone, out.str()); + } + /* push to the back ... TCP ones should be tried first */ it->second.connAddrs.push_back(pca); } @@ -2270,7 +2359,21 @@ bool p3ConnectMgr::retryConnectTCP(std::string id) pca.ts = now; pca.type = RS_NET_CONN_TCP_LOCAL; pca.addr = it->second.localaddr; - + + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::retryConnectTCP() PushBack Local TCP Address: "; + out << " id: " << id; + out << " raddr: " << inet_ntoa(pca.addr.sin_addr); + out << ":" << ntohs(pca.addr.sin_port); + out << " type: " << pca.type; + out << " delay: " << pca.delay; + out << " period: " << pca.period; + out << " ts: " << pca.ts; + rslog(RSL_WARNING, p3connectzone, out.str()); + } + it->second.connAddrs.push_back(pca); } else @@ -2328,6 +2431,20 @@ bool p3ConnectMgr::retryConnectTCP(std::string id) pca.type = RS_NET_CONN_TCP_EXTERNAL; pca.addr = it->second.serveraddr; + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::retryConnectTCP() PushBack Ext TCP Address: "; + out << " id: " << id; + out << " raddr: " << inet_ntoa(pca.addr.sin_addr); + out << ":" << ntohs(pca.addr.sin_port); + out << " type: " << pca.type; + out << " delay: " << pca.delay; + out << " period: " << pca.period; + out << " ts: " << pca.ts; + rslog(RSL_WARNING, p3connectzone, out.str()); + } + it->second.connAddrs.push_back(pca); } else @@ -2425,6 +2542,13 @@ bool p3ConnectMgr::retryConnectNotify(std::string id) std::cerr << " id: " << id; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3ConnectMgr::retryConnectNotify() Notifying Peer"; + out << " id: " << id; + rslog(RSL_WARNING, p3connectzone, out.str()); + } /* attempt UDP connection */ mDhtMgr->notifyPeer(id); diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 2d377d193..a3d66c7f8 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -30,6 +30,8 @@ #include #include "util/rsprint.h" +#include "util/rsdebug.h" +const int p3dhtzone = 3892; /***** * #define DHT_DEBUG 1 @@ -193,6 +195,18 @@ bool p3DhtMgr::setExternalInterface( std::cerr << std::endl; #endif + /* Log External Interface too */ + std::ostringstream out; + out << "p3DhtMgr::setExternalInterface()"; + out << " laddr: " << inet_ntoa(ownEntry.laddr.sin_addr); + out << " lport: " << ntohs(ownEntry.laddr.sin_port); + out << " raddr: " << inet_ntoa(ownEntry.raddr.sin_addr); + out << " rport: " << ntohs(ownEntry.raddr.sin_port); + out << " type: " << ownEntry.type; + out << " state: " << ownEntry.state; + + rslog(RSL_WARNING, p3dhtzone, out.str()); + dhtMtx.unlock(); /* UNLOCK MUTEX */ return true; @@ -293,6 +307,13 @@ bool p3DhtMgr::notifyPeer(std::string id) #ifdef DHT_DEBUG std::cerr << "p3DhtMgr::notifyPeer() TO SOON - DROPPING" << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::notifyPeer() Id: " << id; + out << " TO SOON - DROPPING"; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } return false; } @@ -305,6 +326,13 @@ bool p3DhtMgr::notifyPeer(std::string id) #ifdef DHT_DEBUG std::cerr << "p3DhtMgr::notifyPeer() PEER NOT FOUND - Trigger search" << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::notifyPeer() Id: " << id; + out << " PEER NOT FOUND - Trigger Search"; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } it->second.lastTS = 0; } @@ -566,7 +594,21 @@ int p3DhtMgr::checkOwnDHTKeys() std::cerr << " type: " << peer.type; std::cerr << std::endl; #endif - + + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::checkOwnDHTKeys() PUBLISH OWN ADDR:"; + out << " hash1: " << RsUtil::BinToHex(peer.hash1); + out << " laddr: " << inet_ntoa(peer.laddr.sin_addr); + out << " :" << ntohs(peer.laddr.sin_port); + out << " raddr: " << inet_ntoa(peer.raddr.sin_addr); + out << ":" << ntohs(peer.raddr.sin_port); + out << " type: " << peer.type; + + rslog(RSL_WARNING, p3dhtzone, out.str()); + } + /* publish own key */ if (dhtPublish(peer.hash1, peer.laddr, peer.raddr, peer.type, "")) { @@ -626,6 +668,13 @@ int p3DhtMgr::checkOwnDHTKeys() std::cerr << "p3DhtMgr::checkOwnDHTKeys() check for Notify (rep=0)"; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::checkOwnDHTKeys() Checking for NOTIFY"; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } + if (dhtSearch(peer.hash1, DHT_MODE_NOTIFY)) { dhtMtx.lock(); /* LOCK MUTEX */ @@ -805,12 +854,6 @@ int p3DhtMgr::checkNotifyDHT() if (it->second.notifyPending) { - if (it->second.state == DHT_PEER_FOUND) - { - notifyType = it->second.notifyPending; - break; - } - /* if very old drop it */ if (now - it->second.notifyTS > DHT_NOTIFY_PERIOD) { @@ -820,6 +863,12 @@ int p3DhtMgr::checkNotifyDHT() #endif it->second.notifyPending = 0; } + + if (it->second.state == DHT_PEER_FOUND) + { + notifyType = it->second.notifyPending; + break; + } } } @@ -833,6 +882,12 @@ int p3DhtMgr::checkNotifyDHT() std::cerr << "p3DhtMgr::checkNotifyDHT() Notify From: "; std::cerr << it->first << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::checkNotifyDHT() Notify Request for Known Peer: " << it->first; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } /* update timestamp */ it->second.notifyTS = now; @@ -853,6 +908,12 @@ int p3DhtMgr::checkNotifyDHT() std::cerr << "p3DhtMgr::checkNotifyDHT() Posting Active Notify"; std::cerr << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::checkNotifyDHT() POST DHT (Active Notify) for Peer: " << peer.id; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } dhtNotify(peer.hash1, own.hash2, ""); } @@ -1565,6 +1626,13 @@ bool p3DhtMgr::dhtResultNotify(std::string idhash) #ifdef DHT_DEBUG std::cerr << "p3DhtMgr::dhtResult() NOTIFY for id: " << it->first << std::endl; #endif + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::dhtResultNotify() NOTIFY from Id: " << it->first; + rslog(RSL_WARNING, p3dhtzone, out.str()); + } + /* delay callback -> if they are not found */ it->second.notifyTS = now; it->second.notifyPending = RS_CONNECT_PASSIVE; @@ -1618,6 +1686,19 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash, #endif it->second.lastTS = now; + { + /* Log */ + std::ostringstream out; + out << "p3DhtMgr::dhtSearchResult() for Id: " << it->first; + out << " laddr: " << inet_ntoa(laddr.sin_addr); + out << ":" << ntohs(laddr.sin_port); + out << " raddr: " << inet_ntoa(raddr.sin_addr); + out << ":" << ntohs(raddr.sin_port); + out << " type: " << ownEntry.type; + + rslog(RSL_WARNING, p3dhtzone, out.str()); + } + /* update info .... always */ it->second.state = DHT_PEER_FOUND; it->second.laddr = laddr; diff --git a/libretroshare/src/pqi/pqiarchive.cc b/libretroshare/src/pqi/pqiarchive.cc index 78011a4cf..bd38bb57e 100644 --- a/libretroshare/src/pqi/pqiarchive.cc +++ b/libretroshare/src/pqi/pqiarchive.cc @@ -46,7 +46,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int pqiarchivezone = 9326; diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index 844b1467e..5013b9a4e 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -29,7 +29,7 @@ #include "pqi/pqihandler.h" #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int pqihandlerzone = 34283; /**** diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc index fe89dc4f0..b940e79aa 100644 --- a/libretroshare/src/pqi/pqinetwork.cc +++ b/libretroshare/src/pqi/pqinetwork.cc @@ -32,7 +32,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include #include static const int pqinetzone = 96184; diff --git a/libretroshare/src/pqi/pqiperson.cc b/libretroshare/src/pqi/pqiperson.cc index ed81f5e34..da6c609df 100644 --- a/libretroshare/src/pqi/pqiperson.cc +++ b/libretroshare/src/pqi/pqiperson.cc @@ -28,7 +28,7 @@ #include "pqi/pqipersongrp.h" const int pqipersonzone = 82371; -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include /**** diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index 3ae6f770a..f76adb207 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -25,7 +25,7 @@ #include "pqi/pqipersongrp.h" #include "pqi/p3connmgr.h" -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include diff --git a/libretroshare/src/pqi/pqiservice.cc b/libretroshare/src/pqi/pqiservice.cc index c1dc2a73b..89b35a9d9 100644 --- a/libretroshare/src/pqi/pqiservice.cc +++ b/libretroshare/src/pqi/pqiservice.cc @@ -24,15 +24,22 @@ */ #include "pqi/pqiservice.h" -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include const int pqiservicezone = 60478; +/**** + * #define SERVICE_DEBUG 1 + ****/ + p3ServiceServer::p3ServiceServer() { + +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::p3ServiceServer()"); +#endif rrit = services.begin(); return; @@ -40,8 +47,10 @@ p3ServiceServer::p3ServiceServer() int p3ServiceServer::addService(pqiService *ts) { +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::addService()"); +#endif std::map::iterator it; it = services.find(ts -> getType()); @@ -58,6 +67,7 @@ int p3ServiceServer::addService(pqiService *ts) int p3ServiceServer::incoming(RsRawItem *item) { +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::incoming()"); @@ -73,13 +83,16 @@ int p3ServiceServer::incoming(RsRawItem *item) out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str()); } +#endif std::map::iterator it; it = services.find(item -> PacketId() & 0xffffff00); if (it == services.end()) { +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::incoming() Service: No Service - deleting"); +#endif // delete it. delete item; @@ -89,10 +102,12 @@ int p3ServiceServer::incoming(RsRawItem *item) } { +#ifdef SERVICE_DEBUG std::ostringstream out; out << "p3ServiceServer::incoming() Sending to"; out << it -> second << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str()); +#endif return (it->second) -> receive(item); } @@ -105,8 +120,11 @@ int p3ServiceServer::incoming(RsRawItem *item) RsRawItem *p3ServiceServer::outgoing() { + +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_ALL, pqiservicezone, "p3ServiceServer::outgoing()"); +#endif if (rrit != services.end()) { @@ -126,6 +144,8 @@ RsRawItem *p3ServiceServer::outgoing() { if (NULL != (item = (rrit -> second) -> send())) { + +#ifdef SERVICE_DEBUG std::ostringstream out; out << "p3ServiceServer::outgoing() Got Item From:"; out << rrit -> second << std::endl; @@ -133,6 +153,8 @@ RsRawItem *p3ServiceServer::outgoing() item -> print(out); out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str()); +#endif + return item; } } @@ -142,6 +164,8 @@ RsRawItem *p3ServiceServer::outgoing() { if (NULL != (item = (rrit -> second) -> send())) { + +#ifdef SERVICE_DEBUG std::ostringstream out; out << "p3ServiceServer::outgoing() Got Item From:"; out << rrit -> second << std::endl; @@ -149,6 +173,8 @@ RsRawItem *p3ServiceServer::outgoing() item -> print(out); out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str()); +#endif + return item; } } @@ -159,19 +185,25 @@ RsRawItem *p3ServiceServer::outgoing() int p3ServiceServer::tick() { + +#ifdef SERVICE_DEBUG pqioutput(PQL_DEBUG_ALL, pqiservicezone, "p3ServiceServer::tick()"); +#endif std::map::iterator it; // from the beginning to where we started. for(it = services.begin();it != services.end(); it++) { + +#ifdef SERVICE_DEBUG std::ostringstream out; out << "p3ServiceServer::service id:" << it -> first; out << " -> Service: " << it -> second; out << std::endl; pqioutput(PQL_DEBUG_ALL, pqiservicezone, out.str()); +#endif // now we should actually tick the service. (it -> second) -> tick(); diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index d80cf7771..c6fc68b11 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -31,11 +31,11 @@ #include "pqi/pqinetwork.h" #include "util/rsnet.h" +#include "util/rsdebug.h" #include #include -#include "pqi/pqidebug.h" #include #include "pqi/pqissllistener.h" @@ -115,15 +115,15 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3AuthMgr *am, p3ConnectM { std::ostringstream out; out << "pqissl for PeerId: " << PeerId(); - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); } if (!(mAuthMgr->isAuthenticated(PeerId()))) { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::Warning Certificate Not Approved!"); - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "\t pqissl will not initialise...."); } @@ -133,7 +133,7 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3AuthMgr *am, p3ConnectM pqissl::~pqissl() { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::~pqissl -> destroying pqissl"); stoplistening(); /* remove from pqissllistener only */ reset(); @@ -187,6 +187,7 @@ int pqissl::close() int pqissl::reset() { std::ostringstream out; + std::ostringstream outAlert; /* a reset shouldn't cause us to stop listening * only reasons for stoplistening() are; @@ -197,7 +198,9 @@ int pqissl::reset() * */ - out << "pqissl::reset():" << PeerId() << std::endl; + outAlert << "pqissl::reset():" << PeerId(); + rslog(RSL_ALERT, pqisslzone, outAlert.str()); + out << "pqissl::reset() State Before Reset:" << std::endl; out << "\tActive: " << (int) active << std::endl; @@ -240,7 +243,7 @@ int pqissl::reset() } out << "pqissl::reset() Complete!" << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); // notify people of problem! // but only if we really shut something down. @@ -257,16 +260,31 @@ int pqissl::reset() bool pqissl::connect_parameter(uint32_t type, uint32_t value) { - //std::cerr << "pqissl::connect_parameter() type: " << type << "value: " << value << std::endl; + { + std::ostringstream out; + out << "pqissl::connect_parameter() Peer: " << PeerId(); + out << " type: " << type << "value: " << value; + rslog(RSL_DEBUG_ALL, pqisslzone, out.str()); + } + if (type == NET_PARAM_CONNECT_DELAY) { - //std::cerr << "pqissl::connect_parameter() DELAY: " << value << std::endl; + std::ostringstream out; + out << "pqissl::connect_parameter() Peer: " << PeerId(); + out << " DELAY: " << value; + rslog(RSL_WARNING, pqisslzone, out.str()); + + mConnectDelay = value; return true; } else if (type == NET_PARAM_CONNECT_TIMEOUT) { - //std::cerr << "pqissl::connect_parameter() TIMEOUT: " << value << std::endl; + std::ostringstream out; + out << "pqissl::connect_parameter() Peer: " << PeerId(); + out << " TIMEOUT: " << value; + rslog(RSL_WARNING, pqisslzone, out.str()); + mConnectTimeout = value; return true; } @@ -315,7 +333,7 @@ int pqissl::status() out << " Waiting for connection!" << std::endl; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); if (active) { @@ -342,7 +360,7 @@ int pqissl::tick() std::ostringstream out; out << "pqissl::tick() "; out << "Continuing Connection Attempt!"; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); ConnectAttempt(); return 1; @@ -363,12 +381,12 @@ int pqissl::ConnectAttempt() sslmode = PQISSL_ACTIVE; /* we're starting this one */ - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() STATE = Not Waiting, starting connection"); case WAITING_DELAY: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() STATE = Waiting Delay, starting connection"); return Delay_Connection(); @@ -378,7 +396,7 @@ int pqissl::ConnectAttempt() case WAITING_SOCK_CONNECT: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() STATE = Waiting Sock Connect"); return Initiate_SSL_Connection(); @@ -386,7 +404,7 @@ int pqissl::ConnectAttempt() case WAITING_SSL_CONNECTION: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() STATE = Waiting SSL Connection"); return Authorise_SSL_Connection(); @@ -394,14 +412,14 @@ int pqissl::ConnectAttempt() case WAITING_SSL_AUTHORISE: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() STATE = Waiting SSL Authorise"); return Authorise_SSL_Connection(); break; case WAITING_FAIL_INTERFACE: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() Failed - Retrying"); return Failed_Connection(); @@ -409,13 +427,13 @@ int pqissl::ConnectAttempt() default: - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::ConnectAttempt() STATE = Unknown - Reset"); reset(); break; } - pqioutput(PQL_ALERT, pqisslzone, "pqissl::ConnectAttempt() Unknown"); + rslog(RSL_ALERT, pqisslzone, "pqissl::ConnectAttempt() Unknown"); return -1; } @@ -435,7 +453,7 @@ int pqissl::ConnectAttempt() int pqissl::Failed_Connection() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::ConnectAttempt() Failed - Notifying"); if (parent()) @@ -461,7 +479,7 @@ int pqissl::Failed_Connection() int pqissl::Delay_Connection() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Delay_Connection() Attempting Outgoing Connection...."); if (waiting == WAITING_NOT) @@ -483,7 +501,7 @@ int pqissl::Delay_Connection() out << PeerId() << " for "; out << mConnectDelay; out << " seconds"; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); } @@ -499,7 +517,7 @@ int pqissl::Delay_Connection() out << PeerId() << " starting in "; out << mConnectTS - time(NULL); out << " seconds"; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); } if (time(NULL) > mConnectTS) @@ -509,7 +527,7 @@ int pqissl::Delay_Connection() return 0; } - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Already Attempt in Progress!"); return -1; } @@ -520,17 +538,17 @@ int pqissl::Initiate_Connection() int err; struct sockaddr_in addr = remote_addr; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_Connection() Attempting Outgoing Connection...."); if (waiting != WAITING_DELAY) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Already Attempt in Progress!"); return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_Connection() Opening Socket"); // open socket connection to addr. @@ -539,7 +557,7 @@ int pqissl::Initiate_Connection() { std::ostringstream out; out << "pqissl::Initiate_Connection() osock = " << osock; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); } if (osock < 0) @@ -548,14 +566,14 @@ int pqissl::Initiate_Connection() out << "pqissl::Initiate_Connection()"; out << "Failed to open socket!" << std::endl; out << "Socket Error:" << socket_errorType(errno) << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); net_internal_close(osock); waiting = WAITING_FAIL_INTERFACE; return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_Connection() Making Non-Blocking"); err = unix_fcntl_nonblock(osock); @@ -565,20 +583,21 @@ int pqissl::Initiate_Connection() out << "pqissl::Initiate_Connection()"; out << "Error: Cannot make socket NON-Blocking: "; out << err << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); waiting = WAITING_FAIL_INTERFACE; net_internal_close(osock); return -1; } - - { + { std::ostringstream out; out << "pqissl::Initiate_Connection() "; - out << "Connecting To: " << inet_ntoa(addr.sin_addr) << ":"; - out << ntohs(addr.sin_port) << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + out << "Connecting To: "; + out << PeerId() << " via: "; + out << inet_ntoa(addr.sin_addr); + out << ":" << ntohs(addr.sin_port); + rslog(RSL_WARNING, pqisslzone, out.str()); } if (addr.sin_addr.s_addr == 0) @@ -588,20 +607,12 @@ int pqissl::Initiate_Connection() out << "Invalid (0.0.0.0) Remote Address,"; out << " Aborting Connect."; out << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); waiting = WAITING_FAIL_INTERFACE; net_internal_close(osock); return -1; } - { - std::ostringstream out; - out << "Connecting to "; - out << PeerId() << " via "; - out << inet_ntoa(addr.sin_addr); - out << ":" << ntohs(addr.sin_port); - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); - } mTimeoutTS = time(NULL) + mConnectTimeout; //std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl; @@ -620,14 +631,14 @@ int pqissl::Initiate_Connection() sockfd = osock; out << " EINPROGRESS Waiting for Socket Connection"; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); return 0; } else if ((errno == ENETUNREACH) || (errno == ETIMEDOUT)) { - out << "ENETUNREACHABLE: cert" << PeerId(); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + out << "ENETUNREACHABLE: cert: " << PeerId(); + rslog(RSL_WARNING, pqisslzone, out.str()); // Then send unreachable message. net_internal_close(osock); @@ -653,7 +664,7 @@ int pqissl::Initiate_Connection() osock=-1; waiting = WAITING_FAIL_INTERFACE; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); // extra output for the moment. //std::cerr << out.str(); @@ -661,14 +672,14 @@ int pqissl::Initiate_Connection() } else { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Init_Connection() connect returned 0"); } waiting = WAITING_SOCK_CONNECT; sockfd = osock; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_Connection() Waiting for Socket Connect"); return 1; @@ -691,20 +702,20 @@ int pqissl::Initiate_Connection() int pqissl::Basic_Connection_Complete() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete()..."); /* new TimeOut code. */ if (time(NULL) > mTimeoutTS) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, - "pqissl::Basic_Connection_Complete() Connection Timed Out!"); + std::ostringstream out; + out << "pqissl::Basic_Connection_Complete() Connection Timed Out. "; + out << "Peer: " << PeerId() << " Period: "; + out << mConnectTimeout; + + rslog(RSL_WARNING, pqisslzone, out.str()); /* as sockfd is valid, this should close it all up */ - //std::cerr << "pqissl::Basic_Connection_Complete() Connection Timed Out!"; - //std::cerr << std::endl; - //std::cerr << "pqissl::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout; - //std::cerr << std::endl; reset(); return -1; } @@ -712,7 +723,7 @@ int pqissl::Basic_Connection_Complete() if (waiting != WAITING_SOCK_CONNECT) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Wrong Mode"); return -1; } @@ -732,7 +743,7 @@ int pqissl::Basic_Connection_Complete() timeout.tv_sec = 0; timeout.tv_usec = 0; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Selecting ...."); int sr = 0; @@ -740,7 +751,7 @@ int pqissl::Basic_Connection_Complete() &ReadFDs, &WriteFDs, &ExceptFDs, &timeout))) { // select error. - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() Select ERROR(1)"); net_internal_close(sockfd); @@ -754,7 +765,7 @@ int pqissl::Basic_Connection_Complete() std::ostringstream out; out << "pqissl::Basic_Connection_Complete() Select "; out << " returned " << sr; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); } @@ -763,7 +774,7 @@ int pqissl::Basic_Connection_Complete() // error - reset socket. // this is a definite bad socket!. - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() Select ERROR(2)"); net_internal_close(sockfd); @@ -775,26 +786,26 @@ int pqissl::Basic_Connection_Complete() if (FD_ISSET(sockfd, &WriteFDs)) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Can Write!"); } else { - // not ready return -1; - pqioutput(PQL_WARNING, pqisslzone, + // happens frequently so switched to debug msg. + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Not Yet Ready!"); return 0; } if (FD_ISSET(sockfd, &ReadFDs)) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Can Read!"); } else { // not ready return -1; - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() Cannot Read!"); } @@ -807,10 +818,10 @@ int pqissl::Basic_Connection_Complete() { std::ostringstream out; out << "pqissl::Basic_Connection_Complete()"; - out << "TCP Connection Complete: cert: "; + out << " TCP Connection Complete: cert: "; out << PeerId(); out << " on osock: " << sockfd; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); } return 1; } @@ -819,8 +830,8 @@ int pqissl::Basic_Connection_Complete() std::ostringstream out; out << "pqissl::Basic_Connection_Complete()"; - out << "EINPROGRESS: cert" << PeerId(); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + out << " EINPROGRESS: cert: " << PeerId(); + rslog(RSL_WARNING, pqisslzone, out.str()); return 0; } @@ -828,9 +839,9 @@ int pqissl::Basic_Connection_Complete() { std::ostringstream out; out << "pqissl::Basic_Connection_Complete()"; - out << "ENETUNREACH/ETIMEDOUT: cert"; + out << " ENETUNREACH/ETIMEDOUT: cert: "; out << PeerId(); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); // Then send unreachable message. net_internal_close(sockfd); @@ -847,9 +858,9 @@ int pqissl::Basic_Connection_Complete() { std::ostringstream out; out << "pqissl::Basic_Connection_Complete()"; - out << "EHOSTUNREACH/EHOSTDOWN: cert"; + out << " EHOSTUNREACH/EHOSTDOWN: cert: "; out << PeerId(); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); // Then send unreachable message. net_internal_close(sockfd); @@ -863,9 +874,9 @@ int pqissl::Basic_Connection_Complete() { std::ostringstream out; out << "pqissl::Basic_Connection_Complete()"; - out << "ECONNREFUSED: cert"; + out << " ECONNREFUSED: cert: "; out << PeerId(); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); // Then send unreachable message. net_internal_close(sockfd); @@ -879,7 +890,7 @@ int pqissl::Basic_Connection_Complete() std::ostringstream out; out << "Error: Connection Failed UNKNOWN ERROR: " << err; out << " - " << socket_errorType(err); - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); net_internal_close(sockfd); sockfd=-1; @@ -887,7 +898,7 @@ int pqissl::Basic_Connection_Complete() return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Basic_Connection_Complete() BAD GETSOCKOPT!"); waiting = WAITING_FAIL_INTERFACE; @@ -899,7 +910,7 @@ int pqissl::Initiate_SSL_Connection() { int err; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_SSL_Connection() Checking Basic Connection"); if (0 >= (err = Basic_Connection_Complete())) @@ -907,7 +918,7 @@ int pqissl::Initiate_SSL_Connection() return err; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_SSL_Connection() Basic Connection Okay"); // setup timeout value. @@ -918,14 +929,14 @@ int pqissl::Initiate_SSL_Connection() SSL *ssl = SSL_new(mAuthMgr->getCTX()); if (ssl == NULL) { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::Initiate_SSL_Connection() SSL_new failed!"); exit(1); return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_SSL_Connection() SSL Connection Okay"); ssl_connection = ssl; @@ -939,10 +950,10 @@ int pqissl::Initiate_SSL_Connection() printSSLError(ssl, err, SSL_get_error(ssl, err), ERR_get_error(), out); - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Initiate_SSL_Connection() Waiting for SSL Connection"); waiting = WAITING_SSL_CONNECTION; @@ -951,25 +962,25 @@ int pqissl::Initiate_SSL_Connection() int pqissl::SSL_Connection_Complete() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::SSL_Connection_Complete()??? ... Checking"); if (waiting == WAITING_SSL_AUTHORISE) { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::SSL_Connection_Complete() Waiting = W_SSL_AUTH"); return 1; } if (waiting != WAITING_SSL_CONNECTION) { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::SSL_Connection_Complete() Still Waiting.."); return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::SSL_Connection_Complete() Attempting SSL_connect"); /* if we are passive - then accept! */ @@ -977,12 +988,12 @@ int pqissl::SSL_Connection_Complete() if (sslmode) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, "--------> Active Connect!"); + rslog(RSL_DEBUG_BASIC, pqisslzone, "--------> Active Connect!"); err = SSL_connect(ssl_connection); } else { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, "--------> Passive Accept!"); + rslog(RSL_DEBUG_BASIC, pqisslzone, "--------> Passive Accept!"); err = SSL_accept(ssl_connection); } @@ -992,7 +1003,7 @@ int pqissl::SSL_Connection_Complete() if ((serr == SSL_ERROR_WANT_READ) || (serr == SSL_ERROR_WANT_WRITE)) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "Waiting for SSL handshake!"); waiting = WAITING_SSL_CONNECTION; @@ -1006,7 +1017,7 @@ int pqissl::SSL_Connection_Complete() printSSLError(ssl_connection, err, serr, ERR_get_error(), out); - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, out.str()); // attempt real error. @@ -1018,9 +1029,12 @@ int pqissl::SSL_Connection_Complete() return -1; } // if we get here... success v quickly. - - pqioutput(PQL_WARNING, pqisslzone, - "\tAttempted Connect... Success!"); + + { + std::ostringstream out; + out << "pqissl::SSL_Connection_Complete() Success!: Peer: " << PeerId(); + rslog(RSL_WARNING, pqisslzone, out.str()); + } waiting = WAITING_SSL_AUTHORISE; return 1; @@ -1028,7 +1042,7 @@ int pqissl::SSL_Connection_Complete() int pqissl::Extract_Failed_SSL_Certificate() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Extract_Failed_SSL_Certificate()"); // Get the Peer Certificate.... @@ -1043,12 +1057,12 @@ int pqissl::Extract_Failed_SSL_Certificate() if (peercert == NULL) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Extract_Failed_SSL_Certificate() Peer Didnt Give Cert"); return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Extract_Failed_SSL_Certificate() Have Peer Cert - Registering"); // save certificate... (and ip locations) @@ -1072,14 +1086,14 @@ int pqissl::Extract_Failed_SSL_Certificate() int pqissl::Authorise_SSL_Connection() { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Authorise_SSL_Connection()"); ssl_connect_timeout = time(NULL) + PQISSL_SSL_CONNECT_TIMEOUT; if (time(NULL) > ssl_connect_timeout) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, - "pqissl::Authorise_SSL_Connection() Connectoin Timed Out!"); + rslog(RSL_DEBUG_BASIC, pqisslzone, + "pqissl::Authorise_SSL_Connection() Connection Timed Out!"); /* as sockfd is valid, this should close it all up */ reset(); } @@ -1090,7 +1104,7 @@ int pqissl::Authorise_SSL_Connection() return err; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Authorise_SSL_Connection() SSL_Connection_Complete"); // reset switch. @@ -1110,7 +1124,7 @@ int pqissl::Authorise_SSL_Connection() if (peercert == NULL) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::Authorise_SSL_Connection() Peer Didnt Give Cert"); // Failed completely @@ -1118,7 +1132,7 @@ int pqissl::Authorise_SSL_Connection() return -1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::Authorise_SSL_Connection() Have Peer Cert"); // save certificate... (and ip locations) @@ -1141,15 +1155,20 @@ int pqissl::Authorise_SSL_Connection() if (certCorrect) { // then okay... - pqioutput(PQL_DEBUG_BASIC, pqisslzone, - "pqissl::Authorise_SSL_Connection() Accepting Conn"); + std::ostringstream out; + out << "pqissl::Authorise_SSL_Connection() Accepting Conn. Peer: " << PeerId(); + rslog(RSL_WARNING, pqisslzone, out.str()); accept(ssl_connection, sockfd, remote_addr); return 1; } - pqioutput(PQL_DEBUG_BASIC, pqisslzone, - "pqissl::Authorise_SSL_Connection() Something Wrong ... Shutdown "); + { + std::ostringstream out; + out << "pqissl::Authorise_SSL_Connection() Something Wrong ... "; + out << " Shutdown. Peer: " << PeerId(); + rslog(RSL_WARNING, pqisslzone, out.str()); + } // else shutdown ssl connection. @@ -1161,7 +1180,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat { if (waiting != WAITING_NOT) { - pqioutput(PQL_WARNING, pqisslzone, + rslog(RSL_WARNING, pqisslzone, "pqissl::accept() - Two connections in progress - Shut 1 down!"); // outgoing connection in progress. @@ -1176,35 +1195,35 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat case WAITING_SOCK_CONNECT: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() STATE = Waiting Sock Connect - close the socket"); break; case WAITING_SSL_CONNECTION: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() STATE = Waiting SSL Connection - close sockfd + ssl_conn"); break; case WAITING_SSL_AUTHORISE: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() STATE = Waiting SSL Authorise - close sockfd + ssl_conn"); break; case WAITING_FAIL_INTERFACE: - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() STATE = Failed, ignore?"); break; default: - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::accept() STATE = Unknown - ignore?"); reset(); @@ -1218,14 +1237,14 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat /* shutdown existing - in all cases use the new one */ if ((ssl_connection) && (ssl_connection != ssl)) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() closing Previous/Existing ssl_connection"); SSL_shutdown(ssl_connection); } if ((sockfd > -1) && (sockfd != fd)) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() closing Previous/Existing sockfd"); net_internal_close(sockfd); } @@ -1249,7 +1268,9 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat { std::ostringstream out; - out << "pqissl::accept() checking for same LAN"; + out << "pqissl::accept() Successful connection with: " << PeerId(); + out << std::endl; + out << "\t\tchecking for same LAN"; out << std::endl; out << "\t localaddr: " << inet_ntoa(details.localaddr.sin_addr); out << std::endl; @@ -1265,7 +1286,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat } out << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); } // establish the ssl details. @@ -1279,13 +1300,13 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat out << "SSL Cipher Bits:" << SSL_get_cipher_bits(ssl, &alg); out << " - " << alg << std::endl; out << "SSL Cipher Version:" << SSL_get_cipher_version(ssl) << std::endl; - pqioutput(PQL_DEBUG_BASIC, pqisslzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); } // make non-blocking / or check..... if ((err = net_internal_fcntl_nonblock(sockfd)) < 0) { - pqioutput(PQL_ALERT, pqisslzone, "Error: Cannot make socket NON-Blocking: "); + rslog(RSL_ALERT, pqisslzone, "Error: Cannot make socket NON-Blocking: "); active = false; waiting = WAITING_FAIL_INTERFACE; @@ -1295,11 +1316,10 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat } else { - pqioutput(PQL_ALERT, pqisslzone, "pqissl::accept() Socket Made Non-Blocking!"); + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::accept() Socket Made Non-Blocking!"); } - // remove form listening set. - // no - we want to continue listening - incase this socket is crap, and they try again. + // we want to continue listening - incase this socket is crap, and they try again. //stoplistening(); active = true; @@ -1338,7 +1358,7 @@ int pqissl::senddata(void *data, int len) out << std::endl; out << "Socket Closed Abruptly.... Resetting PQIssl"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); reset(); return -1; } @@ -1346,14 +1366,14 @@ int pqissl::senddata(void *data, int len) { out << "SSL_write() SSL_ERROR_WANT_WRITE"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); return -1; } else if (err == SSL_ERROR_WANT_READ) { out << "SSL_write() SSL_ERROR_WANT_READ"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); return -1; } else @@ -1364,7 +1384,7 @@ int pqissl::senddata(void *data, int len) out << std::endl; out << "\tResetting!"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); reset(); return -1; @@ -1383,7 +1403,7 @@ int pqissl::readdata(void *data, int len) out << " Full Packet Not read!" << std::endl; out << " -> Expected len(" << len << ") actually read("; out << tmppktlen << ")" << std::endl; - pqioutput(PQL_WARNING, pqisslzone, out.str()); + rslog(RSL_WARNING, pqisslzone, out.str()); } // need to catch errors..... if (tmppktlen <= 0) // probably needs a reset. @@ -1424,7 +1444,7 @@ int pqissl::readdata(void *data, int len) reset(); } - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); return 0; } @@ -1435,7 +1455,7 @@ int pqissl::readdata(void *data, int len) out << std::endl; out << "Socket Closed Abruptly.... Resetting PQIssl"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); reset(); return -1; } @@ -1443,14 +1463,14 @@ int pqissl::readdata(void *data, int len) { out << "SSL_read() SSL_ERROR_WANT_WRITE"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); return -1; } else if (error == SSL_ERROR_WANT_READ) { out << "SSL_read() SSL_ERROR_WANT_READ"; out << std::endl; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); return -1; } else @@ -1458,12 +1478,12 @@ int pqissl::readdata(void *data, int len) out << "SSL_read() UNKNOWN ERROR: " << error; out << std::endl; out << "\tResetting!"; - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); reset(); return -1; } - pqioutput(PQL_ALERT, pqisslzone, out.str()); + rslog(RSL_ALERT, pqisslzone, out.str()); //exit(1); } n_read_zero = 0; @@ -1493,7 +1513,7 @@ bool pqissl::moretoread() std::ostringstream out; out << "pqissl::moretoread()"; out << " polling socket (" << sockfd << ")"; - pqioutput(PQL_DEBUG_ALL, pqisslzone, out.str()); + rslog(RSL_DEBUG_ALL, pqisslzone, out.str()); } fd_set ReadFDs, WriteFDs, ExceptFDs; @@ -1511,7 +1531,7 @@ bool pqissl::moretoread() if (select(sockfd + 1, &ReadFDs, &WriteFDs, &ExceptFDs, &timeout) < 0) { - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::moretoread() Select ERROR!"); return 0; } @@ -1519,7 +1539,7 @@ bool pqissl::moretoread() if (FD_ISSET(sockfd, &ExceptFDs)) { // error - reset socket. - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::moretoread() Select Exception ERROR!"); // this is a definite bad socket!. @@ -1531,25 +1551,25 @@ bool pqissl::moretoread() if (FD_ISSET(sockfd, &WriteFDs)) { // write can work. - pqioutput(PQL_DEBUG_ALL, pqisslzone, + rslog(RSL_DEBUG_ALL, pqisslzone, "pqissl::moretoread() Can Write!"); } else { // write can work. - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::moretoread() Can *NOT* Write!"); } if (FD_ISSET(sockfd, &ReadFDs)) { - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::moretoread() Data to Read!"); return 1; } else { - pqioutput(PQL_DEBUG_ALL, pqisslzone, + rslog(RSL_DEBUG_ALL, pqisslzone, "pqissl::moretoread() No Data to Read!"); return 0; } @@ -1558,7 +1578,7 @@ bool pqissl::moretoread() bool pqissl::cansend() { - pqioutput(PQL_DEBUG_ALL, pqisslzone, + rslog(RSL_DEBUG_ALL, pqisslzone, "pqissl::cansend() polling socket!"); // Interestingly - This code might be portable.... @@ -1579,7 +1599,7 @@ bool pqissl::cansend() if (select(sockfd + 1, &ReadFDs, &WriteFDs, &ExceptFDs, &timeout) < 0) { // select error. - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::cansend() Select Error!"); return 0; @@ -1588,7 +1608,7 @@ bool pqissl::cansend() if (FD_ISSET(sockfd, &ExceptFDs)) { // error - reset socket. - pqioutput(PQL_ALERT, pqisslzone, + rslog(RSL_ALERT, pqisslzone, "pqissl::cansend() Select Exception!"); // this is a definite bad socket!. @@ -1600,14 +1620,14 @@ bool pqissl::cansend() if (FD_ISSET(sockfd, &WriteFDs)) { // write can work. - pqioutput(PQL_DEBUG_ALL, pqisslzone, + rslog(RSL_DEBUG_ALL, pqisslzone, "pqissl::cansend() Can Write!"); return 1; } else { // write can work. - pqioutput(PQL_DEBUG_BASIC, pqisslzone, + rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::cansend() Can *NOT* Write!"); return 0; diff --git a/libretroshare/src/pqi/pqissllistener.cc b/libretroshare/src/pqi/pqissllistener.cc index 6a31cefef..4f4370564 100644 --- a/libretroshare/src/pqi/pqissllistener.cc +++ b/libretroshare/src/pqi/pqissllistener.cc @@ -34,7 +34,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include const int pqissllistenzone = 49787; diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index 911cb64d0..8dda2ae14 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -23,11 +23,13 @@ * */ +#include + +#include "util/rsdebug.h" + #include "pqi/pqisslpersongrp.h" -#include "pqi/pqidebug.h" #include "pqi/p3authmgr.h" -#include const int pqipersongrpzone = 354; diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index 0a280e346..a97276534 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -36,9 +36,9 @@ #include #include -#include "pqi/pqidebug.h" #include +#include "util/rsdebug.h" #include "util/rsnet.h" const int pqissludpzone = 3144; @@ -63,7 +63,7 @@ pqissludp::pqissludp(PQInterface *parent, p3AuthMgr *am, p3ConnectMgr *cm) pqissludp::~pqissludp() { - pqioutput(PQL_ALERT, pqissludpzone, + rslog(RSL_ALERT, pqissludpzone, "pqissludp::~pqissludp -> destroying pqissludp"); /* must call reset from here, so that the @@ -102,13 +102,13 @@ int pqissludp::attach() sockfd = tou_socket(0,0,0); if (0 > sockfd) { - pqioutput(PQL_WARNING, pqissludpzone, + rslog(RSL_WARNING, pqissludpzone, "pqissludp::attach() failed to create a socket"); return -1; } // setup remote address - pqioutput(PQL_WARNING, pqissludpzone, + rslog(RSL_WARNING, pqissludpzone, "pqissludp::attach() Opened Local Udp Socket"); return 1; @@ -123,7 +123,7 @@ int pqissludp::Initiate_Connection() attach(); /* open socket */ remote_addr.sin_family = AF_INET; - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Initiate_Connection() Attempting Outgoing Connection...."); /* decide if we're active or passive */ @@ -138,29 +138,37 @@ int pqissludp::Initiate_Connection() if (waiting != WAITING_DELAY) { - pqioutput(PQL_WARNING, pqissludpzone, + rslog(RSL_WARNING, pqissludpzone, "pqissludp::Initiate_Connection() Already Attempt in Progress!"); return -1; } - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + if (sockfd < 0) + { + rslog(RSL_ALERT, pqissludpzone, + "pqissludp::Initiate_Connection() Socket Creation Failed!"); + waiting = WAITING_FAIL_INTERFACE; + return -1; + } + + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Initiate_Connection() Opening Socket"); { std::ostringstream out; out << "pqissludp::Initiate_Connection() "; - out << "Connecting To: " << inet_ntoa(remote_addr.sin_addr) << ":"; - out << ntohs(remote_addr.sin_port) << std::endl; + out << "Connecting To: " << PeerId(); + out << " via: " << inet_ntoa(remote_addr.sin_addr) << ":"; + out << ntohs(remote_addr.sin_port) << " "; if (sslmode) { - out << "Using ACTIVE Connect Mode (SSL_Connect)"; + out << "ACTIVE Connect (SSL_Connect)"; } else { - out << "Using PASSIVE Connect Mode (SSL_Accept)"; + out << "PASSIVE Connect (SSL_Accept)"; } - out << std::endl; - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); } if (remote_addr.sin_addr.s_addr == 0) @@ -170,25 +178,16 @@ int pqissludp::Initiate_Connection() out << "Invalid (0.0.0.0) Remote Address,"; out << " Aborting Connect."; out << std::endl; - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); waiting = WAITING_FAIL_INTERFACE; reset(); return -1; } - { - std::ostringstream out; - out << "Connecting to "; - out << PeerId() << " via "; - out << inet_ntoa(remote_addr.sin_addr); - out << ":" << ntohs(remote_addr.sin_port); - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, out.str()); - } - mTimeoutTS = time(NULL) + mConnectTimeout; - std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl; - std::cerr << " Connect Period is:" << mConnectPeriod << std::endl; + //std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl; + //std::cerr << " Connect Period is:" << mConnectPeriod << std::endl; /* <===================== UDP Difference *******************/ if (0 != (err = tou_connect(sockfd, (struct sockaddr *) &remote_addr, @@ -196,9 +195,6 @@ int pqissludp::Initiate_Connection() /* <===================== UDP Difference *******************/ { int tou_err = tou_errno(sockfd); - std::cerr << "pqissludp::Initiate_Connection() connect returns:"; - std::cerr << err << " -> errno: " << tou_err << " error: "; - std::cerr << socket_errorType(tou_err) << std::endl; std::ostringstream out; out << "pqissludp::Initiate_Connection()"; @@ -209,13 +205,13 @@ int pqissludp::Initiate_Connection() waiting = WAITING_SOCK_CONNECT; out << " EINPROGRESS Waiting for Socket Connection"; - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); return 0; } else if ((tou_err == ENETUNREACH) || (tou_err == ETIMEDOUT)) { - out << "ENETUNREACHABLE: cert" << PeerId(); + out << "ENETUNREACHABLE: cert: " << PeerId(); out << std::endl; // Then send unreachable message. @@ -226,20 +222,21 @@ int pqissludp::Initiate_Connection() out << "Error: Connection Failed: " << tou_err; out << " - " << socket_errorType(tou_err) << std::endl; + rslog(RSL_WARNING, pqissludpzone, out.str()); + reset(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); return -1; } else { - pqioutput(PQL_WARNING, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Init_Connection() connect returned 0"); } waiting = WAITING_SOCK_CONNECT; - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Initiate_Connection() Waiting for Socket Connect"); return 1; @@ -248,20 +245,21 @@ int pqissludp::Initiate_Connection() /********* VERY DIFFERENT **********/ int pqissludp::Basic_Connection_Complete() { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Basic_Connection_Complete()..."); if (time(NULL) > mTimeoutTS) { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, - "pqissludp::Basic_Connection_Complete() Connection Timed Out!"); + std::ostringstream out; + out << "pqissludp::Basic_Connection_Complete() Connection Timed Out. "; + out << "Peer: " << PeerId() << " Period: "; + out << mConnectTimeout; + + rslog(RSL_WARNING, pqissludpzone, out.str()); + /* as sockfd is valid, this should close it all up */ - std::cerr << "pqissludp::Basic_Connection_Complete() Connection Timed Out!"; - std::cerr << std::endl; - std::cerr << "pqissludp::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout; - std::cerr << std::endl; reset(); return -1; } @@ -269,14 +267,12 @@ int pqissludp::Basic_Connection_Complete() if (waiting != WAITING_SOCK_CONNECT) { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Basic_Connection_Complete() Wrong Mode"); return -1; } - - /* new approach is to check for an error */ /* check for an error */ int err; @@ -286,17 +282,25 @@ int pqissludp::Basic_Connection_Complete() { std::ostringstream out; - out << "pqissludp::Basic_Connection_Complete()"; - out << "EINPROGRESS: cert" << PeerId(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + out << "pqissludp::Basic_Connection_Complete() "; + out << "EINPROGRESS: cert: " << PeerId(); + rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str()); } else if ((err == ENETUNREACH) || (err == ETIMEDOUT)) { std::ostringstream out; - out << "pqissludp::Basic_Connection_Complete()"; - out << "ENETUNREACH/ETIMEDOUT: cert"; - out << PeerId() << std::endl; + out << "pqissludp::Basic_Connection_Complete() "; + out << "ENETUNREACH/ETIMEDOUT: cert: "; + out << PeerId(); + rslog(RSL_WARNING, pqissludpzone, out.str()); + + /* is the second one needed? */ + std::ostringstream out2; + out2 << "pqissludp::Basic_Connection_Complete() "; + out2 << "Error: Connection Failed: " << err; + out2 << " - " << socket_errorType(err); + rslog(RSL_DEBUG_BASIC, pqissludpzone, out2.str()); net_unreachable |= net_attempt; @@ -305,10 +309,6 @@ int pqissludp::Basic_Connection_Complete() // Then send unreachable message. waiting = WAITING_FAIL_INTERFACE; - out << "pqissludp::Basic_Connection_Complete()"; - out << "Error: Connection Failed: " << err; - out << " - " << socket_errorType(err); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); return -1; } } @@ -317,14 +317,18 @@ int pqissludp::Basic_Connection_Complete() if (tou_connected(sockfd)) /* <===================== UDP Difference *******************/ { - pqioutput(PQL_WARNING, pqissludpzone, - "pqissludp::Basic_Connection_Complete() Connection Complete!"); + std::ostringstream out; + out << "pqissludp::Basic_Connection_Complete() "; + out << "Connection Complete: cert: "; + out << PeerId(); + rslog(RSL_WARNING, pqissludpzone, out.str()); + return 1; } else { // not ready return -1; - pqioutput(PQL_WARNING, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Basic_Connection_Complete() Not Yet Ready!"); return 0; } @@ -340,7 +344,7 @@ int pqissludp::Basic_Connection_Complete() // used everywhere int pqissludp::net_internal_close(int fd) { - pqioutput(PQL_ALERT, pqissludpzone, + rslog(RSL_ALERT, pqissludpzone, "pqissludp::net_internal_close() -> tou_close()"); return tou_close(fd); } @@ -348,7 +352,7 @@ int pqissludp::net_internal_close(int fd) // install udp BIO. int pqissludp::net_internal_SSL_set_fd(SSL *ssl, int fd) { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::net_internal_SSL_set_fd()"); /* create the bio's */ @@ -362,7 +366,7 @@ int pqissludp::net_internal_SSL_set_fd(SSL *ssl, int fd) int pqissludp::net_internal_fcntl_nonblock(int fd) { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::net_internal_fcntl_nonblock()"); return 0; } @@ -383,7 +387,7 @@ int pqissludp::listen() { std::ostringstream out; out << "pqissludp::listen() (NULLOP)"; - pqioutput(PQL_ALERT, pqissludpzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str()); } return 1; //udpproxy->listen(); } @@ -393,7 +397,7 @@ int pqissludp::stoplistening() { std::ostringstream out; out << "pqissludp::stoplistening() (NULLOP)"; - pqioutput(PQL_ALERT, pqissludpzone, out.str()); + rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str()); } return 1; //udpproxy->stoplistening(); } @@ -401,10 +405,13 @@ int pqissludp::stoplistening() bool pqissludp::connect_parameter(uint32_t type, uint32_t value) { - std::cerr << "pqissludp::connect_parameter() type: " << type << "value: " << value << std::endl; + //std::cerr << "pqissludp::connect_parameter() type: " << type << "value: " << value << std::endl; if (type == NET_PARAM_CONNECT_PERIOD) { - std::cerr << "pqissludp::connect_parameter() PERIOD: " << value << std::endl; + std::ostringstream out; + out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PERIOD: " << value; + rslog(RSL_WARNING, pqissludpzone, out.str()); + mConnectPeriod = value; return true; } @@ -419,7 +426,7 @@ bool pqissludp::moretoread() std::ostringstream out; out << "pqissludp::moretoread()"; out << " polling socket (" << sockfd << ")"; - pqioutput(PQL_DEBUG_ALL, pqissludpzone, out.str()); + rslog(RSL_DEBUG_ALL, pqissludpzone, out.str()); } /* check for more to read first ... if nothing... check error @@ -428,13 +435,13 @@ bool pqissludp::moretoread() if (tou_maxread(sockfd)) /* <===================== UDP Difference *******************/ { - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::moretoread() Data to Read!"); return 1; } /* else check the error */ - pqioutput(PQL_DEBUG_ALL, pqissludpzone, + rslog(RSL_DEBUG_ALL, pqissludpzone, "pqissludp::moretoread() No Data to Read!"); int err; @@ -445,8 +452,8 @@ bool pqissludp::moretoread() std::ostringstream out; out << "pqissludp::moretoread() "; - out << "EAGAIN/EINPROGRESS: cert" << PeerId(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + out << "EAGAIN/EINPROGRESS: cert " << PeerId(); + rslog(RSL_DEBUG_BASIC, pqissludpzone, out.str()); return 0; } @@ -454,27 +461,27 @@ bool pqissludp::moretoread() { std::ostringstream out; out << "pqissludp::moretoread() "; - out << "ENETUNREACH/ETIMEDOUT: cert"; + out << "ENETUNREACH/ETIMEDOUT: cert "; out << PeerId(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); } else if (err == EBADF) { std::ostringstream out; out << "pqissludp::moretoread() "; - out << "EBADF: cert"; + out << "EBADF: cert "; out << PeerId(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); } else { std::ostringstream out; out << "pqissludp::moretoread() "; - out << " Unknown ERROR: " << err << ": cert"; + out << " Unknown ERROR: " << err << ": cert "; out << PeerId(); - pqioutput(PQL_WARNING, pqissludpzone, out.str()); + rslog(RSL_WARNING, pqissludpzone, out.str()); } @@ -483,7 +490,7 @@ bool pqissludp::moretoread() } /* otherwise - not error - strange! */ - pqioutput(PQL_DEBUG_BASIC, pqissludpzone, + rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::moretoread() No Data + No Error (really nothing)"); return 0; @@ -493,7 +500,7 @@ bool pqissludp::moretoread() bool pqissludp::cansend() { - pqioutput(PQL_DEBUG_ALL, pqissludpzone, + rslog(RSL_DEBUG_ALL, pqissludpzone, "pqissludp::cansend() polling socket!"); /* <===================== UDP Difference *******************/ diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index b4e777855..94024eae1 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -24,18 +24,18 @@ */ - - -#include "pqi/pqistreamer.h" -#include "serialiser/rsserial.h" -#include "serialiser/rsbaseitems.h" /***** For RsFileData *****/ #include #include - #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" + +#include "pqi/pqistreamer.h" #include "pqi/pqinotify.h" +#include "serialiser/rsserial.h" +#include "serialiser/rsbaseitems.h" /***** For RsFileData *****/ + + const int pqistreamerzone = 8221; const int PQISTREAM_ABS_MAX = 100000000; /* 100 MB/sec (actually per loop) */ diff --git a/libretroshare/src/rsserver/p3face-config.cc b/libretroshare/src/rsserver/p3face-config.cc index b4bf79785..c54b1879f 100644 --- a/libretroshare/src/rsserver/p3face-config.cc +++ b/libretroshare/src/rsserver/p3face-config.cc @@ -30,7 +30,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int p3facemsgzone = 11453; #include diff --git a/libretroshare/src/rsserver/p3face-file.cc b/libretroshare/src/rsserver/p3face-file.cc index 1a75fdf81..384696a97 100644 --- a/libretroshare/src/rsserver/p3face-file.cc +++ b/libretroshare/src/rsserver/p3face-file.cc @@ -34,7 +34,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int p3facefilezone = 11452; #include diff --git a/libretroshare/src/rsserver/p3face-msgs.cc b/libretroshare/src/rsserver/p3face-msgs.cc index 8bfb267fa..ee8bdf442 100644 --- a/libretroshare/src/rsserver/p3face-msgs.cc +++ b/libretroshare/src/rsserver/p3face-msgs.cc @@ -31,7 +31,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int p3facemsgzone = 11453; #include @@ -57,7 +57,7 @@ int RsServer::SetInChat(std::string id, bool in) /* friend : cha /* so we send this.... */ lockRsCore(); /* LOCK */ - std::cerr << "Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl; + //std::cerr << "Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl; std::list::iterator it; it = std::find(mInChatList.begin(), mInChatList.end(), id); if (it == mInChatList.end()) @@ -98,7 +98,7 @@ int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs /* so we send this.... */ lockRsCore(); /* LOCK */ - std::cerr << "Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl; + //std::cerr << "Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl; std::list::iterator it; it = std::find(mInMsgList.begin(), mInMsgList.end(), id); if (it == mInMsgList.end()) @@ -207,7 +207,7 @@ int RsServer::SetInRecommend(std::string id, bool in) /* file : recom { /* set flag */ it -> inRecommend = in; - std::cerr << "Set InRecommend (" << id << ") to " << (in ? "True" : "False") << std::endl; + //std::cerr << "Set InRecommend (" << id << ") to " << (in ? "True" : "False") << std::endl; } } diff --git a/libretroshare/src/rsserver/p3face-network.cc b/libretroshare/src/rsserver/p3face-network.cc index 1ec5ed450..beb1e5636 100644 --- a/libretroshare/src/rsserver/p3face-network.cc +++ b/libretroshare/src/rsserver/p3face-network.cc @@ -35,7 +35,7 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include #include diff --git a/libretroshare/src/rsserver/p3face-people.cc b/libretroshare/src/rsserver/p3face-people.cc index 43fa69dfc..d2040ffa3 100644 --- a/libretroshare/src/rsserver/p3face-people.cc +++ b/libretroshare/src/rsserver/p3face-people.cc @@ -89,7 +89,7 @@ void intNotifyChangeCert(RsCertId &id) #include #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" const int fltksrvrzone = 25915; #include diff --git a/libretroshare/src/rsserver/p3face-startup.cc b/libretroshare/src/rsserver/p3face-startup.cc index 5363f6ba0..c5eb16ee0 100644 --- a/libretroshare/src/rsserver/p3face-startup.cc +++ b/libretroshare/src/rsserver/p3face-startup.cc @@ -35,8 +35,8 @@ #include "pqi/pqisslpersongrp.h" #include "pqi/pqiloopback.h" #include "pqi/p3cfgmgr.h" -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include "util/rsdir.h" #include "upnp/upnphandler.h" @@ -591,7 +591,7 @@ int RsServer::StartupRetroShare(RsInit *config) mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */ mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir, 3600 * 24 * 30); + localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0)); mCacheStrapper -> addCachePair(cp); /* end of declaration */ @@ -609,7 +609,7 @@ int RsServer::StartupRetroShare(RsInit *config) mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */ mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir, 3600 * 24 * 30); + localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0)); mCacheStrapper -> addCachePair(cp3); diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 7d8133d4e..63134d85c 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -29,14 +29,14 @@ #include #include -#include "pqi/pqidebug.h" +#include "util/rsdir.h" +#include "util/rsdebug.h" const int p3facemsgzone = 11453; #include #include #include "rsiface/rstypes.h" -#include "util/rsdir.h" #include "rsserver/p3msgs.h" #include "services/p3msgservice.h" @@ -74,8 +74,8 @@ bool p3Msgs::MessageSend(MessageInfo &info) /****************************************/ bool p3Msgs::MessageDelete(std::string mid) { - std::cerr << "p3Msgs::MessageDelete() "; - std::cerr << "mid: " << mid << std::endl; + //std::cerr << "p3Msgs::MessageDelete() "; + //std::cerr << "mid: " << mid << std::endl; mMsgSrv -> removeMsgId(mid); @@ -84,8 +84,8 @@ bool p3Msgs::MessageDelete(std::string mid) bool p3Msgs::MessageRead(std::string mid) { - std::cerr << "p3Msgs::MessageRead() "; - std::cerr << "mid: " << mid << std::endl; + //std::cerr << "p3Msgs::MessageRead() "; + //std::cerr << "mid: " << mid << std::endl; mMsgSrv -> markMsgIdRead(mid); @@ -150,14 +150,14 @@ void p3Msgs::initRsChatInfo(RsChatItem *c, ChatInfo &i) i.msg = c -> message; if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) { - std::cerr << "RsServer::initRsChatInfo() Chat Private!!!"; i.chatflags = RS_CHAT_PRIVATE; + //std::cerr << "RsServer::initRsChatInfo() Chat Private!!!"; } else { i.chatflags = RS_CHAT_PUBLIC; - std::cerr << "RsServer::initRsChatInfo() Chat Public!!!"; + //std::cerr << "RsServer::initRsChatInfo() Chat Public!!!"; } - std::cerr << std::endl; + //std::cerr << std::endl; } diff --git a/libretroshare/src/server/filedexserver.cc b/libretroshare/src/server/filedexserver.cc index 3b2c96c1c..367f4117e 100644 --- a/libretroshare/src/server/filedexserver.cc +++ b/libretroshare/src/server/filedexserver.cc @@ -29,9 +29,10 @@ #include "pqi/pqibin.h" #include "pqi/pqiarchive.h" -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include "util/rsdir.h" + #include #include diff --git a/libretroshare/src/server/ftfiler.cc b/libretroshare/src/server/ftfiler.cc index e39d3b4db..2d3e55849 100644 --- a/libretroshare/src/server/ftfiler.cc +++ b/libretroshare/src/server/ftfiler.cc @@ -28,8 +28,8 @@ #include "server/ftfiler.h" #include "util/rsdir.h" +#include "util/rsdebug.h" -#include "pqi/pqidebug.h" #include "pqi/pqinotify.h" #include diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3disc.cc index 1042855c9..7f237a0a6 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -38,7 +38,7 @@ const uint32_t AUTODISC_LDI_SUBTYPE_RPLY = 0x02; #include -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include "util/rsprint.h" const int pqidisczone = 2482; diff --git a/libretroshare/src/services/p3gamelauncher.cc b/libretroshare/src/services/p3gamelauncher.cc index d3695f504..84f9103a9 100644 --- a/libretroshare/src/services/p3gamelauncher.cc +++ b/libretroshare/src/services/p3gamelauncher.cc @@ -25,7 +25,7 @@ #include "services/p3gamelauncher.h" #include "services/p3gameservice.h" -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" #include "pqi/p3connmgr.h" #include #include diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 208b6b07d..4e4f2395f 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -26,12 +26,12 @@ #include "pqi/pqibin.h" #include "pqi/pqiarchive.h" -#include "pqi/pqidebug.h" #include "pqi/p3connmgr.h" #include "services/p3msgservice.h" #include "pqi/pqinotify.h" +#include "util/rsdebug.h" #include "util/rsdir.h" #include @@ -209,7 +209,7 @@ int p3MsgService::checkOutgoingMessages() if (toSend) { /* send msg */ - pqioutput(PQL_ALERT, msgservicezone, + pqioutput(PQL_DEBUG_BASIC, msgservicezone, "p3MsgService::checkOutGoingMessages() Sending out message"); /* remove the pending flag */ (mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING; @@ -219,7 +219,7 @@ int p3MsgService::checkOutgoingMessages() } else { - pqioutput(PQL_ALERT, msgservicezone, + pqioutput(PQL_DEBUG_BASIC, msgservicezone, "p3MsgService::checkOutGoingMessages() Delaying until available..."); } } diff --git a/libretroshare/src/services/p3service.cc b/libretroshare/src/services/p3service.cc index 66b05d316..b05b1c4da 100644 --- a/libretroshare/src/services/p3service.cc +++ b/libretroshare/src/services/p3service.cc @@ -28,7 +28,9 @@ #include #include -#define SERV_DEBUG 1 +/***** + * #define SERV_DEBUG 1 + ****/ void p3Service::addSerialType(RsSerialType *st) { diff --git a/libretroshare/src/tcponudp/tcpstream.cc b/libretroshare/src/tcponudp/tcpstream.cc index e6ba606a8..2d5f476f4 100644 --- a/libretroshare/src/tcponudp/tcpstream.cc +++ b/libretroshare/src/tcponudp/tcpstream.cc @@ -29,6 +29,7 @@ #include "tcpstream.h" #include +#include #include #include #include @@ -36,6 +37,10 @@ #include #include +/* Debugging for STATE change, and Startup SYNs */ +#include "util/rsdebug.h" +const int rstcpstreamzone = 28455; + /* * #define DEBUG_TCP_STREAM 1 @@ -158,9 +163,18 @@ int TcpStream::connect(const struct sockaddr_in &raddr, uint32_t conn_period) toSend(pkt); /* change state */ state = TCP_SYN_SENT; - std::cerr << "TcpStream STATE -> TCP_SYN_SENT" << std::endl; errorState = EAGAIN; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream STATE -> TCP_SYN_SENT" << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_SYN_SENT"; + out << " (Connect)"; + rslog(RSL_WARNING,rstcpstreamzone,out.str()); + } + tcpMtx.unlock(); /******** UNLOCK MUTEX *********/ return -1; @@ -979,6 +993,13 @@ int TcpStream::recv_check() * for max efficiency */ + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSED"; + out << " (kNoPktTimeout)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } + outStreamActive = false; inStreamActive = false; state = TCP_CLOSED; @@ -990,11 +1011,19 @@ int TcpStream::recv_check() int TcpStream::cleanup() { // This shuts it all down! no matter what. + { + std::ostringstream out; + out << "TcpStream::cleanup() state = TCP_CLOSED"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } outStreamActive = false; inStreamActive = false; state = TCP_CLOSED; + +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream STATE -> TCP_CLOSED" << std::endl; +#endif //peerKnown = false; //??? NOT SURE -> for a rapid reconnetion this might be key?? @@ -1147,6 +1176,12 @@ int TcpStream::handleIncoming(TcpPacket *pkt) */ state = TCP_CLOSED; // return incoming_TimedWait(pkt); + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSED"; + out << " (recvd TCP_TIMED_WAIT?)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } break; } delete pkt; @@ -1163,7 +1198,9 @@ int TcpStream::incoming_Closed(TcpPacket *pkt) * else Discard. */ +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::incoming_Closed()" << std::endl; +#endif if ((pkt -> hasSyn()) && (!pkt -> hasAck())) { /* Init Connection */ @@ -1212,7 +1249,16 @@ int TcpStream::incoming_Closed(TcpPacket *pkt) toSend(rsp); /* change state */ state = TCP_SYN_RCVD; + +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream STATE -> TCP_SYN_RCVD" << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_SYN_RECVD"; + out << " (recvd SYN & !ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } delete pkt; @@ -1233,14 +1279,18 @@ int TcpStream::incoming_SynSent(TcpPacket *pkt) * else Discard. */ +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::incoming_SynSent()" << std::endl; +#endif if ((pkt -> hasSyn()) && (pkt -> hasAck())) { /* check stuff */ if (pkt -> getAck() != outSeqno) { +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::incoming_SynSent() Bad Ack - Deleting " << std::endl; +#endif /* bad ignore */ delete pkt; return -1; @@ -1270,7 +1320,15 @@ int TcpStream::incoming_SynSent(TcpPacket *pkt) outStreamActive = true; inStreamActive = true; +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream STATE -> TCP_ESTABLISHED" << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_ESTABLISHED"; + out << " (recvd SUN & ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } delete pkt; } @@ -1291,7 +1349,15 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt) { /* trouble */ state = TCP_CLOSED; +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream STATE -> TCP_CLOSED" << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSED"; + out << " (recvd RST)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } delete pkt; return 1; } @@ -1303,14 +1369,18 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt) if (pkt -> hasSyn()) { /* has resent syn -> check it matches */ +#ifdef DEBUG_TCP_STREAM std::cerr << "incoming_SynRcvd -> Pkt with ACK + SYN" << std::endl; +#endif } /* check stuff */ if (pkt -> getAck() != outSeqno) { /* bad ignore */ +#ifdef DEBUG_TCP_STREAM std::cerr << "incoming_SynRcvd -> Ignoring Pkt with bad ACK" << std::endl; +#endif delete pkt; return -1; } @@ -1320,8 +1390,10 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt) /* save seqno */ if (pkt -> datasize > 0) { +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::incoming_SynRcvd() ACK with Data!" << std::endl; std::cerr << "TcpStream::incoming_SynRcvd() Shoudn't recv ... unless initACK lost!" << std::endl; +#endif // managed to trigger this under windows... // perhaps the initial Ack was lost, // believe we should just pass this packet @@ -1347,20 +1419,32 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt) state = TCP_ESTABLISHED; outStreamActive = true; inStreamActive = true; +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream STATE -> TCP_ESTABLISHED" << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_ESTABLISHED"; + out << " (have SYN, recvd ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } if (ackWithData) { /* connection Established -> handle normally */ +#ifdef DEBUG_TCP_STREAM std::cerr << "incoming_SynRcvd -> Handling Data with Ack Pkt!"; std::cerr << std::endl; +#endif incoming_Established(pkt); } else { +#ifdef DEBUG_TCP_STREAM std::cerr << "incoming_SynRcvd -> Ignoring Pkt!" << std::endl; +#endif /* else nothing */ delete pkt; } @@ -1575,20 +1659,44 @@ int TcpStream::check_InPkts() if (state == TCP_ESTABLISHED) { state = TCP_CLOSE_WAIT; - std::cerr << "TcpStream::state = TCP_CLOSE_WAIT"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_CLOSE_WAIT"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSE_WAIT"; + out << " (recvd FIN)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } else if (state == TCP_FIN_WAIT_1) { state = TCP_CLOSING; - std::cerr << "TcpStream::state = TCP_CLOSING"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_CLOSING"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSING"; + out << " (FIN_WAIT_1, recvd FIN)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } else if (state == TCP_FIN_WAIT_2) { state = TCP_TIMED_WAIT; - std::cerr << "TcpStream::state = TCP_TIMED_WAIT"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_TIMED_WAIT"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_TIMED_WAIT"; + out << " (FIN_WAIT_2, recvd FIN)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } cleanup(); } } @@ -1600,21 +1708,45 @@ int TcpStream::check_InPkts() if (state == TCP_FIN_WAIT_1) { state = TCP_FIN_WAIT_2; - std::cerr << "TcpStream::state = TCP_FIN_WAIT_2"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_FIN_WAIT_2"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_FIN_WAIT_2"; + out << " (FIN_WAIT_1, recvd ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } else if (state == TCP_LAST_ACK) { state = TCP_CLOSED; - std::cerr << "TcpStream::state = TCP_CLOSED"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_CLOSED"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSED"; + out << " (LAST_ACK, recvd ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } cleanup(); } else if (state == TCP_CLOSING) { state = TCP_TIMED_WAIT; - std::cerr << "TcpStream::state = TCP_TIMED_WAIT"; - std::cerr << std::endl; +#ifdef DEBUG_TCP_STREAM + std::cerr << "TcpStream::state = TCP_TIMED_WAIT"; + std::cerr << std::endl; +#endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_TIMED_WAIT"; + out << " (TCP_CLOSING, recvd ACK)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } cleanup(); } } @@ -1681,8 +1813,10 @@ int TcpStream::toSend(TcpPacket *pkt, bool retrans) if (!peerKnown) { /* Major Error! */ +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::toSend() peerUnknown ERROR!!!"; std::cerr << std::endl; +#endif exit(1); } @@ -1769,8 +1903,10 @@ int TcpStream::retrans() if (!peerKnown) { /* Major Error! */ +#ifdef DEBUG_TCP_STREAM std::cerr << "TcpStream::retrans() peerUnknown ERROR!!!"; std::cerr << std::endl; +#endif exit(1); } @@ -1871,14 +2007,6 @@ int TcpStream::retrans() if ((pkt->hasSyn()) && (getTTL() < TCP_STD_TTL)) { - std::cerr << "TcpStream::retrans() Startup SYNs"; - std::cerr << std::endl; - std::cerr << "TcpStream::retrans() retransTimeout: "; - std::cerr << retransTimeout << std::endl; - - //setTTL(1 + pkt->retrans / - // TCP_STARTUP_COUNT_PER_TTL); - /* calculate a new TTL */ if (mTTL_end > cts) { @@ -1889,10 +2017,17 @@ int TcpStream::retrans() setTTL(getTTL() + 1); } - std::cerr << "TcpStream::retrans() retrans count: "; - std::cerr << pkt->retrans << std::endl; - std::cerr << "TcpStream::retrans() Setting TTL to: "; - std::cerr << getTTL() << std::endl; + std::ostringstream out; + out << "TcpStream::retrans() Startup SYNs "; + out << "retrans count: " << pkt->retrans; + out << " New TTL: " << getTTL(); + + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + +#ifdef DEBUG_TCP_STREAM + std::cerr << out.str() << std::endl; +#endif + } @@ -1913,6 +2048,13 @@ int TcpStream::retrans() std::cerr << std::endl; #endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_CLOSED"; + out << " (Too Many Retransmits)"; + rslog(RSL_WARNING,rstcpstreamzone,out.str()); + } + outStreamActive = false; inStreamActive = false; state = TCP_CLOSED; @@ -2236,17 +2378,29 @@ int TcpStream::send() { state = TCP_FIN_WAIT_1; #ifdef DEBUG_TCP_STREAM - std::cerr << "TcpStream::state = TCP_FIN_WAIT_1"; - std::cerr << std::endl; + std::cerr << "TcpStream::state = TCP_FIN_WAIT_1"; + std::cerr << std::endl; #endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_FIN_WAIT_1"; + out << " (End of Stream)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } else if (state == TCP_CLOSE_WAIT) { state = TCP_LAST_ACK; #ifdef DEBUG_TCP_STREAM - std::cerr << "TcpStream::state = TCP_LAST_ACK"; - std::cerr << std::endl; + std::cerr << "TcpStream::state = TCP_LAST_ACK"; + std::cerr << std::endl; #endif + { + std::ostringstream out; + out << "TcpStream::state => TCP_LAST_ACK"; + out << " (CLOSE_WAIT, End of Stream)"; + rslog(RSL_WARNING, rstcpstreamzone, out.str()); + } } } diff --git a/libretroshare/src/tcponudp/udpsorter.cc b/libretroshare/src/tcponudp/udpsorter.cc index 799e6118e..0dfef9d79 100644 --- a/libretroshare/src/tcponudp/udpsorter.cc +++ b/libretroshare/src/tcponudp/udpsorter.cc @@ -32,6 +32,9 @@ #include #include +#include "util/rsdebug.h" +const int rsudpsorterzone = 28477; + static const int STUN_TTL = 64; /* @@ -86,6 +89,10 @@ void UdpSorter::recvPkt(void *data, int size, struct sockaddr_in &from) std::cerr << "UdpSorter::recvPkt() Peer Unknown!"; std::cerr << std::endl; #endif + std::ostringstream out; + out << "UdpSorter::recvPkt() "; + out << "from unknown: " << from; + rslog(RSL_WARNING,rsudpsorterzone,out.str()); } else { @@ -233,6 +240,11 @@ bool UdpSorter::locked_handleStunPkt(void *data, int size, struct sockaddr_in &f std::cerr << inet_ntoa(from.sin_addr) << ":" << ntohs(from.sin_port); std::cerr << std::endl; #endif + { + std::ostringstream out; + out << "UdpSorter::handleStunPkt() got Request from: " << from; + rslog(RSL_WARNING,rsudpsorterzone,out.str()); + } /* generate a response */ int len; @@ -266,6 +278,13 @@ bool UdpSorter::locked_handleStunPkt(void *data, int size, struct sockaddr_in &f std::cerr << inet_ntoa(eAddr.sin_addr) << ":" << ntohs(eAddr.sin_port); std::cerr << std::endl; #endif + { + std::ostringstream out; + out << "UdpSorter::handleStunPkt() got Response from: " << from; + out << " Ext Addr: " << eAddr; + rslog(RSL_WARNING,rsudpsorterzone,out.str()); + } + locked_recvdStun(from, eAddr); return true; diff --git a/libretroshare/src/util/Makefile b/libretroshare/src/util/Makefile index d86d9f3a3..3696985b1 100644 --- a/libretroshare/src/util/Makefile +++ b/libretroshare/src/util/Makefile @@ -7,7 +7,7 @@ RS_TOP_DIR = .. include $(RS_TOP_DIR)/scripts/config.mk ############################################################### -RSOBJ = rsthreads.o rsdir.o rsprint.o rsnet.o +RSOBJ = rsthreads.o rsdir.o rsprint.o rsnet.o rsdebug.o TESTOBJ = dirtest.o dir2test.o diff --git a/libretroshare/src/pqi/pqidebug.cc b/libretroshare/src/util/rsdebug.cc similarity index 68% rename from libretroshare/src/pqi/pqidebug.cc rename to libretroshare/src/util/rsdebug.cc index 36fcc8a0b..d4e690fd2 100644 --- a/libretroshare/src/pqi/pqidebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -1,7 +1,7 @@ /* * "$Id: pqidebug.cc,v 1.6 2007-02-18 21:46:49 rmf24 Exp $" * - * 3P/PQI network interface for RetroShare. + * 3P/RS network interface for RetroShare. * * Copyright 2004-2006 by Robert Fernie. * @@ -26,28 +26,35 @@ -#include "pqi/pqidebug.h" +#include "util/rsdebug.h" +#include "util/rsthreads.h" #include #include -const int PQI_DEBUG_STDERR = 1; /* stuff goes to stderr */ -const int PQI_DEBUG_LOGFILE = 2; /* stuff goes to logfile */ -const int PQI_DEBUG_LOGCRASH = 3; /* minimal logfile stored after crashes */ -const int PQI_DEBUG_LOGC_MAX = 1000; /* max length of carshfile log */ -const int PQI_DEBUG_LOGC_MIN_SAVE = 100; /* max length of carshfile log */ +const int RS_DEBUG_STDERR = 1; /* stuff goes to stderr */ +const int RS_DEBUG_LOGFILE = 2; /* stuff goes to logfile */ +const int RS_DEBUG_LOGCRASH = 3; /* minimal logfile stored after crashes */ +const int RS_DEBUG_LOGC_MAX = 100000; /* max length of crashfile log */ +const int RS_DEBUG_LOGC_MIN_SAVE = 100; /* min length of crashfile log */ static std::map zoneLevel; -static int defaultLevel = PQL_WARNING; +static int defaultLevel = RSL_WARNING; static FILE *ofd = stderr; -static int debugMode = PQI_DEBUG_STDERR; +static int debugMode = RS_DEBUG_STDERR; static int lineCount = 0; static std::string crashfile; static int debugTS = 0; +static RsMutex logMtx; + +int locked_setDebugFile(const char *fname); +int locked_getZoneLevel(int zone); + int setDebugCrashMode(const char *cfile) { + RsStackMutex stack(logMtx); /******** LOCKED ****************/ crashfile = cfile; /* if the file exists - then we crashed, save it */ FILE *tmpin = fopen(crashfile.c_str(), "r"); @@ -55,7 +62,7 @@ int setDebugCrashMode(const char *cfile) { /* see how long it is */ fseek(tmpin, 0, SEEK_END); - if (ftell(tmpin) > PQI_DEBUG_LOGC_MIN_SAVE) + if (ftell(tmpin) > RS_DEBUG_LOGC_MIN_SAVE) { std::string crashfile_save = crashfile + "-save"; fprintf(stderr, "Detected Old Crash File: %s\n", crashfile.c_str()); @@ -95,10 +102,10 @@ int setDebugCrashMode(const char *cfile) } } - if (0 < setDebugFile(crashfile.c_str())) + if (0 < locked_setDebugFile(crashfile.c_str())) { fprintf(stderr, "Switching To CrashLog Mode!\n"); - debugMode = PQI_DEBUG_LOGCRASH; + debugMode = RS_DEBUG_LOGCRASH; lineCount = 0; debugTS = time(NULL); } @@ -109,8 +116,9 @@ int setDebugCrashMode(const char *cfile) /* this is called when we exit normally */ int clearDebugCrashLog() { + RsStackMutex stack(logMtx); /******** LOCKED ****************/ /* check we are in crashLog Mode */ - if (debugMode != PQI_DEBUG_LOGCRASH) + if (debugMode != RS_DEBUG_LOGCRASH) { fprintf(stderr, "Not in CrashLog Mode - nothing to clear!\n"); return 1; @@ -120,7 +128,7 @@ int clearDebugCrashLog() /* shutdown crashLog Mode */ fclose(ofd); ofd = stderr; - debugMode = PQI_DEBUG_STDERR; + debugMode = RS_DEBUG_STDERR; /* just open the file, and then close */ FILE *tmpin = fopen(crashfile.c_str(), "w"); @@ -132,17 +140,23 @@ int clearDebugCrashLog() int setDebugFile(const char *fname) +{ + RsStackMutex stack(logMtx); /******** LOCKED ****************/ + return locked_setDebugFile(fname); +} + +int locked_setDebugFile(const char *fname) { if (NULL != (ofd = fopen(fname, "w"))) { fprintf(stderr, "Logging redirected to %s\n", fname); - debugMode = PQI_DEBUG_LOGFILE; + debugMode = RS_DEBUG_LOGFILE; return 1; } else { ofd = stderr; - debugMode = PQI_DEBUG_STDERR; + debugMode = RS_DEBUG_STDERR; fprintf(stderr, "Logging redirect to %s FAILED\n", fname); return -1; } @@ -151,17 +165,25 @@ int setDebugFile(const char *fname) int setOutputLevel(int lvl) { + RsStackMutex stack(logMtx); /******** LOCKED ****************/ return defaultLevel = lvl; } int setZoneLevel(int lvl, int zone) { + RsStackMutex stack(logMtx); /******** LOCKED ****************/ zoneLevel[zone] = lvl; return zone; } int getZoneLevel(int zone) +{ + RsStackMutex stack(logMtx); /******** LOCKED ****************/ + return locked_getZoneLevel(zone); +} + +int locked_getZoneLevel(int zone) { std::map::iterator it = zoneLevel.find(zone); if (it == zoneLevel.end()) @@ -171,27 +193,28 @@ int getZoneLevel(int zone) return it -> second; } -int pqioutput(unsigned int lvl, int zone, std::string msg) +int rslog(unsigned int lvl, int zone, std::string msg) { - if ((signed) lvl <= getZoneLevel(zone)) + RsStackMutex stack(logMtx); /******** LOCKED ****************/ + if ((signed) lvl <= locked_getZoneLevel(zone)) { time_t t = time(NULL); - if (debugMode == PQI_DEBUG_LOGCRASH) + if (debugMode == RS_DEBUG_LOGCRASH) { - if (lineCount > PQI_DEBUG_LOGC_MAX) + if (lineCount > RS_DEBUG_LOGC_MAX) { /* restarting logging */ fprintf(stderr, "Rolling over the CrashLog\n"); fclose(ofd); ofd = NULL; - if (0 < setDebugFile(crashfile.c_str())) + if (0 < locked_setDebugFile(crashfile.c_str())) { fprintf(ofd, "Debug CrashLog:"); fprintf(ofd, " retroShare uptime %ld secs\n", t-debugTS); - debugMode = PQI_DEBUG_LOGCRASH; + debugMode = RS_DEBUG_LOGCRASH; lineCount = 0; } else diff --git a/libretroshare/src/pqi/pqidebug.h b/libretroshare/src/util/rsdebug.h similarity index 52% rename from libretroshare/src/pqi/pqidebug.h rename to libretroshare/src/util/rsdebug.h index 7826f68fb..87123ee1a 100644 --- a/libretroshare/src/pqi/pqidebug.h +++ b/libretroshare/src/util/rsdebug.h @@ -1,9 +1,9 @@ /* - * "$Id: pqidebug.h,v 1.4 2007-02-18 21:46:49 rmf24 Exp $" + * libretroshare/src/util: rsdebug.h * - * 3P/PQI network interface for RetroShare. + * Debug interface for RetroShare. * - * Copyright 2004-2006 by Robert Fernie. + * Copyright 2004-2008 by Robert Fernie. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,17 +24,22 @@ */ +/* Moved from pqi/ to util/ so it can be used more generally. + */ -#ifndef PQI_LOG_DEBUG_H -#define PQI_LOG_DEBUG_H +#ifndef RS_LOG_DEBUG_H +#define RS_LOG_DEBUG_H + + + +#define RSL_NONE -1 +#define RSL_ALERT 1 +#define RSL_ERROR 3 +#define RSL_WARNING 5 +#define RSL_DEBUG_ALERT 6 +#define RSL_DEBUG_BASIC 8 +#define RSL_DEBUG_ALL 10 -#define PQL_NONE -1 -#define PQL_ALERT 1 -#define PQL_ERROR 3 -#define PQL_WARNING 5 -#define PQL_DEBUG_ALERT 6 -#define PQL_DEBUG_BASIC 8 -#define PQL_DEBUG_ALL 10 #include @@ -44,6 +49,25 @@ int clearDebugCrashLog(); int setDebugFile(const char *fname); int setOutputLevel(int lvl); int setZoneLevel(int lvl, int zone); -int pqioutput(unsigned int lvl, int zone, std::string msg); +int rslog(unsigned int lvl, int zone, std::string msg); + + + +/* + * retaining old #DEFINES and functions for backward compatibility. + */ + +//int pqioutput(unsigned int lvl, int zone, std::string msg); +#define pqioutput rslog + +#define PQL_NONE RSL_NONE +#define PQL_ALERT RSL_ALERT +#define PQL_ERROR RSL_ERROR +#define PQL_WARNING RSL_WARNING +#define PQL_DEBUG_ALERT RSL_DEBUG_ALERT +#define PQL_DEBUG_BASIC RSL_DEBUG_BASIC +#define PQL_DEBUG_ALL RSL_DEBUG_ALL + + #endif