mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Expanded DHT history analysis, and ran some more tests on DHT behaviour.
- Tweaked query parameters (quicker discard, longer requery period). The analysis suggests that in general the DHT is running okay with some minor issues. - BitDHT peers respond to ~50% of FIND_NODE queries. This means we drop them, and so some ONLINE friends, become UNREACHABLE friends. This appears to be caused by too many FIND_NODE queries reaching BitDHT, and the peer starts dropping them. This appears to come from specific peers, which are not RS nodes. Proposed solution is to Track and Filter Over-Querying Peers. (Only one query per peer every 30 seconds). - Should be more lenient on the exact query matches. Allow some dropped messages. - Queries appear to run longer than necessary. A better query completion criteria needs to be established. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6614 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1554e17f48
commit
0608f67d71
@ -3,21 +3,35 @@
|
||||
#include "bitdht/bdhistory.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bitdht/bdmsgs.h"
|
||||
#include <set>
|
||||
|
||||
#define MIN_RESEND_PERIOD 60
|
||||
|
||||
void bdMsgHistoryList::addMsg(time_t ts, uint32_t msgType, bool incoming)
|
||||
bdMsgHistoryList::bdMsgHistoryList()
|
||||
:mPeerVersion("Unknown")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void bdMsgHistoryList::addMsg(time_t ts, uint32_t msgType, bool incoming, const bdNodeId *aboutId)
|
||||
{
|
||||
// std::cerr << "bdMsgHistoryList::addMsg()";
|
||||
// std::cerr << std::endl;
|
||||
|
||||
uint32_t msg = msgType | (incoming ? MSG_DIRECTION_INCOMING : MSG_DIRECTION_OUTGOING);
|
||||
bdMsgHistoryItem msg(msgType, incoming, aboutId);
|
||||
msgHistory.insert(std::make_pair(ts, msg));
|
||||
}
|
||||
|
||||
void bdMsgHistoryList::setPeerType(time_t /* ts */, std::string version)
|
||||
{
|
||||
mPeerVersion = version;
|
||||
}
|
||||
|
||||
int bdMsgHistoryList::msgCount(time_t start_ts, time_t end_ts)
|
||||
{
|
||||
std::multimap<time_t, uint32_t>::iterator sit, eit, it;
|
||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
||||
sit = msgHistory.lower_bound(start_ts);
|
||||
eit = msgHistory.upper_bound(end_ts);
|
||||
int count = 0;
|
||||
@ -48,11 +62,21 @@ bool bdMsgHistoryList::msgClear(time_t before)
|
||||
return false;
|
||||
}
|
||||
|
||||
void bdMsgHistoryList::msgClear()
|
||||
{
|
||||
msgHistory.clear();
|
||||
}
|
||||
|
||||
|
||||
void bdMsgHistoryList::clearHistory()
|
||||
{
|
||||
msgClear();
|
||||
}
|
||||
|
||||
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;
|
||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
||||
sit = msgHistory.lower_bound(start_ts);
|
||||
eit = msgHistory.upper_bound(end_ts);
|
||||
time_t curr_ts = 0;
|
||||
@ -86,28 +110,31 @@ void bdMsgHistoryList::printHistory(std::ostream &out, int mode, time_t start_ts
|
||||
out << "\tTS: " << time(NULL) - curr_ts << " ";
|
||||
}
|
||||
|
||||
if (MSG_DIRECTION_INCOMING & it->second)
|
||||
{
|
||||
uint32_t type = it->second-MSG_DIRECTION_INCOMING;
|
||||
out << "( => ";
|
||||
std::string name;
|
||||
if (bitdht_msgtype(type, name))
|
||||
bitdht_msgtype(it->second.msgType, name);
|
||||
|
||||
if (it->second.incoming)
|
||||
{
|
||||
out << name;
|
||||
}
|
||||
out << " )";
|
||||
out << "( =I> ";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "( ";
|
||||
uint32_t type = it->second - MSG_DIRECTION_OUTGOING;
|
||||
std::string name;
|
||||
if (bitdht_msgtype(type, name))
|
||||
out << "( <O= ";
|
||||
}
|
||||
|
||||
out << name << " ";
|
||||
if ((it->second.aboutId.data[0] == 0)
|
||||
&& (it->second.aboutId.data[3] == 0)
|
||||
&& (it->second.aboutId.data[3] == 0)
|
||||
&& (it->second.aboutId.data[3] == 0))
|
||||
{
|
||||
out << name;
|
||||
/* don't print anything */
|
||||
}
|
||||
out << " <= )";
|
||||
else
|
||||
{
|
||||
bdStdPrintNodeId(out, &(it->second.aboutId));
|
||||
}
|
||||
out << " )";
|
||||
|
||||
}
|
||||
break;
|
||||
@ -126,7 +153,7 @@ bool bdMsgHistoryList::canSend()
|
||||
{
|
||||
std::cerr << "bdMsgHistoryList::canSend()";
|
||||
|
||||
std::multimap<time_t, uint32_t>::reverse_iterator rit;
|
||||
std::multimap<time_t, bdMsgHistoryItem>::reverse_iterator rit;
|
||||
|
||||
rit = msgHistory.rbegin();
|
||||
if (rit != msgHistory.rend())
|
||||
@ -159,11 +186,11 @@ bool bdMsgHistoryList::validPeer()
|
||||
{
|
||||
std::cerr << "bdMsgHistoryList::validPeer()";
|
||||
|
||||
std::multimap<time_t, uint32_t>::iterator it;
|
||||
std::multimap<time_t, bdMsgHistoryItem>::iterator it;
|
||||
|
||||
for(it = msgHistory.begin(); it != msgHistory.end(); it++)
|
||||
{
|
||||
if (MSG_DIRECTION_INCOMING & it->second)
|
||||
if (it->second.incoming)
|
||||
{
|
||||
std::cerr << " Incoming Msg... so validPeer";
|
||||
std::cerr << std::endl;
|
||||
@ -179,11 +206,123 @@ bool bdMsgHistoryList::validPeer()
|
||||
}
|
||||
|
||||
|
||||
#define MAX_PING_PER_MINUTE 2
|
||||
#define MAX_QUERY_PER_MINUTE 2
|
||||
|
||||
bool bdMsgHistoryList::analysePeer()
|
||||
|
||||
{
|
||||
/* analyse and print out details of the peers messages */
|
||||
bool flagged = false;
|
||||
|
||||
//out << "AGE: MSGS => incoming, <= outgoing" << std::endl;
|
||||
std::multimap<time_t, bdMsgHistoryItem>::iterator sit, eit, it;
|
||||
sit = msgHistory.begin();
|
||||
eit = msgHistory.end();
|
||||
if (sit == eit)
|
||||
{
|
||||
// nothing here.
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t start_ts = sit->first;
|
||||
time_t end_ts = msgHistory.rbegin()->first; // must exist.
|
||||
|
||||
|
||||
// don't divide by zero.
|
||||
if (end_ts - start_ts < 60)
|
||||
{
|
||||
end_ts = start_ts + 60;
|
||||
}
|
||||
|
||||
|
||||
/* what do we want to analyse? */
|
||||
|
||||
/* if we have sent / recved too many queries or pings */
|
||||
|
||||
int in_ping = 0;
|
||||
int out_ping = 0;
|
||||
int in_query = 0;
|
||||
int out_query = 0;
|
||||
int in_other = 0;
|
||||
int out_other = 0;
|
||||
|
||||
for(it = sit; it != eit; it++)
|
||||
{
|
||||
if (it->second.incoming)
|
||||
{
|
||||
switch(it->second.msgType)
|
||||
{
|
||||
case BITDHT_MSG_TYPE_PING:
|
||||
in_ping++;
|
||||
break;
|
||||
case BITDHT_MSG_TYPE_FIND_NODE:
|
||||
in_query++;
|
||||
break;
|
||||
default:
|
||||
in_other++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(it->second.msgType)
|
||||
{
|
||||
case BITDHT_MSG_TYPE_PING:
|
||||
out_ping++;
|
||||
break;
|
||||
case BITDHT_MSG_TYPE_FIND_NODE:
|
||||
out_query++;
|
||||
break;
|
||||
default:
|
||||
out_other++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float in_ping_per_min = in_ping * 60.0 / (end_ts - start_ts);
|
||||
float out_ping_per_min = out_ping * 60.0 / (end_ts - start_ts);
|
||||
float in_query_per_min = in_query * 60.0 / (end_ts - start_ts);
|
||||
float out_query_per_min = out_query * 60.0 / (end_ts - start_ts);
|
||||
|
||||
if ((in_ping_per_min > MAX_PING_PER_MINUTE) ||
|
||||
(out_ping_per_min > MAX_PING_PER_MINUTE) ||
|
||||
(in_query_per_min > MAX_PING_PER_MINUTE) ||
|
||||
(out_query_per_min > MAX_PING_PER_MINUTE))
|
||||
{
|
||||
flagged = true;
|
||||
}
|
||||
|
||||
if (flagged)
|
||||
{
|
||||
/* print header */
|
||||
std::ostream &out = std::cerr;
|
||||
out << "BdHistoryAnalysis has flagged peer: ";
|
||||
bdStdPrintId(out, &mId);
|
||||
out << std::endl;
|
||||
|
||||
out << "PeerType: " << mPeerVersion;
|
||||
out << std::endl;
|
||||
|
||||
out << "Ping In Per Min : " << in_ping_per_min << std::endl;
|
||||
out << "Ping Out Per Min : " << out_ping_per_min << std::endl;
|
||||
out << "Query In Per Min : " << in_query_per_min << std::endl;
|
||||
out << "Query Out Per Min: " << out_query_per_min << std::endl;
|
||||
|
||||
out << "Message History: ";
|
||||
out << std::endl;
|
||||
|
||||
printHistory(out, 0, 0, time(NULL));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bdHistory::bdHistory(time_t store_period)
|
||||
:mStorePeriod(store_period) { return; }
|
||||
|
||||
|
||||
void bdHistory::addMsg(const bdId *id, bdToken * /*transId*/, uint32_t msgType, bool incoming)
|
||||
void bdHistory::addMsg(const bdId *id, bdToken * /*transId*/, uint32_t msgType, bool incoming, const bdNodeId *aboutId)
|
||||
{
|
||||
//std::cerr << "bdHistory::addMsg() ";
|
||||
//bdStdPrintId(std::cerr, id);
|
||||
@ -193,10 +332,18 @@ void bdHistory::addMsg(const bdId *id, bdToken * /*transId*/, uint32_t msgType,
|
||||
|
||||
std::map<bdId, bdMsgHistoryList>::iterator it;
|
||||
bdMsgHistoryList &histRef = mHistory[*id]; /* will instaniate empty */
|
||||
histRef.addMsg(now, msgType, incoming);
|
||||
histRef.mId = *id;
|
||||
histRef.addMsg(now, msgType, incoming, aboutId);
|
||||
|
||||
/* add to mMsgTimeline */
|
||||
mMsgTimeline.insert(std::make_pair(now, MsgRegister(id, msgType, incoming)));
|
||||
mMsgTimeline.insert(std::make_pair(now, MsgRegister(id, msgType, incoming, aboutId)));
|
||||
}
|
||||
|
||||
void bdHistory::setPeerType(const bdId *id, std::string version)
|
||||
{
|
||||
std::map<bdId, bdMsgHistoryList>::iterator it;
|
||||
bdMsgHistoryList &histRef = mHistory[*id]; /* will instaniate empty */
|
||||
histRef.setPeerType(time(NULL), version);
|
||||
}
|
||||
|
||||
void bdHistory::printMsgs()
|
||||
@ -216,13 +363,13 @@ void bdHistory::printMsgs()
|
||||
/* print header */
|
||||
out << "Msgs for ";
|
||||
bdStdPrintId(out, &(it->first));
|
||||
out << " v:" << it->second.mPeerVersion;
|
||||
out << std::endl;
|
||||
|
||||
it->second.printHistory(out, 0, 0, time(NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
out << "Msg Timeline:";
|
||||
time_t now = time(NULL);
|
||||
std::multimap<time_t, MsgRegister>::iterator hit;
|
||||
@ -233,11 +380,11 @@ void bdHistory::printMsgs()
|
||||
|
||||
if (hit->second.incoming)
|
||||
{
|
||||
out << " => ";
|
||||
out << " =I> ";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << " <= ";
|
||||
out << " <O= ";
|
||||
}
|
||||
|
||||
std::string name;
|
||||
@ -264,8 +411,8 @@ void bdHistory::cleanupOldMsgs()
|
||||
return; // no cleanup
|
||||
}
|
||||
|
||||
std::list<bdId> to_cleanup;
|
||||
std::list<bdId>::iterator cit;
|
||||
std::set<bdId> to_cleanup;
|
||||
std::set<bdId>::iterator cit;
|
||||
|
||||
time_t before = time(NULL) - mStorePeriod;
|
||||
|
||||
@ -273,7 +420,7 @@ void bdHistory::cleanupOldMsgs()
|
||||
while((mMsgTimeline.begin() != mMsgTimeline.end()) && (mMsgTimeline.begin()->first < before))
|
||||
{
|
||||
std::multimap<time_t, MsgRegister>::iterator it = mMsgTimeline.begin();
|
||||
to_cleanup.push_back(it->second.id);
|
||||
to_cleanup.insert(it->second.id);
|
||||
mMsgTimeline.erase(it);
|
||||
}
|
||||
|
||||
@ -286,20 +433,31 @@ void bdHistory::cleanupOldMsgs()
|
||||
{
|
||||
if (hit->second.msgClear(before))
|
||||
{
|
||||
mHistory.erase(hit);
|
||||
// don't erase actual entry (so we remember peer type).
|
||||
//mHistory.erase(hit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void bdHistory::clearHistory()
|
||||
{
|
||||
mHistory.clear();
|
||||
// Switched to a alternative clear, so we don't drop peers, and remember their type.
|
||||
//mHistory.clear();
|
||||
|
||||
|
||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
||||
{
|
||||
it->second.clearHistory();
|
||||
}
|
||||
}
|
||||
|
||||
bool bdHistory::canSend(const bdId *id)
|
||||
{
|
||||
|
||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||
it = mHistory.find(*id);
|
||||
if (it != mHistory.end())
|
||||
@ -325,4 +483,144 @@ bool bdHistory::validPeer(const bdId *id)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bdHistory::analysePeers()
|
||||
{
|
||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
||||
{
|
||||
it->second.analysePeer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Temp data class. */
|
||||
class TypeStats
|
||||
{
|
||||
public:
|
||||
|
||||
TypeStats() :nodes(0) { return; }
|
||||
|
||||
std::map<uint32_t, uint32_t> incoming, outgoing;
|
||||
int nodes;
|
||||
|
||||
|
||||
void printStats(std::ostream &out, const TypeStats *refStats)
|
||||
{
|
||||
std::map<uint32_t, uint32_t>::iterator it;
|
||||
std::map<uint32_t, uint32_t>::const_iterator rit;
|
||||
|
||||
out << " Nodes: " << nodes;
|
||||
if (refStats)
|
||||
{
|
||||
out << " (" << 100.0 * nodes / (float) refStats->nodes << " %)";
|
||||
}
|
||||
out << std::endl;
|
||||
|
||||
out << " Incoming Msgs";
|
||||
out << std::endl;
|
||||
for(it = incoming.begin(); it != incoming.end(); it++)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
if (refStats)
|
||||
{
|
||||
rit = refStats->incoming.find(it->first);
|
||||
if (rit != refStats->incoming.end())
|
||||
{
|
||||
count = rit->second;
|
||||
}
|
||||
}
|
||||
printStatsLine(out, it->first, it->second, count);
|
||||
}
|
||||
|
||||
out << " Outgoing Msgs";
|
||||
out << std::endl;
|
||||
for(it = outgoing.begin(); it != outgoing.end(); it++)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
if (refStats)
|
||||
{
|
||||
rit = refStats->outgoing.find(it->first);
|
||||
if (rit != refStats->outgoing.end())
|
||||
{
|
||||
count = rit->second;
|
||||
}
|
||||
}
|
||||
printStatsLine(out, it->first, it->second, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void printStatsLine(std::ostream &out, uint32_t msgType, uint32_t count, uint32_t global)
|
||||
{
|
||||
std::string name;
|
||||
bitdht_msgtype(msgType, name);
|
||||
out << "\t" << name << " " << count;
|
||||
if (global != 0)
|
||||
{
|
||||
out << " (" << 100.0 * count / (float) global << " %)";
|
||||
}
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
}; /* end of TypeStats */
|
||||
|
||||
bool bdHistory::peerTypeAnalysis()
|
||||
{
|
||||
|
||||
std::map<std::string, TypeStats> mTypeStats;
|
||||
TypeStats globalStats;
|
||||
|
||||
std::map<bdId, bdMsgHistoryList> ::iterator it;
|
||||
for(it = mHistory.begin(); it != mHistory.end(); it++)
|
||||
{
|
||||
if (it->second.msgHistory.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string version = it->second.mPeerVersion;
|
||||
// group be first two bytes.
|
||||
version = it->second.mPeerVersion.substr(0,2);
|
||||
TypeStats &stats = mTypeStats[version];
|
||||
|
||||
stats.nodes++;
|
||||
globalStats.nodes++;
|
||||
|
||||
std::multimap<time_t, bdMsgHistoryItem>::iterator lit;
|
||||
for (lit = it->second.msgHistory.begin(); lit != it->second.msgHistory.end(); lit++)
|
||||
{
|
||||
if (lit->second.incoming)
|
||||
{
|
||||
stats.incoming[lit->second.msgType]++;
|
||||
globalStats.incoming[lit->second.msgType]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
stats.outgoing[lit->second.msgType]++;
|
||||
globalStats.outgoing[lit->second.msgType]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, TypeStats>::iterator tit;
|
||||
for(tit = mTypeStats.begin(); tit != mTypeStats.end(); tit++)
|
||||
{
|
||||
std::cerr << "Stats for Peer Type: " << tit->first;
|
||||
std::cerr << std::endl;
|
||||
tit->second.printStats(std::cerr, &globalStats);
|
||||
}
|
||||
|
||||
std::cerr << "Global Stats: ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
globalStats.printStats(std::cerr, NULL);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "bitdht/bdobj.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include <map>
|
||||
|
||||
#define MSG_TYPE_DIRECTION_MASK 0x000f0000
|
||||
@ -16,28 +17,78 @@ class MsgRegister
|
||||
{
|
||||
public:
|
||||
MsgRegister() { return; }
|
||||
MsgRegister(const bdId *inId, uint32_t inMsgType, bool inIncoming)
|
||||
:id(*inId), msgType(inMsgType), incoming(inIncoming) { return; }
|
||||
MsgRegister(const bdId *inId, uint32_t inMsgType, bool inIncoming, const bdNodeId *inAboutId)
|
||||
:id(*inId), msgType(inMsgType), incoming(inIncoming)
|
||||
{
|
||||
if (inAboutId)
|
||||
{
|
||||
aboutId = *inAboutId;
|
||||
}
|
||||
else
|
||||
{
|
||||
bdStdZeroNodeId(&aboutId);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bdId id;
|
||||
uint32_t msgType;
|
||||
bool incoming;
|
||||
bdNodeId aboutId; // filled in for queries.
|
||||
};
|
||||
|
||||
|
||||
class bdMsgHistoryItem
|
||||
{
|
||||
public:
|
||||
bdMsgHistoryItem()
|
||||
:msgType(0), incoming(false)
|
||||
{
|
||||
bdStdZeroNodeId(&aboutId);
|
||||
return;
|
||||
}
|
||||
|
||||
bdMsgHistoryItem(uint32_t inMsgType, bool inIncoming, const bdNodeId *inAboutId)
|
||||
:msgType(inMsgType), incoming(inIncoming)
|
||||
{
|
||||
if (inAboutId)
|
||||
{
|
||||
aboutId = *inAboutId;
|
||||
}
|
||||
else
|
||||
{
|
||||
bdStdZeroNodeId(&aboutId);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t msgType;
|
||||
bool incoming;
|
||||
bdNodeId aboutId; // filled in for queries.
|
||||
};
|
||||
|
||||
|
||||
class bdMsgHistoryList
|
||||
{
|
||||
public:
|
||||
void addMsg(time_t ts, uint32_t msgType, bool incoming);
|
||||
bdMsgHistoryList();
|
||||
void addMsg(time_t ts, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
||||
void setPeerType(time_t ts, std::string version);
|
||||
int msgCount(time_t start_ts, time_t end_ts);
|
||||
bool msgClear(time_t before); // 0 => clear all.
|
||||
void msgClear();
|
||||
void printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts);
|
||||
bool analysePeer();
|
||||
void clearHistory();
|
||||
|
||||
bool canSend();
|
||||
bool validPeer();
|
||||
|
||||
std::multimap<time_t, uint32_t> msgHistory;
|
||||
std::multimap<time_t, bdMsgHistoryItem> msgHistory;
|
||||
std::string mPeerVersion;
|
||||
bdId mId;
|
||||
};
|
||||
|
||||
|
||||
@ -47,11 +98,14 @@ class bdHistory
|
||||
public:
|
||||
bdHistory(time_t store_period);
|
||||
|
||||
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming);
|
||||
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
||||
void setPeerType(const bdId *id, std::string version);
|
||||
void printMsgs();
|
||||
|
||||
void cleanupOldMsgs();
|
||||
void clearHistory();
|
||||
bool analysePeers();
|
||||
bool peerTypeAnalysis();
|
||||
|
||||
bool canSend(const bdId *id);
|
||||
bool validPeer(const bdId *id);
|
||||
@ -62,6 +116,7 @@ bool validPeer(const bdId *id);
|
||||
std::multimap<time_t, MsgRegister> mMsgTimeline;
|
||||
|
||||
int mStorePeriod;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
#define BITDHT_QUERY_START_PEERS 10
|
||||
#define BITDHT_QUERY_NEIGHBOUR_PEERS 8
|
||||
|
||||
#define BITDHT_MAX_REMOTE_QUERY_AGE 10
|
||||
#define BITDHT_MAX_REMOTE_QUERY_AGE 3 // 3 seconds, keep it fresh.
|
||||
#define MAX_REMOTE_PROCESS_PER_CYCLE 5
|
||||
|
||||
/****
|
||||
@ -270,6 +270,8 @@ void bdNode::printState()
|
||||
#ifdef USE_HISTORY
|
||||
mHistory.cleanupOldMsgs();
|
||||
mHistory.printMsgs();
|
||||
mHistory.analysePeers();
|
||||
mHistory.peerTypeAnalysis();
|
||||
#endif
|
||||
|
||||
mAccount.printStats(std::cerr);
|
||||
@ -809,7 +811,7 @@ void bdNode::msgout_ping(bdId *id, bdToken *transId)
|
||||
//registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PING);
|
||||
|
||||
bdId dupId(*id);
|
||||
registerOutgoingMsg(&dupId, transId, BITDHT_MSG_TYPE_PING);
|
||||
registerOutgoingMsg(&dupId, transId, BITDHT_MSG_TYPE_PING, NULL);
|
||||
|
||||
/* create string */
|
||||
char msg[10240];
|
||||
@ -834,7 +836,7 @@ void bdNode::msgout_pong(bdId *id, bdToken *transId)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PONG);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_PONG, NULL);
|
||||
|
||||
/* generate message, send to udp */
|
||||
bdToken vid;
|
||||
@ -870,7 +872,7 @@ void bdNode::msgout_find_node(bdId *id, bdToken *transId, bdNodeId *query)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_FIND_NODE);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_FIND_NODE, query);
|
||||
|
||||
|
||||
|
||||
@ -890,7 +892,7 @@ void bdNode::msgout_reply_find_node(bdId *id, bdToken *transId, std::list<bdId>
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NODE);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NODE, NULL);
|
||||
|
||||
mAccount.incCounter(BDACCOUNT_MSG_REPLYFINDNODE, true);
|
||||
|
||||
@ -934,7 +936,7 @@ void bdNode::msgout_get_hash(bdId *id, bdToken *transId, bdNodeId *info_hash)
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_GET_HASH);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_GET_HASH, info_hash);
|
||||
|
||||
|
||||
int blen = bitdht_get_peers_msg(transId, &(mOwnId), info_hash, msg, avail-1);
|
||||
@ -968,7 +970,7 @@ void bdNode::msgout_reply_hash(bdId *id, bdToken *transId, bdToken *token, std::
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_HASH);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_HASH, NULL);
|
||||
|
||||
int blen = bitdht_peers_reply_hash_msg(transId, &(mOwnId), token, values, msg, avail-1);
|
||||
|
||||
@ -1001,7 +1003,7 @@ void bdNode::msgout_reply_nearest(bdId *id, bdToken *transId, bdToken *token, st
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NEAR);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_NEAR, NULL);
|
||||
|
||||
|
||||
|
||||
@ -1031,7 +1033,7 @@ void bdNode::msgout_post_hash(bdId *id, bdToken *transId, bdNodeId *info_hash, u
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_POST_HASH);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_POST_HASH, info_hash);
|
||||
|
||||
|
||||
int blen = bitdht_announce_peers_msg(transId,&(mOwnId),info_hash,port,token,msg,avail-1);
|
||||
@ -1056,7 +1058,7 @@ void bdNode::msgout_reply_post(bdId *id, bdToken *transId)
|
||||
char msg[10240];
|
||||
int avail = 10240;
|
||||
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_POST);
|
||||
registerOutgoingMsg(id, transId, BITDHT_MSG_TYPE_REPLY_POST, NULL);
|
||||
|
||||
int blen = bitdht_reply_announce_msg(transId, &(mOwnId), msg, avail-1);
|
||||
|
||||
@ -1481,7 +1483,15 @@ void bdNode::recvPkt(char *msg, int len, struct sockaddr_in addr)
|
||||
/* Construct Source Id */
|
||||
bdId srcId(id, addr);
|
||||
|
||||
registerIncomingMsg(&srcId, &transId, beType);
|
||||
if (be_target)
|
||||
{
|
||||
registerIncomingMsg(&srcId, &transId, beType, &target_info_hash);
|
||||
}
|
||||
else
|
||||
{
|
||||
registerIncomingMsg(&srcId, &transId, beType, NULL);
|
||||
}
|
||||
|
||||
switch(beType)
|
||||
{
|
||||
case BITDHT_MSG_TYPE_PING: /* a: id, transId */
|
||||
@ -1681,6 +1691,22 @@ void bdNode::msgin_pong(bdId *id, bdToken *transId, bdToken *versionId)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
#ifdef USE_HISTORY
|
||||
std::string version;
|
||||
for(int i = 0; i < versionId->len; i++)
|
||||
{
|
||||
if (isalnum(versionId->data[i]))
|
||||
{
|
||||
version += versionId->data[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
version += 'X';
|
||||
}
|
||||
}
|
||||
mHistory.setPeerType(id, version);
|
||||
#endif
|
||||
|
||||
/* check two bytes */
|
||||
if ((versionId->len >= 2) && (mDhtVersion.size() >= 2) &&
|
||||
(versionId->data[0] == mDhtVersion[0]) && (versionId->data[1] == mDhtVersion[1]))
|
||||
@ -2014,7 +2040,7 @@ void bdNode::msgout_connect_genmsg(bdId *id, bdToken *transId, int msgtype, bdId
|
||||
break;
|
||||
}
|
||||
|
||||
registerOutgoingMsg(id, transId, msgtype);
|
||||
registerOutgoingMsg(id, transId, msgtype, NULL);
|
||||
|
||||
/* create string */
|
||||
char msg[10240];
|
||||
@ -2163,7 +2189,7 @@ int bdNode::queueQuery(bdId *id, bdNodeId *query, bdToken *transId, uint32_t que
|
||||
|
||||
/*************** Register Transaction Ids *************/
|
||||
|
||||
void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||
void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_MSG_CHECKS
|
||||
@ -2177,9 +2203,41 @@ void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||
#endif
|
||||
|
||||
#ifdef USE_HISTORY
|
||||
mHistory.addMsg(id, transId, msgType, false);
|
||||
|
||||
// splitting up - to see if we can isolate the crash causes.
|
||||
switch(msgType)
|
||||
{
|
||||
// disabled types (which appear to crash it!)
|
||||
case BITDHT_MSG_TYPE_PING:
|
||||
if (!id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((id->id.data[0] == 0)
|
||||
&& (id->id.data[1] == 0)
|
||||
&& (id->id.data[2] == 0)
|
||||
&& (id->id.data[3] == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case BITDHT_MSG_TYPE_UNKNOWN:
|
||||
case BITDHT_MSG_TYPE_PONG:
|
||||
case BITDHT_MSG_TYPE_FIND_NODE:
|
||||
case BITDHT_MSG_TYPE_REPLY_NODE:
|
||||
case BITDHT_MSG_TYPE_GET_HASH:
|
||||
case BITDHT_MSG_TYPE_REPLY_HASH:
|
||||
case BITDHT_MSG_TYPE_REPLY_NEAR:
|
||||
case BITDHT_MSG_TYPE_POST_HASH:
|
||||
case BITDHT_MSG_TYPE_REPLY_POST:
|
||||
break;
|
||||
}
|
||||
|
||||
// This line appears to cause crashes on OSX.
|
||||
mHistory.addMsg(id, transId, msgType, false, aboutId);
|
||||
#else
|
||||
(void) transId;
|
||||
(void) aboutId;
|
||||
#endif
|
||||
|
||||
|
||||
@ -2201,7 +2259,7 @@ void bdNode::registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||
|
||||
|
||||
|
||||
uint32_t bdNode::registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType)
|
||||
uint32_t bdNode::registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_MSG_CHECKS
|
||||
@ -2215,9 +2273,10 @@ uint32_t bdNode::registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgTyp
|
||||
#endif
|
||||
|
||||
#ifdef USE_HISTORY
|
||||
mHistory.addMsg(id, transId, msgType, true);
|
||||
mHistory.addMsg(id, transId, msgType, true, aboutId);
|
||||
#else
|
||||
(void) transId;
|
||||
(void) aboutId;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -218,8 +218,8 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
||||
|
||||
/* transId handling */
|
||||
void genNewTransId(bdToken *token);
|
||||
void registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType);
|
||||
uint32_t registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType);
|
||||
void registerOutgoingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId);
|
||||
uint32_t registerIncomingMsg(bdId *id, bdToken *transId, uint32_t msgType, bdNodeId *aboutId);
|
||||
|
||||
void cleanupTransIdRegister();
|
||||
|
||||
|
@ -37,8 +37,8 @@
|
||||
**/
|
||||
|
||||
#define EXPECTED_REPLY 10 // Speed up queries
|
||||
#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNumQueryNodes() * 30)
|
||||
#define MAX_QUERY_IDLE_PERIOD 900 // 15min.
|
||||
#define QUERY_IDLE_RETRY_PEER_PERIOD 600 // 10min = (mFns->bdNumQueryNodes() * 60)
|
||||
#define MAX_QUERY_IDLE_PERIOD 1200 // 20min.
|
||||
|
||||
|
||||
/************************************************************
|
||||
@ -980,6 +980,7 @@ int bdQuery::printQuery()
|
||||
fprintf(stderr, "Id: ");
|
||||
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
||||
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
||||
fprintf(stderr," Flags: %x", it->second.mPeerFlags);
|
||||
fprintf(stderr," Found: %ld ago", ts-it->second.mFoundTime);
|
||||
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
||||
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
||||
@ -992,35 +993,12 @@ int bdQuery::printQuery()
|
||||
fprintf(stderr, "Id: ");
|
||||
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
|
||||
fprintf(stderr, " Bucket: %d ", mFns->bdBucketDistance(&(it->first)));
|
||||
fprintf(stderr," Flags: %x", it->second.mPeerFlags);
|
||||
fprintf(stderr," Found: %ld ago", ts-it->second.mFoundTime);
|
||||
fprintf(stderr," LastSent: %ld ago", ts-it->second.mLastSendTime);
|
||||
fprintf(stderr," LastRecv: %ld ago", ts-it->second.mLastRecvTime);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
std::list<bdPeer>::iterator lit;
|
||||
fprintf(stderr, "\nProxies Flagged:\n");
|
||||
for(lit = mProxiesFlagged.begin(); lit != mProxiesFlagged.end(); lit++)
|
||||
{
|
||||
fprintf(stderr, "ProxyId: ");
|
||||
mFns->bdPrintId(std::cerr, &(lit->mPeerId));
|
||||
fprintf(stderr," Found: %ld ago", ts-lit->mFoundTime);
|
||||
fprintf(stderr," LastSent: %ld ago", ts-lit->mLastSendTime);
|
||||
fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nProxies Unknown:\n");
|
||||
for(lit = mProxiesUnknown.begin(); lit != mProxiesUnknown.end(); lit++)
|
||||
{
|
||||
fprintf(stderr, "ProxyId: ");
|
||||
mFns->bdPrintId(std::cerr, &(lit->mPeerId));
|
||||
fprintf(stderr," Found: %ld ago", ts-lit->mFoundTime);
|
||||
fprintf(stderr," LastSent: %ld ago", ts-lit->mLastSendTime);
|
||||
fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#else
|
||||
// shortened version.
|
||||
fprintf(stderr, "Closest Available Peer: ");
|
||||
@ -1049,6 +1027,7 @@ int bdQuery::printQuery()
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
#endif
|
||||
std::list<bdPeer>::iterator lit;
|
||||
fprintf(stderr, "Flagged Proxies:\n");
|
||||
for(lit = mProxiesFlagged.begin(); lit != mProxiesFlagged.end(); lit++)
|
||||
@ -1073,7 +1052,6 @@ int bdQuery::printQuery()
|
||||
fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ int bdStore::reloadFromStore()
|
||||
{
|
||||
addr.sin_port = htons(port);
|
||||
bdPeer peer;
|
||||
//bdZeroNodeId(&(peer.mPeerId.id));
|
||||
bdZeroNodeId(&(peer.mPeerId.id));
|
||||
peer.mPeerId.addr = addr;
|
||||
peer.mLastSendTime = 0;
|
||||
peer.mLastRecvTime = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user