diff --git a/CMakeLists.txt b/CMakeLists.txt index ad06a047a..8b248c844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ else() endif() project(picoquic - VERSION 1.1.28.10 + VERSION 1.1.29.0 DESCRIPTION "picoquic library" LANGUAGES C CXX) diff --git a/UnitTest1/unittest1.cpp b/UnitTest1/unittest1.cpp index 740bd71f1..218c82e8d 100644 --- a/UnitTest1/unittest1.cpp +++ b/UnitTest1/unittest1.cpp @@ -76,13 +76,27 @@ namespace UnitTest1 Assert::AreEqual(ret, 0); } - TEST_METHOD(sprintf) + TEST_METHOD(util_sprintf) { int ret = util_sprintf_test(); Assert::AreEqual(ret, 0); } + TEST_METHOD(util_debug_print) + { + int ret = util_debug_print_test(); + + Assert::AreEqual(ret, 0); + } + + TEST_METHOD(util_uint8_to_str) + { + int ret = util_uint8_to_str_test(); + + Assert::AreEqual(ret, 0); + } + TEST_METHOD(memcmp) { int ret = util_memcmp_test(); diff --git a/picoquic/packet.c b/picoquic/packet.c index 74c08de8e..9ec2c037a 100644 --- a/picoquic/packet.c +++ b/picoquic/packet.c @@ -308,11 +308,12 @@ int picoquic_parse_long_packet_header( ph->epoch = picoquic_epoch_handshake; break; case picoquic_packet_retry: /* Retry */ + default: + /* No default branch in this statement, because there are only 4 possible types + * parsed in picoquic_parse_long_packet_type */ ph->pc = picoquic_packet_context_initial; ph->epoch = picoquic_epoch_initial; break; - /* No default branch in this statement, because there are only 4 possible types - * parsed in picoquic_parse_long_packet_type */ } if (ph->ptype == picoquic_packet_retry) { diff --git a/picoquic/picoquic.h b/picoquic/picoquic.h index 6c16b4df0..2b1e669a9 100644 --- a/picoquic/picoquic.h +++ b/picoquic/picoquic.h @@ -40,7 +40,7 @@ extern "C" { #endif -#define PICOQUIC_VERSION "1.1.28.10" +#define PICOQUIC_VERSION "1.1.29.0" #define PICOQUIC_ERROR_CLASS 0x400 #define PICOQUIC_ERROR_DUPLICATE (PICOQUIC_ERROR_CLASS + 1) #define PICOQUIC_ERROR_AEAD_CHECK (PICOQUIC_ERROR_CLASS + 3) diff --git a/picoquic/picoquic_utils.h b/picoquic/picoquic_utils.h index a7718de76..eb1a2bc9f 100644 --- a/picoquic/picoquic_utils.h +++ b/picoquic/picoquic_utils.h @@ -66,14 +66,18 @@ extern "C" { void debug_set_stream(FILE *F); +#if 0 void debug_set_callback(void (*cb)(const char *msg, void *argp), void *argp); +#endif void debug_printf(const char* fmt, ...); void debug_printf_push_stream(FILE* f); void debug_printf_pop_stream(void); void debug_printf_suspend(void); void debug_printf_resume(void); int debug_printf_reset(int suspended); +#ifdef _DEBUG void debug_dump(const void * x, int len); +#endif /* utilities */ char* picoquic_string_create(const char* original, size_t len); @@ -88,12 +92,10 @@ int picoquic_is_connection_id_null(const picoquic_connection_id_t * cnx_id); int picoquic_compare_connection_id(const picoquic_connection_id_t * cnx_id1, const picoquic_connection_id_t * cnx_id2); uint64_t picoquic_connection_id_hash(const picoquic_connection_id_t * cid); uint64_t picoquic_val64_connection_id(picoquic_connection_id_t cnx_id); -void picoquic_set64_connection_id(picoquic_connection_id_t * cnx_id, uint64_t val64); uint64_t picoquic_hash_addr(const struct sockaddr* addr); size_t picoquic_parse_hexa(char const* hex_input, size_t input_length, uint8_t* bin_output, size_t output_max); uint8_t picoquic_parse_connection_id_hexa(char const * hex_input, size_t input_length, picoquic_connection_id_t * cnx_id); int picoquic_print_connection_id_hexa(char* buf, size_t buf_len, const picoquic_connection_id_t* cnxid); -uint8_t picoquic_create_packet_header_cnxid_lengths(uint8_t dest_len, uint8_t srce_len); int picoquic_compare_addr(const struct sockaddr* expected, const struct sockaddr* actual); int picoquic_compare_ip_addr(const struct sockaddr* expected, const struct sockaddr* actual); @@ -170,8 +172,10 @@ const uint8_t* picoquic_frames_cid_decode(const uint8_t * bytes, const uint8_t * #define VARINT_LEN(bytes) (((uint8_t)1) << ((bytes[0] >> 6)&3)) #define VARINT_LEN_T(bytes, t_len) (((t_len)1) << ((bytes[0] >> 6)&3)) +#if 0 /* Predict length of a varint encoding */ size_t picoquic_frames_varint_encode_length(uint64_t n64); +#endif /* Encoding functions of the form uint8_t * picoquic_frame_XXX_encode(uint8_t * bytes, uint8_t * bytes-max, ...) */ diff --git a/picoquic/util.c b/picoquic/util.c index a847dff07..7422b56d7 100644 --- a/picoquic/util.c +++ b/picoquic/util.c @@ -92,51 +92,55 @@ char* picoquic_string_free(char* str) return NULL; } -char* picoquic_strip_endofline(char* buf, size_t bufmax, char const* line) -{ - for (size_t i = 0; i < bufmax; i++) { - int c = line[i]; - - if (c == 0 || c == '\r' || c == '\n') { - buf[i] = 0; - break; - } - else { - buf[i] = (char) c; - } - } - - buf[bufmax - 1] = 0; - return buf; -} - static FILE* debug_out = NULL; +#if 0 void (*debug_callback)(const char *msg, void *arg) = NULL; void *debug_callback_argp = NULL; +#endif static int debug_suspended = 0; void debug_set_stream(FILE *F) { debug_out = F; +#if 0 debug_callback = NULL; debug_callback_argp = NULL; +#endif } +FILE* get_debug_out() +{ + return debug_out; +} + +int get_debug_suspended() +{ + return debug_suspended; +} +#if 0 void debug_set_callback(void (*cb)(const char *msg, void *argp), void *argp) { debug_callback = cb; debug_callback_argp = argp; debug_out = NULL; } +#endif void debug_printf(const char* fmt, ...) { +#if 1 + if (debug_suspended == 0 && debug_out != NULL) { +#else if (debug_suspended == 0 && (debug_out != NULL || debug_callback != NULL)) { +#endif if (debug_out) { va_list args; va_start(args, fmt); vfprintf(debug_out, fmt, args); va_end(args); +#if 1 + } +#else } else { char message[1024]; size_t message_length; @@ -153,12 +157,18 @@ void debug_printf(const char* fmt, ...) } debug_callback(message, debug_callback_argp); } +#endif } } +#ifdef _DEBUG void debug_dump(const void * x, int len) { +#if 1 + if (debug_suspended == 0 && debug_out != NULL){ +#else if (debug_suspended == 0 && (debug_out != NULL || debug_callback != NULL)) { +#endif char msg[64]; size_t mlen; uint8_t * bytes = (uint8_t *)x; @@ -173,12 +183,17 @@ void debug_dump(const void * x, int len) } if (debug_out) { fprintf(debug_out, "%s\n", msg); +#if 1 + } +#else } else { debug_callback(msg, debug_callback_argp); } +#endif } } } +#endif void debug_printf_push_stream(FILE* f) { @@ -303,17 +318,6 @@ uint8_t picoquic_parse_connection_id_hexa(char const * hex_input, size_t input_l return (cnx_id->id_len); } -uint8_t picoquic_create_packet_header_cnxid_lengths(uint8_t dest_len, uint8_t srce_len) -{ - uint8_t ret; - - ret = (dest_len < 4) ? 0 : (dest_len - 3); - ret <<= 4; - ret |= (srce_len < 4) ? 0 : (srce_len - 3); - - return ret; -} - uint8_t picoquic_format_connection_id(uint8_t* bytes, size_t bytes_max, picoquic_connection_id_t cnx_id) { uint8_t copied = cnx_id.id_len; @@ -404,18 +408,6 @@ uint64_t picoquic_val64_connection_id(picoquic_connection_id_t cnx_id) return val64; } -void picoquic_set64_connection_id(picoquic_connection_id_t * cnx_id, uint64_t val64) -{ - for (int i = 7; i >= 0; i--) { - cnx_id->id[i] = (uint8_t)(val64 & 0xFF); - val64 >>= 8; - } - for (size_t i = 8; i < sizeof(cnx_id->id); i++) { - cnx_id->id[i] = 0; - } - cnx_id->id_len = 8; -} - uint64_t picoquic_hash_addr(const struct sockaddr* addr) { uint64_t h; @@ -433,7 +425,7 @@ uint64_t picoquic_hash_addr(const struct sockaddr* addr) return h; } - +#if 0 int picoquic_compare_addr(const struct sockaddr * expected, const struct sockaddr * actual) { int ret = -1; @@ -464,7 +456,7 @@ int picoquic_compare_addr(const struct sockaddr * expected, const struct sockadd return ret; } - +#endif int picoquic_compare_ip_addr(const struct sockaddr* expected, const struct sockaddr* actual) { @@ -497,6 +489,16 @@ uint16_t picoquic_get_addr_port(const struct sockaddr* addr) return port; } +int picoquic_compare_addr(const struct sockaddr* expected, const struct sockaddr* actual) +{ + int ret = picoquic_compare_ip_addr(expected, actual); + if (ret == 0 && + picoquic_get_addr_port(expected) != picoquic_get_addr_port(actual)) { + ret = -1; + } + return ret; +} + void picoquic_set_addr_port(const struct sockaddr* addr, uint16_t port) { if (addr->sa_family == AF_INET6) { @@ -830,6 +832,7 @@ const uint8_t* picoquic_frames_cid_decode(const uint8_t* bytes, const uint8_t* b return bytes; } +#if 0 /* Predict length of a varint encoding */ size_t picoquic_frames_varint_encode_length(uint64_t n64) { @@ -849,6 +852,7 @@ size_t picoquic_frames_varint_encode_length(uint64_t n64) return len; } +#endif /* Encoding functions of the form uint8_t * picoquic_frame_XXX_encode(uint8_t * bytes, uint8_t * bytes-max, ...) */ diff --git a/picoquic_t/picoquic_t.c b/picoquic_t/picoquic_t.c index d4ea85653..b0f01fe2a 100644 --- a/picoquic_t/picoquic_t.c +++ b/picoquic_t/picoquic_t.c @@ -45,8 +45,10 @@ typedef enum { static const picoquic_test_def_t test_table[] = { { "connection_id_print", util_connection_id_print_test }, { "connection_id_parse", util_connection_id_parse_test }, - { "sprintf", util_sprintf_test }, - { "memcmp", util_memcmp_test }, + { "util_sprintf", util_sprintf_test }, + { "util_debug_print", util_debug_print_test }, + { "util_uint8_to_str", util_uint8_to_str_test }, + { "util_memcmp", util_memcmp_test }, { "threading", util_threading_test }, { "picohash", picohash_test }, { "picohash_embedded", picohash_embedded_test }, diff --git a/picoquictest/picoquictest.h b/picoquictest/picoquictest.h index de71dc391..439418539 100644 --- a/picoquictest/picoquictest.h +++ b/picoquictest/picoquictest.h @@ -38,6 +38,8 @@ extern size_t picoquic_stress_nb_clients; /* number of stress clients, defaults int util_connection_id_print_test(); int util_connection_id_parse_test(); int util_sprintf_test(); +int util_debug_print_test(); +int util_uint8_to_str_test(); int util_memcmp_test(); int util_threading_test(); int picohash_test(); diff --git a/picoquictest/util_test.c b/picoquictest/util_test.c index bc70beea6..f0ee4bf32 100644 --- a/picoquictest/util_test.c +++ b/picoquictest/util_test.c @@ -113,6 +113,36 @@ int util_sprintf_test() return ret; } +uint8_t util_uint8_to_str_input[] = { + 'a', 'z', 'A', 'Z', '0', '9', '.', 0xff, +}; + +char util_uint8_to_str_out[] = { + 'a', 'z', 'A', 'Z', '0', '9', '.', '?', 0 +}; + +char util_uint8_to_str_out7[] = { + 'a', 'z', 'A', '.', '.', '.', 0 +}; + + +char util_uint8_to_str_out2[] = { + '.', 0 +}; + +int util_uint8_to_str_test() +{ + int ret = 0; + char text[16]; + + if (strcmp(picoquic_uint8_to_str(text, 16, util_uint8_to_str_input, sizeof(util_uint8_to_str_input)), util_uint8_to_str_out) != 0 || + strcmp(picoquic_uint8_to_str(text, 7, util_uint8_to_str_input, sizeof(util_uint8_to_str_input)), util_uint8_to_str_out7) != 0 || + strcmp(picoquic_uint8_to_str(text, 2, util_uint8_to_str_input, sizeof(util_uint8_to_str_input)), util_uint8_to_str_out2) != 0) { + ret = -1; + } + return ret; +} + /* Test the constant time memcmp for correctness and for * time constants. The test suite will include two 4MB * strings each comprising blocks of 16 bytes. @@ -297,6 +327,34 @@ int util_memcmp_test() return ret; } + +#define file_test_debug "file_test_debug.txt" +FILE* get_debug_out(); +int get_debug_suspended(); + +int util_debug_print_test() +{ + int ret = 0; + int was_suspened = get_debug_suspended(); + FILE* old_debug_file = get_debug_out(); + FILE* F = picoquic_file_open(file_test_debug, "w"); + + if (F == NULL) { + ret = -1; + } + else { + debug_set_stream(F); + debug_printf_resume(); + debug_printf("debug set stream: %d\n", ret); + F = picoquic_file_close(F); + debug_set_stream(old_debug_file); + if (was_suspened) { + debug_printf_suspend(); + } + } + return ret; +} + /* Testing the minimal thread support. * * We create one mutex and one event to synchronize two threads: one as a mutex demo, @@ -395,4 +453,5 @@ int util_threading_test() } return ret; -} \ No newline at end of file +} +