| 4156 | } |
| 4157 | |
| 4158 | void node_impl::accept_loop() |
| 4159 | { |
| 4160 | VERIFY_CORRECT_THREAD(); |
| 4161 | while ( !_accept_loop_complete.canceled() ) |
| 4162 | { |
| 4163 | peer_connection_ptr new_peer(peer_connection::make_shared(this)); |
| 4164 | |
| 4165 | try |
| 4166 | { |
| 4167 | _tcp_server.accept( new_peer->get_socket() ); |
| 4168 | ilog( "accepted inbound connection from ${remote_endpoint}", ("remote_endpoint", new_peer->get_socket().remote_endpoint() ) ); |
| 4169 | if (_node_is_shutting_down) |
| 4170 | return; |
| 4171 | new_peer->connection_initiation_time = fc::time_point::now(); |
| 4172 | _handshaking_connections.insert( new_peer ); |
| 4173 | _rate_limiter.add_tcp_socket( &new_peer->get_socket() ); |
| 4174 | std::weak_ptr<peer_connection> new_weak_peer(new_peer); |
| 4175 | new_peer->accept_or_connect_task_done = fc::async( [this, new_weak_peer]() { |
| 4176 | peer_connection_ptr new_peer(new_weak_peer.lock()); |
| 4177 | assert(new_peer); |
| 4178 | if (!new_peer) |
| 4179 | return; |
| 4180 | accept_connection_task(new_peer); |
| 4181 | }, "accept_connection_task" ); |
| 4182 | |
| 4183 | // limit the rate at which we accept connections to mitigate DOS attacks |
| 4184 | fc::usleep( fc::milliseconds(10) ); |
| 4185 | } FC_CAPTURE_AND_RETHROW() |
| 4186 | } |
| 4187 | } // accept_loop() |
| 4188 | |
| 4189 | void node_impl::send_hello_message(const peer_connection_ptr& peer) |
| 4190 | { |