Bitcoin Core  26.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
V1Transport Class Referencefinal

#include <net.h>

Inheritance diagram for V1Transport:
[legend]
Collaboration diagram for V1Transport:
[legend]

Public Member Functions

 V1Transport (const NodeId node_id) noexcept
 
bool ReceivedMessageComplete () const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
 Returns true if the current message is complete (so GetReceivedMessage can be called). More...
 
Info GetInfo () const noexcept override
 Retrieve information about this transport. More...
 
bool ReceivedBytes (Span< const uint8_t > &msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
 Feed wire bytes to the transport. More...
 
CNetMessage GetReceivedMessage (std::chrono::microseconds time, bool &reject_message) 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...
 
bool ShouldReconnectV1 () const noexcept override
 Whether upon disconnections, a reconnect with V1 is warranted. More...
 
- Public Member Functions inherited from Transport
virtual ~Transport ()
 

Private Member Functions

CHash256 hasher GUARDED_BY (m_recv_mutex)
 
uint256 data_hash GUARDED_BY (m_recv_mutex)
 
bool in_data GUARDED_BY (m_recv_mutex)
 
DataStream hdrbuf GUARDED_BY (m_recv_mutex)
 
CMessageHeader hdr GUARDED_BY (m_recv_mutex)
 
DataStream vRecv GUARDED_BY (m_recv_mutex)
 
unsigned int nHdrPos GUARDED_BY (m_recv_mutex)
 
unsigned int nDataPos GUARDED_BY (m_recv_mutex)
 
const uint256GetMessageHash () const EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
 
int readHeader (Span< const uint8_t > msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
 
int readData (Span< const uint8_t > msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
 
void Reset () EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
 
bool CompleteInternal () const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
 
std::vector< uint8_t > m_header_to_send GUARDED_BY (m_send_mutex)
 The header of the message currently being sent. More...
 
CSerializedNetMsg m_message_to_send GUARDED_BY (m_send_mutex)
 The data of the message currently being sent. More...
 
bool m_sending_header GUARDED_BY (m_send_mutex)
 Whether we're currently sending header bytes or message bytes. More...
 
size_t m_bytes_sent GUARDED_BY (m_send_mutex)
 How many bytes have been sent so far (from m_header_to_send, or from m_message_to_send.data). More...
 

Private Attributes

const MessageStartChars m_magic_bytes
 
const NodeId m_node_id
 
Mutex m_recv_mutex
 Lock for receive state. More...
 
Mutex m_send_mutex
 Lock for sending state. More...
 

Additional Inherited Members

- Public Types inherited from Transport
using BytesToSend = std::tuple< Span< const uint8_t >, bool, const std::string & >
 Return type for GetBytesToSend, consisting of: More...
 

Detailed Description

Definition at line 371 of file net.h.

Constructor & Destructor Documentation

◆ V1Transport()

V1Transport::V1Transport ( const NodeId  node_id)
explicitnoexcept

Definition at line 687 of file net.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ CompleteInternal()

bool V1Transport::CompleteInternal ( ) const
inlineprivatenoexcept

Definition at line 402 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBytesToSend()

Transport::BytesToSend V1Transport::GetBytesToSend ( bool  have_next_message) const
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.

Parameters
[in]have_next_messageIf 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:

  • Yes: the transport itself has more bytes to send later. For example, for V1Transport this happens during the sending of the header of a message, when there is a non-empty payload that follows.
  • No: the transport itself has no more bytes to send, but will have bytes to send if handed a message through SetMessageToSend. In V1Transport this happens when sending the payload of a message.
  • Blocked: the transport itself has no more bytes to send, and is also incapable of sending anything more at all now, if it were handed another message to send. This occurs in V2Transport before the handshake is complete, as the encryption ciphers are not set up for sending messages before that point.

The boolean 'more' is true for Yes, false for Blocked, and have_next_message controls what is returned for No.

Returns
a BytesToSend object. The to_send member returned acts as a stream which is only ever appended to. This means that with the exception of MarkBytesSent (which pops bytes off the front of later to_sends), operations on the transport can only append to what is being returned. Also note that m_type and to_send refer to data that is internal to the transport, and calling any non-const function on this object may invalidate them.

Implements Transport.

Definition at line 831 of file net.cpp.

Here is the call graph for this function:

◆ GetInfo()

Transport::Info V1Transport::GetInfo ( ) const
overridevirtualnoexcept

Retrieve information about this transport.

Implements Transport.

Definition at line 694 of file net.cpp.

Here is the caller graph for this function:

◆ GetMessageHash()

const uint256 & V1Transport::GetMessageHash ( ) const
private

Definition at line 758 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetReceivedMessage()

CNetMessage V1Transport::GetReceivedMessage ( std::chrono::microseconds  time,
bool &  reject_message 
)
overridevirtual

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 767 of file net.cpp.

Here is the call graph for this function:

◆ GetSendMemoryUsage()

size_t V1Transport::GetSendMemoryUsage ( ) const
overridevirtualnoexcept

Return the memory usage of this transport attributable to buffered data to send.

Implements Transport.

Definition at line 868 of file net.cpp.

Here is the caller graph for this function:

◆ GUARDED_BY() [1/12]

CHash256 hasher V1Transport::GUARDED_BY ( m_recv_mutex  )
mutableprivate

◆ GUARDED_BY() [2/12]

uint256 data_hash V1Transport::GUARDED_BY ( m_recv_mutex  )
mutableprivate

◆ GUARDED_BY() [3/12]

bool in_data V1Transport::GUARDED_BY ( m_recv_mutex  )
private

◆ GUARDED_BY() [4/12]

DataStream hdrbuf V1Transport::GUARDED_BY ( m_recv_mutex  )
inlineprivate

Definition at line 380 of file net.h.

◆ GUARDED_BY() [5/12]

CMessageHeader hdr V1Transport::GUARDED_BY ( m_recv_mutex  )
private

◆ GUARDED_BY() [6/12]

DataStream vRecv V1Transport::GUARDED_BY ( m_recv_mutex  )
inlineprivate

Definition at line 382 of file net.h.

◆ GUARDED_BY() [7/12]

unsigned int nHdrPos V1Transport::GUARDED_BY ( m_recv_mutex  )
private

◆ GUARDED_BY() [8/12]

unsigned int nDataPos V1Transport::GUARDED_BY ( m_recv_mutex  )
private

◆ GUARDED_BY() [9/12]

std::vector<uint8_t> m_header_to_send V1Transport::GUARDED_BY ( m_send_mutex  )
private

The header of the message currently being sent.

◆ GUARDED_BY() [10/12]

CSerializedNetMsg m_message_to_send V1Transport::GUARDED_BY ( m_send_mutex  )
private

The data of the message currently being sent.

◆ GUARDED_BY() [11/12]

bool m_sending_header V1Transport::GUARDED_BY ( m_send_mutex  )
inlineprivate

Whether we're currently sending header bytes or message bytes.

Definition at line 416 of file net.h.

◆ GUARDED_BY() [12/12]

size_t m_bytes_sent V1Transport::GUARDED_BY ( m_send_mutex  )
inlineprivate

How many bytes have been sent so far (from m_header_to_send, or from m_message_to_send.data).

Definition at line 418 of file net.h.

◆ MarkBytesSent()

void V1Transport::MarkBytesSent ( size_t  bytes_sent)
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 852 of file net.cpp.

Here is the call graph for this function:

◆ readData()

int V1Transport::readData ( Span< const uint8_t >  msg_bytes)
private

Definition at line 740 of file net.cpp.

Here is the call graph for this function:

◆ readHeader()

int V1Transport::readHeader ( Span< const uint8_t >  msg_bytes)
private

Definition at line 699 of file net.cpp.

Here is the call graph for this function:

◆ ReceivedBytes()

bool V1Transport::ReceivedBytes ( Span< const uint8_t > &  msg_bytes)
inlineoverridevirtual

Feed wire bytes to the transport.

Returns
false if some bytes were invalid, in which case the transport can't be used anymore.

Consumed bytes are chopped off the front of msg_bytes.

Implements Transport.

Definition at line 431 of file net.h.

Here is the caller graph for this function:

◆ ReceivedMessageComplete()

bool V1Transport::ReceivedMessageComplete ( ) const
inlineoverridevirtual

Returns true if the current message is complete (so GetReceivedMessage can be called).

Implements Transport.

Definition at line 423 of file net.h.

Here is the caller graph for this function:

◆ Reset()

void V1Transport::Reset ( )
inlineprivate

Definition at line 390 of file net.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMessageToSend()

bool V1Transport::SetMessageToSend ( CSerializedNetMsg msg)
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 806 of file net.cpp.

Here is the call graph for this function:

◆ ShouldReconnectV1()

bool V1Transport::ShouldReconnectV1 ( ) const
inlineoverridevirtualnoexcept

Whether upon disconnections, a reconnect with V1 is warranted.

Implements Transport.

Definition at line 450 of file net.h.

Member Data Documentation

◆ m_magic_bytes

const MessageStartChars V1Transport::m_magic_bytes
private

Definition at line 374 of file net.h.

◆ m_node_id

const NodeId V1Transport::m_node_id
private

Definition at line 375 of file net.h.

◆ m_recv_mutex

Mutex V1Transport::m_recv_mutex
mutableprivate

Lock for receive state.

Definition at line 376 of file net.h.

◆ m_send_mutex

Mutex V1Transport::m_send_mutex
mutableprivate

Lock for sending state.

Definition at line 410 of file net.h.


The documentation for this class was generated from the following files: