Coverage Report

Created: 2025-10-08 19:34

/work/toxcore/announce.h
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: GPL-3.0-or-later
2
 * Copyright © 2020-2025 The TokTok team.
3
 */
4
5
#ifndef C_TOXCORE_TOXCORE_ANNOUNCE_H
6
#define C_TOXCORE_TOXCORE_ANNOUNCE_H
7
8
#include <stdint.h>
9
10
#include "attributes.h"
11
#include "crypto_core.h"
12
#include "forwarding.h"
13
#include "logger.h"
14
#include "mem.h"
15
#include "mono_time.h"
16
17
36
#define MAX_ANNOUNCEMENT_SIZE 512
18
19
typedef void announce_on_retrieve_cb(void *_Nullable object, const uint8_t *_Nullable data, uint16_t length);
20
21
uint8_t announce_response_of_request_type(uint8_t request_type);
22
23
typedef struct Announcements Announcements;
24
25
Announcements *_Nullable new_announcements(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Forwarding *_Nonnull forwarding);
26
27
/**
28
 * @brief If data is stored, run `on_retrieve_callback` on it.
29
 *
30
 * @return true if data is stored, false otherwise.
31
 */
32
bool announce_on_stored(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
33
                        announce_on_retrieve_cb *_Nullable on_retrieve_callback, void *_Nullable object);
34
void announce_set_synch_offset(Announcements *_Nonnull announce, int32_t synch_offset);
35
36
void kill_announcements(Announcements *_Nullable announce);
37
/* The declarations below are not public, they are exposed only for tests. */
38
39
/** @private
40
 * Return xor of first ANNOUNCE_BUCKET_PREFIX_LENGTH bits from one bit after
41
 * base and pk first differ
42
 */
43
uint16_t announce_get_bucketnum(const uint8_t *_Nonnull base, const uint8_t *_Nonnull pk);
44
45
/** @private */
46
bool announce_store_data(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
47
                         const uint8_t *_Nullable data, uint32_t length, uint32_t timeout);
48
/** @private */
49
0
#define MAX_MAX_ANNOUNCEMENT_TIMEOUT 900
50
0
#define MIN_MAX_ANNOUNCEMENT_TIMEOUT 10
51
0
#define MAX_ANNOUNCEMENT_TIMEOUT_UPTIME_RATIO 4
52
53
/** @private
54
 * For efficient lookup and updating, entries are stored as a hash table keyed
55
 * to the first ANNOUNCE_BUCKET_PREFIX_LENGTH bits starting from one bit after
56
 * the first bit in which data public key first differs from the dht key, with
57
 * (2-adically) closest keys preferentially stored within a given bucket. A
58
 * given key appears at most once (even if timed out).
59
 */
60
571k
#define ANNOUNCE_BUCKET_SIZE 8
61
15.3k
#define ANNOUNCE_BUCKET_PREFIX_LENGTH 5
62
494k
#define ANNOUNCE_BUCKETS 32 // ANNOUNCE_BUCKETS = 2 ** ANNOUNCE_BUCKET_PREFIX_LENGTH
63
64
#endif /* C_TOXCORE_TOXCORE_ANNOUNCE_H */