BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
graphene::net::peer_connection Class Reference

#include <peer_connection.hpp>

Inheritance diagram for graphene::net::peer_connection:
graphene::net::message_oriented_connection_delegate

Classes

struct  timestamp_index
 
struct  timestamped_item_id
 

Public Types

enum  our_connection_state { our_connection_state::disconnected, our_connection_state::just_connected, our_connection_state::connection_accepted, our_connection_state::connection_rejected }
 
enum  their_connection_state { their_connection_state::disconnected, their_connection_state::just_connected, their_connection_state::connection_accepted, their_connection_state::connection_rejected }
 
enum  connection_negotiation_status {
  connection_negotiation_status::disconnected, connection_negotiation_status::connecting, connection_negotiation_status::connected, connection_negotiation_status::accepting,
  connection_negotiation_status::accepted, connection_negotiation_status::hello_sent, connection_negotiation_status::peer_connection_accepted, connection_negotiation_status::peer_connection_rejected,
  connection_negotiation_status::negotiation_complete, connection_negotiation_status::closing, connection_negotiation_status::closed
}
 
using item_to_time_map_type = std::unordered_map< item_id, fc::time_point >
 

Public Member Functions

fc::time_point get_connection_time () const
 
fc::time_point get_connection_terminated_time () const
 
virtual ~peer_connection ()
 
fc::tcp_socketget_socket ()
 
void accept_connection ()
 
void connect_to (const fc::ip::endpoint &remote_endpoint, const fc::optional< fc::ip::endpoint > &local_endpoint=fc::optional< fc::ip::endpoint >())
 
void on_message (message_oriented_connection *originating_connection, const message &received_message) override
 
void on_connection_closed (message_oriented_connection *originating_connection) override
 
void send_queueable_message (std::unique_ptr< queued_message > &&message_to_send)
 
virtual void send_message (const message &message_to_send, size_t message_send_time_field_offset=(size_t) -1)
 
void send_item (const item_id &item_to_send)
 
void close_connection ()
 
void destroy_connection ()
 
uint64_t get_total_bytes_sent () const
 
uint64_t get_total_bytes_received () const
 
fc::time_point get_last_message_sent_time () const
 
fc::time_point get_last_message_received_time () const
 
fc::optional< fc::ip::endpointget_remote_endpoint ()
 
fc::ip::endpoint get_local_endpoint ()
 
void set_remote_endpoint (fc::optional< fc::ip::endpoint > new_remote_endpoint)
 
bool busy () const
 
bool idle () const
 
bool is_currently_handling_message () const
 
bool is_transaction_fetching_inhibited () const
 
fc::sha512 get_shared_secret () const
 
void clear_old_inventory ()
 
bool is_inventory_advertised_to_us_list_full_for_transactions () const
 
bool is_inventory_advertised_to_us_list_full () const
 
fc::optional< fc::ip::endpointget_endpoint_for_connecting () const
 

Static Public Member Functions

static peer_connection_ptr make_shared (peer_connection_delegate *delegate)
 Use this instead of the constructor. More...
 

Public Attributes

fc::time_point connection_initiation_time
 
fc::time_point connection_closed_time
 
fc::time_point connection_terminated_time
 
peer_connection_direction direction = peer_connection_direction::unknown
 
firewalled_state is_firewalled = firewalled_state::unknown
 
fc::microseconds clock_offset
 
fc::microseconds round_trip_delay
 
our_connection_state our_state = our_connection_state::disconnected
 
bool they_have_requested_close = false
 
their_connection_state their_state = their_connection_state::disconnected
 
bool we_have_requested_close = false
 
connection_negotiation_status negotiation_status = connection_negotiation_status::disconnected
 
fc::oexception connection_closed_error
 
fc::time_point transaction_fetching_inhibited_until
 
uint32_t last_known_fork_block_number = 0
 
fc::future< void > accept_or_connect_task_done
 
bool expecting_address_message = false
 Whether we're waiting for an address message. More...
 
node_id_t node_public_key
 
node_id_t node_id
 
uint32_t core_protocol_version = 0
 
std::string user_agent
 
fc::optional< std::string > graphene_git_revision_sha
 
fc::optional< fc::time_point_secgraphene_git_revision_unix_timestamp
 
fc::optional< std::string > fc_git_revision_sha
 
fc::optional< fc::time_point_secfc_git_revision_unix_timestamp
 
fc::optional< std::string > platform
 
fc::optional< uint32_t > bitness
 
fc::ip::address inbound_address
 
uint16_t inbound_port = 0
 
uint16_t outbound_port = 0
 
fc::optional< fc::ip::endpointremote_inbound_endpoint
 The inbound endpoint of the remote peer (our best guess) More...
 
fc::flat_set< fc::ip::endpointadditional_inbound_endpoints
 Some nodes may be listening on multiple endpoints. More...
 
fc::flat_map< fc::ip::endpoint, firewalled_statepotential_inbound_endpoints
 Potential inbound endpoints of the peer. More...
 
boost::container::deque< item_hash_tids_of_items_to_get
 
std::set< item_hash_tids_of_items_being_processed
 
uint32_t number_of_unfetched_item_ids = 0
 Number of items in the blockchain that follow ids_of_items_to_get but the peer hasn't yet told us their IDs. More...
 
bool peer_needs_sync_items_from_us = false
 
bool we_need_sync_items_from_peer = false
 
fc::optional< boost::tuple< std::vector< item_hash_t >, fc::time_point > > item_ids_requested_from_peer
 We check this to detect a timed-out request and in busy() More...
 
fc::time_point last_sync_item_received_time
 
std::set< item_hash_tsync_items_requested_from_peer
 IDs of blocks we've requested from this peer during sync. Fetch from another peer if this peer disconnects. More...
 
item_hash_t last_block_delegate_has_seen
 The hash of the last block this peer has told us about that the peer knows. More...
 
fc::time_point_sec last_block_time_delegate_has_seen
 
bool inhibit_fetching_sync_blocks = false
 

Protected Member Functions

 peer_connection (peer_connection_delegate *delegate)
 
using timestamped_items_set_type = boost::multi_index_container< timestamped_item_id, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member< timestamped_item_id, item_id, &timestamped_item_id::item >, std::hash< item_id > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< timestamp_index >, boost::multi_index::member< timestamped_item_id, fc::time_point_sec, &timestamped_item_id::timestamp > > > >
 
timestamped_items_set_type inventory_peer_advertised_to_us
 
timestamped_items_set_type inventory_advertised_to_peer
 
item_to_time_map_type items_requested_from_peer
 

Detailed Description

Definition at line 58 of file peer_connection.hpp.

Member Typedef Documentation

◆ item_to_time_map_type

Definition at line 208 of file peer_connection.hpp.

◆ timestamped_items_set_type

using graphene::net::peer_connection::timestamped_items_set_type = boost::multi_index_container< timestamped_item_id, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::member<timestamped_item_id, item_id, &timestamped_item_id::item>, std::hash<item_id> >, boost::multi_index::ordered_non_unique< boost::multi_index::tag<timestamp_index>, boost::multi_index::member<timestamped_item_id, fc::time_point_sec, &timestamped_item_id::timestamp> > > >

Definition at line 257 of file peer_connection.hpp.

Member Enumeration Documentation

◆ connection_negotiation_status

Enumerator
disconnected 
connecting 
connected 
accepting 
accepted 
hello_sent 
peer_connection_accepted 
peer_connection_rejected 
negotiation_complete 
closing 
closed 

Definition at line 78 of file peer_connection.hpp.

◆ our_connection_state

Enumerator
disconnected 
just_connected 

If in this state, we have sent a hello_message.

connection_accepted 

Remote side has sent us a connection_accepted, we're operating normally with them

connection_rejected 

Remote side has sent us a connection_rejected, we may be exchanging address with them or may just be waiting for them to close

Definition at line 62 of file peer_connection.hpp.

◆ their_connection_state

Enumerator
disconnected 
just_connected 

We have not yet received a hello_message.

connection_accepted 

We have sent them a connection_accepted.

connection_rejected 

We have sent them a connection_rejected.

Definition at line 71 of file peer_connection.hpp.

Constructor & Destructor Documentation

◆ peer_connection()

graphene::net::peer_connection::peer_connection ( peer_connection_delegate delegate)
protected

Definition at line 74 of file peer_connection.cpp.

◆ ~peer_connection()

graphene::net::peer_connection::~peer_connection ( )
virtual

Definition at line 180 of file peer_connection.cpp.

Member Function Documentation

◆ accept_connection()

void graphene::net::peer_connection::accept_connection ( )

Definition at line 192 of file peer_connection.cpp.

◆ busy()

bool graphene::net::peer_connection::busy ( ) const

Definition at line 488 of file peer_connection.cpp.

◆ clear_old_inventory()

void graphene::net::peer_connection::clear_old_inventory ( )

Definition at line 518 of file peer_connection.cpp.

◆ close_connection()

void graphene::net::peer_connection::close_connection ( )

Definition at line 431 of file peer_connection.cpp.

◆ connect_to()

void graphene::net::peer_connection::connect_to ( const fc::ip::endpoint remote_endpoint,
const fc::optional< fc::ip::endpoint > &  local_endpoint = fc::optional<fc::ip::endpoint>() 
)

Definition at line 230 of file peer_connection.cpp.

◆ destroy_connection()

void graphene::net::peer_connection::destroy_connection ( )

Definition at line 440 of file peer_connection.cpp.

◆ get_connection_terminated_time()

fc::time_point graphene::net::peer_connection::get_connection_terminated_time ( ) const
inline

Definition at line 174 of file peer_connection.hpp.

◆ get_connection_time()

fc::time_point graphene::net::peer_connection::get_connection_time ( ) const
inline

Definition at line 173 of file peer_connection.hpp.

◆ get_endpoint_for_connecting()

fc::optional< fc::ip::endpoint > graphene::net::peer_connection::get_endpoint_for_connecting ( ) const

Definition at line 558 of file peer_connection.cpp.

◆ get_last_message_received_time()

fc::time_point graphene::net::peer_connection::get_last_message_received_time ( ) const

Definition at line 465 of file peer_connection.cpp.

◆ get_last_message_sent_time()

fc::time_point graphene::net::peer_connection::get_last_message_sent_time ( ) const

Definition at line 459 of file peer_connection.cpp.

◆ get_local_endpoint()

fc::ip::endpoint graphene::net::peer_connection::get_local_endpoint ( )

Definition at line 476 of file peer_connection.cpp.

◆ get_remote_endpoint()

fc::optional< fc::ip::endpoint > graphene::net::peer_connection::get_remote_endpoint ( )

Definition at line 471 of file peer_connection.cpp.

◆ get_shared_secret()

fc::sha512 graphene::net::peer_connection::get_shared_secret ( ) const

Definition at line 512 of file peer_connection.cpp.

◆ get_socket()

fc::tcp_socket & graphene::net::peer_connection::get_socket ( )

Definition at line 186 of file peer_connection.cpp.

◆ get_total_bytes_received()

uint64_t graphene::net::peer_connection::get_total_bytes_received ( ) const

Definition at line 453 of file peer_connection.cpp.

◆ get_total_bytes_sent()

uint64_t graphene::net::peer_connection::get_total_bytes_sent ( ) const

Definition at line 447 of file peer_connection.cpp.

◆ idle()

bool graphene::net::peer_connection::idle ( ) const

Definition at line 494 of file peer_connection.cpp.

◆ is_currently_handling_message()

bool graphene::net::peer_connection::is_currently_handling_message ( ) const

Definition at line 500 of file peer_connection.cpp.

◆ is_inventory_advertised_to_us_list_full()

bool graphene::net::peer_connection::is_inventory_advertised_to_us_list_full ( ) const

Definition at line 547 of file peer_connection.cpp.

◆ is_inventory_advertised_to_us_list_full_for_transactions()

bool graphene::net::peer_connection::is_inventory_advertised_to_us_list_full_for_transactions ( ) const

Definition at line 541 of file peer_connection.cpp.

◆ is_transaction_fetching_inhibited()

bool graphene::net::peer_connection::is_transaction_fetching_inhibited ( ) const

Definition at line 506 of file peer_connection.cpp.

◆ make_shared()

peer_connection_ptr graphene::net::peer_connection::make_shared ( peer_connection_delegate delegate)
static

Use this instead of the constructor.

Definition at line 98 of file peer_connection.cpp.

◆ on_connection_closed()

void graphene::net::peer_connection::on_connection_closed ( message_oriented_connection originating_connection)
overridevirtual

◆ on_message()

void graphene::net::peer_connection::on_message ( message_oriented_connection originating_connection,
const message received_message 
)
overridevirtual

◆ send_item()

void graphene::net::peer_connection::send_item ( const item_id item_to_send)

Definition at line 422 of file peer_connection.cpp.

◆ send_message()

void graphene::net::peer_connection::send_message ( const message message_to_send,
size_t  message_send_time_field_offset = (size_t)-1 
)
virtual

Definition at line 412 of file peer_connection.cpp.

◆ send_queueable_message()

void graphene::net::peer_connection::send_queueable_message ( std::unique_ptr< queued_message > &&  message_to_send)

Definition at line 380 of file peer_connection.cpp.

◆ set_remote_endpoint()

void graphene::net::peer_connection::set_remote_endpoint ( fc::optional< fc::ip::endpoint new_remote_endpoint)

Definition at line 482 of file peer_connection.cpp.

Member Data Documentation

◆ accept_or_connect_task_done

fc::future<void> graphene::net::peer_connection::accept_or_connect_task_done

Definition at line 272 of file peer_connection.hpp.

◆ additional_inbound_endpoints

fc::flat_set<fc::ip::endpoint> graphene::net::peer_connection::additional_inbound_endpoints

Some nodes may be listening on multiple endpoints.

Definition at line 203 of file peer_connection.hpp.

◆ bitness

fc::optional<uint32_t> graphene::net::peer_connection::bitness

Definition at line 192 of file peer_connection.hpp.

◆ clock_offset

fc::microseconds graphene::net::peer_connection::clock_offset

Definition at line 162 of file peer_connection.hpp.

◆ connection_closed_error

fc::oexception graphene::net::peer_connection::connection_closed_error

Definition at line 171 of file peer_connection.hpp.

◆ connection_closed_time

fc::time_point graphene::net::peer_connection::connection_closed_time

Definition at line 158 of file peer_connection.hpp.

◆ connection_initiation_time

fc::time_point graphene::net::peer_connection::connection_initiation_time

Definition at line 157 of file peer_connection.hpp.

◆ connection_terminated_time

fc::time_point graphene::net::peer_connection::connection_terminated_time

Definition at line 159 of file peer_connection.hpp.

◆ core_protocol_version

uint32_t graphene::net::peer_connection::core_protocol_version = 0

Definition at line 185 of file peer_connection.hpp.

◆ direction

peer_connection_direction graphene::net::peer_connection::direction = peer_connection_direction::unknown

Definition at line 160 of file peer_connection.hpp.

◆ expecting_address_message

bool graphene::net::peer_connection::expecting_address_message = false

Whether we're waiting for an address message.

Definition at line 275 of file peer_connection.hpp.

◆ fc_git_revision_sha

fc::optional<std::string> graphene::net::peer_connection::fc_git_revision_sha

Definition at line 189 of file peer_connection.hpp.

◆ fc_git_revision_unix_timestamp

fc::optional<fc::time_point_sec> graphene::net::peer_connection::fc_git_revision_unix_timestamp

Definition at line 190 of file peer_connection.hpp.

◆ graphene_git_revision_sha

fc::optional<std::string> graphene::net::peer_connection::graphene_git_revision_sha

Definition at line 187 of file peer_connection.hpp.

◆ graphene_git_revision_unix_timestamp

fc::optional<fc::time_point_sec> graphene::net::peer_connection::graphene_git_revision_unix_timestamp

Definition at line 188 of file peer_connection.hpp.

◆ ids_of_items_being_processed

std::set<item_hash_t> graphene::net::peer_connection::ids_of_items_being_processed

List of all items this peer has offered use that we've already handed to the client but the client hasn't finished processing

Definition at line 216 of file peer_connection.hpp.

◆ ids_of_items_to_get

boost::container::deque<item_hash_t> graphene::net::peer_connection::ids_of_items_to_get

Blockchain synchronization state data

ID of items in the blockchain that this peer has told us about

Definition at line 213 of file peer_connection.hpp.

◆ inbound_address

fc::ip::address graphene::net::peer_connection::inbound_address

Definition at line 197 of file peer_connection.hpp.

◆ inbound_port

uint16_t graphene::net::peer_connection::inbound_port = 0

Definition at line 198 of file peer_connection.hpp.

◆ inhibit_fetching_sync_blocks

bool graphene::net::peer_connection::inhibit_fetching_sync_blocks = false

Definition at line 231 of file peer_connection.hpp.

◆ inventory_advertised_to_peer

timestamped_items_set_type graphene::net::peer_connection::inventory_advertised_to_peer

Definition at line 259 of file peer_connection.hpp.

◆ inventory_peer_advertised_to_us

timestamped_items_set_type graphene::net::peer_connection::inventory_peer_advertised_to_us

Definition at line 258 of file peer_connection.hpp.

◆ is_firewalled

firewalled_state graphene::net::peer_connection::is_firewalled = firewalled_state::unknown

Definition at line 161 of file peer_connection.hpp.

◆ item_ids_requested_from_peer

fc::optional<boost::tuple<std::vector<item_hash_t>, fc::time_point> > graphene::net::peer_connection::item_ids_requested_from_peer

We check this to detect a timed-out request and in busy()

Definition at line 222 of file peer_connection.hpp.

◆ items_requested_from_peer

item_to_time_map_type graphene::net::peer_connection::items_requested_from_peer

Items we've requested from this peer during normal operation. Fetch from another peer if this peer disconnects

Definition at line 263 of file peer_connection.hpp.

◆ last_block_delegate_has_seen

item_hash_t graphene::net::peer_connection::last_block_delegate_has_seen

The hash of the last block this peer has told us about that the peer knows.

Definition at line 229 of file peer_connection.hpp.

◆ last_block_time_delegate_has_seen

fc::time_point_sec graphene::net::peer_connection::last_block_time_delegate_has_seen

Definition at line 230 of file peer_connection.hpp.

◆ last_known_fork_block_number

uint32_t graphene::net::peer_connection::last_known_fork_block_number = 0

Definition at line 270 of file peer_connection.hpp.

◆ last_sync_item_received_time

fc::time_point graphene::net::peer_connection::last_sync_item_received_time

The time we received the last sync item or the time we sent the last batch of sync item requests to this peer

Definition at line 225 of file peer_connection.hpp.

◆ negotiation_status

connection_negotiation_status graphene::net::peer_connection::negotiation_status = connection_negotiation_status::disconnected

Definition at line 170 of file peer_connection.hpp.

◆ node_id

node_id_t graphene::net::peer_connection::node_id

the unique identifier we'll use to refer to the node with. zero-initialized before we receive the hello message, at which time it will be filled with either the "node_id" from the user_data field of the hello, or if none is present it will be filled with a copy of node_public_key

Definition at line 184 of file peer_connection.hpp.

◆ node_public_key

node_id_t graphene::net::peer_connection::node_public_key

data about the peer nodenode_public_key from the hello message, zero-initialized before we get the hello

Definition at line 179 of file peer_connection.hpp.

◆ number_of_unfetched_item_ids

uint32_t graphene::net::peer_connection::number_of_unfetched_item_ids = 0

Number of items in the blockchain that follow ids_of_items_to_get but the peer hasn't yet told us their IDs.

Definition at line 218 of file peer_connection.hpp.

◆ our_state

our_connection_state graphene::net::peer_connection::our_state = our_connection_state::disconnected

Definition at line 165 of file peer_connection.hpp.

◆ outbound_port

uint16_t graphene::net::peer_connection::outbound_port = 0

Definition at line 199 of file peer_connection.hpp.

◆ peer_needs_sync_items_from_us

bool graphene::net::peer_connection::peer_needs_sync_items_from_us = false

Definition at line 219 of file peer_connection.hpp.

◆ platform

fc::optional<std::string> graphene::net::peer_connection::platform

Definition at line 191 of file peer_connection.hpp.

◆ potential_inbound_endpoints

fc::flat_map<fc::ip::endpoint, firewalled_state> graphene::net::peer_connection::potential_inbound_endpoints

Potential inbound endpoints of the peer.

Definition at line 205 of file peer_connection.hpp.

◆ remote_inbound_endpoint

fc::optional<fc::ip::endpoint> graphene::net::peer_connection::remote_inbound_endpoint

The inbound endpoint of the remote peer (our best guess)

Definition at line 201 of file peer_connection.hpp.

◆ round_trip_delay

fc::microseconds graphene::net::peer_connection::round_trip_delay

Definition at line 163 of file peer_connection.hpp.

◆ sync_items_requested_from_peer

std::set<item_hash_t> graphene::net::peer_connection::sync_items_requested_from_peer

IDs of blocks we've requested from this peer during sync. Fetch from another peer if this peer disconnects.

Definition at line 227 of file peer_connection.hpp.

◆ their_state

their_connection_state graphene::net::peer_connection::their_state = their_connection_state::disconnected

Definition at line 167 of file peer_connection.hpp.

◆ they_have_requested_close

bool graphene::net::peer_connection::they_have_requested_close = false

Definition at line 166 of file peer_connection.hpp.

◆ transaction_fetching_inhibited_until

fc::time_point graphene::net::peer_connection::transaction_fetching_inhibited_until

Definition at line 268 of file peer_connection.hpp.

◆ user_agent

std::string graphene::net::peer_connection::user_agent

Definition at line 186 of file peer_connection.hpp.

◆ we_have_requested_close

bool graphene::net::peer_connection::we_have_requested_close = false

Definition at line 168 of file peer_connection.hpp.

◆ we_need_sync_items_from_peer

bool graphene::net::peer_connection::we_need_sync_items_from_peer = false

Definition at line 220 of file peer_connection.hpp.


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