seeder/db.h

53 lines
1.3 KiB
C
Raw Normal View History

2011-12-16 18:37:05 +01:00
#include <stdint.h>
#include <pair>
#include <set>
#include <map>
#include <vector>
#include <deque>
#include "netbase.h"
#include "protocol.h"
#include "util.h"
class CAddrInfo {
private:
CIP ip;
uint64_t services;
uint32_t lastTry;
uint32_t ourLastTry;
double reliabity;
double weight;
}
2011-12-16 18:51:45 +01:00
// seen nodes
// / \
// (a) banned nodes tracked nodes
// / \
// tried nodes (b) unknown nodes
// / \
// (d) good nodes (c) non-good nodes
2011-12-16 18:37:05 +01:00
class CAddrDb {
private:
CCriticalSection cs;
int nId; // number of address id's
2011-12-16 18:51:45 +01:00
map<int, CAddrInfo> idToInfo; // map address id to address info (b,c,d)
map<CIP, int> ipToId; // map ip to id (b,c,d)
deque<int> ourId; // sequence of tried nodes, in order we have tried connecting to them (c,d)
set<int> unkId; // set of nodes not yet tried (b)
set<int> goodId; // set of good nodes (d)
map<CIP, pair<uint32_t, uint32_t> > banned; // nodes that are banned, with their from/to ban time (a)
2011-12-16 18:37:05 +01:00
public:
void Add(const CAddress &addr);
void Add(const vector<CAddress> &vAddr);
void Good(const CIP &addr);
void Bad(const CIP &addr, int fail);
CIP Get();
}
extern "C" {
int GetIPv4Address(struct in_addr *addr, int max);
}