BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
peer_connection.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
26 #include <graphene/net/config.hpp>
28 
29 #include <fc/io/raw.hpp>
30 #include <fc/thread/thread.hpp>
31 
32 #include <boost/scope_exit.hpp>
33 
34 #ifdef DEFAULT_LOGGER
35 # undef DEFAULT_LOGGER
36 #endif
37 #define DEFAULT_LOGGER "p2p"
38 
39 #ifndef NDEBUG
40 # define VERIFY_CORRECT_THREAD() assert(_thread->is_current())
41 #else
42 # define VERIFY_CORRECT_THREAD() do {} while (0)
43 #endif
44 
45 namespace graphene { namespace net
46  {
47  message peer_connection::real_queued_message::get_message(peer_connection_delegate*)
48  {
49  if (message_send_time_field_offset != (size_t)-1)
50  {
51  // patch the current time into the message. Since this operates on the packed version of the structure,
52  // it won't work for anything after a variable-length field
53  std::vector<char> packed_current_time = fc::raw::pack(fc::time_point::now());
54  assert(message_send_time_field_offset + packed_current_time.size() <= message_to_send.data.size());
55  memcpy(message_to_send.data.data() + message_send_time_field_offset,
56  packed_current_time.data(), packed_current_time.size());
57  }
58  return message_to_send;
59  }
60  size_t peer_connection::real_queued_message::get_size_in_queue()
61  {
62  return message_to_send.data.size();
63  }
64  message peer_connection::virtual_queued_message::get_message(peer_connection_delegate* node)
65  {
66  return node->get_message_for_item(item_to_send);
67  }
68 
69  size_t peer_connection::virtual_queued_message::get_size_in_queue()
70  {
71  return sizeof(item_id);
72  }
73 
75  _node(delegate),
76  _message_connection(this),
77  _total_queued_messages_size(0),
79  our_state(our_connection_state::disconnected),
80  they_have_requested_close(false),
81  their_state(their_connection_state::disconnected),
82  we_have_requested_close(false),
83  negotiation_status(connection_negotiation_status::disconnected),
84  number_of_unfetched_item_ids(0),
85  peer_needs_sync_items_from_us(true),
86  we_need_sync_items_from_peer(true),
87  inhibit_fetching_sync_blocks(false),
88  transaction_fetching_inhibited_until(fc::time_point::min()),
89  last_known_fork_block_number(0),
90 #ifndef NDEBUG
91  _thread(&fc::thread::current()),
92  _send_message_queue_tasks_running(0),
93 #endif
94  _currently_handling_message(false)
95  {
96  }
97 
99  {
100  // The lifetime of peer_connection objects is managed by shared_ptrs in node. The peer_connection
101  // is responsible for notifying the node when it should be deleted, and the process of deleting it
102  // cleans up the peer connection's asynchronous tasks which are responsible for notifying the node
103  // when it should be deleted.
104  // To ease this vicious cycle, we slightly delay the execution of the destructor until the
105  // current task yields. In the (not uncommon) case where it is the task executing
106  // connect_to or read_loop, this allows the task to finish before the destructor is forced
107  // to cancel it.
108 
109  // Implementation: derive peer_connection so that make_shared has access to the constructor
110  class peer_connection_subclass : public peer_connection
111  {
112  public:
113  explicit peer_connection_subclass(peer_connection_delegate* delegate) : peer_connection(delegate) {}
114  };
115  return std::make_shared<peer_connection_subclass>(delegate);
116  }
117 
118  void peer_connection::destroy()
119  {
121 
122 #if 0 // this gets too verbose
123 #ifndef NDEBUG
124  struct scope_logger {
126  scope_logger(const fc::optional<fc::ip::endpoint>& endpoint) : endpoint(endpoint) { dlog("entering peer_connection::destroy() for peer ${endpoint}", ("endpoint", endpoint)); }
127  ~scope_logger() { dlog("leaving peer_connection::destroy() for peer ${endpoint}", ("endpoint", endpoint)); }
128  } send_message_scope_logger(get_remote_endpoint());
129 #endif
130 #endif
131 
132  try
133  {
134  dlog("calling close_connection()");
136  dlog("close_connection completed normally");
137  }
138  catch ( const fc::canceled_exception& )
139  {
140  assert(false && "the task that deletes peers should not be canceled because it will prevent us from cleaning up correctly");
141  }
142  catch ( ... )
143  {
144  dlog("close_connection threw");
145  }
146 
147  try
148  {
149  dlog("canceling _send_queued_messages task");
150  _send_queued_messages_done.cancel_and_wait(__FUNCTION__);
151  dlog("cancel_and_wait completed normally");
152  }
153  catch( const fc::exception& e )
154  {
155  wlog("Unexpected exception from peer_connection's send_queued_messages_task : ${e}", ("e", e));
156  }
157  catch( ... )
158  {
159  wlog("Unexpected exception from peer_connection's send_queued_messages_task");
160  }
161 
162  try
163  {
164  dlog("canceling accept_or_connect_task");
166  dlog("accept_or_connect_task completed normally");
167  }
168  catch( const fc::exception& e )
169  {
170  wlog("Unexpected exception from peer_connection's accept_or_connect_task : ${e}", ("e", e));
171  }
172  catch( ... )
173  {
174  wlog("Unexpected exception from peer_connection's accept_or_connect_task");
175  }
176 
177  _message_connection.destroy_connection(); // shut down the read loop
178  }
179 
181  {
183  destroy();
184  }
185 
187  {
189  return _message_connection.get_socket();
190  }
191 
193  {
195 
196  struct scope_logger {
197  scope_logger() { dlog("entering peer_connection::accept_connection()"); }
198  ~scope_logger() { dlog("leaving peer_connection::accept_connection()"); }
199  } accept_connection_scope_logger;
200 
201  try
202  {
207  _message_connection.accept(); // perform key exchange
209  _remote_endpoint = _message_connection.get_socket().remote_endpoint();
210 
211  // firewall-detecting info is pretty useless for inbound connections, but initialize
212  // it the best we can
213  fc::ip::endpoint local_endpoint = _message_connection.get_socket().local_endpoint();
214  inbound_address = local_endpoint.get_address();
215  inbound_port = local_endpoint.port();
217 
220  ilog( "established inbound connection from ${remote_endpoint}, sending hello",
221  ("remote_endpoint", _message_connection.get_socket().remote_endpoint() ) );
222  }
223  catch ( const fc::exception& e )
224  {
225  wlog( "error accepting connection ${e}", ("e", e.to_detail_string() ) );
226  throw;
227  }
228  }
229 
230  void peer_connection::connect_to( const fc::ip::endpoint& remote_endpoint,
231  const fc::optional<fc::ip::endpoint>& local_endpoint )
232  {
234  try
235  {
239 
240  _remote_endpoint = remote_endpoint;
241  bool failed_to_bind = false;
242  if( local_endpoint )
243  {
244  // the caller wants us to bind the local side of this socket to a specific ip/port
245  // This depends on the ip/port being unused, and on being able to set the
246  // SO_REUSEADDR/SO_REUSEPORT flags, and either of these might fail, so we need to
247  // detect if this fails.
248  try
249  {
250  _message_connection.bind( *local_endpoint );
251  }
252  catch ( const fc::canceled_exception& )
253  {
254  throw;
255  }
256  catch ( const fc::exception& except )
257  {
258  failed_to_bind = true;
259  wlog( "Failed to bind to desired local endpoint ${endpoint}, will connect using an OS-selected "
260  "endpoint: ${except}",
261  ("endpoint", *local_endpoint )("except", except ) );
262  }
263  }
265  bool retry = false;
266  try
267  {
268  _message_connection.connect_to( remote_endpoint );
269  }
270  catch ( const fc::canceled_exception& )
271  {
272  throw;
273  }
274  catch ( const fc::exception& except )
275  {
276  if( local_endpoint && !failed_to_bind )
277  {
278  retry = true;
279  wlog( "Failed to connect to remote endpoint ${remote_endpoint} from local endpoint ${local_endpoint}, "
280  "will connect using an OS-selected endpoint: ${except}",
281  ("remote_endpoint", remote_endpoint )("local_endpoint", *local_endpoint )("except", except ) );
282  }
283  else
284  throw;
285  }
286  if( retry )
287  {
288  get_socket().close();
289  get_socket().open();
290  _message_connection.connect_to( remote_endpoint );
291  }
295  remote_inbound_endpoint = remote_endpoint;
296  ilog( "established outbound connection to ${remote_endpoint}", ("remote_endpoint", remote_endpoint ) );
297  }
298  catch ( fc::exception& e )
299  {
300  wlog( "error connecting to peer ${remote_endpoint}: ${e}",
301  ("remote_endpoint", remote_endpoint )("e", e.to_detail_string() ) );
302  throw;
303  }
304  } // connect_to()
305 
307  const message& received_message )
308  {
310  _currently_handling_message = true;
311  BOOST_SCOPE_EXIT(this_) {
312  this_->_currently_handling_message = false;
313  } BOOST_SCOPE_EXIT_END
314  _node->on_message( this, received_message );
315  }
316 
318  {
321  _node->on_connection_closed( this );
322  }
323 
324  void peer_connection::send_queued_messages_task()
325  {
327 #ifndef NDEBUG
328  struct counter {
329  unsigned& _send_message_queue_tasks_counter;
330  counter(unsigned& var) : _send_message_queue_tasks_counter(var) { /* dlog("entering peer_connection::send_queued_messages_task()"); */ assert(_send_message_queue_tasks_counter == 0); ++_send_message_queue_tasks_counter; }
331  ~counter() { assert(_send_message_queue_tasks_counter == 1); --_send_message_queue_tasks_counter; /* dlog("leaving peer_connection::send_queued_messages_task()"); */ }
332  } concurrent_invocation_counter(_send_message_queue_tasks_running);
333 #endif
334  while (!_queued_messages.empty())
335  {
336  _queued_messages.front()->transmission_start_time = fc::time_point::now();
337  message message_to_send = _queued_messages.front()->get_message(_node);
338  try
339  {
340  //dlog("peer_connection::send_queued_messages_task() calling message_oriented_connection::send_message() "
341  // "to send message of type ${type} for peer ${endpoint}",
342  // ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint()));
343  _message_connection.send_message(message_to_send);
344  //dlog("peer_connection::send_queued_messages_task()'s call to message_oriented_connection::send_message() completed normally for peer ${endpoint}",
345  // ("endpoint", get_remote_endpoint()));
346  }
347  catch (const fc::canceled_exception&)
348  {
349  dlog("message_oriented_connection::send_message() was canceled, rethrowing canceled_exception");
350  throw;
351  }
352  catch (const fc::exception& send_error)
353  {
354  wlog("Error sending message: ${exception}. Closing connection.", ("exception", send_error));
355  try
356  {
358  }
359  catch (const fc::exception& close_error)
360  {
361  wlog("Caught error while closing connection: ${exception}", ("exception", close_error));
362  }
363  return;
364  }
365  catch (const std::exception& e)
366  {
367  wlog("message_oriented_exception::send_message() threw a std::exception(): ${what}", ("what", e.what()));
368  }
369  catch (...)
370  {
371  wlog("message_oriented_exception::send_message() threw an unhandled exception");
372  }
373  _queued_messages.front()->transmission_finish_time = fc::time_point::now();
374  _total_queued_messages_size -= _queued_messages.front()->get_size_in_queue();
375  _queued_messages.pop();
376  }
377  //dlog("leaving peer_connection::send_queued_messages_task() due to queue exhaustion");
378  }
379 
380  void peer_connection::send_queueable_message(std::unique_ptr<queued_message>&& message_to_send)
381  {
383  _total_queued_messages_size += message_to_send->get_size_in_queue();
384  _queued_messages.emplace(std::move(message_to_send));
385  if (_total_queued_messages_size > GRAPHENE_NET_MAXIMUM_QUEUED_MESSAGES_IN_BYTES)
386  {
387  wlog("send queue exceeded maximum size of ${max} bytes (current size ${current} bytes)",
388  ("max", GRAPHENE_NET_MAXIMUM_QUEUED_MESSAGES_IN_BYTES)("current", _total_queued_messages_size));
389  try
390  {
392  }
393  catch (const fc::exception& e)
394  {
395  wlog("Caught error while closing connection: ${exception}", ("exception", e));
396  }
397  return;
398  }
399 
400  if( _send_queued_messages_done.valid() && _send_queued_messages_done.canceled() )
401  FC_THROW_EXCEPTION(fc::exception, "Attempting to send a message on a connection that is being shut down");
402 
403  if (!_send_queued_messages_done.valid() || _send_queued_messages_done.ready())
404  {
405  //dlog("peer_connection::send_message() is firing up send_queued_message_task");
406  _send_queued_messages_done = fc::async([this](){ send_queued_messages_task(); }, "send_queued_messages_task");
407  }
408  //else
409  // dlog("peer_connection::send_message() doesn't need to fire up send_queued_message_task, it's already running");
410  }
411 
412  void peer_connection::send_message(const message& message_to_send, size_t message_send_time_field_offset)
413  {
415  //dlog("peer_connection::send_message() enqueueing message of type ${type} for peer ${endpoint}",
416  // ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint())); // for debug
417  auto message_to_enqueue = std::make_unique<real_queued_message>(
418  message_to_send, message_send_time_field_offset );
419  send_queueable_message(std::move(message_to_enqueue));
420  }
421 
422  void peer_connection::send_item(const item_id& item_to_send)
423  {
425  //dlog("peer_connection::send_item() enqueueing message of type ${type} for peer ${endpoint}",
426  // ("type", item_to_send.item_type)("endpoint", get_remote_endpoint())); // for debug
427  auto message_to_enqueue = std::make_unique<virtual_queued_message>(item_to_send);
428  send_queueable_message(std::move(message_to_enqueue));
429  }
430 
432  {
437  _message_connection.close_connection();
438  }
439 
441  {
444  destroy();
445  }
446 
448  {
450  return _message_connection.get_total_bytes_sent();
451  }
452 
454  {
456  return _message_connection.get_total_bytes_received();
457  }
458 
460  {
462  return _message_connection.get_last_message_sent_time();
463  }
464 
466  {
468  return _message_connection.get_last_message_received_time();
469  }
470 
472  {
474  return _remote_endpoint;
475  }
477  {
479  return _message_connection.get_socket().local_endpoint();
480  }
481 
483  {
485  _remote_endpoint = new_remote_endpoint;
486  }
487 
489  {
492  }
493 
495  {
497  return !busy();
498  }
499 
501  {
503  return _currently_handling_message;
504  }
505 
507  {
510  }
511 
513  {
515  return _message_connection.get_shared_secret();
516  }
517 
519  {
522 
523  // expire old items from inventory_advertised_to_peer
524  auto oldest_inventory_to_keep_iter = inventory_advertised_to_peer.get<timestamp_index>().lower_bound(oldest_inventory_to_keep);
525  auto begin_iter = inventory_advertised_to_peer.get<timestamp_index>().begin();
526  unsigned number_of_elements_advertised_to_peer_to_discard = std::distance(begin_iter, oldest_inventory_to_keep_iter);
527  inventory_advertised_to_peer.get<timestamp_index>().erase(begin_iter, oldest_inventory_to_keep_iter);
528 
529  // also expire items from inventory_peer_advertised_to_us
530  oldest_inventory_to_keep_iter = inventory_peer_advertised_to_us.get<timestamp_index>().lower_bound(oldest_inventory_to_keep);
531  begin_iter = inventory_peer_advertised_to_us.get<timestamp_index>().begin();
532  unsigned number_of_elements_peer_advertised_to_discard = std::distance(begin_iter, oldest_inventory_to_keep_iter);
533  inventory_peer_advertised_to_us.get<timestamp_index>().erase(begin_iter, oldest_inventory_to_keep_iter);
534  dlog("Expiring old inventory for peer ${peer}: removing ${to_peer} items advertised to peer (${remain_to_peer} left), and ${to_us} advertised to us (${remain_to_us} left)",
535  ("peer", get_remote_endpoint())
536  ("to_peer", number_of_elements_advertised_to_peer_to_discard)("remain_to_peer", inventory_advertised_to_peer.size())
537  ("to_us", number_of_elements_peer_advertised_to_discard)("remain_to_us", inventory_peer_advertised_to_us.size()));
538  }
539 
540  // we have a higher limit for blocks than transactions so we will still fetch blocks even when transactions are throttled
542  {
545  }
546 
548  {
550  // allow the total inventory size to be the maximum number of transactions we'll store in the inventory (above)
551  // plus the maximum number of blocks that would be generated in GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES (plus one,
552  // to give us some wiggle room)
553  return inventory_peer_advertised_to_us.size() >
556  }
557 
559  {
561  }
562 
563 } } // end namespace graphene::net
graphene::net::peer_connection::send_item
void send_item(const item_id &item_to_send)
Definition: peer_connection.cpp:422
graphene::net::peer_connection::inbound_address
fc::ip::address inbound_address
Definition: peer_connection.hpp:197
graphene::net::peer_connection::our_connection_state::disconnected
@ disconnected
graphene::net::peer_connection::their_state
their_connection_state their_state
Definition: peer_connection.hpp:167
GRAPHENE_NET_MAXIMUM_QUEUED_MESSAGES_IN_BYTES
#define GRAPHENE_NET_MAXIMUM_QUEUED_MESSAGES_IN_BYTES
Definition: config.hpp:63
graphene::net::peer_connection_delegate::on_message
virtual void on_message(peer_connection *originating_peer, const message &received_message)=0
GRAPHENE_MIN_BLOCK_INTERVAL
#define GRAPHENE_MIN_BLOCK_INTERVAL
Definition: config.hpp:59
graphene::net::peer_connection::outbound_port
uint16_t outbound_port
Definition: peer_connection.hpp:199
graphene::net::peer_connection::negotiation_status
connection_negotiation_status negotiation_status
Definition: peer_connection.hpp:170
graphene::net::peer_connection::is_transaction_fetching_inhibited
bool is_transaction_fetching_inhibited() const
Definition: peer_connection.cpp:506
graphene::net::peer_connection::items_requested_from_peer
item_to_time_map_type items_requested_from_peer
Definition: peer_connection.hpp:263
graphene::net::peer_connection::get_last_message_received_time
fc::time_point get_last_message_received_time() const
Definition: peer_connection.cpp:465
wlog
#define wlog(FORMAT,...)
Definition: logger.hpp:123
graphene::net::peer_connection::direction
peer_connection_direction direction
Definition: peer_connection.hpp:160
graphene::net::peer_connection::on_connection_closed
void on_connection_closed(message_oriented_connection *originating_connection) override
Definition: peer_connection.cpp:317
fc::exception
Used to generate a useful error report when an exception is thrown.
Definition: exception.hpp:56
graphene::net::message_oriented_connection::get_total_bytes_sent
uint64_t get_total_bytes_sent() const
Definition: message_oriented_connection.cpp:425
graphene::net::peer_connection::get_total_bytes_sent
uint64_t get_total_bytes_sent() const
Definition: peer_connection.cpp:447
graphene::net::peer_connection::make_shared
static peer_connection_ptr make_shared(peer_connection_delegate *delegate)
Use this instead of the constructor.
Definition: peer_connection.cpp:98
graphene::net::peer_connection::~peer_connection
virtual ~peer_connection()
Definition: peer_connection.cpp:180
graphene::net::peer_connection::get_total_bytes_received
uint64_t get_total_bytes_received() const
Definition: peer_connection.cpp:453
graphene::net::message_oriented_connection::connect_to
void connect_to(const fc::ip::endpoint &remote_endpoint)
Definition: message_oriented_connection.cpp:400
graphene::net::peer_connection_direction::outbound
@ outbound
graphene::net::peer_connection::connection_negotiation_status
connection_negotiation_status
Definition: peer_connection.hpp:78
fc
Definition: api.hpp:15
fc::tcp_socket::close
virtual void close()
Definition: tcp_socket.cpp:103
graphene::net::peer_connection::is_inventory_advertised_to_us_list_full
bool is_inventory_advertised_to_us_list_full() const
Definition: peer_connection.cpp:547
graphene::net::peer_connection::our_state
our_connection_state our_state
Definition: peer_connection.hpp:165
graphene::net::message
Definition: message.hpp:58
graphene::net::peer_connection::sync_items_requested_from_peer
std::set< item_hash_t > sync_items_requested_from_peer
IDs of blocks we've requested from this peer during sync. Fetch from another peer if this peer discon...
Definition: peer_connection.hpp:227
graphene::net::message_oriented_connection
Definition: message_oriented_connection.hpp:43
graphene::net::peer_connection::clear_old_inventory
void clear_old_inventory()
Definition: peer_connection.cpp:518
graphene::net::peer_connection::connection_negotiation_status::accepting
@ accepting
graphene::net::message_oriented_connection::get_socket
fc::tcp_socket & get_socket()
Definition: message_oriented_connection.cpp:390
graphene::net::peer_connection::busy
bool busy() const
Definition: peer_connection.cpp:488
fc::future< void >::canceled
bool canceled() const
Definition: future.hpp:312
graphene::net::peer_connection::connection_negotiation_status::connecting
@ connecting
graphene::net::peer_connection::connection_terminated_time
fc::time_point connection_terminated_time
Definition: peer_connection.hpp:159
fc::asio::tcp::endpoint
boost::asio::ip::tcp::endpoint endpoint
Definition: asio.hpp:239
fc::ip::endpoint
Definition: ip.hpp:65
graphene::net::peer_connection::get_shared_secret
fc::sha512 get_shared_secret() const
Definition: peer_connection.cpp:512
graphene::net::peer_connection::on_message
void on_message(message_oriented_connection *originating_connection, const message &received_message) override
Definition: peer_connection.cpp:306
graphene::net::peer_connection::send_queueable_message
void send_queueable_message(std::unique_ptr< queued_message > &&message_to_send)
Definition: peer_connection.cpp:380
graphene::net::peer_connection::connection_negotiation_status::closed
@ closed
fc::sha512
Definition: sha512.hpp:9
fc::ip::endpoint::get_address
const address & get_address() const
Definition: ip.cpp:79
graphene::net::peer_connection::inventory_advertised_to_peer
timestamped_items_set_type inventory_advertised_to_peer
Definition: peer_connection.hpp:259
graphene::net::message_oriented_connection::get_last_message_sent_time
fc::time_point get_last_message_sent_time() const
Definition: message_oriented_connection.cpp:435
graphene::net::item_id
Definition: core_messages.hpp:49
graphene::net::message_oriented_connection::get_last_message_received_time
fc::time_point get_last_message_received_time() const
Definition: message_oriented_connection.cpp:440
graphene::net::peer_connection::send_message
virtual void send_message(const message &message_to_send, size_t message_send_time_field_offset=(size_t) -1)
Definition: peer_connection.cpp:412
graphene::net::peer_connection::get_endpoint_for_connecting
fc::optional< fc::ip::endpoint > get_endpoint_for_connecting() const
Definition: peer_connection.cpp:558
graphene::net::message_oriented_connection::bind
void bind(const fc::ip::endpoint &local_endpoint)
Definition: message_oriented_connection.cpp:405
ilog
#define ilog(FORMAT,...)
Definition: logger.hpp:117
dlog
#define dlog(FORMAT,...)
Definition: logger.hpp:100
graphene::net::peer_connection_ptr
std::shared_ptr< peer_connection > peer_connection_ptr
Definition: peer_connection.hpp:57
graphene::net::peer_connection::accept_connection
void accept_connection()
Definition: peer_connection.cpp:192
graphene::net::peer_connection::our_connection_state
our_connection_state
Definition: peer_connection.hpp:62
graphene::net::peer_connection::set_remote_endpoint
void set_remote_endpoint(fc::optional< fc::ip::endpoint > new_remote_endpoint)
Definition: peer_connection.cpp:482
config.hpp
graphene::net::peer_connection_direction::inbound
@ inbound
fc::time_point_sec
Definition: time.hpp:74
thread.hpp
graphene::net::peer_connection::get_remote_endpoint
fc::optional< fc::ip::endpoint > get_remote_endpoint()
Definition: peer_connection.cpp:471
peer_connection.hpp
fc::async
auto async(Functor &&f, const char *desc FC_TASK_NAME_DEFAULT_ARG, priority prio=priority()) -> fc::future< decltype(f())>
Definition: thread.hpp:227
fc::time_point::min
static time_point min()
Definition: time.hpp:49
graphene::net::peer_connection::get_local_endpoint
fc::ip::endpoint get_local_endpoint()
Definition: peer_connection.cpp:476
graphene::net::peer_connection::transaction_fetching_inhibited_until
fc::time_point transaction_fetching_inhibited_until
Definition: peer_connection.hpp:268
fc::tcp_socket
Definition: tcp_socket.hpp:14
fc::minutes
microseconds minutes(int64_t m)
Definition: time.hpp:36
fc::exception::to_detail_string
std::string to_detail_string(log_level ll=log_level::all) const
Definition: exception.cpp:183
graphene::net::peer_connection::connection_negotiation_status::closing
@ closing
graphene::net::peer_connection_direction
peer_connection_direction
Definition: core_messages.hpp:270
fc::future< void >::valid
bool valid() const
Definition: future.hpp:311
graphene::net::peer_connection::get_last_message_sent_time
fc::time_point get_last_message_sent_time() const
Definition: peer_connection.cpp:459
fc::future< void >::cancel_and_wait
void cancel_and_wait(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG)
Definition: future.hpp:314
exceptions.hpp
graphene::net::peer_connection::close_connection
void close_connection()
Definition: peer_connection.cpp:431
fc::tcp_socket::remote_endpoint
fc::ip::endpoint remote_endpoint() const
Definition: tcp_socket.cpp:126
graphene::net::peer_connection::peer_connection
peer_connection(peer_connection_delegate *delegate)
Definition: peer_connection.cpp:74
graphene::net::peer_connection::get_socket
fc::tcp_socket & get_socket()
Definition: peer_connection.cpp:186
fc::future< void >::ready
bool ready() const
Definition: future.hpp:327
graphene::net::peer_connection::is_currently_handling_message
bool is_currently_handling_message() const
Definition: peer_connection.cpp:500
graphene::net::peer_connection::destroy_connection
void destroy_connection()
Definition: peer_connection.cpp:440
graphene::net::peer_connection::connection_negotiation_status::connected
@ connected
fc::time_point::now
static time_point now()
Definition: time.cpp:13
graphene::net::peer_connection::timestamp_index
Definition: peer_connection.hpp:245
fc::tcp_socket::open
void open()
Definition: tcp_socket.cpp:89
graphene::net::peer_connection_delegate::on_connection_closed
virtual void on_connection_closed(peer_connection *originating_peer)=0
fc::time_point
Definition: time.hpp:44
graphene::net::message_oriented_connection::get_shared_secret
fc::sha512 get_shared_secret() const
Definition: message_oriented_connection.cpp:448
graphene::net::peer_connection::their_connection_state
their_connection_state
Definition: peer_connection.hpp:71
graphene::net::peer_connection::item_ids_requested_from_peer
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()
Definition: peer_connection.hpp:222
graphene::net::peer_connection::connect_to
void connect_to(const fc::ip::endpoint &remote_endpoint, const fc::optional< fc::ip::endpoint > &local_endpoint=fc::optional< fc::ip::endpoint >())
Definition: peer_connection.cpp:230
graphene::net::peer_connection::inbound_port
uint16_t inbound_port
Definition: peer_connection.hpp:198
graphene::net::peer_connection::remote_inbound_endpoint
fc::optional< fc::ip::endpoint > remote_inbound_endpoint
The inbound endpoint of the remote peer (our best guess)
Definition: peer_connection.hpp:201
GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES
#define GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES
Definition: config.hpp:85
graphene::net::peer_connection::their_connection_state::just_connected
@ just_connected
We have not yet received a hello_message.
graphene::net::peer_connection_delegate
Definition: peer_connection.hpp:47
graphene::net::message_oriented_connection::destroy_connection
void destroy_connection()
Definition: message_oriented_connection.cpp:420
fc::optional< fc::ip::endpoint >
fc::tcp_socket::local_endpoint
fc::ip::endpoint local_endpoint() const
Definition: tcp_socket.cpp:137
graphene::net::message_oriented_connection::send_message
void send_message(const message &message_to_send)
Definition: message_oriented_connection.cpp:410
fc::ip::endpoint::port
uint16_t port() const
Definition: ip.cpp:78
graphene::net::message_oriented_connection::accept
void accept()
Definition: message_oriented_connection.cpp:395
graphene::net::peer_connection::is_inventory_advertised_to_us_list_full_for_transactions
bool is_inventory_advertised_to_us_list_full_for_transactions() const
Definition: peer_connection.cpp:541
FC_THROW_EXCEPTION
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Definition: exception.hpp:379
graphene::net::peer_connection::their_connection_state::disconnected
@ disconnected
graphene::net::message_oriented_connection::close_connection
void close_connection()
Definition: message_oriented_connection.cpp:415
VERIFY_CORRECT_THREAD
#define VERIFY_CORRECT_THREAD()
Definition: peer_connection.cpp:40
graphene::net::peer_connection::our_connection_state::just_connected
@ just_connected
If in this state, we have sent a hello_message.
GRAPHENE_NET_MAX_TRX_PER_SECOND
#define GRAPHENE_NET_MAX_TRX_PER_SECOND
Definition: config.hpp:110
config.hpp
graphene::net::message_oriented_connection::get_total_bytes_received
uint64_t get_total_bytes_received() const
Definition: message_oriented_connection.cpp:430
graphene::net::peer_connection::idle
bool idle() const
Definition: peer_connection.cpp:494
graphene
Definition: api.cpp:48
graphene::net::peer_connection::connection_negotiation_status::accepted
@ accepted
graphene::net::peer_connection::accept_or_connect_task_done
fc::future< void > accept_or_connect_task_done
Definition: peer_connection.hpp:272
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
graphene::net::peer_connection_direction::unknown
@ unknown
graphene::net::peer_connection::inventory_peer_advertised_to_us
timestamped_items_set_type inventory_peer_advertised_to_us
Definition: peer_connection.hpp:258
graphene::net::peer_connection
Definition: peer_connection.hpp:58
raw.hpp