mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge bitcoin/bitcoin#28892: refactor: P2P transport without serialize version and type
fa79a881cerefactor: P2P transport without serialize version and type (MarcoFalke)fa9b5f4fe3refactor: NetMsg::Make() without nVersion (MarcoFalke)66669da4a5Remove unused Make() overload in netmessagemaker.h (MarcoFalke)fa0ed07941refactor: VectorWriter without nVersion (MarcoFalke) Pull request description: Now that the serialize framework ignores the serialize version and serialize type, everything related to it can be removed from the code. This is the first step, removing dead code from the P2P stack. A different pull will remove it from the wallet and other parts. ACKs for top commit: ajtowns: reACKfa79a881ceTree-SHA512: 785b413580d980f51f0d4f70ea5e0a99ce14cd12cb065393de2f5254891be94a14f4266110c8b87bd2dbc37467676655bce13bdb295ab139749fcd8b61bd5110
This commit is contained in:
31
src/net.cpp
31
src/net.cpp
@@ -683,8 +683,8 @@ bool CNode::ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete)
|
||||
return true;
|
||||
}
|
||||
|
||||
V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noexcept :
|
||||
m_magic_bytes{Params().MessageStart()}, m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn)
|
||||
V1Transport::V1Transport(const NodeId node_id) noexcept
|
||||
: m_magic_bytes{Params().MessageStart()}, m_node_id{node_id}
|
||||
{
|
||||
LOCK(m_recv_mutex);
|
||||
Reset();
|
||||
@@ -818,7 +818,7 @@ bool V1Transport::SetMessageToSend(CSerializedNetMsg& msg) noexcept
|
||||
|
||||
// serialize header
|
||||
m_header_to_send.clear();
|
||||
CVectorWriter{INIT_PROTO_VERSION, m_header_to_send, 0, hdr};
|
||||
VectorWriter{m_header_to_send, 0, hdr};
|
||||
|
||||
// update state
|
||||
m_message_to_send = std::move(msg);
|
||||
@@ -968,12 +968,12 @@ void V2Transport::StartSendingHandshake() noexcept
|
||||
// We cannot wipe m_send_garbage as it will still be used as AAD later in the handshake.
|
||||
}
|
||||
|
||||
V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept :
|
||||
m_cipher{key, ent32}, m_initiating{initiating}, m_nodeid{nodeid},
|
||||
m_v1_fallback{nodeid, type_in, version_in}, m_recv_type{type_in}, m_recv_version{version_in},
|
||||
m_recv_state{initiating ? RecvState::KEY : RecvState::KEY_MAYBE_V1},
|
||||
m_send_garbage{std::move(garbage)},
|
||||
m_send_state{initiating ? SendState::AWAITING_KEY : SendState::MAYBE_V1}
|
||||
V2Transport::V2Transport(NodeId nodeid, bool initiating, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept
|
||||
: m_cipher{key, ent32}, m_initiating{initiating}, m_nodeid{nodeid},
|
||||
m_v1_fallback{nodeid},
|
||||
m_recv_state{initiating ? RecvState::KEY : RecvState::KEY_MAYBE_V1},
|
||||
m_send_garbage{std::move(garbage)},
|
||||
m_send_state{initiating ? SendState::AWAITING_KEY : SendState::MAYBE_V1}
|
||||
{
|
||||
Assume(m_send_garbage.size() <= MAX_GARBAGE_LEN);
|
||||
// Start sending immediately if we're the initiator of the connection.
|
||||
@@ -983,9 +983,9 @@ V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int versio
|
||||
}
|
||||
}
|
||||
|
||||
V2Transport::V2Transport(NodeId nodeid, bool initiating, int type_in, int version_in) noexcept :
|
||||
V2Transport{nodeid, initiating, type_in, version_in, GenerateRandomKey(),
|
||||
MakeByteSpan(GetRandHash()), GenerateRandomGarbage()} { }
|
||||
V2Transport::V2Transport(NodeId nodeid, bool initiating) noexcept
|
||||
: V2Transport{nodeid, initiating, GenerateRandomKey(),
|
||||
MakeByteSpan(GetRandHash()), GenerateRandomGarbage()} {}
|
||||
|
||||
void V2Transport::SetReceiveState(RecvState recv_state) noexcept
|
||||
{
|
||||
@@ -1429,8 +1429,7 @@ CNetMessage V2Transport::GetReceivedMessage(std::chrono::microseconds time, bool
|
||||
Assume(m_recv_state == RecvState::APP_READY);
|
||||
Span<const uint8_t> contents{m_recv_decode_buffer};
|
||||
auto msg_type = GetMessageType(contents);
|
||||
CDataStream ret(m_recv_type, m_recv_version);
|
||||
CNetMessage msg{std::move(ret)};
|
||||
CNetMessage msg{DataStream{}};
|
||||
// Note that BIP324Cipher::EXPANSION also includes the length descriptor size.
|
||||
msg.m_raw_message_size = m_recv_decode_buffer.size() + BIP324Cipher::EXPANSION;
|
||||
if (msg_type) {
|
||||
@@ -3660,9 +3659,9 @@ ServiceFlags CConnman::GetLocalServices() const
|
||||
static std::unique_ptr<Transport> MakeTransport(NodeId id, bool use_v2transport, bool inbound) noexcept
|
||||
{
|
||||
if (use_v2transport) {
|
||||
return std::make_unique<V2Transport>(id, /*initiating=*/!inbound, SER_NETWORK, INIT_PROTO_VERSION);
|
||||
return std::make_unique<V2Transport>(id, /*initiating=*/!inbound);
|
||||
} else {
|
||||
return std::make_unique<V1Transport>(id, SER_NETWORK, INIT_PROTO_VERSION);
|
||||
return std::make_unique<V1Transport>(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user