2016-04-16 01:13:15 -03:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2020-12-31 05:48:25 -03:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2016-04-16 01:13:15 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_ADDRDB_H
|
|
|
|
#define BITCOIN_ADDRDB_H
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <fs.h>
|
2019-10-29 05:49:48 -03:00
|
|
|
#include <net_types.h> // For banmap_t
|
2021-01-14 05:33:04 -03:00
|
|
|
#include <univalue.h>
|
2016-04-16 01:13:15 -03:00
|
|
|
|
2020-09-12 11:59:09 -03:00
|
|
|
#include <vector>
|
2016-04-16 01:13:15 -03:00
|
|
|
|
2020-09-12 11:59:09 -03:00
|
|
|
class CAddress;
|
2016-04-16 01:13:15 -03:00
|
|
|
class CAddrMan;
|
2016-04-16 15:47:18 -03:00
|
|
|
class CDataStream;
|
2016-04-16 01:13:15 -03:00
|
|
|
|
|
|
|
/** Access to the (IP) address database (peers.dat) */
|
|
|
|
class CAddrDB
|
|
|
|
{
|
|
|
|
private:
|
2017-03-01 13:05:50 -03:00
|
|
|
fs::path pathAddr;
|
2016-04-16 01:13:15 -03:00
|
|
|
public:
|
|
|
|
CAddrDB();
|
|
|
|
bool Write(const CAddrMan& addr);
|
|
|
|
bool Read(CAddrMan& addr);
|
2017-04-21 08:50:55 -03:00
|
|
|
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
2016-04-16 01:13:15 -03:00
|
|
|
};
|
|
|
|
|
2021-07-28 14:00:23 -04:00
|
|
|
/** Access to the banlist database (banlist.json) */
|
2016-04-16 01:13:15 -03:00
|
|
|
class CBanDB
|
|
|
|
{
|
|
|
|
private:
|
2021-01-14 05:33:04 -03:00
|
|
|
/**
|
|
|
|
* JSON key under which the data is stored in the json database.
|
|
|
|
*/
|
|
|
|
static constexpr const char* JSON_KEY = "banned_nets";
|
|
|
|
|
|
|
|
const fs::path m_banlist_dat;
|
|
|
|
const fs::path m_banlist_json;
|
2016-04-16 01:13:15 -03:00
|
|
|
public:
|
2017-10-05 14:35:20 -03:00
|
|
|
explicit CBanDB(fs::path ban_list_path);
|
2016-04-16 01:13:15 -03:00
|
|
|
bool Write(const banmap_t& banSet);
|
2021-01-14 05:33:04 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the banlist from disk.
|
|
|
|
* @param[out] banSet The loaded list. Set if `true` is returned, otherwise it is left
|
|
|
|
* in an undefined state.
|
|
|
|
* @return true on success
|
|
|
|
*/
|
2021-07-28 14:00:23 -04:00
|
|
|
bool Read(banmap_t& banSet);
|
2016-04-16 01:13:15 -03:00
|
|
|
};
|
|
|
|
|
2020-09-12 11:59:09 -03:00
|
|
|
/**
|
|
|
|
* Dump the anchor IP address database (anchors.dat)
|
|
|
|
*
|
|
|
|
* Anchors are last known outgoing block-relay-only peers that are
|
|
|
|
* tried to re-connect to on startup.
|
|
|
|
*/
|
|
|
|
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors);
|
|
|
|
|
2020-09-12 12:01:19 -03:00
|
|
|
/**
|
|
|
|
* Read the anchor IP address database (anchors.dat)
|
|
|
|
*
|
|
|
|
* Deleting anchors.dat is intentional as it avoids renewed peering to anchors after
|
|
|
|
* an unclean shutdown and thus potential exploitation of the anchor peer policy.
|
|
|
|
*/
|
|
|
|
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path);
|
|
|
|
|
2016-04-16 01:13:15 -03:00
|
|
|
#endif // BITCOIN_ADDRDB_H
|