diff options
Diffstat (limited to 'toxcore/DHT.h')
-rw-r--r-- | toxcore/DHT.h | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index e5122b5e..d980f269 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -75,10 +75,22 @@ typedef struct { | |||
75 | uint64_t NATping_timestamp; | 75 | uint64_t NATping_timestamp; |
76 | } DHT_Friend; | 76 | } DHT_Friend; |
77 | 77 | ||
78 | /* this must be kept even if IP_Port is expanded: wire compatibility */ | ||
79 | typedef struct { | ||
80 | uint8_t client_id[CLIENT_ID_SIZE]; | ||
81 | IP4_Port ip_port; | ||
82 | } Node4_format; | ||
83 | |||
78 | typedef struct { | 84 | typedef struct { |
79 | uint8_t client_id[CLIENT_ID_SIZE]; | 85 | uint8_t client_id[CLIENT_ID_SIZE]; |
80 | IP_Port ip_port; | 86 | IP_Port ip_port; |
81 | } Node_format; | 87 | } Node46_format; |
88 | |||
89 | #ifdef TOX_ENABLE_IPV6 | ||
90 | typedef Node46_format Node_format; | ||
91 | #else | ||
92 | typedef Node4_format Node_format; | ||
93 | #endif | ||
82 | 94 | ||
83 | typedef struct { | 95 | typedef struct { |
84 | IP_Port ip_port; | 96 | IP_Port ip_port; |
@@ -88,15 +100,15 @@ typedef struct { | |||
88 | 100 | ||
89 | /*----------------------------------------------------------------------------------*/ | 101 | /*----------------------------------------------------------------------------------*/ |
90 | typedef struct { | 102 | typedef struct { |
91 | Net_Crypto *c; | 103 | Net_Crypto *c; |
92 | Client_data close_clientlist[LCLIENT_LIST]; | 104 | Client_data close_clientlist[LCLIENT_LIST]; |
93 | DHT_Friend *friends_list; | 105 | DHT_Friend *friends_list; |
94 | uint16_t num_friends; | 106 | uint16_t num_friends; |
95 | Pinged send_nodes[LSEND_NODES_ARRAY]; | 107 | Pinged send_nodes[LSEND_NODES_ARRAY]; |
96 | Node_format toping[MAX_TOPING]; | 108 | Node_format toping[MAX_TOPING]; |
97 | uint64_t last_toping; | 109 | uint64_t last_toping; |
98 | uint64_t close_lastgetnodes; | 110 | uint64_t close_lastgetnodes; |
99 | void *ping; | 111 | void *ping; |
100 | } DHT; | 112 | } DHT; |
101 | /*----------------------------------------------------------------------------------*/ | 113 | /*----------------------------------------------------------------------------------*/ |
102 | 114 | ||
@@ -124,11 +136,21 @@ int DHT_delfriend(DHT *dht, uint8_t *client_id); | |||
124 | * ip must be 4 bytes long. | 136 | * ip must be 4 bytes long. |
125 | * port must be 2 bytes long. | 137 | * port must be 2 bytes long. |
126 | * | 138 | * |
139 | * !!! Signature changed!!! | ||
140 | * | ||
141 | * OLD: IP_Port DHT_getfriendip(DHT *dht, uint8_t *client_id); | ||
142 | * | ||
127 | * return ip if success. | 143 | * return ip if success. |
128 | * return ip of 0 if failure (This means the friend is either offline or we have not found him yet). | 144 | * return ip of 0 if failure (This means the friend is either offline or we have not found him yet). |
129 | * return ip of 1 if friend is not in list. | 145 | * return ip of 1 if friend is not in list. |
146 | * | ||
147 | * NEW: int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); | ||
148 | * | ||
149 | * return -1, -- if client_id does NOT refer to a friend | ||
150 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) | ||
151 | * return 1, ip if client_id refers to a friend and we found him | ||
130 | */ | 152 | */ |
131 | IP_Port DHT_getfriendip(DHT *dht, uint8_t *client_id); | 153 | int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); |
132 | 154 | ||
133 | /* Run this function at least a couple times per second (It's the main loop). */ | 155 | /* Run this function at least a couple times per second (It's the main loop). */ |
134 | void do_DHT(DHT *dht); | 156 | void do_DHT(DHT *dht); |
@@ -137,6 +159,7 @@ void do_DHT(DHT *dht); | |||
137 | * Sends a get nodes request to the given node with ip port and public_key. | 159 | * Sends a get nodes request to the given node with ip port and public_key. |
138 | */ | 160 | */ |
139 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key); | 161 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key); |
162 | void DHT_bootstrap_ex(DHT *dht, const char *address, uint8_t ipv6enabled, uint16_t port, uint8_t *public_key); | ||
140 | 163 | ||
141 | /* Add nodes to the toping list. | 164 | /* Add nodes to the toping list. |
142 | * All nodes in this list are pinged every TIME_TOPING seconds | 165 | * All nodes in this list are pinged every TIME_TOPING seconds |