Skip to content

Commit b933bec

Browse files
committed
bind out network_interface_names_array from connection manager options
1 parent 7a0d9d9 commit b933bec

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

include/aws/crt/http/HttpConnectionManager.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ namespace Aws
5757
* reference to the connection manager.
5858
*/
5959
bool EnableBlockingShutdown;
60+
61+
/**
62+
* THIS IS AN EXPERIMENTAL AND UNSTABLE API
63+
* (Optional)
64+
* An array of network interface names. The manager will distribute the connections across network
65+
* interface names provided in this array. If any interface name is invalid, goes down, or has any
66+
* issues like network access, you will see connection failures. If
67+
* `socket_options.network_interface_name` is also set, an `AWS_ERROR_INVALID_ARGUMENT` error will be
68+
* raised.
69+
*
70+
* This option is only supported on Linux, MacOS, and platforms that have either SO_BINDTODEVICE or
71+
* IP_BOUND_IF. It is not supported on Windows. `AWS_ERROR_PLATFORM_NOT_SUPPORTED` will be raised on
72+
* unsupported platforms.
73+
*/
74+
Vector<ByteCursor> NetworkInterfaces;
6075
};
6176

6277
/**

source/http/HttpConnectionManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ namespace Aws
136136
}
137137
managerOptions.host = aws_byte_cursor_from_c_str(connectionOptions.HostName.c_str());
138138

139+
if (m_options.NetworkInterfaces.size() > 0)
140+
{
141+
managerOptions.network_interface_names_array = m_options.NetworkInterfaces.data();
142+
managerOptions.num_network_interface_names = m_options.NetworkInterfaces.size();
143+
}
144+
139145
m_connectionManager = aws_http_connection_manager_new(allocator, &managerOptions);
140146
}
141147

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ if(NOT BYO_CRYPTO)
9191
add_net_test_case(HttpClientConnectionManagerInvalidTlsConnectionOptions)
9292
add_net_test_case(HttpClientConnectionWithPendingAcquisitions)
9393
add_net_test_case(HttpClientConnectionWithPendingAcquisitionsAndClosedConnections)
94+
add_net_test_case(HttpClientCreateManagerWithNetworkInterfacesList)
9495
add_net_test_case(IotConnectionDestruction)
9596
add_net_test_case(IotConnectionDestructionWithExecutingCallback)
9697
add_net_test_case(IotConnectionDestructionWithinConnectionCallback)

tests/HttpClientConnectionManagerTest.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,69 @@ AWS_TEST_CASE(
447447
HttpClientConnectionWithPendingAcquisitionsAndClosedConnections,
448448
s_TestHttpClientConnectionWithPendingAcquisitionsAndClosedConnections)
449449

450+
static int s_TestHttpClientCreateManagerWithNetworkInterfacesList(struct aws_allocator *allocator, void *ctx)
451+
{
452+
(void)ctx;
453+
{
454+
Aws::Crt::ApiHandle apiHandle(allocator);
455+
456+
Aws::Crt::Io::TlsContextOptions tlsCtxOptions = Aws::Crt::Io::TlsContextOptions::InitDefaultClient();
457+
458+
// Ensure that if PQ TLS ciphers are supported on the current platform, that setting them works when connecting
459+
// to S3. This TlsCipherPreference has post quantum ciphers at the top of it's preference list (that will be
460+
// ignored if S3 doesn't support them) followed by regular TLS ciphers that can be chosen and negotiated by S3.
461+
aws_tls_cipher_pref tls_cipher_pref = AWS_IO_TLS_CIPHER_PREF_PQ_DEFAULT;
462+
463+
if (aws_tls_is_cipher_pref_supported(tls_cipher_pref))
464+
{
465+
tlsCtxOptions.SetTlsCipherPreference(tls_cipher_pref);
466+
}
467+
468+
Aws::Crt::Io::TlsContext tlsContext(tlsCtxOptions, Aws::Crt::Io::TlsMode::CLIENT, allocator);
469+
ASSERT_TRUE(tlsContext);
470+
471+
Aws::Crt::Io::TlsConnectionOptions tlsConnectionOptions = tlsContext.NewConnectionOptions();
472+
473+
ByteCursor cursor = ByteCursorFromCString("https://s3.amazonaws.com");
474+
Io::Uri uri(cursor, allocator);
475+
476+
auto hostName = uri.GetHostName();
477+
tlsConnectionOptions.SetServerName(hostName);
478+
479+
Aws::Crt::Io::SocketOptions socketOptions;
480+
socketOptions.SetConnectTimeoutMs(10000);
481+
482+
Aws::Crt::Io::EventLoopGroup eventLoopGroup(1, allocator);
483+
ASSERT_TRUE(eventLoopGroup);
484+
485+
Aws::Crt::Io::DefaultHostResolver defaultHostResolver(eventLoopGroup, 8, 30, allocator);
486+
ASSERT_TRUE(defaultHostResolver);
487+
488+
Aws::Crt::Io::ClientBootstrap clientBootstrap(eventLoopGroup, defaultHostResolver, allocator);
489+
ASSERT_TRUE(clientBootstrap);
490+
clientBootstrap.EnableBlockingShutdown();
491+
Http::HttpClientConnectionOptions connectionOptions;
492+
connectionOptions.Bootstrap = &clientBootstrap;
493+
connectionOptions.SocketOptions = socketOptions;
494+
connectionOptions.TlsOptions = tlsConnectionOptions;
495+
connectionOptions.HostName = String((const char *)hostName.ptr, hostName.len);
496+
connectionOptions.Port = 443;
497+
498+
Http::HttpClientConnectionManagerOptions connectionManagerOptions;
499+
connectionManagerOptions.ConnectionOptions = connectionOptions;
500+
connectionManagerOptions.MaxConnections = 30;
501+
connectionManagerOptions.EnableBlockingShutdown = true;
502+
503+
Vector<ByteCursor> networkInterfaces{ByteCursorFromCString("eth0"), ByteCursorFromCString("eth1")};
504+
connectionManagerOptions.NetworkInterfaces = networkInterfaces;
505+
506+
auto connectionManager =
507+
Http::HttpClientConnectionManager::NewClientConnectionManager(connectionManagerOptions, allocator);
508+
ASSERT_TRUE(connectionManager);
509+
}
510+
return AWS_OP_SUCCESS;
511+
}
512+
513+
AWS_TEST_CASE(HttpClientCreateManagerWithNetworkInterfacesList, s_TestHttpClientCreateManagerWithNetworkInterfacesList)
514+
450515
#endif // !BYO_CRYPTO

0 commit comments

Comments
 (0)