diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_dht.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_dht.c | 90 |
1 files changed, 59 insertions, 31 deletions
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c index 9b11ebf18..22673b167 100644 --- a/src/cadet/gnunet-service-cadet_dht.c +++ b/src/cadet/gnunet-service-cadet_dht.c | |||
@@ -42,16 +42,24 @@ | |||
42 | */ | 42 | */ |
43 | struct GCD_search_handle | 43 | struct GCD_search_handle |
44 | { | 44 | { |
45 | /** DHT_GET handle. */ | 45 | /** |
46 | * DHT_GET handle. | ||
47 | */ | ||
46 | struct GNUNET_DHT_GetHandle *dhtget; | 48 | struct GNUNET_DHT_GetHandle *dhtget; |
47 | 49 | ||
48 | /** Provided callback to call when a path is found. */ | 50 | /** |
51 | * Provided callback to call when a path is found. | ||
52 | */ | ||
49 | GCD_search_callback callback; | 53 | GCD_search_callback callback; |
50 | 54 | ||
51 | /** Provided closure. */ | 55 | /** |
56 | * Provided closure. | ||
57 | */ | ||
52 | void *cls; | 58 | void *cls; |
53 | 59 | ||
54 | /** Peer ID searched for */ | 60 | /** |
61 | * Peer ID searched for | ||
62 | */ | ||
55 | GNUNET_PEER_Id peer_id; | 63 | GNUNET_PEER_Id peer_id; |
56 | }; | 64 | }; |
57 | 65 | ||
@@ -224,13 +232,16 @@ announce_id (void *cls) | |||
224 | announce_id_task = NULL; | 232 | announce_id_task = NULL; |
225 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n"); | 233 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n"); |
226 | hello = GCH_get_mine (); | 234 | hello = GCH_get_mine (); |
227 | size = NULL != hello ? GNUNET_HELLO_size (hello) : 0; | 235 | size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0; |
228 | if (NULL == hello || 0 == size) | 236 | if ( (NULL == hello) || (0 == size) ) |
229 | { | 237 | { |
230 | /* Peerinfo gave us no hello yet, try again soon. */ | 238 | /* Peerinfo gave us no hello yet, try again soon. */ |
231 | LOG (GNUNET_ERROR_TYPE_INFO, " no hello, waiting!\n"); | 239 | LOG (GNUNET_ERROR_TYPE_INFO, |
232 | GNUNET_STATISTICS_update (stats, "# DHT announce skipped (no hello)", | 240 | " no hello, waiting!\n"); |
233 | 1, GNUNET_NO); | 241 | GNUNET_STATISTICS_update (stats, |
242 | "# DHT announce skipped (no hello)", | ||
243 | 1, | ||
244 | GNUNET_NO); | ||
234 | expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 245 | expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
235 | announce_delay); | 246 | announce_delay); |
236 | announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay); | 247 | announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay); |
@@ -241,29 +252,43 @@ announce_id (void *cls) | |||
241 | announce_delay = GNUNET_TIME_UNIT_SECONDS; | 252 | announce_delay = GNUNET_TIME_UNIT_SECONDS; |
242 | } | 253 | } |
243 | 254 | ||
244 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Hello %p size: %u\n", hello, size); | 255 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
245 | GNUNET_STATISTICS_update (stats, "# DHT announce", | 256 | "Hello %p size: %u\n", |
246 | 1, GNUNET_NO); | 257 | hello, |
247 | memset (&phash, 0, sizeof (phash)); | 258 | size); |
248 | GNUNET_memcpy (&phash, &my_full_id, sizeof (my_full_id)); | 259 | if (NULL != hello) |
249 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | 260 | { |
250 | &phash, /* Key to use */ | 261 | GNUNET_STATISTICS_update (stats, |
251 | dht_replication_level, /* Replication level */ | 262 | "# DHT announce", |
252 | GNUNET_DHT_RO_RECORD_ROUTE | 263 | 1, GNUNET_NO); |
253 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | 264 | memset (&phash, |
254 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ | 265 | 0, |
255 | size, /* Size of the data */ | 266 | sizeof (phash)); |
256 | (const char *) hello, /* Data itself */ | 267 | GNUNET_memcpy (&phash, |
257 | expiration, /* Data expiration */ | 268 | &my_full_id, |
258 | NULL, /* Continuation */ | 269 | sizeof (my_full_id)); |
259 | NULL); /* Continuation closure */ | 270 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
260 | 271 | &phash, /* Key to use */ | |
272 | dht_replication_level, /* Replication level */ | ||
273 | GNUNET_DHT_RO_RECORD_ROUTE | ||
274 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | ||
275 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ | ||
276 | size, /* Size of the data */ | ||
277 | (const char *) hello, /* Data itself */ | ||
278 | expiration, /* Data expiration */ | ||
279 | NULL, /* Continuation */ | ||
280 | NULL); /* Continuation closure */ | ||
281 | } | ||
261 | /* Call again in id_announce_time, unless HELLO expires first, | 282 | /* Call again in id_announce_time, unless HELLO expires first, |
262 | * but wait at least 1s. */ | 283 | * but wait at least 1s. */ |
263 | next_put = GNUNET_TIME_absolute_get_remaining (expiration); | 284 | next_put = GNUNET_TIME_absolute_get_remaining (expiration); |
264 | next_put = GNUNET_TIME_relative_min (next_put, id_announce_time); | 285 | next_put = GNUNET_TIME_relative_min (next_put, |
265 | next_put = GNUNET_TIME_relative_max (next_put, GNUNET_TIME_UNIT_SECONDS); | 286 | id_announce_time); |
266 | announce_id_task = GNUNET_SCHEDULER_add_delayed (next_put, &announce_id, cls); | 287 | next_put = GNUNET_TIME_relative_max (next_put, |
288 | GNUNET_TIME_UNIT_SECONDS); | ||
289 | announce_id_task = GNUNET_SCHEDULER_add_delayed (next_put, | ||
290 | &announce_id, | ||
291 | cls); | ||
267 | } | 292 | } |
268 | 293 | ||
269 | /** | 294 | /** |
@@ -378,8 +403,11 @@ GCD_search (const struct GNUNET_PeerIdentity *peer_id, | |||
378 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 403 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
379 | NULL, /* xquery */ | 404 | NULL, /* xquery */ |
380 | 0, /* xquery bits */ | 405 | 0, /* xquery bits */ |
381 | &dht_get_id_handler, h); | 406 | &dht_get_id_handler, |
382 | GNUNET_CONTAINER_multihashmap32_put (get_requests, h->peer_id, h, | 407 | h); |
408 | GNUNET_CONTAINER_multihashmap32_put (get_requests, | ||
409 | h->peer_id, | ||
410 | h, | ||
383 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 411 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
384 | return h; | 412 | return h; |
385 | } | 413 | } |