diff options
Diffstat (limited to 'toxcore/DHT.h')
-rw-r--r-- | toxcore/DHT.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 4beda37e..e1e14cd9 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -122,6 +122,8 @@ typedef struct { | |||
122 | uint64_t NATping_timestamp; | 122 | uint64_t NATping_timestamp; |
123 | } NAT; | 123 | } NAT; |
124 | 124 | ||
125 | #define DHT_FRIEND_MAX_LOCKS 32 | ||
126 | |||
125 | typedef struct { | 127 | typedef struct { |
126 | uint8_t client_id[CLIENT_ID_SIZE]; | 128 | uint8_t client_id[CLIENT_ID_SIZE]; |
127 | Client_data client_list[MAX_FRIEND_CLIENTS]; | 129 | Client_data client_list[MAX_FRIEND_CLIENTS]; |
@@ -133,10 +135,17 @@ typedef struct { | |||
133 | 135 | ||
134 | /* Symetric NAT hole punching stuff. */ | 136 | /* Symetric NAT hole punching stuff. */ |
135 | NAT nat; | 137 | NAT nat; |
138 | |||
139 | uint16_t lock_count; | ||
140 | struct { | ||
141 | void (*ip_callback)(void *, int32_t, IP_Port); | ||
142 | void *data; | ||
143 | int32_t number; | ||
144 | } callbacks[DHT_FRIEND_MAX_LOCKS]; | ||
145 | |||
136 | } DHT_Friend; | 146 | } DHT_Friend; |
137 | 147 | ||
138 | typedef struct __attribute__ ((__packed__)) | 148 | typedef struct { |
139 | { | ||
140 | uint8_t client_id[CLIENT_ID_SIZE]; | 149 | uint8_t client_id[CLIENT_ID_SIZE]; |
141 | IP_Port ip_port; | 150 | IP_Port ip_port; |
142 | } | 151 | } |
@@ -246,18 +255,25 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con | |||
246 | /* Add a new friend to the friends list. | 255 | /* Add a new friend to the friends list. |
247 | * client_id must be CLIENT_ID_SIZE bytes long. | 256 | * client_id must be CLIENT_ID_SIZE bytes long. |
248 | * | 257 | * |
258 | * ip_callback is the callback of a function that will be called when the ip address | ||
259 | * is found along with arguments data and number. | ||
260 | * | ||
261 | * lock_count will be set to a non zero number that must be passed to DHT_delfriend() | ||
262 | * to properly remove the callback. | ||
263 | * | ||
249 | * return 0 if success. | 264 | * return 0 if success. |
250 | * return 1 if failure (friends list is full). | 265 | * return -1 if failure (friends list is full). |
251 | */ | 266 | */ |
252 | int DHT_addfriend(DHT *dht, const uint8_t *client_id); | 267 | int DHT_addfriend(DHT *dht, const uint8_t *client_id, void (*ip_callback)(void *data, int32_t number, IP_Port), |
268 | void *data, int32_t number, uint16_t *lock_count); | ||
253 | 269 | ||
254 | /* Delete a friend from the friends list. | 270 | /* Delete a friend from the friends list. |
255 | * client_id must be CLIENT_ID_SIZE bytes long. | 271 | * client_id must be CLIENT_ID_SIZE bytes long. |
256 | * | 272 | * |
257 | * return 0 if success. | 273 | * return 0 if success. |
258 | * return 1 if failure (client_id not in friends list). | 274 | * return -1 if failure (client_id not in friends list). |
259 | */ | 275 | */ |
260 | int DHT_delfriend(DHT *dht, const uint8_t *client_id); | 276 | int DHT_delfriend(DHT *dht, const uint8_t *client_id, uint16_t lock_count); |
261 | 277 | ||
262 | /* Get ip of friend. | 278 | /* Get ip of friend. |
263 | * client_id must be CLIENT_ID_SIZE bytes long. | 279 | * client_id must be CLIENT_ID_SIZE bytes long. |