Skip to content

Commit d9f4db8

Browse files
Prefer IP4 than IP6 when both are available
1 parent ec89359 commit d9f4db8

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

python/example/fetpapi.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
" sleep(0.25)\t\n",
132132
"if client_session.isEtpSessionClosed():\n",
133133
" print(\"The ETP session could not be established in 5 seconds.\")\n",
134+
" if not etp_server_url.endswith(\"/\"):\n",
135+
" print(\"You may try adding an ending slash to your ETP server URL.\")\n",
134136
"else:\n",
135137
" print(\"Now connected to ETP Server\")"
136138
]

src/etp/HttpClientSession.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ namespace ETP_NS
9595
return;
9696
}
9797

98+
// Reality check: IPv6 is unlikely to be available yet
99+
std::vector<tcp::endpoint> endpoints(results.begin(), results.end());
100+
std::stable_partition(endpoints.begin(), endpoints.end(), [](auto entry) {return entry.protocol() == tcp::v4(); });
101+
98102
// Make the connection on the IP address we get from a lookup
99103
boost::asio::async_connect(
100104
socket_,
101-
results.begin(),
102-
results.end(),
105+
endpoints.begin(),
106+
endpoints.end(),
103107
std::bind(
104108
&HttpClientSession::on_connect,
105109
shared_from_this(),

src/etp/PlainClientSession.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ namespace ETP_NS
4545
std::cerr << "on_resolve : " << ec.message() << std::endl;
4646
}
4747

48+
// Reality check: IPv6 is unlikely to be available yet
49+
std::vector<tcp::endpoint> endpoints(results.begin(), results.end());
50+
std::stable_partition(endpoints.begin(), endpoints.end(), [](auto entry) {return entry.protocol() == tcp::v4(); });
51+
4852
// Make the connection on the IP address we get from a lookup
4953
boost::asio::async_connect(
5054
ws_.next_layer(),
51-
results.begin(),
52-
results.end(),
55+
endpoints.begin(),
56+
endpoints.end(),
5357
std::bind(
5458
&AbstractClientSessionCRTP::on_connect,
5559
std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this()),

src/etp/ssl/HttpsClientSession.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,15 @@ namespace ETP_NS
122122
return;
123123
}
124124

125+
// Reality check: IPv6 is unlikely to be available yet
126+
std::vector<tcp::endpoint> endpoints(results.begin(), results.end());
127+
std::stable_partition(endpoints.begin(), endpoints.end(), [](auto entry) {return entry.protocol() == tcp::v4();});
128+
125129
// Make the connection on the IP address we get from a lookup
126130
boost::asio::async_connect(
127131
stream_.next_layer(),
128-
results.begin(),
129-
results.end(),
132+
endpoints.begin(),
133+
endpoints.end(),
130134
std::bind(
131135
&HttpsClientSession::on_connect,
132136
shared_from_this(),

src/etp/ssl/SslClientSession.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ namespace ETP_NS
6666
std::cerr << "on_resolve : " << ec.message() << std::endl;
6767
}
6868

69+
// Reality check: IPv6 is unlikely to be available yet
70+
std::vector<tcp::endpoint> endpoints(results.begin(), results.end());
71+
std::stable_partition(endpoints.begin(), endpoints.end(), [](auto entry) {return entry.protocol() == tcp::v4(); });
72+
6973
// Make the connection on the IP address we get from a lookup
7074
boost::asio::async_connect(
7175
ws_.next_layer().next_layer(),
72-
results.begin(),
73-
results.end(),
76+
endpoints.begin(),
77+
endpoints.end(),
7478
std::bind(
7579
&SslClientSession::on_ssl_connect,
7680
std::static_pointer_cast<SslClientSession>(shared_from_this()),

0 commit comments

Comments
 (0)