2010-09-29 15:59:31 -04:00
|
|
|
#ifndef BITDHT_HISTORY_H
|
|
|
|
#define BITDHT_HISTORY_H
|
|
|
|
|
|
|
|
#include "bitdht/bdpeer.h"
|
|
|
|
#include "bitdht/bdobj.h"
|
2013-08-26 00:29:27 -04:00
|
|
|
#include "bitdht/bdstddht.h"
|
2010-09-29 15:59:31 -04:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#define MSG_TYPE_DIRECTION_MASK 0x000f0000
|
|
|
|
|
|
|
|
#define MSG_DIRECTION_INCOMING 0x00010000
|
|
|
|
#define MSG_DIRECTION_OUTGOING 0x00020000
|
|
|
|
|
|
|
|
/**** DEBUGGING HISTORY ****/
|
|
|
|
|
2012-10-25 18:36:22 -04:00
|
|
|
class MsgRegister
|
2013-08-26 00:29:27 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
MsgRegister() { 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
|
2010-09-29 15:59:31 -04:00
|
|
|
{
|
|
|
|
public:
|
2013-08-26 00:29:27 -04:00
|
|
|
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;
|
|
|
|
}
|
2012-10-25 18:36:22 -04:00
|
|
|
|
|
|
|
uint32_t msgType;
|
|
|
|
bool incoming;
|
2013-08-26 00:29:27 -04:00
|
|
|
bdNodeId aboutId; // filled in for queries.
|
2012-10-25 18:36:22 -04:00
|
|
|
};
|
2010-09-29 15:59:31 -04:00
|
|
|
|
2012-10-25 18:36:22 -04:00
|
|
|
|
|
|
|
class bdMsgHistoryList
|
|
|
|
{
|
|
|
|
public:
|
2013-08-26 00:29:27 -04:00
|
|
|
bdMsgHistoryList();
|
|
|
|
void addMsg(time_t ts, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
|
|
|
void setPeerType(time_t ts, std::string version);
|
2010-09-29 15:59:31 -04:00
|
|
|
int msgCount(time_t start_ts, time_t end_ts);
|
2013-08-26 00:29:27 -04:00
|
|
|
bool msgClear(time_t before); // 0 => clear all.
|
|
|
|
void msgClear();
|
2010-09-29 15:59:31 -04:00
|
|
|
void printHistory(std::ostream &out, int mode, time_t start_ts, time_t end_ts);
|
2013-08-26 00:29:27 -04:00
|
|
|
bool analysePeer();
|
|
|
|
void clearHistory();
|
2010-09-29 15:59:31 -04:00
|
|
|
|
|
|
|
bool canSend();
|
|
|
|
bool validPeer();
|
|
|
|
|
2013-08-26 00:29:27 -04:00
|
|
|
std::multimap<time_t, bdMsgHistoryItem> msgHistory;
|
|
|
|
std::string mPeerVersion;
|
|
|
|
bdId mId;
|
2010-09-29 15:59:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class bdHistory
|
|
|
|
{
|
|
|
|
public:
|
2013-08-26 00:29:27 -04:00
|
|
|
bdHistory(time_t store_period);
|
2012-10-25 18:36:22 -04:00
|
|
|
|
2013-08-26 00:29:27 -04:00
|
|
|
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming, const bdNodeId *aboutId);
|
|
|
|
void setPeerType(const bdId *id, std::string version);
|
2010-09-29 15:59:31 -04:00
|
|
|
void printMsgs();
|
2012-10-25 18:36:22 -04:00
|
|
|
|
2013-08-26 00:29:27 -04:00
|
|
|
void cleanupOldMsgs();
|
2010-09-29 15:59:31 -04:00
|
|
|
void clearHistory();
|
2013-08-26 00:29:27 -04:00
|
|
|
bool analysePeers();
|
|
|
|
bool peerTypeAnalysis();
|
2010-09-29 15:59:31 -04:00
|
|
|
|
|
|
|
bool canSend(const bdId *id);
|
|
|
|
bool validPeer(const bdId *id);
|
|
|
|
|
|
|
|
/* recent history */
|
|
|
|
//std::list<bdId> lastMsgs;
|
|
|
|
std::map<bdId, bdMsgHistoryList> mHistory;
|
2013-08-26 00:29:27 -04:00
|
|
|
std::multimap<time_t, MsgRegister> mMsgTimeline;
|
2012-10-25 18:36:22 -04:00
|
|
|
|
|
|
|
int mStorePeriod;
|
2013-08-26 00:29:27 -04:00
|
|
|
|
2010-09-29 15:59:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|