2010-09-29 15:59:31 -04:00
|
|
|
#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 ****/
|
|
|
|
|
2012-10-25 18:36:22 -04:00
|
|
|
class MsgRegister
|
2010-09-29 15:59:31 -04:00
|
|
|
{
|
|
|
|
public:
|
2012-10-25 18:36:22 -04:00
|
|
|
MsgRegister() { return; }
|
|
|
|
MsgRegister(const bdId *inId, uint32_t inMsgType, bool inIncoming)
|
|
|
|
:id(*inId), msgType(inMsgType), incoming(inIncoming) { return; }
|
|
|
|
|
|
|
|
bdId id;
|
|
|
|
uint32_t msgType;
|
|
|
|
bool incoming;
|
|
|
|
};
|
2010-09-29 15:59:31 -04:00
|
|
|
|
2012-10-25 18:36:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
class bdMsgHistoryList
|
|
|
|
{
|
|
|
|
public:
|
2010-09-29 15:59:31 -04:00
|
|
|
void addMsg(time_t ts, uint32_t msgType, bool incoming);
|
|
|
|
int msgCount(time_t start_ts, time_t end_ts);
|
2012-10-25 18:36:22 -04:00
|
|
|
bool msgClear(time_t before); // 0 => clear all.
|
2010-09-29 15:59:31 -04:00
|
|
|
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:
|
2012-10-25 18:36:22 -04:00
|
|
|
bdHistory(time_t store_period);
|
|
|
|
|
2010-09-29 15:59:31 -04:00
|
|
|
void addMsg(const bdId *id, bdToken *transId, uint32_t msgType, bool incoming);
|
|
|
|
void printMsgs();
|
2012-10-25 18:36:22 -04:00
|
|
|
|
|
|
|
void cleanupOldMsgs();
|
2010-09-29 15:59:31 -04:00
|
|
|
void clearHistory();
|
|
|
|
|
|
|
|
bool canSend(const bdId *id);
|
|
|
|
bool validPeer(const bdId *id);
|
|
|
|
|
|
|
|
/* recent history */
|
|
|
|
//std::list<bdId> lastMsgs;
|
|
|
|
std::map<bdId, bdMsgHistoryList> mHistory;
|
2012-10-25 18:36:22 -04:00
|
|
|
std::multimap<time_t, MsgRegister> mMsgTimeline;
|
|
|
|
|
|
|
|
int mStorePeriod;
|
2010-09-29 15:59:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|