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

View File

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

View File

@ -33,7 +33,9 @@
#include <openssl/sha.h> #include <openssl/sha.h>
#define FI_DEBUG 1 /****
* #define FI_DEBUG 1
****/
DirEntry::~DirEntry() 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 MAX_DHT_ATTEMPTS 10 /* attempts per search/publish */
#define MIN_DHT_SERVERS 5 #define MIN_DHT_SERVERS 5
#define OPENDHT_DEBUG 1 /****
* #define OPENDHT_DEBUG 1
****/
bool OpenDHTClient::checkServerFile(std::string filename) 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])) if (isspace(value[i]))
{ {
value.erase(i,1); value.erase(i,1);
#ifdef OPENDHT_DEBUG
std::cerr << "Cleanup Result:" << value << ":END:" << std::endl; std::cerr << "Cleanup Result:" << value << ":END:" << std::endl;
#endif
} }
else else
{ {
@ -498,10 +502,12 @@ bool OpenDHTClient::searchKey(std::string key, std::list<std::string> &values)
if (value.length() > 0) if (value.length() > 0)
{ {
std::cerr << "openDHT_searchKey() Value:" << value << ":END:" << std::endl;
std::string result = convertFromBase64(value); std::string result = convertFromBase64(value);
std::cerr << "openDHT_searchKey() Result: 0x" << RsUtil::BinToHex(result) << ":END:" << std::endl;
values.push_back(result); 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 */ /* the answer should be between loc and end */
@ -541,19 +547,23 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
else else
{ {
/* no address */ /* no address */
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: No Address"; std::cerr << " ERROR: No Address";
std::cerr << std::endl; std::cerr << std::endl;
#endif
setServerFailed(host); setServerFailed(host);
return false; return false;
} }
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Connecting to:" << host << ":" << port; std::cerr << " Connecting to:" << host << ":" << port;
std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")"; std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* create request */ /* create request */
std::string putheader = createHttpHeader(host, port, openDHT_Agent, msg.length()); 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) if (err)
{ {
unix_close(sockfd); unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Connect"; std::cerr << " ERROR: Failed to Connect";
std::cerr << std::endl; std::cerr << std::endl;
#endif
setServerFailed(host); setServerFailed(host);
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP message *******************" << std::endl; std::cerr << "HTTP message *******************" << std::endl;
std::cerr << putheader; std::cerr << putheader;
std::cerr << msg; std::cerr << msg;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "HTTP message *******************" << std::endl; std::cerr << "HTTP message *******************" << std::endl;
#endif
/* send data */ /* send data */
int sendsize = strlen(putheader.c_str()); int sendsize = strlen(putheader.c_str());
@ -587,35 +601,43 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
if (sendsize != size) if (sendsize != size)
{ {
unix_close(sockfd); unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Send(1)"; std::cerr << " ERROR: Failed to Send(1)";
std::cerr << std::endl; std::cerr << std::endl;
#endif
setServerFailed(host); setServerFailed(host);
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Send(1):" << size; std::cerr << " Send(1):" << size;
std::cerr << std::endl; std::cerr << std::endl;
#endif
sendsize = strlen(msg.c_str()); sendsize = strlen(msg.c_str());
size = send(sockfd, msg.c_str(), sendsize, 0); size = send(sockfd, msg.c_str(), sendsize, 0);
if (sendsize != size) if (sendsize != size)
{ {
unix_close(sockfd); unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " ERROR: Failed to Send(2)"; std::cerr << " ERROR: Failed to Send(2)";
std::cerr << std::endl; std::cerr << std::endl;
#endif
setServerFailed(host); setServerFailed(host);
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Send(2):" << size; std::cerr << " Send(2):" << size;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* now wait for the response */ /* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -631,19 +653,24 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
uint32_t idx = 0; uint32_t idx = 0;
while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0))) while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0)))
{ {
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Recvd Chunk:" << size; std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl; std::cerr << std::endl;
#endif
idx += size; idx += size;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_sendMessage()"; std::cerr << "OpenDHTClient::openDHT_sendMessage()";
std::cerr << " Recvd Msg:" << idx; std::cerr << " Recvd Msg:" << idx;
#endif
response = std::string(inbuf, idx); response = std::string(inbuf, idx);
free(inbuf); free(inbuf);
/* print it out */ /* print it out */
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP What We Sent ***************" << std::endl; std::cerr << "HTTP What We Sent ***************" << std::endl;
std::cerr << putheader; std::cerr << putheader;
std::cerr << msg; std::cerr << msg;
@ -652,6 +679,7 @@ bool OpenDHTClient::openDHT_sendMessage(std::string msg, std::string &response)
std::cerr << response; std::cerr << response;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl; std::cerr << "HTTP response *******************" << std::endl;
#endif
unix_close(sockfd); unix_close(sockfd);
@ -672,17 +700,21 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (!LookupDNSAddr(host, addr)) if (!LookupDNSAddr(host, addr))
{ {
/* no address */ /* no address */
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: No Address"; std::cerr << " ERROR: No Address";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Connecting to:" << host << ":" << port; std::cerr << " Connecting to:" << host << ":" << port;
std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")"; std::cerr << " (" << inet_ntoa(addr.sin_addr) << ":" << ntohs(addr.sin_port) << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* create request */ /* create request */
std::string putheader = createHttpHeaderGET(host, port, "servers.txt", openDHT_Agent, 0); std::string putheader = createHttpHeaderGET(host, port, "servers.txt", openDHT_Agent, 0);
@ -695,17 +727,21 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (err) if (err)
{ {
unix_close(sockfd); unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: Failed to Connect"; std::cerr << " ERROR: Failed to Connect";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP message *******************" << std::endl; std::cerr << "HTTP message *******************" << std::endl;
std::cerr << putheader; std::cerr << putheader;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "HTTP message *******************" << std::endl; std::cerr << "HTTP message *******************" << std::endl;
#endif
/* send data */ /* send data */
int sendsize = strlen(putheader.c_str()); int sendsize = strlen(putheader.c_str());
@ -713,15 +749,19 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
if (sendsize != size) if (sendsize != size)
{ {
unix_close(sockfd); unix_close(sockfd);
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " ERROR: Failed to Send(1)"; std::cerr << " ERROR: Failed to Send(1)";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return false; return false;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Send(1):" << size; std::cerr << " Send(1):" << size;
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* now wait for the response */ /* now wait for the response */
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ /********************************** WINDOWS/UNIX SPECIFIC PART ******************/
@ -737,23 +777,29 @@ bool OpenDHTClient::openDHT_getDHTList(std::string &response)
uint32_t idx = 0; uint32_t idx = 0;
while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0))) while(0 < (size = recv(sockfd, &(inbuf[idx]), recvsize - idx, 0)))
{ {
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Recvd Chunk:" << size; std::cerr << " Recvd Chunk:" << size;
std::cerr << std::endl; std::cerr << std::endl;
#endif
idx += size; idx += size;
} }
#ifdef OPENDHT_DEBUG
std::cerr << "OpenDHTClient::openDHT_getDHTList()"; std::cerr << "OpenDHTClient::openDHT_getDHTList()";
std::cerr << " Recvd Msg:" << idx; std::cerr << " Recvd Msg:" << idx;
#endif
response = std::string(inbuf, idx); response = std::string(inbuf, idx);
free(inbuf); free(inbuf);
/* print it out */ /* print it out */
#ifdef OPENDHT_DEBUG
std::cerr << "HTTP response *******************" << std::endl; std::cerr << "HTTP response *******************" << std::endl;
std::cerr << response; std::cerr << response;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "HTTP response *******************" << std::endl; std::cerr << "HTTP response *******************" << std::endl;
#endif
unix_close(sockfd); 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"); FILE *tmpfp = fopen(cert_file, "r");
if (tmpfp == NULL) if (tmpfp == NULL)
{ {
#ifdef XPGP_DEBUG
std::cerr << "sslroot::LoadCheckAndGetXPGPName()"; std::cerr << "sslroot::LoadCheckAndGetXPGPName()";
std::cerr << " Failed to open Certificate File:" << cert_file; std::cerr << " Failed to open Certificate File:" << cert_file;
std::cerr << std::endl; std::cerr << std::endl;
#endif
return 0; return 0;
} }
@ -1604,7 +1606,9 @@ std::list<std::string> getXPGPsigners(XPGP *cert)
XPGP_SIGNATURE *sig = sk_XPGP_SIGNATURE_value(cert->signs,i); XPGP_SIGNATURE *sig = sk_XPGP_SIGNATURE_value(cert->signs,i);
std::string str = getX509CNString(sig->issuer); std::string str = getX509CNString(sig->issuer);
signers.push_back(str); signers.push_back(str);
#ifdef XPGP_DEBUG
std::cerr << "XPGPsigners(" << i << ")" << str << std::endl; std::cerr << "XPGPsigners(" << i << ")" << str << std::endl;
#endif
} }
return signers; return signers;
} }
@ -1767,7 +1771,6 @@ bool AuthXPGP::saveCertificates()
conftxt += "\n"; conftxt += "\n";
conftxt += hash; conftxt += hash;
conftxt += "\n"; conftxt += "\n";
std::cerr << std::endl;
} }
} }
} }
@ -1786,34 +1789,48 @@ bool AuthXPGP::saveCertificates()
if (0 == EVP_SignInit_ex(mdctx, EVP_sha1(), NULL)) if (0 == EVP_SignInit_ex(mdctx, EVP_sha1(), NULL))
{ {
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignInit Failure!" << std::endl; std::cerr << "EVP_SignInit Failure!" << std::endl;
#endif
} }
if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length())) if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length()))
{ {
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignUpdate Failure!" << std::endl; std::cerr << "EVP_SignUpdate Failure!" << std::endl;
#endif
} }
if (0 == EVP_SignFinal(mdctx, signature, &signlen, pkey)) if (0 == EVP_SignFinal(mdctx, signature, &signlen, pkey))
{ {
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignFinal Failure!" << std::endl; std::cerr << "EVP_SignFinal Failure!" << std::endl;
#endif
} }
#ifdef XPGP_DEBUG
std::cerr << "Conf Signature is(" << signlen << "): "; std::cerr << "Conf Signature is(" << signlen << "): ";
#endif
for(i = 0; i < signlen; i++) for(i = 0; i < signlen; i++)
{ {
#ifdef XPGP_DEBUG
fprintf(stderr, "%02x", signature[i]); fprintf(stderr, "%02x", signature[i]);
#endif
conftxt += signature[i]; conftxt += signature[i];
} }
#ifdef XPGP_DEBUG
std::cerr << std::endl; std::cerr << std::endl;
#endif
FILE *cfd = fopen(configfile.c_str(), "wb"); FILE *cfd = fopen(configfile.c_str(), "wb");
int wrec; int wrec;
if (1 != (wrec = fwrite(conftxt.c_str(), conftxt.length(), 1, cfd))) if (1 != (wrec = fwrite(conftxt.c_str(), conftxt.length(), 1, cfd)))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Error writing: " << configfile << std::endl; std::cerr << "Error writing: " << configfile << std::endl;
std::cerr << "Wrote: " << wrec << "/" << 1 << " Records" << std::endl; std::cerr << "Wrote: " << wrec << "/" << 1 << " Records" << std::endl;
#endif
} }
EVP_MD_CTX_destroy(mdctx); 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"); FILE *cfd = fopen(configfile.c_str(), "rb");
if (cfd == NULL) if (cfd == NULL)
{ {
#ifdef XPGP_DEBUG
std::cerr << "Unable to Load Configuration File!" << std::endl; std::cerr << "Unable to Load Configuration File!" << std::endl;
std::cerr << "File: " << configfile << std::endl; std::cerr << "File: " << configfile << std::endl;
#endif
return false; return false;
} }
@ -1925,11 +1944,13 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
{ {
if (EOF == (c = fgetc(cfd))) if (EOF == (c = fgetc(cfd)))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Signature of: "; std::cerr << "Error Reading Signature of: ";
std::cerr << fname; std::cerr << fname;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "ABorting Load!"; std::cerr << "ABorting Load!";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return -1; return -1;
} }
unsigned char uc = (unsigned char) c; 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))) if ('\n' != (c = fgetc(cfd)))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Warning Mising seperator" << std::endl; std::cerr << "Warning Mising seperator" << std::endl;
#endif
} }
#ifdef XPGP_DEBUG
std::cerr << "Read fname:" << fname << std::endl; std::cerr << "Read fname:" << fname << std::endl;
std::cerr << "Signature:" << std::endl; std::cerr << "Signature:" << std::endl;
for(i = 0; i < signlen; i++) 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;
std::cerr << std::endl; std::cerr << std::endl;
#endif
// push back..... // push back.....
fnames.push_back(fname); fnames.push_back(fname);
@ -1982,11 +2007,13 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
{ {
if (EOF == (c = fgetc(cfd))) if (EOF == (c = fgetc(cfd)))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Value of: "; std::cerr << "Error Reading Value of: ";
std::cerr << opt; std::cerr << opt;
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "ABorting Load!"; std::cerr << "ABorting Load!";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return -1; return -1;
} }
// remove zeros on strings... // remove zeros on strings...
@ -1998,11 +2025,15 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
} }
if ('\n' != (c = fgetc(cfd))) if ('\n' != (c = fgetc(cfd)))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Warning Mising seperator" << std::endl; std::cerr << "Warning Mising seperator" << std::endl;
#endif
} }
#ifdef XPGP_DEBUG
std::cerr << "Read OPT:" << opt; std::cerr << "Read OPT:" << opt;
std::cerr << " Val:" << val << std::endl; std::cerr << " Val:" << val << std::endl;
#endif
// push back..... // push back.....
tmpsettings[opt] = val; tmpsettings[opt] = val;
@ -2029,8 +2060,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
c = fgetc(cfd); c = fgetc(cfd);
if (c == EOF) if (c == EOF)
{ {
#ifdef XPGP_DEBUG
std::cerr << "Error Reading Conf Signature:"; std::cerr << "Error Reading Conf Signature:";
std::cerr << std::endl; std::cerr << std::endl;
#endif
return 1; return 1;
} }
unsigned char uc = (unsigned char) c; 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; std::cerr << "Configuration File Signature: " << std::endl;
for(i = 0; i < signlen; i++) for(i = 0; i < signlen; i++)
{ {
fprintf(stderr, "%02x", (unsigned char) name[i]); fprintf(stderr, "%02x", (unsigned char) name[i]);
} }
std::cerr << std::endl; std::cerr << std::endl;
#endif
// when we get here - should have the final signature in the buffer. // 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())) if (0 == EVP_SignInit(mdctx, EVP_sha1()))
{ {
#ifdef XPGP_DEBUG
#endif
std::cerr << "EVP_SignInit Failure!" << std::endl; std::cerr << "EVP_SignInit Failure!" << std::endl;
} }
if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length())) if (0 == EVP_SignUpdate(mdctx, conftxt.c_str(), conftxt.length()))
{ {
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignUpdate Failure!" << std::endl; std::cerr << "EVP_SignUpdate Failure!" << std::endl;
#endif
} }
if (0 == EVP_SignFinal(mdctx, conf_signature, &signlen, pkey)) if (0 == EVP_SignFinal(mdctx, conf_signature, &signlen, pkey))
{ {
#ifdef XPGP_DEBUG
std::cerr << "EVP_SignFinal Failure!" << std::endl; std::cerr << "EVP_SignFinal Failure!" << std::endl;
#endif
} }
EVP_MD_CTX_destroy(mdctx); EVP_MD_CTX_destroy(mdctx);
fclose(cfd); fclose(cfd);
#ifdef XPGP_DEBUG
std::cerr << "Recalced File Signature: " << std::endl; std::cerr << "Recalced File Signature: " << std::endl;
for(i = 0; i < signlen; i++) for(i = 0; i < signlen; i++)
{ {
fprintf(stderr, "%02x", conf_signature[i]); fprintf(stderr, "%02x", conf_signature[i]);
} }
std::cerr << std::endl; std::cerr << std::endl;
#endif
bool same = true; bool same = true;
for(i = 0; i < signlen; i++) for(i = 0; i < signlen; i++)
@ -2091,8 +2134,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
if (same == false) if (same == false)
{ {
#ifdef XPGP_DEBUG
std::cerr << "ERROR VALIDATING CONFIGURATION!" << std::endl; std::cerr << "ERROR VALIDATING CONFIGURATION!" << std::endl;
std::cerr << "PLEASE FIX!" << std::endl; std::cerr << "PLEASE FIX!" << std::endl;
#endif
return false; return false;
} }
@ -2107,8 +2152,10 @@ bool AuthXPGP::loadCertificates(bool &oldFormat, std::map<std::string, std::s
std::string id; std::string id;
if (ProcessXPGP(xpgp, id)) if (ProcessXPGP(xpgp, id))
{ {
#ifdef XPGP_DEBUG
std::cerr << "Loaded Certificate: " << id; std::cerr << "Loaded Certificate: " << id;
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -257,16 +257,16 @@ int pqissl::reset()
bool pqissl::connect_parameter(uint32_t type, uint32_t value) 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) 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; mConnectDelay = value;
return true; return true;
} }
else if (type == NET_PARAM_CONNECT_TIMEOUT) 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; mConnectTimeout = value;
return true; return true;
} }
@ -604,7 +604,7 @@ int pqissl::Initiate_Connection()
} }
mTimeoutTS = time(NULL) + mConnectTimeout; 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)))) 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()); pqioutput(PQL_WARNING, pqisslzone, out.str());
// extra output for the moment. // extra output for the moment.
std::cerr << out.str(); //std::cerr << out.str();
return -1; return -1;
} }
@ -701,10 +701,10 @@ int pqissl::Basic_Connection_Complete()
"pqissl::Basic_Connection_Complete() Connection Timed Out!"); "pqissl::Basic_Connection_Complete() Connection Timed Out!");
/* as sockfd is valid, this should close it all up */ /* as sockfd is valid, this should close it all up */
std::cerr << "pqissl::Basic_Connection_Complete() Connection Timed Out!"; //std::cerr << "pqissl::Basic_Connection_Complete() Connection Timed Out!";
std::cerr << std::endl; //std::cerr << std::endl;
std::cerr << "pqissl::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout; //std::cerr << "pqissl::Basic_Connection_Complete() Timeout Period: " << mConnectTimeout;
std::cerr << std::endl; //std::cerr << std::endl;
reset(); reset();
return -1; return -1;
} }

View File

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

View File

@ -147,34 +147,23 @@ bool RsRankSerialiser::serialiseLink(RsRankLinkMsg *item, void *data, uint32
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); 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 */ /* skip the header */
offset += 8; offset += 8;
/* add mandatory parts first */ /* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid); 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); 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); 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); 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); 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))); ok &= setRawUInt32(data, tlvsize, &offset, *((uint32_t *) &(item->score)));
std::cerr << "RsRankLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype); 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); ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
std::cerr << "RsRankLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
if (offset != tlvsize) 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 */ if (size < tlvend) /* check size */
return false; /* not enough space */ return false; /* not enough space */
std::cout << "yeah!!!" << std::endl;
if (tlvtype != TLV_TYPE_PEERSET) /* check type */ if (tlvtype != TLV_TYPE_PEERSET) /* check type */
return false; return false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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