MCPcopy Create free account
hub / github.com/cryptonomex/graphene / p2p_network_connect_loop

Method p2p_network_connect_loop

libraries/net/node.cpp:885–980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

883 }
884
885 void node_impl::p2p_network_connect_loop()
886 {
887 VERIFY_CORRECT_THREAD();
888 while (!_p2p_network_connect_loop_done.canceled())
889 {
890 try
891 {
892 dlog("Starting an iteration of p2p_network_connect_loop().");
893 display_current_connections();
894
895 // add-once peers bypass our checks on the maximum/desired number of connections (but they will still be counted against the totals once they're connected)
896 if (!_add_once_node_list.empty())
897 {
898 std::list<potential_peer_record> add_once_node_list;
899 add_once_node_list.swap(_add_once_node_list);
900 dlog("Processing \"add once\" node list containing ${count} peers:", ("count", add_once_node_list.size()));
901 for (const potential_peer_record& add_once_peer : add_once_node_list)
902 {
903 dlog(" ${peer}", ("peer", add_once_peer.endpoint));
904 }
905 for (const potential_peer_record& add_once_peer : add_once_node_list)
906 {
907 // see if we have an existing connection to that peer. If we do, disconnect them and
908 // then try to connect the next time through the loop
909 peer_connection_ptr existing_connection_ptr = get_connection_to_endpoint( add_once_peer.endpoint );
910 if(!existing_connection_ptr)
911 connect_to_endpoint(add_once_peer.endpoint);
912 }
913 dlog("Done processing \"add once\" node list");
914 }
915
916 while (is_wanting_new_connections())
917 {
918 bool initiated_connection_this_pass = false;
919 _potential_peer_database_updated = false;
920
921 for (peer_database::iterator iter = _potential_peer_db.begin();
922 iter != _potential_peer_db.end() && is_wanting_new_connections();
923 ++iter)
924 {
925 fc::microseconds delay_until_retry = fc::seconds((iter->number_of_failed_connection_attempts + 1) * _peer_connection_retry_timeout);
926
927 if (!is_connection_to_endpoint_in_progress(iter->endpoint) &&
928 ((iter->last_connection_disposition != last_connection_failed &&
929 iter->last_connection_disposition != last_connection_rejected &&
930 iter->last_connection_disposition != last_connection_handshaking_failed) ||
931 (fc::time_point::now() - iter->last_connection_attempt_time) > delay_until_retry))
932 {
933 connect_to_endpoint(iter->endpoint);
934 initiated_connection_this_pass = true;
935 }
936 }
937
938 if (!initiated_connection_this_pass && !_potential_peer_database_updated)
939 break;
940 }
941
942 display_current_connections();

Callers

nothing calls this directly

Calls 4

nowFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected