Skip to content

Commit

Permalink
feat(ipv6): add the ability to enforce IPv6 usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
parfeon committed Nov 19, 2024
1 parent 3869006 commit e58459c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

echo "::group::Run unit tests ('$1' $CC / $CXX)"
cd "$GITHUB_WORKSPACE/core"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/composite/unit-test-framework/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_ccore_pubsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_coreapi_ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions core/pubnub_coreapi_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
Expand Down
15 changes: 14 additions & 1 deletion core/pubnub_dns_servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions core/pubnub_dns_servers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions core/pubnub_pubsubapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions core/pubnub_subscribe_v2_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)));
Expand All @@ -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));
Expand Down

0 comments on commit e58459c

Please sign in to comment.