MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / string_to_endpoint

Method string_to_endpoint

src/Chain/libraries/client/Client.cpp:1916–1946  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1914 }
1915
1916 std::vector<fc::ip::endpoint> Client::string_to_endpoint(const std::string& remote_endpoint) {
1917 try {
1918 ASSERT_TASK_NOT_PREEMPTED(); // make sure no cancel gets swallowed by catch(...)
1919 // first, try and parse the endpoint as a numeric_ipv4_address:port that doesn't need DNS lookup
1920 std::vector<fc::ip::endpoint> endpoints;
1921 endpoints.push_back(fc::ip::endpoint::from_string(remote_endpoint));
1922 return endpoints;
1923
1924 } catch (...) {
1925 }
1926
1927 // couldn't parse as a numeric ip address, try resolving as a DNS name. This can yield, so don't
1928 // do it in the catch block above
1929 string::size_type colon_pos = remote_endpoint.find(':');
1930
1931 try {
1932 uint16_t port = boost::lexical_cast<uint16_t>(remote_endpoint.substr(colon_pos + 1, remote_endpoint.size()));
1933 string hostname = remote_endpoint.substr(0, colon_pos);
1934 std::vector<fc::ip::endpoint> endpoints = fc::resolve(hostname, port);
1935
1936 if (endpoints.empty())
1937 FC_THROW_EXCEPTION(fc::unknown_host_exception, "The host name can not be resolved: ${hostname}", ("hostname", hostname));
1938
1939 std::random_shuffle(endpoints.begin(), endpoints.end());
1940
1941 return endpoints;
1942
1943 } catch (const boost::bad_lexical_cast&) {
1944 FC_THROW("Bad port: ${port}", ("port", remote_endpoint.substr(colon_pos + 1, remote_endpoint.size())));
1945 }
1946 }
1947
1948 void Client::add_node(const string& remote_endpoint, int32_t oper_flag) {
1949

Callers

nothing calls this directly

Calls 10

from_stringFunction · 0.85
resolveClass · 0.50
random_shuffleClass · 0.50
push_backMethod · 0.45
findMethod · 0.45
substrMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected