Bitcoin Core  27.99.0
P2P Digital Currency
Classes | Public Types | Public Member Functions | List of all members
Transport Class Referenceabstract

The Transport converts one connection's sent messages to wire bytes, and received bytes back. More...

#include <net.h>

Inheritance diagram for Transport:
[legend]

Classes

struct  Info
 

Public Types

using BytesToSend = std::tuple< Span< const uint8_t >, bool, const std::string & >
 Return type for GetBytesToSend, consisting of: More...
 

Public Member Functions

virtual ~Transport ()=default
 
virtual Info GetInfo () const noexcept=0
 Retrieve information about this transport. More...
 
virtual bool ReceivedMessageComplete () const =0
 Returns true if the current message is complete (so GetReceivedMessage can be called). More...
 
virtual bool ReceivedBytes (Span< const uint8_t > &msg_bytes)=0
 Feed wire bytes to the transport. More...
 
virtual CNetMessage GetReceivedMessage (std::chrono::microseconds time, bool &reject_message)=0
 Retrieve a completed message from transport. More...
 
virtual bool SetMessageToSend (CSerializedNetMsg &msg) noexcept=0
 Set the next message to send. More...
 
virtual BytesToSend GetBytesToSend (bool have_next_message) const noexcept=0
 Get bytes to send on the wire, if any, along with other information about it. More...
 
virtual void MarkBytesSent (size_t bytes_sent) noexcept=0
 Report how many bytes returned by the last GetBytesToSend() have been sent. More...
 
virtual size_t GetSendMemoryUsage () const noexcept=0
 Return the memory usage of this transport attributable to buffered data to send. More...
 
virtual bool ShouldReconnectV1 () const noexcept=0
 Whether upon disconnections, a reconnect with V1 is warranted. More...
 

Detailed Description

The Transport converts one connection's sent messages to wire bytes, and received bytes back.

Definition at line 251 of file net.h.

Member Typedef Documentation

◆ BytesToSend

using Transport::BytesToSend = std::tuple< Span<const uint8_t> , bool , const std::string& >

Return type for GetBytesToSend, consisting of:

  • Span<const uint8_t> to_send: span of bytes to be sent over the wire (possibly empty).
  • bool more: whether there will be more bytes to be sent after the ones in to_send are all sent (as signaled by MarkBytesSent()).
  • const std::string& m_type: message type on behalf of which this is being sent ("" for bytes that are not on behalf of any message).

Definition at line 304 of file net.h.

Constructor & Destructor Documentation

◆ ~Transport()

virtual Transport::~Transport ( )
virtualdefault

Member Function Documentation

◆ GetBytesToSend()

virtual BytesToSend Transport::GetBytesToSend ( bool  have_next_message) const
pure virtualnoexcept

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.

Implemented in V2Transport, and V1Transport.

◆ GetInfo()

virtual Info Transport::GetInfo ( ) const
pure virtualnoexcept

Retrieve information about this transport.

Implemented in V2Transport, and V1Transport.

◆ GetReceivedMessage()

virtual CNetMessage Transport::GetReceivedMessage ( std::chrono::microseconds  time,
bool &  reject_message 
)
pure virtual

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.

Implemented in V1Transport, and V2Transport.

◆ GetSendMemoryUsage()

virtual size_t Transport::GetSendMemoryUsage ( ) const
pure virtualnoexcept

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

Implemented in V2Transport, and V1Transport.

◆ MarkBytesSent()

virtual void Transport::MarkBytesSent ( size_t  bytes_sent)
pure virtualnoexcept

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.

Implemented in V2Transport, and V1Transport.

◆ ReceivedBytes()

virtual bool Transport::ReceivedBytes ( Span< const uint8_t > &  msg_bytes)
pure virtual

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.

Implemented in V1Transport, and V2Transport.

◆ ReceivedMessageComplete()

virtual bool Transport::ReceivedMessageComplete ( ) const
pure virtual

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

Implemented in V1Transport, and V2Transport.

◆ SetMessageToSend()

virtual bool Transport::SetMessageToSend ( CSerializedNetMsg msg)
pure virtualnoexcept

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.

Implemented in V2Transport, and V1Transport.

◆ ShouldReconnectV1()

virtual bool Transport::ShouldReconnectV1 ( ) const
pure virtualnoexcept

Whether upon disconnections, a reconnect with V1 is warranted.

Implemented in V2Transport, and V1Transport.


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