Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

initial PR to toggle quic support and add esp threading #63

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
40 changes: 30 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ project(quicr-transport
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(QTRANSPORT_BUILD_TESTS "Build tests for quicr transport" ON)
else()
option(QTRANSPORT_BUILD_TESTS "Build tests for quicr trasnsport" OFF)
option(QTRANSPORT_BUILD_TESTS "Build tests for quicr transport" OFF)
endif()

option(PLATFORM_ESP_IDF "Enabble suppport for esp-idf (Default OFF)" OFF)

find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
if (NOT PLATFORM_ESP_IDF)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
endif()

###
### Dependencies
Expand All @@ -24,16 +27,33 @@ add_subdirectory(dependencies)
###
### Main code
###
add_library(quicr-transport
src/transport.cpp
src/transport_udp.cpp
src/transport_picoquic.cpp
)

set (sources
src/transport.cpp
src/transport_udp.cpp
)

if (NOT PLATFORM_ESP_IDF)
list(APPEND sources src/transport_picoquic.cpp)
endif()

add_library(quicr-transport ${sources})

target_link_libraries(quicr-transport
PUBLIC
cantina::logger
picoquic-core)
cantina::logger
)

if (NOT PLATFORM_ESP_IDF)
target_link_libraries(quicr-transport
PUBLIC
picoquic-core)
endif()

if (PLATFORM_ESP_IDF)
TimEvens marked this conversation as resolved.
Show resolved Hide resolved
add_compile_definitions(${LIB_NAME} PLATFORM_ESP)
endif()

target_include_directories(quicr-transport PUBLIC include src )
set_target_properties(quicr-transport
PROPERTIES
Expand Down
20 changes: 8 additions & 12 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
add_executable(server echoServer.cc)
target_link_libraries(server
PRIVATE
cantina::logger
quicr-transport
picotls-core
picotls-openssl)
target_link_libraries(server PRIVATE cantina::logger quicr-transport)
if (NOT PLATFORM_ESP_IDF)
target_link_libraries(server PRIVATE picotls-core picotls-openssl)
endif()

target_compile_options(server
PRIVATE
Expand All @@ -18,12 +16,10 @@ set_target_properties(server


add_executable(client client.cc)
target_link_libraries(client
PRIVATE
cantina::logger
quicr-transport
picotls-core
picotls-openssl)
target_link_libraries(client PRIVATE cantina::logger quicr-transport)
if (NOT PLATFORM_ESP_IDF)
target_link_libraries(client PRIVATE picotls-core picotls-openssl)
endif()

target_compile_options(client
PRIVATE
Expand Down
46 changes: 25 additions & 21 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@

set(INSTALL_DESTINATION_DEFAULT
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
FRAMEWORK DESTINATION lib
BUNDLE DESTINATION bin
RUNTIME DESTINATION bin)

add_subdirectory( boringssl )
add_subdirectory(logger)

if (NOT PLATFORM_ESP_IDF)
add_subdirectory( boringssl )

set (OPENSSL_FOUND ON)
set (OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl")
set (OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl/include")
set (OPENSSL_FOUND ON)
set (OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl")
set (OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl/include")

LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/crypto")
LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/decrepit")
LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/ssl")
set (BORINGSSL_LIBDIR "${CMAKE_CURRENT_BINARY_DIR}/boringssl")
LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/crypto")
LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/decrepit")
LIST(APPEND BORINGSSL_LIBRARIES "${CMAKE_CURRENT_BINARY_DIR}/boringssl/ssl")
set (BORINGSSL_LIBDIR "${CMAKE_CURRENT_BINARY_DIR}/boringssl")

# TODO: When BORINGSSL_LIBRARIES is set, brotli will be disabled.
# TODO: Should check on adding brotli as a submodule if it's needed
set (picotls_BUILD_TESTS OFF)
add_subdirectory( picotls )
# TODO: When BORINGSSL_LIBRARIES is set, brotli will be disabled.
# TODO: Should check on adding brotli as a submodule if it's needed
set (picotls_BUILD_TESTS OFF)
add_subdirectory( picotls )

# picotls still attempts to find OpenSSL, which will override some variables. Need
# set them again after picotls
set (OPENSSL_FOUND ON)
set (OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl")
set (OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl/include")
# picotls still attempts to find OpenSSL, which will override some variables. Need
# set them again after picotls
set (OPENSSL_FOUND ON)
set (OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl")
set (OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/boringssl/include")

set (PICOQUIC_PTLS_SUBMODULE ON)
set (picoquic_BUILD_TESTS OFF)
add_subdirectory( picoquic )
set (PICOQUIC_PTLS_SUBMODULE ON)
set (picoquic_BUILD_TESTS OFF)
add_subdirectory( picoquic )
endif()

add_subdirectory(logger)
12 changes: 7 additions & 5 deletions src/transport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <transport/transport.h>
#include <transport_udp.h>
#include <transport_picoquic.h>
#if not defined(PLATFORM_ESP)
#include <transport_picoquic.h>
#endif
#include <cantina/logger.h>

namespace qtransport {
Expand All @@ -15,14 +17,14 @@ ITransport::make_client_transport(const TransportRemote& server,
switch (server.proto) {
case TransportProtocol::UDP:
return std::make_shared<UDPTransport>(server, delegate, false, logger);

#if not defined(PLATFORM_ESP)
case TransportProtocol::QUIC:
return std::make_shared<PicoQuicTransport>(server,
tcfg,
delegate,
false,
logger);

#endif
default:
logger->error << "Protocol not implemented" << std::flush;
throw std::runtime_error(
Expand All @@ -42,13 +44,13 @@ ITransport::make_server_transport(const TransportRemote& server,
switch (server.proto) {
case TransportProtocol::UDP:
return std::make_shared<UDPTransport>(server, delegate, true, logger);

#if not defined(PLATFORM_ESP)
case TransportProtocol::QUIC:
return std::make_shared<PicoQuicTransport>(server,
tcfg,
delegate,
true, logger);

#endif
default:
logger->error << "Protocol not implemented" << std::flush;

Expand Down
51 changes: 48 additions & 3 deletions src/transport_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,32 @@

#include "transport_udp.h"

#if defined(PLATFORM_ESP)
#include <lwip/netdb.h>
#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include <lwip/netdb.h>

#include "esp_pthread.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#endif

using namespace qtransport;

#if defined (PLATFORM_ESP)
static esp_pthread_cfg_t create_config(const char *name, int core_id, int stack, int prio)
{
auto cfg = esp_pthread_get_default_config();
cfg.thread_name = name;
cfg.pin_to_core = core_id;
cfg.stack_size = stack;
cfg.prio = prio;
return cfg;
}
#endif

UDPTransport::~UDPTransport()
{
// TODO: Close all streams and connections
Expand Down Expand Up @@ -250,10 +274,14 @@ UDPTransport::fd_writer()
void
UDPTransport::fd_reader()
{
logger->Log("Starting transport reader thread");

const int dataSize = 65535; // TODO Add config var to set this value. Sizes
logger->Log(cantina::LogLevel::Info, "Starting transport reader thread");
#if defined(PLATFORM_ESP)
// TODO (Suhas): Revisit this once we have basic esp functionality working
const int dataSize = 2048;
#else
const int dataSize = 65535; // TODO Add config var to set this value.
// larger than actual MTU require IP frags
#endif
struct sockaddr_storage remoteAddr;
memset(&remoteAddr, 0, sizeof(remoteAddr));
socklen_t remoteAddrLen = sizeof(remoteAddr);
Expand Down Expand Up @@ -517,8 +545,25 @@ UDPTransport::connect_client()
// Notify caller that the connection is now ready
delegate.on_connection_status(last_context_id, TransportStatus::Ready);

#if defined(PLATFORM_ESP)
auto cfg = create_config("FDReader", 1, 12 * 1024, 5);
TimEvens marked this conversation as resolved.
Show resolved Hide resolved
auto esp_err = esp_pthread_set_cfg(&cfg);
if(esp_err != ESP_OK) {
s_log << "esp_pthread_set_cfg failed " << esp_err_to_name(esp_err);
throw std::runtime_error(s_log.str());
}
#endif
running_threads.emplace_back(&UDPTransport::fd_reader, this);

#if defined(PLATFORM_ESP)
cfg = create_config("FDWriter", 1, 12 * 1024, 5);
esp_err = esp_pthread_set_cfg(&cfg);
if(esp_err != ESP_OK) {
s_log << "esp_pthread_set_cfg failed " << esp_err_to_name(esp_err);
throw std::runtime_error(s_log.str());
}
#endif

running_threads.emplace_back(&UDPTransport::fd_writer, this);

return last_context_id;
Expand Down