Coverage Report

Created: 2026-10-24 08:16

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