Skip to content

Commit

Permalink
Merge branch 'main' into update-cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Oct 17, 2024
2 parents 91c7837 + 188cff7 commit e928d6e
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'docs'

env:
BUILDER_VERSION: v0.9.56
BUILDER_VERSION: v0.9.63
BUILDER_SOURCE: releases
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
PACKAGE_NAME: aws-crt-cpp
Expand Down
44 changes: 29 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,36 @@ if(BUILD_DEPS)

if(UNIX AND NOT APPLE AND NOT BYO_CRYPTO)
if(NOT USE_OPENSSL)
set(DISABLE_PERL ON CACHE BOOL "Disable Perl for AWS-LC.")
set(DISABLE_GO ON CACHE BOOL "Disable Go for AWS-LC.")
set(BUILD_LIBSSL OFF CACHE BOOL "Build libssl for AWS-LC.")
include(AwsPrebuildDependency)

# temporarily disable certain warnings as errors for the aws-lc build
set(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(AWSLC_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

# temporarily disable certain warnings as errors for the aws-lc build
if(NOT MSVC)
check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW)

if(HAS_WNO_STRINGOP_OVERFLOW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-stringop-overflow")
set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-stringop-overflow")
endif()

check_c_compiler_flag(-Wno-array-parameter HAS_WNO_ARRAY_PARAMETER)

if(HAS_WNO_ARRAY_PARAMETER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-parameter")
set(AWSLC_CMAKE_C_FLAGS "${AWSLC_CMAKE_C_FLAGS} -Wno-array-parameter")
endif()
endif()

add_subdirectory(crt/aws-lc)

# restore previous build flags
set(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}")

set(SEARCH_LIBCRYPTO OFF CACHE BOOL "Let S2N use libcrypto from AWS-LC.")
else()
set(SEARCH_LIBCRYPTO ON CACHE BOOL "Let S2N search libcrypto in the system.")
# s2n-tls uses libcrypto during its configuration, so we need to prebuild aws-lc.
prebuild_dependency(
DEPENDENCY_NAME AWSLC
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/crt/aws-lc
CMAKE_ARGUMENTS
-DDISABLE_GO=ON
-DDISABLE_PERL=ON
-DBUILD_LIBSSL=OFF
-DBUILD_TESTING=OFF
-DCMAKE_C_FLAGS=${AWSLC_CMAKE_C_FLAGS}
)
endif()

set(UNSAFE_TREAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Disable warnings-as-errors when building S2N")
Expand Down Expand Up @@ -143,6 +144,10 @@ file(GLOB AWS_CRT_AUTH_HEADERS
"include/aws/crt/auth/*.h"
)

file(GLOB AWS_CRT_CHECKSUM_HEADERS
"include/aws/crt/checksum/*.h"
)

file(GLOB AWS_CRT_CRYPTO_HEADERS
"include/aws/crt/crypto/*.h"
)
Expand Down Expand Up @@ -174,6 +179,7 @@ file(GLOB AWS_CRT_CBOR_HEADERS
file(GLOB AWS_CRT_PUBLIC_HEADERS
${AWS_CRT_HEADERS}
${AWS_CRT_AUTH_HEADERS}
${AWS_CRT_CHECKSUM_HEADERS}
${AWS_CRT_CRYPTO_HEADERS}
${AWS_CRT_IO_HEADERS}
${AWS_CRT_IOT_HEADERS}
Expand All @@ -200,6 +206,10 @@ file(GLOB AWS_CRT_AUTH_SRC
"source/auth/*.cpp"
)

file(GLOB AWS_CRT_CHECKSUM_SRC
"source/checksum/*.cpp"
)

file(GLOB AWS_CRT_CRYPTO_SRC
"source/crypto/*.cpp"
)
Expand Down Expand Up @@ -231,6 +241,7 @@ file(GLOB AWS_CRT_CBOR_SRC
file(GLOB AWS_CRT_CPP_SRC
${AWS_CRT_SRC}
${AWS_CRT_AUTH_SRC}
${AWS_CRT_CHECKSUM_SRC}
${AWS_CRT_CRYPTO_SRC}
${AWS_CRT_IO_SRC}
${AWS_CRT_IOT_SRC}
Expand All @@ -244,6 +255,7 @@ if(WIN32)
if(MSVC)
source_group("Header Files\\aws\\crt" FILES ${AWS_CRT_HEADERS})
source_group("Header Files\\aws\\crt\\auth" FILES ${AWS_CRT_AUTH_HEADERS})
source_group("Header Files\\aws\\crt\\checksum" FILES ${AWS_CRT_CHECKSUM_HEADERS})
source_group("Header Files\\aws\\crt\\crypto" FILES ${AWS_CRT_CRYPTO_HEADERS})
source_group("Header Files\\aws\\crt\\io" FILES ${AWS_CRT_IO_HEADERS})
source_group("Header Files\\aws\\iot" FILES ${AWS_CRT_IOT_HEADERS})
Expand All @@ -254,6 +266,7 @@ if(WIN32)

source_group("Source Files" FILES ${AWS_CRT_SRC})
source_group("Source Files\\auth" FILES ${AWS_CRT_AUTH_SRC})
source_group("Source Files\\checksum" FILES ${AWS_CRT_CHECKSUM_SRC})
source_group("Source Files\\crypto" FILES ${AWS_CRT_CRYPTO_SRC})
source_group("Source Files\\io" FILES ${AWS_CRT_IO_SRC})
source_group("Source Files\\iot" FILES ${AWS_CRT_IOT_SRC})
Expand Down Expand Up @@ -325,6 +338,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS})

install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development)
install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "include/aws/crt/auth" COMPONENT Development)
install(FILES ${AWS_CRT_CHECKSUM_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development)
install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development)
install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io" COMPONENT Development)
install(FILES ${AWS_CRT_IOT_HEADERS} DESTINATION "include/aws/iot" COMPONENT Development)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.27.6
0.28.3
2 changes: 1 addition & 1 deletion crt/aws-c-cal
2 changes: 1 addition & 1 deletion crt/aws-c-mqtt
Submodule aws-c-mqtt updated 40 files
+1 −1 .github/workflows/ci.yml
+18 −10 CMakeLists.txt
+29 −0 bin/elastishadow/CMakeLists.txt
+1,272 −0 bin/elastishadow/main.c
+12 −0 include/aws/mqtt/mqtt.h
+54 −0 include/aws/mqtt/private/client_impl.h
+24 −0 include/aws/mqtt/private/client_impl_shared.h
+204 −0 include/aws/mqtt/private/mqtt311_listener.h
+220 −0 include/aws/mqtt/private/request-response/protocol_adapter.h
+23 −0 include/aws/mqtt/private/request-response/request_response_client.h
+264 −0 include/aws/mqtt/private/request-response/subscription_manager.h
+2 −0 include/aws/mqtt/private/shared.h
+274 −0 include/aws/mqtt/request-response/request_response_client.h
+3 −0 include/aws/mqtt/v5/mqtt5_client.h
+176 −58 source/client.c
+6 −0 source/client_channel_handler.c
+9 −0 source/client_impl_shared.c
+34 −0 source/mqtt.c
+329 −0 source/mqtt311_listener.c
+964 −0 source/request-response/protocol_adapter.c
+2,276 −0 source/request-response/request_response_client.c
+822 −0 source/request-response/subscription_manager.c
+1 −1 source/shared.c
+1 −1 source/v5/mqtt5_client.c
+1 −0 source/v5/mqtt5_listener.c
+14 −0 source/v5/mqtt5_to_mqtt3_adapter.c
+135 −3 tests/CMakeLists.txt
+1,784 −0 tests/request-response/protocol_adapter_tests.c
+3,151 −0 tests/request-response/request_response_client_tests.c
+2,877 −0 tests/request-response/subscription_manager_tests.c
+739 −998 tests/v3/connection_state_test.c
+488 −0 tests/v3/mqtt311_listener_test.c
+582 −0 tests/v3/mqtt311_testing_utils.c
+155 −0 tests/v3/mqtt311_testing_utils.h
+51 −2 tests/v3/mqtt_mock_server_handler.c
+18 −0 tests/v3/mqtt_mock_server_handler.h
+18 −40 tests/v5/mqtt5_client_tests.c
+26 −0 tests/v5/mqtt5_testing_utils.c
+20 −0 tests/v5/mqtt5_testing_utils.h
+0 −4 tests/v5/mqtt5_to_mqtt3_adapter_tests.c
2 changes: 1 addition & 1 deletion crt/aws-lc
2 changes: 1 addition & 1 deletion crt/s2n
Submodule s2n updated from 79c0f1 to ffe0bf
3 changes: 2 additions & 1 deletion include/aws/crt/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <iterator>
#include <limits>
#include <stddef.h>
#include <string>
#include <type_traits>

#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
Expand Down Expand Up @@ -859,6 +860,6 @@ namespace std
const Aws::Crt::basic_string_view<CharT, Traits> &val) const noexcept
{
auto str = std::basic_string<CharT, Traits>(val.data(), val.size());
return std::hash<std::basic_string<CharT, Traits>>()(str);
return std::hash<std::basic_string<CharT, Traits>>{}(str);
}
} // namespace std
2 changes: 1 addition & 1 deletion include/aws/crt/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Aws
{
using VariantIndex = short;

template <typename T, typename Last> constexpr VariantIndex GetIndexOf(VariantIndex curIndex = -1)
template <typename T, typename Last> constexpr VariantIndex GetIndexOf(VariantIndex curIndex = 0)
{
return std::is_same<T, Last>::value ? curIndex : -1;
}
Expand Down
39 changes: 39 additions & 0 deletions include/aws/crt/checksum/CRC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/crt/Exports.h>
#include <aws/crt/Types.h>

namespace Aws
{
namespace Crt
{
namespace Checksum
{
/**
* The entry point function to perform a CRC32 (Ethernet, gzip) computation.
* Selects a suitable implementation based on hardware capabilities.
* Pass previousCRC32 if updating a running checksum.
*/
uint32_t AWS_CRT_CPP_API ComputeCRC32(ByteCursor input, uint32_t previousCRC32 = 0) noexcept;

/**
* The entry point function to perform a Castagnoli CRC32c (iSCSI) computation.
* Selects a suitable implementation based on hardware capabilities.
* Pass previousCRC32C if updating a running checksum.
*/
uint32_t AWS_CRT_CPP_API ComputeCRC32C(ByteCursor input, uint32_t previousCRC32C = 0) noexcept;

/**
* The entry point function to perform a CRC64-NVME (a.k.a. CRC64-Rocksoft) computation.
* Selects a suitable implementation based on hardware capabilities.
* Pass previousCRC64NVME if updating a running checksum.
* There are many variants of CRC64 algorithms. This CRC64 variant is bit-reflected (based on
* the non bit-reflected polynomial 0xad93d23594c93659) and inverts the CRC input and output bits.
*/
uint64_t AWS_CRT_CPP_API ComputeCRC64NVME(ByteCursor input, uint64_t previousCRC64NVME = 0) noexcept;
} // namespace Checksum
} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/crypto/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace Aws

/**
* Complete the hash computation and write the final digest to output.
* This cannote be called more than once.
* This cannot be called more than once.
* If truncate_to is something other than 0, the output must be truncated to that number of bytes.
* Raise an AWS error and return false to indicate failure.
*/
Expand Down
24 changes: 24 additions & 0 deletions include/aws/crt/io/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ namespace Aws
*/
virtual bool ReadImpl(ByteBuf &buffer) noexcept = 0;

/***
* Read up-to buffer::capacity - buffer::len immediately available bytes into buffer::buffer
* Increment buffer::len by the amount you read in.
*
* @return true if nothing went wrong.
* Return true even if you read 0 bytes because the end-of-file has been reached.
* Return true even if you read 0 bytes because data is not currently available.
*
* Return false if an actual failure condition occurs,
* you SHOULD also raise an error via aws_raise_error().
*/
virtual bool ReadSomeImpl(ByteBuf &buffer) noexcept = 0;

/**
* @return the current status of the stream.
*/
Expand All @@ -136,6 +149,15 @@ namespace Aws
*/
virtual bool SeekImpl(int64_t offset, StreamSeekBasis seekBasis) noexcept = 0;

/**
* Peeks the stream
*
* Essentially calls peek on the underlying istream
*
* @return return value of the underlying istream::peek
*/
virtual int64_t PeekImpl() const noexcept = 0;

private:
static int s_Seek(aws_input_stream *stream, int64_t offset, enum aws_stream_seek_basis basis);
static int s_Read(aws_input_stream *stream, aws_byte_buf *dest);
Expand All @@ -161,9 +183,11 @@ namespace Aws

protected:
bool ReadImpl(ByteBuf &buffer) noexcept override;
bool ReadSomeImpl(ByteBuf &buffer) noexcept override;
StreamStatus GetStatusImpl() const noexcept override;
int64_t GetLengthImpl() const noexcept override;
bool SeekImpl(OffsetType offsetType, StreamSeekBasis seekBasis) noexcept override;
int64_t PeekImpl() const noexcept override;

private:
std::shared_ptr<Aws::Crt::Io::IStream> m_stream;
Expand Down
9 changes: 9 additions & 0 deletions include/aws/iot/Mqtt5Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ namespace Aws
*/
Mqtt5ClientBuilder &WithCertificateAuthority(const Crt::ByteCursor &cert) noexcept;

/**
* Overrides the socket properties of the underlying MQTT connections made by the client. Leave undefined
* to use defaults (no TCP keep alive, 10 second socket timeout).
*
* @param socketOptions - The socket properties of the underlying MQTT connections made by the client
* @return - The Mqtt5ClientBuilder
*/
Mqtt5ClientBuilder &WithSocketOptions(Crt::Io::SocketOptions socketOptions) noexcept;

/**
* Sets http proxy options.
*
Expand Down
32 changes: 32 additions & 0 deletions source/checksum/CRC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/crt/checksum/CRC.h>

#include <aws/checksums/crc.h>

namespace Aws
{
namespace Crt
{
namespace Checksum
{
uint32_t ComputeCRC32(ByteCursor input, uint32_t previousCRC32) noexcept
{
return aws_checksums_crc32_ex(input.ptr, input.len, previousCRC32);
}

uint32_t ComputeCRC32C(ByteCursor input, uint32_t previousCRC32C) noexcept
{
return aws_checksums_crc32c_ex(input.ptr, input.len, previousCRC32C);
}

uint64_t ComputeCRC64NVME(ByteCursor input, uint64_t previousCRC64NVME) noexcept
{
return aws_checksums_crc64nvme_ex(input.ptr, input.len, previousCRC64NVME);
}

} // namespace Checksum
} // namespace Crt
} // namespace Aws
26 changes: 26 additions & 0 deletions source/io/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <aws/crt/StlAllocator.h>
#include <aws/crt/io/Stream.h>
#include <iostream>

#include <aws/io/stream.h>

Expand Down Expand Up @@ -150,6 +151,26 @@ namespace Aws
return status.is_valid && !status.is_end_of_stream;
}

bool StdIOStreamInputStream::ReadSomeImpl(ByteBuf &buffer) noexcept
{
// I have no idea why "readsome() doesn't work at all" for the original dev. It works well for me
// Jokes aside, read will always block and try to read till eof
// readsome will return available bytes without waiting for eof and without closing the stream.
auto actuallyRead = m_stream->readsome(
reinterpret_cast<char *>(buffer.buffer + buffer.len), buffer.capacity - buffer.len);

buffer.len += static_cast<size_t>(actuallyRead);

if (actuallyRead > 0 || (actuallyRead == 0 && m_stream->eof()))
{
return true;
}

auto status = GetStatusImpl();

return status.is_valid && !status.is_end_of_stream;
}

StreamStatus StdIOStreamInputStream::GetStatusImpl() const noexcept
{
StreamStatus status;
Expand Down Expand Up @@ -206,6 +227,11 @@ namespace Aws

return true;
}

int64_t StdIOStreamInputStream::PeekImpl() const noexcept
{
return m_stream->peek();
}
} // namespace Io
} // namespace Crt
} // namespace Aws
6 changes: 6 additions & 0 deletions source/iot/Mqtt5Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ namespace Aws
return *this;
}

Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithSocketOptions(Crt::Io::SocketOptions socketOptions) noexcept
{
m_options->WithSocketOptions(std::move(socketOptions));
return *this;
}

Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithHttpProxyOptions(
const Crt::Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept
{
Expand Down
Loading

0 comments on commit e928d6e

Please sign in to comment.