Removed some std::ostringstream.

To be continued.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5097 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-04-14 00:30:23 +00:00
parent 3b85873313
commit 545743ad77
17 changed files with 506 additions and 947 deletions

View File

@ -23,13 +23,10 @@
* *
*/ */
#include "pqi/pqihandler.h" #include "pqi/pqihandler.h"
#include <sstream>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include "util/rsstring.h"
#include <stdlib.h> #include <stdlib.h>
const int pqihandlerzone = 34283; const int pqihandlerzone = 34283;
@ -51,13 +48,7 @@ pqihandler::pqihandler(SecurityPolicy *Global) : pqiQoS(PQI_HANDLER_NB_PRIORITY_
// cannot be enabled by module. // cannot be enabled by module.
globsec = Global; globsec = Global;
{ pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, "New pqihandler()\nSecurity Policy: " + secpolicy_print(globsec));
std::ostringstream out;
out << "New pqihandler()" << std::endl;
out << "Security Policy: " << secpolicy_print(globsec);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
}
// setup minimal total+individual rates. // setup minimal total+individual rates.
rateIndiv_out = 0.01; rateIndiv_out = 0.01;
@ -171,17 +162,15 @@ int pqihandler::status()
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
{ // for output { // for output
std::ostringstream out; std::string out = "pqihandler::status() Active Modules:\n";
out << "pqihandler::status() Active Modules:" << std::endl;
// display all interfaces... // display all interfaces...
for(it = mods.begin(); it != mods.end(); it++) for(it = mods.begin(); it != mods.end(); it++)
{ {
out << "\tModule [" << it -> first << "] Pointer <"; rs_sprintf_append(out, "\tModule [%s] Pointer <%p>", it -> first.c_str(), (void *) ((it -> second) -> pqi));
out << (void *) ((it -> second) -> pqi) << ">" << std::endl;
} }
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
} // end of output. } // end of output.
@ -194,8 +183,6 @@ int pqihandler::status()
return 1; return 1;
} }
bool pqihandler::AddSearchModule(SearchModule *mod) bool pqihandler::AddSearchModule(SearchModule *mod)
{ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
@ -204,27 +191,21 @@ bool pqihandler::AddSearchModule(SearchModule *mod)
if (mod->peerid != mod->pqi->PeerId()) if (mod->peerid != mod->pqi->PeerId())
{ {
// ERROR! // ERROR!
std::ostringstream out; pqioutput(PQL_ALERT, pqihandlerzone, "ERROR peerid != PeerId!");
out << "ERROR peerid != PeerId!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false; return false;
} }
if (mod->peerid == "") if (mod->peerid == "")
{ {
// ERROR! // ERROR!
std::ostringstream out; pqioutput(PQL_ALERT, pqihandlerzone, "ERROR peerid == NULL");
out << "ERROR peerid == NULL" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false; return false;
} }
if (mods.find(mod->peerid) != mods.end()) if (mods.find(mod->peerid) != mods.end())
{ {
// ERROR! // ERROR!
std::ostringstream out; pqioutput(PQL_ALERT, pqihandlerzone, "ERROR PeerId Module already exists!");
out << "ERROR PeerId Module already exists!" << std::endl;
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
return false; return false;
} }
@ -280,12 +261,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
if (allowglobal) if (allowglobal)
{ {
/* error */ /* error */
std::ostringstream out; std::string out = "pqihandler::HandleSearchItem() Cannot send out Global RsItem";
out << "pqihandler::HandleSearchItem()"; pqioutput(PQL_ALERT, pqihandlerzone, out);
out << " Cannot send out Global RsItem";
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << out.str(); std::cerr << out << std::endl;
#endif #endif
delete item; delete item;
return -1; return -1;
@ -293,15 +272,13 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
if (!locked_checkOutgoingRsItem(item, allowglobal)) if (!locked_checkOutgoingRsItem(item, allowglobal))
{ {
std::ostringstream out; std::string out = "pqihandler::HandleRsItem() checkOutgoingPQItem Failed on item: \n";
out << "pqihandler::HandleRsItem() checkOutgoingPQItem";
out << " Failed on item: " << std::endl;
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << out.str(); std::cerr << out;
#endif #endif
item -> print(out); item -> print_string(out);
pqioutput(PQL_ALERT, pqihandlerzone, out.str()); pqioutput(PQL_ALERT, pqihandlerzone, out);
delete item; delete item;
return -1; return -1;
} }
@ -316,11 +293,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
// find module. // find module.
if ((it = mods.find(item->PeerId())) == mods.end()) if ((it = mods.find(item->PeerId())) == mods.end())
{ {
std::ostringstream out; std::string out = "pqihandler::HandleRsItem() Invalid chan!";
out << "pqihandler::HandleRsItem() Invalid chan!"; pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << out.str(); std::cerr << out << std::endl;
#endif #endif
delete item; delete item;
@ -330,12 +306,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
// check security... is output allowed. // check security... is output allowed.
if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING)) if(0 < secpolicy_check((it -> second) -> sp, 0, PQI_OUTGOING))
{ {
std::ostringstream out; std::string out = "pqihandler::HandleRsItem() sending to chan: " + it -> first;
out << "pqihandler::HandleRsItem() sending to chan:"; pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
out << it -> first << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << out.str(); std::cerr << out << std::endl;
#endif #endif
// if yes send on item. // if yes send on item.
@ -344,12 +318,10 @@ int pqihandler::locked_HandleRsItem(RsItem *item, int allowglobal,uint32_t& comp
} }
else else
{ {
std::ostringstream out; std::string out = "pqihandler::HandleRsItem() Sec not approved";
out << "pqihandler::HandleRsItem()"; pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out);
out << " Sec not approved";
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
#ifdef DEBUG_TICK #ifdef DEBUG_TICK
std::cerr << out.str(); std::cerr << out << std::endl;
#endif #endif
delete item; delete item;
@ -439,13 +411,12 @@ int pqihandler::locked_GetItems()
while((item = (mod -> pqi) -> GetItem()) != NULL) while((item = (mod -> pqi) -> GetItem()) != NULL)
{ {
#ifdef RSITEM_DEBUG #ifdef RSITEM_DEBUG
std::ostringstream out; std::string out;
out << "pqihandler::GetItems() Incoming Item "; rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
out << " from: " << mod -> pqi << std::endl; item -> print_string(out);
item -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out.str()); pqihandlerzone, out);
#endif #endif
if (item->PeerId() != (mod->pqi)->PeerId()) if (item->PeerId() != (mod->pqi)->PeerId())
@ -465,16 +436,13 @@ int pqihandler::locked_GetItems()
// not allowed to recieve from here.... // not allowed to recieve from here....
while((item = (mod -> pqi) -> GetItem()) != NULL) while((item = (mod -> pqi) -> GetItem()) != NULL)
{ {
std::ostringstream out; std::string out;
out << "pqihandler::GetItems() Incoming Item "; rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
out << " from: " << mod -> pqi << std::endl; item -> print_string(out);
item -> print(out); out += "\nItem Not Allowed (Sec Pol). deleting!";
out << std::endl;
out << "Item Not Allowed (Sec Pol). deleting!";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqioutput(PQL_DEBUG_BASIC,
pqihandlerzone, out.str()); pqihandlerzone, out);
delete item; delete item;
} }
@ -483,9 +451,6 @@ int pqihandler::locked_GetItems()
return count; return count;
} }
void pqihandler::locked_SortnStoreItem(RsItem *item) void pqihandler::locked_SortnStoreItem(RsItem *item)
{ {
/* get class type / subtype out of the item */ /* get class type / subtype out of the item */

View File

@ -4,8 +4,6 @@
#include "pqi/pqinetstatebox.h" #include "pqi/pqinetstatebox.h"
#include "time.h" #include "time.h"
#include <sstream>
// External Interface. // External Interface.
void pqiNetStateBox::setAddressStunDht(struct sockaddr_in *addr, bool stable) void pqiNetStateBox::setAddressStunDht(struct sockaddr_in *addr, bool stable)
@ -690,28 +688,28 @@ std::string NetStateNatHoleString(uint32_t natHole)
std::string NetStateConnectModesString(uint32_t connect) std::string NetStateConnectModesString(uint32_t connect)
{ {
std::ostringstream connOut; std::string connOut;
if (connect & RSNET_CONNECT_OUTGOING_TCP) if (connect & RSNET_CONNECT_OUTGOING_TCP)
{ {
connOut << "TCP_OUT "; connOut += "TCP_OUT ";
} }
if (connect & RSNET_CONNECT_ACCEPT_TCP) if (connect & RSNET_CONNECT_ACCEPT_TCP)
{ {
connOut << "TCP_IN "; connOut += "TCP_IN ";
} }
if (connect & RSNET_CONNECT_DIRECT_UDP) if (connect & RSNET_CONNECT_DIRECT_UDP)
{ {
connOut << "DIRECT_UDP "; connOut += "DIRECT_UDP ";
} }
if (connect & RSNET_CONNECT_PROXY_UDP) if (connect & RSNET_CONNECT_PROXY_UDP)
{ {
connOut << "PROXY_UDP "; connOut += "PROXY_UDP ";
} }
if (connect & RSNET_CONNECT_RELAY_UDP) if (connect & RSNET_CONNECT_RELAY_UDP)
{ {
connOut << "RELAY_UDP "; connOut += "RELAY_UDP ";
} }
return connOut.str(); return connOut;
} }

View File

@ -35,7 +35,7 @@
#include <unistd.h> #include <unistd.h>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <sstream> #include "util/rsstring.h"
#include <iomanip> #include <iomanip>
static const int pqinetzone = 96184; static const int pqinetzone = 96184;
@ -56,12 +56,10 @@ int errno;
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
std::ostream &showSocketError(std::ostream &out) void showSocketError(std::string &out)
{ {
int err = errno; int err = errno;
out << "\tSocket Error(" << err << ") : "; rs_sprintf_append(out, "\tSocket Error(%d) : %s\n", err, socket_errorType(err).c_str());
out << socket_errorType(err) << std::endl;
return out;
} }
std::string socket_errorType(int err) std::string socket_errorType(int err)
@ -178,10 +176,9 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
if(ioctl(sock, SIOCGIFADDR, &ifreq) != 0) if(ioctl(sock, SIOCGIFADDR, &ifreq) != 0)
{ {
std::ostringstream out; std::string out;
out << "Cannot Determine Address for Iface: "; rs_sprintf(out, "Cannot Determine Address for Iface: %s", ifptr -> if_name);
out << ifptr -> if_name << std::endl; pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
} }
else else
{ {
@ -189,12 +186,9 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
(struct sockaddr_in *) &ifreq.ifr_addr; (struct sockaddr_in *) &ifreq.ifr_addr;
std::string astr =rs_inet_ntoa(aptr -> sin_addr); std::string astr =rs_inet_ntoa(aptr -> sin_addr);
std::ostringstream out; std::string out;
out << "Iface: "; rs_sprintf(out, "Iface: %s\n Address: %s", ifptr -> if_name, astr.c_str());
out << ifptr -> if_name << std::endl; pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
out << " Address: " << astr;
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
// Now check wether the interface is up and running. If not, we don't use it!! // Now check wether the interface is up and running. If not, we don't use it!!
// //
@ -223,12 +217,10 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#else #else
std::ostream &showSocketError(std::ostream &out) void showSocketError(std::string &out)
{ {
int err = WSAGetLastError(); int err = WSAGetLastError();
out << "\tSocket Error(" << err << ") : "; rs_sprintf_append(out, "\tSocket Error(%d) : %s\n", err, socket_errorType(err).c_str());
out << socket_errorType(err) << std::endl;
return out;
} }
@ -356,13 +348,11 @@ bool getLocalInterfaces(std::list<struct in_addr> &addrs)
for(unsigned int i = 0; i < iptable -> dwNumEntries; i++) for(unsigned int i = 0; i < iptable -> dwNumEntries; i++)
{ {
std::ostringstream out; std::string out;
out << "Iface(" << iptable->table[i].dwIndex << ") ";
addr.s_addr = iptable->table[i].dwAddr; addr.s_addr = iptable->table[i].dwAddr;
out << " => " << rs_inet_ntoa(addr); rs_sprintf(out, "Iface(%ld) => %s\n", iptable->table[i].dwIndex, rs_inet_ntoa(addr).c_str());
out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
addrs.push_back(addr); addrs.push_back(addr);
} }
@ -501,12 +491,9 @@ int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 )
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 ) int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 )
{ {
#ifdef NET_DEBUG #ifdef NET_DEBUG
std::ostringstream out; std::string out;
out << "inaddr_cmp(" << rs_inet_ntoa(addr1.sin_addr); rs_sprintf(out, "inaddr_cmp(%s-%lu,%s-%lu)", rs_inet_ntoa(addr1.sin_addr).c_str(), addr1.sin_addr.s_addr, rs_inet_ntoa(addr2.sin_addr).c_str(), addr2.sin_addr.s_addr);
out << "-" << addr1.sin_addr.s_addr; pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
out << "," << rs_inet_ntoa(addr2.sin_addr);
out << "-" << addr2.sin_addr.s_addr << ")" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
#endif #endif
@ -525,13 +512,9 @@ int inaddr_cmp(struct sockaddr_in addr1, unsigned long addr2)
struct in_addr inaddr_tmp; struct in_addr inaddr_tmp;
inaddr_tmp.s_addr = addr2; inaddr_tmp.s_addr = addr2;
std::ostringstream out; std::string out;
out << "inaddr_cmp2(" << rs_inet_ntoa(addr1.sin_addr); rs_sprintf(out, "inaddr_cmp2(%s vs %s /or/ %10x vs %10x)", rs_inet_ntoa(addr1.sin_addr).c_str(), rs_inet_ntoa(inaddr_tmp).c_str(), addr1.sin_addr.s_addr, addr2);
out << " vs " << rs_inet_ntoa(inaddr_tmp); pqioutput(PQL_DEBUG_BASIC, pqinetzone, out);
out << " /or/ ";
out << std::hex << std::setw(10) << addr1.sin_addr.s_addr;
out << " vs " << std::setw(10) << addr2 << ")" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
#endif #endif
if (addr1.sin_addr.s_addr == addr2) if (addr1.sin_addr.s_addr == addr2)

View File

@ -96,7 +96,7 @@ extern int errno; /* Define extern errno, to duplicate unix behaviour */
// Same def - different functions... // Same def - different functions...
std::ostream &showSocketError(std::ostream &out); void showSocketError(std::string &out);
std::string socket_errorType(int err); std::string socket_errorType(int err);
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 ); int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 );

View File

@ -30,7 +30,7 @@
const int pqipersonzone = 82371; const int pqipersonzone = 82371;
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <sstream> #include "util/rsstring.h"
/**** /****
* #define PERSON_DEBUG * #define PERSON_DEBUG
@ -63,25 +63,23 @@ pqiperson::~pqiperson()
// The PQInterface interface. // The PQInterface interface.
int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size) int pqiperson::SendItem(RsItem *i,uint32_t& serialized_size)
{ {
std::ostringstream out; std::string out = "pqiperson::SendItem()";
out << "pqiperson::SendItem()";
if (active) if (active)
{ {
out << " Active: Sending On" << std::endl; out += " Active: Sending On\n";
i->print(out, 5); i->print_string(out, 5);
#ifdef PERSON_DEBUG #ifdef PERSON_DEBUG
std::cerr << out.str() << std::endl; std::cerr << out << std::endl;
#endif #endif
return activepqi -> SendItem(i,serialized_size); return activepqi -> SendItem(i,serialized_size);
} }
else else
{ {
out << " Not Active: Used to put in ToGo Store"; out += " Not Active: Used to put in ToGo Store\n";
out << std::endl; out += " Now deleting...";
out << " Now deleting...";
delete i; delete i;
} }
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
return 0; // queued. return 0; // queued.
} }
@ -116,23 +114,19 @@ int pqiperson::tick()
(time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5) (time(NULL) - lastHeartbeatReceived) > HEARTBEAT_REPEAT_TIME * 5)
{ {
int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS(); int ageLastIncoming = time(NULL) - activepqi->getLastIncomingTS();
std::ostringstream out; std::string out = "pqiperson::tick() WARNING No heartbeat from: " + PeerId();
out << "pqiperson::tick() WARNING No heartbeat from: " << PeerId();
//out << " assume dead. calling pqissl::reset(), LastHeartbeat was: "; //out << " assume dead. calling pqissl::reset(), LastHeartbeat was: ";
out << " LastHeartbeat was: "; rs_sprintf_append(out, " LastHeartbeat was: %ld secs ago", time(NULL) - lastHeartbeatReceived);
out << time(NULL) - lastHeartbeatReceived << " secs ago"; rs_sprintf_append(out, " LastIncoming was: %d secs ago", ageLastIncoming);
out << " LastIncoming was: "; pqioutput(PQL_WARNING, pqipersonzone, out);
out << ageLastIncoming << " secs ago";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
#define NO_PACKET_TIMEOUT 60 #define NO_PACKET_TIMEOUT 60
if (ageLastIncoming > NO_PACKET_TIMEOUT) if (ageLastIncoming > NO_PACKET_TIMEOUT)
{ {
std::ostringstream out2; out = "pqiperson::tick() " + PeerId();
out2 << "pqiperson::tick() " << PeerId(); out += " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()";
out2 << " No Heartbeat & No Packets -> assume dead. calling pqissl::reset()"; pqioutput(PQL_WARNING, pqipersonzone, out);
pqioutput(PQL_WARNING, pqipersonzone, out2.str());
this->reset(); this->reset();
} }
@ -142,22 +136,20 @@ int pqiperson::tick()
int activeTick = 0; int activeTick = 0;
{ {
std::ostringstream out; std::string out = "pqiperson::tick() Id: " + PeerId() + " ";
out << "pqiperson::tick() Id: " << PeerId() << " ";
if (active) if (active)
out << "***Active***"; out += "***Active***";
else else
out << ">>InActive<<"; out += ">>InActive<<";
out << std::endl; out += "\n";
out << "Activepqi: " << activepqi << " inConnectAttempt: "; rs_sprintf_append(out, "Activepqi: %p inConnectAttempt: ", activepqi);
if (inConnectAttempt) if (inConnectAttempt)
out << "In Connection Attempt"; out += "In Connection Attempt";
else else
out << " Not Connecting "; out += " Not Connecting ";
out << std::endl; out += "\n";
// tick the children. // tick the children.
std::map<uint32_t, pqiconnect *>::iterator it; std::map<uint32_t, pqiconnect *>::iterator it;
@ -167,10 +159,10 @@ int pqiperson::tick()
{ {
activeTick = 1; activeTick = 1;
} }
out << "\tTicking Child: " << (it->first) << std::endl; rs_sprintf_append(out, "\tTicking Child: %d\n", it->first);
} }
pqioutput(PQL_DEBUG_ALL, pqipersonzone, out.str()); pqioutput(PQL_DEBUG_ALL, pqipersonzone, out);
} // end of pqioutput. } // end of pqioutput.
return activeTick; return activeTick;
@ -182,13 +174,11 @@ int pqiperson::tick()
int pqiperson::notifyEvent(NetInterface *ni, int newState) int pqiperson::notifyEvent(NetInterface *ni, int newState)
{ {
{ {
std::ostringstream out; std::string out = "pqiperson::notifyEvent() Id: " + PeerId() + "\n";
out << "pqiperson::notifyEvent() Id: " << PeerId(); rs_sprintf_append(out, "Message: %d from: %p\n", newState, ni);
out << std::endl; rs_sprintf_append(out, "Active pqi : %p", activepqi);
out << "Message: " << newState << " from: " << ni << std::endl;
out << "Active pqi : " << activepqi;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
} }
/* find the pqi, */ /* find the pqi, */
@ -200,14 +190,10 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
int i = 0; int i = 0;
for(it = kids.begin(); it != kids.end(); it++) for(it = kids.begin(); it != kids.end(); it++)
{ {
std::ostringstream out; std::string out;
out << "pqiperson::connectattempt() Kid# "; rs_sprintf(out, "pqiperson::connectattempt() Kid# %d of %u\n", i, kids.size());
out << i << " of " << kids.size(); rs_sprintf_append(out, " type: %u in_ni: %p", it->first, ni);
out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
out << " type: " << (it->first);
//out << " ni: " << (it->second)->ni;
out << " in_ni: " << ni;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
i++; i++;
if ((it->second)->thisNetInterface(ni)) if ((it->second)->thisNetInterface(ni))
@ -238,12 +224,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
if ((active) && (activepqi != pqi)) // already connected - trouble if ((active) && (activepqi != pqi)) // already connected - trouble
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS+active-> activing new connection, shutting others");
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_SUCCESS+active-> activing new connection, shutting others";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
// This is the RESET that's killing the connections..... // This is the RESET that's killing the connections.....
//activepqi -> reset(); //activepqi -> reset();
@ -255,12 +236,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
/* now install a new one. */ /* now install a new one. */
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_SUCCESS->marking so! (resetting others)");
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_SUCCESS->marking so! (resetting others)";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
// mark as active. // mark as active.
active = true; active = true;
@ -273,9 +249,9 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
{ {
if (!(it->second)->thisNetInterface(ni)) if (!(it->second)->thisNetInterface(ni))
{ {
std::ostringstream out; std::string out;
out << "Resetting pqi ref : " << &(it->second) << std::endl; rs_sprintf(out, "Resetting pqi ref : %p", &(it->second));
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
it->second->reset(); it->second->reset();
} else { } else {
//std::cerr << "Active pqi : not resetting." << std::endl; //std::cerr << "Active pqi : not resetting." << std::endl;
@ -293,34 +269,19 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
{ {
if (activepqi == pqi) if (activepqi == pqi)
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED->marking so!");
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED->marking so!";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
active = false; active = false;
activepqi = NULL; activepqi = NULL;
} }
else else
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !");
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
} }
} }
else else
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::notifyEvent() Id: " + PeerId() + " CONNECT_FAILED+NOT active -> try connect again");
std::ostringstream out;
out << "pqiperson::notifyEvent() Id: " << PeerId();
out << " CONNECT_FAILED+NOT active -> try connect again";
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
} }
/* notify up */ /* notify up */
@ -344,11 +305,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
int pqiperson::reset() int pqiperson::reset()
{ {
{ pqioutput(PQL_WARNING, pqipersonzone, "pqiperson::reset() resetting all pqiconnect for Id: " + PeerId());
std::ostringstream out;
out << "pqiperson::reset() resetting all pqiconnect for Id: " << PeerId();
pqioutput(PQL_WARNING, pqipersonzone, out.str());
}
std::map<uint32_t, pqiconnect *>::iterator it; std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++) for(it = kids.begin(); it != kids.end(); it++)
@ -366,10 +323,9 @@ int pqiperson::reset()
int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi) int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
{ {
{ {
std::ostringstream out; std::string out;
out << "pqiperson::addChildInterface() : Id " << PeerId() << " " << type; rs_sprintf(out, "pqiperson::addChildInterface() : Id %s %u", PeerId().c_str(), type);
out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out);
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
} }
kids[type] = pqi; kids[type] = pqi;
@ -382,12 +338,7 @@ int pqiperson::addChildInterface(uint32_t type, pqiconnect *pqi)
int pqiperson::listen() int pqiperson::listen()
{ {
{ pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::listen() Id: " + PeerId());
std::ostringstream out;
out << "pqiperson::listen() Id: " << PeerId();
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
}
if (!active) if (!active)
{ {
@ -404,12 +355,7 @@ int pqiperson::listen()
int pqiperson::stoplistening() int pqiperson::stoplistening()
{ {
{ pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::stoplistening() Id: " + PeerId());
std::ostringstream out;
out << "pqiperson::stoplistening() Id: " << PeerId();
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
}
std::map<uint32_t, pqiconnect *>::iterator it; std::map<uint32_t, pqiconnect *>::iterator it;
for(it = kids.begin(); it != kids.end(); it++) for(it = kids.begin(); it != kids.end(); it++)
@ -427,20 +373,18 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
#ifdef PERSON_DEBUG #ifdef PERSON_DEBUG
#endif #endif
{ {
std::ostringstream out; std::string out = "pqiperson::connect() Id: " + PeerId();
out << "pqiperson::connect() Id: " << PeerId(); rs_sprintf_append(out, " type: %u", type);
out << " type: " << type; rs_sprintf_append(out, " addr: %s:%u", rs_inet_ntoa(raddr.sin_addr).c_str(), ntohs(raddr.sin_port));
out << " addr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port); rs_sprintf_append(out, " proxyaddr: %s:%u", rs_inet_ntoa(proxyaddr.sin_addr).c_str(), ntohs(proxyaddr.sin_port));
out << " proxyaddr: " << rs_inet_ntoa(proxyaddr.sin_addr) << ":" << ntohs(proxyaddr.sin_port); rs_sprintf_append(out, " srcaddr: %s:%u", rs_inet_ntoa(srcaddr.sin_addr).c_str(), ntohs(srcaddr.sin_port));
out << " srcaddr: " << rs_inet_ntoa(srcaddr.sin_addr) << ":" << ntohs(srcaddr.sin_port); rs_sprintf_append(out, " delay: %u", delay);
out << " delay: " << delay; rs_sprintf_append(out, " period: %u", period);
out << " period: " << period; rs_sprintf_append(out, " timeout: %u", timeout);
out << " timeout: " << timeout; rs_sprintf_append(out, " flags: %u", flags);
out << " flags: " << flags; rs_sprintf_append(out, " bandwidth: %u", bandwidth);
out << " bandwidth: " << bandwidth;
out << std::endl;
//std::cerr << out.str(); //std::cerr << out.str();
pqioutput(PQL_WARNING, pqipersonzone, out.str()); pqioutput(PQL_WARNING, pqipersonzone, out);
} }
std::map<uint32_t, pqiconnect *>::iterator it; std::map<uint32_t, pqiconnect *>::iterator it;
@ -449,12 +393,7 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
if (it == kids.end()) if (it == kids.end())
{ {
#ifdef PERSON_DEBUG #ifdef PERSON_DEBUG
std::ostringstream out; //pqioutput(PQL_DEBUG_BASIC, pqipersonzone, "pqiperson::connect() missing pqiconnect");
out << "pqiperson::connect()";
out << " missing pqiconnect";
out << std::endl;
std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
#endif #endif
/* notify of fail! */ /* notify of fail! */

View File

@ -27,7 +27,6 @@
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <sstream>
#include <stdio.h> #include <stdio.h>
const int pqipersongrpzone = 354; const int pqipersongrpzone = 354;
@ -61,11 +60,8 @@ int pqipersongrp::tickServiceRecv()
{ {
RsRawItem *pqi = NULL; RsRawItem *pqi = NULL;
int i = 0; int i = 0;
{
std::ostringstream out; pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, "pqipersongrp::tickTunnelServer()");
out << "pqipersongrp::tickTunnelServer()";
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
//p3ServiceServer::tick(); //p3ServiceServer::tick();
@ -89,11 +85,8 @@ int pqipersongrp::tickServiceSend()
{ {
RsRawItem *pqi = NULL; RsRawItem *pqi = NULL;
int i = 0; int i = 0;
{
std::ostringstream out; pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, "pqipersongrp::tickServiceSend()");
out << "pqipersongrp::tickServiceSend()";
pqioutput(PQL_DEBUG_ALL, pqipersongrpzone, out.str());
}
p3ServiceServer::tick(); p3ServiceServer::tick();
@ -390,11 +383,7 @@ void pqipersongrp::statusChanged()
int pqipersongrp::addPeer(std::string id) int pqipersongrp::addPeer(std::string id)
{ {
{ pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrp::addPeer() PeerId: " + id);
std::ostringstream out;
out << "pqipersongrp::addPeer() PeerId: " << id;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
std::cerr << "pqipersongrp::addPeer() id: " << id; std::cerr << "pqipersongrp::addPeer() id: " << id;
std::cerr << std::endl; std::cerr << std::endl;
@ -707,11 +696,7 @@ pqilistener * pqipersongrpDummy::createListener(struct sockaddr_in /*laddr*/)
pqiperson * pqipersongrpDummy::createPerson(std::string id, pqilistener */*listener*/) pqiperson * pqipersongrpDummy::createPerson(std::string id, pqilistener */*listener*/)
{ {
{ pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, "pqipersongrpDummy::createPerson() PeerId: " + id);
std::ostringstream out;
out << "pqipersongrpDummy::createPerson() PeerId: " << id;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
pqiperson *pqip = new pqiperson(id, this); pqiperson *pqip = new pqiperson(id, this);

View File

@ -25,7 +25,7 @@
#include "pqi/pqiservice.h" #include "pqi/pqiservice.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <sstream> #include "util/rsstring.h"
const int pqiservicezone = 60478; const int pqiservicezone = 60478;
@ -77,16 +77,10 @@ int p3ServiceServer::incoming(RsRawItem *item)
"p3ServiceServer::incoming()"); "p3ServiceServer::incoming()");
{ {
std::ostringstream out; std::string out;
out << "p3ServiceServer::incoming() PacketId: "; rs_sprintf(out, "p3ServiceServer::incoming() PacketId: %x\nLooking for Service: %x\nItem:\n", item -> PacketId(), (item -> PacketId() & 0xffffff00));
out << std::hex << item -> PacketId() << std::endl; item -> print_string(out);
out << "Looking for Service: "; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
out << (item -> PacketId() & 0xffffff00) << std::dec << std::endl;
out << "Item:" << std::endl;
item -> print(out);
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
} }
#endif #endif
@ -108,10 +102,9 @@ int p3ServiceServer::incoming(RsRawItem *item)
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::ostringstream out; std::string out;
out << "p3ServiceServer::incoming() Sending to"; rs_sprintf(out, "p3ServiceServer::incoming() Sending to %p", it -> second);
out << it -> second << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
#endif #endif
return (it->second) -> receive(item); return (it->second) -> receive(item);
@ -152,14 +145,12 @@ RsRawItem *p3ServiceServer::outgoing()
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::ostringstream out; std::string out;
out << "p3ServiceServer::outgoing() Got Item From:"; rs_sprintf(out, "p3ServiceServer::outgoing() Got Item From: %p\n", rrit -> second);
out << rrit -> second << std::endl;
item -> print(out); item -> print_string(out);
out << std::endl; std::cerr << out << std::endl;
std::cerr << out.str(); pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
#endif #endif
return item; return item;
@ -173,14 +164,12 @@ RsRawItem *p3ServiceServer::outgoing()
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::ostringstream out; std::string out;
out << "p3ServiceServer::outgoing() Got Item From:"; rs_sprintf(out, "p3ServiceServer::outgoing() Got Item From: %p\n", rrit -> second);
out << rrit -> second << std::endl;
item -> print(out); item -> print_string(out);
out << std::endl; pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out);
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str()); std::cerr << out << std::endl;
std::cerr << out.str();
#endif #endif
return item; return item;
@ -208,11 +197,9 @@ int p3ServiceServer::tick()
{ {
#ifdef SERVICE_DEBUG #ifdef SERVICE_DEBUG
std::ostringstream out; std::string out;
out << "p3ServiceServer::service id:" << it -> first; rs_sprintf(out, "p3ServiceServer::service id: %u -> Service: %p", it -> first, it -> second);
out << " -> Service: " << it -> second; pqioutput(PQL_DEBUG_ALL, pqiservicezone, out);
out << std::endl;
pqioutput(PQL_DEBUG_ALL, pqiservicezone, out.str());
#endif #endif
// now we should actually tick the service. // now we should actually tick the service.

View File

@ -23,23 +23,18 @@
* *
*/ */
#include "pqi/pqissl.h" #include "pqi/pqissl.h"
#include "pqi/pqinetwork.h" #include "pqi/pqinetwork.h"
#include "pqi/sslfns.h" #include "pqi/sslfns.h"
#include "util/rsnet.h" #include "util/rsnet.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include "util/rsstring.h"
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <sstream>
#include "pqi/pqissllistener.h" #include "pqi/pqissllistener.h"
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
@ -66,10 +61,6 @@ const int PQISSL_REMOTE_FLAG = 0x02;
const int PQISSL_UDP_FLAG = 0x02; const int PQISSL_UDP_FLAG = 0x02;
***********/ ***********/
static const int PQISSL_MAX_READ_ZERO_COUNT = 20; static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
static const time_t PQISSL_MAX_READ_ZERO_TIME = 15; // 15 seconds of no data => reset. (atm HeartBeat pkt sent 5 secs) static const time_t PQISSL_MAX_READ_ZERO_TIME = 15; // 15 seconds of no data => reset. (atm HeartBeat pkt sent 5 secs)
@ -115,11 +106,7 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3LinkMgr *lm)
sockaddr_clear(&remote_addr); sockaddr_clear(&remote_addr);
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl for PeerId: " + PeerId());
std::ostringstream out;
out << "pqissl for PeerId: " << PeerId();
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
}
#endif #endif
#if 0 #if 0
@ -203,7 +190,7 @@ int pqissl::close()
// put back on the listening queue. // put back on the listening queue.
int pqissl::reset() int pqissl::reset()
{ {
std::ostringstream outLog; std::string outLog;
/* a reset shouldn't cause us to stop listening /* a reset shouldn't cause us to stop listening
* only reasons for stoplistening() are; * only reasons for stoplistening() are;
@ -214,13 +201,13 @@ int pqissl::reset()
* *
*/ */
outLog << "pqissl::reset():" << PeerId(); outLog += "pqissl::reset():" + PeerId();
outLog << " (A: " << (int) active; rs_sprintf_append(outLog, " (A: %d", (int) active);
outLog << " FD: " << sockfd; rs_sprintf_append(outLog, " FD: %d", sockfd);
outLog << " W: " << waiting; rs_sprintf_append(outLog, " W: %d", waiting);
outLog << " SSL: " << ssl_connection << ") "; rs_sprintf_append(outLog, " SSL: %p) ", ssl_connection);
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
outLog << std::endl; outLog += "\n";
#endif #endif
bool neededReset = false; bool neededReset = false;
@ -238,8 +225,7 @@ int pqissl::reset()
if (sockfd > 0) if (sockfd > 0)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
outLog << "pqissl::reset() Shutting down (active) socket"; outLog += "pqissl::reset() Shutting down (active) socket\n";
outLog << std::endl;
#endif #endif
net_internal_close(sockfd); net_internal_close(sockfd);
sockfd = -1; sockfd = -1;
@ -258,13 +244,12 @@ int pqissl::reset()
if (neededReset) if (neededReset)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
outLog << "pqissl::reset() Reset Required!" << std::endl; outLog += "pqissl::reset() Reset Required!\n";
outLog << "pqissl::reset() Will Attempt notifyEvent(FAILED)"; outLog += "pqissl::reset() Will Attempt notifyEvent(FAILED)\n";
outLog << std::endl;
#endif #endif
} }
rslog(RSL_ALERT, pqisslzone, outLog.str()); rslog(RSL_ALERT, pqisslzone, outLog);
// notify people of problem! // notify people of problem!
// but only if we really shut something down. // but only if we really shut something down.
@ -283,20 +268,18 @@ bool pqissl::connect_parameter(uint32_t type, uint32_t value)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
std::ostringstream out; std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
out << "pqissl::connect_parameter() Peer: " << PeerId(); rs_sprintf_append(out, " type: %u value: %u", type, value);
out << " type: " << type << "value: " << value; rslog(RSL_DEBUG_ALL, pqisslzone, out);
rslog(RSL_DEBUG_ALL, pqisslzone, out.str());
} }
#endif #endif
if (type == NET_PARAM_CONNECT_DELAY) if (type == NET_PARAM_CONNECT_DELAY)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
std::ostringstream out; std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
out << "pqissl::connect_parameter() Peer: " << PeerId(); rs_sprintf_append(out, " DELAY: %u", value);
out << " DELAY: " << value; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
#endif #endif
@ -306,10 +289,9 @@ bool pqissl::connect_parameter(uint32_t type, uint32_t value)
else if (type == NET_PARAM_CONNECT_TIMEOUT) else if (type == NET_PARAM_CONNECT_TIMEOUT)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
std::ostringstream out; std::string out = "pqissl::connect_parameter() Peer: " + PeerId();
out << "pqissl::connect_parameter() Peer: " << PeerId(); rs_sprintf_append(out, " TIMEOUT: %u", value);
out << " TIMEOUT: " << value; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
#endif #endif
mConnectTimeout = value; mConnectTimeout = value;
@ -337,32 +319,26 @@ int pqissl::status()
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
std::ostringstream out; std::string out = "pqissl::status()";
out << "pqissl::status()";
if (active) if (active)
{ {
int alg; int alg;
out << " active: " << std::endl; out += " active: \n";
// print out connection. // print out connection.
out << "Connected TO : " << PeerId(); out += "Connected TO : " + PeerId() + "\n";
out << std::endl;
// print out cipher. // print out cipher.
out << "\t\tSSL Cipher:" << SSL_get_cipher(ssl_connection); rs_sprintf_append(out, "\t\tSSL Cipher:%s", SSL_get_cipher(ssl_connection));
out << " (" << SSL_get_cipher_bits(ssl_connection, &alg); rs_sprintf_append(out, " (%d:%d)", SSL_get_cipher_bits(ssl_connection, &alg), alg);
out << ":" << alg << ") "; rs_sprintf_append(out, "Vers:%s\n\n", SSL_get_cipher_version(ssl_connection));
out << "Vers:" << SSL_get_cipher_version(ssl_connection);
out << std::endl;
out << std::endl;
} }
else else
{ {
out << " Waiting for connection!" << std::endl; out += " Waiting for connection!\n";
} }
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif #endif
if (active) if (active)
@ -388,10 +364,7 @@ int pqissl::tick()
if (waiting > 0) if (waiting > 0)
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
std::ostringstream out; rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissl::tick() Continuing Connection Attempt!");
out << "pqissl::tick() ";
out << "Continuing Connection Attempt!";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
#endif #endif
ConnectAttempt(); ConnectAttempt();
@ -544,17 +517,12 @@ int pqissl::Delay_Connection()
*/ */
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
std::ostringstream out; std::string out;
out << "pqissl::Delay_Connection() "; rs_sprintf(out, "pqissl::Delay_Connection() Delaying Connection to %s for %lu seconds", PeerId().c_str(), mConnectDelay);
out << " Delaying Connection to "; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
out << PeerId() << " for ";
out << mConnectDelay;
out << " seconds";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
} }
#endif #endif
mConnectTS = time(NULL) + mConnectDelay; mConnectTS = time(NULL) + mConnectDelay;
return 0; return 0;
} }
@ -562,13 +530,9 @@ int pqissl::Delay_Connection()
{ {
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
std::ostringstream out; std::string out;
out << "pqissl::Delay_Connection() "; rs_sprintf(out, "pqissl::Delay_Connection() Connection to %s starting in %ld seconds", PeerId().c_str(), mConnectTS - time(NULL));
out << " Connection to "; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
out << PeerId() << " starting in ";
out << mConnectTS - time(NULL);
out << " seconds";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
} }
#endif #endif
@ -612,19 +576,17 @@ int pqissl::Initiate_Connection()
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
std::ostringstream out; std::string out;
out << "pqissl::Initiate_Connection() osock = " << osock; rs_sprintf(out, "pqissl::Initiate_Connection() osock = %d", osock);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); rslog(RSL_DEBUG_BASIC, pqisslzone, out);
} }
#endif #endif
if (osock < 0) if (osock < 0)
{ {
std::ostringstream out; std::string out = "pqissl::Initiate_Connection() Failed to open socket!\n";
out << "pqissl::Initiate_Connection()"; out += "Socket Error:" + socket_errorType(errno);
out << "Failed to open socket!" << std::endl; rslog(RSL_WARNING, pqisslzone, out);
out << "Socket Error:" << socket_errorType(errno) << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
net_internal_close(osock); net_internal_close(osock);
waiting = WAITING_FAIL_INTERFACE; waiting = WAITING_FAIL_INTERFACE;
@ -639,11 +601,9 @@ int pqissl::Initiate_Connection()
err = unix_fcntl_nonblock(osock); err = unix_fcntl_nonblock(osock);
if (err < 0) if (err < 0)
{ {
std::ostringstream out; std::string out;
out << "pqissl::Initiate_Connection()"; rs_sprintf(out, "pqissl::Initiate_Connection() Error: Cannot make socket NON-Blocking: %d", err);
out << "Error: Cannot make socket NON-Blocking: "; rslog(RSL_WARNING, pqisslzone, out);
out << err << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
waiting = WAITING_FAIL_INTERFACE; waiting = WAITING_FAIL_INTERFACE;
net_internal_close(osock); net_internal_close(osock);
@ -651,23 +611,14 @@ int pqissl::Initiate_Connection()
} }
{ {
std::ostringstream out; std::string out;
out << "pqissl::Initiate_Connection() "; rs_sprintf(out, "pqissl::Initiate_Connection() Connecting To: %s via: %s:%u", PeerId().c_str(), rs_inet_ntoa(addr.sin_addr).c_str(), ntohs(addr.sin_port));
out << "Connecting To: "; rslog(RSL_WARNING, pqisslzone, out);
out << PeerId() << " via: ";
out << rs_inet_ntoa(addr.sin_addr);
out << ":" << ntohs(addr.sin_port);
rslog(RSL_WARNING, pqisslzone, out.str());
} }
if (addr.sin_addr.s_addr == 0) if (addr.sin_addr.s_addr == 0)
{ {
std::ostringstream out; rslog(RSL_WARNING, pqisslzone, "pqissl::Initiate_Connection() Invalid (0.0.0.0) Remote Address, Aborting Connect.");
out << "pqissl::Initiate_Connection() ";
out << "Invalid (0.0.0.0) Remote Address,";
out << " Aborting Connect.";
out << std::endl;
rslog(RSL_WARNING, pqisslzone, out.str());
waiting = WAITING_FAIL_INTERFACE; waiting = WAITING_FAIL_INTERFACE;
net_internal_close(osock); net_internal_close(osock);
return -1; return -1;
@ -725,10 +676,8 @@ int pqissl::Initiate_Connection()
if (0 != (err = unix_connect(osock, (struct sockaddr *) &addr, sizeof(addr)))) if (0 != (err = unix_connect(osock, (struct sockaddr *) &addr, sizeof(addr))))
{ {
std::ostringstream out; std::string out;
out << "pqissl::Initiate_Connection() connect returns:"; rs_sprintf(out, "pqissl::Initiate_Connection() connect returns:%d -> errno: %d error: %s\n", err, errno, socket_errorType(errno).c_str());
out << err << " -> errno: " << errno << " error: ";
out << socket_errorType(errno) << std::endl;
if (errno == EINPROGRESS) if (errno == EINPROGRESS)
{ {
@ -737,16 +686,16 @@ int pqissl::Initiate_Connection()
sockfd = osock; sockfd = osock;
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
out << " EINPROGRESS Waiting for Socket Connection"; out += " EINPROGRESS Waiting for Socket Connection";
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str()); rslog(RSL_DEBUG_BASIC, pqisslzone, out);
#endif #endif
return 0; return 0;
} }
else if ((errno == ENETUNREACH) || (errno == ETIMEDOUT)) else if ((errno == ENETUNREACH) || (errno == ETIMEDOUT))
{ {
out << "ENETUNREACHABLE: cert: " << PeerId(); out += "ENETUNREACHABLE: cert: " + PeerId();
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
// Then send unreachable message. // Then send unreachable message.
net_internal_close(osock); net_internal_close(osock);
@ -763,14 +712,13 @@ int pqissl::Initiate_Connection()
* Known reasons to get here: EINVAL (bad address) * Known reasons to get here: EINVAL (bad address)
*/ */
out << "Error: Connection Failed: " << errno; rs_sprintf_append(out, "Error: Connection Failed: %d - %s", errno, socket_errorType(errno).c_str());
out << " - " << socket_errorType(errno) << std::endl;
net_internal_close(osock); net_internal_close(osock);
osock=-1; osock=-1;
waiting = WAITING_FAIL_INTERFACE; waiting = WAITING_FAIL_INTERFACE;
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
// extra output for the moment. // extra output for the moment.
//std::cerr << out.str(); //std::cerr << out.str();
@ -820,12 +768,10 @@ int pqissl::Basic_Connection_Complete()
/* new TimeOut code. */ /* new TimeOut code. */
if (time(NULL) > mTimeoutTS) if (time(NULL) > mTimeoutTS)
{ {
std::ostringstream out; std::string out;
out << "pqissl::Basic_Connection_Complete() Connection Timed Out. "; rs_sprintf(out, "pqissl::Basic_Connection_Complete() Connection Timed Out. Peer: %s Period: %lu", PeerId().c_str(), mConnectTimeout);
out << "Peer: " << PeerId() << " Period: ";
out << mConnectTimeout;
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
/* as sockfd is valid, this should close it all up */ /* as sockfd is valid, this should close it all up */
rslog(RSL_ALERT, pqisslzone, "pqissl::Basic_Connection_Complete() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::Basic_Connection_Complete() -> calling reset()");
@ -888,10 +834,9 @@ int pqissl::Basic_Connection_Complete()
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
std::ostringstream out; std::string out;
out << "pqissl::Basic_Connection_Complete() Select "; rs_sprintf(out, "pqissl::Basic_Connection_Complete() Select returned %d", sr);
out << " returned " << sr; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
} }
#endif #endif
@ -949,34 +894,22 @@ int pqissl::Basic_Connection_Complete()
{ {
if (err == 0) if (err == 0)
{ {
{ {
std::ostringstream out; std::string out;
out << "pqissl::Basic_Connection_Complete()"; rs_sprintf(out, "pqissl::Basic_Connection_Complete() TCP Connection Complete: cert: %s on osock: ", PeerId().c_str(), sockfd);
out << " TCP Connection Complete: cert: "; rslog(RSL_WARNING, pqisslzone, out);
out << PeerId();
out << " on osock: " << sockfd;
rslog(RSL_WARNING, pqisslzone, out.str());
} }
return 1; return 1;
} }
else if (err == EINPROGRESS) else if (err == EINPROGRESS)
{ {
rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() EINPROGRESS: cert: " + PeerId());
std::ostringstream out;
out << "pqissl::Basic_Connection_Complete()";
out << " EINPROGRESS: cert: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
return 0; return 0;
} }
else if ((err == ENETUNREACH) || (err == ETIMEDOUT)) else if ((err == ENETUNREACH) || (err == ETIMEDOUT))
{ {
std::ostringstream out; rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() ENETUNREACH/ETIMEDOUT: cert: " + PeerId());
out << "pqissl::Basic_Connection_Complete()";
out << " ENETUNREACH/ETIMEDOUT: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
// Then send unreachable message. // Then send unreachable message.
net_internal_close(sockfd); net_internal_close(sockfd);
@ -989,11 +922,7 @@ int pqissl::Basic_Connection_Complete()
} }
else if ((err == EHOSTUNREACH) || (err == EHOSTDOWN)) else if ((err == EHOSTUNREACH) || (err == EHOSTDOWN))
{ {
std::ostringstream out; rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() EHOSTUNREACH/EHOSTDOWN: cert: " + PeerId());
out << "pqissl::Basic_Connection_Complete()";
out << " EHOSTUNREACH/EHOSTDOWN: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
// Then send unreachable message. // Then send unreachable message.
net_internal_close(sockfd); net_internal_close(sockfd);
@ -1005,11 +934,7 @@ int pqissl::Basic_Connection_Complete()
} }
else if ((err == ECONNREFUSED)) else if ((err == ECONNREFUSED))
{ {
std::ostringstream out; rslog(RSL_WARNING, pqisslzone, "pqissl::Basic_Connection_Complete() ECONNREFUSED: cert: " + PeerId());
out << "pqissl::Basic_Connection_Complete()";
out << " ECONNREFUSED: cert: ";
out << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
// Then send unreachable message. // Then send unreachable message.
net_internal_close(sockfd); net_internal_close(sockfd);
@ -1020,10 +945,9 @@ int pqissl::Basic_Connection_Complete()
return -1; return -1;
} }
std::ostringstream out; std::string out;
out << "Error: Connection Failed UNKNOWN ERROR: " << err; rs_sprintf(out, "Error: Connection Failed UNKNOWN ERROR: %d - %s", err, socket_errorType(err).c_str());
out << " - " << socket_errorType(err); rslog(RSL_WARNING, pqisslzone, out);
rslog(RSL_WARNING, pqisslzone, out.str());
net_internal_close(sockfd); net_internal_close(sockfd);
sockfd=-1; sockfd=-1;
@ -1083,13 +1007,10 @@ int pqissl::Initiate_SSL_Connection()
net_internal_SSL_set_fd(ssl, sockfd); net_internal_SSL_set_fd(ssl, sockfd);
if (err < 1) if (err < 1)
{ {
std::ostringstream out; std::string out = "pqissl::Initiate_SSL_Connection() SSL_set_fd failed!\n";
out << "pqissl::Initiate_SSL_Connection() SSL_set_fd failed!"; printSSLError(ssl, err, SSL_get_error(ssl, err), ERR_get_error(), out);
out << std::endl;
printSSLError(ssl, err, SSL_get_error(ssl, err),
ERR_get_error(), out);
rslog(RSL_ALERT, pqisslzone, out.str()); rslog(RSL_ALERT, pqisslzone, out);
} }
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
@ -1162,14 +1083,11 @@ int pqissl::SSL_Connection_Complete()
} }
std::ostringstream out; std::string out;
out << "pqissl::SSL_Connection_Complete()" << std::endl; rs_sprintf(out, "pqissl::SSL_Connection_Complete()\nIssues with SSL Connect(%d)!\n", err);
out << "Issues with SSL Connect(" << err << ")!" << std::endl; printSSLError(ssl_connection, err, serr, ERR_get_error(), out);
printSSLError(ssl_connection, err, serr,
ERR_get_error(), out);
rslog(RSL_WARNING, pqisslzone, rslog(RSL_WARNING, pqisslzone, out);
out.str());
// attempt real error. // attempt real error.
Extract_Failed_SSL_Certificate(); Extract_Failed_SSL_Certificate();
@ -1182,11 +1100,7 @@ int pqissl::SSL_Connection_Complete()
} }
// if we get here... success v quickly. // if we get here... success v quickly.
{ rslog(RSL_WARNING, pqisslzone, "pqissl::SSL_Connection_Complete() Success!: Peer: " + PeerId());
std::ostringstream out;
out << "pqissl::SSL_Connection_Complete() Success!: Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
}
waiting = WAITING_SSL_AUTHORISE; waiting = WAITING_SSL_AUTHORISE;
return 1; return 1;
@ -1310,20 +1224,13 @@ int pqissl::Authorise_SSL_Connection()
if (certCorrect) if (certCorrect)
{ {
// then okay... // then okay...
std::ostringstream out; rslog(RSL_WARNING, pqisslzone, "pqissl::Authorise_SSL_Connection() Accepting Conn. Peer: " + PeerId());
out << "pqissl::Authorise_SSL_Connection() Accepting Conn. Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
accept(ssl_connection, sockfd, remote_addr); accept(ssl_connection, sockfd, remote_addr);
return 1; return 1;
} }
{ rslog(RSL_WARNING, pqisslzone, "pqissl::Authorise_SSL_Connection() Something Wrong ... Shutdown. Peer: " + PeerId());
std::ostringstream out;
out << "pqissl::Authorise_SSL_Connection() Something Wrong ... ";
out << " Shutdown. Peer: " << PeerId();
rslog(RSL_WARNING, pqisslzone, out.str());
}
// else shutdown ssl connection. // else shutdown ssl connection.
rslog(RSL_ALERT, pqisslzone, "pqissl::Authorise_Connection_Complete() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::Authorise_Connection_Complete() -> calling reset()");
@ -1336,12 +1243,7 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
{ {
if (waiting != WAITING_NOT) if (waiting != WAITING_NOT)
{ {
{ rslog(RSL_WARNING, pqisslzone, "pqissl::accept() Peer: " + PeerId() + " - Two connections in progress - Shut 1 down!");
std::ostringstream out;
out << "pqissl::accept() Peer: " << PeerId();
out << " - Two connections in progress - Shut 1 down!";
rslog(RSL_WARNING, pqisslzone, out.str());
}
// outgoing connection in progress. // outgoing connection in progress.
// shut this baby down. // shut this baby down.
@ -1435,21 +1337,20 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(localaddr.sin_addr)); sameLAN = isSameSubnet(&(remote_addr.sin_addr), &(localaddr.sin_addr));
{ {
std::ostringstream out; std::string out = "pqissl::accept() SUCCESSFUL connection to: " + PeerId();
out << "pqissl::accept() SUCCESSFUL connection to: " << PeerId(); out += " localaddr: " + rs_inet_ntoa(localaddr.sin_addr);
out << " localaddr: " << rs_inet_ntoa(localaddr.sin_addr); out += " remoteaddr: " + rs_inet_ntoa(remote_addr.sin_addr);
out << " remoteaddr: " << rs_inet_ntoa(remote_addr.sin_addr);
if (sameLAN) if (sameLAN)
{ {
out << " SAME LAN"; out += " SAME LAN";
} }
else else
{ {
out << " DIFF LANs"; out += " DIFF LANs";
} }
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
} }
// establish the ssl details. // establish the ssl details.
@ -1459,12 +1360,11 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
#ifdef PQISSL_LOG_DEBUG #ifdef PQISSL_LOG_DEBUG
{ {
int alg; int alg;
std::ostringstream out; std::string out;
out << "SSL Cipher:" << SSL_get_cipher(ssl) << std::endl; rs_sprintf(out, "SSL Cipher:%s\n", SSL_get_cipher(ssl));
out << "SSL Cipher Bits:" << SSL_get_cipher_bits(ssl, &alg); rs_sprintf_append(out, "SSL Cipher Bits:%d - %d\n", SSL_get_cipher_bits(ssl, &alg), alg);
out << " - " << alg << std::endl; rs_sprintf_append(out, "SSL Cipher Version:%s\n", SSL_get_cipher_version(ssl));
out << "SSL Cipher Version:" << SSL_get_cipher_version(ssl) << std::endl; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
} }
#endif #endif
@ -1517,43 +1417,35 @@ int pqissl::senddata(void *data, int len)
if (len != tmppktlen) if (len != tmppktlen)
{ {
std::ostringstream out; std::string out = "pqissl::senddata() " + PeerId();
out << "pqissl::senddata() " << PeerId(); rs_sprintf_append(out, " Partial Send: len: %d sent: %d ", len, tmppktlen);
out << " Partial Send: ";
out << "len: " << len << " sent: ";
out << tmppktlen << " ";
int err = SSL_get_error(ssl_connection, tmppktlen); int err = SSL_get_error(ssl_connection, tmppktlen);
// incomplete operations - to repeat.... // incomplete operations - to repeat....
// handled by the pqistreamer... // handled by the pqistreamer...
if (err == SSL_ERROR_SYSCALL) if (err == SSL_ERROR_SYSCALL)
{ {
out << "SSL_write() SSL_ERROR_SYSCALL "; rs_sprintf_append(out, "SSL_write() SSL_ERROR_SYSCALL SOCKET_DEAD -> calling reset() errno: %d ", errno);
out << "SOCKET_DEAD -> calling reset()"; out += socket_errorType(errno);
out << " errno: " << errno; std::cerr << out << std::endl;
out << " " << socket_errorType(errno); rslog(RSL_ALERT, pqisslzone, out);
std::cerr << out.str() << std::endl;
rslog(RSL_ALERT, pqisslzone, out.str());
/* extra debugging - based on SSL_get_error() man page */ /* extra debugging - based on SSL_get_error() man page */
{ {
int errsys = errno; int errsys = errno;
int sslerr = 0; int sslerr = 0;
std::ostringstream out2; std::string out2;
out2 << "SSL_ERROR_SYSCALL, ret == " << tmppktlen; rs_sprintf(out2, "SSL_ERROR_SYSCALL, ret == %d errno: %d %s\n", tmppktlen, errsys, socket_errorType(errsys).c_str());
out2 << " errno: " << errsys;
out2 << " " << socket_errorType(errsys);
out2 << std::endl;
while(0 != (sslerr = ERR_get_error())) while(0 != (sslerr = ERR_get_error()))
{ {
out2 << "SSLERR:" << sslerr << " : "; rs_sprintf_append(out2, "SSLERR:%d:", sslerr);
char sslbuf[256] = {0}; char sslbuf[256] = {0};
out2 << ERR_error_string(sslerr, sslbuf); out2 += ERR_error_string(sslerr, sslbuf);
out2 << std::endl; out2 += "\n";
} }
rslog(RSL_ALERT, pqisslzone, out2.str()); rslog(RSL_ALERT, pqisslzone, out2);
} }
rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()");
@ -1562,27 +1454,24 @@ int pqissl::senddata(void *data, int len)
} }
else if (err == SSL_ERROR_WANT_WRITE) else if (err == SSL_ERROR_WANT_WRITE)
{ {
out << "SSL_write() SSL_ERROR_WANT_WRITE"; out += "SSL_write() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
return -1; return -1;
} }
else if (err == SSL_ERROR_WANT_READ) else if (err == SSL_ERROR_WANT_READ)
{ {
out << "SSL_write() SSL_ERROR_WANT_READ"; out += "SSL_write() SSL_ERROR_WANT_READ";
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
//std::cerr << out.str() << std::endl; //std::cerr << out << std::endl;
return -1; return -1;
} }
else else
{ {
out << "SSL_write() UNKNOWN ERROR: " << err; rs_sprintf_append(out, "SSL_write() UNKNOWN ERROR: %d\n", err);
out << std::endl;
printSSLError(ssl_connection, tmppktlen, err, ERR_get_error(), out); printSSLError(ssl_connection, tmppktlen, err, ERR_get_error(), out);
out << std::endl; out += "\n\tResetting!";
out << "\tResetting!"; std::cerr << out << std::endl;
out << std::endl; rslog(RSL_ALERT, pqisslzone, out);
std::cerr << out.str() ;
rslog(RSL_ALERT, pqisslzone, out.str());
rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::senddata() -> calling reset()");
reset(); reset();
@ -1626,7 +1515,7 @@ int pqissl::readdata(void *data, int len)
// //
if (tmppktlen <= 0) // probably needs a reset. if (tmppktlen <= 0) // probably needs a reset.
{ {
std::ostringstream out; std::string out;
int error = SSL_get_error(ssl_connection, tmppktlen); int error = SSL_get_error(ssl_connection, tmppktlen);
unsigned long err2 = ERR_get_error(); unsigned long err2 = ERR_get_error();
@ -1655,65 +1544,62 @@ int pqissl::readdata(void *data, int len)
} }
++n_read_zero; ++n_read_zero;
out << "pqissl::readdata() " << PeerId(); out += "pqissl::readdata() " + PeerId();
out << " SSL_read() SSL_ERROR_ZERO_RETURN : nReadZero: " << n_read_zero; rs_sprintf_append(out, " SSL_read() SSL_ERROR_ZERO_RETURN : nReadZero: %d", n_read_zero);
if ((PQISSL_MAX_READ_ZERO_COUNT < n_read_zero) if ((PQISSL_MAX_READ_ZERO_COUNT < n_read_zero)
&& (time(NULL) - mReadZeroTS > PQISSL_MAX_READ_ZERO_TIME)) && (time(NULL) - mReadZeroTS > PQISSL_MAX_READ_ZERO_TIME))
{ {
out << "Count passed Limit, shutting down!"; out += " Count passed Limit, shutting down!";
out << " ReadZero Age: " << time(NULL) - mReadZeroTS; rs_sprintf_append(out, " ReadZero Age: %ld", time(NULL) - mReadZeroTS);
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset(); reset();
} }
rslog(RSL_ALERT, pqisslzone, out.str()); rslog(RSL_ALERT, pqisslzone, out);
std::cerr << out.str() << std::endl ; std::cerr << out << std::endl ;
return -1; return -1;
} }
/* the only real error we expect */ /* the only real error we expect */
if (error == SSL_ERROR_SYSCALL) if (error == SSL_ERROR_SYSCALL)
{ {
out << "pqissl::readdata() " << PeerId(); out += "pqissl::readdata() " + PeerId();
out << " SSL_read() SSL_ERROR_SYSCALL"; out += " SSL_read() SSL_ERROR_SYSCALL";
out << " SOCKET_DEAD -> calling reset()"; out += " SOCKET_DEAD -> calling reset()";
out << " errno: " << errno; rs_sprintf_append(out, " errno: %d", errno);
out << " " << socket_errorType(errno); out += " " + socket_errorType(errno);
rslog(RSL_ALERT, pqisslzone, out.str()); rslog(RSL_ALERT, pqisslzone, out);
/* extra debugging - based on SSL_get_error() man page */ /* extra debugging - based on SSL_get_error() man page */
{ {
int syserr = errno; int syserr = errno;
int sslerr = 0; int sslerr = 0;
std::ostringstream out2; std::string out2;
out2 << "SSL_ERROR_SYSCALL, ret == " << tmppktlen; rs_sprintf(out2, "SSL_ERROR_SYSCALL, ret == %d errno: %d %s\n", tmppktlen, syserr, socket_errorType(syserr).c_str());
out2 << " errno: " << syserr;
out2 << " " << socket_errorType(syserr);
out2 << std::endl;
while(0 != (sslerr = ERR_get_error())) while(0 != (sslerr = ERR_get_error()))
{ {
out2 << "SSLERR:" << sslerr << " : "; rs_sprintf_append(out2, "SSLERR:%d : ", sslerr);
char sslbuf[256] = {0}; char sslbuf[256] = {0};
out2 << ERR_error_string(sslerr, sslbuf); out2 += ERR_error_string(sslerr, sslbuf);
out2 << std::endl; out2 += "\n";
} }
rslog(RSL_ALERT, pqisslzone, out2.str()); rslog(RSL_ALERT, pqisslzone, out2);
} }
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset(); reset();
std::cerr << out.str() << std::endl ; std::cerr << out << std::endl ;
return -1; return -1;
} }
else if (error == SSL_ERROR_WANT_WRITE) else if (error == SSL_ERROR_WANT_WRITE)
{ {
out << "SSL_read() SSL_ERROR_WANT_WRITE"; out += "SSL_read() SSL_ERROR_WANT_WRITE";
rslog(RSL_WARNING, pqisslzone, out.str()); rslog(RSL_WARNING, pqisslzone, out);
std::cerr << out.str() << std::endl ; std::cerr << out << std::endl ;
return -1; return -1;
} }
else if (error == SSL_ERROR_WANT_READ) else if (error == SSL_ERROR_WANT_READ)
@ -1724,25 +1610,23 @@ int pqissl::readdata(void *data, int len)
// call of readdata(). // call of readdata().
#ifdef PQISSL_DEBUG #ifdef PQISSL_DEBUG
out << "SSL_read() SSL_ERROR_WANT_READ"; out += "SSL_read() SSL_ERROR_WANT_READ";
out << std::endl; rslog(RSL_DEBUG_BASIC, pqisslzone, out);
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
#endif #endif
return -1; return -1;
} }
else else
{ {
out << "SSL_read() UNKNOWN ERROR: " << error; rs_sprintf_append(out, "SSL_read() UNKNOWN ERROR: %d Resetting!", error);
out << " Resetting!"; rslog(RSL_ALERT, pqisslzone, out);
rslog(RSL_ALERT, pqisslzone, out.str()); std::cerr << out << std::endl ;
std::cerr << out.str() << std::endl ;
rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()"); rslog(RSL_ALERT, pqisslzone, "pqissl::readdata() -> calling reset()");
reset(); reset();
return -1; return -1;
} }
rslog(RSL_ALERT, pqisslzone, out.str()); rslog(RSL_ALERT, pqisslzone, out);
//exit(1); //exit(1);
} }
else else
@ -1755,13 +1639,10 @@ int pqissl::readdata(void *data, int len)
if (len != total_len) if (len != total_len)
{ {
std::ostringstream out; std::string out;
out << "pqissl::readdata()"; rs_sprintf(out, "pqissl::readdata() Full Packet Not read!\n -> Expected len(%d) actually read(%d)", len, total_len);
out << " Full Packet Not read!" << std::endl; std::cerr << out << std::endl;
out << " -> Expected len(" << len << ") actually read("; rslog(RSL_WARNING, pqisslzone, out);
out << total_len << ")" << std::endl;
std::cerr << out.str() ;
rslog(RSL_WARNING, pqisslzone, out.str());
} }
total_len = 0 ; // reset the packet pointer as we have finished a packet. total_len = 0 ; // reset the packet pointer as we have finished a packet.
n_read_zero = 0; n_read_zero = 0;
@ -1784,10 +1665,9 @@ bool pqissl::moretoread()
{ {
#ifdef PQISSL_DEBUG #ifdef PQISSL_DEBUG
{ {
std::ostringstream out; std::string out;
out << "pqissl::moretoread()"; rs_sprintf(out, "pqissl::moretoread() polling socket (%d)", sockfd);
out << " polling socket (" << sockfd << ")"; rslog(RSL_DEBUG_ALL, pqisslzone, out);
rslog(RSL_DEBUG_ALL, pqisslzone, out.str());
} }
#endif #endif

View File

@ -23,10 +23,6 @@
* *
*/ */
#include "pqi/pqissl.h" #include "pqi/pqissl.h"
#include "pqi/pqissllistener.h" #include "pqi/pqissllistener.h"
#include "pqi/pqinetwork.h" #include "pqi/pqinetwork.h"
@ -38,7 +34,7 @@
#include <openssl/err.h> #include <openssl/err.h>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include <sstream> #include "util/rsstring.h"
#include <unistd.h> #include <unistd.h>
const int pqissllistenzone = 49787; const int pqissllistenzone = 49787;
@ -90,15 +86,12 @@ int pqissllistenbase::tick()
int pqissllistenbase::status() int pqissllistenbase::status()
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::status(): "; rs_sprintf(out, "pqissllistenbase::status(): Listening on port: %u", ntohs(laddr.sin_port));
out << " Listening on port: " << ntohs(laddr.sin_port) << std::endl; pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out);
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out.str());
return 1; return 1;
} }
int pqissllistenbase::setuplisten() int pqissllistenbase::setuplisten()
{ {
int err; int err;
@ -119,10 +112,9 @@ int pqissllistenbase::setuplisten()
err = fcntl(lsock, F_SETFL, O_NONBLOCK); err = fcntl(lsock, F_SETFL, O_NONBLOCK);
if (err < 0) if (err < 0)
{ {
std::ostringstream out; std::string out;
out << "Error: Cannot make socket NON-Blocking: "; rs_sprintf(out, "Error: Cannot make socket NON-Blocking: %d", err);
out << err << std::endl; pqioutput(PQL_ERROR, pqissllistenzone, out);
pqioutput(PQL_ERROR, pqissllistenzone, out.str());
return -1; return -1;
} }
@ -131,12 +123,9 @@ int pqissllistenbase::setuplisten()
#else //WINDOWS_SYS #else //WINDOWS_SYS
if ((unsigned) lsock == INVALID_SOCKET) if ((unsigned) lsock == INVALID_SOCKET)
{ {
std::ostringstream out; std::string out = "pqissllistenbase::setuplisten() Cannot Open Socket!\n";
out << "pqissllistenbase::setuplisten()"; out += "Socket Error: "+ socket_errorType(WSAGetLastError());
out << " Cannot Open Socket!" << std::endl; pqioutput(PQL_ALERT, pqissllistenzone, out);
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
return -1; return -1;
} }
@ -145,13 +134,10 @@ int pqissllistenbase::setuplisten()
unsigned long int on = 1; unsigned long int on = 1;
if (0 != (err = ioctlsocket(lsock, FIONBIO, &on))) if (0 != (err = ioctlsocket(lsock, FIONBIO, &on)))
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::setuplisten()"; rs_sprintf(out, "pqissllistenbase::setuplisten() Error: Cannot make socket NON-Blocking: %d\n", err);
out << "Error: Cannot make socket NON-Blocking: "; out += "Socket Error: " + socket_errorType(WSAGetLastError());
out << err << std::endl; pqioutput(PQL_ALERT, pqissllistenzone, out);
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
return -1; return -1;
} }
@ -165,15 +151,12 @@ int pqissllistenbase::setuplisten()
laddr.sin_family = AF_INET; laddr.sin_family = AF_INET;
{ {
std::ostringstream out; std::string out = "pqissllistenbase::setuplisten()\n";
out << "pqissllistenbase::setuplisten()"; rs_sprintf_append(out, "\tAddress Family: %d\n", (int) laddr.sin_family);
out << "\tAddress Family: " << (int) laddr.sin_family; rs_sprintf_append(out, "\tSetup Address: %s\n", rs_inet_ntoa(laddr.sin_addr).c_str());
out << std::endl; rs_sprintf_append(out, "\tSetup Port: %u", ntohs(laddr.sin_port));
out << "\tSetup Address: " << rs_inet_ntoa(laddr.sin_addr);
out << std::endl;
out << "\tSetup Port: " << ntohs(laddr.sin_port);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
//std::cerr << out.str() << std::endl; //std::cerr << out.str() << std::endl;
} }
@ -192,12 +175,10 @@ int pqissllistenbase::setuplisten()
#endif #endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
{ {
std::ostringstream out; std::string out = "pqissllistenbase::setuplisten() Cannot setsockopt SO_REUSEADDR!\n";
out << "pqissllistenbase::setuplisten()";
out << " Cannot setsockopt SO_REUSEADDR!" << std::endl;
showSocketError(out); showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out.str() << std::endl; std::cerr << out << std::endl;
exit(1); exit(1);
} }
@ -211,12 +192,10 @@ int pqissllistenbase::setuplisten()
if (0 != (err = bind(lsock, (struct sockaddr *) &laddr, sizeof(laddr)))) if (0 != (err = bind(lsock, (struct sockaddr *) &laddr, sizeof(laddr))))
#endif #endif
{ {
std::ostringstream out; std::string out = "pqissllistenbase::setuplisten() Cannot Bind to Local Address!\n";
out << "pqissllistenbase::setuplisten()";
out << " Cannot Bind to Local Address!" << std::endl;
showSocketError(out); showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out.str() << std::endl; std::cerr << out << std::endl;
exit(1); exit(1);
return -1; return -1;
@ -271,13 +250,11 @@ int pqissllistenbase::setuplisten()
if (0 != (err = listen(lsock, 100))) if (0 != (err = listen(lsock, 100)))
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::setuplisten()"; rs_sprintf(out, "pqissllistenbase::setuplisten() Error: Cannot Listen to Socket: %d\n", err);
out << "Error: Cannot Listen to Socket: ";
out << err << std::endl;
showSocketError(out); showSocketError(out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_ALERT, pqissllistenzone, out);
std::cerr << out.str() << std::endl; std::cerr << out << std::endl;
exit(1); exit(1);
return -1; return -1;
@ -345,11 +322,9 @@ int pqissllistenbase::acceptconnection()
err = fcntl(fd, F_SETFL, O_NONBLOCK); err = fcntl(fd, F_SETFL, O_NONBLOCK);
if (err < 0) if (err < 0)
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::acceptconnection()"; rs_sprintf(out, "pqissllistenbase::acceptconnection() Error: Cannot make socket NON-Blocking: %d", err);
out << "Error: Cannot make socket NON-Blocking: "; pqioutput(PQL_ERROR, pqissllistenzone, out;
out << err << std::endl;
pqioutput(PQL_ERROR, pqissllistenzone, out.str());
close(fd); close(fd);
return -1; return -1;
@ -368,13 +343,10 @@ int pqissllistenbase::acceptconnection()
unsigned long int on = 1; unsigned long int on = 1;
if (0 != (err = ioctlsocket(fd, FIONBIO, &on))) if (0 != (err = ioctlsocket(fd, FIONBIO, &on)))
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::acceptconnection()"; rs_sprintf(out, "pqissllistenbase::acceptconnection() Error: Cannot make socket NON-Blocking: %d\n", err);
out << "Error: Cannot make socket NON-Blocking: "; out += "Socket Error:" + socket_errorType(WSAGetLastError());
out << err << std::endl; pqioutput(PQL_ALERT, pqissllistenzone, out);
out << "Socket Error:";
out << socket_errorType(WSAGetLastError()) << std::endl;
pqioutput(PQL_ALERT, pqissllistenzone, out.str());
closesocket(fd); closesocket(fd);
return 0; return 0;
@ -383,10 +355,9 @@ int pqissllistenbase::acceptconnection()
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
{ {
std::ostringstream out; std::string out;
out << "Accepted Connection from "; rs_sprintf(out, "Accepted Connection from %s:%u", rs_inet_ntoa(remote_addr.sin_addr).c_str(), ntohs(remote_addr.sin_port));
out << rs_inet_ntoa(remote_addr.sin_addr) << ":" << ntohs(remote_addr.sin_port); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
} }
// Negotiate certificates. SSL stylee. // Negotiate certificates. SSL stylee.
@ -409,31 +380,26 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
int err_err = ERR_get_error(); int err_err = ERR_get_error();
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::continueSSL() "; rs_sprintf(out, "pqissllistenbase::continueSSL() Issues with SSL Accept(%d)!\n", err);
out << "Issues with SSL Accept(" << err << ")!" << std::endl;
printSSLError(ssl, err, ssl_err, err_err, out); printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
} }
if ((ssl_err == SSL_ERROR_WANT_READ) || if ((ssl_err == SSL_ERROR_WANT_READ) ||
(ssl_err == SSL_ERROR_WANT_WRITE)) (ssl_err == SSL_ERROR_WANT_WRITE))
{ {
std::ostringstream out; std::string out = "pqissllistenbase::continueSSL() Connection Not Complete!\n";
out << "pqissllistenbase::continueSSL() ";
out << " Connection Not Complete!";
out << std::endl;
if (addin) if (addin)
{ {
out << "pqissllistenbase::continueSSL() "; out += "pqissllistenbase::continueSSL() Adding SSL to incoming!";
out << "Adding SSL to incoming!";
// add to incomingqueue. // add to incomingqueue.
incoming_ssl[ssl] = remote_addr; incoming_ssl[ssl] = remote_addr;
} }
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
// zero means still continuing.... // zero means still continuing....
return 0; return 0;
@ -444,11 +410,7 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
closeConnection(fd, ssl); closeConnection(fd, ssl);
std::ostringstream out; pqioutput(PQL_WARNING, pqissllistenzone, "Read Error on the SSL Socket\nShutting it down!");
out << "Read Error on the SSL Socket";
out << std::endl;
out << "Shutting it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
// failure -1, pending 0, sucess 1. // failure -1, pending 0, sucess 1.
return -1; return -1;
@ -466,9 +428,7 @@ int pqissllistenbase::continueSSL(SSL *ssl, struct sockaddr_in remote_addr, bool
closeConnection(fd, ssl); closeConnection(fd, ssl);
std::ostringstream out; pqioutput(PQL_WARNING, pqissllistenzone, "Shutting it down!");
out << "Shutting it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
// failure -1, pending 0, sucess 1. // failure -1, pending 0, sucess 1.
return -1; return -1;
@ -514,13 +474,11 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
if (peercert == NULL) if (peercert == NULL)
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::Extract_Failed_SSL_Certificate() from: "; rs_sprintf(out, "pqissllistenbase::Extract_Failed_SSL_Certificate() from: %s:%u ERROR Peer didn't give Cert!", rs_inet_ntoa(addr->sin_addr).c_str(), ntohs(addr->sin_port));
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port); std::cerr << out << std::endl;
out << " ERROR Peer didn't give Cert!";
std::cerr << out.str() << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str()); pqioutput(PQL_WARNING, pqissllistenzone, out);
return -1; return -1;
} }
@ -528,15 +486,11 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
"pqissllistenbase::Extract_Failed_SSL_Certificate() Have Peer Cert - Registering"); "pqissllistenbase::Extract_Failed_SSL_Certificate() Have Peer Cert - Registering");
{ {
std::ostringstream out; std::string out;
rs_sprintf(out, "pqissllistenbase::Extract_Failed_SSL_Certificate() from: %s:%u Passing Cert to AuthSSL() for analysis", rs_inet_ntoa(addr->sin_addr).c_str(), ntohs(addr->sin_port));
std::cerr << out << std::endl;
out << "pqissllistenbase::Extract_Failed_SSL_Certificate() from: "; pqioutput(PQL_WARNING, pqissllistenzone, out);
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
out << " Passing Cert to AuthSSL() for analysis";
out << std::endl;
std::cerr << out.str() << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
} }
// save certificate... (and ip locations) // save certificate... (and ip locations)
@ -639,21 +593,15 @@ int pqissllistenbase::isSSLActive(int /*fd*/, SSL *ssl)
int err_err = ERR_get_error(); int err_err = ERR_get_error();
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::isSSLActive() "; rs_sprintf(out, "pqissllistenbase::isSSLActive() Issues with SSL_Accept(%d)!\n", err);
out << "Issues with SSL_Accept(" << err << ")!" << std::endl;
printSSLError(ssl, err, ssl_err, err_err, out); printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
} }
if (ssl_err == SSL_ERROR_ZERO_RETURN) if (ssl_err == SSL_ERROR_ZERO_RETURN)
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, "pqissllistenbase::isSSLActive() SSL_ERROR_ZERO_RETURN Connection state unknown");
out << "pqissllistenbase::isSSLActive() SSL_ERROR_ZERO_RETURN ";
out << " Connection state unknown";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
// zero means still continuing.... // zero means still continuing....
return 0; return 0;
@ -661,38 +609,27 @@ int pqissllistenbase::isSSLActive(int /*fd*/, SSL *ssl)
if ((ssl_err == SSL_ERROR_WANT_READ) || if ((ssl_err == SSL_ERROR_WANT_READ) ||
(ssl_err == SSL_ERROR_WANT_WRITE)) (ssl_err == SSL_ERROR_WANT_WRITE))
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, "pqissllistenbase::isSSLActive() SSL_ERROR_WANT_READ || SSL_ERROR_WANT_WRITE Connection state unknown");
out << "pqissllistenbase::isSSLActive() SSL_ERROR_WANT_READ || SSL_ERROR_WANT_WRITE ";
out << " Connection state unknown";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str());
// zero means still continuing.... // zero means still continuing....
return 0; return 0;
} }
else else
{ {
std::ostringstream out; std::string out;
out << "pqissllistenbase::isSSLActive() "; rs_sprintf(out, "pqissllistenbase::isSSLActive() Issues with SSL Peek(%d) Likely the Connection was killed by Peer\n", err);
out << "Issues with SSL Peek(" << err << ") Likely the Connection was killed by Peer" << std::endl;
printSSLError(ssl, err, ssl_err, err_err, out); printSSLError(ssl, err, ssl_err, err_err, out);
pqioutput(PQL_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_ALERT, pqissllistenzone, out);
return -1; return -1;
} }
} }
std::ostringstream out; pqioutput(PQL_WARNING, pqissllistenzone, "pqissllistenbase::isSSLActive() Successful Peer -> Connection Okay");
out << "pqissllistenbase::isSSLActive() Successful Peer -> Connection Okay";
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
return 1; return 1;
} }
/************************ PQI SSL LISTENER **************************** /************************ PQI SSL LISTENER ****************************
* *
* This is the standard pqissl listener interface.... * This is the standard pqissl listener interface....
@ -717,26 +654,21 @@ int pqissllistener::addlistenaddr(std::string id, pqissl *acc)
{ {
std::map<std::string, pqissl *>::iterator it; std::map<std::string, pqissl *>::iterator it;
std::ostringstream out; std::string out = "Adding to Cert Listening Addresses Id: " + id + "\nCurrent Certs:\n";
out << "Adding to Cert Listening Addresses Id: " << id << std::endl;
out << "Current Certs:" << std::endl;
for(it = listenaddr.begin(); it != listenaddr.end(); it++) for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{ {
out << id << std::endl; out += id + "\n";
if (it -> first == id) if (it -> first == id)
{ {
out << "pqissllistener::addlistenaddr()"; out += "pqissllistener::addlistenaddr() Already listening for Certificate!\n";
out << "Already listening for Certificate!";
out << std::endl;
pqioutput(PQL_DEBUG_ALERT, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_ALERT, pqissllistenzone, out);
return -1; return -1;
} }
} }
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
// not there can accept it! // not there can accept it!
listenaddr[id] = acc; listenaddr[id] = acc;
@ -775,14 +707,13 @@ int pqissllistener::status()
// print certificates we are listening for. // print certificates we are listening for.
std::map<std::string, pqissl *>::iterator it; std::map<std::string, pqissl *>::iterator it;
std::ostringstream out; std::string out = "pqissllistener::status(): ";
out << "pqissllistener::status(): "; rs_sprintf(out, " Listening (%u) for Certs:", ntohs(laddr.sin_port));
out << " Listening (" << ntohs(laddr.sin_port) << ") for Certs:" << std::endl;
for(it = listenaddr.begin(); it != listenaddr.end(); it++) for(it = listenaddr.begin(); it != listenaddr.end(); it++)
{ {
out << it -> first << std::endl; out += "\n" + it -> first ;
} }
pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_ALL, pqissllistenzone, out);
return 1; return 1;
} }
@ -831,18 +762,15 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
} }
else else
{ {
std::ostringstream out; std::string out = "pqissllistener::continueSSL()\nchecking: " + newPeerId + "\n";
out << "pqissllistener::continueSSL()" << std::endl;
out << "checking: " << newPeerId << std::endl;
// check if cert is in our list..... // check if cert is in our list.....
for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());) for(it = listenaddr.begin();(found!=true) && (it!=listenaddr.end());)
{ {
out << "\tagainst: " << it->first << std::endl; out + "\tagainst: " + it->first + "\n";
if (it -> first == newPeerId) if (it -> first == newPeerId)
{ {
// accept even if already connected. // accept even if already connected.
out << "\t\tMatch!"; out += "\t\tMatch!";
found = true; found = true;
} }
else else
@ -851,17 +779,13 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
} }
} }
pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqissllistenzone, out);
} }
if (found == false) if (found == false)
{ {
std::ostringstream out; std::string out = "No Matching Certificate for Connection:" + rs_inet_ntoa(remote_addr.sin_addr) +"\npqissllistenbase: Will shut it down!";
out << "No Matching Certificate"; pqioutput(PQL_WARNING, pqissllistenzone, out);
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr);
out << std::endl;
out << "pqissllistenbase: Will shut it down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
// but as it passed the authentication step, // but as it passed the authentication step,
// we can add it into the AuthSSL, and mConnMgr. // we can add it into the AuthSSL, and mConnMgr.
@ -889,46 +813,33 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
accepted_ssl.push_back(as); accepted_ssl.push_back(as);
std::ostringstream out; std::string out = "pqissllistener::completeConnection() Successful Connection with: " + newPeerId;
out += " for Connection:" + rs_inet_ntoa(remote_addr.sin_addr) + " Adding to WAIT-ACCEPT Queue";
out << "pqissllistener::completeConnection() Successful Connection with: " << newPeerId; pqioutput(PQL_WARNING, pqissllistenzone, out);
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr) << " Adding to WAIT-ACCEPT Queue";
out << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
return 1; return 1;
} }
int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, struct sockaddr_in &remote_addr) int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, struct sockaddr_in &remote_addr)
{ {
std::map<std::string, pqissl *>::iterator it; std::map<std::string, pqissl *>::iterator it;
std::ostringstream out; std::string out = "pqissllistener::finaliseConnection()\n";
out += "checking: " + peerId + "\n";
out << "pqissllistener::finaliseConnection()" << std::endl;
out << "checking: " << peerId << std::endl;
// check if cert is in the list..... // check if cert is in the list.....
it = listenaddr.find(peerId); it = listenaddr.find(peerId);
if (it == listenaddr.end()) if (it == listenaddr.end())
{ {
out << "No Matching Peer"; out += "No Matching Peer for Connection:" + rs_inet_ntoa(remote_addr.sin_addr);
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr); out += "\npqissllistener => Shutting Down!";
out << std::endl; pqioutput(PQL_WARNING, pqissllistenzone, out);
out << "pqissllistener => Shutting Down!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
return -1; return -1;
} }
out << "Found Matching Peer"; out += "Found Matching Peer for Connection:" + rs_inet_ntoa(remote_addr.sin_addr);
out << " for Connection:" << rs_inet_ntoa(remote_addr.sin_addr); out += "\npqissllistener => Passing to pqissl module!";
out << std::endl; pqioutput(PQL_WARNING, pqissllistenzone, out);
out << "pqissllistener => Passing to pqissl module!" << std::endl;
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
// hand off ssl conection. // hand off ssl conection.
pqissl *pqis = it -> second; pqissl *pqis = it -> second;
@ -936,7 +847,3 @@ int pqissllistener::finaliseConnection(int fd, SSL *ssl, std::string peerId, str
return 1; return 1;
} }

View File

@ -45,8 +45,8 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include "util/rsstring.h"
// //
// #define PQISTORE_DEBUG // #define PQISTORE_DEBUG
@ -58,19 +58,11 @@ pqistore::pqistore(RsSerialiser *rss, const std::string &srcId, BinInterface *bi
:PQInterface(""), rsSerialiser(rss), bio_flags(bio_flags_in), :PQInterface(""), rsSerialiser(rss), bio_flags(bio_flags_in),
nextPkt(NULL), mSrcId(srcId), bio(bio_in) nextPkt(NULL), mSrcId(srcId), bio(bio_in)
{ {
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::pqistore() Initialisation!");
std::ostringstream out;
out << "pqistore::pqistore()";
out << " Initialisation!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
if (!bio_in) if (!bio_in)
{ {
std::ostringstream out; pqioutput(PQL_ALERT, pqistorezone, "pqistore::pqistore() NULL bio, FATAL ERROR!");
out << "pqistore::pqistore()";
out << " NULL bio, FATAL ERROR!" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
exit(1); exit(1);
} }
@ -79,26 +71,15 @@ pqistore::pqistore(RsSerialiser *rss, const std::string &srcId, BinInterface *bi
pqistore::~pqistore() pqistore::~pqistore()
{ {
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Destruction!");
std::ostringstream out;
out << "pqistore::~pqistore()";
out << " Destruction!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
if (bio_flags & BIN_FLAGS_NO_CLOSE) if (bio_flags & BIN_FLAGS_NO_CLOSE)
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Not Closing BinInterface!;");
out << "pqistore::~pqistore()";
out << " Not Closing BinInterface!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
} }
else if (bio) else if (bio)
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::~pqistore() Deleting BinInterface!");
out << "pqistore::~pqistore()";
out << " Deleting BinInterface!" << std::endl;
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
delete bio; delete bio;
} }
@ -119,10 +100,9 @@ int pqistore::SendItem(RsItem *si)
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ {
std::ostringstream out; std::string out = "pqistore::SendItem()\n";
out << "pqistore::SendItem()" << std::endl;
si -> print(out); si -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
} }
#endif #endif
@ -144,21 +124,14 @@ int pqistore::SendItem(RsItem *si)
RsItem *pqistore::GetItem() RsItem *pqistore::GetItem()
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::GetItem()");
std::ostringstream out;
out << "pqistore::GetItem()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
// check if this is a reading bio. // check if this is a reading bio.
if (!(bio_flags & BIN_FLAGS_READABLE)) if (!(bio_flags & BIN_FLAGS_READABLE))
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Error Not Readable");
out << "pqistore::GetItem()";
out << "Error Not Readable" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
#endif #endif
return NULL; return NULL;
} }
@ -168,10 +141,7 @@ RsItem *pqistore::GetItem()
{ {
if (!readPkt(&nextPkt)) if (!readPkt(&nextPkt))
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Failed to ReadPkt");
out << "pqistore::GetItem()";
out << "Failed to ReadPkt" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
return NULL; return NULL;
} }
} }
@ -184,10 +154,9 @@ RsItem *pqistore::GetItem()
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
if (outPkt != NULL) if (outPkt != NULL)
{ {
std::ostringstream out; std::string out = "pqistore::GetItem() Returning:\n";
out << "pqistore::GetItem() Returning:" << std::endl;
outPkt -> print(out); outPkt -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
} }
#endif #endif
return outPkt; return outPkt;
@ -200,11 +169,7 @@ RsItem *pqistore::GetItem()
int pqistore::tick() int pqistore::tick()
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ std::cerr << "pqistore::tick()" << std::endl;
std::ostringstream out;
out << "pqistore::tick()";
out << std::endl;
}
#endif #endif
return 0; return 0;
} }
@ -212,11 +177,7 @@ int pqistore::tick()
int pqistore::status() int pqistore::status()
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::status()");
std::ostringstream out;
out << "pqistore::status()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
return 0; return 0;
} }
@ -228,11 +189,7 @@ int pqistore::writePkt(RsItem *pqi)
{ {
// std::cerr << "writePkt, pqi->peerId()=" << pqi->PeerId() << std::endl ; // std::cerr << "writePkt, pqi->peerId()=" << pqi->PeerId() << std::endl ;
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::writePkt()");
std::ostringstream out;
out << "pqistore::writePkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
uint32_t pktsize = rsSerialiser->size(pqi); uint32_t pktsize = rsSerialiser->size(pqi);
@ -240,12 +197,9 @@ int pqistore::writePkt(RsItem *pqi)
if (!(rsSerialiser->serialise(pqi, ptr, &pktsize))) if (!(rsSerialiser->serialise(pqi, ptr, &pktsize)))
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
std::ostringstream out; std::string out = "pqistore::writePkt() Null Pkt generated!\nCaused By:\n";
out << "pqistore::writePkt() Null Pkt generated!";
out << std::endl;
out << "Caused By: " << std::endl;
pqi -> print(out); pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str()); pqioutput(PQL_ALERT, pqistorezone, out);
#endif #endif
free(ptr); free(ptr);
@ -258,13 +212,10 @@ int pqistore::writePkt(RsItem *pqi)
uint32_t len = getRsItemSize(ptr); uint32_t len = getRsItemSize(ptr);
if (len != pktsize) if (len != pktsize)
{ {
std::ostringstream out; std::string out;
out << "pqistore::writePkt() Length MisMatch: len: " << len; rs_sprintf(out, "pqistore::writePkt() Length MisMatch: len: %u!= pktsize: %u\nCaused By:\n", len, pktsize);
out << " != pktsize: " << pktsize; pqi -> print_string(out);
out << std::endl; pqioutput(PQL_ALERT, pqistorezone, out);
out << "Caused By: " << std::endl;
pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
free(ptr); free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE)) if (!(bio_flags & BIN_FLAGS_NO_DELETE))
@ -275,12 +226,10 @@ int pqistore::writePkt(RsItem *pqi)
if (!(bio->cansend())) if (!(bio->cansend()))
{ {
std::ostringstream out; std::string out;
out << "pqistore::writePkt() BIO cannot write!"; rs_sprintf(out, "pqistore::writePkt() BIO cannot write!\niscarding:\n");
out << std::endl; pqi -> print_string(out);
out << "Discarding: " << std::endl; pqioutput(PQL_ALERT, pqistorezone, out);
pqi -> print(out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
free(ptr); free(ptr);
if (!(bio_flags & BIN_FLAGS_NO_DELETE)) if (!(bio_flags & BIN_FLAGS_NO_DELETE))
@ -290,16 +239,14 @@ int pqistore::writePkt(RsItem *pqi)
} }
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
std::ostringstream out; std::string out = "Writing Pkt Body";
out << "Writing Pkt Body" << std::endl;
#endif #endif
// write packet. // write packet.
if (len != (uint32_t) bio->senddata(ptr, len)) if (len != (uint32_t) bio->senddata(ptr, len))
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
out << "Problems with Send Data!"; out += " Problems with Send Data!";
out << std::endl; pqioutput(PQL_ALERT, pqistorezone, out);
pqioutput(PQL_ALERT, pqistorezone, out.str());
#endif #endif
free(ptr); free(ptr);
@ -310,8 +257,8 @@ int pqistore::writePkt(RsItem *pqi)
} }
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
out << " Success!" << std::endl; out += " Success!";
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
#endif #endif
free(ptr); free(ptr);
@ -328,11 +275,7 @@ int pqistore::writePkt(RsItem *pqi)
int pqistore::readPkt(RsItem **item_out) int pqistore::readPkt(RsItem **item_out)
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::readPkt()");
std::ostringstream out;
out << "pqistore::readPkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
if ((!(bio->isactive())) || (!(bio->moretoread()))) if ((!(bio->isactive())) || (!(bio->moretoread())))
@ -353,8 +296,7 @@ int pqistore::readPkt(RsItem **item_out)
// read the basic block (minimum packet size) // read the basic block (minimum packet size)
if (blen != (tmplen = bio->readdata(block, blen))) if (blen != (tmplen = bio->readdata(block, blen)))
{ {
pqioutput(PQL_WARNING, pqistorezone, pqioutput(PQL_WARNING, pqistorezone, "pqistore::readPkt() bad read(2)");
"pqistore::readPkt() bad read(2)");
free(block); free(block);
return 0; return 0;
@ -379,12 +321,9 @@ int pqistore::readPkt(RsItem **item_out)
if (extralen != (tmplen = bio->readdata(extradata, extralen))) if (extralen != (tmplen = bio->readdata(extradata, extralen)))
{ {
std::string out;
std::ostringstream out; rs_sprintf(out, "pqistore::readPkt() Error Completing Read (read %d/%d)", tmplen, extralen);
out << "pqistore::readPkt() "; pqioutput(PQL_ALERT, pqistorezone, out);
out << "Error Completing Read (read ";
out << tmplen << "/" << extralen << ")" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
free(block); free(block);
return 0; return 0;
@ -401,8 +340,7 @@ int pqistore::readPkt(RsItem **item_out)
if (item == NULL) if (item == NULL)
{ {
pqioutput(PQL_ALERT, pqistorezone, pqioutput(PQL_ALERT, pqistorezone, "pqistore::readPkt() Failed to create Item from store!");
"pqistore::readPkt() Failed to create Item from store!");
return 0; return 0;
} }
@ -480,20 +418,13 @@ bool pqiSSLstore::getEncryptedItems(std::list<RsItem* >& rsItemList)
RsItem *pqiSSLstore::GetItem() RsItem *pqiSSLstore::GetItem()
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::GetItem()");
std::ostringstream out;
out << "pqistore::GetItem()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
// check if this is a reading bio. // check if this is a reading bio.
if (!(bio_flags & BIN_FLAGS_READABLE)) if (!(bio_flags & BIN_FLAGS_READABLE))
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Error Not Readable");
out << "pqistore::GetItem()";
out << "Error Not Readable" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
return NULL; return NULL;
} }
@ -502,10 +433,7 @@ RsItem *pqiSSLstore::GetItem()
{ {
if (!readPkt(&nextPkt)) if (!readPkt(&nextPkt))
{ {
std::ostringstream out; pqioutput(PQL_DEBUG_BASIC, pqistorezone, "pqistore::GetItem() Failed to ReadPkt");
out << "pqistore::GetItem()";
out << "Failed to ReadPkt" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str());
return NULL; return NULL;
} }
} }
@ -518,10 +446,10 @@ RsItem *pqiSSLstore::GetItem()
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
if (outPkt != NULL) if (outPkt != NULL)
{ {
std::ostringstream out; std::string out;
out << "pqistore::GetItem() Returning:" << std::endl; rs_sprintf(out, "pqistore::GetItem() Returning:\n");
outPkt -> print(out); outPkt -> print(out);
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out.str()); pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
} }
#endif #endif
return outPkt; return outPkt;
@ -531,11 +459,7 @@ RsItem *pqiSSLstore::GetItem()
int pqiSSLstore::readPkt(RsItem **item_out) int pqiSSLstore::readPkt(RsItem **item_out)
{ {
#ifdef PQISTORE_DEBUG #ifdef PQISTORE_DEBUG
{ pqioutput(PQL_DEBUG_ALL, pqistorezone, "pqistore::readPkt()");
std::ostringstream out;
out << "pqistore::readPkt()";
pqioutput(PQL_DEBUG_ALL, pqistorezone, out.str());
}
#endif #endif
if ((!(enc_bio->isactive())) || (!(enc_bio->moretoread()))) if ((!(enc_bio->isactive())) || (!(enc_bio->moretoread())))
@ -582,12 +506,9 @@ int pqiSSLstore::readPkt(RsItem **item_out)
if (extralen != (tmplen = enc_bio->readdata(extradata, extralen))) if (extralen != (tmplen = enc_bio->readdata(extradata, extralen)))
{ {
std::string out;
std::ostringstream out; rs_sprintf(out, "pqistore::readPkt() Error Completing Read (read %d/%d)", tmplen, extralen);
out << "pqistore::readPkt() "; pqioutput(PQL_ALERT, pqistorezone, out);
out << "Error Completing Read (read ";
out << tmplen << "/" << extralen << ")" << std::endl;
pqioutput(PQL_ALERT, pqistorezone, out.str());
free(block); free(block);
return 0; return 0;

View File

@ -33,6 +33,7 @@
#include "pqi/sslfns.h" #include "pqi/sslfns.h"
#include "pqi/pqi_base.h" #include "pqi/pqi_base.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsstring.h"
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
@ -650,16 +651,15 @@ bool getX509id(X509 *x509, std::string &xid) {
// else copy in the first CERTSIGNLEN. // else copy in the first CERTSIGNLEN.
unsigned char *signdata = ASN1_STRING_data(signature); unsigned char *signdata = ASN1_STRING_data(signature);
std::ostringstream id; xid.clear();
/* switched to the other end of the signature. for /* switched to the other end of the signature. for
* more randomness * more randomness
*/ */
for(int i = signlen - CERTSIGNLEN; i < signlen; i++) for(int i = signlen - CERTSIGNLEN; i < signlen; i++)
{ {
id << std::hex << std::setw(2) << std::setfill('0') rs_sprintf_append(xid, "%02x", (uint16_t) (((uint8_t *) (signdata))[i]));
<< (uint16_t) (((uint8_t *) (signdata))[i]);
} }
xid = id.str();
return true; return true;
} }
@ -875,8 +875,7 @@ std::string getX509Info(X509 *cert)
/********** SSL ERROR STUFF ******************************************/ /********** SSL ERROR STUFF ******************************************/
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::string &out)
std::ostream &out)
{ {
(void) ssl; /* remove unused parameter warnings */ (void) ssl; /* remove unused parameter warnings */
@ -919,9 +918,7 @@ int printSSLError(SSL *ssl, int retval, int err, unsigned long err2,
{ {
mainreason = std::string("SSL_ERROR_SSL"); mainreason = std::string("SSL_ERROR_SSL");
} }
out << "RetVal(" << retval; rs_sprintf_append(out, "RetVal(%d) -> SSL Error: %s\n\t + ERR Error: %s\n", retval, mainreason.c_str(), ERR_error_string(err2, NULL));
out << ") -> SSL Error: " << mainreason << std::endl;
out << "\t + ERR Error: " << ERR_error_string(err2, NULL) << std::endl;
return 1; return 1;
} }

View File

@ -126,8 +126,7 @@ std::string getX509Info(X509 *cert);
/********** SSL ERROR STUFF ******************************************/ /********** SSL ERROR STUFF ******************************************/
int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, int printSSLError(SSL *ssl, int retval, int err, unsigned long err2, std::string &out);
std::ostream &out);
#endif /* RS_PQI_SSL_HELPER_H */ #endif /* RS_PQI_SSL_HELPER_H */

View File

@ -44,7 +44,6 @@
#include <list> #include <list>
#include <string> #include <string>
#include <sstream>
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>
@ -1392,14 +1391,10 @@ bool RsInit::GenerateSSLCertificate(const std::string& gpg_id, const std::st
/* Flag as first time run */ /* Flag as first time run */
RsInitConfig::firsttime_run = true; RsInitConfig::firsttime_run = true;
{ std::cerr << "RetroShare has Successfully generated a Certficate/Key" << std::endl;
std::ostringstream out; std::cerr << "\tCert Located: " << cert_name << std::endl;
out << "RetroShare has Successfully generated"; std::cerr << "\tLocated: " << key_name << std::endl;
out << "a Certficate/Key" << std::endl;
out << "\tCert Located: " << cert_name << std::endl;
out << "\tLocated: " << key_name << std::endl;
std::cerr << out.str();
}
return true; return true;
} }
@ -1643,13 +1638,10 @@ std::string RsInit::getHomePath()
#else /* Windows */ #else /* Windows */
std::ostringstream out;
char *h2 = getenv("HOMEDRIVE"); char *h2 = getenv("HOMEDRIVE");
out << "getHomePath() -> $HOMEDRIVE = "; std::cerr << "getHomePath() -> $HOMEDRIVE = " << h2 << std::endl;
out << h2 << std::endl;
char *h3 = getenv("HOMEPATH"); char *h3 = getenv("HOMEPATH");
out << "getHomePath() -> $HOMEPATH = "; std::cerr << "getHomePath() -> $HOMEPATH = " << h3 << std::endl;
out << h3 << std::endl;
if (h2 == NULL) if (h2 == NULL)
{ {
@ -1664,8 +1656,7 @@ std::string RsInit::getHomePath()
home += "\\Desktop"; home += "\\Desktop";
} }
out << "fltkserver::getHomePath() -> " << home << std::endl; std::cerr << "fltkserver::getHomePath() -> " << home << std::endl;
std::cerr << out.str();
// convert to FLTK desired format. // convert to FLTK desired format.
home = RsDirUtil::convertPathToUnix(home); home = RsDirUtil::convertPathToUnix(home);

View File

@ -125,7 +125,13 @@ RsItem::~RsItem()
{ {
} }
void RsItem::print_string(std::string &out, uint16_t indent)
{
std::ostringstream stream;
print(stream, indent);
out += stream.str();
}
uint32_t RsItem::PacketId() uint32_t RsItem::PacketId()
{ {
return type; return type;

View File

@ -81,6 +81,7 @@ class RsItem: public RsMemoryManagement::SmallObject
virtual ~RsItem(); virtual ~RsItem();
virtual void clear() = 0; virtual void clear() = 0;
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0; virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) = 0;
void print_string(std::string &out, uint16_t indent = 0);
/* source / destination id */ /* source / destination id */
const std::string& PeerId() const { return peerId; } const std::string& PeerId() const { return peerId; }

View File

@ -191,7 +191,7 @@ int locked_getZoneLevel(int zone)
return it -> second; return it -> second;
} }
int rslog(unsigned int lvl, int zone, std::string msg) int rslog(unsigned int lvl, int zone, const std::string &msg)
{ {
RsStackMutex stack(logMtx); /******** LOCKED ****************/ RsStackMutex stack(logMtx); /******** LOCKED ****************/
if ((signed) lvl <= locked_getZoneLevel(zone)) if ((signed) lvl <= locked_getZoneLevel(zone))

View File

@ -49,7 +49,7 @@ int clearDebugCrashLog();
int setDebugFile(const char *fname); int setDebugFile(const char *fname);
int setOutputLevel(int lvl); int setOutputLevel(int lvl);
int setZoneLevel(int lvl, int zone); int setZoneLevel(int lvl, int zone);
int rslog(unsigned int lvl, int zone, std::string msg); int rslog(unsigned int lvl, int zone, const std::string &msg);