diff options
-rw-r--r-- | src/cadet/gnunet-service-cadet_dht.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c index 9b11ebf18..43b1c8252 100644 --- a/src/cadet/gnunet-service-cadet_dht.c +++ b/src/cadet/gnunet-service-cadet_dht.c | |||
@@ -224,13 +224,16 @@ announce_id (void *cls) | |||
224 | announce_id_task = NULL; | 224 | announce_id_task = NULL; |
225 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n"); | 225 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n"); |
226 | hello = GCH_get_mine (); | 226 | hello = GCH_get_mine (); |
227 | size = NULL != hello ? GNUNET_HELLO_size (hello) : 0; | 227 | size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0; |
228 | if (NULL == hello || 0 == size) | 228 | if ( (NULL == hello) || (0 == size) ) |
229 | { | 229 | { |
230 | /* Peerinfo gave us no hello yet, try again soon. */ | 230 | /* Peerinfo gave us no hello yet, try again soon. */ |
231 | LOG (GNUNET_ERROR_TYPE_INFO, " no hello, waiting!\n"); | 231 | LOG (GNUNET_ERROR_TYPE_INFO, |
232 | GNUNET_STATISTICS_update (stats, "# DHT announce skipped (no hello)", | 232 | " no hello, waiting!\n"); |
233 | 1, GNUNET_NO); | 233 | GNUNET_STATISTICS_update (stats, |
234 | "# DHT announce skipped (no hello)", | ||
235 | 1, | ||
236 | GNUNET_NO); | ||
234 | expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 237 | expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
235 | announce_delay); | 238 | announce_delay); |
236 | announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay); | 239 | announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay); |
@@ -241,29 +244,43 @@ announce_id (void *cls) | |||
241 | announce_delay = GNUNET_TIME_UNIT_SECONDS; | 244 | announce_delay = GNUNET_TIME_UNIT_SECONDS; |
242 | } | 245 | } |
243 | 246 | ||
244 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Hello %p size: %u\n", hello, size); | 247 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
245 | GNUNET_STATISTICS_update (stats, "# DHT announce", | 248 | "Hello %p size: %u\n", |
246 | 1, GNUNET_NO); | 249 | hello, |
247 | memset (&phash, 0, sizeof (phash)); | 250 | size); |
248 | GNUNET_memcpy (&phash, &my_full_id, sizeof (my_full_id)); | 251 | if (NULL != hello) |
249 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | 252 | { |
250 | &phash, /* Key to use */ | 253 | GNUNET_STATISTICS_update (stats, |
251 | dht_replication_level, /* Replication level */ | 254 | "# DHT announce", |
252 | GNUNET_DHT_RO_RECORD_ROUTE | 255 | 1, GNUNET_NO); |
253 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | 256 | memset (&phash, |
254 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ | 257 | 0, |
255 | size, /* Size of the data */ | 258 | sizeof (phash)); |
256 | (const char *) hello, /* Data itself */ | 259 | GNUNET_memcpy (&phash, |
257 | expiration, /* Data expiration */ | 260 | &my_full_id, |
258 | NULL, /* Continuation */ | 261 | sizeof (my_full_id)); |
259 | NULL); /* Continuation closure */ | 262 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
260 | 263 | &phash, /* Key to use */ | |
264 | dht_replication_level, /* Replication level */ | ||
265 | GNUNET_DHT_RO_RECORD_ROUTE | ||
266 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | ||
267 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ | ||
268 | size, /* Size of the data */ | ||
269 | (const char *) hello, /* Data itself */ | ||
270 | expiration, /* Data expiration */ | ||
271 | NULL, /* Continuation */ | ||
272 | NULL); /* Continuation closure */ | ||
273 | } | ||
261 | /* Call again in id_announce_time, unless HELLO expires first, | 274 | /* Call again in id_announce_time, unless HELLO expires first, |
262 | * but wait at least 1s. */ | 275 | * but wait at least 1s. */ |
263 | next_put = GNUNET_TIME_absolute_get_remaining (expiration); | 276 | next_put = GNUNET_TIME_absolute_get_remaining (expiration); |
264 | next_put = GNUNET_TIME_relative_min (next_put, id_announce_time); | 277 | next_put = GNUNET_TIME_relative_min (next_put, |
265 | next_put = GNUNET_TIME_relative_max (next_put, GNUNET_TIME_UNIT_SECONDS); | 278 | id_announce_time); |
266 | announce_id_task = GNUNET_SCHEDULER_add_delayed (next_put, &announce_id, cls); | 279 | next_put = GNUNET_TIME_relative_max (next_put, |
280 | GNUNET_TIME_UNIT_SECONDS); | ||
281 | announce_id_task = GNUNET_SCHEDULER_add_delayed (next_put, | ||
282 | &announce_id, | ||
283 | cls); | ||
267 | } | 284 | } |
268 | 285 | ||
269 | /** | 286 | /** |
@@ -378,8 +395,11 @@ GCD_search (const struct GNUNET_PeerIdentity *peer_id, | |||
378 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 395 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
379 | NULL, /* xquery */ | 396 | NULL, /* xquery */ |
380 | 0, /* xquery bits */ | 397 | 0, /* xquery bits */ |
381 | &dht_get_id_handler, h); | 398 | &dht_get_id_handler, |
382 | GNUNET_CONTAINER_multihashmap32_put (get_requests, h->peer_id, h, | 399 | h); |
400 | GNUNET_CONTAINER_multihashmap32_put (get_requests, | ||
401 | h->peer_id, | ||
402 | h, | ||
383 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 403 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
384 | return h; | 404 | return h; |
385 | } | 405 | } |