Skip to content

Commit

Permalink
Single Commit for Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mahajanadhitya committed May 15, 2024
1 parent 12f290f commit 1b12b2a
Show file tree
Hide file tree
Showing 28 changed files with 1,026 additions and 444 deletions.
8 changes: 4 additions & 4 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ blocks:
value: -std=gnu90 # Test minimum C standard, default in CentOS 7
prologue:
commands:
- docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY
- '[[ -z $DOCKERHUB_APIKEY ]] || docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY'
jobs:
- name: 'Build and integration tests'
commands:
- wget -O rapidjson-dev.deb https://launchpad.net/ubuntu/+archive/primary/+files/rapidjson-dev_1.1.0+dfsg2-3_all.deb
- sudo dpkg -i rapidjson-dev.deb
- python3 -m pip install -U pip
- python3 -m pip -V
- python3 -m pip install -r tests/requirements.txt
- (cd tests && python3 -m pip install -r requirements.txt)
- ./configure --install-deps
# split these up
- ./packaging/tools/rdutcoverage.sh
Expand All @@ -147,7 +147,7 @@ blocks:
type: s1-prod-ubuntu20-04-amd64-2
prologue:
commands:
- docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY
- '[[ -z $DOCKERHUB_APIKEY ]] || docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY'
epilogue:
commands:
- '[[ -z $SEMAPHORE_GIT_TAG_NAME ]] || artifact push workflow artifacts/ --destination artifacts/${ARTIFACT_KEY}/'
Expand Down Expand Up @@ -203,7 +203,7 @@ blocks:
type: s1-prod-ubuntu20-04-arm64-1
prologue:
commands:
- docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY
- '[[ -z $DOCKERHUB_APIKEY ]] || docker login --username $DOCKERHUB_USER --password $DOCKERHUB_APIKEY'
epilogue:
commands:
- '[[ -z $SEMAPHORE_GIT_TAG_NAME ]] || artifact push workflow artifacts/ --destination artifacts/${ARTIFACT_KEY}/'
Expand Down
82 changes: 80 additions & 2 deletions src/rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#endif

#include "rdtime.h"
#include "rdmap.h"
#include "crc32c.h"
#include "rdunittest.h"

Expand Down Expand Up @@ -4250,8 +4251,8 @@ rd_kafka_op_res_t rd_kafka_poll_cb(rd_kafka_t *rk,
rd_kafka_purge(rk, rko->rko_u.purge.flags);
break;

case RD_KAFKA_OP_METADATA_951:
/* Merge metadata and updates cache. */
case RD_KAFKA_OP_METADATA_UPDATE:
/* Merges metadata and updates cache. */
rd_kafka_handle_metadata_update_op(rk, rko->rko_u.metadata.mdi);
break;

Expand Down Expand Up @@ -5329,6 +5330,38 @@ rd_kafka_Uuid_t *rd_kafka_Uuid_copy(const rd_kafka_Uuid_t *uuid) {
return copy_uuid;
}

/**
* Returns a new non cryptographically secure UUIDv4 (random).
*
* @return A UUIDv4.
*
* @remark Must be freed after use using rd_kafka_Uuid_destroy().
*/
rd_kafka_Uuid_t rd_kafka_Uuid_random() {
int i;
unsigned char rand_values_bytes[16] = {0};
uint64_t *rand_values_uint64 = (uint64_t *)rand_values_bytes;
unsigned char *rand_values_app;
rd_kafka_Uuid_t ret = RD_KAFKA_UUID_ZERO;
for (i = 0; i < 16; i += 2) {
uint16_t rand_uint16 = (uint16_t)rd_jitter(0, INT16_MAX - 1);
/* No need to convert endianess here because it's still only
* a random value. */
rand_values_app = (unsigned char *)&rand_uint16;
rand_values_bytes[i] |= rand_values_app[0];
rand_values_bytes[i + 1] |= rand_values_app[1];
}

rand_values_bytes[6] &= 0x0f; /* clear version */
rand_values_bytes[6] |= 0x40; /* version 4 */
rand_values_bytes[8] &= 0x3f; /* clear variant */
rand_values_bytes[8] |= 0x80; /* IETF variant */

ret.most_significant_bits = be64toh(rand_values_uint64[0]);
ret.least_significant_bits = be64toh(rand_values_uint64[1]);
return ret;
}

/**
* @brief Destroy the provided uuid.
*
Expand All @@ -5338,6 +5371,40 @@ void rd_kafka_Uuid_destroy(rd_kafka_Uuid_t *uuid) {
rd_free(uuid);
}

/**
* @brief Computes canonical encoding for the given uuid string.
* Mainly useful for testing.
*
* @param uuid UUID for which canonical encoding is required.
*
* @return canonical encoded string for the given UUID.
*
* @remark Must be freed after use.
*/
const char *rd_kafka_Uuid_str(const rd_kafka_Uuid_t *uuid) {
int i, j;
unsigned char bytes[16];
char *ret = rd_calloc(37, sizeof(*ret));

for (i = 0; i < 8; i++) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
j = 7 - i;
#elif __BYTE_ORDER == __BIG_ENDIAN
j = i;
#endif
bytes[i] = (uuid->most_significant_bits >> (8 * j)) & 0xFF;
bytes[8 + i] = (uuid->least_significant_bits >> (8 * j)) & 0xFF;
}

rd_snprintf(ret, 37,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%"
"02x%02x%02x",
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5],
bytes[6], bytes[7], bytes[8], bytes[9], bytes[10],
bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]);
return ret;
}

const char *rd_kafka_Uuid_base64str(const rd_kafka_Uuid_t *uuid) {
if (*uuid->base64str)
return uuid->base64str;
Expand All @@ -5364,6 +5431,17 @@ const char *rd_kafka_Uuid_base64str(const rd_kafka_Uuid_t *uuid) {
return uuid->base64str;
}

unsigned int rd_kafka_Uuid_hash(const rd_kafka_Uuid_t *uuid) {
unsigned char bytes[16];
memcpy(bytes, &uuid->most_significant_bits, 8);
memcpy(&bytes[8], &uuid->least_significant_bits, 8);
return rd_bytes_hash(bytes, 16);
}

unsigned int rd_kafka_Uuid_map_hash(const void *key) {
return rd_kafka_Uuid_hash(key);
}

int64_t rd_kafka_Uuid_least_significant_bits(const rd_kafka_Uuid_t *uuid) {
return uuid->least_significant_bits;
}
Expand Down
Loading

0 comments on commit 1b12b2a

Please sign in to comment.