Coverage Report

Created: 2024-01-26 01:52

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