diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2021-07-06 16:41:42 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2021-07-06 16:41:42 +0200 |
commit | a8cbc99928e0a83e249e97707b12d3ca38a81ca0 (patch) | |
tree | 464b161f7effbb1bd84814df0bbc00c968f04bdd | |
parent | 064113c2465826a6038a996b0e4cbc967e888b80 (diff) | |
download | gnunet-a8cbc99928e0a83e249e97707b12d3ca38a81ca0.tar.gz gnunet-a8cbc99928e0a83e249e97707b12d3ca38a81ca0.zip |
-more work on IP plugin
-rw-r--r-- | src/dhtu/plugin_dhtu_ip.c | 204 |
1 files changed, 192 insertions, 12 deletions
diff --git a/src/dhtu/plugin_dhtu_ip.c b/src/dhtu/plugin_dhtu_ip.c index f6ceabc2c..c76744d9a 100644 --- a/src/dhtu/plugin_dhtu_ip.c +++ b/src/dhtu/plugin_dhtu_ip.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_dhtu_plugin.h" | 28 | #include "gnunet_dhtu_plugin.h" |
29 | 29 | ||
30 | #define SCAN_FREQ GNUNET_TIME_UNIT_MINUTES | ||
31 | |||
30 | /** | 32 | /** |
31 | * Opaque handle that the underlay offers for our address to be used when | 33 | * Opaque handle that the underlay offers for our address to be used when |
32 | * sending messages to another peer. | 34 | * sending messages to another peer. |
@@ -35,9 +37,45 @@ struct GNUNET_DHTU_Source | |||
35 | { | 37 | { |
36 | 38 | ||
37 | /** | 39 | /** |
40 | * Kept in a DLL. | ||
41 | */ | ||
42 | struct GNUNET_DHTU_Source *next; | ||
43 | |||
44 | /** | ||
45 | * Kept in a DLL. | ||
46 | */ | ||
47 | struct GNUNET_DHTU_Source *prev; | ||
48 | |||
49 | /** | ||
38 | * Application context for this source. | 50 | * Application context for this source. |
39 | */ | 51 | */ |
40 | void *app_ctx; | 52 | void *app_ctx; |
53 | |||
54 | /** | ||
55 | * Address in URL form ("ip+udp://$IP:$PORT") | ||
56 | */ | ||
57 | char *address; | ||
58 | |||
59 | /** | ||
60 | * Hash of the IP address. | ||
61 | */ | ||
62 | struct GNUNET_DHTU_Hash id; | ||
63 | |||
64 | /** | ||
65 | * My actual address. | ||
66 | */ | ||
67 | struct sockaddr_storage addr; | ||
68 | |||
69 | /** | ||
70 | * Number of bytes in @a addr. | ||
71 | */ | ||
72 | socklen_t addrlen; | ||
73 | |||
74 | /** | ||
75 | * Last generation this address was observed. | ||
76 | */ | ||
77 | unsigned int scan_generation; | ||
78 | |||
41 | }; | 79 | }; |
42 | 80 | ||
43 | 81 | ||
@@ -62,8 +100,18 @@ struct GNUNET_DHTU_Target | |||
62 | * Tail of preferences expressed for this target. | 100 | * Tail of preferences expressed for this target. |
63 | */ | 101 | */ |
64 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; | 102 | struct GNUNET_DHTU_PreferenceHandle *ph_tail; |
103 | |||
104 | /** | ||
105 | * Target IP address. | ||
106 | */ | ||
107 | struct sockaddr_storage addr; | ||
65 | 108 | ||
66 | /** | 109 | /** |
110 | * Number of bytes in @a addr. | ||
111 | */ | ||
112 | socklen_t addrlen; | ||
113 | |||
114 | /** | ||
67 | * Preference counter, length of the @a ph_head DLL. | 115 | * Preference counter, length of the @a ph_head DLL. |
68 | */ | 116 | */ |
69 | unsigned int ph_count; | 117 | unsigned int ph_count; |
@@ -94,15 +142,6 @@ struct GNUNET_DHTU_PreferenceHandle | |||
94 | 142 | ||
95 | 143 | ||
96 | /** | 144 | /** |
97 | * Opaque handle for a private key used by this underlay. | ||
98 | */ | ||
99 | struct GNUNET_DHTU_PrivateKey | ||
100 | { | ||
101 | /* we are IP, we do not do crypto */ | ||
102 | }; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Closure for all plugin functions. | 145 | * Closure for all plugin functions. |
107 | */ | 146 | */ |
108 | struct Plugin | 147 | struct Plugin |
@@ -113,9 +152,34 @@ struct Plugin | |||
113 | struct GNUNET_DHTU_PluginEnvironment *env; | 152 | struct GNUNET_DHTU_PluginEnvironment *env; |
114 | 153 | ||
115 | /** | 154 | /** |
155 | * Head of sources where we receive traffic. | ||
156 | */ | ||
157 | struct GNUNET_DHTU_Source *src_head; | ||
158 | |||
159 | /** | ||
160 | * Tail of sources where we receive traffic. | ||
161 | */ | ||
162 | struct GNUNET_DHTU_Source *src_tail; | ||
163 | |||
164 | /** | ||
165 | * Task that scans for IP address changes. | ||
166 | */ | ||
167 | struct GNUNET_SCHEDULER_Task *scan_task; | ||
168 | |||
169 | /** | ||
116 | * Port we bind to. FIXME: initialize... | 170 | * Port we bind to. FIXME: initialize... |
117 | */ | 171 | */ |
118 | char *my_port; | 172 | char *my_port; |
173 | |||
174 | /** | ||
175 | * How often have we scanned for IPs? | ||
176 | */ | ||
177 | unsigned int scan_generation; | ||
178 | |||
179 | /** | ||
180 | * My UDP socket. | ||
181 | */ | ||
182 | int sock; | ||
119 | }; | 183 | }; |
120 | 184 | ||
121 | 185 | ||
@@ -293,7 +357,120 @@ ip_send (void *cls, | |||
293 | GNUNET_SCHEDULER_TaskCallback finished_cb, | 357 | GNUNET_SCHEDULER_TaskCallback finished_cb, |
294 | void *finished_cb_cls) | 358 | void *finished_cb_cls) |
295 | { | 359 | { |
296 | GNUNET_break (0); | 360 | struct Plugin *plugin = cls; |
361 | |||
362 | sendto (plugin->sock, | ||
363 | msg, | ||
364 | msg_size, | ||
365 | 0, | ||
366 | (const struct sockaddr *) &target->addr, | ||
367 | target->addrlen); | ||
368 | finished_cb (finished_cb_cls); | ||
369 | } | ||
370 | |||
371 | |||
372 | /** | ||
373 | * Callback function invoked for each interface found. | ||
374 | * | ||
375 | * @param cls closure | ||
376 | * @param name name of the interface (can be NULL for unknown) | ||
377 | * @param isDefault is this presumably the default interface | ||
378 | * @param addr address of this interface (can be NULL for unknown or unassigned) | ||
379 | * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) | ||
380 | * @param netmask the network mask (can be NULL for unknown or unassigned) | ||
381 | * @param addrlen length of the address | ||
382 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort | ||
383 | */ | ||
384 | static int | ||
385 | process_ifcs (void *cls, | ||
386 | const char *name, | ||
387 | int isDefault, | ||
388 | const struct sockaddr *addr, | ||
389 | const struct sockaddr *broadcast_addr, | ||
390 | const struct sockaddr *netmask, | ||
391 | socklen_t addrlen) | ||
392 | { | ||
393 | struct Plugin *plugin = cls; | ||
394 | struct GNUNET_DHTU_Source *src; | ||
395 | |||
396 | for (src = plugin->src_head; | ||
397 | NULL != src; | ||
398 | src = src->next) | ||
399 | { | ||
400 | if ( (addrlen == src->addrlen) && | ||
401 | (0 == memcmp (addr, | ||
402 | &src->addr, | ||
403 | addrlen)) ) | ||
404 | { | ||
405 | src->scan_generation = plugin->scan_generation; | ||
406 | return GNUNET_OK; | ||
407 | } | ||
408 | } | ||
409 | src = GNUNET_new (struct GNUNET_DHTU_Source); | ||
410 | src->addrlen = addrlen; | ||
411 | memcpy (&src->addr, | ||
412 | addr, | ||
413 | addrlen); | ||
414 | src->scan_generation = plugin->scan_generation; | ||
415 | switch (addr->sa_family) | ||
416 | { | ||
417 | case AF_INET: | ||
418 | // hash v4 address | ||
419 | // convert address to src->address | ||
420 | break; | ||
421 | case AF_INET6: | ||
422 | // hash v6 address | ||
423 | // convert address to src->address | ||
424 | break; | ||
425 | default: | ||
426 | GNUNET_break (0); | ||
427 | GNUNET_free (src); | ||
428 | return GNUNET_OK; | ||
429 | } | ||
430 | GNUNET_CONTAINER_DLL_insert (plugin->src_head, | ||
431 | plugin->src_tail, | ||
432 | src); | ||
433 | plugin->env->address_add_cb (plugin->env->cls, | ||
434 | &src->id, | ||
435 | NULL, /* no key */ | ||
436 | src->address, | ||
437 | src, | ||
438 | &src->app_ctx); | ||
439 | return GNUNET_OK; | ||
440 | } | ||
441 | |||
442 | |||
443 | /** | ||
444 | * Scan network interfaces for IP address changes. | ||
445 | * | ||
446 | * @param cls a `struct Plugin` | ||
447 | */ | ||
448 | static void | ||
449 | scan (void *cls) | ||
450 | { | ||
451 | struct Plugin *plugin = cls; | ||
452 | struct GNUNET_DHTU_Source *next; | ||
453 | |||
454 | plugin->scan_generation++; | ||
455 | GNUNET_OS_network_interfaces_list (&process_ifcs, | ||
456 | plugin); | ||
457 | for (struct GNUNET_DHTU_Source *src = plugin->src_head; | ||
458 | NULL != src; | ||
459 | src = next) | ||
460 | { | ||
461 | next = src->next; | ||
462 | if (src->scan_generation == plugin->scan_generation) | ||
463 | continue; | ||
464 | GNUNET_CONTAINER_DLL_remove (plugin->src_head, | ||
465 | plugin->src_tail, | ||
466 | src); | ||
467 | plugin->env->address_del_cb (src->app_ctx); | ||
468 | GNUNET_free (src->address); | ||
469 | GNUNET_free (src); | ||
470 | } | ||
471 | plugin->scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ, | ||
472 | &scan, | ||
473 | plugin); | ||
297 | } | 474 | } |
298 | 475 | ||
299 | 476 | ||
@@ -312,9 +489,11 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
312 | 489 | ||
313 | plugin = GNUNET_new (struct Plugin); | 490 | plugin = GNUNET_new (struct Plugin); |
314 | plugin->env = env; | 491 | plugin->env = env; |
315 | // FIXME: port configuration? | 492 | // FIXME: get port configuration! |
316 | // FIXME: figure out our own IP addresses... | 493 | plugin->scan_task = GNUNET_SCHEDULER_add_now (&scan, |
494 | plugin); | ||
317 | // FIXME: bind, start receive loop | 495 | // FIXME: bind, start receive loop |
496 | // FIXME: deal with NSE callback... | ||
318 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); | 497 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); |
319 | api->cls = plugin; | 498 | api->cls = plugin; |
320 | api->sign = &ip_sign; | 499 | api->sign = &ip_sign; |
@@ -339,6 +518,7 @@ libgnunet_plugin_dhtu_ip_done (void *cls) | |||
339 | struct GNUNET_DHTU_PluginFunctions *api = cls; | 518 | struct GNUNET_DHTU_PluginFunctions *api = cls; |
340 | struct Plugin *plugin = api->cls; | 519 | struct Plugin *plugin = api->cls; |
341 | 520 | ||
521 | GNUNET_SCHEDULER_cancel (plugin->scan_task); | ||
342 | GNUNET_free (plugin); | 522 | GNUNET_free (plugin); |
343 | GNUNET_free (api); | 523 | GNUNET_free (api); |
344 | return NULL; | 524 | return NULL; |