Removed most of the output to stderr.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@641 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-07-09 09:55:09 +00:00
parent d5376cd575
commit ca69e3d5e3
24 changed files with 586 additions and 93 deletions

View File

@ -30,9 +30,9 @@
#include <sstream>
#include <iomanip>
/***
#define CS_DEBUG 1
***/
/****
* #define CS_DEBUG 1
***/
bool operator<(const CacheId &a, const CacheId &b)
{
@ -329,7 +329,10 @@ bool CacheStore::getAllStoredCaches(std::list<CacheData> &data)
*/
void CacheStore::availableCache(const CacheData &data)
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::availableCache() :" << data << std::endl;
#endif
/* basic checks */
lockData(); /* LOCK MUTEX */
@ -369,7 +372,10 @@ void CacheStore::availableCache(const CacheData &data)
/* called when the download is completed ... updates internal data */
void CacheStore::downloadedCache(const CacheData &data)
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::downloadedCache() :" << data << std::endl;
#endif
/* updates data */
if (!loadCache(data))
{
@ -379,7 +385,9 @@ void CacheStore::downloadedCache(const CacheData &data)
/* called when the download is completed ... updates internal data */
void CacheStore::failedCache(const CacheData &data)
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::failedCache() :" << data << std::endl;
#endif
return;
}
@ -388,7 +396,9 @@ void CacheStore::failedCache(const CacheData &data)
bool CacheStore::fetchCache(const CacheData &data)
{
/* should we fetch it? */
#ifdef CS_DEBUG
std::cerr << "CacheStore::fetchCache() tofetch?:" << data << std::endl;
#endif
CacheData incache = data;
@ -401,11 +411,15 @@ bool CacheStore::fetchCache(const CacheData &data)
if (haveCache)
{
#ifdef CS_DEBUG
std::cerr << "CacheStore::fetchCache() Already have it: false" << std::endl;
#endif
return false;
}
#ifdef CS_DEBUG
std::cerr << "CacheStore::fetchCache() Missing this cache: true" << std::endl;
#endif
return true;
}
@ -415,11 +429,16 @@ int CacheStore::nameCache(CacheData &data)
/* name it... */
lockData(); /* LOCK MUTEX */
#ifdef CS_DEBUG
std::cerr << "CacheStore::nameCache() for:" << data << std::endl;
#endif
data.name = data.hash;
data.path = getCacheDir();
#ifdef CS_DEBUG
std::cerr << "CacheStore::nameCache() done:" << data << std::endl;
#endif
unlockData(); /* UNLOCK MUTEX */
@ -430,7 +449,9 @@ int CacheStore::nameCache(CacheData &data)
int CacheStore::loadCache(const CacheData &data)
{
/* attempt to load -> dummy function */
#ifdef CS_DEBUG
std::cerr << "CacheStore::loadCache() Dummy Load for:" << data << std::endl;
#endif
lockData(); /* LOCK MUTEX */
@ -994,11 +1015,13 @@ bool CacheTransfer::RequestCache(CacheData &data, CacheStore *cbStore)
/* to be overloaded */
bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
{
#ifdef CS_DEBUG
std::cerr << "CacheTransfer::RequestCacheFile() : from:" << id << " #";
std::cerr << hash << " size: " << size;
std::cerr << " savepath: " << path << std::endl;
std::cerr << "CacheTransfer::RequestCacheFile() Dummy... saying completed";
std::cerr << std::endl;
#endif
/* just tell them we've completed! */
CompletedCache(hash);
@ -1008,11 +1031,13 @@ bool CacheTransfer::RequestCacheFile(RsPeerId id, std::string path, std::string
/* to be overloaded */
bool CacheTransfer::CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
{
#ifdef CS_DEBUG
std::cerr << "CacheTransfer::CancelCacheFile() : from:" << id << " #";
std::cerr << hash << " size: " << size;
std::cerr << " savepath: " << path << std::endl;
std::cerr << "CacheTransfer::CancelCacheFile() Dummy fn";
std::cerr << std::endl;
#endif
return true;
}

View File

@ -516,7 +516,9 @@ void FileIndexMonitor::updateCycle()
/* print out the new directory structure */
#ifdef FIM_DEBUG
fi.printFileIndex(std::cerr);
#endif
/* now if we have changed things -> restore file/hash it/and
* tell the CacheSource
@ -671,7 +673,9 @@ bool FileIndexMonitor::internal_setSharedDirectories()
unique = true;
/* add it! */
directoryMap[tst_dir.c_str()] = root_dir;
#ifdef FIM_DEBUG
std::cerr << "Added [" << tst_dir << "] => " << root_dir << std::endl;
#endif
}
}
}

View File

@ -33,7 +33,9 @@
#include <openssl/sha.h>
#define FI_DEBUG 1
/****
* #define FI_DEBUG 1
****/
DirEntry::~DirEntry()

View File

@ -42,7 +42,9 @@ const std::string openDHT_Agent = "RS-HTTP-V0.4";
#define MAX_DHT_ATTEMPTS 10 /* attempts per search/publish */
#define MIN_DHT_SERVERS 5
#define OPENDHT_DEBUG 1
/****
* #define OPENDHT_DEBUG 1
****/
bool OpenDHTClient::checkServerFile(std::string filename)
{
@ -488,7 +490,9 @@ bool OpenDHTClient::searchKey(std::string key, std::list<std::string> &values)
if (isspace(value[i]))
{
value.erase(i,1);
#ifdef OPENDHT_DEBUG
std::cerr << "Cleanup Result:" << value << ":END:" << std::endl;
#endif
}
else
{
@ -498,10 +502,12 @@ bool OpenDHTClient::searchKey(std::string key, std::list<std::string> &values)
if (value.length() > 0)
{
std::cerr << "openDHT_searchKey() Value:" << value << ":END:" << std::endl;
std::string result = convertFromBase64(value);
std::cerr << "openDHT_searchKey() Result: 0x" << RsUtil::BinToHex(result) << ":END:" << std::endl;
values.push_back(result);
#ifdef OPENDHT_DEBUG
std::cerr << "openDHT_searchKey() Value:" << value << ":END:" << std::endl;
std::cerr << "openDHT_searchKey() Result: 0x" << RsUtil::BinToHex(result) << ":END:" << std::endl;
#endif
}
/* the answer should be between loc and end */
@ -541,19 +547,23 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
else
{
/* no address */
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: No Address";
std::cerr << std::endl;
#endif
setServerFailed(host);
return false;
}
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Connecting to:" << host << ":" << port;
std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")";
std::cerr << std::endl;
#endif
/* create request */
std::string putheader = createHttpHeader(host, port, openDHT_Agent, msg.length());
@ -566,20 +576,24 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
if (err)
{
unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Connect";
std::cerr << std::endl;
#endif
setServerFailed(host);
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP message *******************" << std::endl;
std::cerr << putheader;
std::cerr << msg;
std::cerr << std::endl;
std::cerr << "HTTP message *******************" << std::endl;
#endif
/* send data */
int sendsize = strlen(putheader.c_str());
@ -587,35 +601,43 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
if (sendsize != size)
{
unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Send(1)";
std::cerr << std::endl;
#endif
setServerFailed(host);
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Send(1):" << size;
std::cerr << std::endl;
#endif
sendsize = strlen(msg.c_str());
size = send(sockfd, msg.c_str(), sendsize, 0);
if (sendsize != size)
{
unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Send(2)";
std::cerr << std::endl;
#endif
setServerFailed(host);
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Send(2):" << size;
std::cerr << std::endl;
#endif
/* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -631,19 +653,24 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
uint32_t idx = 0;
while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0)))
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl;
#endif
idx += size;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Recvd Msg:" << idx;
#endif
response = std::string(inbuf, idx);
free(inbuf);
/* print it out */
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP What We Sent ***************" << std::endl;
std::cerr << putheader;
std::cerr << msg;
@ -652,6 +679,7 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
std::cerr << response;
std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl;
#endif
unix_close(sockfd);
@ -672,17 +700,21 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (!LookupDNSAddr(host, addr))
{
/* no address */
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: No Address";
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Connecting to:" << host << ":" << port;
std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")";
std::cerr << std::endl;
#endif
/* create request */
std::string putheader = createHttpHeaderGET(host, port, "servers.txt", openDHT_Agent, 0);
@ -695,17 +727,21 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (err)
{
unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: Failed to Connect";
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP message *******************" << std::endl;
std::cerr << putheader;
std::cerr << std::endl;
std::cerr << "HTTP message *******************" << std::endl;
#endif
/* send data */
int sendsize = strlen(putheader.c_str());
@ -713,15 +749,19 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (sendsize != size)
{
unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: Failed to Send(1)";
std::cerr << std::endl;
#endif
return false;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Send(1):" << size;
std::cerr << std::endl;
#endif
/* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -737,23 +777,29 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
uint32_t idx = 0;
while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0)))
{
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl;
#endif
idx += size;
}
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Recvd Msg:" << idx;
#endif
response = std::string(inbuf, idx);
free(inbuf);
/* print it out */
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP response *******************" << std::endl;
std::cerr << response;
std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl;
#endif
unix_close(sockfd);

View File

@ -1364,9 +1364,11 @@ int LoadCheckXPGPandGetName(const char *cert_file, std::string &userName, std::s
FILE *tmpfp = fopen(cert_file, "r");
if (tmpfp == NULL)
{
#ifdef XPGP_DEBUG
std::cerr << "sslroot::LoadCheckAndGetXPGPName()";
std::cerr << " Failed to open Certificate File:" << cert_file;
std::cerr << std::endl;
#endif
return 0;
}
@ -1604,7 +1606,9 @@ std::list<std::string> getXPGPsigners(XPGP *cert)
XPGP_SIGNATURE *sig = sk_XPGP_SIGNATURE_value(cert->signs,i);
std::string str = getX509CNString(sig->issuer);
signers.push_back(str);
#ifdef XPGP_DEBUG
std::cerr << "XPGPsigners(" << i << ")" << str << std::endl;
#endif
}
return signers;
}
@ -1767,7 +1771,6 @@ bool AuthXPGP::saveCertificates()
conftxt += "\n";
conftxt += hash;
conftxt += "\n";
std::cerr << std::endl;
}
}
}
@ -1786,34 +1789,48 @@ bool AuthXPGP::saveCertificates()
if (0 == EVP_SignInit_ex(mdctx, EVP_sha1(), NULL))
{
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignInit Failure!" << std::endl;
#endif
}
if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length()))
{
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignUpdate Failure!" << std::endl;
#endif
}
if (0 == EVP_SignFinal(mdctx, signature, &signlen, pkey))
{
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignFinal Failure!" << std::endl;
#endif
}
#ifdef XPGP_DEBUG
std::cerr << "Conf Signature is(" << signlen << "): ";
#endif
for(i = 0; i < signlen; i++)
{
#ifdef XPGP_DEBUG
fprintf(stderr, "%02x", signature[i]);
#endif
conftxt += signature[i];
}
#ifdef XPGP_DEBUG
std::cerr << std::endl;
#endif
FILE *cfd = fopen(configfile.c_str(), "wb");
int wrec;
if (1 != (wrec = fwrite(conftxt.c_str(), conftxt.length(), 1, cfd)))
{
#ifdef XPGP_DEBUG
std::cerr << "Error writing: " << configfile << std::endl;
std::cerr << "Wrote: " << wrec << "/" << 1 << " Records" << std::endl;
#endif
}
EVP_MD_CTX_destroy(mdctx);
@ -1889,8 +1906,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
FILE *cfd = fopen(configfile.c_str(), "rb");
if (cfd == NULL)
{
#ifdef XPGP_DEBUG
std::cerr << "Unable to Load Configuration File!" << std::endl;
std::cerr << "File: " << configfile << std::endl;
#endif
return false;
}
@ -1925,11 +1944,13 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
{
if (EOF == (c = fgetc(cfd)))
{
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Signature of: ";
std::cerr << fname;
std::cerr << std::endl;
std::cerr << "ABorting Load!";
std::cerr << std::endl;
#endif
return -1;
}
unsigned char uc = (unsigned char) c;
@ -1937,9 +1958,12 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
}
if ('\n' != (c = fgetc(cfd)))
{
#ifdef XPGP_DEBUG
std::cerr << "Warning Mising seperator" << std::endl;
#endif
}
#ifdef XPGP_DEBUG
std::cerr << "Read fname:" << fname << std::endl;
std::cerr << "Signature:" << std::endl;
for(i = 0; i < signlen; i++)
@ -1948,6 +1972,7 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
}
std::cerr << std::endl;
std::cerr << std::endl;
#endif
// push back.....
fnames.push_back(fname);
@ -1982,11 +2007,13 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
{
if (EOF == (c = fgetc(cfd)))
{
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Value of: ";
std::cerr << opt;
std::cerr << std::endl;
std::cerr << "ABorting Load!";
std::cerr << std::endl;
#endif
return -1;
}
// remove zeros on strings...
@ -1998,11 +2025,15 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
}
if ('\n' != (c = fgetc(cfd)))
{
#ifdef XPGP_DEBUG
std::cerr << "Warning Mising seperator" << std::endl;
#endif
}
#ifdef XPGP_DEBUG
std::cerr << "Read OPT:" << opt;
std::cerr << " Val:" << val << std::endl;
#endif
// push back.....
tmpsettings[opt] = val;
@ -2029,8 +2060,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
c = fgetc(cfd);
if (c == EOF)
{
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Conf Signature:";
std::cerr << std::endl;
#endif
return 1;
}
unsigned char uc = (unsigned char) c;
@ -2038,12 +2071,14 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
}
}
#ifdef XPGP_DEBUG
std::cerr << "Configuration File Signature: " << std::endl;
for(i = 0; i < signlen; i++)
{
fprintf(stderr, "%02x", (unsigned char) name[i]);
}
std::cerr << std::endl;
#endif
// when we get here - should have the final signature in the buffer.
@ -2057,28 +2092,36 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
if (0 == EVP_SignInit(mdctx, EVP_sha1()))
{
#ifdef XPGP_DEBUG
#endif
std::cerr << "EVP_SignInit Failure!" << std::endl;
}
if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length()))
{
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignUpdate Failure!" << std::endl;
#endif
}
if (0 == EVP_SignFinal(mdctx, conf_signature, &signlen, pkey))
{
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignFinal Failure!" << std::endl;
#endif
}
EVP_MD_CTX_destroy(mdctx);
fclose(cfd);
#ifdef XPGP_DEBUG
std::cerr << "Recalced File Signature: " << std::endl;
for(i = 0; i < signlen; i++)
{
fprintf(stderr, "%02x", conf_signature[i]);
}
std::cerr << std::endl;
#endif
bool same = true;
for(i = 0; i < signlen; i++)
@ -2091,8 +2134,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
if (same == false)
{
#ifdef XPGP_DEBUG
std::cerr << "ERROR VALIDATING CONFIGURATION!" << std::endl;
std::cerr << "PLEASE FIX!" << std::endl;
#endif
return false;
}
@ -2107,8 +2152,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
std::string id;
if (ProcessXPGP(xpgp, id))
{
#ifdef XPGP_DEBUG
std::cerr << "Loaded Certificate: " << id;
std::cerr << std::endl;
#endif
}
}
}

View File

@ -31,7 +31,9 @@
#include "serialiser/rsconfigitems.h"
#define CONFIG_DEBUG 1
/****
* #define CONFIG_DEBUG 1
***/
p3ConfigMgr::p3ConfigMgr(p3AuthMgr *am, std::string dir, std::string fname, std::string signame)
:mAuthMgr(am), basedir(dir), metafname(fname), metasigfname(signame),

View File

@ -851,10 +851,12 @@ bool p3ConnectMgr::stunCheck()
void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::stunStatus()";
std::cerr << " id: " << RsUtil::BinToHex(id) << " raddr: " << inet_ntoa(raddr.sin_addr);
std::cerr << ":" << ntohs(raddr.sin_port);
std::cerr << std::endl;
#endif
connMtx.lock(); /* LOCK MUTEX */
@ -1263,19 +1265,22 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
it = mFriendList.find(id);
if (it == mFriendList.end())
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectAttempt() FAILED Not in FriendList!";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
return false;
}
if (it->second.connAddrs.size() < 1)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectAttempt() FAILED No ConnectAddresses";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
return false;
}
@ -1289,6 +1294,7 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
period = it->second.currentConnAddr.period;
type = it->second.currentConnAddr.type;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
std::cerr << " id: " << id;
std::cerr << std::endl;
@ -1298,6 +1304,7 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
std::cerr << " period: " << period;
std::cerr << " type: " << type;
std::cerr << std::endl;
#endif
return true;
}
@ -1323,12 +1330,14 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
return false;
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectResult() Success: ";
std::cerr << " id: " << id;
std::cerr << std::endl;
std::cerr << " Success: " << success;
std::cerr << " flags: " << flags;
std::cerr << std::endl;
#endif
it->second.inConnAttempt = false;
@ -1340,12 +1349,14 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
/* update address (will come through from DISC) */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
std::cerr << " id: " << id;
std::cerr << std::endl;
std::cerr << " Success: " << success;
std::cerr << " flags: " << flags;
std::cerr << std::endl;
#endif
/* change state */
@ -1419,6 +1430,7 @@ void p3ConnectMgr::peerStatus(std::string id,
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus()";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr);
@ -1429,6 +1441,7 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " flags: " << flags;
std::cerr << " source: " << source;
std::cerr << std::endl;
#endif
/* look up the id */
it = mFriendList.find(id);
@ -1440,17 +1453,23 @@ void p3ConnectMgr::peerStatus(std::string id,
if (it == mOthersList.end())
{
/* not found - ignore */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Peer Not Found - Ignore";
std::cerr << std::endl;
#endif
return;
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Peer is in mOthersList";
std::cerr << std::endl;
#endif
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Current Peer State:" << std::endl;
printConnectState(it->second);
std::cerr << std::endl;
#endif
/* update the status */
@ -1580,9 +1599,11 @@ void p3ConnectMgr::peerStatus(std::string id,
if (!isFriend)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() NOT FRIEND ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
return;
}
@ -1590,9 +1611,11 @@ void p3ConnectMgr::peerStatus(std::string id,
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() PEER ONLINE ALREADY ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
return;
}
@ -1600,6 +1623,7 @@ void p3ConnectMgr::peerStatus(std::string id,
/* are the addresses different? */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus()";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr);
@ -1610,6 +1634,7 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " flags: " << flags;
std::cerr << " source: " << source;
std::cerr << std::endl;
#endif
#ifndef P3CONNMGR_NO_AUTO_CONNECTION
@ -1644,6 +1669,7 @@ void p3ConnectMgr::peerStatus(std::string id,
pca.type = RS_NET_CONN_TCP_LOCAL;
pca.addr = details.laddr;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() ADDING TCP_LOCAL ADDR: ";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(pca.addr.sin_addr);
@ -1653,11 +1679,13 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " type: " << pca.type;
std::cerr << " source: " << source;
std::cerr << std::endl;
#endif
it->second.connAddrs.push_back(pca);
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Not adding Local Connect (Diff Network)";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(details.laddr.sin_addr);
@ -1665,6 +1693,7 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " own.laddr: " << inet_ntoa(ownState.localaddr.sin_addr);
std::cerr << ": " << ntohs(ownState.localaddr.sin_port);
std::cerr << std::endl;
#endif
}
@ -1680,6 +1709,7 @@ void p3ConnectMgr::peerStatus(std::string id,
pca.type = RS_NET_CONN_TCP_EXTERNAL;
pca.addr = details.raddr;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() ADDING TCP_REMOTE ADDR: ";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(pca.addr.sin_addr);
@ -1689,17 +1719,20 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << " type: " << pca.type;
std::cerr << " source: " << source;
std::cerr << std::endl;
#endif
it->second.connAddrs.push_back(pca);
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Not adding Remote Connect (Type != E or Invalid Network)";
std::cerr << " id: " << id;
std::cerr << " raddr: " << inet_ntoa(details.raddr.sin_addr);
std::cerr << ": " << ntohs(details.raddr.sin_port);
std::cerr << " type: " << details.type;
std::cerr << std::endl;
#endif
}
#endif // P3CONNMGR_NO_TCP_CONNECTIONS
@ -1719,6 +1752,7 @@ void p3ConnectMgr::peerStatus(std::string id,
if (it->second.inConnAttempt)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() ALREADY IN CONNECT ATTEMPT: ";
std::cerr << " id: " << id;
std::cerr << std::endl;
@ -1728,6 +1762,7 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << "p3ConnectMgr::peerStatus() Resulting Peer State:" << std::endl;
printConnectState(it->second);
std::cerr << std::endl;
#endif
return;
}
@ -1736,40 +1771,50 @@ void p3ConnectMgr::peerStatus(std::string id,
/* start a connection attempt */
if (it->second.connAddrs.size() > 0)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Started CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
it->second.actions |= RS_PEER_CONNECT_REQ;
mStatusChanged = true;
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() No addr suitable for CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerStatus() Resulting Peer State:" << std::endl;
printConnectState(it->second);
std::cerr << std::endl;
#endif
}
void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest()";
std::cerr << " id: " << id;
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr);
std::cerr << ":" << ntohs(raddr.sin_port);
std::cerr << " source: " << source;
std::cerr << std::endl;
#endif
/******************** TCP PART *****************************/
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Try TCP first";
std::cerr << std::endl;
#endif
retryConnectTCP(id);
@ -1779,8 +1824,10 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
if (ownState.netMode & RS_NET_MODE_UNREACHABLE)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Unreachable - no UDP connection";
std::cerr << std::endl;
#endif
return;
}
@ -1796,20 +1843,26 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
if (it == mOthersList.end())
{
/* not found - ignore */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Peer Not Found - Ignore";
std::cerr << std::endl;
#endif
return;
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Peer is in mOthersList - Ignore";
std::cerr << std::endl;
#endif
return;
}
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Already connected - Ignore";
std::cerr << std::endl;
#endif
return;
}
@ -1827,25 +1880,33 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
if (source == RS_CB_DHT)
{
pca.period = P3CONNMGR_UDP_DHT_DELAY;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() source = DHT ";
std::cerr << std::endl;
#endif
}
else if (source == RS_CB_PROXY)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() source = PROXY ";
std::cerr << std::endl;
#endif
pca.period = P3CONNMGR_UDP_PROXY_DELAY;
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() source = UNKNOWN ";
std::cerr << std::endl;
#endif
/* error! */
pca.period = P3CONNMGR_UDP_PROXY_DELAY;
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() period = " << pca.period;
std::cerr << std::endl;
#endif
pca.addr = raddr;
@ -1862,18 +1923,22 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
/* start a connection attempt */
if (it->second.connAddrs.size() > 0)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() Started CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
it->second.actions |= RS_PEER_CONNECT_REQ;
mStatusChanged = true;
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::peerConnectRequest() No addr suitable for CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
}
}
@ -2125,24 +2190,30 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* push addresses onto stack */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP()";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer is not Friend";
std::cerr << std::endl;
#endif
return false;
}
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer Already Connected";
std::cerr << std::endl;
#endif
return true;
}
@ -2162,10 +2233,12 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
&(it->second.localaddr.sin_addr))))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Local Address Valid: ";
std::cerr << inet_ntoa(it->second.localaddr.sin_addr);
std::cerr << ":" << ntohs(it->second.localaddr.sin_port);
std::cerr << std::endl;
#endif
bool localExists = false;
if ((it->second.inConnAttempt) &&
@ -2187,8 +2260,10 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
if (!localExists)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Adding Local Addr to Queue";
std::cerr << std::endl;
#endif
/* add the local address */
peerConnectAddress pca;
@ -2200,8 +2275,10 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Local Addr already in Queue";
std::cerr << std::endl;
#endif
}
}
@ -2212,10 +2289,12 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
/* always try external */
if (isValidNet(&(it->second.serveraddr.sin_addr)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Ext Address Valid: ";
std::cerr << inet_ntoa(it->second.serveraddr.sin_addr);
std::cerr << ":" << ntohs(it->second.serveraddr.sin_port);
std::cerr << std::endl;
#endif
bool remoteExists = false;
@ -2238,8 +2317,10 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
if (!remoteExists)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Adding Ext Addr to Queue";
std::cerr << std::endl;
#endif
/* add the remote address */
peerConnectAddress pca;
@ -2251,8 +2332,10 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Ext Addr already in Queue";
std::cerr << std::endl;
#endif
}
}
@ -2270,18 +2353,22 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
/* start a connection attempt */
if (it->second.connAddrs.size() > 0)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() Started CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
it->second.actions |= RS_PEER_CONNECT_REQ;
mStatusChanged = true;
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectTCP() No addr suitable for CONNECT ATTEMPT! ";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
}
return true;
}
@ -2292,25 +2379,31 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* push addresses onto stack */
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectNotify()";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectNotify() Peer is not Friend";
std::cerr << std::endl;
#endif
return false;
}
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectNotify() Peer Already Connected";
std::cerr << std::endl;
#endif
return true;
}
@ -2319,15 +2412,19 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
if (ownState.netMode & RS_NET_MODE_UNREACHABLE)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectNotify() UNREACHABLE so no Notify!";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::retryConnectNotify() Notifying Peer";
std::cerr << " id: " << id;
std::cerr << std::endl;
#endif
/* attempt UDP connection */
mDhtMgr->notifyPeer(id);
@ -2497,8 +2594,10 @@ bool p3ConnectMgr::getDHTEnabled()
bool p3ConnectMgr::checkNetAddress()
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress()";
std::cerr << std::endl;
#endif
std::list<std::string> addrs = getLocalInterfaces();
std::list<std::string>::iterator it;
@ -2508,13 +2607,17 @@ bool p3ConnectMgr::checkNetAddress()
bool found = false;
for(it = addrs.begin(); (!found) && (it != addrs.end()); it++)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Local Interface: " << *it;
std::cerr << std::endl;
#endif
if ((*it) == inet_ntoa(ownState.localaddr.sin_addr))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Matches Existing Address! FOUND = true";
std::cerr << std::endl;
#endif
found = true;
}
}
@ -2528,9 +2631,11 @@ bool p3ConnectMgr::checkNetAddress()
{
ownState.localaddr.sin_addr = getPreferredInterface();
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Local Address Not Found: Using Preferred Interface: ";
std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
std::cerr << std::endl;
#endif
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -2568,10 +2673,12 @@ bool p3ConnectMgr::checkNetAddress()
ownState.localaddr.sin_family = AF_INET;
ownState.serveraddr.sin_family = AF_INET;
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Final Local Address: ";
std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
std::cerr << ":" << ntohs(ownState.localaddr.sin_port);
std::cerr << std::endl;
#endif
return 1;
}

View File

@ -36,8 +36,6 @@
* #define P3DHTMGR_USE_LOCAL_UDP_CONN 1 // For Testing only
****/
#define DHT_DEBUG 1
/**** DHT State Variables ****
* TODO:
* (1) notify call in.
@ -950,7 +948,9 @@ int p3DhtMgr::checkStunState()
/* if we run out of stun peers -> get some more */
if (stunIds.size() < 1)
{
#ifdef DHT_DEBUG
std::cerr << "WARNING: out of Stun Peers - switching to Active Now" << std::endl;
#endif
mDhtState = DHT_STATE_ACTIVE;
dhtMtx.unlock(); /* UNLOCK MUTEX */
@ -980,7 +980,9 @@ int p3DhtMgr::checkStunState_Active()
if (moreIds)
/* if we run out of stun peers -> get some more */
{
#ifdef DHT_DEBUG
std::cerr << "WARNING: out of Stun Peers - getting more" << std::endl;
#endif
getDhtBootstrapList();
}
@ -1320,7 +1322,9 @@ bool p3DhtMgr::dhtPublish(std::string idhash,
bool p3DhtMgr::dhtNotify(std::string idhash, std::string ownIdHash, std::string sign)
{
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtNotify()" << std::endl;
#endif
std::ostringstream value;
value << "RSDHT:" << std::setw(2) << std::setfill('0') << DHT_MODE_NOTIFY << ":";
@ -1332,7 +1336,9 @@ bool p3DhtMgr::dhtNotify(std::string idhash, std::string ownIdHash, std::string
bool p3DhtMgr::dhtSearch(std::string idhash, uint32_t mode)
{
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtSearch()" << std::endl;
#endif
/* call to the real DHT */
return searchDHT(idhash);
@ -1341,7 +1347,9 @@ bool p3DhtMgr::dhtSearch(std::string idhash, uint32_t mode)
bool p3DhtMgr::dhtBootstrap(std::string storehash, std::string ownIdHash, std::string sign)
{
#ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::dhtBootstrap()" << std::endl;
#endif
std::ostringstream value;
value << "RSDHT:" << std::setw(2) << std::setfill('0') << DHT_MODE_BOOTSTRAP << ":";

View File

@ -37,6 +37,10 @@
#include <iomanip>
static const int pqinetzone = 96184;
/*****
* #define NET_DEBUG 1
****/
#ifdef WINDOWS_SYS /* Windows - define errno */
int errno;
@ -360,8 +364,10 @@ in_addr_t inet_network(const char *inet_name)
struct in_addr addr;
if (inet_aton(inet_name, &addr))
{
#ifdef NET_DEBUG
// std::cerr << "inet_network(" << inet_name << ") : ";
// std::cerr << inet_ntoa(addr) << std::endl;
#endif
return ntohl(inet_netof(addr));
}
return 0xffffffff;
@ -387,59 +393,66 @@ in_addr_t pqi_inet_netof(struct in_addr addr)
unsigned long bbit = haddr & 0xffff0000UL;
unsigned long cbit = haddr & 0xffffff00UL;
#ifdef NET_DEBUG
std::cerr << "inet_netof(" << inet_ntoa(addr) << ") ";
#endif
if (!((haddr >> 31) | 0x0UL)) // MSB = 0
{
#ifdef NET_DEBUG
std::cerr << " Type A " << std::endl;
std::cerr << "\tShifted(31): " << (haddr >> 31);
std::cerr << " Xord(0x0UL): " <<
!((haddr >> 31) | 0x0UL) << std::endl;
#endif
return htonl(abit);
//return abit;
}
else if (!((haddr >> 30) ^ 0x2UL)) // 2MSBs = 10
{
#ifdef NET_DEBUG
std::cerr << " Type B " << std::endl;
std::cerr << "\tShifted(30): " << (haddr >> 30);
std::cerr << " Xord(0x2UL): " <<
!((haddr >> 30) | 0x2UL) << std::endl;
#endif
return htonl(bbit);
//return bbit;
}
else if (!((haddr >> 29) ^ 0x6UL)) // 3MSBs = 110
{
#ifdef NET_DEBUG
std::cerr << " Type C " << std::endl;
std::cerr << "\tShifted(29): " << (haddr >> 29);
std::cerr << " Xord(0x6UL): " <<
!((haddr >> 29) | 0x6UL) << std::endl;
#endif
return htonl(cbit);
//return cbit;
}
else if (!((haddr >> 28) ^ 0xeUL)) // 4MSBs = 1110
{
#ifdef NET_DEBUG
std::cerr << " Type Multicast " << std::endl;
std::cerr << "\tShifted(28): " << (haddr >> 28);
std::cerr << " Xord(0xeUL): " <<
!((haddr >> 29) | 0xeUL) << std::endl;
#endif
return addr.s_addr; // return full address.
//return haddr;
}
else if (!((haddr >> 27) ^ 0x1eUL)) // 5MSBs = 11110
{
#ifdef NET_DEBUG
std::cerr << " Type Reserved " << std::endl;
std::cerr << "\tShifted(27): " << (haddr >> 27);
std::cerr << " Xord(0x1eUL): " <<
!((haddr >> 27) | 0x1eUL) << std::endl;
#endif
return addr.s_addr; // return full address.
//return haddr;
}
return htonl(abit);
//return abit;
}
int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 )
@ -455,12 +468,14 @@ int sockaddr_cmp(struct sockaddr_in &addr1, struct sockaddr_in &addr2 )
int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 )
{
#ifdef NET_DEBUG
std::ostringstream out;
out << "inaddr_cmp(" << inet_ntoa(addr1.sin_addr);
out << "-" << addr1.sin_addr.s_addr;
out << "," << inet_ntoa(addr2.sin_addr);
out << "-" << addr2.sin_addr.s_addr << ")" << std::endl;
pqioutput(PQL_DEBUG_BASIC, pqinetzone, out.str());
#endif
if (addr1.sin_addr.s_addr == addr2.sin_addr.s_addr)
@ -474,8 +489,10 @@ int inaddr_cmp(struct sockaddr_in addr1, struct sockaddr_in addr2 )
int inaddr_cmp(struct sockaddr_in addr1, unsigned long addr2)
{
#ifdef NET_DEBUG
struct in_addr inaddr_tmp;
inaddr_tmp.s_addr = addr2;
std::ostringstream out;
out << "inaddr_cmp2(" << inet_ntoa(addr1.sin_addr);
out << " vs " << inet_ntoa(inaddr_tmp);
@ -483,6 +500,7 @@ int inaddr_cmp(struct sockaddr_in addr1, unsigned long addr2)
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
if (addr1.sin_addr.s_addr == addr2)
{
@ -569,16 +587,21 @@ struct in_addr getPreferredInterface() // returns best addr.
bool sameNet(struct in_addr *addr, struct in_addr *addr2)
{
#ifdef NET_DEBUG
std::cerr << "sameNet: " << inet_ntoa(*addr);
std::cerr << " VS " << inet_ntoa(*addr2);
std::cerr << std::endl;
#endif
struct in_addr addrnet, addrnet2;
addrnet.s_addr = inet_netof(*addr);
addrnet2.s_addr = inet_netof(*addr2);
#ifdef NET_DEBUG
std::cerr << " (" << inet_ntoa(addrnet);
std::cerr << " =?= " << inet_ntoa(addrnet2);
std::cerr << ")" << std::endl;
#endif
in_addr_t address1 = htonl(addr->s_addr);
in_addr_t address2 = htonl(addr2->s_addr);
@ -634,30 +657,41 @@ bool LookupDNSAddr(std::string name, struct sockaddr_in &addr)
sprintf(service, "%d", ntohs(addr.sin_port));
/* set it to IPV4 */
#ifdef NET_DEBUG
std::cerr << "LookupDNSAddr() name: " << name << " service: " << service << std::endl;
#endif
int err = 0;
if (0 != (err = getaddrinfo(name.c_str(), service, hints, &res)))
{
#ifdef NET_DEBUG
std::cerr << "LookupDNSAddr() getaddrinfo failed!" << std::endl;
std::cerr << "Error: " << gai_strerror(err) << std::endl;
#endif
return false;
}
if ((res) && (res->ai_family == AF_INET))
{
std::cerr << "LookupDNSAddr() getaddrinfo found address" << std::endl;
addr = *((struct sockaddr_in *) res->ai_addr);
freeaddrinfo(res);
#ifdef NET_DEBUG
std::cerr << "LookupDNSAddr() getaddrinfo found address" << std::endl;
std::cerr << "addr: " << inet_ntoa(addr.sin_addr) << std::endl;
std::cerr << "port: " << ntohs(addr.sin_port) << std::endl;
freeaddrinfo(res);
#endif
return true;
}
#ifdef NET_DEBUG
std::cerr << "getaddrinfo failed - no address" << std::endl;
#endif
#endif
std::cerr << "getaddrinfo disabled" << std::endl;
#ifdef NET_DEBUG
//std::cerr << "getaddrinfo disabled" << std::endl;
#endif
return false;
}
@ -674,7 +708,10 @@ int unix_close(int fd)
#ifndef WINDOWS_SYS // ie UNIX
ret = close(fd);
#else
#ifdef NET_DEBUG
std::cerr << "unix_close()" << std::endl;
#endif
ret = closesocket(fd);
/* translate error */
#endif
@ -688,7 +725,11 @@ int unix_socket(int domain, int type, int protocol)
/******************* WINDOWS SPECIFIC PART ******************/
#ifdef WINDOWS_SYS // WINDOWS
#ifdef NET_DEBUG
std::cerr << "unix_socket()" << std::endl;
#endif
if ((unsigned) osock == INVALID_SOCKET)
{
// Invalidate socket Unix style.
@ -708,11 +749,18 @@ int unix_fcntl_nonblock(int fd)
/******************* WINDOWS SPECIFIC PART ******************/
#ifndef WINDOWS_SYS // ie UNIX
ret = fcntl(fd, F_SETFL, O_NONBLOCK);
#ifdef NET_DEBUG
std::cerr << "unix_fcntl_nonblock():" << ret << " errno:" << errno << std::endl;
#endif
#else
unsigned long int on = 1;
ret = ioctlsocket(fd, FIONBIO, &on);
#ifdef NET_DEBUG
std::cerr << "unix_fcntl_nonblock()" << std::endl;
#endif
if (ret != 0)
{
/* store unix-style error
@ -732,7 +780,10 @@ int unix_connect(int fd, const struct sockaddr *serv_addr, socklen_t addrlen)
/******************* WINDOWS SPECIFIC PART ******************/
#ifdef WINDOWS_SYS // WINDOWS
#ifdef NET_DEBUG
std::cerr << "unix_connect()" << std::endl;
#endif
if (ret != 0)
{
errno = WinToUnixError(WSAGetLastError());
@ -756,7 +807,9 @@ int unix_getsockopt_error(int sockfd, int *err)
int optlen = 4;
ret=getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char *) err, &optlen);
/* translate */
#ifdef NET_DEBUG
std::cerr << "unix_getsockopt_error() returned: " << (int) err << std::endl;
#endif
if (*err != 0)
{
*err = WinToUnixError(*err);
@ -771,7 +824,9 @@ int unix_getsockopt_error(int sockfd, int *err)
int WinToUnixError(int error)
{
#ifdef NET_DEBUG
std::cerr << "WinToUnixError(" << error << ")" << std::endl;
#endif
switch(error)
{
case WSAEINPROGRESS:
@ -796,8 +851,10 @@ int WinToUnixError(int error)
return ECONNRESET;
break;
default:
#ifdef NET_DEBUG
std::cerr << "WinToUnixError(" << error << ") Code Unknown!";
std::cerr << std::endl;
#endif
break;
}
return ECONNREFUSED; /* sensible default? */

View File

@ -31,6 +31,9 @@ const int pqipersonzone = 82371;
#include "pqi/pqidebug.h"
#include <sstream>
/****
* #define PERSON_DEBUG
****/
pqiperson::pqiperson(std::string id, pqipersongrp *pg)
:PQInterface(id), active(false), activepqi(NULL),
@ -345,6 +348,7 @@ int pqiperson::stoplistening()
int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout)
{
#ifdef PERSON_DEBUG
{
std::ostringstream out;
out << "pqiperson::connect() Id: " << PeerId();
@ -358,25 +362,30 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
}
#endif
std::map<uint32_t, pqiconnect *>::iterator it;
it = kids.find(type);
if (it == kids.end())
{
#ifdef PERSON_DEBUG
std::ostringstream out;
out << "pqiperson::connect()";
out << " missing pqiconnect";
out << std::endl;
std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
#endif
return 0;
}
/* set the parameters */
(it->second)->reset();
#ifdef PERSON_DEBUG
std::cerr << "pqiperson::connect() setting connect_parameters" << std::endl;
#endif
(it->second)->connect_parameter(NET_PARAM_CONNECT_DELAY, delay);
(it->second)->connect_parameter(NET_PARAM_CONNECT_PERIOD, period);
(it->second)->connect_parameter(NET_PARAM_CONNECT_TIMEOUT, timeout);

View File

@ -32,8 +32,8 @@
const int pqipersongrpzone = 354;
/****
#define DEBUG_TICK 1
****/
*#define PGRP_DEBUG 1
****/
// handle the tunnel services.
int pqipersongrp::tickServiceRecv()
@ -114,7 +114,7 @@ int pqipersongrp::tick()
if (tickServiceSend())
{
i = 1;
#ifdef DEBUG_TICK
#ifdef PGRP_DEBUG
std::cerr << "pqipersongrp::tick() moreToTick from tickServiceSend()" << std::endl;
#endif
}
@ -122,7 +122,7 @@ int pqipersongrp::tick()
if (pqihandler::tick()) /* does actual Send/Recv */
{
i = 1;
#ifdef DEBUG_TICK
#ifdef PGRP_DEBUG
std::cerr << "pqipersongrp::tick() moreToTick from pqihandler::tick()" << std::endl;
#endif
}
@ -131,7 +131,7 @@ int pqipersongrp::tick()
if (tickServiceRecv())
{
i = 1;
#ifdef DEBUG_TICK
#ifdef PGRP_DEBUG
std::cerr << "pqipersongrp::tick() moreToTick from tickServiceRecv()" << std::endl;
#endif
}
@ -279,8 +279,10 @@ int pqipersongrp::addPeer(std::string id)
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone, out.str());
}
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::addPeer() id: " << id;
std::cerr << std::endl;
#endif
SearchModule *sm = NULL;
std::map<std::string, SearchModule *>::iterator it;
@ -312,8 +314,10 @@ int pqipersongrp::removePeer(std::string id)
{
std::map<std::string, SearchModule *>::iterator it;
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::removePeer() id: " << id;
std::cerr << std::endl;
#endif
it = mods.find(id);
if (it != mods.end())
@ -333,8 +337,10 @@ int pqipersongrp::removePeer(std::string id)
int pqipersongrp::connectPeer(std::string id)
{
/* get status from p3connectMgr */
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() id: " << id << " does nothing yet! ";
std::cerr << std::endl;
#endif
std::map<std::string, SearchModule *>::iterator it;
it = mods.find(id);
@ -359,17 +365,21 @@ int pqipersongrp::connectPeer(std::string id)
if (!mConnMgr->connectAttempt(id, addr, delay, period, type))
{
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() No Net Address";
std::cerr << std::endl;
#endif
return 0;
}
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() connectAttempt data id: " << id;
std::cerr << " addr: " << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port);
std::cerr << " delay: " << delay;
std::cerr << " period: " << period;
std::cerr << " type: " << type;
std::cerr << std::endl;
#endif
uint32_t ptype;
@ -377,15 +387,19 @@ int pqipersongrp::connectPeer(std::string id)
{
ptype = PQI_CONNECT_TCP;
timeout = RS_TCP_STD_TIMEOUT_PERIOD;
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() connecting with TCP: Timeout :" << timeout;
std::cerr << std::endl;
#endif
}
else if (type & RS_NET_CONN_UDP_ALL)
{
ptype = PQI_CONNECT_UDP;
timeout = period * 2;
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout;
std::cerr << std::endl;
#endif
}
else
return 0;

View File

@ -257,16 +257,16 @@ int pqissl::reset()
bool pqissl::connect_parameter(uint32_t type, uint32_t value)
{
std::cerr << "pqissl::connect_parameter() type: " << type << "value: " << value << std::endl;
//std::cerr << "pqissl::connect_parameter() type: " << type << "value: " << value << std::endl;
if (type == NET_PARAM_CONNECT_DELAY)
{
std::cerr << "pqissl::connect_parameter() DELAY: " << value << std::endl;
//std::cerr << "pqissl::connect_parameter() DELAY: " << value << std::endl;
mConnectDelay = value;
return true;
}
else if (type == NET_PARAM_CONNECT_TIMEOUT)
{
std::cerr << "pqissl::connect_parameter() TIMEOUT: " << value << std::endl;
//std::cerr << "pqissl::connect_parameter() TIMEOUT: " << value << std::endl;
mConnectTimeout = value;
return true;
}
@ -604,7 +604,7 @@ int pqissl::Initiate_Connection()
}
mTimeoutTS = time(NULL) + mConnectTimeout;
std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
//std::cerr << "Setting Connect Timeout " << mConnectTimeout << " Seconds into Future " << std::endl;
if (0 != (err = unix_connect(osock, (struct sockaddr *) &addr, sizeof(addr))))
{
@ -655,7 +655,7 @@ int pqissl::Initiate_Connection()
pqioutput(PQL_WARNING, pqisslzone, out.str());
// extra output for the moment.
std::cerr << out.str();
//std::cerr << out.str();
return -1;
}
@ -701,10 +701,10 @@ int pqissl::Basic_Connection_Complete()
"pqissl::Basic_Connection_Complete() Connection Timed Out!");
/* as sockfd is valid, this should close it all up */
std::cerr << "pqissl::Basic_Connection_Complete() Connection Timed Out!";
std::cerr << std::endl;
std::cerr << "pqissl::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout;
std::cerr << std::endl;
//std::cerr << "pqissl::Basic_Connection_Complete() Connection Timed Out!";
//std::cerr << std::endl;
//std::cerr << "pqissl::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout;
//std::cerr << std::endl;
reset();
return -1;
}

View File

@ -234,41 +234,26 @@ bool RsDistribSerialiser::serialiseGrp(RsDistribGrp *item, void *data, uint3
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsDistribSerialiser::serialiseGrp() Header: " << ok << std::endl;
std::cerr << "RsDistribSerialiser::serialiseGrp() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* RsDistribGrp */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpId: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
std::cerr << "RsDistribSerialiser::serialiseGrp() timestamp: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->grpFlags);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpFlags: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_NAME, item->grpName);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpName: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->grpDesc);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpDesc: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_CATEGORY, item->grpCategory);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpCategory: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->grpControlFlags);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpControlFlags: " << ok << std::endl;
ok &= item->grpControlList.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpControlList: " << ok << std::endl;
ok &= item->grpPixmap.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrp() grpPixmap: " << ok << std::endl;
ok &= item->adminKey.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrp() adminKey: " << ok << std::endl;
ok &= item->publishKeys.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrp() publishKeys: " << ok << std::endl;
ok &= item->adminSignature.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrp() adminSignature: " << ok << std::endl;
if (offset != tlvsize)
{
@ -371,18 +356,13 @@ bool RsDistribSerialiser::serialiseGrpKey(RsDistribGrpKey *item, void *data,
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsDistribSerialiser::serialiseGrpKey() Header: " << ok << std::endl;
std::cerr << "RsDistribSerialiser::serialiseGrpKey() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* RsDistribGrp */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
std::cerr << "RsDistribSerialiser::serialiseGrpKey() grpId: " << ok << std::endl;
ok &= item->key.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseGrpKey() key: " << ok << std::endl;
if (offset != tlvsize)
{
@ -477,30 +457,20 @@ bool RsDistribSerialiser::serialiseSignedMsg(RsDistribSignedMsg *item, void
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() Header: " << ok << std::endl;
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* RsDistribSignedMsg */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->grpId);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() grpId: " << ok << std::endl;
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID, item->msgId);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() msgId: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->flags);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() flags: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() timestamp: " << ok << std::endl;
ok &= item->packet.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() packet: " << ok << std::endl;
ok &= item->publishSignature.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() publishSignature: " << ok << std::endl;
ok &= item->personalSignature.SetTlv(data, tlvsize, &offset);
std::cerr << "RsDistribSerialiser::serialiseSignedMsg() personalSignature: " << ok << std::endl;
if (offset != tlvsize)
{

View File

@ -147,34 +147,23 @@ bool RsRankSerialiser::serialiseLink(RsRankLinkMsg *item, void *data, uint32
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsRankLinkSerialiser::serialiseLink() Header: " << ok << std::endl;
std::cerr << "RsRankLinkSerialiser::serialiseLink() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid);
std::cerr << "RsRankLinkSerialiser::serialiseLink() rid: " << ok << std::endl;
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->pid);
std::cerr << "RsRankLinkSerialiser::serialiseLink() pid: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
std::cerr << "RsRankLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
std::cerr << "RsRankLinkSerialiser::serialiseLink() Title: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
std::cerr << "RsRankLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, *((uint32_t *) &(item->score)));
std::cerr << "RsRankLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
std::cerr << "RsRankLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
std::cerr << "RsRankLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
if (offset != tlvsize)
{

View File

@ -270,7 +270,7 @@ bool RsTlvPeerIdSet::GetTlv(void *data, uint32_t size, uint32_t *offset) /*
if (size < tlvend) /* check size */
return false; /* not enough space */
std::cout << "yeah!!!" << std::endl;
if (tlvtype != TLV_TYPE_PEERSET) /* check type */
return false;

View File

@ -318,9 +318,11 @@ int filedexserver::FileCacheSave()
std::map<CacheId, CacheData> ids;
std::map<CacheId, CacheData>::iterator it;
#ifdef SERVER_DEBUG
std::cerr << "filedexserver::FileCacheSave() listCaches:" << std::endl;
fimon->listCaches(std::cerr);
fimon->cachesAvailable(pid, ids);
#endif
std::string localCacheFile;
std::string localCacheHash;
@ -482,10 +484,12 @@ int filedexserver::handleInputQueues()
ci -> cacheType = (it->second).cid.type;
ci -> cacheSubId = (it->second).cid.subid;
#ifdef SERVER_DEBUG
std::ostringstream out2;
out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl;
ci -> print(out2);
std::cerr << out2.str() << std::endl;
#endif
//pqioutput(PQL_DEBUG_BASIC, fldxsrvrzone, out2.str());
pqisi -> SendSearchResult(ci);
@ -523,8 +527,8 @@ int filedexserver::handleInputQueues()
i_init = i;
while((fd = pqisi -> GetFileData()) != NULL )
{
//std::cerr << "filedexserver::handleInputQueues() Recvd ftFiler Data" << std::endl;
#ifdef SERVER_DEBUG
//std::cerr << "filedexserver::handleInputQueues() Recvd ftFiler Data" << std::endl;
std::ostringstream out;
if (i == i_init)
{

View File

@ -26,17 +26,26 @@
#include "server/ft.h"
/****
* #define FT_DEBUG 1
***/
bool ftManager::lookupLocalHash(std::string hash, std::string &path, uint64_t &size)
{
std::list<FileDetail> details;
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() hash: " << hash << std::endl;
#endif
if (FindCacheFile(hash, path, size))
{
/* got it from the CacheTransfer() */
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() Found in CacheStrapper:";
std::cerr << path << " size: " << size << std::endl;
#endif
return true;
}
@ -48,13 +57,17 @@ bool ftManager::lookupLocalHash(std::string hash, std::string &path, uint64_t &s
}
else
{
#ifdef FT_DEBUG
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
#endif
}
if (ok)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupLocalHash() Found in FileHashSearch:";
std::cerr << path << " size: " << size << std::endl;
#endif
return true;
}
return ok;
@ -68,7 +81,9 @@ bool ftManager::lookupRemoteHash(std::string hash, std::list<std::string> &ids)
std::list<FileDetail> details;
std::list<FileDetail>::iterator it;
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() hash: " << hash << std::endl;
#endif
if (fhs)
{
@ -76,19 +91,25 @@ bool ftManager::lookupRemoteHash(std::string hash, std::list<std::string> &ids)
}
else
{
#ifdef FT_DEBUG
std::cerr << "Warning FileHashSearch is Invalid" << std::endl;
#endif
}
if (details.size() == 0)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() Not Found!" << std::endl;
#endif
return false;
}
for(it = details.begin(); it != details.end(); it++)
{
#ifdef FT_DEBUG
std::cerr << "ftManager::lookupRemoteHash() Found in FileHashSearch:";
std::cerr << " id: " << it->id << std::endl;
#endif
ids.push_back(it->id);
}
return true;

View File

@ -37,6 +37,10 @@
const int ftfilerzone = 86539;
/****
* #define FT_DEBUG 1
***/
/*
* PQI Filer
*
@ -84,6 +88,7 @@ int ftfiler::getFile(std::string name, std::string hash,
uint64_t size, std::string destpath)
{
/* add to local queue */
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::getFile(): ";
@ -92,14 +97,17 @@ int ftfiler::getFile(std::string name, std::string hash,
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* check for duplicates */
ftFileStatus *state = findRecvFileItem(hash);
if (state)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::getFile() - duplicate, giving push!";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* if duplicate - give download a push! */
/* do this by flagging last transfer at 0.
@ -119,11 +127,13 @@ int ftfiler::getFile(std::string name, std::string hash,
state = new ftFileStatus(name, hash, size, "", FT_MODE_STD);
if (initiateFileTransfer(state))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::getFile() ";
out << "adding to recvFiles queue";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
recvFiles.push_back(state);
}
return 1;
@ -132,6 +142,7 @@ int ftfiler::getFile(std::string name, std::string hash,
bool ftfiler::RequestCacheFile(std::string id, std::string destpath, std::string hash, uint64_t size)
{
/* add to local queue */
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::getCacheFile(): ";
@ -141,14 +152,17 @@ bool ftfiler::RequestCacheFile(std::string id, std::string destpath, std::str
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* check for duplicates */
ftFileStatus *state = findRecvFileItem(hash);
if (state)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::getFile() - duplicate, giving push!";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* if duplicate - give download a push! */
/* do this by flagging last transfer at 0.
@ -166,10 +180,12 @@ bool ftfiler::RequestCacheFile(std::string id, std::string destpath, std::str
state = new ftFileStatus(id, hash, hash, size, destpath, FT_MODE_CACHE);
if (initiateFileTransfer(state))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::getFile() ";
out << "adding to recvFiles queue";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
recvFiles.push_back(state);
}
@ -180,11 +196,13 @@ bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
std::string hash, uint64_t size)
{
/* clean up old transfer - just remove it (no callback) */
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::CancelCacheFile() Looking for: " << hash;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* iterate through fileItems and check for this one */
std::list<ftFileStatus *>::iterator it;
@ -194,6 +212,7 @@ bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
(size==(*it)->size) &&
((*it)->ftMode == FT_MODE_CACHE))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::CancelCacheFile() ";
out << "Match ftFileStatus: " << hash;
@ -202,6 +221,8 @@ bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
std::cerr << "Clearing Failed Cache Transfer: " << (*it)->name;
std::cerr << std::endl;
#endif
delete (*it);
it = recvFiles.erase(it);
@ -209,10 +230,12 @@ bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
}
}
#ifdef FT_DEBUG
std::cerr << "************* ERROR *****************";
std::cerr << std::endl;
std::cerr << "ftfiler::CancelCacheFile() Failed to Find: " << hash;
std::cerr << std::endl;
#endif
return false;
}
@ -220,11 +243,13 @@ bool ftfiler::CancelCacheFile(RsPeerId id, std::string path,
ftFileStatus *ftfiler::findRecvFileItem(std::string hash)
{
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::findRecvFileItem() Looking for: " << hash;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* iterate through fileItems and check for this one */
std::list<ftFileStatus *>::iterator it;
@ -232,10 +257,12 @@ ftFileStatus *ftfiler::findRecvFileItem(std::string hash)
{
if (hash==(*it)->hash)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::findRecvFileItem() ";
out << "Match ftFileStatus: " << hash;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* same */
return (*it);
}
@ -250,21 +277,25 @@ int ftfiler::cancelFile(std::string hash)
{
/* flag as cancelled */
/* iterate through fileItems and check for this one */
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::cancelFile() hash: " << hash << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
std::list<ftFileStatus *>::iterator it;
for(it = recvFiles.begin(); it != recvFiles.end(); it++)
{
if (hash==(*it)->hash)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::cancelFile() ";
out << "Found file: " << hash;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* same */
(*it)->status = (PQIFILE_FAIL | PQIFILE_FAIL_CANCEL);
@ -272,12 +303,14 @@ int ftfiler::cancelFile(std::string hash)
}
}
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::cancelFile() ";
out << "couldn't match ftFileStatus!";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
return 0;
}
@ -285,8 +318,10 @@ int ftfiler::clearFailedTransfers()
{
/* remove all the failed items */
/* iterate through fileItems and check for this one */
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::clearFailedTransfers()");
#endif
std::list<ftFileStatus *>::iterator it;
int cleared = 0;
@ -294,10 +329,12 @@ int ftfiler::clearFailedTransfers()
{
if ((*it)->status & PQIFILE_FAIL)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::clearFailedTransfers() ";
out << "removing item: " << (*it) -> name;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* same */
ftFileStatus *cfile = (*it);
@ -307,11 +344,13 @@ int ftfiler::clearFailedTransfers()
}
else if ((*it)->status & PQIFILE_COMPLETE)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::clearFailedTransfers() ";
out << "removing Completed item: ";
out << (*it) -> name;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* same */
ftFileStatus *cfile = (*it);
@ -325,20 +364,26 @@ int ftfiler::clearFailedTransfers()
}
}
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::clearFailedTransfers() cleared: ";
out << cleared;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
return 1;
}
std::list<RsFileTransfer *> ftfiler::getStatus()
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::getTransferStatus()");
#endif
std::list<RsFileTransfer *> stateList;
/* iterate through all files to recv */
@ -525,8 +570,11 @@ int ftfiler::recvFileInfo(ftFileRequest *in)
int ftfiler::handleFileError(std::string hash, uint32_t err)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileError()");
#endif
/* get out the error */
if (err & PQIFILE_NOT_ONLINE)
{
@ -541,8 +589,11 @@ int ftfiler::handleFileError(std::string hash, uint32_t err)
int ftfiler::handleFileNotOnline(std::string hash)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileNotOnline()");
#endif
/* flag recvFile item as not Online */
ftFileStatus *s = findRecvFileItem(hash);
if ((!s) || (s -> status & PQIFILE_FAIL))
@ -558,8 +609,11 @@ int ftfiler::handleFileNotOnline(std::string hash)
int ftfiler::handleFileNotAvailable(std::string hash)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileNotAvailable()");
#endif
/* error - flag recvFile item with FAILED */
ftFileStatus *s = findRecvFileItem(hash);
if (!s)
@ -575,21 +629,28 @@ int ftfiler::handleFileNotAvailable(std::string hash)
int ftfiler::handleFileData(std::string hash, uint64_t offset,
void *data, uint32_t datalen)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileData()");
#endif
/* find the right ftFileStatus */
ftFileStatus *recv = findRecvFileItem(hash);
if (!recv)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileData() no matching ftFileStatus (current download)");
#endif
return 0;
}
if(recv->status & PQIFILE_FAIL)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileData() marked as FAIL");
#endif
return 0;
}
@ -613,8 +674,10 @@ int ftfiler::handleFileData(std::string hash, uint64_t offset,
int ftfiler::handleFileRequest(std::string id, std::string hash, uint64_t offset, uint32_t chunk)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileRequest()");
#endif
/* see if in cache */
/* if yes send out chunk */
if (handleFileCacheRequest(id, hash, offset, chunk))
@ -627,8 +690,10 @@ int ftfiler::handleFileRequest(std::string id, std::string hash, uint64_t offset
if (!new_file)
{
/* bad file */
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileRequest() Failed to Load File-sendNotAvail");
#endif
return 0;
//sendFileNotAvail(in);
}
@ -640,8 +705,10 @@ int ftfiler::handleFileRequest(std::string id, std::string hash, uint64_t offset
int ftfiler::handleFileCacheRequest(std::string id, std::string hash, uint64_t offset, uint32_t chunk)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::handleFileCacheRequest()");
#endif
/* check if in cache */
bool found = false;
ftFileStatus *s;
@ -675,8 +742,10 @@ int ftfiler::handleFileCacheRequest(std::string id, std::string hash, uint64_t o
int ftfiler::tick()
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::tick()");
#endif
/* check the status of recved files */
queryInactive();
@ -690,11 +759,12 @@ int ftfiler::tick()
void ftfiler::queryInactive()
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::queryInactive()";
out << std::endl;
#endif
/* iterate through all files to recv */
@ -706,6 +776,7 @@ void ftfiler::queryInactive()
switch((*it) -> status)
{
case PQIFILE_NOT_ONLINE:
#ifdef FT_DEBUG
out << "File: " << (*it)->name << " Not Online: ";
out << "Delta: " << (ts - (*it)->lastTS) << std::endl;
out << " LDelta: " << (*it)->lastDelta;
@ -713,6 +784,7 @@ void ftfiler::queryInactive()
out << " Total: " << (*it)->total_size;
out << " LChunk: " << (*it)->req_size;
out << std::endl;
#endif
if (ts - ((*it)->lastTS) > PQIFILE_OFFLINE_CHECK)
{
@ -721,6 +793,7 @@ void ftfiler::queryInactive()
}
break;
case PQIFILE_DOWNLOADING:
#ifdef FT_DEBUG
out << "File: " << (*it)->name << " Downloading: ";
out << " Delta: " << (ts - (*it)->lastTS) << std::endl;
out << " LDelta: " << (*it)->lastDelta;
@ -728,6 +801,7 @@ void ftfiler::queryInactive()
out << " Total: " << (*it)->total_size;
out << " LChunk: " << (*it)->req_size;
out << std::endl;
#endif
if (ts - ((*it)->lastTS) > PQIFILE_DOWNLOAD_CHECK)
{
@ -735,6 +809,7 @@ void ftfiler::queryInactive()
}
break;
default:
#ifdef FT_DEBUG
out << "File: " << (*it)->name << " Other mode: " << (*it)->status;
out << " Delta: " << (ts - (*it)->lastTS) << std::endl;
out << " LDelta: " << (*it)->lastDelta;
@ -742,6 +817,7 @@ void ftfiler::queryInactive()
out << " Total: " << (*it)->total_size;
out << " LChunk: " << (*it)->req_size;
out << std::endl;
#endif
/* nothing */
break;
}
@ -749,8 +825,10 @@ void ftfiler::queryInactive()
/* remove/increment */
if (((*it) -> status == PQIFILE_COMPLETE) && ((*it)->ftMode == FT_MODE_CACHE))
{
#ifdef FT_DEBUG
std::cerr << "Clearing Completed Cache File: " << (*it)->name;
std::cerr << std::endl;
#endif
delete (*it);
it = recvFiles.erase(it);
}
@ -767,8 +845,10 @@ void ftfiler::queryInactive()
{
if (now - (*it)->lastTS > CACHE_FILE_TIMEOUT)
{
#ifdef FT_DEBUG
std::cerr << "Clearing Timed-out Cache File: " << (*it)->name;
std::cerr << std::endl;
#endif
delete (*it);
it = fileCache.erase(it);
}
@ -778,7 +858,9 @@ void ftfiler::queryInactive()
}
}
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
}
@ -791,8 +873,10 @@ int ftfiler::requestData(ftFileStatus *item)
* well.
*/
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::requestData()" << std::endl;
#endif
/* get the time since last request */
int tm = time(NULL);
@ -821,8 +905,10 @@ int ftfiler::requestData(ftFileStatus *item)
default:
break;
}
#ifdef FT_DEBUG
out << "max rate: " << max_rate;
out << std::endl;
#endif
/* not finished */
if (item->recv_size < item->req_loc + item->req_size)
@ -834,17 +920,23 @@ int ftfiler::requestData(ftFileStatus *item)
*/
/* start again slowly */
item->req_size = (int) (0.1 * max_rate);
#ifdef FT_DEBUG
out << "Timeout: switching to Offline.";
out << std::endl;
#endif
item->status = PQIFILE_NOT_ONLINE;
}
else
{
#ifdef FT_DEBUG
out << "Pause: Not Finished";
out << std::endl;
#endif
/* pause */
}
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
return 0;
}
@ -852,9 +944,11 @@ int ftfiler::requestData(ftFileStatus *item)
if (delta <= PQIFILE_DOWNLOAD_MIN_DELTA)
{
/* pause */
#ifdef FT_DEBUG
out << "Small Delta -> Pause";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
return 0;
}
@ -862,8 +956,10 @@ int ftfiler::requestData(ftFileStatus *item)
/* calc rate */
float bytes_psec = item -> req_size / delta;
item -> rate = 0.7 * item -> rate + 0.3 * bytes_psec;
#ifdef FT_DEBUG
out << "delta: " << delta << " bytes: " << bytes_psec << " rate: " << item -> rate;
out << std::endl;
#endif
if (item->lastDelta <= PQIFILE_DOWNLOAD_TOO_FAST)
{
@ -881,11 +977,13 @@ int ftfiler::requestData(ftFileStatus *item)
if (item->req_size > max_rate * PQIFILE_DOWNLOAD_CHECK)
item->req_size = (int) (max_rate * PQIFILE_DOWNLOAD_CHECK);
#ifdef FT_DEBUG
out << "Small Delta: " << ldelta_f << " (sec), rate: " << tf_p_sec;
out << std::endl;
out << "Small Delta Incrementing req_size from: " << data_tf;
out << " to :" << item->req_size;
out << std::endl;
#endif
}
else if (item->lastDelta > PQIFILE_DOWNLOAD_TOO_SLOW)
@ -899,11 +997,13 @@ int ftfiler::requestData(ftFileStatus *item)
item -> req_size -= (int) (1.25 * extra_tf);
#ifdef FT_DEBUG
out << "Long Delta: " << ldelta_f << " (sec), rate: " << tf_p_sec;
out << std::endl;
out << "Long Delta Decrementing req_size from: " << data_tf;
out << " to :" << item->req_size;
out << std::endl;
#endif
}
/* make the packet */
@ -926,9 +1026,11 @@ int ftfiler::requestData(ftFileStatus *item)
}
}
#ifdef FT_DEBUG
out << "Making Packet: offset: " << item->req_loc << " size: " << item->req_size;
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
ftFileRequest *req = generateFileRequest(item);
out_queue.push_back(req);
@ -947,28 +1049,38 @@ int ftfiler::requestData(ftFileStatus *item)
int ftfiler::generateFileData(ftFileStatus *s, std::string id, uint64_t offset, uint32_t chunk)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::generateFileData()");
#endif
if ((!s) || (!s->fd) || (s->status & PQIFILE_FAIL))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::generateFileData() Bad Status");
#endif
if (!s)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::generateFileData() Bad Status (!s)");
#endif
}
if (!s->fd)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::generateFileData() Bad Status (!s->fd)");
#endif
}
if (s->status & PQIFILE_FAIL)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::generateFileData() Bad Status (s->status): " << s->status;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,out.str());
#endif
}
/* return an error */
@ -985,6 +1097,7 @@ int ftfiler::generateFileData(ftFileStatus *s, std::string id, uint64_t offset,
tosend = s -> total_size - base_loc;
}
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::generateFileData() Sending " << tosend;
@ -992,6 +1105,7 @@ int ftfiler::generateFileData(ftFileStatus *s, std::string id, uint64_t offset,
out << "\tFrom File:" << s -> name;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
if (tosend > 0)
{
@ -1002,11 +1116,11 @@ int ftfiler::generateFileData(ftFileStatus *s, std::string id, uint64_t offset,
/* read the data */
if (1 != fread(data, tosend, 1, s->fd))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::generateFileData() Failed to get data!";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
free(data);
return 0;
@ -1038,12 +1152,15 @@ int ftfiler::generateFileData(ftFileStatus *s, std::string id, uint64_t offset,
ftFileRequest *ftfiler::generateFileRequest(ftFileStatus *s)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::generatePQFileRequest()");
#endif
ftFileRequest *fr = new ftFileRequest(s->id, s->hash,
s->size, s->req_loc, s->req_size);
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::generateFileRequest() for: " << s->name << std::endl;
@ -1051,6 +1168,7 @@ ftFileRequest *ftfiler::generateFileRequest(ftFileStatus *s)
out << fr->chunk << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
// timestamp request.
s->lastTS = time(NULL);
@ -1072,8 +1190,10 @@ const std::string PARTIAL_DIR = "partials";
std::string ftfiler::determineTmpFilePath(ftFileStatus *s)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::determineTmpFilePath()");
#endif
/* get the download path */
// savePath = ".";
@ -1090,8 +1210,10 @@ std::string ftfiler::determineTmpFilePath(ftFileStatus *s)
std::string ftfiler::determineDestFilePath(ftFileStatus *s)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::determineDestFilePath()");
#endif
/* should be three different options here:
* (1) relative to baseSavePath (default)
@ -1134,27 +1256,33 @@ std::string ftfiler::determineDestFilePath(ftFileStatus *s)
int ftfiler::initiateFileTransfer(ftFileStatus *s)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::initiateFileTransfer()");
#endif
std::string partialpath = saveBasePath + "/";
partialpath += PARTIAL_DIR;
if (!RsDirUtil::checkCreateDirectory(partialpath))
{
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Cannot create partial directory: " << partialpath;
pqioutput(PQL_ALERT, ftfilerzone, out.str());
}
#endif
std::string tmppath = mEmergencyIncomingDir;
if (!RsDirUtil::checkCreateDirectory(tmppath))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Cannot create EmergencyIncomingDir: ";
out << tmppath;
pqioutput(PQL_ALERT, ftfilerzone, out.str());
#endif
exit(1);
}
@ -1166,18 +1294,22 @@ int ftfiler::initiateFileTransfer(ftFileStatus *s)
if (!RsDirUtil::checkCreateDirectory(tmppath))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Cannot create EmergencyIncomingPartialsDir: ";
out << tmppath;
pqioutput(PQL_ALERT, ftfilerzone, out.str());
#endif
exit(1);
}
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Using Emergency Download Directory: " << saveBasePath;
pqioutput(PQL_ALERT, ftfilerzone, out.str());
}
#endif
pqiNotify *notify = getPqiNotify();
if (notify)
@ -1209,8 +1341,10 @@ int ftfiler::initiateFileTransfer(ftFileStatus *s)
}
else
{
#ifdef FT_DEBUG
std::cerr << "ftfiler::initiateFileTransfer() Notify not exist!";
std::cerr << std::endl;
#endif
exit(1);
}
}
@ -1218,17 +1352,20 @@ int ftfiler::initiateFileTransfer(ftFileStatus *s)
/* check if the file exists */
s->file_name = determineTmpFilePath(s);
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Filename: ";
out << s->file_name;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* attempt to open file */
FILE *fd = fopen(s->file_name.c_str(), "r+b");
if (!fd)
{
#ifdef FT_DEBUG
{
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Failed to open (r+b): ";
@ -1236,15 +1373,18 @@ int ftfiler::initiateFileTransfer(ftFileStatus *s)
out << " Will try to create file";
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
}
#endif
/* open in writing mode */
fd = fopen(s->file_name.c_str(), "w+b");
if (!fd)
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::initiateFileTransfer() Failed to open (w+b): ";
out << s->file_name << " Error:" << errno;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* failed to open the file */
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_OPEN);
@ -1258,8 +1398,10 @@ int ftfiler::initiateFileTransfer(ftFileStatus *s)
/* move to the end */
if (0 != fseek(fd, 0L, SEEK_END))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::initiateFileTransfer() Seek Failed");
#endif
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_SEEK);
return 0;
}
@ -1299,8 +1441,10 @@ int ftfiler::resetFileTransfer(ftFileStatus *state)
state->sources.clear();
if (!lookupRemoteHash(state->hash, state->sources))
{
#ifdef FT_DEBUG
pqioutput(PQL_WARNING, ftfilerzone,
"ftfiler::resetFileTransfer() Failed to locate Peers");
#endif
}
if (state->sources.size() == 0)
{
@ -1328,8 +1472,10 @@ int ftfiler::resetFileTransfer(ftFileStatus *state)
int ftfiler::addFileData(ftFileStatus *s, uint64_t idx, void *data, uint32_t size)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::addFileData()");
#endif
//std::cerr << "ftfiler::addFileData() PreStatus" << std::endl;
//printFtFileStatus(s, std::cerr);
@ -1337,27 +1483,33 @@ int ftfiler::addFileData(ftFileStatus *s, uint64_t idx, void *data, uint32_t siz
/* check the status */
if ((!s) || (!s->fd) || (s->status & PQIFILE_FAIL))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::addFileData() Bad Status");
#endif
return 0;
}
/* check its at the correct location */
if ((idx != s->recv_size) || (s->recv_size + size > s->total_size))
{
#ifdef FT_DEBUG
std::ostringstream out;
out << "ftfiler::addFileData() Bad Data Location" << std::endl;
out << " recv_size: " << s->recv_size << " offset: " << idx;
out << " total_size: " << s->total_size << " size: " << size;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
return 0;
}
/* go to the end of the file */
if (0 != fseek(s->fd, 0L, SEEK_END))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::addFileData() Bad fseek");
#endif
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_SEEK);
return 0;
}
@ -1365,8 +1517,10 @@ int ftfiler::addFileData(ftFileStatus *s, uint64_t idx, void *data, uint32_t siz
/* add the data */
if (1 != fwrite(data, size, 1, s->fd))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::addFileData() Bad fwrite");
#endif
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_WRITE);
return 0;
}
@ -1382,8 +1536,10 @@ int ftfiler::addFileData(ftFileStatus *s, uint64_t idx, void *data, uint32_t siz
if (s->recv_size == s->total_size)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::addFileData() File Complete!");
#endif
s->status = PQIFILE_COMPLETE;
/* HANDLE COMPLETION HERE */
@ -1453,8 +1609,10 @@ int ftfiler::completeFileTransfer(ftFileStatus *s)
ftFileStatus *ftfiler::createFileCache(std::string hash)
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::createFileCache()");
#endif
ftFileStatus *s = new ftFileStatus(hash, hash, 0, "", FT_MODE_UPLOAD);
@ -1473,8 +1631,10 @@ ftFileStatus *ftfiler::createFileCache(std::string hash)
if ((!found) || (s->file_name.length() < 1))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::createFileCache() Failed to Find File");
#endif
/* failed to open the file */
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_BAD_PATH);
delete s;
@ -1486,10 +1646,12 @@ ftFileStatus *ftfiler::createFileCache(std::string hash)
FILE *fd = fopen(s->file_name.c_str(), "rb");
if (!fd)
{
#ifdef FT_DEBUG
std::stringstream out;
out << "ftfiler::createFileCache() Failed to Open the File" << std::endl;
out << "\tFull Path:" << s->file_name.c_str() << std::endl;
pqioutput(PQL_DEBUG_BASIC, ftfilerzone, out.str());
#endif
/* failed to open the file */
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_OPEN);
delete s;
@ -1500,8 +1662,10 @@ ftFileStatus *ftfiler::createFileCache(std::string hash)
/* move to the end */
if (0 != fseek(fd, 0L, SEEK_END))
{
#ifdef FT_DEBUG
pqioutput(PQL_DEBUG_BASIC, ftfilerzone,
"ftfiler::createFileCache() Fseek Failed");
#endif
s->status = (PQIFILE_FAIL | PQIFILE_FAIL_NOT_OPEN);
delete s;

View File

@ -35,7 +35,9 @@ const uint32_t RANK_MAX_FWD_OFFSET = (60 * 60 * 24 * 2); /* 2 Days */
const uint32_t FRIEND_QBLOG_REPOST_PERIOD = 60; /* every minute for testing */
#define QBLOG_DEBUG 1
/****
* #define QBLOG_DEBUG 1
****/
p3Qblog::p3Qblog(p3ConnectMgr *connMgr,
uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
@ -530,8 +532,8 @@ void p3Qblog::loadDummy(void)
mConnMgr->getFriendList(peers); // retrieve peers list from core
if(peers.empty())
{
for(int i = 0; i < 50; i++)
std::cerr << "nothing in peer list!!!" << std::endl;
//for(int i = 0; i < 50; i++)
// std::cerr << "nothing in peer list!!!" << std::endl;
}

View File

@ -33,7 +33,9 @@
#include "pqi/pqibin.h"
#define DISTRIB_DEBUG 1
/*****
* #define DISTRIB_DEBUG 1
****/
RSA *extractPublicKey(RsTlvSecurityKey &key);
RSA *extractPrivateKey(RsTlvSecurityKey &key);

View File

@ -320,9 +320,10 @@ bool p3MsgService::loadConfiguration(std::string &loadHash)
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
std::cerr << "MSG_PENDING";
std::cerr << std::endl;
mitem->print(std::cerr);
//std::cerr << "MSG_PENDING";
//std::cerr << std::endl;
//mitem->print(std::cerr);
msgOutgoing[mitem->msgId] = mitem;
}
else
@ -760,8 +761,8 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, std::string to)
msg -> attachment.items.push_back(mfi);
}
std::cerr << "p3MsgService::initMIRsMsg()" << std::endl;
msg->print(std::cerr);
//std::cerr << "p3MsgService::initMIRsMsg()" << std::endl;
//msg->print(std::cerr);
return msg;
}

View File

@ -32,7 +32,9 @@
std::string generateRandomShowId();
#define PHOTO_DEBUG 1
/****
* #define PHOTO_DEBUG 1
****/
PhotoSet::PhotoSet()

View File

@ -642,7 +642,9 @@ bool UdpSorter::checkStunKeepAlive()
#endif
}
#ifdef DEBUG_UDP_SORTER
locked_printStunList();
#endif
}
@ -679,7 +681,9 @@ bool UdpSorter::locked_recvdStun(const struct sockaddr_in &remote, const stru
}
}
#ifdef DEBUG_UDP_SORTER
locked_printStunList();
#endif
if (!eaddrKnown)
{
@ -754,6 +758,7 @@ bool UdpSorter::locked_checkExternalAddress()
bool UdpSorter::locked_printStunList()
{
#ifdef DEBUG_UDP_SORTER
std::ostringstream out;
time_t now = time(NULL);
@ -774,6 +779,7 @@ bool UdpSorter::locked_printStunList()
}
std::cerr << out.str();
#endif
return true;
}

View File

@ -34,6 +34,10 @@
#include <iostream>
#include <algorithm>
/****
* #define RSDIR_DEBUG 1
****/
std::string RsDirUtil::getTopDir(std::string dir)
{
std::string top;
@ -123,7 +127,6 @@ std::string RsDirUtil::removeRootDirs(std::string path, std::string root)
{
/* too tired */
std::string notroot;
//std::cerr << "remoteRootDir( TODO! )";
unsigned int i = 0, j = 0;
@ -209,23 +212,31 @@ bool RsDirUtil::checkCreateDirectory(std::string dir)
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
{
#ifdef RSDIR_DEBUG
std::cerr << "check_create_directory() Fatal Error --";
std::cerr <<std::endl<< "\tcannot create:" <<dir<<std::endl;
#endif
return 0;
}
#ifdef RSDIR_DEBUG
std::cerr << "check_create_directory()";
std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl;
#endif
}
else if (!S_ISDIR(buf.st_mode))
{
// Some other type - error.
#ifdef RSDIR_DEBUG
std::cerr<<"check_create_directory() Fatal Error --";
std::cerr<<std::endl<<"\t"<<dir<<" is nor Directory"<<std::endl;
#endif
return 0;
}
#ifdef RSDIR_DEBUG
std::cerr << "check_create_directory()";
std::cerr <<std::endl<< "\tDir Exists:" <<dir<<std::endl;
#endif
return 1;
}