Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To support VSOCK, stop limiting port to 16 bits. #733

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crt/aws-c-auth
2 changes: 1 addition & 1 deletion crt/aws-c-common
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void onConnectionResumed(boolean sessionPresent) {
// Set all the settings
tlsOptions.overrideDefaultTrustStoreFromPath(null, caFilePath);
config.setEndpoint(endpoint);
config.setPort((short)port);
config.setPort(port);
config.setClientId(clientId);
config.setCleanSession(true);
config.setProtocolOperationTimeoutMs(60000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public ClientConnectionContinuation newStream(final ClientConnectionContinuation
* @param connectionHandler handler to process connection messages and state changes.
* @return The future will be completed once the connection either succeeds or fails.
*/
public static CompletableFuture<Void> connect(final String hostName, short port, final SocketOptions socketOptions,
public static CompletableFuture<Void> connect(final String hostName, int port, final SocketOptions socketOptions,
final ClientTlsContext tlsContext, final ClientBootstrap bootstrap,
final ClientConnectionHandler connectionHandler) {
long tlsContextHandle = tlsContext != null ? tlsContext.getNativeHandle() : 0;
Expand Down Expand Up @@ -196,7 +196,7 @@ protected boolean canReleaseReferencesImmediately() {
return true;
}

private static native int clientConnect(byte[] hostName, short port, long socketOptions, long tlsContext, long bootstrap, ClientConnectionHandler connectionHandler);
private static native int clientConnect(byte[] hostName, int port, long socketOptions, long tlsContext, long bootstrap, ClientConnectionHandler connectionHandler);
private static native boolean isClientConnectionOpen(long connection);
private static native void closeClientConnection(long connection, int errorCode);
private static native void acquireClientConnection(long connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ServerListener extends CrtResource {
* @param serverBootstrap bootstrap object for handling connections.
* @param handler functor interface for handling incoming connections and connection closures.
*/
public ServerListener(final String hostName, short port, final SocketOptions socketOptions,
public ServerListener(final String hostName, int port, final SocketOptions socketOptions,
final ServerTlsContext tlsContext, final ServerBootstrap serverBootstrap,
final ServerListenerHandler handler) {

Expand Down Expand Up @@ -87,7 +87,7 @@ private void onShutdownComplete() {
public CompletableFuture<Void> getShutdownCompleteFuture() { return shutdownComplete; }

private static native long serverListenerNew(ServerListener serverListener, byte[] hostName,
short port, long socketOptionsHandle,
int port, long socketOptionsHandle,
long tlsContextHandle, long bootstrapHandle,
ServerListenerHandler handler);
private static native int getBoundPort(long serverListener);
Expand Down
4 changes: 2 additions & 2 deletions src/native/credentials_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ JNIEXPORT jlong JNICALL
proxy_connection_type,
&proxy_tls_connection_options,
jni_proxy_host,
(uint16_t)jni_proxy_port,
jni_proxy_port,
jni_proxy_authorization_username,
jni_proxy_authorization_password,
jni_proxy_authorization_type,
Expand Down Expand Up @@ -739,7 +739,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_auth_credentials_CognitoCredential
proxy_connection_type,
&proxy_tls_connection_options,
proxy_host,
(uint16_t)proxy_port,
proxy_port,
proxy_authorization_username,
proxy_authorization_password,
proxy_authorization_type,
Expand Down
4 changes: 2 additions & 2 deletions src/native/event_stream_rpc_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jint JNICALL Java_software_amazon_awssdk_crt_eventstream_ClientConnection_client
JNIEnv *env,
jclass jni_class,
jbyteArray jni_host_name,
jshort port,
jint port,
jlong jni_socket_options,
jlong jni_tls_ctx,
jlong jni_client_bootstrap,
Expand Down Expand Up @@ -221,7 +221,7 @@ jint JNICALL Java_software_amazon_awssdk_crt_eventstream_ClientConnection_client
.socket_options = socket_options,
.tls_options = conn_options_ptr,
.user_data = callback_data,
.port = (uint16_t)port,
.port = (uint32_t)port,
graebm marked this conversation as resolved.
Show resolved Hide resolved
.bootstrap = client_bootstrap,
.host_name = c_str_host_name,
.on_connection_setup = s_on_connection_setup,
Expand Down
6 changes: 3 additions & 3 deletions src/native/event_stream_rpc_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_eventstream_ServerListener_serverL
jclass jni_class,
jobject jni_server_listener,
jbyteArray jni_host_name,
jshort port,
jint port,
jlong jni_socket_options,
jlong jni_tls_ctx,
jlong jni_server_bootstrap,
Expand Down Expand Up @@ -552,7 +552,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_eventstream_ServerListener_serverL
.on_destroy_callback = s_server_listener_shutdown_complete,
.bootstrap = server_bootstrap,
.tls_options = conn_options_ptr,
.port = port,
.port = (uint32_t)port,
.host_name = c_str_host_name,
.user_data = callback_data,
.on_new_connection = s_on_new_connection_fn,
Expand Down Expand Up @@ -598,7 +598,7 @@ jint JNICALL Java_software_amazon_awssdk_crt_eventstream_ServerListener_getBound
(struct aws_event_stream_rpc_server_listener *)jni_server_listener;
if (!listener) {
aws_jni_throw_runtime_exception(env, "ServerListener.getBoundPort: Invalid serverListener");
return (jshort)-1;
return -1;
}

return (jint)aws_event_stream_rpc_server_listener_get_bound_port(listener);
Expand Down
8 changes: 4 additions & 4 deletions src/native/http2_stream_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_

struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_endpoint);

if (jni_port <= 0 || 65535 < jni_port) {
aws_jni_throw_illegal_argument_exception(env, "Port must be between 1 and 65535");
if (jni_port == 0) {
graebm marked this conversation as resolved.
Show resolved Hide resolved
aws_jni_throw_illegal_argument_exception(env, "Port must not be 0");
goto cleanup;
}

Expand All @@ -165,7 +165,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_
goto cleanup;
}

uint16_t port = (uint16_t)jni_port;
uint32_t port = (uint32_t)jni_port;

bool new_tls_conn_opts = (jni_tls_ctx != 0 && !tls_connection_options);

Expand Down Expand Up @@ -229,7 +229,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_
jni_proxy_connection_type,
&proxy_tls_conn_options,
jni_proxy_host,
(uint16_t)jni_proxy_port,
jni_proxy_port,
jni_proxy_authorization_username,
jni_proxy_authorization_password,
jni_proxy_authorization_type,
Expand Down
9 changes: 2 additions & 7 deletions src/native/http_connection_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
struct aws_allocator *allocator = aws_jni_get_allocator();
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_endpoint);

if (jni_port <= 0 || 65535 < jni_port) {
graebm marked this conversation as resolved.
Show resolved Hide resolved
aws_jni_throw_runtime_exception(env, "Port must be between 1 and 65535");
goto cleanup;
}

size_t window_size;
if (aws_size_t_from_java(env, &window_size, jni_window_size, "Initial window size")) {
goto cleanup;
Expand All @@ -156,7 +151,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
goto cleanup;
}

uint16_t port = (uint16_t)jni_port;
uint32_t port = (uint32_t)jni_port;

bool new_tls_conn_opts = (jni_tls_ctx != 0 && !tls_connection_options);

Expand Down Expand Up @@ -216,7 +211,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
jni_proxy_connection_type,
&proxy_tls_conn_options,
jni_proxy_host,
(uint16_t)jni_proxy_port,
jni_proxy_port,
jni_proxy_authorization_username,
jni_proxy_authorization_password,
jni_proxy_authorization_type,
Expand Down
4 changes: 2 additions & 2 deletions src/native/http_proxy_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void aws_http_proxy_options_jni_init(
jint proxy_connection_type,
struct aws_tls_connection_options *tls_options,
jbyteArray proxy_host,
uint16_t proxy_port,
jint proxy_port,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
int proxy_authorization_type,
Expand All @@ -39,7 +39,7 @@ void aws_http_proxy_options_jni_init(
struct aws_allocator *allocator = aws_jni_get_allocator();

options->connection_type = proxy_connection_type;
options->port = proxy_port;
options->port = (uint32_t)proxy_port;
options->auth_type = proxy_authorization_type;

if (proxy_host != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/native/http_proxy_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void aws_http_proxy_options_jni_init(
jint proxy_connection_type,
struct aws_tls_connection_options *tls_options,
jbyteArray proxy_host,
uint16_t proxy_port,
jint proxy_port,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
int proxy_authorization_type,
Expand Down
15 changes: 3 additions & 12 deletions src/native/mqtt5_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,7 @@ static struct aws_http_proxy_options_java_jni *s_aws_mqtt5_http_proxy_options_cr
goto on_error;
}
if (jni_proxy_port) {
int32_t jni_proxy_port_check = (int32_t)jni_proxy_port;
if (jni_proxy_port_check < 0) {
AWS_LOGF_ERROR(AWS_LS_MQTT_CLIENT, "HTTP Proxy Options port is less than 0");
goto on_error;
} else if (jni_proxy_port_check > UINT16_MAX) {
AWS_LOGF_ERROR(AWS_LS_MQTT_CLIENT, "HTTP Proxy Options port is more than UINT16_MAX");
goto on_error;
} else {
http_options->options.port = (uint16_t)jni_proxy_port;
}
http_options->options.port = (uint32_t)jni_proxy_port;
}

jobject jni_proxy_tls_context = (*env)->CallObjectMethod(
Expand Down Expand Up @@ -1743,8 +1734,8 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_mqtt5_Mqtt5Client_mqtt5C
goto clean_up;
}

uint16_t port = 0;
if (aws_get_uint16_from_jobject(
uint32_t port = 0;
if (aws_get_uint32_from_jobject(
env,
jni_options,
mqtt5_client_options_properties.options_port_field_id,
Expand Down
7 changes: 3 additions & 4 deletions src/native/mqtt_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,11 @@ void JNICALL Java_software_amazon_awssdk_crt_mqtt_MqttClientConnection_mqttClien
struct aws_byte_cursor client_id;
AWS_ZERO_STRUCT(client_id);
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jstring_acquire(env, jni_endpoint);
uint16_t port = (uint16_t)jni_port;
uint32_t port = (uint32_t)jni_port;
if (!port) {
aws_jni_throw_runtime_exception(
env,
"MqttClientConnection.mqtt_new: Endpoint should be in the format hostname:port and port must be between 1 "
"and 65535");
"MqttClientConnection.mqtt_new: Endpoint should be in the format hostname:port and port must not be 0");
goto cleanup;
}

Expand Down Expand Up @@ -1327,7 +1326,7 @@ void JNICALL Java_software_amazon_awssdk_crt_mqtt_MqttClientConnection_mqttClien
proxy_options.connection_type = (enum aws_http_proxy_connection_type)jni_proxy_connection_type;

proxy_options.host = aws_jni_byte_cursor_from_jstring_acquire(env, jni_proxy_host);
proxy_options.port = (uint16_t)jni_proxy_port;
proxy_options.port = (uint32_t)jni_proxy_port;

proxy_options.auth_type = (enum aws_http_proxy_authentication_type)jni_proxy_authorization_type;

Expand Down
2 changes: 1 addition & 1 deletion src/native/s3_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew(
jni_proxy_connection_type,
&proxy_tls_conn_options,
jni_proxy_host,
(uint16_t)jni_proxy_port,
jni_proxy_port,
jni_proxy_authorization_username,
jni_proxy_authorization_password,
jni_proxy_authorization_type,
Expand Down
Loading