![]() |
Bitcoin Core
25.99.0
P2P Digital Currency
|
#include <net.h>
Public Member Functions | |
V2Transport (NodeId nodeid, bool initiating, int type_in, int version_in) noexcept | |
Construct a V2 transport with securely generated random keys. More... | |
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 | |
Construct a V2 transport with specified keys and garbage (test use only). More... | |
bool | ReceivedMessageComplete () const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) |
Returns true if the current message is complete (so GetReceivedMessage can be called). More... | |
bool | ReceivedBytes (Span< const uint8_t > &msg_bytes) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex |
Feed wire bytes to the transport. More... | |
CNetMessage | GetReceivedMessage (std::chrono::microseconds time, bool &reject_message) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex) |
Retrieve a completed message from transport. More... | |
bool | SetMessageToSend (CSerializedNetMsg &msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) |
Set the next message to send. More... | |
BytesToSend | GetBytesToSend (bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) |
Get bytes to send on the wire, if any, along with other information about it. More... | |
void | MarkBytesSent (size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) |
Report how many bytes returned by the last GetBytesToSend() have been sent. More... | |
size_t | GetSendMemoryUsage () const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) |
Return the memory usage of this transport attributable to buffered data to send. More... | |
![]() | |
virtual | ~Transport () |
Static Public Attributes | |
static constexpr uint32_t | MAX_GARBAGE_LEN = 4095 |
Private Types | |
enum class | RecvState : uint8_t { KEY_MAYBE_V1 , KEY , GARB_GARBTERM , VERSION , APP , APP_READY , V1 } |
State type that defines the current contents of the receive buffer and/or how the next received bytes added to it will be interpreted. More... | |
enum class | SendState : uint8_t { MAYBE_V1 , AWAITING_KEY , READY , V1 } |
State type that controls the sender side. More... | |
Private Member Functions | |
Mutex m_recv_mutex | ACQUIRED_BEFORE (m_send_mutex) |
Lock for receiver-side fields. More... | |
uint32_t m_recv_len | GUARDED_BY (m_recv_mutex) |
In {VERSION, APP}, the decrypted packet length, if m_recv_buffer.size() >= BIP324Cipher::LENGTH_LEN. More... | |
std::vector< uint8_t > m_recv_buffer | GUARDED_BY (m_recv_mutex) |
Receive buffer; meaning is determined by m_recv_state. More... | |
std::vector< uint8_t > m_recv_aad | GUARDED_BY (m_recv_mutex) |
AAD expected in next received packet (currently used only for garbage). More... | |
std::vector< uint8_t > m_recv_decode_buffer | GUARDED_BY (m_recv_mutex) |
Buffer to put decrypted contents in, for converting to CNetMessage. More... | |
RecvState m_recv_state | GUARDED_BY (m_recv_mutex) |
Current receiver state. More... | |
Mutex m_send_mutex | ACQUIRED_AFTER (m_recv_mutex) |
Lock for sending-side fields. More... | |
std::vector< uint8_t > m_send_buffer | GUARDED_BY (m_send_mutex) |
The send buffer; meaning is determined by m_send_state. More... | |
uint32_t m_send_pos | GUARDED_BY (m_send_mutex) |
How many bytes from the send buffer have been sent so far. More... | |
std::vector< uint8_t > m_send_garbage | GUARDED_BY (m_send_mutex) |
The garbage sent, or to be sent (MAYBE_V1 and AWAITING_KEY state only). More... | |
std::string m_send_type | GUARDED_BY (m_send_mutex) |
Type of the message being sent. More... | |
SendState m_send_state | GUARDED_BY (m_send_mutex) |
Current sender state. More... | |
void | SetReceiveState (RecvState recv_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) |
Change the receive state. More... | |
void | SetSendState (SendState send_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex) |
Change the send state. More... | |
size_t | GetMaxBytesToProcess () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) |
Determine how many received bytes can be processed in one go (not allowed in V1 state). More... | |
void | StartSendingHandshake () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex) |
Put our public key + garbage in the send buffer. More... | |
void | ProcessReceivedMaybeV1Bytes () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex |
Process bytes in m_recv_buffer, while in KEY_MAYBE_V1 state. More... | |
bool | ProcessReceivedKeyBytes () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex |
Process bytes in m_recv_buffer, while in KEY state. More... | |
bool | ProcessReceivedGarbageBytes () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) |
Process bytes in m_recv_buffer, while in GARB_GARBTERM state. More... | |
bool | ProcessReceivedPacketBytes () noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) |
Process bytes in m_recv_buffer, while in VERSION/APP state. More... | |
Static Private Member Functions | |
static std::optional< std::string > | GetMessageType (Span< const uint8_t > &contents) noexcept |
Given a packet's contents, find the message type (if valid), and strip it from contents. More... | |
Private Attributes | |
BIP324Cipher | m_cipher |
Cipher state. More... | |
const bool | m_initiating |
Whether we are the initiator side. More... | |
const NodeId | m_nodeid |
NodeId (for debug logging). More... | |
V1Transport | m_v1_fallback |
Encapsulate a V1Transport to fall back to. More... | |
const int | m_recv_type |
Deserialization type. More... | |
const int | m_recv_version |
Deserialization version number. More... | |
void | !m_send_mutex |
bool | !m_send_mutex |
Static Private Attributes | |
static constexpr std::array< std::byte, 0 > | VERSION_CONTENTS = {} |
Contents of the version packet to send. More... | |
static constexpr size_t | V1_PREFIX_LEN = 12 |
The length of the V1 prefix to match bytes initially received by responders with to determine if their peer is speaking V1 or V2. More... | |
Additional Inherited Members | |
![]() | |
using | BytesToSend = std::tuple< Span< const uint8_t >, bool, const std::string & > |
Return type for GetBytesToSend, consisting of: More... | |
|
strongprivate |
State type that defines the current contents of the receive buffer and/or how the next received bytes added to it will be interpreted.
Diagram:
start(responder) | | start(initiator) /------—\ | | | | v v v | KEY_MAYBE_V1 -> KEY -> GARB_GARBTERM -> VERSION -> APP -> APP_READY | ----—> V1
|
strongprivate |
State type that controls the sender side.
Diagram:
start(responder) | | start(initiator) | | v v MAYBE_V1 -> AWAITING_KEY -> READY | -----> V1
|
noexcept |
Construct a V2 transport with securely generated random keys.
[in] | nodeid | the node's NodeId (only for debug log output). |
[in] | initiating | whether we are the initiator side. |
[in] | type_in | the serialization type of returned CNetMessages. |
[in] | version_in | the serialization version of returned CNetMessages. |
Definition at line 1023 of file net.cpp.
|
mutableprivate |
Lock for sending-side fields.
If both sending and receiving fields are accessed, m_recv_mutex must be acquired before m_send_mutex.
|
mutableprivate |
Lock for receiver-side fields.
|
overridevirtualnoexcept |
Get bytes to send on the wire, if any, along with other information about it.
As a const function, it does not modify the transport's observable state, and is thus safe to be called multiple times.
[in] | have_next_message | If true, the "more" return value reports whether more will be sendable after a SetMessageToSend call. It is set by the caller when they know they have another message ready to send, and only care about what happens after that. The have_next_message argument only affects this "more" return value and nothing else. |
Effectively, there are three possible outcomes about whether there are more bytes to send:
The boolean 'more' is true for Yes, false for Blocked, and have_next_message controls what is returned for No.
Implements Transport.
Definition at line 1522 of file net.cpp.
|
privatenoexcept |
|
staticprivatenoexcept |
|
overridevirtualnoexcept |
Retrieve a completed message from transport.
This can only be called when ReceivedMessageComplete() is true.
If reject_message=true is returned the message itself is invalid, but (other than false returned by ReceivedBytes) the transport is not in an inconsistent state.
Implements Transport.
Definition at line 1460 of file net.cpp.
|
overridevirtualnoexcept |
|
inlineprivate |
In {VERSION, APP}, the decrypted packet length, if m_recv_buffer.size() >= BIP324Cipher::LENGTH_LEN.
Unspecified otherwise.
|
private |
Receive buffer; meaning is determined by m_recv_state.
|
private |
AAD expected in next received packet (currently used only for garbage).
|
private |
Buffer to put decrypted contents in, for converting to CNetMessage.
|
private |
Current receiver state.
|
private |
The send buffer; meaning is determined by m_send_state.
|
inlineprivate |
|
private |
The garbage sent, or to be sent (MAYBE_V1 and AWAITING_KEY state only).
|
private |
Type of the message being sent.
|
private |
Current sender state.
|
overridevirtualnoexcept |
Report how many bytes returned by the last GetBytesToSend() have been sent.
bytes_sent cannot exceed to_send.size() of the last GetBytesToSend() result.
If bytes_sent=0, this call has no effect.
Implements Transport.
Definition at line 1539 of file net.cpp.
|
privatenoexcept |
|
privatenoexcept |
|
privatenoexcept |
|
privatenoexcept |
|
overridevirtualnoexcept |
Feed wire bytes to the transport.
Consumed bytes are chopped off the front of msg_bytes.
How many bytes to allocate in the receive buffer at most above what is received so far.
Implements Transport.
Definition at line 1330 of file net.cpp.
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Set the next message to send.
If no message can currently be set (perhaps because the previous one is not yet done being sent), returns false, and msg will be unmodified. Otherwise msg is enqueued (and possibly moved-from) and true is returned.
Implements Transport.
Definition at line 1490 of file net.cpp.
|
privatenoexcept |
|
privatenoexcept |
|
privatenoexcept |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Encapsulate a V1Transport to fall back to.
|
staticconstexpr |
|
staticconstexprprivate |
|
staticconstexprprivate |