From 100a7aea825102c2681921dba700a9771b5570b3 Mon Sep 17 00:00:00 2001 From: drbob Date: Mon, 25 Feb 2008 21:39:08 +0000 Subject: [PATCH] Changed DHT string output to use std::ostringstream, as snprintf wasn't working with inet_ntoa.... also added some other debug and fixed notifytxt. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@353 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dht/opendht.cc | 4 +++ libretroshare/src/pqi/p3dhtmgr.cc | 45 ++++++++++++++++++++++++-- libretroshare/src/rsiface/notifytxt.cc | 25 -------------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/dht/opendht.cc b/libretroshare/src/dht/opendht.cc index 96d5c1886..074fe02be 100644 --- a/libretroshare/src/dht/opendht.cc +++ b/libretroshare/src/dht/opendht.cc @@ -230,6 +230,10 @@ bool OpenDHTClient::dhtActive() bool OpenDHTClient::publishKey(std::string key, std::string value, uint32_t ttl) { /* create request */ +#ifdef OPENDHT_DEBUG + std::cerr << "OpenDHTClient::openDHT_publishKey() key: " << key << " value: " << value; + std::cerr << std::endl; +#endif std::string putmsg = createOpenDHT_put(key, value, ttl, openDHT_Client); std::string response; diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 130646268..6536cfdd8 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -495,8 +495,20 @@ int p3DhtMgr::checkOwnDHTKeys() (now - peer.lastTS > DHT_PUBLISH_PERIOD)) { #ifdef DHT_DEBUG - std::cerr << "p3DhtMgr::checkOwnDHTKeys() OWN ADDR REPUB" << std::endl; + std::cerr << "p3DhtMgr::checkOwnDHTKeys() OWN ADDR REPUB" << std::endl; #endif + +#ifdef DHT_DEBUG + std::cerr << "PUBLISH: "; + std::cerr << " hash1: " << peer.hash1; + std::cerr << " laddr: " << inet_ntoa(peer.laddr.sin_addr); + std::cerr << ":" << ntohs(peer.laddr.sin_port); + std::cerr << " raddr: " << inet_ntoa(peer.raddr.sin_addr); + std::cerr << ":" << ntohs(peer.raddr.sin_port); + std::cerr << " type: " << peer.type; + std::cerr << std::endl; +#endif + /* publish own key */ if (dhtPublish(peer.hash1, peer.laddr, peer.raddr, peer.type, "")) { @@ -1016,11 +1028,29 @@ bool p3DhtMgr::dhtPublish(std::string idhash, uint32_t type, std::string sign) { /* ... goes and searches */ +#ifdef DHT_DEBUG std::cerr << "p3DhtMgr::dhtPublish()" << std::endl; - /* Create a Value from addresses and type */ + std::cerr << "PUBLISHing: idhash: " << idhash; + std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr); + std::cerr << ":" << ntohs(laddr.sin_port); + std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr); + std::cerr << ":" << ntohs(raddr.sin_port); + std::cerr << " type: " << type; + std::cerr << " sign: " << sign; + std::cerr << std::endl; +#endif + /* Create a Value from addresses and type */ /* to store the ip address and flags */ + + std::ostringstream out; + out << "RSDHT:" << std::setw(2) << std::setfill('0') << DHT_MODE_SEARCH << ": "; + out << "IPL=" << inet_ntoa(laddr.sin_addr) << ":" << ntohs(laddr.sin_port) << ", "; + out << "IPE=" << inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port) << ", "; + out << "type=" << std::setw(4) << std::setfill('0') << std::hex << type << ", "; + +/******* char valuearray[1024]; snprintf(valuearray, 1024, "RSDHT:%02d: IPL=%s:%d, IPE=%s:%d, type=%04X,", DHT_MODE_SEARCH, @@ -1031,6 +1061,17 @@ bool p3DhtMgr::dhtPublish(std::string idhash, type); std::string value = valuearray; +******/ + + std::string value = out.str(); + +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::dhtPublish()" << std::endl; + + std::cerr << "PUBLISH: key: " << idhash; + std::cerr << " value: " << value; + std::cerr << std::endl; +#endif /* call to the real DHT */ return publishDHT(idhash, value, DHT_TTL_PUBLISH); diff --git a/libretroshare/src/rsiface/notifytxt.cc b/libretroshare/src/rsiface/notifytxt.cc index 18c6a9290..35c0a6125 100644 --- a/libretroshare/src/rsiface/notifytxt.cc +++ b/libretroshare/src/rsiface/notifytxt.cc @@ -139,31 +139,6 @@ void NotifyTxt::displaySearch() void NotifyTxt::displayMessages() { iface->lockData(); /* Lock Interface */ - - std::ostringstream out; - std::cerr << out.str(); - - std::list::const_iterator it; - const std::list &msgs = iface->getMessages(); - - std::list::const_iterator fit; - int i; - - for(it = msgs.begin(); it != msgs.end(); it++) - { - out << "Message: "; - std::string cnv_title(it->title.begin(), it->title.end()); - out << cnv_title << std::endl; - std::string cnv_msg(it->msg.begin(), it->msg.end()); - out << "\t" << cnv_msg << std::endl; - const std::list &files = it -> files; - for(fit = files.begin(), i = 1; fit != files.end(); fit++, i++) - { - out << "\t\tFile(" << i << ") " << fit->fname << std::endl; - } - out << std::endl; - } - iface->unlockData(); /* UnLock Interface */ }