mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
a9d771e497
* net: move CBanDB and CAddrDB out of net.h/cpp This will eventually solve a circular dependency * net: Create CConnman to encapsulate p2p connections * net: Move socket binding into CConnman * net: move OpenNetworkConnection into CConnman * net: move ban and addrman functions into CConnman * net: Add oneshot functions to CConnman * net: move added node functions to CConnman * net: Add most functions needed for vNodes to CConnman * net: handle nodesignals in CConnman * net: Pass CConnection to wallet rather than using the global * net: Add rpc error for missing/disabled p2p functionality * net: Pass CConnman around as needed * gui: add NodeID to the peer table * net: create generic functor accessors and move vNodes to CConnman * net: move whitelist functions into CConnman * net: move nLastNodeId to CConnman * net: move nLocalHostNonce to CConnman This behavior seems to have been quite racy and broken. Move nLocalHostNonce into CNode, and check received nonces against all non-fully-connected nodes. If there's a match, assume we've connected to ourself. * net: move messageHandlerCondition to CConnman * net: move send/recv statistics to CConnman * net: move SendBufferSize/ReceiveFloodSize to CConnman * net: move nLocalServices/nRelevantServices to CConnman These are in-turn passed to CNode at connection time. This allows us to offer different services to different peers (or test the effects of doing so). * net: move semOutbound and semMasternodeOutbound to CConnman * net: SocketSendData returns written size * net: move max/max-outbound to CConnman * net: Pass best block known height into CConnman CConnman then passes the current best height into CNode at creation time. This way CConnman/CNode have no dependency on main for height, and the signals only move in one direction. This also helps to prevent identity leakage a tiny bit. Before this change, an attacker could theoretically make 2 connections on different interfaces. They would connect fully on one, and only establish the initial connection on the other. Once they receive a new block, they would relay it to your first connection, and immediately commence the version handshake on the second. Since the new block height is reflected immediately, they could attempt to learn whether the two connections were correlated. This is, of course, incredibly unlikely to work due to the small timings involved and receipt from other senders. But it doesn't hurt to lock-in nBestHeight at the time of connection, rather than letting the remote choose the time. * net: pass CClientUIInterface into CConnman * net: Drop StartNode/StopNode and use CConnman directly * net: Introduce CConnection::Options to avoid passing so many params * net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options * net: move vNodesDisconnected into CConnman * Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting * Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead * net: move MAX_FEELER_CONNECTIONS into connman
104 lines
2.2 KiB
C++
104 lines
2.2 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// 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
|
|
|
|
#include "serialize.h"
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
class CSubNet;
|
|
class CAddrMan;
|
|
class CDataStream;
|
|
|
|
typedef enum BanReason
|
|
{
|
|
BanReasonUnknown = 0,
|
|
BanReasonNodeMisbehaving = 1,
|
|
BanReasonManuallyAdded = 2
|
|
} BanReason;
|
|
|
|
class CBanEntry
|
|
{
|
|
public:
|
|
static const int CURRENT_VERSION=1;
|
|
int nVersion;
|
|
int64_t nCreateTime;
|
|
int64_t nBanUntil;
|
|
uint8_t banReason;
|
|
|
|
CBanEntry()
|
|
{
|
|
SetNull();
|
|
}
|
|
|
|
CBanEntry(int64_t nCreateTimeIn)
|
|
{
|
|
SetNull();
|
|
nCreateTime = nCreateTimeIn;
|
|
}
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
template <typename Stream, typename Operation>
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
READWRITE(this->nVersion);
|
|
nVersion = this->nVersion;
|
|
READWRITE(nCreateTime);
|
|
READWRITE(nBanUntil);
|
|
READWRITE(banReason);
|
|
}
|
|
|
|
void SetNull()
|
|
{
|
|
nVersion = CBanEntry::CURRENT_VERSION;
|
|
nCreateTime = 0;
|
|
nBanUntil = 0;
|
|
banReason = BanReasonUnknown;
|
|
}
|
|
|
|
std::string banReasonToString()
|
|
{
|
|
switch (banReason) {
|
|
case BanReasonNodeMisbehaving:
|
|
return "node misbehaving";
|
|
case BanReasonManuallyAdded:
|
|
return "manually added";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|
|
};
|
|
|
|
typedef std::map<CSubNet, CBanEntry> banmap_t;
|
|
|
|
/** Access to the (IP) address database (peers.dat) */
|
|
class CAddrDB
|
|
{
|
|
private:
|
|
boost::filesystem::path pathAddr;
|
|
public:
|
|
CAddrDB();
|
|
bool Write(const CAddrMan& addr);
|
|
bool Read(CAddrMan& addr);
|
|
bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
|
};
|
|
|
|
/** Access to the banlist database (banlist.dat) */
|
|
class CBanDB
|
|
{
|
|
private:
|
|
boost::filesystem::path pathBanlist;
|
|
public:
|
|
CBanDB();
|
|
bool Write(const banmap_t& banSet);
|
|
bool Read(banmap_t& banSet);
|
|
};
|
|
|
|
#endif // BITCOIN_ADDRDB_H
|