From 474aa31fd1dbfa3af0bf89ce79eb861bf2ce4289 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Jan 2011 17:25:30 +0000 Subject: [PATCH] suppressed debug printfs and costly outputs git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3967 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/pqibin.cc | 10 +++++ libretroshare/src/pqi/pqistore.cc | 47 +++++++++++++++++--- libretroshare/src/serialiser/rsforumitems.cc | 29 +++++++++++- libretroshare/src/services/p3distrib.cc | 4 ++ 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/pqi/pqibin.cc b/libretroshare/src/pqi/pqibin.cc index a50ac75d7..3ca7d04e7 100644 --- a/libretroshare/src/pqi/pqibin.cc +++ b/libretroshare/src/pqi/pqibin.cc @@ -31,6 +31,7 @@ #include "pqi/authssl.h" #include "util/rsnet.h" +// #define DEBUG_PQIBIN BinFileInterface::BinFileInterface(const char *fname, int flags) :bin_flags(flags), buf(NULL), hash(NULL), bcount(0) @@ -65,6 +66,9 @@ BinFileInterface::BinFileInterface(const char *fname, int flags) if (buf) { +#ifdef DEBUG_PQIBIN + std::cerr << "BinFileInterface: " << (void*)this << ": openned file " << fname << std::endl; +#endif /* no problem */ /* go to the end */ @@ -91,6 +95,9 @@ BinFileInterface::~BinFileInterface() if (buf) { fclose(buf); +#ifdef DEBUG_PQIBIN + std::cerr << "BinFileInterface: " << (void*)this << ": closed file " << std::endl; +#endif } if (hash) @@ -104,6 +111,9 @@ int BinFileInterface::close() if (buf) { fclose(buf); +#ifdef DISTRIB_DEBUG + std::cerr << "BinFileInterface: " << (void*)this << ": closed file " << std::endl; +#endif buf = NULL; } return 1; diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index ea7b5e8b2..3871d58a6 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -48,6 +48,10 @@ #include #include "util/rsdebug.h" +// +// #define PQISTORE_DEBUG +// + const int pqistorezone = 9511; pqistore::pqistore(RsSerialiser *rss, const std::string &srcId, BinInterface *bio_in, int bio_flags_in) @@ -113,12 +117,14 @@ pqistore::~pqistore() // Get/Send Items. int pqistore::SendItem(RsItem *si) { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::SendItem()" << std::endl; si -> print(out); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); } +#endif // check if this is a writing bio. @@ -137,19 +143,23 @@ int pqistore::SendItem(RsItem *si) RsItem *pqistore::GetItem() { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::GetItem()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif // check if this is a reading bio. if (!(bio_flags & BIN_FLAGS_READABLE)) { +#ifdef PQISTORE_DEBUG std::ostringstream out; out << "pqistore::GetItem()"; out << "Error Not Readable" << std::endl; pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); +#endif return NULL; } @@ -171,13 +181,15 @@ RsItem *pqistore::GetItem() RsItem *outPkt = nextPkt; nextPkt = NULL; +#ifdef PQISTORE_DEBUG if (outPkt != NULL) - { - std::ostringstream out; - out << "pqistore::GetItem() Returning:" << std::endl; - outPkt -> print(out); - pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); + { + std::ostringstream out; + out << "pqistore::GetItem() Returning:" << std::endl; + outPkt -> print(out); + pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); } +#endif return outPkt; } @@ -187,21 +199,25 @@ RsItem *pqistore::GetItem() // // PQInterface int pqistore::tick() { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::tick()"; out << std::endl; } +#endif return 0; } int pqistore::status() { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::status()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif return 0; } @@ -211,22 +227,26 @@ int pqistore::status() int pqistore::writePkt(RsItem *pqi) { // std::cerr << "writePkt, pqi->peerId()=" << pqi->PeerId() << std::endl ; +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::writePkt()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif uint32_t pktsize = rsSerialiser->size(pqi); void *ptr = malloc(pktsize); if (!(rsSerialiser->serialise(pqi, ptr, &pktsize))) { +#ifdef PQISTORE_DEBUG std::ostringstream out; out << "pqistore::writePkt() Null Pkt generated!"; out << std::endl; out << "Caused By: " << std::endl; pqi -> print(out); pqioutput(PQL_ALERT, pqistorezone, out.str()); +#endif free(ptr); if (!(bio_flags & BIN_FLAGS_NO_DELETE)) @@ -269,14 +289,18 @@ int pqistore::writePkt(RsItem *pqi) return 0; } +#ifdef PQISTORE_DEBUG std::ostringstream out; out << "Writing Pkt Body" << std::endl; +#endif // write packet. if (len != bio->senddata(ptr, len)) { +#ifdef PQISTORE_DEBUG out << "Problems with Send Data!"; out << std::endl; pqioutput(PQL_ALERT, pqistorezone, out.str()); +#endif free(ptr); if (!(bio_flags & BIN_FLAGS_NO_DELETE)) @@ -285,8 +309,10 @@ int pqistore::writePkt(RsItem *pqi) return 0; } +#ifdef PQISTORE_DEBUG out << " Success!" << std::endl; pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); +#endif free(ptr); if (!(bio_flags & BIN_FLAGS_NO_DELETE)) @@ -301,11 +327,13 @@ int pqistore::writePkt(RsItem *pqi) int pqistore::readPkt(RsItem **item_out) { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::readPkt()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif if ((!(bio->isactive())) || (!(bio->moretoread()))) { @@ -397,6 +425,7 @@ pqiSSLstore::pqiSSLstore(RsSerialiser *rss, std::string srcId, BinEncryptedFileI pqiSSLstore::~pqiSSLstore() { + // no need to delete member enc_bio, as it is deleted by the parent class. return; } @@ -450,11 +479,13 @@ bool pqiSSLstore::getEncryptedItems(std::list& rsItemList) RsItem *pqiSSLstore::GetItem() { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::GetItem()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif // check if this is a reading bio. if (!(bio_flags & BIN_FLAGS_READABLE)) @@ -484,6 +515,7 @@ RsItem *pqiSSLstore::GetItem() RsItem *outPkt = nextPkt; nextPkt = NULL; +#ifdef PQISTORE_DEBUG if (outPkt != NULL) { std::ostringstream out; @@ -491,17 +523,20 @@ RsItem *pqiSSLstore::GetItem() outPkt -> print(out); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); } +#endif return outPkt; } int pqiSSLstore::readPkt(RsItem **item_out) { +#ifdef PQISTORE_DEBUG { std::ostringstream out; out << "pqistore::readPkt()"; pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str()); } +#endif if ((!(enc_bio->isactive())) || (!(enc_bio->moretoread()))) { @@ -567,12 +602,14 @@ int pqiSSLstore::readPkt(RsItem **item_out) RsItem *item = rsSerialiser->deserialise(block, &readbytes); free(block); +#ifdef PQISTORE_DEBUG if (item == NULL) { pqioutput(PQL_ALERT, pqistorezone, "pqistore::readPkt() Failed to create Item from store!"); return 0; } +#endif item->PeerId(mSrcId); *item_out = item; diff --git a/libretroshare/src/serialiser/rsforumitems.cc b/libretroshare/src/serialiser/rsforumitems.cc index b195c4db2..91c9ac47d 100644 --- a/libretroshare/src/serialiser/rsforumitems.cc +++ b/libretroshare/src/serialiser/rsforumitems.cc @@ -29,7 +29,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" -#define RSSERIAL_DEBUG 1 +// #define RSSERIAL_DEBUG 1 #include /*************************************************************************/ @@ -145,32 +145,47 @@ bool RsForumSerialiser::serialiseMsg(RsForumMsg *item, void *data, uint32_t bool ok = true; ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() Header: " << ok << std::endl; std::cerr << "RsForumSerialiser::serialiseMsg() Size: " << tlvsize << std::endl; +#endif /* skip the header */ offset += 8; /* RsDistribMsg first */ ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() grpId: " << ok << std::endl; +#endif ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PARENTID, item->parentId); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() parentId: " << ok << std::endl; +#endif ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_THREADID, item->threadId); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() threadId: " << ok << std::endl; +#endif ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() timestamp: " << ok << std::endl; +#endif /* RsForumMsg */ ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->srcId); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() srcId: " << ok << std::endl; +#endif ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() Title: " << ok << std::endl; +#endif ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, item->msg); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseMsg() Msg: " << ok << std::endl; +#endif if (offset != tlvsize) { @@ -282,8 +297,10 @@ bool RsForumSerialiser::serialiseReadStatus(RsForumReadStatus *item, void *d ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseReadStatus() Header: " << ok << std::endl; std::cerr << "RsForumSerialiser::serialiseReadStatus() Size: " << tlvsize << std::endl; +#endif /* skip the header */ offset += 8; @@ -291,13 +308,17 @@ bool RsForumSerialiser::serialiseReadStatus(RsForumReadStatus *item, void *d /* RsDistribMsg first */ ok &= setRawUInt32(data, tlvsize, &offset, item->save_type); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseReadStatus() save_type: " << ok << std::endl; +#endif /* RsForumMsg */ ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->forumId); +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseReadStatus() forumId: " << ok << std::endl; +#endif std::map::iterator mit = item->msgReadStatus.begin(); @@ -307,12 +328,16 @@ bool RsForumSerialiser::serialiseReadStatus(RsForumReadStatus *item, void *d ok &= setRawUInt32(data, tlvsize, &offset, mit->second); /* value */ } +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseReadStatus() msgReadStatus: " << ok << std::endl; +#endif if (offset != tlvsize) { ok = false; +#ifdef RSSERIAL_DEBUG std::cerr << "RsForumSerialiser::serialiseReadStatus() Size Error! " << std::endl; +#endif } return ok; diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index bb5aa9f6c..cec13b62a 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -233,7 +233,9 @@ void p3GroupDistrib::loadFileGroups(const std::string &filename, const std::stri BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE); pqistore *store = createStore(bio, src, BIN_FLAGS_READABLE); +#ifdef DISTRIB_DEBUG std::cerr << "loading file " << filename << std::endl ; +#endif RsItem *item; RsDistribGrp *newGrp; @@ -297,7 +299,9 @@ void p3GroupDistrib::loadFileMsgs(const std::string &filename, uint16_t cacheSub BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE); pqistore *store = createStore(bio, src, BIN_FLAGS_READABLE); +#ifdef DISTRIB_DEBUG std::cerr << "loading file " << filename << std::endl ; +#endif RsItem *item; RsDistribSignedMsg *newMsg;