diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 21:51:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-19 12:39:55 +0100 |
commit | ba9296269617c157baffb59a6240c87ae5935e95 (patch) | |
tree | 7f82470cce894be0b3441f8150baea36d7138834 /src/dhtu | |
parent | 25ef40ef768743a10b7b29881c267e0fdc9fc677 (diff) | |
download | gnunet-ba9296269617c157baffb59a6240c87ae5935e95.tar.gz gnunet-ba9296269617c157baffb59a6240c87ae5935e95.zip |
first steps towards usable dhtu
Diffstat (limited to 'src/dhtu')
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 30 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_ip.c | 264 |
2 files changed, 137 insertions, 157 deletions
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index 2163af941..a75c47ce3 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -70,11 +70,6 @@ struct GNUNET_DHTU_Source | |||
70 | { | 70 | { |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Hash of @e pid, position of this peer in the DHT overlay. | ||
74 | */ | ||
75 | struct GNUNET_DHTU_HashKey id; | ||
76 | |||
77 | /** | ||
78 | * Application context for this source. | 73 | * Application context for this source. |
79 | */ | 74 | */ |
80 | void *app_ctx; | 75 | void *app_ctx; |
@@ -125,11 +120,6 @@ struct GNUNET_DHTU_Target | |||
125 | struct GNUNET_PeerIdentity pid; | 120 | struct GNUNET_PeerIdentity pid; |
126 | 121 | ||
127 | /** | 122 | /** |
128 | * Hash of @e pid, position of this peer in the DHT overlay. | ||
129 | */ | ||
130 | struct GNUNET_DHTU_HashKey id; | ||
131 | |||
132 | /** | ||
133 | * Preference counter, length of the @a ph_head DLL. | 123 | * Preference counter, length of the @a ph_head DLL. |
134 | */ | 124 | */ |
135 | unsigned int ph_count; | 125 | unsigned int ph_count; |
@@ -240,10 +230,12 @@ hello_offered_cb (void *cls) | |||
240 | * Request creation of a session with a peer at the given @a address. | 230 | * Request creation of a session with a peer at the given @a address. |
241 | * | 231 | * |
242 | * @param cls closure (internal context for the plugin) | 232 | * @param cls closure (internal context for the plugin) |
233 | * @param pid target identity of the peer to connect to | ||
243 | * @param address target address to connect to | 234 | * @param address target address to connect to |
244 | */ | 235 | */ |
245 | static void | 236 | static void |
246 | ip_try_connect (void *cls, | 237 | ip_try_connect (void *cls, |
238 | struct GNUNET_PeerIdentity *pid, | ||
247 | const char *address) | 239 | const char *address) |
248 | { | 240 | { |
249 | struct Plugin *plugin = cls; | 241 | struct Plugin *plugin = cls; |
@@ -251,16 +243,13 @@ ip_try_connect (void *cls, | |||
251 | struct HelloHandle *hh; | 243 | struct HelloHandle *hh; |
252 | struct GNUNET_CRYPTO_EddsaPublicKey pubkey; | 244 | struct GNUNET_CRYPTO_EddsaPublicKey pubkey; |
253 | 245 | ||
246 | (void) pid; /* will be needed with future address URIs */ | ||
254 | if (GNUNET_OK != | 247 | if (GNUNET_OK != |
255 | GNUNET_HELLO_parse_uri (address, | 248 | GNUNET_HELLO_parse_uri (address, |
256 | &pubkey, | 249 | &pubkey, |
257 | &hello, | 250 | &hello, |
258 | &GPI_plugins_find)) | 251 | &GPI_plugins_find)) |
259 | { | ||
260 | GNUNET_break (0); | ||
261 | return; | 252 | return; |
262 | } | ||
263 | |||
264 | hh = GNUNET_new (struct HelloHandle); | 253 | hh = GNUNET_new (struct HelloHandle); |
265 | hh->plugin = plugin; | 254 | hh->plugin = plugin; |
266 | GNUNET_CONTAINER_DLL_insert (plugin->hh_head, | 255 | GNUNET_CONTAINER_DLL_insert (plugin->hh_head, |
@@ -394,12 +383,9 @@ core_connect_cb (void *cls, | |||
394 | target->plugin = plugin; | 383 | target->plugin = plugin; |
395 | target->mq = mq; | 384 | target->mq = mq; |
396 | target->pid = *peer; | 385 | target->pid = *peer; |
397 | GNUNET_CRYPTO_hash (peer, | ||
398 | sizeof (*peer), | ||
399 | &target->id.sha512); | ||
400 | plugin->env->connect_cb (plugin->env->cls, | 386 | plugin->env->connect_cb (plugin->env->cls, |
401 | target, | 387 | target, |
402 | &target->id, | 388 | &target->pid, |
403 | &target->app_ctx); | 389 | &target->app_ctx); |
404 | return target; | 390 | return target; |
405 | } | 391 | } |
@@ -461,11 +447,7 @@ peerinfo_cb (void *cls, | |||
461 | &GPI_plugins_find); | 447 | &GPI_plugins_find); |
462 | if (NULL == addr) | 448 | if (NULL == addr) |
463 | return; | 449 | return; |
464 | GNUNET_CRYPTO_hash (peer, | ||
465 | sizeof (*peer), | ||
466 | &plugin->src.id.sha512); | ||
467 | plugin->env->address_add_cb (plugin->env->cls, | 450 | plugin->env->address_add_cb (plugin->env->cls, |
468 | &plugin->src.id, | ||
469 | addr, | 451 | addr, |
470 | &plugin->src, | 452 | &plugin->src, |
471 | &plugin->src.app_ctx); | 453 | &plugin->src.app_ctx); |
@@ -584,6 +566,10 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) | |||
584 | } | 566 | } |
585 | if (NULL != plugin->nse) | 567 | if (NULL != plugin->nse) |
586 | GNUNET_NSE_disconnect (plugin->nse); | 568 | GNUNET_NSE_disconnect (plugin->nse); |
569 | plugin->env->network_size_cb (plugin->env->cls, | ||
570 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
571 | 0.0, | ||
572 | 0.0); | ||
587 | if (NULL != plugin->core) | 573 | if (NULL != plugin->core) |
588 | GNUNET_CORE_disconnect (plugin->core); | 574 | GNUNET_CORE_disconnect (plugin->core); |
589 | if (NULL != plugin->ats) | 575 | if (NULL != plugin->ats) |
diff --git a/src/dhtu/plugin_dhtu_ip.c b/src/dhtu/plugin_dhtu_ip.c index 8eec6294b..7c01e5baf 100644 --- a/src/dhtu/plugin_dhtu_ip.c +++ b/src/dhtu/plugin_dhtu_ip.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 2022 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -56,17 +56,12 @@ struct GNUNET_DHTU_Source | |||
56 | struct GNUNET_DHTU_Source *prev; | 56 | struct GNUNET_DHTU_Source *prev; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Position of this peer in the DHT. | ||
60 | */ | ||
61 | struct GNUNET_DHTU_HashKey id; | ||
62 | |||
63 | /** | ||
64 | * Application context for this source. | 59 | * Application context for this source. |
65 | */ | 60 | */ |
66 | void *app_ctx; | 61 | void *app_ctx; |
67 | 62 | ||
68 | /** | 63 | /** |
69 | * Address in URL form ("ip+udp://$IP:$PORT") | 64 | * Address in URL form ("ip+udp://$PID/$IP:$PORT") |
70 | */ | 65 | */ |
71 | char *address; | 66 | char *address; |
72 | 67 | ||
@@ -121,9 +116,9 @@ struct GNUNET_DHTU_Target | |||
121 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; | 116 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; |
122 | 117 | ||
123 | /** | 118 | /** |
124 | * Position of this peer in the DHT. | 119 | * Peer's identity. |
125 | */ | 120 | */ |
126 | struct GNUNET_DHTU_HashKey id; | 121 | struct GNUNET_PeerIdentity pid; |
127 | 122 | ||
128 | /** | 123 | /** |
129 | * Target IP address. | 124 | * Target IP address. |
@@ -217,14 +212,19 @@ struct Plugin | |||
217 | char *port; | 212 | char *port; |
218 | 213 | ||
219 | /** | 214 | /** |
220 | * How often have we scanned for IPs? | 215 | * My UDP socket. |
221 | */ | 216 | */ |
222 | unsigned int scan_generation; | 217 | struct GNUNET_NETWORK_Handle *sock; |
223 | 218 | ||
224 | /** | 219 | /** |
225 | * My UDP socket. | 220 | * My identity. |
226 | */ | 221 | */ |
227 | struct GNUNET_NETWORK_Handle *sock; | 222 | struct GNUNET_PeerIdentity my_id; |
223 | |||
224 | /** | ||
225 | * How often have we scanned for IPs? | ||
226 | */ | ||
227 | unsigned int scan_generation; | ||
228 | }; | 228 | }; |
229 | 229 | ||
230 | 230 | ||
@@ -232,12 +232,14 @@ struct Plugin | |||
232 | * Create a target to which we may send traffic. | 232 | * Create a target to which we may send traffic. |
233 | * | 233 | * |
234 | * @param plugin our plugin | 234 | * @param plugin our plugin |
235 | * @param pid presumed identity of the target | ||
235 | * @param addr target address | 236 | * @param addr target address |
236 | * @param addrlen number of bytes in @a addr | 237 | * @param addrlen number of bytes in @a addr |
237 | * @return new target object | 238 | * @return new target object |
238 | */ | 239 | */ |
239 | static struct GNUNET_DHTU_Target * | 240 | static struct GNUNET_DHTU_Target * |
240 | create_target (struct Plugin *plugin, | 241 | create_target (struct Plugin *plugin, |
242 | const struct GNUNET_PeerIdentity *pid, | ||
241 | const struct sockaddr *addr, | 243 | const struct sockaddr *addr, |
242 | socklen_t addrlen) | 244 | socklen_t addrlen) |
243 | { | 245 | { |
@@ -275,42 +277,16 @@ create_target (struct Plugin *plugin, | |||
275 | } | 277 | } |
276 | dst = GNUNET_new (struct GNUNET_DHTU_Target); | 278 | dst = GNUNET_new (struct GNUNET_DHTU_Target); |
277 | dst->addrlen = addrlen; | 279 | dst->addrlen = addrlen; |
280 | dst->pid = *pid; | ||
278 | memcpy (&dst->addr, | 281 | memcpy (&dst->addr, |
279 | addr, | 282 | addr, |
280 | addrlen); | 283 | addrlen); |
281 | switch (addr->sa_family) | ||
282 | { | ||
283 | case AF_INET: | ||
284 | { | ||
285 | const struct sockaddr_in *s4 = (const struct sockaddr_in *) addr; | ||
286 | |||
287 | GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); | ||
288 | GNUNET_CRYPTO_hash (&s4->sin_addr, | ||
289 | sizeof (struct in_addr), | ||
290 | &dst->id.sha512); | ||
291 | } | ||
292 | break; | ||
293 | case AF_INET6: | ||
294 | { | ||
295 | const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) addr; | ||
296 | |||
297 | GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); | ||
298 | GNUNET_CRYPTO_hash (&s6->sin6_addr, | ||
299 | sizeof (struct in6_addr), | ||
300 | &dst->id.sha512); | ||
301 | } | ||
302 | break; | ||
303 | default: | ||
304 | GNUNET_break (0); | ||
305 | GNUNET_free (dst); | ||
306 | return NULL; | ||
307 | } | ||
308 | GNUNET_CONTAINER_DLL_insert (plugin->dst_head, | 284 | GNUNET_CONTAINER_DLL_insert (plugin->dst_head, |
309 | plugin->dst_tail, | 285 | plugin->dst_tail, |
310 | dst); | 286 | dst); |
311 | plugin->env->connect_cb (plugin->env->cls, | 287 | plugin->env->connect_cb (plugin->env->cls, |
312 | dst, | 288 | dst, |
313 | &dst->id, | 289 | &dst->pid, |
314 | &dst->app_ctx); | 290 | &dst->app_ctx); |
315 | return dst; | 291 | return dst; |
316 | } | 292 | } |
@@ -321,6 +297,7 @@ create_target (struct Plugin *plugin, | |||
321 | * create one! | 297 | * create one! |
322 | * | 298 | * |
323 | * @param plugin the plugin handle | 299 | * @param plugin the plugin handle |
300 | * @param pid presumed identity of the target | ||
324 | * @param src source target is from, or NULL if unknown | 301 | * @param src source target is from, or NULL if unknown |
325 | * @param addr socket address to find | 302 | * @param addr socket address to find |
326 | * @param addrlen number of bytes in @a addr | 303 | * @param addrlen number of bytes in @a addr |
@@ -328,6 +305,7 @@ create_target (struct Plugin *plugin, | |||
328 | */ | 305 | */ |
329 | static struct GNUNET_DHTU_Target * | 306 | static struct GNUNET_DHTU_Target * |
330 | find_target (struct Plugin *plugin, | 307 | find_target (struct Plugin *plugin, |
308 | const struct GNUNET_PeerIdentity *pid, | ||
331 | const void *addr, | 309 | const void *addr, |
332 | size_t addrlen) | 310 | size_t addrlen) |
333 | { | 311 | { |
@@ -342,6 +320,7 @@ find_target (struct Plugin *plugin, | |||
342 | if (NULL == dst) | 320 | if (NULL == dst) |
343 | { | 321 | { |
344 | dst = create_target (plugin, | 322 | dst = create_target (plugin, |
323 | pid, | ||
345 | (const struct sockaddr *) addr, | 324 | (const struct sockaddr *) addr, |
346 | addrlen); | 325 | addrlen); |
347 | GNUNET_assert (GNUNET_YES == | 326 | GNUNET_assert (GNUNET_YES == |
@@ -370,10 +349,12 @@ find_target (struct Plugin *plugin, | |||
370 | * Request creation of a session with a peer at the given @a address. | 349 | * Request creation of a session with a peer at the given @a address. |
371 | * | 350 | * |
372 | * @param cls closure (internal context for the plugin) | 351 | * @param cls closure (internal context for the plugin) |
352 | * @param pid identity of the target peer | ||
373 | * @param address target address to connect to | 353 | * @param address target address to connect to |
374 | */ | 354 | */ |
375 | static void | 355 | static void |
376 | ip_try_connect (void *cls, | 356 | ip_try_connect (void *cls, |
357 | struct GNUNET_PeerIdentity *pid, | ||
377 | const char *address) | 358 | const char *address) |
378 | { | 359 | { |
379 | struct Plugin *plugin = cls; | 360 | struct Plugin *plugin = cls; |
@@ -384,24 +365,19 @@ ip_try_connect (void *cls, | |||
384 | .ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | 365 | .ai_flags = AI_NUMERICHOST | AI_NUMERICSERV |
385 | }; | 366 | }; |
386 | struct addrinfo *result = NULL; | 367 | struct addrinfo *result = NULL; |
368 | char *epid; | ||
387 | 369 | ||
388 | if (0 != | 370 | if (0 != |
389 | strncmp (address, | 371 | strncmp (address, |
390 | "ip+", | 372 | "ip+", |
391 | strlen ("ip+"))) | 373 | strlen ("ip+"))) |
392 | { | ||
393 | GNUNET_break (0); | ||
394 | return; | 374 | return; |
395 | } | ||
396 | address += strlen ("ip+"); | 375 | address += strlen ("ip+"); |
397 | if (0 != | 376 | if (0 != |
398 | strncmp (address, | 377 | strncmp (address, |
399 | "udp://", | 378 | "udp://", |
400 | strlen ("udp://"))) | 379 | strlen ("udp://"))) |
401 | { | ||
402 | GNUNET_break (0); | ||
403 | return; | 380 | return; |
404 | } | ||
405 | address += strlen ("udp://"); | 381 | address += strlen ("udp://"); |
406 | addr = GNUNET_strdup (address); | 382 | addr = GNUNET_strdup (address); |
407 | colon = strchr (addr, ':'); | 383 | colon = strchr (addr, ':'); |
@@ -426,6 +402,7 @@ ip_try_connect (void *cls, | |||
426 | } | 402 | } |
427 | GNUNET_free (addr); | 403 | GNUNET_free (addr); |
428 | (void) find_target (plugin, | 404 | (void) find_target (plugin, |
405 | pid, | ||
429 | result->ai_addr, | 406 | result->ai_addr, |
430 | result->ai_addrlen); | 407 | result->ai_addrlen); |
431 | freeaddrinfo (result); | 408 | freeaddrinfo (result); |
@@ -499,10 +476,17 @@ ip_send (void *cls, | |||
499 | void *finished_cb_cls) | 476 | void *finished_cb_cls) |
500 | { | 477 | { |
501 | struct Plugin *plugin = cls; | 478 | struct Plugin *plugin = cls; |
502 | 479 | char buf[sizeof (plugin->my_id) + msg_size]; | |
480 | |||
481 | memcpy (buf, | ||
482 | &plugin->my_id, | ||
483 | sizeof (plugin->my_id)); | ||
484 | memcpy (&buf[sizeof (plugin->my_id)], | ||
485 | msg, | ||
486 | msg_size); | ||
503 | GNUNET_NETWORK_socket_sendto (plugin->sock, | 487 | GNUNET_NETWORK_socket_sendto (plugin->sock, |
504 | msg, | 488 | buf, |
505 | msg_size, | 489 | sizeof (buf), |
506 | (const struct sockaddr *) &target->addr, | 490 | (const struct sockaddr *) &target->addr, |
507 | target->addrlen); | 491 | target->addrlen); |
508 | finished_cb (finished_cb_cls); | 492 | finished_cb (finished_cb_cls); |
@@ -523,6 +507,7 @@ create_source (struct Plugin *plugin, | |||
523 | socklen_t addrlen) | 507 | socklen_t addrlen) |
524 | { | 508 | { |
525 | struct GNUNET_DHTU_Source *src; | 509 | struct GNUNET_DHTU_Source *src; |
510 | char *pid; | ||
526 | 511 | ||
527 | src = GNUNET_new (struct GNUNET_DHTU_Source); | 512 | src = GNUNET_new (struct GNUNET_DHTU_Source); |
528 | src->addrlen = addrlen; | 513 | src->addrlen = addrlen; |
@@ -538,9 +523,6 @@ create_source (struct Plugin *plugin, | |||
538 | char buf[INET_ADDRSTRLEN]; | 523 | char buf[INET_ADDRSTRLEN]; |
539 | 524 | ||
540 | GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); | 525 | GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); |
541 | GNUNET_CRYPTO_hash (&s4->sin_addr, | ||
542 | sizeof (struct in_addr), | ||
543 | &src->id.sha512); | ||
544 | GNUNET_asprintf (&src->address, | 526 | GNUNET_asprintf (&src->address, |
545 | "ip+udp://%s:%u", | 527 | "ip+udp://%s:%u", |
546 | inet_ntop (AF_INET, | 528 | inet_ntop (AF_INET, |
@@ -556,9 +538,6 @@ create_source (struct Plugin *plugin, | |||
556 | char buf[INET6_ADDRSTRLEN]; | 538 | char buf[INET6_ADDRSTRLEN]; |
557 | 539 | ||
558 | GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); | 540 | GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); |
559 | GNUNET_CRYPTO_hash (&s6->sin6_addr, | ||
560 | sizeof (struct in6_addr), | ||
561 | &src->id.sha512); | ||
562 | GNUNET_asprintf (&src->address, | 541 | GNUNET_asprintf (&src->address, |
563 | "ip+udp://[%s]:%u", | 542 | "ip+udp://[%s]:%u", |
564 | inet_ntop (AF_INET6, | 543 | inet_ntop (AF_INET6, |
@@ -570,6 +549,7 @@ create_source (struct Plugin *plugin, | |||
570 | break; | 549 | break; |
571 | default: | 550 | default: |
572 | GNUNET_break (0); | 551 | GNUNET_break (0); |
552 | GNUNET_free (pid); | ||
573 | GNUNET_free (src); | 553 | GNUNET_free (src); |
574 | return NULL; | 554 | return NULL; |
575 | } | 555 | } |
@@ -577,7 +557,6 @@ create_source (struct Plugin *plugin, | |||
577 | plugin->src_tail, | 557 | plugin->src_tail, |
578 | src); | 558 | src); |
579 | plugin->env->address_add_cb (plugin->env->cls, | 559 | plugin->env->address_add_cb (plugin->env->cls, |
580 | &src->id, | ||
581 | src->address, | 560 | src->address, |
582 | src, | 561 | src, |
583 | &src->app_ctx); | 562 | &src->app_ctx); |
@@ -597,7 +576,7 @@ create_source (struct Plugin *plugin, | |||
597 | * @param addrlen length of the address | 576 | * @param addrlen length of the address |
598 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort | 577 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort |
599 | */ | 578 | */ |
600 | static int | 579 | static enum GNUNET_GenericReturnValue |
601 | process_ifcs (void *cls, | 580 | process_ifcs (void *cls, |
602 | const char *name, | 581 | const char *name, |
603 | int isDefault, | 582 | int isDefault, |
@@ -704,7 +683,8 @@ read_cb (void *cls) | |||
704 | { | 683 | { |
705 | struct Plugin *plugin = cls; | 684 | struct Plugin *plugin = cls; |
706 | ssize_t ret; | 685 | ssize_t ret; |
707 | char buf[65536]; | 686 | const struct GNUNET_PeerIdentity *pid; |
687 | char buf[65536] GNUNET_ALIGN; | ||
708 | struct sockaddr_storage sa; | 688 | struct sockaddr_storage sa; |
709 | struct iovec iov = { | 689 | struct iovec iov = { |
710 | .iov_base = buf, | 690 | .iov_base = buf, |
@@ -719,98 +699,101 @@ read_cb (void *cls) | |||
719 | .msg_control = ctl, | 699 | .msg_control = ctl, |
720 | .msg_controllen = sizeof (ctl) | 700 | .msg_controllen = sizeof (ctl) |
721 | }; | 701 | }; |
702 | struct GNUNET_DHTU_Target *dst = NULL; | ||
703 | struct GNUNET_DHTU_Source *src = NULL; | ||
704 | struct cmsghdr *cmsg; | ||
722 | 705 | ||
723 | ret = recvmsg (GNUNET_NETWORK_get_fd (plugin->sock), | 706 | ret = recvmsg (GNUNET_NETWORK_get_fd (plugin->sock), |
724 | &mh, | 707 | &mh, |
725 | MSG_DONTWAIT); | 708 | MSG_DONTWAIT); |
726 | if (ret >= 0) | 709 | plugin->read_task = GNUNET_SCHEDULER_add_read_net ( |
710 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
711 | plugin->sock, | ||
712 | &read_cb, | ||
713 | plugin); | ||
714 | if (ret < 0) | ||
715 | return; /* read failure, hopefully EAGAIN */ | ||
716 | if (ret < sizeof (*pid)) | ||
727 | { | 717 | { |
728 | struct GNUNET_DHTU_Target *dst = NULL; | 718 | GNUNET_break_op (0); |
729 | struct GNUNET_DHTU_Source *src = NULL; | 719 | return; |
730 | struct cmsghdr *cmsg; | 720 | } |
731 | 721 | /* find IP where we received message */ | |
732 | /* find IP where we received message */ | 722 | for (cmsg = CMSG_FIRSTHDR (&mh); |
733 | for (cmsg = CMSG_FIRSTHDR (&mh); | 723 | NULL != cmsg; |
734 | NULL != cmsg; | 724 | cmsg = CMSG_NXTHDR (&mh, |
735 | cmsg = CMSG_NXTHDR (&mh, | 725 | cmsg)) |
736 | cmsg)) | 726 | { |
727 | if ( (cmsg->cmsg_level == IPPROTO_IP) && | ||
728 | (cmsg->cmsg_type == IP_PKTINFO) ) | ||
737 | { | 729 | { |
738 | if ( (cmsg->cmsg_level == IPPROTO_IP) && | 730 | if (CMSG_LEN (sizeof (struct in_pktinfo)) == |
739 | (cmsg->cmsg_type == IP_PKTINFO) ) | 731 | cmsg->cmsg_len) |
740 | { | 732 | { |
741 | if (CMSG_LEN (sizeof (struct in_pktinfo)) == | 733 | struct in_pktinfo pi; |
742 | cmsg->cmsg_len) | 734 | |
735 | memcpy (&pi, | ||
736 | CMSG_DATA (cmsg), | ||
737 | sizeof (pi)); | ||
743 | { | 738 | { |
744 | struct in_pktinfo pi; | 739 | struct sockaddr_in sa = { |
745 | 740 | .sin_family = AF_INET, | |
746 | memcpy (&pi, | 741 | .sin_addr = pi.ipi_addr |
747 | CMSG_DATA (cmsg), | 742 | }; |
748 | sizeof (pi)); | 743 | |
749 | { | 744 | src = find_source (plugin, |
750 | struct sockaddr_in sa = { | 745 | &sa, |
751 | .sin_family = AF_INET, | 746 | sizeof (sa)); |
752 | .sin_addr = pi.ipi_addr | ||
753 | }; | ||
754 | |||
755 | src = find_source (plugin, | ||
756 | &sa, | ||
757 | sizeof (sa)); | ||
758 | } | ||
759 | break; | ||
760 | } | 747 | } |
761 | else | 748 | break; |
762 | GNUNET_break (0); | ||
763 | } | 749 | } |
764 | if ( (cmsg->cmsg_level == IPPROTO_IPV6) && | 750 | else |
765 | (cmsg->cmsg_type == IPV6_RECVPKTINFO) ) | 751 | GNUNET_break (0); |
752 | } | ||
753 | if ( (cmsg->cmsg_level == IPPROTO_IPV6) && | ||
754 | (cmsg->cmsg_type == IPV6_RECVPKTINFO) ) | ||
755 | { | ||
756 | if (CMSG_LEN (sizeof (struct in6_pktinfo)) == | ||
757 | cmsg->cmsg_len) | ||
766 | { | 758 | { |
767 | if (CMSG_LEN (sizeof (struct in6_pktinfo)) == | 759 | struct in6_pktinfo pi; |
768 | cmsg->cmsg_len) | 760 | |
761 | memcpy (&pi, | ||
762 | CMSG_DATA (cmsg), | ||
763 | sizeof (pi)); | ||
769 | { | 764 | { |
770 | struct in6_pktinfo pi; | 765 | struct sockaddr_in6 sa = { |
771 | 766 | .sin6_family = AF_INET6, | |
772 | memcpy (&pi, | 767 | .sin6_addr = pi.ipi6_addr, |
773 | CMSG_DATA (cmsg), | 768 | .sin6_scope_id = pi.ipi6_ifindex |
774 | sizeof (pi)); | 769 | }; |
775 | { | 770 | |
776 | struct sockaddr_in6 sa = { | 771 | src = find_source (plugin, |
777 | .sin6_family = AF_INET6, | 772 | &sa, |
778 | .sin6_addr = pi.ipi6_addr, | 773 | sizeof (sa)); |
779 | .sin6_scope_id = pi.ipi6_ifindex | 774 | break; |
780 | }; | ||
781 | |||
782 | src = find_source (plugin, | ||
783 | &sa, | ||
784 | sizeof (sa)); | ||
785 | break; | ||
786 | } | ||
787 | } | 775 | } |
788 | else | ||
789 | GNUNET_break (0); | ||
790 | } | 776 | } |
791 | } | 777 | else |
792 | dst = find_target (plugin, | 778 | GNUNET_break (0); |
793 | &sa, | ||
794 | mh.msg_namelen); | ||
795 | if ( (NULL == src) || | ||
796 | (NULL == dst) ) | ||
797 | { | ||
798 | GNUNET_break (0); | ||
799 | } | ||
800 | else | ||
801 | { | ||
802 | plugin->env->receive_cb (plugin->env->cls, | ||
803 | dst->app_ctx, | ||
804 | src->app_ctx, | ||
805 | buf, | ||
806 | ret); | ||
807 | } | 779 | } |
808 | } | 780 | } |
809 | plugin->read_task = GNUNET_SCHEDULER_add_read_net ( | 781 | pid = (const struct GNUNET_PeerIdentity *) buf; |
810 | GNUNET_TIME_UNIT_FOREVER_REL, | 782 | dst = find_target (plugin, |
811 | plugin->sock, | 783 | pid, |
812 | &read_cb, | 784 | &sa, |
813 | plugin); | 785 | mh.msg_namelen); |
786 | if ( (NULL == src) || | ||
787 | (NULL == dst) ) | ||
788 | { | ||
789 | GNUNET_break (0); | ||
790 | return; | ||
791 | } | ||
792 | plugin->env->receive_cb (plugin->env->cls, | ||
793 | dst->app_ctx, | ||
794 | src->app_ctx, | ||
795 | &buf[sizeof(*pid)], | ||
796 | ret - sizeof (*pid)); | ||
814 | } | 797 | } |
815 | 798 | ||
816 | 799 | ||
@@ -874,6 +857,13 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
874 | plugin = GNUNET_new (struct Plugin); | 857 | plugin = GNUNET_new (struct Plugin); |
875 | plugin->env = env; | 858 | plugin->env = env; |
876 | plugin->port = port; | 859 | plugin->port = port; |
860 | if (GNUNET_OK != | ||
861 | GNUNET_CRYPTO_get_peer_identity (env->cfg, | ||
862 | &plugin->my_id)) | ||
863 | { | ||
864 | GNUNET_free (plugin); | ||
865 | return NULL; | ||
866 | } | ||
877 | af = AF_INET6; | 867 | af = AF_INET6; |
878 | sock = socket (af, | 868 | sock = socket (af, |
879 | SOCK_DGRAM, | 869 | SOCK_DGRAM, |
@@ -1017,6 +1007,10 @@ libgnunet_plugin_dhtu_ip_done (void *cls) | |||
1017 | GNUNET_free (src->address); | 1007 | GNUNET_free (src->address); |
1018 | GNUNET_free (src); | 1008 | GNUNET_free (src); |
1019 | } | 1009 | } |
1010 | plugin->env->network_size_cb (plugin->env->cls, | ||
1011 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
1012 | 0.0, | ||
1013 | 0.0); | ||
1020 | GNUNET_CONTAINER_multihashmap_destroy (plugin->dsts); | 1014 | GNUNET_CONTAINER_multihashmap_destroy (plugin->dsts); |
1021 | GNUNET_SCHEDULER_cancel (plugin->scan_task); | 1015 | GNUNET_SCHEDULER_cancel (plugin->scan_task); |
1022 | GNUNET_break (0 == | 1016 | GNUNET_break (0 == |