Removed some std::ostringstream.

To be continued.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5108 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-04-18 00:00:59 +00:00
parent b2ea453804
commit 9aee68a2a9
8 changed files with 140 additions and 233 deletions

View File

@ -27,9 +27,9 @@
#include "retroshare/rsconfig.h"
#include "util/rsrandom.h"
#include "util/rsstring.h"
#include <iostream>
#include <sstream>
/**
*
@ -241,22 +241,22 @@ void PeerConnectStateBox::stateMsg(std::ostream &out, std::string msg, uint32_t
std::string PeerConnectStateBox::connectState() const
{
std::string str = StateAsString(mState);
std::ostringstream out;
time_t now = time(NULL);
out << str << "(" << mNoAttempts << "/" << mNoFailedAttempts << ") for " << now - mStateTS << " secs";
std::string out;
rs_sprintf(out, "%s(%lu/%lu) for %ld secs", str.c_str(), mNoAttempts, mNoFailedAttempts, now - mStateTS);
if ( (mState == CSB_CONNECTED) || (mState == CSB_DIRECT_ATTEMPT) ||
(mState == CSB_PROXY_ATTEMPT) || (mState == CSB_RELAY_ATTEMPT) ||
(mState == CSB_FAILED_WAIT) )
{
out << " Last Attempt: " << mAttemptLength;
rs_sprintf_append(out, " Last Attempt: %ld", mAttemptLength);
}
else
{
out << " LA: " << mAttemptLength;
out << " NextAttempt: " << mNextAttemptTS - now;
rs_sprintf_append(out, " LA: %ld", mAttemptLength);
rs_sprintf_append(out, " NextAttempt: %ld", mNextAttemptTS - now);
}
return out.str();
return out;
}

View File

@ -149,49 +149,47 @@ int p3BitDht::getNetFailedPeer(std::string peerId, PeerStatus &status)
std::string p3BitDht::getUdpAddressString()
{
std::ostringstream out;
std::string out;
struct sockaddr_in extAddr;
uint8_t extStable;
if (mDhtStunner->externalAddr(extAddr, extStable))
{
out << " DhtExtAddr: " << rs_inet_ntoa(extAddr.sin_addr);
out << ":" << ntohs(extAddr.sin_port);
rs_sprintf_append(out, " DhtExtAddr: %s:%u", rs_inet_ntoa(extAddr.sin_addr).c_str(), ntohs(extAddr.sin_port));
if (extStable)
{
out << " (Stable) ";
out += " (Stable) ";
}
else
{
out << " (Unstable) ";
out += " (Unstable) ";
}
}
else
{
out << " DhtExtAddr: Unknown ";
out += " DhtExtAddr: Unknown ";
}
if (mProxyStunner->externalAddr(extAddr, extStable))
{
out << " ProxyExtAddr: " << rs_inet_ntoa(extAddr.sin_addr);
out << ":" << ntohs(extAddr.sin_port);
rs_sprintf_append(out, " ProxyExtAddr: %s:%u", rs_inet_ntoa(extAddr.sin_addr).c_str(), ntohs(extAddr.sin_port));
if (extStable)
{
out << " (Stable) ";
out += " (Stable) ";
}
else
{
out << " (Unstable) ";
out += " (Unstable) ";
}
}
else
{
out << " ProxyExtAddr: Unknown ";
out += " ProxyExtAddr: Unknown ";
}
return out.str();
return out;
}
void p3BitDht::updateDataRates()

View File

@ -60,7 +60,7 @@
#include "serialiser/rsconfigitems.h"
#include <stdio.h>
#include <unistd.h> /* for (u)sleep() */
#include <sstream>
#include <sstream> // for std::istringstream
/******
* #define CONTROL_DEBUG 1
@ -1911,20 +1911,17 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
std::list<std::string>::iterator it;
/* basic control parameters */
std::ostringstream strn ;
strn << getMinPrioritizedTransfers() ;
configMap[min_prioritized_downl_ss] = strn.str() ;
std::ostringstream strm ;
strm << getQueueSize() ;
configMap[active_downloads_size_ss] = strm.str() ;
std::string s ;
rs_sprintf(s, "%lu", getMinPrioritizedTransfers()) ;
configMap[min_prioritized_downl_ss] = s ;
rs_sprintf(s, "%lu", getQueueSize()) ;
configMap[active_downloads_size_ss] = s ;
configMap[download_dir_ss] = getDownloadDirectory();
configMap[partial_dir_ss] = getPartialsDirectory();
configMap[default_chunk_strategy_ss] = (mDefaultChunkStrategy==FileChunksInfo::CHUNK_STRATEGY_STREAMING) ? "STREAMING" : "RANDOM";
std::ostringstream s ;
s << RsDiscSpace::freeSpaceLimit();
configMap[free_space_limit_ss] = s.str() ;
rs_sprintf(s, "%lu", RsDiscSpace::freeSpaceLimit());
configMap[free_space_limit_ss] = s ;
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();

View File

@ -252,20 +252,14 @@ bool ftServer::checkHash(const std::string& hash,std::string& error_string)
if(hash.length() != HASH_LENGTH)
{
std::ostringstream is ;
is << "Line too long : " << hash.length() << " chars, " << HASH_LENGTH << " expected." ;
is.flush() ;
error_string = is.str() ;
rs_sprintf(error_string, "Line too long : %u chars, %ld expected.", hash.length(), HASH_LENGTH) ;
return false ;
}
for(uint32_t i=0;i<hash.length();++i)
if(!((hash[i] > 47 && hash[i] < 58) || (hash[i] > 96 && hash[i] < 103)))
{
std::ostringstream is;
is << "unexpected char code=" << (int)hash[i] << " '" << hash[i] << "'" ;
is.flush() ;
error_string = is.str() ;
rs_sprintf(error_string, "unexpected char code=%d '%c'", (int)hash[i], hash[i]) ;
return false ;
}
@ -1042,7 +1036,6 @@ int ftServer::tick()
std::cerr << "ftServer::tick() ERROR: mP3iface == NULL";
#endif
std::ostringstream out;
rslog(RSL_DEBUG_BASIC, ftserverzone,
"filedexserver::tick() Invalid Interface()");
@ -1102,13 +1095,13 @@ bool ftServer::handleCacheData()
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleCacheData() Recvd SearchResult (CacheResponse!)" << std::endl;
std::ostringstream out;
std::string out;
if (i++ == i_init)
{
out << "Recieved Search Results:" << std::endl;
out += "Recieved Search Results:\n";
}
ci -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
ci -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
/* these go to the CacheStrapper! */
@ -1132,10 +1125,9 @@ bool ftServer::handleCacheData()
{
#ifdef SERVER_DEBUG
/* just delete these */
std::ostringstream out;
out << "Requested Search:" << std::endl;
cr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
std::string out = "Requested Search:\n";
cr -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
delete cr;
}
@ -1163,10 +1155,9 @@ bool ftServer::handleCacheData()
ci -> cacheSubId = (it->second).cid.subid;
#ifdef SERVER_DEBUG
std::ostringstream out2;
out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl;
ci -> print(out2);
std::cerr << out2.str() << std::endl;
std::string out2 = "Outgoing CacheStrapper Update -> RsCacheItem:\n";
ci -> print_string(out2);
std::cerr << out2 << std::endl;
#endif
//rslog(RSL_DEBUG_BASIC, ftserverzone, out2.str());
@ -1199,13 +1190,13 @@ bool ftServer::handleFileData()
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ftFiler Request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Item:" << std::endl;
out += "Incoming(Net) File Item:\n";
}
fr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fr -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1228,13 +1219,13 @@ FileInfo(ffr);
std::cerr << " data: " << fd->fd.binData.bin_data;
std::cerr << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fd -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fd -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1256,13 +1247,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fcmr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fcmr -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1277,13 +1268,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fcm -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fcm -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1298,13 +1289,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fccrcmr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fccrcmr -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1319,13 +1310,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fccrcm -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fccrcm -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1340,13 +1331,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File CRC Request:" << std::endl;
out += "Incoming(Net) File CRC Request:\n";
}
fscrcr -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fscrcr -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */
@ -1361,13 +1352,13 @@ FileInfo(ffr);
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::handleFileData() Recvd ChunkMap request" << std::endl;
std::ostringstream out;
std::string out;
if (i == i_init)
{
out << "Incoming(Net) File Data:" << std::endl;
out += "Incoming(Net) File Data:\n";
}
fscrc -> print(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out.str());
fscrc -> print_string(out);
rslog(RSL_DEBUG_BASIC, ftserverzone, out);
#endif
i++; /* count */

View File

@ -29,7 +29,6 @@
#include "tcpstream.h"
#include <iostream>
#include <sstream>
#include <assert.h>
#include <errno.h>
#include <math.h>
@ -40,7 +39,7 @@
/* Debugging for STATE change, and Startup SYNs */
#include "util/rsdebug.h"
#include "util/rsstring.h"
#include "util/rsrandom.h"
const int rstcpstreamzone = 28455;
@ -173,10 +172,7 @@ int TcpStream::connect(const struct sockaddr_in &raddr, uint32_t conn_period)
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());
rslog(RSL_WARNING,rstcpstreamzone,"TcpStream::state => TCP_SYN_SENT (Connect)");
}
tcpMtx.unlock(); /******** UNLOCK MUTEX *********/
@ -997,12 +993,7 @@ int TcpStream::recv_check()
* for max efficiency
*/
{
std::ostringstream out;
out << "TcpStream::state => TCP_CLOSED";
out << " (kNoPktTimeout)";
rslog(RSL_WARNING, rstcpstreamzone, out.str());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSED (kNoPktTimeout)");
outStreamActive = false;
inStreamActive = false;
@ -1015,11 +1006,7 @@ 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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::cleanup() state = TCP_CLOSED");
outStreamActive = false;
inStreamActive = false;
@ -1181,10 +1168,7 @@ 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());
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSED (recvd TCP_TIMED_WAIT?)");
}
break;
}
@ -1257,12 +1241,8 @@ int TcpStream::incoming_Closed(TcpPacket *pkt)
#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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_SYN_RECVD (recvd SYN & !ACK)");
}
delete pkt;
@ -1327,12 +1307,8 @@ int TcpStream::incoming_SynSent(TcpPacket *pkt)
#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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_ESTABLISHED (recvd SUN & ACK)");
delete pkt;
}
@ -1356,12 +1332,9 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt)
#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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSED (recvd RST)");
delete pkt;
return 1;
}
@ -1426,13 +1399,8 @@ int TcpStream::incoming_SynRcvd(TcpPacket *pkt)
#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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_ESTABLISHED (have SYN, recvd ACK)");
}
if (ackWithData)
@ -1735,12 +1703,8 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSE_WAIT (recvd FIN)");
}
else if (state == TCP_FIN_WAIT_1)
{
@ -1749,12 +1713,8 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSING (FIN_WAIT_1, recvd FIN)");
}
else if (state == TCP_FIN_WAIT_2)
{
@ -1763,12 +1723,9 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_TIMED_WAIT (FIN_WAIT_2, recvd FIN)");
cleanup();
}
}
@ -1784,12 +1741,8 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_FIN_WAIT_2 (FIN_WAIT_1, recvd ACK)");
}
else if (state == TCP_LAST_ACK)
{
@ -1798,12 +1751,9 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_CLOSED (LAST_ACK, recvd ACK)");
cleanup();
}
else if (state == TCP_CLOSING)
@ -1813,12 +1763,9 @@ int TcpStream::check_InPkts()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_TIMED_WAIT (TCP_CLOSING, recvd ACK)");
cleanup();
}
}
@ -2089,12 +2036,10 @@ int TcpStream::retrans()
setTTL(getTTL() + 1);
}
std::ostringstream out;
out << "TcpStream::retrans() Startup SYNs ";
out << "retrans count: " << pkt->retrans;
out << " New TTL: " << getTTL();
std::string out;
rs_sprintf(out, "TcpStream::retrans() Startup SYNs retrans count: %u New TTL: %d", pkt->retrans, getTTL());
rslog(RSL_WARNING, rstcpstreamzone, out.str());
rslog(RSL_WARNING, rstcpstreamzone, out);
#ifdef DEBUG_TCP_STREAM
std::cerr << out.str() << std::endl;
@ -2128,12 +2073,8 @@ 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());
}
rslog(RSL_WARNING,rstcpstreamzone,"TcpStream::state => TCP_CLOSED (Too Many Retransmits)");
outStreamActive = false;
inStreamActive = false;
@ -2461,12 +2402,8 @@ int TcpStream::send()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_FIN_WAIT_1 (End of Stream)");
}
else if (state == TCP_CLOSE_WAIT)
{
@ -2475,12 +2412,8 @@ int TcpStream::send()
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());
}
rslog(RSL_WARNING, rstcpstreamzone, "TcpStream::state => TCP_LAST_ACK (CLOSE_WAIT, End of Stream)");
}
}

View File

@ -34,7 +34,7 @@
#ifdef DEBUG_UDP_RELAY
// DEBUG FUNCTION
#include <sstream>
#include "util/rsstring.h"
#include <iomanip>
int displayUdpRelayPacketHeader(const void *data, const int size);
#endif
@ -888,19 +888,19 @@ int displayUdpRelayPacketHeader(const void *data, const int size)
dsize = size;
}
std::ostringstream out;
for(int i = 0; i < dsize; i++)
{
std::string out;
for(int i = 0; i < dsize; i++)
{
if ((i > 0) && (i % 16 == 0))
{
out << std::endl;
out += "\n";
}
out << std::setw(2) << std::setfill('0') << std::hex << (uint32_t) ((uint8_t*) data)[i];
}
rs_sprintf_append(out, "%02x", (uint32_t) ((uint8_t*) data)[i]);
}
std::cerr << "displayUdpRelayPacketHeader()" << std::endl;
std::cerr << out.str();
std::cerr << out;
std::cerr << std::endl;
return 1;

View File

@ -25,10 +25,10 @@
#include "tcponudp/udpstunner.h"
#include <iostream>
#include <sstream>
#include "util/rsrandom.h"
#include "util/rsprint.h"
#include "util/rsstring.h"
static const int STUN_TTL = 64;
@ -117,7 +117,7 @@ int UdpStunner::grabExclusiveMode(std::string holder) /* returns seconds since
#ifdef DEBUG_UDP_STUNNER_FILTER
std::cerr << "UdpStunner::grabExclusiveMode();"
std::cerr << "UdpStunner::grabExclusiveMode()";
std::cerr << std::endl;
#endif
@ -464,14 +464,12 @@ int UdpStunner::doStun(struct sockaddr_in stun_addr)
}
#ifdef DEBUG_UDP_STUNNER
std::ostringstream out;
out << "UdpStunner::doStun() Sent Stun Packet(" << sentlen << ") ";
out << " to:";
out << inet_ntoa(stun_addr.sin_addr) << ":" << ntohs(stun_addr.sin_port);
std::string out;
rs_sprintf(out, "UdpStunner::doStun() Sent Stun Packet(%d) to:%s:%u", sentlen, rs_inet_ntoa(stun_addr.sin_addr).c_str(), ntohs(stun_addr.sin_port));
std::cerr << out.str() << std::endl;
std::cerr << out << std::endl;
//pqioutput(PQL_ALERT, pqistunzone, out.str());
//pqioutput(PQL_ALERT, pqistunzone, out);
#endif
return 1;
@ -504,10 +502,9 @@ bool UdpStun_response(void *stun_pkt, int size, struct sockaddr_in &addr)
#ifdef DEBUG_UDP_STUNNER_FILTER
std::ostringstream out;
out << "UdpStunner::response() Recvd a Stun Response, ext_addr: ";
out << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port);
std::cerr << out.str() << std::endl;
std::string out;
rs_sprintf(out, "UdpStunner::response() Recvd a Stun Response, ext_addr: %s:%u", rs_inet_ntoa(addr.sin_addr).c_str(), ntohs(addr.sin_port));
std::cerr << out << std::endl;
#endif
return true;
@ -909,13 +906,11 @@ bool UdpStunner::attemptStun()
bool UdpStunner::locked_recvdStun(const struct sockaddr_in &remote, const struct sockaddr_in &extaddr)
{
#ifdef DEBUG_UDP_STUNNER
std::ostringstream out;
out << "UdpStunner::locked_recvdStun() from:";
out << inet_ntoa(remote.sin_addr) << ":" << ntohs(remote.sin_port);
out << " claiming ExtAddr is:";
out << inet_ntoa(extaddr.sin_addr) << ":" << ntohs(extaddr.sin_port);
std::string out;
rs_sprintf(out, "UdpStunner::locked_recvdStun() from:%s:%u", rs_inet_ntoa(remote.sin_addr).c_str(), ntohs(remote.sin_port));
rs_sprintf_append(out, " claiming ExtAddr is:%s:%u", rs_inet_ntoa(extaddr.sin_addr).c_str(), ntohs(extaddr.sin_port));
std::cerr << out.str() << std::endl;
std::cerr << out << std::endl;
#endif
#ifdef UDPSTUN_ALLOW_LOCALNET
@ -1016,9 +1011,8 @@ bool UdpStunner::locked_recvdStun(const struct sockaddr_in &remote, const str
bool UdpStunner::locked_checkExternalAddress()
{
#ifdef DEBUG_UDP_STUNNER
std::ostringstream out;
out << "UdpStunner::locked_checkExternalAddress()";
std::cerr << out.str() << std::endl;
std::string out = "UdpStunner::locked_checkExternalAddress()";
std::cerr << out << std::endl;
#endif
bool found1 = false;
@ -1128,28 +1122,25 @@ bool UdpStunner::locked_checkExternalAddress()
bool UdpStunner::locked_printStunList()
{
#ifdef DEBUG_UDP_STUNNER
std::ostringstream out;
std::string out = "locked_printStunList()\n";
time_t now = time(NULL);
out << "locked_printStunList()" << std::endl;
out << "\tLastSendStun: " << now - mStunLastSendStun << std::endl;
out << "\tLastSendAny: " << now - mStunLastSendAny << std::endl;
out << "\tLastRecvResp: " << now - mStunLastRecvResp << std::endl;
out << "\tLastRecvAny: " << now - mStunLastRecvAny << std::endl;
rs_sprintf_append(out, "\tLastSendStun: %ld\n", now - mStunLastSendStun);
rs_sprintf_append(out, "\tLastSendAny: %ld\n", now - mStunLastSendAny);
rs_sprintf_append(out, "\tLastRecvResp: %ld\n", now - mStunLastRecvResp);
rs_sprintf_append(out, "\tLastRecvAny: %ld\n", now - mStunLastRecvAny);
std::list<TouStunPeer>::iterator it;
for(it = mStunList.begin(); it != mStunList.end(); it++)
{
out << "id:" << RsUtil::BinToHex(it->id) << " addr: " << inet_ntoa(it->remote.sin_addr);
out << ":" << htons(it->remote.sin_port);
out << " eaddr: " << inet_ntoa(it->eaddr.sin_addr);
out << ":" << htons(it->eaddr.sin_port);
out << " failCount: " << it->failCount;
out << " lastSend: " << now - it->lastsend;
out << std::endl;
out += "id:" + RsUtil::BinToHex(it->id);
rs_sprintf_append(out, " addr: %s:%u", rs_inet_ntoa(it->remote.sin_addr).c_str(), htons(it->remote.sin_port));
rs_sprintf_append(out, " eaddr: %s:%u", rs_inet_ntoa(it->eaddr.sin_addr).c_str(), htons(it->eaddr.sin_port));
rs_sprintf_append(out, " failCount: %lu", it->failCount);
rs_sprintf_append(out, " lastSend: %ld\n", now - it->lastsend);
}
std::cerr << out.str();
std::cerr << out;
#endif
return true;

View File

@ -71,9 +71,6 @@ bool isLoopbackNet(const struct in_addr *addr);
bool isPrivateNet(const struct in_addr *addr);
bool isExternalNet(const struct in_addr *addr);
/* convert addresses */
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr);
std::ostream& operator<<(std::ostream& o,const struct sockaddr_in&) ;
/* thread-safe version of inet_ntoa */