From e58459c1156515c76c46a108d7363ceb00b71ef8 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 20 Nov 2024 01:00:55 +0200 Subject: [PATCH] feat(ipv6): add the ability to enforce IPv6 usage Add `pubnub_set_ipv4_connectivity` and `pubnub_set_ipv6_connectivity` functions to make it possible to enforce specific protocol usage. test(message-type): add subscription test for custom message type Modify subscription integration with additional information about custom message type to check parsing. --- .../run-unit-tests.sh | 1 + .../composite/unit-test-framework/action.yaml | 4 ++-- .github/workflows/run-tests.yml | 4 ++-- core/pubnub_ccore_pubsub.c | 2 +- core/pubnub_coreapi_ex.c | 2 +- core/pubnub_coreapi_ex.h | 6 ++++-- core/pubnub_dns_servers.c | 15 ++++++++++++++- core/pubnub_dns_servers.h | 8 ++++++++ core/pubnub_pubsubapi.c | 6 ++---- core/pubnub_subscribe_v2_unit_test.c | 7 ++++--- 10 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh b/.github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh index 0da15bf5..80927afe 100755 --- a/.github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh +++ b/.github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e echo "::group::Run unit tests ('$1' $CC / $CXX)" cd "$GITHUB_WORKSPACE/core" diff --git a/.github/workflows/composite/unit-test-framework/action.yaml b/.github/workflows/composite/unit-test-framework/action.yaml index e0114ddc..70b3fd18 100644 --- a/.github/workflows/composite/unit-test-framework/action.yaml +++ b/.github/workflows/composite/unit-test-framework/action.yaml @@ -18,7 +18,7 @@ runs: steps: - name: Build and Cache Unit Test framework ('${{ inputs.os }}' ${{ inputs.compilers }}) id: unit-test-framework - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | cgreen @@ -27,7 +27,7 @@ runs: ${{ inputs.os }}-cgreen-${{ inputs.version }}- - name: Checkout Unit Test framework if: steps.unit-test-framework.outputs.cache-hit != 'true' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: cgreen-devs/cgreen ref: ${{ matrix.cgreen }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 66fe81d8..0c70fab6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -25,11 +25,11 @@ jobs: # group: organization/macos-gh steps: - name: Checkout project - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN }} - name: Checkout actions - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 diff --git a/core/pubnub_ccore_pubsub.c b/core/pubnub_ccore_pubsub.c index 62d6026b..405695c7 100644 --- a/core/pubnub_ccore_pubsub.c +++ b/core/pubnub_ccore_pubsub.c @@ -597,7 +597,7 @@ enum pubnub_res pbcc_publish_prep(struct pbcc_context* pb, URL_PARAMS_INIT(qparam, PUBNUB_MAX_URL_PARAMS); if (uname) { ADD_URL_PARAM(qparam, pnsdk, uname); } ADD_URL_PARAM(qparam, uuid, user_id); - if (ttl != SIZE_MAX) { ADD_URL_PARAM_SIZET(qparam, ttl, ttl); } + if (ttl != 0) { ADD_URL_PARAM_SIZET(qparam, ttl, ttl); } #if PUBNUB_CRYPTO_API if (pb->secret_key == NULL) { ADD_URL_AUTH_PARAM(pb, qparam, auth); } ADD_TS_TO_URL_PARAM(); diff --git a/core/pubnub_coreapi_ex.c b/core/pubnub_coreapi_ex.c index 513f8284..30fdfa66 100644 --- a/core/pubnub_coreapi_ex.c +++ b/core/pubnub_coreapi_ex.c @@ -32,7 +32,7 @@ struct pubnub_publish_options pubnub_publish_defopts(void) result.replicate = true; result.meta = NULL; result.method = pubnubSendViaGET; - result.ttl = SIZE_MAX; + result.ttl = 0; result.custom_message_type = NULL; return result; } diff --git a/core/pubnub_coreapi_ex.h b/core/pubnub_coreapi_ex.h index 2b0a8b95..f48eec6a 100644 --- a/core/pubnub_coreapi_ex.h +++ b/core/pubnub_coreapi_ex.h @@ -74,7 +74,8 @@ struct pubnub_publish_options { /** This returns the default options for publish V1 transactions. Will set `store = true`, `cipher_key = NULL`, `replicate = true`, - `meta = NULL` and `method = pubnubPublishViaGet` + `meta = NULL`, `method = pubnubPublishViaGet`, `ttl=0`, and + `custom_message_type=NULL`. */ PUBNUB_EXTERN struct pubnub_publish_options pubnub_publish_defopts(void); @@ -108,7 +109,8 @@ struct pubnub_signal_options { char const* custom_message_type; }; -/** This returns the default options for signal V1 transactions. */ +/** This returns the default options for signal V1 transactions. + Will set `custom_message_type=NULL`. */ PUBNUB_EXTERN struct pubnub_signal_options pubnub_signal_defopts(void); /** The extended signal V1. Basically the same as pubnub_signal(), diff --git a/core/pubnub_dns_servers.c b/core/pubnub_dns_servers.c index 5a8eb32c..b02d07da 100644 --- a/core/pubnub_dns_servers.c +++ b/core/pubnub_dns_servers.c @@ -33,7 +33,6 @@ void pubnub_dns_servers_deinit(void) pubnub_mutex_destroy(m_lock); } - int pubnub_dns_set_primary_server_ipv4(struct pubnub_ipv4_address ipv4_address) { uint8_t* ipv4 = ipv4_address.ipv4; @@ -166,6 +165,20 @@ int pubnub_get_dns_secondary_server_ipv4(struct pubnub_ipv4_address* o_ipv4) } #if PUBNUB_USE_IPV6 +void pubnub_set_ipv4_connectivity(pubnub_t *p) +{ + pubnub_mutex_lock(p->monitor); + p->options.ipv6_connectivity = false; + pubnub_mutex_unlock(p->monitor); +} + +void pubnub_set_ipv6_connectivity(pubnub_t *p) +{ + pubnub_mutex_lock(p->monitor); + p->options.ipv6_connectivity = true; + pubnub_mutex_unlock(p->monitor); +} + int pubnub_dns_set_primary_server_ipv6(struct pubnub_ipv6_address ipv6_address) { uint8_t* ipv6 = ipv6_address.ipv6; diff --git a/core/pubnub_dns_servers.h b/core/pubnub_dns_servers.h index 4a742990..e4b170a3 100644 --- a/core/pubnub_dns_servers.h +++ b/core/pubnub_dns_servers.h @@ -19,6 +19,14 @@ struct pubnub_ipv6_address { uint8_t ipv6[16]; }; +/** IPv4 connectivity type for @p. + Use IPv4 addresses to establish connection with remote origin. */ +void pubnub_set_ipv4_connectivity(pubnub_t *p); + +/** IPv6 connectivity type for @p. + Use IPv6 addresses to establish connection with remote origin. */ +void pubnub_set_ipv6_connectivity(pubnub_t *p); + /* primary, secondary(ipv4, ipv6) and default dns server */ #define PUBNUB_MAX_DNS_SERVERS_MASK 0x10 #else diff --git a/core/pubnub_pubsubapi.c b/core/pubnub_pubsubapi.c index 624dc0ef..a8ffdd25 100644 --- a/core/pubnub_pubsubapi.c +++ b/core/pubnub_pubsubapi.c @@ -53,10 +53,8 @@ pubnub_t* pubnub_init(pubnub_t* p, const char* publish_key, const char* subscrib p->trans = PBTT_NONE; p->options.use_http_keep_alive = true; #if PUBNUB_USE_IPV6 && defined(PUBNUB_CALLBACK_API) - /* Connectivity type(true-Ipv6/false-Ipv4) chosen on given contex. - Ipv4 by default. - */ - p->options.ipv6_connectivity = false; + /* IPv4 connectivity type by default. */ + pubnub_set_ipv4_connectivity(p); #endif p->flags.started_while_kept_alive = false; p->method = pubnubSendViaGET; diff --git a/core/pubnub_subscribe_v2_unit_test.c b/core/pubnub_subscribe_v2_unit_test.c index eb89c06e..fad553bb 100644 --- a/core/pubnub_subscribe_v2_unit_test.c +++ b/core/pubnub_subscribe_v2_unit_test.c @@ -53,7 +53,7 @@ Ensure(subscribe_v2, should_parse_response_correctly) { assert_that(pubnub_auth_get(pbp), is_equal_to_string(NULL)); expect_have_dns_for_pubnub_origin_on_ctx(pbp); expect_outgoing_with_url_on_ctx(pbp, - "/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=0&tr=0&uuid=test_id&heartbeat=270"); + "/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=0&uuid=test_id&heartbeat=300"); incoming("HTTP/1.1 200\r\nContent-Length: " "44\r\n\r\n{\"t\":{\"t\":\"15628652479932717\",\"r\":4},\"m\":[]}", NULL); @@ -71,9 +71,9 @@ Ensure(subscribe_v2, should_parse_response_correctly) { expect(pbntf_got_socket, when(pb, is_equal_to(pbp)), will_return(0)); expect_outgoing_with_url_on_ctx(pbp, - "/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=15628652479932717&tr=4&uuid=test_id&heartbeat=270"); + "/v2/subscribe/sub_key/my-channel/0?pnsdk=unit-test-0.1&tt=15628652479932717&tr=4&uuid=test_id&heartbeat=300"); incoming("HTTP/1.1 220\r\nContent-Length: " - "183\r\n\r\n{\"t\":{\"t\":\"15628652479932717\",\"r\":4},\"m\":[{\"a\":\"1\",\"f\":514,\"i\":\"publisher_id\",\"s\":1,\"p\":{\"t\":\"15628652479933927\",\"r\":4},\"k\":\"demo\",\"c\":\"my-channel\",\"d\":\"mymessage\",\"b\":\"my-channel\"}]}", + "209\r\n\r\n{\"t\":{\"t\":\"15628652479932717\",\"r\":4},\"m\":[{\"a\":\"1\",\"f\":514,\"cmt\":\"test-message-type\",\"i\":\"publisher_id\",\"s\":1,\"p\":{\"t\":\"15628652479933927\",\"r\":4},\"k\":\"demo\",\"c\":\"my-channel\",\"d\":\"mymessage\",\"b\":\"my-channel\"}]}", NULL); expect(pbntf_lost_socket, when(pb, is_equal_to(pbp))); @@ -88,6 +88,7 @@ Ensure(subscribe_v2, should_parse_response_correctly) { assert_char_mem_block(msg.channel, "my-channel"); assert_char_mem_block(msg.payload, "\"mymessage\""); assert_char_mem_block(msg.publisher, "publisher_id"); + assert_char_mem_block(msg.custom_message_type, "test-message-type"); assert_that(msg.region, is_equal_to(4)); assert_that(msg.flags, is_equal_to(514));