summaryrefslogtreecommitdiff
path: root/toxcore/assoc.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/assoc.h')
-rw-r--r--toxcore/assoc.h108
1 files changed, 0 insertions, 108 deletions
diff --git a/toxcore/assoc.h b/toxcore/assoc.h
deleted file mode 100644
index 1739d295..00000000
--- a/toxcore/assoc.h
+++ /dev/null
@@ -1,108 +0,0 @@
1#ifndef ASSOC_H
2#define ASSOC_H
3
4#include "DHT.h"
5#include "logger.h"
6#include "network.h"
7
8#include <stddef.h>
9#include <stdint.h>
10
11/* used by rendezvous */
12#define ASSOC_AVAILABLE
13
14/* For the legalese parts, see tox.h. */
15
16/* enumerated lists are superior to magic numbers */
17enum NODE_STATUS { BAD, SEENB_HEARDG, SEENG, USED };
18
19/*
20 * Module to store currently unused ID <=> IP associations
21 * for a potential future use
22 */
23
24typedef struct Assoc Assoc;
25
26/*****************************************************************************/
27
28/* custom distance handler, if it's not ID-distance based
29 * return values exactly like id_closest() */
30typedef int (*Assoc_distance_relative_callback)(const Assoc *assoc, void *callback_data, const uint8_t *client_id,
31 const uint8_t *client_id1, const uint8_t *client_id2);
32
33#define DISTANCE_INDEX_DISTANCE_BITS 44
34
35/* absolute distance: can be same for different client_id_check values
36 * return value should have DISTANCE_INDEX_DISTANCE_BITS valid bits */
37typedef uint64_t (*Assoc_distance_absolute_callback)(const Assoc *assoc, void *callback_data,
38 const uint8_t *client_id_ref, const uint8_t *client_id_check);
39
40/*****************************************************************************/
41
42/* Central entry point for new associations: add a new candidate to the cache
43 * returns 1 if entry is stored, 2 if existing entry was updated, 0 else */
44uint8_t Assoc_add_entry(Assoc *assoc, const uint8_t *id, const IPPTs *ippts_send, const IP_Port *ipp_recv,
45 uint8_t used);
46
47/*****************************************************************************/
48
49typedef enum AssocCloseEntriesFlags {
50 ProtoIPv4 = 1,
51 ProtoIPv6 = 2,
52 LANOk = 4,
53} AssocCloseEntriesFlags;
54
55typedef struct Assoc_close_entries {
56 void *custom_data; /* given to distance functions */
57 const uint8_t *wanted_id; /* the target client_id */
58 uint8_t flags; /* additional flags */
59
60 Assoc_distance_relative_callback distance_relative_func;
61 Assoc_distance_absolute_callback distance_absolute_func;
62
63 uint8_t count_good; /* that many should be "good" w.r.t. timeout */
64 uint8_t count; /* allocated number of close_indices */
65 Client_data **result;
66} Assoc_close_entries;
67
68/* find up to close_count nodes to put into close_nodes_used of ID_Nodes
69 * the distance functions can be NULL, then standard distance functions will be used
70 * the caller is responsible for allocating close_indices of sufficient size
71 *
72 * returns 0 on error
73 * returns the number of found nodes and the list of indices usable by Assoc_client()
74 * the caller is assumed to be registered from Assoc_register_callback()
75 * if they aren't, they should copy the Client_data and call Assoc_client_drop()
76 */
77uint8_t Assoc_get_close_entries(Assoc *assoc, Assoc_close_entries *state);
78
79/*****************************************************************************/
80
81/* create: default sizes (6, 5 => 320 entries) */
82Assoc *new_Assoc_default(Logger *log, const uint8_t *public_id);
83
84/* create: customized sizes
85 * total is (2^bits) * entries
86 * bits should be between 2 and 15 (else it's trimmed)
87 * entries will be reduced to the closest prime smaller or equal
88 *
89 * preferably bits should be large and entries small to ensure spread
90 * in the search space (e. g. 5, 5 is preferable to 2, 41) */
91Assoc *new_Assoc(Logger *log, size_t bits, size_t entries, const uint8_t *public_id);
92
93/* public_id changed (loaded), update which entry isn't stored */
94void Assoc_self_client_id_changed(Assoc *assoc, const uint8_t *id);
95
96/* every 45s send out a getnodes() for a "random" bucket */
97#define ASSOC_BUCKET_REFRESH 45
98
99/* refresh bucket's data from time to time
100 * this must be called only from DHT */
101void do_Assoc(Assoc *assoc, DHT *dht);
102
103/* destroy */
104void kill_Assoc(Assoc *assoc);
105
106void Assoc_status(Logger *log, const Assoc *assoc);
107
108#endif /* !ASSOC_H */