mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-09 11:28:42 -05:00
bitdht improvements
* Added bdHistory, to monitoring all the p2p dht messages (disabled normally) * cleaned up all compile warnings on OSX. * added Found timestamp to peer info. * disable save, until store is close to full. * ...?other stuff? git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3559 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
327af4ca61
commit
c9229fb6e8
211
libbitdht/src/bitdht/bdhistory.cc
Normal file
211
libbitdht/src/bitdht/bdhistory.cc
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "bitdht/bdhistory.h"
|
||||||
|
#include "bitdht/bdstddht.h"
|
||||||
|
|
||||||
|
#define MIN_RESEND_PERIOD 60
|
||||||
|
|
||||||
|
void bdMsgHistoryList::addMsg(time_t ts, uint32_t msgType, bool incoming)
|
||||||
|
|
||||||
|
{
|
||||||
|
uint32_t msg = msgType | (incoming ? MSG_DIRECTION_INCOMING : MSG_DIRECTION_OUTGOING);
|
||||||
|
msgHistory.insert(std::make_pair(ts, msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
int bdMsgHistoryList::msgCount(time_t start_ts, time_t end_ts)
|
||||||
|
{
|
||||||
|
std::multimap<time_t, uint32_t>::iterator sit, eit, it;
|
||||||
|
sit = msgHistory.lower_bound(start_ts);
|
||||||
|
eit = msgHistory.upper_bound(end_ts);
|
||||||
|
int count = 0;
|
||||||
|
for (it = sit; it != eit; it++, count++) ; // empty loop.
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdMsgHistoryList::msgClear()
|
||||||
|
{
|
||||||
|
msgHistory.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void bdMsgHistoryList::printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts)
|
||||||
|
{
|
||||||
|
//out << "AGE: MSGS => incoming, <= outgoing" << std::endl;
|
||||||
|
std::multimap<time_t, uint32_t>::iterator sit, eit, it;
|
||||||
|
sit = msgHistory.lower_bound(start_ts);
|
||||||
|
eit = msgHistory.upper_bound(end_ts);
|
||||||
|
time_t curr_ts = 0;
|
||||||
|
time_t old_ts = 0;
|
||||||
|
bool time_changed = false;
|
||||||
|
bool first_line = true;
|
||||||
|
|
||||||
|
for(it = sit; it != eit; it++)
|
||||||
|
{
|
||||||
|
time_changed = false;
|
||||||
|
if (curr_ts != it->first)
|
||||||
|
{
|
||||||
|
old_ts = curr_ts;
|
||||||
|
curr_ts = it->first;
|
||||||
|
time_changed = true;
|
||||||
|
}
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/* print one line per ts */
|
||||||
|
if (time_changed)
|
||||||
|
{
|
||||||
|
if (!first_line)
|
||||||
|
{
|
||||||
|
/* finish existing line */
|
||||||
|
out << " " << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
first_line = false;
|
||||||
|
}
|
||||||
|
out << "\tTS: " << time(NULL) - curr_ts << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MSG_DIRECTION_INCOMING & it->second)
|
||||||
|
{
|
||||||
|
out << " =>" << it->second - MSG_DIRECTION_INCOMING;
|
||||||
|
out << " ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out << " ";
|
||||||
|
out << it->second - MSG_DIRECTION_OUTGOING << "=> ";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} // end of switch.
|
||||||
|
}
|
||||||
|
|
||||||
|
/* finish up last line */
|
||||||
|
if (!first_line)
|
||||||
|
{
|
||||||
|
out << " " << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool bdMsgHistoryList::canSend()
|
||||||
|
{
|
||||||
|
std::cerr << "bdMsgHistoryList::canSend()";
|
||||||
|
|
||||||
|
std::multimap<time_t, uint32_t>::reverse_iterator rit;
|
||||||
|
|
||||||
|
rit = msgHistory.rbegin();
|
||||||
|
if (rit != msgHistory.rend())
|
||||||
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (now - rit->first > MIN_RESEND_PERIOD)
|
||||||
|
{
|
||||||
|
std::cerr << " OVER RESEND_PERIOD... true";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msgHistory.size() % 2 == 0)
|
||||||
|
{
|
||||||
|
std::cerr << " SIZE: " << msgHistory.size() << " % 2 = 0 ... true";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << " false";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bdMsgHistoryList::validPeer()
|
||||||
|
{
|
||||||
|
std::cerr << "bdMsgHistoryList::validPeer()";
|
||||||
|
|
||||||
|
std::multimap<time_t, uint32_t>::iterator it;
|
||||||
|
|
||||||
|
for(it = msgHistory.begin(); it != msgHistory.end(); it++)
|
||||||
|
{
|
||||||
|
if (MSG_DIRECTION_INCOMING & it->second)
|
||||||
|
{
|
||||||
|
std::cerr << " Incoming Msg... so validPeer";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << " false";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdHistory::addMsg(const bdId *id, bdToken * /*transId*/, uint32_t msgType, bool incoming)
|
||||||
|
{
|
||||||
|
std::map<bdId, bdMsgHistoryList>::iterator it;
|
||||||
|
bdMsgHistoryList &histRef = mHistory[*id]; /* will instaniate empty */
|
||||||
|
histRef.addMsg(time(NULL), msgType, incoming);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdHistory::printMsgs()
|
||||||
|
{
|
||||||
|
/* print and clear msgs */
|
||||||
|
std::ostream &out = std::cerr;
|
||||||
|
|
||||||
|
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||||
|
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->second.msgCount(0, time(NULL))) // all msg count.
|
||||||
|
{
|
||||||
|
/* print header */
|
||||||
|
out << "Msgs for ";
|
||||||
|
bdStdPrintId(out, &(it->first));
|
||||||
|
out << std::endl;
|
||||||
|
|
||||||
|
it->second.printHistory(out, 0, 0, time(NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdHistory::clearHistory()
|
||||||
|
{
|
||||||
|
mHistory.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bdHistory::canSend(const bdId *id)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||||
|
it = mHistory.find(*id);
|
||||||
|
if (it != mHistory.end())
|
||||||
|
{
|
||||||
|
return (it->second.canSend());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if not found - then can send */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool bdHistory::validPeer(const bdId *id)
|
||||||
|
{
|
||||||
|
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||||
|
it = mHistory.find(*id);
|
||||||
|
if (it != mHistory.end())
|
||||||
|
{
|
||||||
|
return (it->second.validPeer());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if not found - then can send */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
50
libbitdht/src/bitdht/bdhistory.h
Normal file
50
libbitdht/src/bitdht/bdhistory.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef BITDHT_HISTORY_H
|
||||||
|
#define BITDHT_HISTORY_H
|
||||||
|
|
||||||
|
#include "bitdht/bdpeer.h"
|
||||||
|
#include "bitdht/bdobj.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#define MSG_TYPE_DIRECTION_MASK 0x000f0000
|
||||||
|
|
||||||
|
#define MSG_DIRECTION_INCOMING 0x00010000
|
||||||
|
#define MSG_DIRECTION_OUTGOING 0x00020000
|
||||||
|
|
||||||
|
/**** DEBUGGING HISTORY ****/
|
||||||
|
|
||||||
|
class bdMsgHistoryList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
void addMsg(time_t ts, uint32_t msgType, bool incoming);
|
||||||
|
int msgCount(time_t start_ts, time_t end_ts);
|
||||||
|
void msgClear();
|
||||||
|
void printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts);
|
||||||
|
|
||||||
|
bool canSend();
|
||||||
|
bool validPeer();
|
||||||
|
|
||||||
|
std::multimap<time_t, uint32_t> msgHistory;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class bdHistory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming);
|
||||||
|
void printMsgs();
|
||||||
|
void clearHistory();
|
||||||
|
|
||||||
|
bool canSend(const bdId *id);
|
||||||
|
bool validPeer(const bdId *id);
|
||||||
|
|
||||||
|
/* recent history */
|
||||||
|
//std::list<bdId> lastMsgs;
|
||||||
|
std::map<bdId, bdMsgHistoryList> mHistory;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -151,7 +151,7 @@ class BitDhtCallback
|
|||||||
// ~BitDhtCallback();
|
// ~BitDhtCallback();
|
||||||
|
|
||||||
// dummy cos not needed for standard dht behaviour;
|
// dummy cos not needed for standard dht behaviour;
|
||||||
virtual int dhtNodeCallback(const bdId *id, uint32_t peerflags) { return 0; }
|
virtual int dhtNodeCallback(const bdId * /*id*/, uint32_t /*peerflags*/) { return 0; }
|
||||||
|
|
||||||
// must be implemented.
|
// must be implemented.
|
||||||
virtual int dhtPeerCallback(const bdNodeId *id, uint32_t status) = 0;
|
virtual int dhtPeerCallback(const bdNodeId *id, uint32_t status) = 0;
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
* #define DEBUG_MGR_PKT 1
|
* #define DEBUG_MGR_PKT 1
|
||||||
***/
|
***/
|
||||||
|
|
||||||
//#define DEBUG_MGR 1
|
|
||||||
|
|
||||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||||
:bdNode(id, dhtVersion, bootfile, fns)
|
:bdNode(id, dhtVersion, bootfile, fns)
|
||||||
@ -122,7 +121,7 @@ void bdNodeManager::startQueries()
|
|||||||
std::cerr << "bdNodeManager::startQueries() Found READY Query.";
|
std::cerr << "bdNodeManager::startQueries() Found READY Query.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
it->second.mStatus == BITDHT_QUERY_QUERYING;
|
it->second.mStatus = BITDHT_QUERY_QUERYING;
|
||||||
|
|
||||||
uint32_t qflags = it->second.mQFlags | BITDHT_QFLAGS_DISGUISE;
|
uint32_t qflags = it->second.mQFlags | BITDHT_QFLAGS_DISGUISE;
|
||||||
addQuery(&(it->first), qflags);
|
addQuery(&(it->first), qflags);
|
||||||
@ -545,7 +544,7 @@ int bdNodeManager::SearchOutOfDate()
|
|||||||
/* Request DHT Peer Lookup */
|
/* Request DHT Peer Lookup */
|
||||||
/* Request Keyword Lookup */
|
/* Request Keyword Lookup */
|
||||||
|
|
||||||
void bdNodeManager::findDhtValue(bdNodeId *id, std::string key, uint32_t mode)
|
void bdNodeManager::findDhtValue(bdNodeId * /*id*/, std::string /*key*/, uint32_t /*mode*/)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_MGR
|
#ifdef DEBUG_MGR
|
||||||
std::cerr << "bdNodeManager::findDhtValue() TODO";
|
std::cerr << "bdNodeManager::findDhtValue() TODO";
|
||||||
@ -555,24 +554,29 @@ void bdNodeManager::findDhtValue(bdNodeId *id, std::string key, uint32_t mode)
|
|||||||
|
|
||||||
|
|
||||||
/***** Get Results Details *****/
|
/***** Get Results Details *****/
|
||||||
int bdNodeManager::getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from)
|
int bdNodeManager::getDhtPeerAddress(bdNodeId *id, struct sockaddr_in & /*from*/)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_MGR
|
#ifdef DEBUG_MGR
|
||||||
std::cerr << "bdNodeManager::getDhtPeerAddress() Id: ";
|
std::cerr << "bdNodeManager::getDhtPeerAddress() Id: ";
|
||||||
mFns->bdPrintNodeId(std::cerr, id);
|
mFns->bdPrintNodeId(std::cerr, id);
|
||||||
std::cerr << " ... ? TODO" << std::endl;
|
std::cerr << " ... ? TODO" << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdNodeManager::getDhtValue(bdNodeId *id, std::string key, std::string &value)
|
int bdNodeManager::getDhtValue(bdNodeId *id, std::string key, std::string & /*value*/)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_MGR
|
#ifdef DEBUG_MGR
|
||||||
std::cerr << "bdNodeManager::getDhtValue() Id: ";
|
std::cerr << "bdNodeManager::getDhtValue() Id: ";
|
||||||
mFns->bdPrintNodeId(std::cerr, id);
|
mFns->bdPrintNodeId(std::cerr, id);
|
||||||
std::cerr << " key: " << key;
|
std::cerr << " key: " << key;
|
||||||
std::cerr << " ... ? TODO" << std::endl;
|
std::cerr << " ... ? TODO" << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) key;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -661,7 +665,7 @@ void bdNodeManager::doPeerCallback(const bdNodeId *id, uint32_t status)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdNodeManager::doValueCallback(const bdNodeId *id, std::string key, uint32_t status)
|
void bdNodeManager::doValueCallback(const bdNodeId *id, std::string /*key*/, uint32_t status)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_MGR
|
#ifdef DEBUG_MGR
|
||||||
std::cerr << "bdNodeManager::doValueCallback()";
|
std::cerr << "bdNodeManager::doValueCallback()";
|
||||||
@ -677,7 +681,7 @@ void bdNodeManager::doValueCallback(const bdNodeId *id, std::string key, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/******************* Internals *************************/
|
/******************* Internals *************************/
|
||||||
int bdNodeManager::isBitDhtPacket(char *data, int size, struct sockaddr_in &from)
|
int bdNodeManager::isBitDhtPacket(char *data, int size, struct sockaddr_in & from)
|
||||||
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_MGR_PKT
|
#ifdef DEBUG_MGR_PKT
|
||||||
@ -710,6 +714,8 @@ int bdNodeManager::isBitDhtPacket(char *data, int size, struct sockaddr_in &
|
|||||||
}
|
}
|
||||||
std::cerr << "bdNodeManager::isBitDhtPacket() *******************************";
|
std::cerr << "bdNodeManager::isBitDhtPacket() *******************************";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) from;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* try to parse it! */
|
/* try to parse it! */
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#define BITDHT_MAX_REMOTE_QUERY_AGE 10
|
#define BITDHT_MAX_REMOTE_QUERY_AGE 10
|
||||||
|
|
||||||
/****
|
/****
|
||||||
|
* #define USE_HISTORY 1
|
||||||
|
*
|
||||||
* #define DEBUG_NODE_MULTIPEER 1
|
* #define DEBUG_NODE_MULTIPEER 1
|
||||||
* #define DEBUG_NODE_PARSE 1
|
* #define DEBUG_NODE_PARSE 1
|
||||||
|
|
||||||
@ -55,6 +57,7 @@
|
|||||||
|
|
||||||
//#define DEBUG_NODE_MSGS 1
|
//#define DEBUG_NODE_MSGS 1
|
||||||
|
|
||||||
|
|
||||||
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||||
:mOwnId(*ownId), mNodeSpace(ownId, fns), mStore(bootfile, fns), mDhtVersion(dhtVersion), mFns(fns)
|
:mOwnId(*ownId), mNodeSpace(ownId, fns), mStore(bootfile, fns), mDhtVersion(dhtVersion), mFns(fns)
|
||||||
{
|
{
|
||||||
@ -130,6 +133,10 @@ void bdNode::printState()
|
|||||||
|
|
||||||
printQueries();
|
printQueries();
|
||||||
|
|
||||||
|
#ifdef USE_HISTORY
|
||||||
|
mHistory.printMsgs();
|
||||||
|
#endif
|
||||||
|
|
||||||
printStats(std::cerr);
|
printStats(std::cerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,32 +196,60 @@ void bdNode::iteration()
|
|||||||
|
|
||||||
while((mPotentialPeers.size() > 0) && (i < ilim))
|
while((mPotentialPeers.size() > 0) && (i < ilim))
|
||||||
{
|
{
|
||||||
|
/* check history ... is we have pinged them already...
|
||||||
|
* then simulate / pretend we have received a pong,
|
||||||
|
* and don't bother sending another ping.
|
||||||
|
*/
|
||||||
|
|
||||||
bdId pid = mPotentialPeers.front();
|
bdId pid = mPotentialPeers.front();
|
||||||
mPotentialPeers.pop_front();
|
mPotentialPeers.pop_front();
|
||||||
|
|
||||||
bdToken transId;
|
/* don't send too many queries ... check history first */
|
||||||
genNewTransId(&transId);
|
#ifdef USE_HISTORY
|
||||||
registerOutgoingMsg(&pid, &transId, BITDHT_MSG_TYPE_PING);
|
if (mHistory.validPeer(&pid))
|
||||||
msgout_ping(&pid, &transId);
|
{
|
||||||
i++;
|
/* just add as peer */
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_MSGS
|
#ifdef DEBUG_NODE_MSGS
|
||||||
std::cerr << "bdNode::iteration() Pinging Potential Peer : ";
|
std::cerr << "bdNode::iteration() Pinging Known Potential Peer : ";
|
||||||
mFns->bdPrintId(std::cerr, &pid);
|
mFns->bdPrintId(std::cerr, &pid);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
mCounterPings++;
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**** TEMP ****/
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
bdToken transId;
|
||||||
|
genNewTransId(&transId);
|
||||||
|
//registerOutgoingMsg(&pid, &transId, BITDHT_MSG_TYPE_PING);
|
||||||
|
msgout_ping(&pid, &transId);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
#ifdef DEBUG_NODE_MSGS
|
||||||
|
std::cerr << "bdNode::iteration() Pinging Potential Peer : ";
|
||||||
|
mFns->bdPrintId(std::cerr, &pid);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mCounterPings++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
||||||
{
|
{
|
||||||
|
/* go through the possible queries */
|
||||||
if (it->nextQuery(id, targetNodeId))
|
if (it->nextQuery(id, targetNodeId))
|
||||||
{
|
{
|
||||||
/* push out query */
|
/* push out query */
|
||||||
bdToken transId;
|
bdToken transId;
|
||||||
genNewTransId(&transId);
|
genNewTransId(&transId);
|
||||||
registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_FIND_NODE);
|
//registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_FIND_NODE);
|
||||||
|
|
||||||
msgout_find_node(&id, &transId, &targetNodeId);
|
msgout_find_node(&id, &transId, &targetNodeId);
|
||||||
|
|
||||||
@ -237,7 +272,7 @@ void bdNode::iteration()
|
|||||||
/* push out ping */
|
/* push out ping */
|
||||||
bdToken transId;
|
bdToken transId;
|
||||||
genNewTransId(&transId);
|
genNewTransId(&transId);
|
||||||
registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_PING);
|
//registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_PING);
|
||||||
msgout_ping(&id, &transId);
|
msgout_ping(&id, &transId);
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_MSGS
|
#ifdef DEBUG_NODE_MSGS
|
||||||
@ -630,6 +665,9 @@ void bdNode::msgout_ping(bdId *id, bdToken *transId)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PING);
|
||||||
|
|
||||||
|
|
||||||
/* create string */
|
/* create string */
|
||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
@ -654,6 +692,8 @@ void bdNode::msgout_pong(bdId *id, bdToken *transId)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PONG);
|
||||||
|
|
||||||
/* generate message, send to udp */
|
/* generate message, send to udp */
|
||||||
bdToken vid;
|
bdToken vid;
|
||||||
memcpy(vid.data, version, 5);
|
memcpy(vid.data, version, 5);
|
||||||
@ -681,6 +721,9 @@ void bdNode::msgout_find_node(bdId *id, bdToken *transId, bdNodeId *query)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_FIND_NODE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
@ -697,6 +740,9 @@ void bdNode::msgout_reply_find_node(bdId *id, bdToken *transId, std::list<bdId>
|
|||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NODE);
|
||||||
|
|
||||||
|
|
||||||
int blen = bitdht_resp_node_msg(transId, &(mOwnId), peers, msg, avail-1);
|
int blen = bitdht_resp_node_msg(transId, &(mOwnId), peers, msg, avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -737,6 +783,9 @@ void bdNode::msgout_get_hash(bdId *id, bdToken *transId, bdNodeId *info_hash)
|
|||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_GET_HASH);
|
||||||
|
|
||||||
|
|
||||||
int blen = bitdht_get_peers_msg(transId, &(mOwnId), info_hash, msg, avail-1);
|
int blen = bitdht_get_peers_msg(transId, &(mOwnId), info_hash, msg, avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -767,6 +816,8 @@ void bdNode::msgout_reply_hash(bdId *id, bdToken *transId, bdToken *token, std::
|
|||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_HASH);
|
||||||
|
|
||||||
int blen = bitdht_peers_reply_hash_msg(transId, &(mOwnId), token, values, msg, avail-1);
|
int blen = bitdht_peers_reply_hash_msg(transId, &(mOwnId), token, values, msg, avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -796,7 +847,11 @@ void bdNode::msgout_reply_nearest(bdId *id, bdToken *transId, bdToken *token, st
|
|||||||
|
|
||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NEAR);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int blen = bitdht_peers_reply_closest_msg(transId, &(mOwnId), token, nodes, msg, avail-1);
|
int blen = bitdht_peers_reply_closest_msg(transId, &(mOwnId), token, nodes, msg, avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -820,7 +875,10 @@ void bdNode::msgout_post_hash(bdId *id, bdToken *transId, bdNodeId *info_hash, u
|
|||||||
|
|
||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_POST_HASH);
|
||||||
|
|
||||||
|
|
||||||
int blen = bitdht_announce_peers_msg(transId,&(mOwnId),info_hash,port,token,msg,avail-1);
|
int blen = bitdht_announce_peers_msg(transId,&(mOwnId),info_hash,port,token,msg,avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -841,6 +899,8 @@ void bdNode::msgout_reply_post(bdId *id, bdToken *transId)
|
|||||||
char msg[10240];
|
char msg[10240];
|
||||||
int avail = 10240;
|
int avail = 10240;
|
||||||
|
|
||||||
|
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_POST);
|
||||||
|
|
||||||
int blen = bitdht_reply_announce_msg(transId, &(mOwnId), msg, avail-1);
|
int blen = bitdht_reply_announce_msg(transId, &(mOwnId), msg, avail-1);
|
||||||
|
|
||||||
sendPkt(msg, blen, id->addr);
|
sendPkt(msg, blen, id->addr);
|
||||||
@ -1121,7 +1181,8 @@ void bdNode::recvPkt(char *msg, int len, struct sockaddr_in addr)
|
|||||||
/****************** Bits Parsed Ok. Process Msg ***********************/
|
/****************** Bits Parsed Ok. Process Msg ***********************/
|
||||||
/* Construct Source Id */
|
/* Construct Source Id */
|
||||||
bdId srcId(id, addr);
|
bdId srcId(id, addr);
|
||||||
|
|
||||||
|
checkIncomingMsg(&srcId, &transId, beType);
|
||||||
switch(beType)
|
switch(beType)
|
||||||
{
|
{
|
||||||
case BITDHT_MSG_TYPE_PING: /* a: id, transId */
|
case BITDHT_MSG_TYPE_PING: /* a: id, transId */
|
||||||
@ -1274,6 +1335,8 @@ void bdNode::msgin_pong(bdId *id, bdToken *transId, bdToken *versionId)
|
|||||||
std::cerr << " To: ";
|
std::cerr << " To: ";
|
||||||
mFns->bdPrintId(std::cerr, id);
|
mFns->bdPrintId(std::cerr, id);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) transId;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mCounterRecvPong++;
|
mCounterRecvPong++;
|
||||||
@ -1364,6 +1427,8 @@ void bdNode::msgin_reply_find_node(bdId *id, bdToken *transId, std::list<bdId> &
|
|||||||
mFns->bdPrintId(std::cerr, &(*it));
|
mFns->bdPrintId(std::cerr, &(*it));
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) transId;
|
||||||
#endif
|
#endif
|
||||||
mCounterRecvReplyFindNode++;
|
mCounterRecvReplyFindNode++;
|
||||||
|
|
||||||
@ -1422,7 +1487,11 @@ void bdNode::msgin_reply_hash(bdId *id, bdToken *transId, bdToken *token, std::l
|
|||||||
bdPrintCompactPeerId(std::cerr, *it);
|
bdPrintCompactPeerId(std::cerr, *it);
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) transId;
|
||||||
|
(void) token;
|
||||||
|
(void) values;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1446,6 +1515,11 @@ void bdNode::msgin_reply_nearest(bdId *id, bdToken *transId, bdToken *token, std
|
|||||||
mFns->bdPrintId(std::cerr, &(*it));
|
mFns->bdPrintId(std::cerr, &(*it));
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) transId;
|
||||||
|
(void) token;
|
||||||
|
(void) nodes;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1466,6 +1540,12 @@ void bdNode::msgin_post_hash(bdId *id, bdToken *transId, bdNodeId *info_hash,
|
|||||||
std::cerr << " Token: ";
|
std::cerr << " Token: ";
|
||||||
bdPrintToken(std::cerr, token);
|
bdPrintToken(std::cerr, token);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) transId;
|
||||||
|
(void) info_hash;
|
||||||
|
(void) port;
|
||||||
|
(void) token;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1482,6 +1562,9 @@ void bdNode::msgin_reply_post(bdId *id, bdToken *transId)
|
|||||||
std::cerr << " From: ";
|
std::cerr << " From: ";
|
||||||
mFns->bdPrintId(std::cerr, id);
|
mFns->bdPrintId(std::cerr, id);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) transId;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1550,6 +1633,24 @@ int bdNode::queueQuery(bdId *id, bdNodeId *query, bdToken *transId, uint32_t que
|
|||||||
|
|
||||||
void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef DEBUG_MSG_CHECKS
|
||||||
|
std::cerr << "bdNode::registerOutgoingMsg(";
|
||||||
|
mFns->bdPrintId(std::cerr, id);
|
||||||
|
std::cerr << ", " << msgType << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) msgType;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_HISTORY
|
||||||
|
mHistory.addMsg(id, transId, msgType, false);
|
||||||
|
#else
|
||||||
|
(void) transId;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****
|
/****
|
||||||
#define BITDHT_MSG_TYPE_UNKNOWN 0
|
#define BITDHT_MSG_TYPE_UNKNOWN 0
|
||||||
@ -1566,8 +1667,27 @@ void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t bdNode::checkIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
uint32_t bdNode::checkIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef DEBUG_MSG_CHECKS
|
||||||
|
std::cerr << "bdNode::checkIncomingMsg(";
|
||||||
|
mFns->bdPrintId(std::cerr, id);
|
||||||
|
std::cerr << ", " << msgType << ")";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#else
|
||||||
|
(void) id;
|
||||||
|
(void) msgType;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_HISTORY
|
||||||
|
mHistory.addMsg(id, transId, msgType, true);
|
||||||
|
#else
|
||||||
|
(void) transId;
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "bitdht/bdstore.h"
|
#include "bitdht/bdstore.h"
|
||||||
#include "bitdht/bdobj.h"
|
#include "bitdht/bdobj.h"
|
||||||
#include "bitdht/bdhash.h"
|
#include "bitdht/bdhash.h"
|
||||||
|
#include "bitdht/bdhistory.h"
|
||||||
|
|
||||||
|
|
||||||
#define BD_QUERY_NEIGHBOURS 1
|
#define BD_QUERY_NEIGHBOURS 1
|
||||||
@ -191,6 +192,8 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||||||
bdDhtFunctions *mFns;
|
bdDhtFunctions *mFns;
|
||||||
|
|
||||||
bdHashSpace mHashSpace;
|
bdHashSpace mHashSpace;
|
||||||
|
|
||||||
|
bdHistory mHistory; /* for understanding the DHT */
|
||||||
|
|
||||||
std::list<bdQuery> mLocalQueries;
|
std::list<bdQuery> mLocalQueries;
|
||||||
std::list<bdRemoteQuery> mRemoteQueries;
|
std::list<bdRemoteQuery> mRemoteQueries;
|
||||||
|
@ -43,7 +43,7 @@ void bdPrintToken(std::ostream &out, bdToken *token)
|
|||||||
out << std::dec;
|
out << std::dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdPrintCompactPeerId(std::ostream &out, std::string cpi)
|
void bdPrintCompactPeerId(std::ostream &out, std::string /*cpi*/ )
|
||||||
{
|
{
|
||||||
out << "DummyCompactPeerId";
|
out << "DummyCompactPeerId";
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ bdSpace::bdSpace(bdNodeId *ownId, bdDhtFunctions *fns)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdSpace::find_nearest_nodes(const bdNodeId *id, int number, std::list<bdId> excluding, std::multimap<bdMetric, bdId> &nearest)
|
int bdSpace::find_nearest_nodes(const bdNodeId *id, int number, std::list<bdId> /*excluding*/, std::multimap<bdMetric, bdId> &nearest)
|
||||||
{
|
{
|
||||||
std::multimap<bdMetric, bdId> closest;
|
std::multimap<bdMetric, bdId> closest;
|
||||||
std::multimap<bdMetric, bdId>::iterator mit;
|
std::multimap<bdMetric, bdId>::iterator mit;
|
||||||
|
@ -124,6 +124,7 @@ class bdPeer
|
|||||||
uint32_t mPeerFlags;
|
uint32_t mPeerFlags;
|
||||||
time_t mLastSendTime;
|
time_t mLastSendTime;
|
||||||
time_t mLastRecvTime;
|
time_t mLastRecvTime;
|
||||||
|
time_t mFoundTime; /* time stamp that peer was found */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,10 +36,9 @@
|
|||||||
* #define DEBUG_QUERY 1
|
* #define DEBUG_QUERY 1
|
||||||
**/
|
**/
|
||||||
|
|
||||||
//#define DEBUG_QUERY 1
|
|
||||||
|
|
||||||
#define EXPECTED_REPLY 10
|
#define EXPECTED_REPLY 20
|
||||||
#define QUERY_IDLE_RETRY_PEER_PERIOD (mFns->bdNodesPerBucket() * 15)
|
#define QUERY_IDLE_RETRY_PEER_PERIOD (mFns->bdNodesPerBucket() * 30)
|
||||||
|
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
@ -52,18 +51,21 @@
|
|||||||
* This involves
|
* This involves
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bdQuery::bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryFlags, bdDhtFunctions *fns)
|
bdQuery::bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryFlags,
|
||||||
|
bdDhtFunctions *fns)
|
||||||
{
|
{
|
||||||
/* */
|
/* */
|
||||||
mId = *id;
|
mId = *id;
|
||||||
mFns = fns;
|
mFns = fns;
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
std::list<bdId>::iterator it;
|
std::list<bdId>::iterator it;
|
||||||
for(it = startList.begin(); it != startList.end(); it++)
|
for(it = startList.begin(); it != startList.end(); it++)
|
||||||
{
|
{
|
||||||
bdPeer peer;
|
bdPeer peer;
|
||||||
peer.mLastSendTime = 0;
|
peer.mLastSendTime = 0;
|
||||||
peer.mLastRecvTime = 0;
|
peer.mLastRecvTime = 0;
|
||||||
|
peer.mFoundTime = now;
|
||||||
peer.mPeerId = *it;
|
peer.mPeerId = *it;
|
||||||
|
|
||||||
bdMetric dist;
|
bdMetric dist;
|
||||||
@ -77,7 +79,7 @@ bdQuery::bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryF
|
|||||||
|
|
||||||
mState = BITDHT_QUERY_QUERYING;
|
mState = BITDHT_QUERY_QUERYING;
|
||||||
mQueryFlags = queryFlags;
|
mQueryFlags = queryFlags;
|
||||||
mQueryTS = time(NULL);
|
mQueryTS = now;
|
||||||
|
|
||||||
/* setup the limit of the search
|
/* setup the limit of the search
|
||||||
* by default it is setup to 000000 = exact match
|
* by default it is setup to 000000 = exact match
|
||||||
@ -130,7 +132,8 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* re-request every so often */
|
/* re-request every so often */
|
||||||
if ((mQueryFlags & BITDHT_QFLAGS_DO_IDLE) && (now - it->second.mLastSendTime > QUERY_IDLE_RETRY_PEER_PERIOD))
|
if ((!queryPeer) && (mQueryFlags & BITDHT_QFLAGS_DO_IDLE) &&
|
||||||
|
(now - it->second.mLastSendTime > QUERY_IDLE_RETRY_PEER_PERIOD))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "NextQuery() Found out-of-date. queryPeer = true : ");
|
fprintf(stderr, "NextQuery() Found out-of-date. queryPeer = true : ");
|
||||||
@ -145,7 +148,6 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
|||||||
* - replacement policy will still work.
|
* - replacement policy will still work.
|
||||||
*/
|
*/
|
||||||
if (it->second.mLastRecvTime == 0)
|
if (it->second.mLastRecvTime == 0)
|
||||||
//if (it->second.mLastRecvTime < it->second.mLastSendTime)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "NextQuery() Never Received: notFinished = true: ");
|
fprintf(stderr, "NextQuery() Never Received: notFinished = true: ");
|
||||||
@ -240,7 +242,6 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
||||||
{
|
{
|
||||||
bdMetric dist;
|
bdMetric dist;
|
||||||
@ -264,7 +265,6 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
|||||||
{
|
{
|
||||||
time_t sendts = ts - it->second.mLastSendTime;
|
time_t sendts = ts - it->second.mLastSendTime;
|
||||||
bool hasSent = (it->second.mLastSendTime != 0);
|
bool hasSent = (it->second.mLastSendTime != 0);
|
||||||
//bool hasReply = (it->second.mLastRecvTime != 0);
|
|
||||||
bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime);
|
bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime);
|
||||||
if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY))
|
if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY))
|
||||||
{
|
{
|
||||||
@ -296,8 +296,9 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
|||||||
#endif
|
#endif
|
||||||
if (mode & BITDHT_PEER_STATUS_RECV_NODES)
|
if (mode & BITDHT_PEER_STATUS_RECV_NODES)
|
||||||
{
|
{
|
||||||
|
/* only update recvTime if sendTime > checkTime.... (then its our query) */
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "Updating LastRecvTime\n");
|
fprintf(stderr, "Updating LastRecvTime\n");
|
||||||
#endif
|
#endif
|
||||||
it->second.mLastRecvTime = ts;
|
it->second.mLastRecvTime = ts;
|
||||||
}
|
}
|
||||||
@ -320,7 +321,6 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
|||||||
{
|
{
|
||||||
time_t sendts = ts - it->second.mLastSendTime;
|
time_t sendts = ts - it->second.mLastSendTime;
|
||||||
bool hasSent = (it->second.mLastSendTime != 0);
|
bool hasSent = (it->second.mLastSendTime != 0);
|
||||||
//bool hasReply = (it->second.mLastRecvTime != 0);
|
|
||||||
bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime);
|
bool hasReply = (it->second.mLastRecvTime >= it->second.mLastSendTime);
|
||||||
if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY))
|
if ((hasSent) && (!hasReply) && (sendts > EXPECTED_REPLY))
|
||||||
{
|
{
|
||||||
@ -364,10 +364,13 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
|||||||
peer.mPeerId = *id;
|
peer.mPeerId = *id;
|
||||||
peer.mLastSendTime = 0;
|
peer.mLastSendTime = 0;
|
||||||
peer.mLastRecvTime = 0;
|
peer.mLastRecvTime = 0;
|
||||||
|
peer.mFoundTime = ts;
|
||||||
|
|
||||||
if (mode & BITDHT_PEER_STATUS_RECV_NODES)
|
if (mode & BITDHT_PEER_STATUS_RECV_NODES)
|
||||||
{
|
{
|
||||||
peer.mLastRecvTime = ts;
|
peer.mLastRecvTime = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
mClosest.insert(std::pair<bdMetric, bdPeer>(dist, peer));
|
mClosest.insert(std::pair<bdMetric, bdPeer>(dist, peer));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -515,6 +518,7 @@ int bdQuery::addPotentialPeer(const bdId *id, uint32_t mode)
|
|||||||
peer.mPeerId = *id;
|
peer.mPeerId = *id;
|
||||||
peer.mLastSendTime = 0;
|
peer.mLastSendTime = 0;
|
||||||
peer.mLastRecvTime = ts;
|
peer.mLastRecvTime = ts;
|
||||||
|
peer.mFoundTime = ts;
|
||||||
mPotentialClosest.insert(std::pair<bdMetric, bdPeer>(dist, peer));
|
mPotentialClosest.insert(std::pair<bdMetric, bdPeer>(dist, peer));
|
||||||
|
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
@ -534,7 +538,8 @@ int bdQuery::printQuery()
|
|||||||
time_t ts = time(NULL);
|
time_t ts = time(NULL);
|
||||||
fprintf(stderr, "Query for: ");
|
fprintf(stderr, "Query for: ");
|
||||||
mFns->bdPrintNodeId(std::cerr, &mId);
|
mFns->bdPrintNodeId(std::cerr, &mId);
|
||||||
fprintf(stderr, " Query State: %d", mState);
|
fprintf(stderr, " Query State: %d", mState);
|
||||||
|
fprintf(stderr, " Query Age %ld secs", ts-mQueryTS);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
fprintf(stderr, "Closest Available Peers:\n");
|
fprintf(stderr, "Closest Available Peers:\n");
|
||||||
@ -544,6 +549,7 @@ int bdQuery::printQuery()
|
|||||||
fprintf(stderr, "Id: ");
|
fprintf(stderr, "Id: ");
|
||||||
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
||||||
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
||||||
|
fprintf(stderr," Found: %ld ago", ts-it->second.mFoundTime);
|
||||||
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
||||||
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
@ -555,10 +561,12 @@ int bdQuery::printQuery()
|
|||||||
fprintf(stderr, "Id: ");
|
fprintf(stderr, "Id: ");
|
||||||
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
||||||
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
||||||
|
fprintf(stderr," Found: %ld ago", ts-it->second.mFoundTime);
|
||||||
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
||||||
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ int bdStore::getPeer(bdPeer *peer)
|
|||||||
|
|
||||||
std::list<bdPeer>::iterator it;
|
std::list<bdPeer>::iterator it;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(it = store.begin(); (it != store.end()) && (i < mIndex); it++, i++);
|
for(it = store.begin(); (it != store.end()) && (i < mIndex); it++, i++) ; /* empty loop */
|
||||||
if (it != store.end())
|
if (it != store.end())
|
||||||
{
|
{
|
||||||
*peer = *it;
|
*peer = *it;
|
||||||
@ -161,6 +161,16 @@ void bdStore::writeStore(std::string file)
|
|||||||
fprintf(stderr, "bdStore::writeStore(%s) = %d entries\n", file.c_str(), store.size());
|
fprintf(stderr, "bdStore::writeStore(%s) = %d entries\n", file.c_str(), store.size());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (store.size() < 0.9 * MAX_ENTRIES)
|
||||||
|
{
|
||||||
|
/* don't save yet! */
|
||||||
|
#ifdef DEBUG_STORE
|
||||||
|
fprintf(stderr, "bdStore::writeStore() Delaying until more entries\n");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FILE *fd = fopen(file.c_str(), "w");
|
FILE *fd = fopen(file.c_str(), "w");
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user