mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
refactor: Rename announce functions into their own namespace.
This avoids common names like `on_stored` and `store_data` in global symbols. Turns out, toxic also has a `store_data`.
This commit is contained in:
parent
d539e34f91
commit
c4beda4dd1
|
@ -19,21 +19,21 @@ static void test_bucketnum(void)
|
|||
random_bytes(rng, key1, sizeof(key1));
|
||||
memcpy(key2, key1, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
ck_assert_msg(get_bucketnum(key1, key2) == 0, "Bad bucketnum");
|
||||
ck_assert_msg(announce_get_bucketnum(key1, key2) == 0, "Bad bucketnum");
|
||||
|
||||
key2[4] ^= 0x09;
|
||||
key2[5] ^= 0xc5;
|
||||
|
||||
ck_assert_msg(get_bucketnum(key1, key2) == 7, "Bad bucketnum");
|
||||
ck_assert_msg(announce_get_bucketnum(key1, key2) == 7, "Bad bucketnum");
|
||||
|
||||
key2[4] ^= 0x09;
|
||||
|
||||
ck_assert_msg(get_bucketnum(key1, key2) == 17, "Bad bucketnum");
|
||||
ck_assert_msg(announce_get_bucketnum(key1, key2) == 17, "Bad bucketnum");
|
||||
|
||||
key2[5] ^= 0xc5;
|
||||
key2[31] ^= 0x09;
|
||||
|
||||
ck_assert_msg(get_bucketnum(key1, key2) == 4, "Bad bucketnum");
|
||||
ck_assert_msg(announce_get_bucketnum(key1, key2) == 4, "Bad bucketnum");
|
||||
}
|
||||
|
||||
typedef struct Announce_Test_Data {
|
||||
|
@ -65,7 +65,7 @@ static void test_store_data(void)
|
|||
ck_assert(announce != nullptr);
|
||||
|
||||
/* Just to prevent CI from complaining that set_synch_offset is unused: */
|
||||
set_synch_offset(announce, 0);
|
||||
announce_set_synch_offset(announce, 0);
|
||||
|
||||
Announce_Test_Data test_data;
|
||||
random_bytes(rng, test_data.data, sizeof(test_data.data));
|
||||
|
@ -74,30 +74,30 @@ static void test_store_data(void)
|
|||
uint8_t key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
random_bytes(rng, key, sizeof(key));
|
||||
|
||||
ck_assert_msg(!on_stored(announce, key, nullptr, nullptr), "Unstored announcement exists");
|
||||
ck_assert_msg(!announce_on_stored(announce, key, nullptr, nullptr), "Unstored announcement exists");
|
||||
|
||||
ck_assert_msg(store_data(announce, key, test_data.data, sizeof(test_data.data),
|
||||
ck_assert_msg(announce_store_data(announce, key, test_data.data, sizeof(test_data.data),
|
||||
MAX_MAX_ANNOUNCEMENT_TIMEOUT), "Failed to store announcement");
|
||||
|
||||
ck_assert_msg(on_stored(announce, key, test_announce_data, &test_data), "Failed to get stored announcement");
|
||||
ck_assert_msg(announce_on_stored(announce, key, test_announce_data, &test_data), "Failed to get stored announcement");
|
||||
|
||||
ck_assert_msg(test_data.passed, "Bad stored announcement data");
|
||||
|
||||
const uint8_t *const base = dht_get_self_public_key(dht);
|
||||
ck_assert_msg(store_data(announce, base, test_data.data, sizeof(test_data.data), 1), "failed to store base");
|
||||
ck_assert_msg(announce_store_data(announce, base, test_data.data, sizeof(test_data.data), 1), "failed to store base");
|
||||
|
||||
uint8_t test_keys[ANNOUNCE_BUCKET_SIZE + 1][CRYPTO_PUBLIC_KEY_SIZE];
|
||||
|
||||
for (uint8_t i = 0; i < ANNOUNCE_BUCKET_SIZE + 1; ++i) {
|
||||
memcpy(test_keys[i], base, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
test_keys[i][i] ^= 1;
|
||||
ck_assert_msg(store_data(announce, test_keys[i], test_data.data, sizeof(test_data.data), 1),
|
||||
ck_assert_msg(announce_store_data(announce, test_keys[i], test_data.data, sizeof(test_data.data), 1),
|
||||
"Failed to store announcement %d", i);
|
||||
}
|
||||
|
||||
ck_assert_msg(on_stored(announce, base, nullptr, nullptr), "base was evicted");
|
||||
ck_assert_msg(!on_stored(announce, test_keys[0], nullptr, nullptr), "furthest was not evicted");
|
||||
ck_assert_msg(!store_data(announce, test_keys[0], nullptr, 0, 1), "furthest evicted closer");
|
||||
ck_assert_msg(announce_on_stored(announce, base, nullptr, nullptr), "base was evicted");
|
||||
ck_assert_msg(!announce_on_stored(announce, test_keys[0], nullptr, nullptr), "furthest was not evicted");
|
||||
ck_assert_msg(!announce_store_data(announce, test_keys[0], nullptr, 0, 1), "furthest evicted closer");
|
||||
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
|
|
|
@ -1 +1 @@
|
|||
4e6c181b03e20cdd0669296fae53a9433e31a7c37beed5430272fbefbf501bbb /usr/local/bin/tox-bootstrapd
|
||||
146fb36bf3100115f913a07583c096c8dc98ab26e1220567e465b2ca86a69583 /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "timed_auth.h"
|
||||
#include "util.h"
|
||||
|
||||
uint8_t response_of_request_type(uint8_t request_type)
|
||||
uint8_t announce_response_of_request_type(uint8_t request_type)
|
||||
{
|
||||
switch (request_type) {
|
||||
case NET_PACKET_DATA_SEARCH_REQUEST:
|
||||
|
@ -63,7 +63,7 @@ struct Announcements {
|
|||
Announce_Entry entries[ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE];
|
||||
};
|
||||
|
||||
void set_synch_offset(Announcements *announce, int32_t synch_offset)
|
||||
void announce_set_synch_offset(Announcements *announce, int32_t synch_offset)
|
||||
{
|
||||
announce->synch_offset = synch_offset;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static uint8_t truncate_pk_at_index(const uint8_t *pk, uint16_t index, uint16_t
|
|||
((i + 1 < CRYPTO_PUBLIC_KEY_SIZE ? pk[i + 1] : 0) >> (16 - bits - j));
|
||||
}
|
||||
|
||||
uint16_t get_bucketnum(const uint8_t *base, const uint8_t *pk)
|
||||
uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk)
|
||||
{
|
||||
const uint16_t index = bit_by_bit_cmp(base, pk);
|
||||
|
||||
|
@ -106,7 +106,7 @@ uint16_t get_bucketnum(const uint8_t *base, const uint8_t *pk)
|
|||
non_null()
|
||||
static Announce_Entry *bucket_of_key(Announcements *announce, const uint8_t *pk)
|
||||
{
|
||||
return &announce->entries[get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
}
|
||||
|
||||
non_null()
|
||||
|
@ -130,7 +130,7 @@ static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_p
|
|||
non_null()
|
||||
static const Announce_Entry *bucket_of_key_const(const Announcements *announce, const uint8_t *pk)
|
||||
{
|
||||
return &announce->entries[get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
}
|
||||
|
||||
non_null()
|
||||
|
@ -152,8 +152,8 @@ static const Announce_Entry *get_stored_const(const Announcements *announce, con
|
|||
}
|
||||
|
||||
|
||||
bool on_stored(const Announcements *announce, const uint8_t *data_public_key,
|
||||
on_retrieve_cb *on_retrieve_callback, void *object)
|
||||
bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key,
|
||||
announce_on_retrieve_cb *on_retrieve_callback, void *object)
|
||||
{
|
||||
const Announce_Entry *const entry = get_stored_const(announce, data_public_key);
|
||||
|
||||
|
@ -210,7 +210,7 @@ static bool would_accept_store_request(Announcements *announce, const uint8_t *d
|
|||
return find_entry_slot(announce, data_public_key) != nullptr;
|
||||
}
|
||||
|
||||
bool store_data(Announcements *announce, const uint8_t *data_public_key,
|
||||
bool announce_store_data(Announcements *announce, const uint8_t *data_public_key,
|
||||
const uint8_t *data, uint32_t length, uint32_t timeout)
|
||||
{
|
||||
if (length > MAX_ANNOUNCEMENT_SIZE) {
|
||||
|
@ -479,7 +479,7 @@ static int create_reply_plain_store_announce_request(Announcements *announce,
|
|||
stored->store_until = mono_time_get(announce->mono_time) + timeout;
|
||||
}
|
||||
} else {
|
||||
if (!store_data(announce, data_public_key, announcement, announcement_len, timeout)) {
|
||||
if (!announce_store_data(announce, data_public_key, announcement, announcement_len, timeout)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ static int create_reply(Announcements *announce, const IP_Port *source,
|
|||
|
||||
const uint16_t plain_reply_len = plain_reply_noping_len + sizeof(uint64_t);
|
||||
|
||||
const uint8_t response_type = response_of_request_type(data[0]);
|
||||
const uint8_t response_type = announce_response_of_request_type(data[0]);
|
||||
|
||||
return dht_create_packet(announce->rng, announce->public_key, shared_key, response_type,
|
||||
plain_reply, plain_reply_len, reply, reply_max_length);
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
#define MAX_ANNOUNCEMENT_SIZE 512
|
||||
|
||||
typedef void on_retrieve_cb(void *object, const uint8_t *data, uint16_t length);
|
||||
typedef void announce_on_retrieve_cb(void *object, const uint8_t *data, uint16_t length);
|
||||
|
||||
uint8_t response_of_request_type(uint8_t request_type);
|
||||
uint8_t announce_response_of_request_type(uint8_t request_type);
|
||||
|
||||
typedef struct Announcements Announcements;
|
||||
|
||||
|
@ -24,11 +24,11 @@ Announcements *new_announcements(const Logger *log, const Random *rng, const Mon
|
|||
* @return true if data is stored, false otherwise.
|
||||
*/
|
||||
non_null(1, 2) nullable(3, 4)
|
||||
bool on_stored(const Announcements *announce, const uint8_t *data_public_key,
|
||||
on_retrieve_cb *on_retrieve_callback, void *object);
|
||||
bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key,
|
||||
announce_on_retrieve_cb *on_retrieve_callback, void *object);
|
||||
|
||||
non_null()
|
||||
void set_synch_offset(Announcements *announce, int32_t synch_offset);
|
||||
void announce_set_synch_offset(Announcements *announce, int32_t synch_offset);
|
||||
|
||||
nullable(1)
|
||||
void kill_announcements(Announcements *announce);
|
||||
|
@ -41,11 +41,11 @@ void kill_announcements(Announcements *announce);
|
|||
* base and pk first differ
|
||||
*/
|
||||
non_null()
|
||||
uint16_t get_bucketnum(const uint8_t *base, const uint8_t *pk);
|
||||
uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk);
|
||||
|
||||
/** @private */
|
||||
non_null(1, 2) nullable(3)
|
||||
bool store_data(Announcements *announce, const uint8_t *data_public_key,
|
||||
bool announce_store_data(Announcements *announce, const uint8_t *data_public_key,
|
||||
const uint8_t *data, uint32_t length, uint32_t timeout);
|
||||
|
||||
/** @private */
|
||||
|
|
Loading…
Reference in New Issue
Block a user