Skip to content

Commit

Permalink
Sync point
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Feb 15, 2024
1 parent e373de0 commit e742c9d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 54 deletions.
1 change: 1 addition & 0 deletions include/aws/iotdevice/iotdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum aws_iotdevice_error {
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION,
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_PROTOCOL_VERSION_MISMATCH,
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID,
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE,

AWS_ERROR_END_IOTDEVICE_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IOTDEVICE_PACKAGE_ID),
};
Expand Down
6 changes: 5 additions & 1 deletion source/iotdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static struct aws_error_info s_errors[] = {
"Secure Tunnel terminated by user request."),
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DECODE_FAILURE,
"Error occured while decoding an incoming message." ),
"Error occurred while decoding an incoming message." ),
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_DATA_NO_ACTIVE_CONNECTION,
"DATA message processing failed due to no active connection found." ),
Expand All @@ -102,6 +102,10 @@ static struct aws_error_info s_errors[] = {
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_INACTIVE_SERVICE_ID,
"Secure Tunnel operation failed due to using inactive service id." ),
AWS_DEFINE_ERROR_INFO_IOTDEVICE(
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE,
"Error occurred while encoding an outbound message." ),

};
/* clang-format on */
#undef AWS_DEFINE_ERROR_INFO_IOTDEVICE
Expand Down
2 changes: 1 addition & 1 deletion source/linux/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int s_hashfn_foreach_total_iface_transfer_metrics(void *context, struct aws_hash
return AWS_COMMON_HASH_TABLE_ITER_CONTINUE;
}

enum linux_network_connection_state { LINUX_NCS_UNKNOWN = 0, LINUX_NCS_ESTABLISHED = 1, LINUX_NCS_LISTEN = 10 };
enum linux_network_connection_state { LINUX_NCS_UNKNOWN = 0, LINUX_NCS_ESTABLISHED = 1, LINUX_NCS_LISTEN = 10, };

static uint16_t map_network_state(uint16_t linux_state) {
switch (linux_state) {
Expand Down
47 changes: 6 additions & 41 deletions source/secure_tunneling.c
Original file line number Diff line number Diff line change
Expand Up @@ -2168,12 +2168,9 @@ static void s_secure_tunnel_submit_operation_task_fn(struct aws_task *task, void
aws_mem_release(submit_operation_task->allocator, submit_operation_task);
}

static int s_submit_operation(struct aws_secure_tunnel *secure_tunnel, struct aws_secure_tunnel_operation *operation) {
static void s_submit_operation(struct aws_secure_tunnel *secure_tunnel, struct aws_secure_tunnel_operation *operation) {
struct aws_secure_tunnel_submit_operation_task *submit_task =
aws_mem_calloc(secure_tunnel->allocator, 1, sizeof(struct aws_secure_tunnel_submit_operation_task));
if (submit_task == NULL) {
return AWS_OP_ERR;
}

aws_task_init(
&submit_task->task, s_secure_tunnel_submit_operation_task_fn, submit_task, "SecureTunnelSubmitOperation");
Expand All @@ -2182,8 +2179,6 @@ static int s_submit_operation(struct aws_secure_tunnel *secure_tunnel, struct aw
submit_task->operation = operation;

aws_event_loop_schedule_task_now(secure_tunnel->loop, &submit_task->task);

return AWS_OP_SUCCESS;
}

/*********************************************************************************************************************
Expand Down Expand Up @@ -2655,15 +2650,9 @@ int aws_secure_tunnel_send_message(
(void *)secure_tunnel,
(void *)message_op);

if (s_submit_operation(secure_tunnel, &message_op->base)) {
goto error;
}
s_submit_operation(secure_tunnel, &message_op->base);

return AWS_OP_SUCCESS;

error:
aws_secure_tunnel_operation_release(&message_op->base);
return aws_last_error();
}

int aws_secure_tunnel_stream_start(
Expand All @@ -2690,15 +2679,9 @@ int aws_secure_tunnel_stream_start(
(void *)secure_tunnel,
(void *)message_op);

if (s_submit_operation(secure_tunnel, &message_op->base)) {
goto error;
}
s_submit_operation(secure_tunnel, &message_op->base);

return AWS_OP_SUCCESS;

error:
aws_secure_tunnel_operation_release(&message_op->base);
return AWS_OP_ERR;
}

int aws_secure_tunnel_connection_start(
Expand All @@ -2725,15 +2708,9 @@ int aws_secure_tunnel_connection_start(
(void *)secure_tunnel,
(void *)message_op);

if (s_submit_operation(secure_tunnel, &message_op->base)) {
goto error;
}
s_submit_operation(secure_tunnel, &message_op->base);

return AWS_OP_SUCCESS;

error:
aws_secure_tunnel_operation_release(&message_op->base);
return AWS_OP_ERR;
}

/*********************************************************************************************************************
Expand Down Expand Up @@ -2763,15 +2740,9 @@ int aws_secure_tunnel_stream_reset(
(void *)secure_tunnel,
(void *)message_op);

if (s_submit_operation(secure_tunnel, &message_op->base)) {
goto error;
}
s_submit_operation(secure_tunnel, &message_op->base);

return AWS_OP_SUCCESS;

error:
aws_secure_tunnel_operation_release(&message_op->base);
return AWS_OP_ERR;
}

int aws_secure_tunnel_connection_reset(
Expand All @@ -2793,13 +2764,7 @@ int aws_secure_tunnel_connection_reset(
(void *)secure_tunnel,
(void *)message_op);

if (s_submit_operation(secure_tunnel, &message_op->base)) {
goto error;
}
s_submit_operation(secure_tunnel, &message_op->base);

return AWS_OP_SUCCESS;

error:
aws_secure_tunnel_operation_release(&message_op->base);
return AWS_OP_ERR;
}
23 changes: 12 additions & 11 deletions source/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ static int s_iot_st_encode_varint_uint32_t(struct aws_byte_buf *buffer, uint32_t
// 0xFF == b11111111
// 0x80 == b10000000
aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)(n & 0xFF) | 0x80) == AWS_OP_SUCCESS,
AWS_OP_ERR);
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
n = n >> 7;
}
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)n) == AWS_OP_SUCCESS, AWS_OP_ERR);
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)n) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
return AWS_OP_SUCCESS;
}

Expand All @@ -34,7 +34,7 @@ static int s_iot_st_encode_varint_negative_uint32_t(struct aws_byte_buf *buffer,
// 0xFF == b11111111
// 0x80 == b10000000
aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)(n & 0xFF) | 0x80) == AWS_OP_SUCCESS,
AWS_OP_ERR);
AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
n = n >> 7;
byte_count += 1;
}
Expand All @@ -48,11 +48,11 @@ static int s_iot_st_encode_varint_negative_uint32_t(struct aws_byte_buf *buffer,
n = n >> 1;
n = n | 0x80;
}
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)n) == AWS_OP_SUCCESS, AWS_OP_ERR);
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, (uint8_t)n) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
for (int i = 0; i < 10 - byte_count - 2; i++) {
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, 0xFF) == AWS_OP_SUCCESS, AWS_OP_ERR);
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, 0xFF) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
}
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, 0x1) == AWS_OP_SUCCESS, AWS_OP_ERR);
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, 0x1) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
return AWS_OP_SUCCESS;
}

Expand All @@ -72,7 +72,7 @@ static int s_iot_st_encode_varint(
struct aws_byte_buf *buffer) {
const uint8_t field_and_wire_type = (field_number << AWS_IOT_ST_FIELD_NUMBER_SHIFT) + wire_type;
AWS_RETURN_ERROR_IF2(
aws_byte_buf_append_byte_dynamic_secure(buffer, field_and_wire_type) == AWS_OP_SUCCESS, AWS_OP_ERR);
aws_byte_buf_append_byte_dynamic_secure(buffer, field_and_wire_type) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
return s_iot_st_encode_varint_pos(buffer, value);
}

Expand All @@ -82,8 +82,8 @@ static int s_iot_st_encode_byte_range(
const struct aws_byte_cursor *payload,
struct aws_byte_buf *buffer) {
const uint8_t field_and_wire_type = (field_number << AWS_IOT_ST_FIELD_NUMBER_SHIFT) + wire_type;
aws_byte_buf_append_byte_dynamic_secure(buffer, field_and_wire_type);
s_iot_st_encode_varint_uint32_t(buffer, (uint32_t)payload->len);
AWS_RETURN_ERROR_IF2(aws_byte_buf_append_byte_dynamic_secure(buffer, field_and_wire_type) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
AWS_RETURN_ERROR_IF2(s_iot_st_encode_varint_uint32_t(buffer, (uint32_t)payload->len) == AWS_OP_SUCCESS, AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
struct aws_byte_cursor temp = aws_byte_cursor_from_array(payload->ptr, payload->len);
return aws_byte_buf_append_dynamic_secure(buffer, &temp);
}
Expand Down Expand Up @@ -266,6 +266,7 @@ int aws_iot_st_msg_serialize_from_view(
}
} else {
AWS_LOGF_ERROR(AWS_LS_IOTDEVICE_SECURE_TUNNELING, "Message missing type during encoding");
aws_raise_error(AWS_ERROR_IOTDEVICE_SECURE_TUNNELING_ENCODE_FAILURE);
goto cleanup;
}

Expand Down Expand Up @@ -349,7 +350,7 @@ static int s_iot_st_decode_varint_uint32_t(struct aws_byte_cursor *cursor, uint3
return AWS_OP_SUCCESS;
}

int aws_secure_tunnel_deserialize_varint_from_cursor_to_message(
static int s_aws_secure_tunnel_deserialize_varint_from_cursor_to_message(
struct aws_byte_cursor *cursor,
uint8_t field_number,
struct aws_secure_tunnel_message_view *message) {
Expand Down Expand Up @@ -423,7 +424,7 @@ int aws_secure_tunnel_deserialize_message_from_cursor(

switch (wire_type) {
case AWS_SECURE_TUNNEL_PBWT_VARINT:
if (aws_secure_tunnel_deserialize_varint_from_cursor_to_message(cursor, field_number, &message_view)) {
if (s_aws_secure_tunnel_deserialize_varint_from_cursor_to_message(cursor, field_number, &message_view)) {
goto error;
}
break;
Expand Down

0 comments on commit e742c9d

Please sign in to comment.