Exemple #1
0
    void peer_connection::send_queued_messages_task()
    {
      VERIFY_CORRECT_THREAD();
#ifndef NDEBUG
      struct counter {
        unsigned& _send_message_queue_tasks_counter;
        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; }
        ~counter() { assert(_send_message_queue_tasks_counter == 1); --_send_message_queue_tasks_counter; dlog("leaving peer_connection::send_queued_messages_task()"); }
      } concurrent_invocation_counter(_send_message_queue_tasks_running);
#endif
      while (!_queued_messages.empty())
      {
        _queued_messages.front()->transmission_start_time = fc::time_point::now();
        message message_to_send = _queued_messages.front()->get_message(_node);
        try
        {
          dlog("peer_connection::send_queued_messages_task() calling message_oriented_connection::send_message() "
               "to send message of type ${type} for peer ${endpoint}",
               ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint()));
          _message_connection.send_message(message_to_send);
          dlog("peer_connection::send_queued_messages_task()'s call to message_oriented_connection::send_message() completed normally for peer ${endpoint}",
               ("endpoint", get_remote_endpoint()));
        }
        catch (const fc::canceled_exception&)
        {
          dlog("message_oriented_connection::send_message() was canceled, rethrowing canceled_exception");
          throw;
        }
        catch (const fc::exception& send_error)
        {
          elog("Error sending message: ${exception}.  Closing connection.", ("exception", send_error));
          try
          {
            close_connection();
          }
          catch (const fc::exception& close_error)
          {
            elog("Caught error while closing connection: ${exception}", ("exception", close_error));
          }
          return;
        }
        catch (const std::exception& e)
        {
          elog("message_oriented_exception::send_message() threw a std::exception(): ${what}", ("what", e.what()));
        }
        catch (...)
        {
          elog("message_oriented_exception::send_message() threw an unhandled exception");
        }
        _queued_messages.front()->transmission_finish_time = fc::time_point::now();
        _total_queued_messages_size -= _queued_messages.front()->get_size_in_queue();
        _queued_messages.pop();
      }
      dlog("leaving peer_connection::send_queued_messages_task() due to queue exhaustion");
    }
Exemple #2
0
 void peer_connection::send_item(const item_id& item_to_send)
 {
   VERIFY_CORRECT_THREAD();
   dlog("peer_connection::send_item() enqueueing message of type ${type} for peer ${endpoint}",
        ("type", item_to_send.item_type)("endpoint", get_remote_endpoint()));
   std::unique_ptr<queued_message> message_to_enqueue(new virtual_queued_message(item_to_send));
   send_queueable_message(std::move(message_to_enqueue));
 }
Exemple #3
0
 void peer_connection::send_message(const message& message_to_send, size_t message_send_time_field_offset)
 {
   VERIFY_CORRECT_THREAD();
   dlog("peer_connection::send_message() enqueueing message of type ${type} for peer ${endpoint}",
        ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint()));
   std::unique_ptr<queued_message> message_to_enqueue(new real_queued_message(message_to_send, message_send_time_field_offset));
   send_queueable_message(std::move(message_to_enqueue));
 }
Exemple #4
0
    void peer_connection::clear_old_inventory()
    {
      VERIFY_CORRECT_THREAD();
      fc::time_point_sec oldest_inventory_to_keep(fc::time_point::now() - fc::minutes(GRAPHENE_NET_MAX_INVENTORY_SIZE_IN_MINUTES));

      // expire old items from inventory_advertised_to_peer
      auto oldest_inventory_to_keep_iter = inventory_advertised_to_peer.get<timestamp_index>().lower_bound(oldest_inventory_to_keep);
      auto begin_iter = inventory_advertised_to_peer.get<timestamp_index>().begin();
      unsigned number_of_elements_advertised_to_peer_to_discard = std::distance(begin_iter, oldest_inventory_to_keep_iter);
      inventory_advertised_to_peer.get<timestamp_index>().erase(begin_iter, oldest_inventory_to_keep_iter);

      // also expire items from inventory_peer_advertised_to_us
      oldest_inventory_to_keep_iter = inventory_peer_advertised_to_us.get<timestamp_index>().lower_bound(oldest_inventory_to_keep);
      begin_iter = inventory_peer_advertised_to_us.get<timestamp_index>().begin();
      unsigned number_of_elements_peer_advertised_to_discard = std::distance(begin_iter, oldest_inventory_to_keep_iter);
      inventory_peer_advertised_to_us.get<timestamp_index>().erase(begin_iter, oldest_inventory_to_keep_iter);
      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)",
           ("peer", get_remote_endpoint())
           ("to_peer", number_of_elements_advertised_to_peer_to_discard)("remain_to_peer", inventory_advertised_to_peer.size())
           ("to_us", number_of_elements_peer_advertised_to_discard)("remain_to_us", inventory_peer_advertised_to_us.size()));
    }
Exemple #5
0
bool ControlServer::on_validate(websocketpp::connection_hdl hdl) {
	log_->trace() << log_tag() << BOOST_CURRENT_FUNCTION;

	auto connection_ptr = ws_server_.get_con_from_hdl(hdl);
	auto subprotocols = connection_ptr->get_requested_subprotocols();
	auto origin = connection_ptr->get_origin();

	log_->debug() << log_tag() << "Incoming connection from " << connection_ptr->get_remote_endpoint() << " Origin: " << origin;

	// Restrict access by "Origin" header
	if(!origin.empty()) {   // TODO: Add a way to relax this restriction
		url origin_url(origin);
		if(origin_url.host != "127.0.0.1" && origin_url.host != "::1" && origin_url.host != "localhost")
			return false;
	}

	// Detect loopback
	if(std::find(subprotocols.begin(), subprotocols.end(), "librevaultctl1.0") != subprotocols.end())
		connection_ptr->select_subprotocol("librevaultctl1.0");
	return true;
}
Exemple #6
0
	void NetServer::add_client(sf::TcpSocket* socket)
	{
		ipendpoint remote = get_remote_endpoint(*socket);
		
		NetConnection* netconn = new NetConnection(socket, this);
		_connections[remote] = netconn;
		
		NetConnectionThreadStartReceiveFunctor rfunctor;
		rfunctor.netconnptr = netconn;
		
		NetConnectionThreadStartSendFunctor sfunctor;
		sfunctor.netconnptr = netconn;
		
		sf::Thread* netconnrthread = new sf::Thread(rfunctor);
		sf::Thread* netconnsthread = new sf::Thread(sfunctor);
		
		_receive_threads[remote] = netconnrthread;
		_send_threads[remote] = netconnsthread;
		
		netconnrthread->launch();
		netconnsthread->launch();
		
		_clientids[remote] = _gameserv->add_connection(netconn);
	}
std::uint16_t connection::get_remote_port() const
{
    return get_remote_endpoint().port();
}
asio::ip::address connection::get_remote_address() const
{
    return get_remote_endpoint().address();
}
 /**
  * Returns the client's port number
  * 
  * @return client's port number
  */
 unsigned short get_remote_port() const {
     return get_remote_endpoint().port();
 }
 /**
  * Returns the client's IP address
  * 
  * @return client's IP address
  */
 asio::ip::address get_remote_ip() const {
     return get_remote_endpoint().address();
 }