void protocol::handle_accept(const code& ec, channel::ptr node, acceptor::ptr accept) { // Relisten for connections. start_accept(ec, accept); if (ec) { log_debug(LOG_PROTOCOL) << "Failure accepting connection: " << ec.message(); return; } if (inbound_connections_.size() >= max_inbound_) { log_debug(LOG_PROTOCOL) << "Rejected inbound connection due to connection limit"; return; } const auto address = node->address(); if (is_blacklisted(node->address())) { log_debug(LOG_PROTOCOL) << "Rejected inbound connection due to blacklisted address"; return; } if (is_loopback(node)) { log_debug(LOG_PROTOCOL) << "Rejected inbound connection from self"; return; } // Save the connection as we are now assured of getting stop event. inbound_connections_.push_back(node); // Accepted! log_info(LOG_PROTOCOL) << "Accepted connection from [" << address << "] (" << inbound_connections_.size() << " total)"; const auto stop_handler = dispatch_.ordered_delegate(&protocol::inbound_channel_stopped, this, _1, node, address.to_string()); start_talking(node, stop_handler, relay_); }
void protocol::handle_handshake(const code& ec, channel::ptr node) { if (ec) { log_debug(LOG_PROTOCOL) << "Failure in peer handshake [" << node->address() << "] " << ec.message(); node->stop(ec); return; } // Attach ping protocol to the new connection (until node stop event). std::make_shared<protocol_ping>(node, pool_, timeouts_.heartbeat)->start(); // Attach address protocol to the new connection (until node stop event). std::make_shared<protocol_address>(node, pool_, hosts_, self_)->start(); }