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

Fix some errors in SYNC before #143

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion demo/quic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ find_package(nng CONFIG REQUIRED)

find_package(Threads)
find_package(msquic)
find_package(OpenSSL)

add_executable(quic_client client.c)
target_link_libraries(quic_client nng msquic pthread ssl crypto)

if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIRS})
target_link_libraries(quic_client OpenSSL::SSL OpenSSL::Crypto)
endif()

target_link_libraries(quic_client nng msquic pthread)
target_compile_definitions(quic_client PRIVATE NNG_ELIDE_DEPRECATED)

if (NNG_ENABLE_SQLITE)
Expand Down
2 changes: 1 addition & 1 deletion demo/quic/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ client(int type, const char *url, const char *qos, const char *topic, const char
nng_msg * msg;
const char *arg = "CLIENT FOR QUIC";

if ((rv = nng_mqtt_quic_client_open(&sock, url)) != 0) {
if ((rv = nng_mqtt_quic_client_open2(&sock, url)) != 0) {
printf("error in quic client open.\n");
}

Expand Down
3 changes: 1 addition & 2 deletions include/nng/mqtt/mqtt_quic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
extern "C" {
#endif
NNG_DECL int nng_mqtt_quic_client_open(nng_socket *, const char *url);
NNG_DECL int nng_mqtt_quic_open_keepalive(
nng_socket *sock, const char *url, uint64_t interval);
NNG_DECL int nng_mqtt_quic_client_open2(nng_socket *sock, const char *url);
NNG_DECL int nng_mqtt_quic_set_connect_cb(
nng_socket *, int (*cb)(void *, void *), void *arg);
NNG_DECL int nng_mqtt_quic_set_disconnect_cb(
Expand Down
18 changes: 9 additions & 9 deletions src/mqtt/protocol/mqtt/mqtt_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,26 @@ struct conf_bridge_node {
static conf_bridge_node config_node = {
.tls = {
.enable = false,
.url = "",
.url = "", // Depracated
.cafile = "",
.certfile = "",
.keyfile = "",
.ca = "",
.cert = "",
.key = "",
.key_password = "",
.verify_peer = false,
.set_fail = false,
.verify_peer = true,
.set_fail = true,
},
.multi_stream = true,
.stream_auto_genid = true,
.qos_first = true,
.hybrid = false,
.multi_stream = false,
.stream_auto_genid = false,
.qos_first = false,
.hybrid = false, // Depracated
.qkeepalive = 30,
.qconnect_timeout = 60,
.qdiscon_timeout = 30,
.qidle_timeout = 30,
.qcongestion_control = 1, // bbr
.qcongestion_control = 0, // cubic
.max_send_queue_len = 32,
.max_recv_queue_len = 32,
};
Expand Down Expand Up @@ -1927,7 +1927,7 @@ nng_mqtt_quic_client_open(nng_socket *sock, const char *url)
* open mqtt quic transport with self-defined conf params
*/
int
nng_mqtt_quic_open_sdk(nng_socket *sock, const char *url)
nng_mqtt_quic_client_open2(nng_socket *sock, const char *url)
{
nni_sock *nsock = NULL;
int rv = 0;
Expand Down
43 changes: 10 additions & 33 deletions src/supplemental/quic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,16 @@ if (NNG_ENABLE_QUIC)
nng_sources(quic_api.c)
nng_sources(quic_api.h)

find_library(OPENSSLQUIC_LIBRARIES
NAMES openssl ssl libssl libopenssl
HINTS "${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl"
PATHS "${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl"
PATH_SUFFIXES lib)

find_library(CRYPTOQUIC_LIBRARIES
NAMES crypto libcrypto
HINTS "${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl"
PATHS "${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl"
PATH_SUFFIXES lib)

if(OPENSSLQUIC_LIBRARIES_NOTFOUND)
message("No openssl for MsQuic be found!")
elif(CRYPTOQUIC_LIBRARIES_NOTFOUND)
message("No openssl for MsQuic be found!")
else()
nng_include_directories(${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/include)

set(SSLQUIC_LIBRARIES ${OPENSSLQUIC_LIBRARIES})
mark_as_advanced(SSLQUIC_LIBRARIES)
nng_link_libraries(${SSLQUIC_LIBRARIES})

set(SSLCRYPTO_LIBRARIES ${CRYPTOQUIC_LIBRARIES})
mark_as_advanced(CRYPTOQUIC_LIBRARIES)
nng_link_libraries(${CRYPTOQUIC_LIBRARIES})
endif()

#nng_include_directories(${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/include)
#nng_link_libraries("${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/lib/libssl.a")
#nng_link_libraries("${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/lib/libcrypto.a")


# In sdk. use openssl from system
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIRS})
nng_link_libraries(OpenSSL::SSL OpenSSL::Crypto)
endif()

#nng_include_directories(${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/include)
#nng_link_libraries("${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/lib/libssl.a")
#nng_link_libraries("${CMAKE_SOURCE_DIR}/build/_deps/opensslquic-build/openssl/lib/libcrypto.a")

# set_property(CACHE NNG_QUIC_LIB PROPERTY STRINGS ${NNG_TLS_ENGINES})
else ()
Expand Down
40 changes: 10 additions & 30 deletions src/supplemental/quic/quic_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ HQUIC configuration;
static conf_quic_sdk conf_node;
nni_proto *g_quic_proto;

static BOOLEAN quic_load_sdk_config(BOOLEAN Unsecure, uint64_t qconnect_timeout,
uint32_t qdiscon_timeout, uint32_t qidle_timeout,
uint8_t qcongestion_control, bool tls_enable,
char *certifile, char *keyfile,
char *key_password, char *cafile, bool verify_peer);
static BOOLEAN quic_load_sdk_config(BOOLEAN Unsecure);

static void quic_pipe_send_cancel(nni_aio *aio, void *arg, int rv);
static void quic_pipe_recv_cancel(nni_aio *aio, void *arg, int rv);
Expand Down Expand Up @@ -238,29 +234,13 @@ verify_peer_cert_tls(QUIC_CERTIFICATE* cert, QUIC_CERTIFICATE* chain, char *cace

// Helper function to load a client configuration.
static BOOLEAN
quic_load_sdk_config(BOOLEAN Unsecure, uint64_t qconnect_timeout,
uint32_t qdiscon_timeout, uint32_t qidle_timeout,
uint8_t qcongestion_control, bool tls_enable,
char *certifile, char *keyfile,
char *key_password, char *cafile, bool verify_peer
)
quic_load_sdk_config(BOOLEAN Unsecure)
{
QUIC_SETTINGS Settings = { 0 };
QUIC_CREDENTIAL_CONFIG CredConfig;

conf_quic_sdk *node = &conf_node;

node->tls.enable = tls_enable;
node->tls.certfile = certifile;
node->tls.keyfile = keyfile;
node->tls.key_password = key_password;
node->tls.verify_peer = verify_peer;
node->tls.cafile = cafile;
node->qidle_timeout = qidle_timeout;
node->qconnect_timeout = qconnect_timeout;
node->qdiscon_timeout = qdiscon_timeout;
node->qcongestion_control = qcongestion_control;

if (!node) {
Settings.IsSet.IdleTimeoutMs = TRUE;
Settings.IdleTimeoutMs = 90 * 1000;
Expand Down Expand Up @@ -765,17 +745,11 @@ quic_disconnect(void *qsock, void *qpipe)
return 0;
}

void
quic_proto_set_sdk_config(void *config)
{
memcpy(&conf_node, config, sizeof(conf_quic_sdk));
}

int
quic_connect_ipv4(const char *url, nni_sock *sock, uint32_t *index)
{
// Load the client configuration
if (!quic_load_sdk_config(TRUE, 60, 20, 120, 0, FALSE, NULL, NULL, NULL, NULL,FALSE)) {
if (!quic_load_sdk_config(TRUE)) {
log_error("Failed in load quic configuration");
return (-1);
}
Expand Down Expand Up @@ -873,7 +847,7 @@ static int
quic_sock_reconnect(quic_sock_t *qsock)
{
// Load the client configuration.
if (!quic_load_sdk_config(TRUE, 60, 20, 120, 0, FALSE, NULL, NULL, NULL, NULL,FALSE)) {
if (!quic_load_sdk_config(TRUE)) {
log_error("Failed in load quic configuration");
return (-1);
}
Expand Down Expand Up @@ -1504,6 +1478,12 @@ quic_proto_close()
g_quic_proto = NULL;
}

void
quic_proto_set_sdk_config(void *config)
{
memcpy(&conf_node, config, sizeof(conf_quic_sdk));
}

void
quic_proto_set_bridge_conf(void *node)
{
Expand Down