dash/src/evo/mnauth.h
Kittywhiskers Van Gogh 0f9ece0ed9
merge bitcoin#25514: Move CNode::nServices and CNode::nLocalServices to Peer
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2024-08-09 17:34:41 +07:00

72 lines
2.6 KiB
C++

// Copyright (c) 2019-2023 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_EVO_MNAUTH_H
#define BITCOIN_EVO_MNAUTH_H
#include <bls/bls.h>
#include <net_types.h>
#include <serialize.h>
class CActiveMasternodeManager;
class CBlockIndex;
class CChain;
class CConnman;
class CDataStream;
class CDeterministicMN;
class CDeterministicMNList;
class CDeterministicMNListDiff;
class CDeterministicMNManager;
class CMasternodeMetaMan;
class CMasternodeSync;
class CNode;
class UniValue;
enum ServiceFlags : uint64_t;
/**
* This class handles the p2p message MNAUTH. MNAUTH is sent directly after VERACK and authenticates the sender as a
* masternode. It is only sent when the sender is actually a masternode.
*
* MNAUTH signs a challenge that was previously sent via VERSION. The challenge is signed differently depending on
* the connection being an inbound or outbound connection, which avoids MITM of this form:
* node1 <- Eve -> node2
* while still allowing:
* node1 -> Eve -> node2
*
* This is fine as we only use this mechanism for DoS protection. It allows us to keep masternode connections open for
* a very long time without evicting the connections when inbound connection limits are hit (non-MNs will then be evicted).
*
* If we ever want to add transfer of sensitive data, THIS AUTHENTICATION MECHANISM IS NOT ENOUGH!! We'd need to implement
* proper encryption for these connections first.
*/
class CMNAuth
{
public:
uint256 proRegTxHash;
CBLSSignature sig;
SERIALIZE_METHODS(CMNAuth, obj)
{
READWRITE(obj.proRegTxHash, obj.sig);
}
static void PushMNAUTH(CNode& peer, CConnman& connman, const CActiveMasternodeManager& mn_activeman,
const CBlockIndex* tip);
/**
* @pre CMasternodeMetaMan's database must be successfully loaded before
* attempting to call this function regardless of sync state
*/
static PeerMsgRet ProcessMessage(CNode& peer, ServiceFlags node_services, CConnman& connman, CMasternodeMetaMan& mn_metaman, const CActiveMasternodeManager* const mn_activeman,
const CChain& active_chain, const CMasternodeSync& mn_sync, const CDeterministicMNList& tip_mn_list,
std::string_view msg_type, CDataStream& vRecv);
static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman);
};
#endif // BITCOIN_EVO_MNAUTH_H