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
This commit is contained in:
drbob 2008-02-25 21:39:08 +00:00
parent 39d8b258ab
commit 100a7aea82
3 changed files with 47 additions and 27 deletions

View File

@ -230,6 +230,10 @@ bool OpenDHTClient::dhtActive()
bool OpenDHTClient::publishKey(std::string key, std::string value, uint32_t ttl) bool OpenDHTClient::publishKey(std::string key, std::string value, uint32_t ttl)
{ {
/* create request */ /* 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 putmsg = createOpenDHT_put(key, value, ttl, openDHT_Client);
std::string response; std::string response;

View File

@ -495,8 +495,20 @@ int p3DhtMgr::checkOwnDHTKeys()
(now - peer.lastTS > DHT_PUBLISH_PERIOD)) (now - peer.lastTS > DHT_PUBLISH_PERIOD))
{ {
#ifdef DHT_DEBUG #ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::checkOwnDHTKeys() OWN ADDR REPUB" << std::endl; std::cerr << "p3DhtMgr::checkOwnDHTKeys() OWN ADDR REPUB" << std::endl;
#endif #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 */ /* publish own key */
if (dhtPublish(peer.hash1, peer.laddr, peer.raddr, peer.type, "")) 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) uint32_t type, std::string sign)
{ {
/* ... goes and searches */ /* ... goes and searches */
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtPublish()" << std::endl; 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 */ /* 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]; char valuearray[1024];
snprintf(valuearray, 1024, "RSDHT:%02d: IPL=%s:%d, IPE=%s:%d, type=%04X,", snprintf(valuearray, 1024, "RSDHT:%02d: IPL=%s:%d, IPE=%s:%d, type=%04X,",
DHT_MODE_SEARCH, DHT_MODE_SEARCH,
@ -1031,6 +1061,17 @@ bool p3DhtMgr::dhtPublish(std::string idhash,
type); type);
std::string value = valuearray; 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 */ /* call to the real DHT */
return publishDHT(idhash, value, DHT_TTL_PUBLISH); return publishDHT(idhash, value, DHT_TTL_PUBLISH);

View File

@ -139,31 +139,6 @@ void NotifyTxt::displaySearch()
void NotifyTxt::displayMessages() void NotifyTxt::displayMessages()
{ {
iface->lockData(); /* Lock Interface */ iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
std::list<MessageInfo>::const_iterator it;
const std::list<MessageInfo> &msgs = iface->getMessages();
std::list<FileInfo>::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<FileInfo> &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 */ iface->unlockData(); /* UnLock Interface */
} }