aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dht/Makefile.am1
-rw-r--r--src/dht/gnunet-service-dht.c286
-rw-r--r--src/dht/gnunet-service-dht.h8
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c235
-rw-r--r--src/dht/gnunet-service-dht_neighbours.h46
-rw-r--r--src/dht/gnunet-service-dht_nse.c121
-rw-r--r--src/dht/gnunet-service-dht_nse.h52
-rw-r--r--src/dht/plugin_block_dht.c325
-rw-r--r--src/dhtu/plugin_dhtu_gnunet.c30
-rw-r--r--src/dhtu/plugin_dhtu_ip.c264
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_block_lib.h6
-rw-r--r--src/include/gnunet_dhtu_plugin.h23
-rw-r--r--src/include/gnunet_hello_uri_lib.h169
14 files changed, 917 insertions, 650 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index be48fab02..44439f66f 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -59,7 +59,6 @@ gnunet_service_dht_SOURCES = \
59 gnunet-service-dht.c gnunet-service-dht.h \ 59 gnunet-service-dht.c gnunet-service-dht.h \
60 gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \ 60 gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \
61 gnunet-service-dht_hello.c gnunet-service-dht_hello.h \ 61 gnunet-service-dht_hello.c gnunet-service-dht_hello.h \
62 gnunet-service-dht_nse.c gnunet-service-dht_nse.h \
63 gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \ 62 gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \
64 gnunet-service-dht_routing.c gnunet-service-dht_routing.h 63 gnunet-service-dht_routing.c gnunet-service-dht_routing.h
65gnunet_service_dht_LDADD = \ 64gnunet_service_dht_LDADD = \
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index da46dcfee..6f2573d26 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -27,8 +27,6 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_block_lib.h" 28#include "gnunet_block_lib.h"
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_transport_service.h"
31#include "gnunet_transport_hello_service.h"
32#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
33#include "gnunet_dht_service.h" 31#include "gnunet_dht_service.h"
34#include "gnunet_statistics_service.h" 32#include "gnunet_statistics_service.h"
@@ -36,44 +34,223 @@
36#include "gnunet-service-dht_datacache.h" 34#include "gnunet-service-dht_datacache.h"
37#include "gnunet-service-dht_hello.h" 35#include "gnunet-service-dht_hello.h"
38#include "gnunet-service-dht_neighbours.h" 36#include "gnunet-service-dht_neighbours.h"
39#include "gnunet-service-dht_nse.h"
40#include "gnunet-service-dht_routing.h" 37#include "gnunet-service-dht_routing.h"
41 38
39
40/**
41 * Information we keep per underlay.
42 */
43struct Underlay
44{
45
46 /**
47 * Kept in a DLL.
48 */
49 struct Underlay *next;
50
51 /**
52 * Kept in a DLL.
53 */
54 struct Underlay *prev;
55
56 /**
57 * Environment for this underlay.
58 */
59 struct GNUNET_DHTU_PluginEnvironment env;
60
61 /**
62 * Underlay API handle.
63 */
64 struct GNUNET_DHTU_PluginFunctions *dhtu;
65
66 /**
67 * current network size estimate for this underlay.
68 */
69 double network_size_estimate;
70
71 /**
72 * Name of the underlay (i.e. "gnunet" or "ip").
73 */
74 char *name;
75};
76
77
78/**
79 * An address of this peer.
80 */
81struct MyAddress
82{
83 /**
84 * Kept in a DLL.
85 */
86 struct MyAddress *next;
87
88 /**
89 * Kept in a DLL.
90 */
91 struct MyAddress *prev;
92
93 /**
94 * Underlay handle for the address.
95 */
96 struct GNUNET_DHTU_Source *source;
97
98 /**
99 * Textual representation of the address.
100 */
101 char *url;
102
103 /**
104 * Underlay of this address.
105 */
106 struct Underlay *u;
107};
108
109
42/** 110/**
43 * Our HELLO 111 * Our HELLO
44 */ 112 */
45struct GNUNET_MessageHeader *GDS_my_hello; 113struct GNUNET_MessageHeader *GDS_my_hello;
46 114
47/** 115/**
48 * Handle to get our current HELLO. 116 * Handles for the DHT underlays.
117 */
118static struct Underlay *u_head;
119
120/**
121 * Handles for the DHT underlays.
122 */
123static struct Underlay *u_tail;
124
125/**
126 * Head of addresses of this peer.
127 */
128static struct MyAddress *a_head;
129
130/**
131 * Tail of addresses of this peer.
49 */ 132 */
50static struct GNUNET_TRANSPORT_HelloGetHandle *ghh; 133static struct MyAddress *a_tail;
51 134
52/** 135/**
53 * Hello address expiration 136 * Hello address expiration
54 */ 137 */
55struct GNUNET_TIME_Relative hello_expiration; 138struct GNUNET_TIME_Relative hello_expiration;
56 139
140/**
141 * log of the current network size estimate, used as the point where
142 * we switch between random and deterministic routing.
143 */
144static double log_of_network_size_estimate;
57 145
58#include "gnunet-service-dht_clients.c" 146
147/**
148 * Callback that is called when network size estimate is updated.
149 *
150 * @param cls a `struct Underlay`
151 * @param timestamp time when the estimate was received from the server (or created by the server)
152 * @param logestimate the log(Base 2) value of the current network size estimate
153 * @param std_dev standard deviation for the estimate
154 *
155 */
156static void
157update_network_size_estimate (void *cls,
158 struct GNUNET_TIME_Absolute timestamp,
159 double logestimate,
160 double std_dev)
161{
162 struct Underlay *u = cls;
163 double sum = 0.0;
164
165 GNUNET_STATISTICS_update (GDS_stats,
166 "# Network size estimates received",
167 1,
168 GNUNET_NO);
169 /* do not allow estimates < 0.5 */
170 u->network_size_estimate = pow (2.0,
171 GNUNET_MAX (0.5,
172 logestimate));
173 for (struct Underlay *p; NULL != p; p = p->next)
174 sum += p->network_size_estimate;
175 if (sum <= 2.0)
176 log_of_network_size_estimate = 0.5;
177 else
178 log_of_network_size_estimate = log2 (sum);
179}
59 180
60 181
61/** 182/**
62 * Receive the HELLO from transport service, free current and replace 183 * Return the current NSE
63 * if necessary.
64 * 184 *
65 * @param cls NULL 185 * @return the current NSE as a logarithm
66 * @param message HELLO message of peer 186 */
187double
188GDS_NSE_get (void)
189{
190 return log_of_network_size_estimate;
191}
192
193
194#include "gnunet-service-dht_clients.c"
195
196
197/**
198 * Update our HELLO with all of our our addresses.
67 */ 199 */
68static void 200static void
69process_hello (void *cls, 201update_hello (void)
70 const struct GNUNET_MessageHeader *message)
71{ 202{
72 GNUNET_free (GDS_my_hello); 203 GNUNET_free (GDS_my_hello);
73 GDS_my_hello = GNUNET_malloc (ntohs (message->size)); 204 // FIXME: build new HELLO properly!
74 GNUNET_memcpy (GDS_my_hello, 205}
75 message, 206
76 ntohs (message->size)); 207
208/**
209 * Function to call with new addresses of this peer.
210 *
211 * @param cls the closure
212 * @param address address under which we are likely reachable,
213 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://$PID/1.1.1.1:2086/"
214 * @param source handle for sending from this address, NULL if we can only receive
215 * @param[out] ctx storage space for DHT to use in association with this address
216 */
217static void
218u_address_add (void *cls,
219 const char *address,
220 struct GNUNET_DHTU_Source *source,
221 void **ctx)
222{
223 struct Underlay *u = cls;
224 struct MyAddress *a;
225
226 a = GNUNET_new (struct MyAddress);
227 a->source = source;
228 a->url = GNUNET_strdup (address);
229 a->u = u;
230 GNUNET_CONTAINER_DLL_insert (a_head,
231 a_tail,
232 a);
233 *ctx = a;
234 update_hello ();
235}
236
237
238/**
239 * Function to call with expired addresses of this peer.
240 *
241 * @param[in] ctx storage space used by the DHT in association with this address
242 */
243static void
244u_address_del (void *ctx)
245{
246 struct MyAddress *a = ctx;
247
248 GNUNET_CONTAINER_DLL_remove (a_head,
249 a_tail,
250 a);
251 GNUNET_free (a->url);
252 GNUNET_free (a);
253 update_hello ();
77} 254}
78 255
79 256
@@ -85,16 +262,10 @@ process_hello (void *cls,
85static void 262static void
86shutdown_task (void *cls) 263shutdown_task (void *cls)
87{ 264{
88 if (NULL != ghh)
89 {
90 GNUNET_TRANSPORT_hello_get_cancel (ghh);
91 ghh = NULL;
92 }
93 GDS_NEIGHBOURS_done (); 265 GDS_NEIGHBOURS_done ();
94 GDS_DATACACHE_done (); 266 GDS_DATACACHE_done ();
95 GDS_ROUTING_done (); 267 GDS_ROUTING_done ();
96 GDS_HELLO_done (); 268 GDS_HELLO_done ();
97 GDS_NSE_done ();
98 if (NULL != GDS_block_context) 269 if (NULL != GDS_block_context)
99 { 270 {
100 GNUNET_BLOCK_context_destroy (GDS_block_context); 271 GNUNET_BLOCK_context_destroy (GDS_block_context);
@@ -113,6 +284,57 @@ shutdown_task (void *cls)
113 284
114 285
115/** 286/**
287 * Function iterating over all configuration sections.
288 * Loads plugins for enabled DHT underlays.
289 *
290 * @param cls NULL
291 * @param section configuration section to inspect
292 */
293static void
294load_underlay (void *cls,
295 const char *section)
296{
297 struct Underlay *u;
298 char *libname;
299
300 (void) cls;
301 if (0 != strncasecmp (section,
302 "dhtu-",
303 strlen ("dhtu-")))
304 return;
305 if (GNUNET_YES !=
306 GNUNET_CONFIGURATION_get_value_yesno (GDS_cfg,
307 section,
308 "ENABLED"))
309 return;
310 section += strlen ("dhtu-");
311 u = GNUNET_new (struct Underlay);
312 u->env.cls = u;
313 u->env.address_add_cb = &u_address_add;
314 u->env.address_del_cb = &u_address_del;
315 u->env.network_size_cb = &update_network_size_estimate;
316 u->env.connect_cb = &GDS_u_connect;
317 u->env.disconnect_cb = &GDS_u_disconnect;
318 u->env.receive_cb = &GDS_u_receive;
319 GNUNET_asprintf (&libname,
320 "libgnunet_plugin_dhtu_%s",
321 section);
322 u->dhtu = GNUNET_PLUGIN_load (libname,
323 &u->env);
324 if (NULL == u->dhtu)
325 {
326 GNUNET_free (libname);
327 GNUNET_free (u);
328 return;
329 }
330 u->name = GNUNET_strdup (section);
331 GNUNET_CONTAINER_DLL_insert (u_head,
332 u_tail,
333 u);
334}
335
336
337/**
116 * Process dht requests. 338 * Process dht requests.
117 * 339 *
118 * @param cls closure 340 * @param cls closure
@@ -137,23 +359,21 @@ run (void *cls,
137 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 359 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
138 GDS_stats = GNUNET_STATISTICS_create ("dht", 360 GDS_stats = GNUNET_STATISTICS_create ("dht",
139 GDS_cfg); 361 GDS_cfg);
140 GNUNET_SERVICE_suspend (GDS_service);
141 GDS_CLIENTS_init (); 362 GDS_CLIENTS_init ();
142 GDS_ROUTING_init (); 363 GDS_ROUTING_init ();
143 GDS_NSE_init ();
144 GDS_DATACACHE_init (); 364 GDS_DATACACHE_init ();
145 GDS_HELLO_init (); 365 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
146 if (GNUNET_OK != GDS_NEIGHBOURS_init ()) 366 NULL);
367 GNUNET_CONFIGURATION_iterate_sections (GDS_cfg,
368 &load_underlay,
369 NULL);
370 if (NULL == u_head)
147 { 371 {
148 shutdown_task (NULL); 372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
373 "No DHT underlays configured!\n");
374 GNUNET_SCHEDULER_shutdown ();
149 return; 375 return;
150 } 376 }
151 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
152 NULL);
153 ghh = GNUNET_TRANSPORT_hello_get (GDS_cfg,
154 GNUNET_TRANSPORT_AC_GLOBAL,
155 &process_hello,
156 NULL);
157} 377}
158 378
159 379
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h
index 367ff426e..687e2d4d3 100644
--- a/src/dht/gnunet-service-dht.h
+++ b/src/dht/gnunet-service-dht.h
@@ -128,4 +128,12 @@ GDS_CLIENTS_process_put (enum GNUNET_DHT_RouteOption options,
128 uint32_t hop_count, 128 uint32_t hop_count,
129 uint32_t desired_replication_level); 129 uint32_t desired_replication_level);
130 130
131/**
132 * Return the current NSE
133 *
134 * @return the current NSE as a logarithm
135 */
136double
137GDS_NSE_get (void);
138
131#endif 139#endif
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index cf150ea0c..bc473df69 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -28,13 +28,10 @@
28#include "gnunet_constants.h" 28#include "gnunet_constants.h"
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30#include "gnunet_signatures.h" 30#include "gnunet_signatures.h"
31#include "gnunet_ats_service.h"
32#include "gnunet_core_service.h"
33#include "gnunet_hello_lib.h" 31#include "gnunet_hello_lib.h"
34#include "gnunet-service-dht.h" 32#include "gnunet-service-dht.h"
35#include "gnunet-service-dht_hello.h" 33#include "gnunet-service-dht_hello.h"
36#include "gnunet-service-dht_neighbours.h" 34#include "gnunet-service-dht_neighbours.h"
37#include "gnunet-service-dht_nse.h"
38#include "gnunet-service-dht_routing.h" 35#include "gnunet-service-dht_routing.h"
39#include "dht.h" 36#include "dht.h"
40 37
@@ -278,12 +275,12 @@ struct PeerInfo
278 /** 275 /**
279 * Handle for sending messages to this peer. 276 * Handle for sending messages to this peer.
280 */ 277 */
281 struct GNUNET_MQ_Handle *mq; 278 struct GNUNET_DHTU_Target *target;
282 279
283 /** 280 /**
284 * What is the identity of the peer? 281 * What is the identity of the peer?
285 */ 282 */
286 const struct GNUNET_PeerIdentity *id; 283 struct GNUNET_PeerIdentity id;
287 284
288 /** 285 /**
289 * Hash of @e id. 286 * Hash of @e id.
@@ -332,7 +329,7 @@ struct ConnectInfo
332 /** 329 /**
333 * Handle to active connectivity suggestion operation, or NULL. 330 * Handle to active connectivity suggestion operation, or NULL.
334 */ 331 */
335 struct GNUNET_ATS_ConnectivitySuggestHandle *sh; 332 struct GNUNET_DHTU_PreferenceHandle *ph;
336 333
337 /** 334 /**
338 * How much would we like to connect to this peer? 335 * How much would we like to connect to this peer?
@@ -400,16 +397,6 @@ static struct GNUNET_PeerIdentity my_identity;
400struct GNUNET_HashCode my_identity_hash; 397struct GNUNET_HashCode my_identity_hash;
401 398
402/** 399/**
403 * Handle to CORE.
404 */
405static struct GNUNET_CORE_Handle *core_api;
406
407/**
408 * Handle to ATS connectivity.
409 */
410static struct GNUNET_ATS_ConnectivityHandle *ats_ch;
411
412/**
413 * Our private key. 400 * Our private key.
414 */ 401 */
415static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; 402static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key;
@@ -517,10 +504,10 @@ free_connect_info (void *cls,
517 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers, 504 GNUNET_CONTAINER_multipeermap_remove (all_desired_peers,
518 peer, 505 peer,
519 ci)); 506 ci));
520 if (NULL != ci->sh) 507 if (NULL != ci->ph)
521 { 508 {
522 GNUNET_ATS_connectivity_suggest_cancel (ci->sh); 509 // ci->u->drop (ci->ph); // FIXME!
523 ci->sh = NULL; 510 ci->ph = NULL;
524 } 511 }
525 if (NULL != ci->oh) 512 if (NULL != ci->oh)
526 { 513 {
@@ -597,14 +584,18 @@ try_connect (const struct GNUNET_PeerIdentity *pid,
597 h, 584 h,
598 &offer_hello_done, 585 &offer_hello_done,
599 ci); 586 ci);
600 if ( (NULL != ci->sh) && 587 if ( (NULL != ci->ph) &&
601 (ci->strength != strength) ) 588 (ci->strength != strength) )
602 GNUNET_ATS_connectivity_suggest_cancel (ci->sh); 589 {
590 // ci->u_api->drop (ci->ph);
591 ci->ph = NULL;
592 }
603 if (ci->strength != strength) 593 if (ci->strength != strength)
604 { 594 {
605 ci->sh = GNUNET_ATS_connectivity_suggest (ats_ch, 595#if FIXME
606 pid, 596 ci->ph = ci->u_api->hold (ci->u_api->cls,
607 strength); 597 TARGET);
598#endif
608 ci->strength = strength; 599 ci->strength = strength;
609 } 600 }
610} 601}
@@ -719,7 +710,7 @@ send_find_peer_message (void *cls)
719 struct GNUNET_CONTAINER_BloomFilter *peer_bf; 710 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
720 711
721 bg = GNUNET_BLOCK_group_create (GDS_block_context, 712 bg = GNUNET_BLOCK_group_create (GDS_block_context,
722 GNUNET_BLOCK_TYPE_DHT_HELLO, 713 GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
723 GNUNET_CRYPTO_random_u32 ( 714 GNUNET_CRYPTO_random_u32 (
724 GNUNET_CRYPTO_QUALITY_WEAK, 715 GNUNET_CRYPTO_QUALITY_WEAK,
725 UINT32_MAX), 716 UINT32_MAX),
@@ -736,7 +727,7 @@ send_find_peer_message (void *cls)
736 DHT_BLOOM_SIZE, 727 DHT_BLOOM_SIZE,
737 GNUNET_CONSTANTS_BLOOMFILTER_K); 728 GNUNET_CONSTANTS_BLOOMFILTER_K);
738 if (GNUNET_OK != 729 if (GNUNET_OK !=
739 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_HELLO, 730 GDS_NEIGHBOURS_handle_get (GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
740 GNUNET_DHT_RO_FIND_PEER 731 GNUNET_DHT_RO_FIND_PEER
741 | GNUNET_DHT_RO_RECORD_ROUTE, 732 | GNUNET_DHT_RO_RECORD_ROUTE,
742 FIND_PEER_REPLICATION_LEVEL, 733 FIND_PEER_REPLICATION_LEVEL,
@@ -764,18 +755,11 @@ send_find_peer_message (void *cls)
764} 755}
765 756
766 757
767/** 758void
768 * Method called whenever a peer connects. 759GDS_u_connect (void *cls,
769 * 760 struct GNUNET_DHTU_Target *target,
770 * @param cls closure 761 const struct GNUNET_PeerIdentity *pid,
771 * @param peer peer identity this notification is about 762 void **ctx)
772 * @param mq message queue for sending messages to @a peer
773 * @return our `struct PeerInfo` for @a peer
774 */
775static void *
776handle_core_connect (void *cls,
777 const struct GNUNET_PeerIdentity *peer,
778 struct GNUNET_MQ_Handle *mq)
779{ 763{
780 struct PeerInfo *pi; 764 struct PeerInfo *pi;
781 struct PeerBucket *bucket; 765 struct PeerBucket *bucket;
@@ -783,23 +767,23 @@ handle_core_connect (void *cls,
783 (void) cls; 767 (void) cls;
784 /* Check for connect to self message */ 768 /* Check for connect to self message */
785 if (0 == GNUNET_memcmp (&my_identity, 769 if (0 == GNUNET_memcmp (&my_identity,
786 peer)) 770 pid))
787 return NULL; 771 return;
788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 "Connected to peer %s\n", 773 "Connected to peer %s\n",
790 GNUNET_i2s (peer)); 774 GNUNET_i2s (pid));
791 GNUNET_assert (NULL == 775 GNUNET_assert (NULL ==
792 GNUNET_CONTAINER_multipeermap_get (all_connected_peers, 776 GNUNET_CONTAINER_multipeermap_get (all_connected_peers,
793 peer)); 777 pid));
794 GNUNET_STATISTICS_update (GDS_stats, 778 GNUNET_STATISTICS_update (GDS_stats,
795 "# peers connected", 779 "# peers connected",
796 1, 780 1,
797 GNUNET_NO); 781 GNUNET_NO);
798 pi = GNUNET_new (struct PeerInfo); 782 pi = GNUNET_new (struct PeerInfo);
799 pi->id = peer; 783 pi->id = *pid;
800 pi->mq = mq; 784 pi->target = target;
801 GNUNET_CRYPTO_hash (peer, 785 GNUNET_CRYPTO_hash (pid,
802 sizeof(struct GNUNET_PeerIdentity), 786 sizeof(*pid),
803 &pi->phash); 787 &pi->phash);
804 pi->peer_bucket = find_bucket (&pi->phash); 788 pi->peer_bucket = find_bucket (&pi->phash);
805 GNUNET_assert ( (pi->peer_bucket >= 0) && 789 GNUNET_assert ( (pi->peer_bucket >= 0) &&
@@ -813,7 +797,7 @@ handle_core_connect (void *cls,
813 (unsigned int) pi->peer_bucket + 1); 797 (unsigned int) pi->peer_bucket + 1);
814 GNUNET_assert (GNUNET_OK == 798 GNUNET_assert (GNUNET_OK ==
815 GNUNET_CONTAINER_multipeermap_put (all_connected_peers, 799 GNUNET_CONTAINER_multipeermap_put (all_connected_peers,
816 pi->id, 800 &pi->id,
817 pi, 801 pi,
818 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 802 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
819 if (bucket->peers_size <= bucket_size) 803 if (bucket->peers_size <= bucket_size)
@@ -829,39 +813,34 @@ handle_core_connect (void *cls,
829 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message, 813 find_peer_task = GNUNET_SCHEDULER_add_now (&send_find_peer_message,
830 NULL); 814 NULL);
831 } 815 }
832 return pi; 816 *ctx = pi;
833} 817}
834 818
835 819
836/** 820/**
837 * Method called whenever a peer disconnects. 821 * Method called whenever a peer disconnects.
838 * 822 *
839 * @param cls closure 823 * @param ctx context
840 * @param peer peer identity this notification is about
841 * @param internal_cls our `struct PeerInfo` for @a peer
842 */ 824 */
843static void 825void
844handle_core_disconnect (void *cls, 826GDS_u_disconnect (void *ctx)
845 const struct GNUNET_PeerIdentity *peer,
846 void *internal_cls)
847{ 827{
848 struct PeerInfo *to_remove = internal_cls; 828 struct PeerInfo *to_remove = ctx;
849 struct PeerBucket *bucket; 829 struct PeerBucket *bucket;
850 830
851 (void) cls;
852 /* Check for disconnect from self message (on shutdown) */ 831 /* Check for disconnect from self message (on shutdown) */
853 if (NULL == to_remove) 832 if (NULL == to_remove)
854 return; 833 return;
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "Disconnected from peer %s\n", 835 "Disconnected from peer %s\n",
857 GNUNET_i2s (peer)); 836 GNUNET_i2s (&to_remove->id));
858 GNUNET_STATISTICS_update (GDS_stats, 837 GNUNET_STATISTICS_update (GDS_stats,
859 "# peers connected", 838 "# peers connected",
860 -1, 839 -1,
861 GNUNET_NO); 840 GNUNET_NO);
862 GNUNET_assert (GNUNET_YES == 841 GNUNET_assert (GNUNET_YES ==
863 GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, 842 GNUNET_CONTAINER_multipeermap_remove (all_connected_peers,
864 peer, 843 &to_remove->id,
865 to_remove)); 844 to_remove));
866 if ( (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) && 845 if ( (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers)) &&
867 (GNUNET_YES != disable_try_connect)) 846 (GNUNET_YES != disable_try_connect))
@@ -1073,7 +1052,7 @@ select_peer (const struct GNUNET_HashCode *key,
1073 { 1052 {
1074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1053 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1075 "Excluded peer `%s' due to BF match in greedy routing for %s\n", 1054 "Excluded peer `%s' due to BF match in greedy routing for %s\n",
1076 GNUNET_i2s (pos->id), 1055 GNUNET_i2s (&pos->id),
1077 GNUNET_h2s (key)); 1056 GNUNET_h2s (key));
1078 continue; 1057 continue;
1079 } 1058 }
@@ -1140,7 +1119,7 @@ select_peer (const struct GNUNET_HashCode *key,
1140 } 1119 }
1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 "Selected peer `%s' in greedy routing for %s\n", 1121 "Selected peer `%s' in greedy routing for %s\n",
1143 GNUNET_i2s (chosen->id), 1122 GNUNET_i2s (&chosen->id),
1144 GNUNET_h2s (key)); 1123 GNUNET_h2s (key));
1145 return chosen; 1124 return chosen;
1146 } /* end of 'greedy' peer selection */ 1125 } /* end of 'greedy' peer selection */
@@ -1170,7 +1149,7 @@ select_peer (const struct GNUNET_HashCode *key,
1170 { 1149 {
1171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1172 "Excluded peer `%s' due to BF match in random routing for %s\n", 1151 "Excluded peer `%s' due to BF match in random routing for %s\n",
1173 GNUNET_i2s (pos->id), 1152 GNUNET_i2s (&pos->id),
1174 GNUNET_h2s (key)); 1153 GNUNET_h2s (key));
1175 continue; /* Ignore filtered peers */ 1154 continue; /* Ignore filtered peers */
1176 } 1155 }
@@ -1209,7 +1188,7 @@ select_peer (const struct GNUNET_HashCode *key,
1209 { 1188 {
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "Selected peer `%s' in random routing for %s\n", 1190 "Selected peer `%s' in random routing for %s\n",
1212 GNUNET_i2s (pos->id), 1191 GNUNET_i2s (&pos->id),
1213 GNUNET_h2s (key)); 1192 GNUNET_h2s (key));
1214 return pos; 1193 return pos;
1215 } 1194 }
@@ -1371,6 +1350,7 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1371 struct PeerPutMessage *ppm; 1350 struct PeerPutMessage *ppm;
1372 struct GNUNET_DHT_PathElement *pp; 1351 struct GNUNET_DHT_PathElement *pp;
1373 1352
1353#if FIXME_LEGACY
1374 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) 1354 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER)
1375 { 1355 {
1376 /* skip */ 1356 /* skip */
@@ -1381,11 +1361,12 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1381 skip_count++; 1361 skip_count++;
1382 continue; 1362 continue;
1383 } 1363 }
1364#endif
1384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1385 "Routing PUT for %s after %u hops to %s\n", 1366 "Routing PUT for %s after %u hops to %s\n",
1386 GNUNET_h2s (&bd->key), 1367 GNUNET_h2s (&bd->key),
1387 (unsigned int) hop_count, 1368 (unsigned int) hop_count,
1388 GNUNET_i2s (target->id)); 1369 GNUNET_i2s (&target->id));
1389 env = GNUNET_MQ_msg_extra (ppm, 1370 env = GNUNET_MQ_msg_extra (ppm,
1390 msize, 1371 msize,
1391 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT); 1372 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT);
@@ -1417,15 +1398,17 @@ GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
1417 bd->data_size, 1398 bd->data_size,
1418 bd->expiration_time, 1399 bd->expiration_time,
1419 &pp[put_path_length - 1].pred, 1400 &pp[put_path_length - 1].pred,
1420 target->id, 1401 &target->id,
1421 &pp[put_path_length - 1].sig); 1402 &pp[put_path_length - 1].sig);
1422 } 1403 }
1423 1404
1424 GNUNET_memcpy (&pp[put_path_length], 1405 GNUNET_memcpy (&pp[put_path_length],
1425 bd->data, 1406 bd->data,
1426 bd->data_size); 1407 bd->data_size);
1408#if FIXME
1427 GNUNET_MQ_send (target->mq, 1409 GNUNET_MQ_send (target->mq,
1428 env); 1410 env);
1411#endif
1429 } 1412 }
1430 GNUNET_free (targets); 1413 GNUNET_free (targets);
1431 GNUNET_STATISTICS_update (GDS_stats, 1414 GNUNET_STATISTICS_update (GDS_stats,
@@ -1508,6 +1491,7 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1508 struct PeerGetMessage *pgm; 1491 struct PeerGetMessage *pgm;
1509 char *xq; 1492 char *xq;
1510 1493
1494#if FIXME
1511 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER) 1495 if (GNUNET_MQ_get_length (target->mq) >= MAXIMUM_PENDING_PER_PEER)
1512 { 1496 {
1513 /* skip */ 1497 /* skip */
@@ -1518,11 +1502,12 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1518 skip_count++; 1502 skip_count++;
1519 continue; 1503 continue;
1520 } 1504 }
1505#endif
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "Routing GET for %s after %u hops to %s\n", 1507 "Routing GET for %s after %u hops to %s\n",
1523 GNUNET_h2s (key), 1508 GNUNET_h2s (key),
1524 (unsigned int) hop_count, 1509 (unsigned int) hop_count,
1525 GNUNET_i2s (target->id)); 1510 GNUNET_i2s (&target->id));
1526 env = GNUNET_MQ_msg_extra (pgm, 1511 env = GNUNET_MQ_msg_extra (pgm,
1527 msize, 1512 msize,
1528 GNUNET_MESSAGE_TYPE_DHT_P2P_GET); 1513 GNUNET_MESSAGE_TYPE_DHT_P2P_GET);
@@ -1547,8 +1532,10 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1547 GNUNET_memcpy (&xq[xquery_size], 1532 GNUNET_memcpy (&xq[xquery_size],
1548 reply_bf, 1533 reply_bf,
1549 reply_bf_size); 1534 reply_bf_size);
1535#if FIXME
1550 GNUNET_MQ_send (target->mq, 1536 GNUNET_MQ_send (target->mq,
1551 env); 1537 env);
1538#endif
1552 } 1539 }
1553 GNUNET_STATISTICS_update (GDS_stats, 1540 GNUNET_STATISTICS_update (GDS_stats,
1554 "# GET messages queued for transmission", 1541 "# GET messages queued for transmission",
@@ -1622,6 +1609,7 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1622 GNUNET_break (0); 1609 GNUNET_break (0);
1623 return; 1610 return;
1624 } 1611 }
1612#if FIXME
1625 if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER) 1613 if (GNUNET_MQ_get_length (pi->mq) >= MAXIMUM_PENDING_PER_PEER)
1626 { 1614 {
1627 /* skip */ 1615 /* skip */
@@ -1634,11 +1622,11 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1634 GNUNET_h2s (&bd->key)); 1622 GNUNET_h2s (&bd->key));
1635 return; 1623 return;
1636 } 1624 }
1637 1625#endif
1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1639 "Forwarding reply for key %s to peer %s\n", 1627 "Forwarding reply for key %s to peer %s\n",
1640 GNUNET_h2s (query_hash), 1628 GNUNET_h2s (query_hash),
1641 GNUNET_i2s (pi->id)); 1629 GNUNET_i2s (&pi->id));
1642 GNUNET_STATISTICS_update (GDS_stats, 1630 GNUNET_STATISTICS_update (GDS_stats,
1643 "# RESULT messages queued for transmission", 1631 "# RESULT messages queued for transmission",
1644 1, 1632 1,
@@ -1668,36 +1656,16 @@ GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi,
1668 bd->data_size, 1656 bd->data_size,
1669 bd->expiration_time, 1657 bd->expiration_time,
1670 &paths[ppl + get_path_length - 1].pred, 1658 &paths[ppl + get_path_length - 1].pred,
1671 pi->id, 1659 &pi->id,
1672 &paths[ppl + get_path_length - 1].sig); 1660 &paths[ppl + get_path_length - 1].sig);
1673 } 1661 }
1674 GNUNET_memcpy (&paths[ppl + get_path_length], 1662 GNUNET_memcpy (&paths[ppl + get_path_length],
1675 bd->data, 1663 bd->data,
1676 bd->data_size); 1664 bd->data_size);
1665#if FIXME
1677 GNUNET_MQ_send (pi->mq, 1666 GNUNET_MQ_send (pi->mq,
1678 env); 1667 env);
1679} 1668#endif
1680
1681
1682/**
1683 * To be called on core init.
1684 *
1685 * @param cls service closure
1686 * @param identity the public identity of this peer
1687 */
1688static void
1689core_init (void *cls,
1690 const struct GNUNET_PeerIdentity *identity)
1691{
1692 (void) cls;
1693 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1694 "CORE called, I am %s\n",
1695 GNUNET_i2s (identity));
1696 my_identity = *identity;
1697 GNUNET_CRYPTO_hash (identity,
1698 sizeof(struct GNUNET_PeerIdentity),
1699 &my_identity_hash);
1700 GNUNET_SERVICE_resume (GDS_service);
1701} 1669}
1702 1670
1703 1671
@@ -1759,7 +1727,7 @@ handle_dht_p2p_put (void *cls,
1759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1760 "PUT for `%s' from %s\n", 1728 "PUT for `%s' from %s\n",
1761 GNUNET_h2s (&put->key), 1729 GNUNET_h2s (&put->key),
1762 GNUNET_i2s (peer->id)); 1730 GNUNET_i2s (&peer->id));
1763 if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) 1731 if (GNUNET_TIME_absolute_is_past (bd.expiration_time))
1764 { 1732 {
1765 GNUNET_STATISTICS_update (GDS_stats, 1733 GNUNET_STATISTICS_update (GDS_stats,
@@ -1841,7 +1809,7 @@ handle_dht_p2p_put (void *cls,
1841 } 1809 }
1842 GNUNET_break (0 != 1810 GNUNET_break (0 !=
1843 GNUNET_memcmp (&pp[i].pred, 1811 GNUNET_memcmp (&pp[i].pred,
1844 peer->id)); 1812 &peer->id));
1845 } 1813 }
1846 if (0 != 1814 if (0 !=
1847 GNUNET_DHT_verify_path (&bd.key, 1815 GNUNET_DHT_verify_path (&bd.key,
@@ -1860,7 +1828,7 @@ handle_dht_p2p_put (void *cls,
1860 GNUNET_memcpy (pp, 1828 GNUNET_memcpy (pp,
1861 put_path, 1829 put_path,
1862 putlen * sizeof(struct GNUNET_DHT_PathElement)); 1830 putlen * sizeof(struct GNUNET_DHT_PathElement));
1863 pp[putlen].pred = *peer->id; 1831 pp[putlen].pred = peer->id;
1864 /* zero-out signature, not valid until we actually do forward! */ 1832 /* zero-out signature, not valid until we actually do forward! */
1865 memset (&pp[putlen].sig, 1833 memset (&pp[putlen].sig,
1866 0, 1834 0,
@@ -1924,7 +1892,7 @@ handle_find_peer (struct PeerInfo *pi,
1924 struct PeerInfo *peer; 1892 struct PeerInfo *peer;
1925 unsigned int choice; 1893 unsigned int choice;
1926 struct GDS_DATACACHE_BlockData bd = { 1894 struct GDS_DATACACHE_BlockData bd = {
1927 .type = GNUNET_BLOCK_TYPE_DHT_HELLO 1895 .type = GNUNET_BLOCK_TYPE_DHT_URL_HELLO
1928 }; 1896 };
1929 1897
1930 /* first, check about our own HELLO */ 1898 /* first, check about our own HELLO */
@@ -1939,7 +1907,7 @@ handle_find_peer (struct PeerInfo *pi,
1939 GNUNET_break (bd.data_size >= sizeof(struct GNUNET_MessageHeader)); 1907 GNUNET_break (bd.data_size >= sizeof(struct GNUNET_MessageHeader));
1940 if (GNUNET_BLOCK_REPLY_OK_MORE == 1908 if (GNUNET_BLOCK_REPLY_OK_MORE ==
1941 GNUNET_BLOCK_check_reply (GDS_block_context, 1909 GNUNET_BLOCK_check_reply (GDS_block_context,
1942 GNUNET_BLOCK_TYPE_DHT_HELLO, 1910 GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
1943 bg, 1911 bg,
1944 &my_identity_hash, 1912 &my_identity_hash,
1945 NULL, 0, 1913 NULL, 0,
@@ -2003,12 +1971,12 @@ handle_find_peer (struct PeerInfo *pi,
2003 return; /* no non-masked peer available */ 1971 return; /* no non-masked peer available */
2004 if (NULL == peer) 1972 if (NULL == peer)
2005 peer = bucket->head; 1973 peer = bucket->head;
2006 hello = GDS_HELLO_get (peer->id); 1974 hello = GDS_HELLO_get (&peer->id);
2007 } while ( (NULL == hello) || 1975 } while ( (NULL == hello) ||
2008 (GNUNET_BLOCK_REPLY_OK_MORE != 1976 (GNUNET_BLOCK_REPLY_OK_MORE !=
2009 GNUNET_BLOCK_check_reply ( 1977 GNUNET_BLOCK_check_reply (
2010 GDS_block_context, 1978 GDS_block_context,
2011 GNUNET_BLOCK_TYPE_DHT_HELLO, 1979 GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
2012 bg, 1980 bg,
2013 &peer->phash, 1981 &peer->phash,
2014 NULL, 0, /* xquery */ 1982 NULL, 0, /* xquery */
@@ -2170,7 +2138,7 @@ handle_dht_p2p_get (void *cls,
2170 } 2138 }
2171 2139
2172 /* remember request for routing replies */ 2140 /* remember request for routing replies */
2173 GDS_ROUTING_add (peer->id, 2141 GDS_ROUTING_add (&peer->id,
2174 type, 2142 type,
2175 bg, /* bg now owned by routing, but valid at least until end of this function! */ 2143 bg, /* bg now owned by routing, but valid at least until end of this function! */
2176 options, 2144 options,
@@ -2363,7 +2331,7 @@ handle_dht_p2p_result (void *cls,
2363 } 2331 }
2364 2332
2365 /* if we got a HELLO, consider it for our own routing table */ 2333 /* if we got a HELLO, consider it for our own routing table */
2366 if (GNUNET_BLOCK_TYPE_DHT_HELLO == bd.type) 2334 if (GNUNET_BLOCK_TYPE_DHT_URL_HELLO == bd.type)
2367 { 2335 {
2368 const struct GNUNET_MessageHeader *h = bd.data; 2336 const struct GNUNET_MessageHeader *h = bd.data;
2369 struct GNUNET_PeerIdentity pid; 2337 struct GNUNET_PeerIdentity pid;
@@ -2397,7 +2365,7 @@ handle_dht_p2p_result (void *cls,
2397 so, truncate it instead of expanding. */ 2365 so, truncate it instead of expanding. */
2398 for (unsigned int i = 0; i <= get_path_length; i++) 2366 for (unsigned int i = 0; i <= get_path_length; i++)
2399 if (0 == GNUNET_memcmp (&get_path[i].pred, 2367 if (0 == GNUNET_memcmp (&get_path[i].pred,
2400 peer->id)) 2368 &peer->id))
2401 { 2369 {
2402 process_reply_with_path (&bd, 2370 process_reply_with_path (&bd,
2403 &prm->key, 2371 &prm->key,
@@ -2412,7 +2380,7 @@ handle_dht_p2p_result (void *cls,
2412 GNUNET_memcpy (xget_path, 2380 GNUNET_memcpy (xget_path,
2413 get_path, 2381 get_path,
2414 get_path_length * sizeof(struct GNUNET_DHT_PathElement)); 2382 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
2415 xget_path[get_path_length].pred = *peer->id; 2383 xget_path[get_path_length].pred = peer->id;
2416 memset (&xget_path[get_path_length].sig, 2384 memset (&xget_path[get_path_length].sig,
2417 0, 2385 0,
2418 sizeof (xget_path[get_path_length].sig)); 2386 sizeof (xget_path[get_path_length].sig));
@@ -2423,24 +2391,57 @@ handle_dht_p2p_result (void *cls,
2423} 2391}
2424 2392
2425 2393
2426enum GNUNET_GenericReturnValue 2394void
2427GDS_NEIGHBOURS_init () 2395GDS_u_receive (void *cls,
2396 void **tctx,
2397 void **sctx,
2398 const void *message,
2399 size_t message_size)
2428{ 2400{
2401 struct PeerInfo *pi = *tctx;
2429 struct GNUNET_MQ_MessageHandler core_handlers[] = { 2402 struct GNUNET_MQ_MessageHandler core_handlers[] = {
2430 GNUNET_MQ_hd_var_size (dht_p2p_get, 2403 GNUNET_MQ_hd_var_size (dht_p2p_get,
2431 GNUNET_MESSAGE_TYPE_DHT_P2P_GET, 2404 GNUNET_MESSAGE_TYPE_DHT_P2P_GET,
2432 struct PeerGetMessage, 2405 struct PeerGetMessage,
2433 NULL), 2406 pi),
2434 GNUNET_MQ_hd_var_size (dht_p2p_put, 2407 GNUNET_MQ_hd_var_size (dht_p2p_put,
2435 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, 2408 GNUNET_MESSAGE_TYPE_DHT_P2P_PUT,
2436 struct PeerPutMessage, 2409 struct PeerPutMessage,
2437 NULL), 2410 pi),
2438 GNUNET_MQ_hd_var_size (dht_p2p_result, 2411 GNUNET_MQ_hd_var_size (dht_p2p_result,
2439 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, 2412 GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT,
2440 struct PeerResultMessage, 2413 struct PeerResultMessage,
2441 NULL), 2414 pi),
2442 GNUNET_MQ_handler_end () 2415 GNUNET_MQ_handler_end ()
2443 }; 2416 };
2417 const struct GNUNET_MessageHeader *mh = message;
2418
2419 (void) cls; /* the 'struct Underlay' */
2420 (void) sctx; /* our receiver address */
2421 if (message_size < sizeof (*mh))
2422 {
2423 GNUNET_break_op (0);
2424 return;
2425 }
2426 if (message_size != ntohs (mh->size))
2427 {
2428 GNUNET_break_op (0);
2429 return;
2430 }
2431 if (GNUNET_OK !=
2432 GNUNET_MQ_handle_message (core_handlers,
2433 mh))
2434 {
2435 GNUNET_break_op (0);
2436 return;
2437 }
2438}
2439
2440
2441enum GNUNET_GenericReturnValue
2442GDS_NEIGHBOURS_init ()
2443{
2444
2444 unsigned long long temp_config_num; 2445 unsigned long long temp_config_num;
2445 2446
2446 disable_try_connect 2447 disable_try_connect
@@ -2482,16 +2483,12 @@ GDS_NEIGHBOURS_init ()
2482 } 2483 }
2483 GNUNET_free (keyfile); 2484 GNUNET_free (keyfile);
2484 } 2485 }
2486 GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key,
2487 &my_identity.public_key);
2488 GNUNET_CRYPTO_hash (&my_identity,
2489 sizeof(struct GNUNET_PeerIdentity),
2490 &my_identity_hash);
2485 2491
2486 ats_ch = GNUNET_ATS_connectivity_init (GDS_cfg);
2487 core_api = GNUNET_CORE_connect (GDS_cfg,
2488 NULL,
2489 &core_init,
2490 &handle_core_connect,
2491 &handle_core_disconnect,
2492 core_handlers);
2493 if (NULL == core_api)
2494 return GNUNET_SYSERR;
2495 all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256, 2492 all_connected_peers = GNUNET_CONTAINER_multipeermap_create (256,
2496 GNUNET_YES); 2493 GNUNET_YES);
2497 all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256, 2494 all_desired_peers = GNUNET_CONTAINER_multipeermap_create (256,
@@ -2503,10 +2500,8 @@ GDS_NEIGHBOURS_init ()
2503void 2500void
2504GDS_NEIGHBOURS_done () 2501GDS_NEIGHBOURS_done ()
2505{ 2502{
2506 if (NULL == core_api) 2503 if (NULL == all_connected_peers)
2507 return; 2504 return;
2508 GNUNET_CORE_disconnect (core_api);
2509 core_api = NULL;
2510 GNUNET_assert (0 == 2505 GNUNET_assert (0 ==
2511 GNUNET_CONTAINER_multipeermap_size (all_connected_peers)); 2506 GNUNET_CONTAINER_multipeermap_size (all_connected_peers));
2512 GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers); 2507 GNUNET_CONTAINER_multipeermap_destroy (all_connected_peers);
@@ -2516,8 +2511,6 @@ GDS_NEIGHBOURS_done ()
2516 NULL); 2511 NULL);
2517 GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers); 2512 GNUNET_CONTAINER_multipeermap_destroy (all_desired_peers);
2518 all_desired_peers = NULL; 2513 all_desired_peers = NULL;
2519 GNUNET_ATS_connectivity_done (ats_ch);
2520 ats_ch = NULL;
2521 GNUNET_assert (NULL == find_peer_task); 2514 GNUNET_assert (NULL == find_peer_task);
2522} 2515}
2523 2516
diff --git a/src/dht/gnunet-service-dht_neighbours.h b/src/dht/gnunet-service-dht_neighbours.h
index 35bbb125d..e1a553f06 100644
--- a/src/dht/gnunet-service-dht_neighbours.h
+++ b/src/dht/gnunet-service-dht_neighbours.h
@@ -30,6 +30,7 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_block_lib.h" 31#include "gnunet_block_lib.h"
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33#include "gnunet_dhtu_plugin.h"
33#include "gnunet-service-dht_datacache.h" 34#include "gnunet-service-dht_datacache.h"
34 35
35/** 36/**
@@ -137,6 +138,51 @@ GDS_am_closest_peer (const struct GNUNET_HashCode *key,
137 138
138 139
139/** 140/**
141 * Function to call when we connect to a peer and can henceforth transmit to
142 * that peer.
143 *
144 * @param cls the closure
145 * @param target handle to the target,
146 * pointer will remain valid until @e disconnect_cb is called
147 * @para pid peer identity,
148 * pointer will remain valid until @e disconnect_cb is called
149 * @param[out] ctx storage space for DHT to use in association with this target
150 */
151void
152GDS_u_connect (void *cls,
153 struct GNUNET_DHTU_Target *target,
154 const struct GNUNET_PeerIdentity *pid,
155 void **ctx);
156
157/**
158 * Function to call when we disconnected from a peer and can henceforth
159 * cannot transmit to that peer anymore.
160 *
161 * @param[in] ctx storage space used by the DHT in association with this target
162 */
163void
164GDS_u_disconnect (void *ctx);
165
166
167/**
168 * Function to call when we receive a message.
169 *
170 * @param cls the closure
171 * @param origin where the message originated from
172 * @param[in,out] tctx ctx of target address where we received the message from
173 * @param[in,out] sctx ctx of our own source address at which we received the message
174 * @param message the message we received @param message_size number of
175 * bytes in @a message
176 */
177void
178GDS_u_receive (void *cls,
179 void **tctx,
180 void **sctx,
181 const void *message,
182 size_t message_size);
183
184
185/**
140 * Initialize neighbours subsystem. 186 * Initialize neighbours subsystem.
141 * 187 *
142 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 188 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
diff --git a/src/dht/gnunet-service-dht_nse.c b/src/dht/gnunet-service-dht_nse.c
deleted file mode 100644
index 58f18816a..000000000
--- a/src/dht/gnunet-service-dht_nse.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file dht/gnunet-service-dht_nse.c
23 * @brief GNUnet DHT integration with NSE
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_nse_service.h"
28#include "gnunet-service-dht.h"
29#include "gnunet-service-dht_nse.h"
30
31/**
32 * log of the current network size estimate, used as the point where
33 * we switch between random and deterministic routing. Default
34 * value of 4.0 is used if NSE module is not available (i.e. not
35 * configured).
36 */
37static double log_of_network_size_estimate = 4.0;
38
39/**
40 * Network size estimation handle.
41 */
42static struct GNUNET_NSE_Handle *nse;
43
44
45/**
46 * Callback that is called when network size estimate is updated.
47 *
48 * @param cls closure
49 * @param timestamp time when the estimate was received from the server (or created by the server)
50 * @param logestimate the log(Base 2) value of the current network size estimate
51 * @param std_dev standard deviation for the estimate
52 *
53 */
54static void
55update_network_size_estimate (void *cls,
56 struct GNUNET_TIME_Absolute timestamp,
57 double logestimate,
58 double std_dev)
59{
60 GNUNET_STATISTICS_update (GDS_stats,
61 "# Network size estimates received",
62 1, GNUNET_NO);
63 /* do not allow estimates < 0.5 */
64 log_of_network_size_estimate = GNUNET_MAX (0.5, logestimate);
65}
66
67
68/**
69 * Return the log of the current network size estimate.
70 *
71 * @return log of NSE
72 */
73double
74GDS_NSE_get ()
75{
76 return log_of_network_size_estimate;
77}
78
79
80/**
81 * Initialize NSE subsystem.
82 */
83void
84GDS_NSE_init ()
85{
86 unsigned long long hops;
87
88 if ( (GNUNET_YES ==
89 GNUNET_CONFIGURATION_have_value (GDS_cfg,
90 "dht",
91 "FORCE_NSE")) &&
92 (GNUNET_OK ==
93 GNUNET_CONFIGURATION_get_value_number (GDS_cfg,
94 "dht",
95 "FORCE_NSE",
96 &hops)) )
97 {
98 log_of_network_size_estimate = (double) hops;
99 return;
100 }
101 nse = GNUNET_NSE_connect (GDS_cfg,
102 &update_network_size_estimate,
103 NULL);
104}
105
106
107/**
108 * Shutdown NSE subsystem.
109 */
110void
111GDS_NSE_done ()
112{
113 if (NULL != nse)
114 {
115 GNUNET_NSE_disconnect (nse);
116 nse = NULL;
117 }
118}
119
120
121/* end of gnunet-service-dht_nse.c */
diff --git a/src/dht/gnunet-service-dht_nse.h b/src/dht/gnunet-service-dht_nse.h
deleted file mode 100644
index e99389e74..000000000
--- a/src/dht/gnunet-service-dht_nse.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file dht/gnunet-service-dht_nse.h
23 * @brief GNUnet DHT integration with NSE
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SERVICE_DHT_NSE_H
27#define GNUNET_SERVICE_DHT_NSE_H
28
29
30/**
31 * Return the log of the current network size estimate.
32 *
33 * @return log of NSE
34 */
35double
36GDS_NSE_get (void);
37
38
39/**
40 * Initialize NSE subsystem.
41 */
42void
43GDS_NSE_init (void);
44
45
46/**
47 * Shutdown NSE subsystem.
48 */
49void
50GDS_NSE_done (void);
51
52#endif
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 7c6fb9ed6..a6a2104ce 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -116,45 +116,51 @@ block_plugin_dht_evaluate (void *cls,
116 const void *reply_block, 116 const void *reply_block,
117 size_t reply_block_size) 117 size_t reply_block_size)
118{ 118{
119 const struct GNUNET_HELLO_Message *hello; 119 switch (type)
120 struct GNUNET_PeerIdentity pid;
121 const struct GNUNET_MessageHeader *msg;
122 struct GNUNET_HashCode phash;
123
124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 if (0 != xquery_size)
127 {
128 GNUNET_break_op (0);
129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
130 }
131 if (NULL == reply_block)
132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
133 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
134 {
135 GNUNET_break_op (0);
136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
137 }
138 msg = reply_block;
139 if (reply_block_size != ntohs (msg->size))
140 {
141 GNUNET_break_op (0);
142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
143 }
144 hello = reply_block;
145 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
146 { 120 {
147 GNUNET_break_op (0); 121 case GNUNET_BLOCK_TYPE_DHT_HELLO:
148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 122 {
123 const struct GNUNET_HELLO_Message *hello;
124 struct GNUNET_PeerIdentity pid;
125 const struct GNUNET_MessageHeader *msg;
126 struct GNUNET_HashCode phash;
127
128 if (0 != xquery_size)
129 {
130 GNUNET_break_op (0);
131 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
132 }
133 if (NULL == reply_block)
134 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
135 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
136 {
137 GNUNET_break_op (0);
138 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
139 }
140 msg = reply_block;
141 if (reply_block_size != ntohs (msg->size))
142 {
143 GNUNET_break_op (0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 }
146 hello = reply_block;
147 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
148 {
149 GNUNET_break_op (0);
150 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
151 }
152 GNUNET_CRYPTO_hash (&pid,
153 sizeof(pid),
154 &phash);
155 if (GNUNET_YES ==
156 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
157 &phash))
158 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
159 return GNUNET_BLOCK_EVALUATION_OK_MORE;
160 }
161 default:
162 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
149 } 163 }
150 GNUNET_CRYPTO_hash (&pid,
151 sizeof(pid),
152 &phash);
153 if (GNUNET_YES ==
154 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
155 &phash))
156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
157 return GNUNET_BLOCK_EVALUATION_OK_MORE;
158} 164}
159 165
160 166
@@ -171,19 +177,23 @@ block_plugin_dht_evaluate (void *cls,
171 */ 177 */
172static enum GNUNET_GenericReturnValue 178static enum GNUNET_GenericReturnValue
173block_plugin_dht_check_query (void *cls, 179block_plugin_dht_check_query (void *cls,
174 enum GNUNET_BLOCK_Type type, 180 enum GNUNET_BLOCK_Type type,
175 const struct GNUNET_HashCode *query, 181 const struct GNUNET_HashCode *query,
176 const void *xquery, 182 const void *xquery,
177 size_t xquery_size) 183 size_t xquery_size)
178{ 184{
179 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 185 switch (type)
180 return GNUNET_SYSERR;
181 if (0 != xquery_size)
182 { 186 {
183 GNUNET_break_op (0); 187 case GNUNET_BLOCK_TYPE_DHT_HELLO:
184 return GNUNET_NO; 188 if (0 != xquery_size)
189 {
190 GNUNET_break_op (0);
191 return GNUNET_NO;
192 }
193 return GNUNET_OK;
194 default:
195 return GNUNET_SYSERR;
185 } 196 }
186 return GNUNET_OK;
187} 197}
188 198
189 199
@@ -199,37 +209,43 @@ block_plugin_dht_check_query (void *cls,
199 */ 209 */
200static enum GNUNET_GenericReturnValue 210static enum GNUNET_GenericReturnValue
201block_plugin_dht_check_block (void *cls, 211block_plugin_dht_check_block (void *cls,
202 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
203 const struct GNUNET_HashCode *query, 213 const struct GNUNET_HashCode *query,
204 const void *block, 214 const void *block,
205 size_t block_size) 215 size_t block_size)
206{ 216{
207 const struct GNUNET_HELLO_Message *hello; 217 switch (type)
208 struct GNUNET_PeerIdentity pid;
209 const struct GNUNET_MessageHeader *msg;
210
211 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
212 return GNUNET_SYSERR;
213 if (block_size < sizeof(struct GNUNET_MessageHeader))
214 {
215 GNUNET_break_op (0);
216 return GNUNET_NO;
217 }
218 msg = block;
219 if (block_size != ntohs (msg->size))
220 {
221 GNUNET_break_op (0);
222 return GNUNET_NO;
223 }
224 hello = block;
225 if (GNUNET_OK !=
226 GNUNET_HELLO_get_id (hello,
227 &pid))
228 { 218 {
229 GNUNET_break_op (0); 219 case GNUNET_BLOCK_TYPE_DHT_HELLO:
230 return GNUNET_NO; 220 {
221 const struct GNUNET_HELLO_Message *hello;
222 struct GNUNET_PeerIdentity pid;
223 const struct GNUNET_MessageHeader *msg;
224
225 if (block_size < sizeof(struct GNUNET_MessageHeader))
226 {
227 GNUNET_break_op (0);
228 return GNUNET_NO;
229 }
230 msg = block;
231 if (block_size != ntohs (msg->size))
232 {
233 GNUNET_break_op (0);
234 return GNUNET_NO;
235 }
236 hello = block;
237 if (GNUNET_OK !=
238 GNUNET_HELLO_get_id (hello,
239 &pid))
240 {
241 GNUNET_break_op (0);
242 return GNUNET_NO;
243 }
244 return GNUNET_OK;
245 }
246 default:
247 return GNUNET_SYSERR;
231 } 248 }
232 return GNUNET_OK;
233} 249}
234 250
235 251
@@ -251,49 +267,55 @@ block_plugin_dht_check_block (void *cls,
251 */ 267 */
252static enum GNUNET_BLOCK_ReplyEvaluationResult 268static enum GNUNET_BLOCK_ReplyEvaluationResult
253block_plugin_dht_check_reply ( 269block_plugin_dht_check_reply (
254 void *cls, 270 void *cls,
255 enum GNUNET_BLOCK_Type type, 271 enum GNUNET_BLOCK_Type type,
256 struct GNUNET_BLOCK_Group *group, 272 struct GNUNET_BLOCK_Group *group,
257 const struct GNUNET_HashCode *query, 273 const struct GNUNET_HashCode *query,
258 const void *xquery, 274 const void *xquery,
259 size_t xquery_size, 275 size_t xquery_size,
260 const void *reply_block, 276 const void *reply_block,
261 size_t reply_block_size) 277 size_t reply_block_size)
262{ 278{
263 const struct GNUNET_HELLO_Message *hello; 279 switch (type)
264 struct GNUNET_PeerIdentity pid;
265 const struct GNUNET_MessageHeader *msg;
266 struct GNUNET_HashCode phash;
267
268 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
269 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
270 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
271 {
272 GNUNET_break_op (0);
273 return GNUNET_BLOCK_REPLY_INVALID;
274 }
275 msg = reply_block;
276 if (reply_block_size != ntohs (msg->size))
277 {
278 GNUNET_break_op (0);
279 return GNUNET_BLOCK_REPLY_INVALID;
280 }
281 hello = reply_block;
282 if (GNUNET_OK !=
283 GNUNET_HELLO_get_id (hello,
284 &pid))
285 { 280 {
286 GNUNET_break_op (0); 281 case GNUNET_BLOCK_TYPE_DHT_HELLO:
287 return GNUNET_BLOCK_REPLY_INVALID; 282 {
283 const struct GNUNET_HELLO_Message *hello;
284 struct GNUNET_PeerIdentity pid;
285 const struct GNUNET_MessageHeader *msg;
286 struct GNUNET_HashCode phash;
287
288 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
289 {
290 GNUNET_break_op (0);
291 return GNUNET_BLOCK_REPLY_INVALID;
292 }
293 msg = reply_block;
294 if (reply_block_size != ntohs (msg->size))
295 {
296 GNUNET_break_op (0);
297 return GNUNET_BLOCK_REPLY_INVALID;
298 }
299 hello = reply_block;
300 if (GNUNET_OK !=
301 GNUNET_HELLO_get_id (hello,
302 &pid))
303 {
304 GNUNET_break_op (0);
305 return GNUNET_BLOCK_REPLY_INVALID;
306 }
307 GNUNET_CRYPTO_hash (&pid,
308 sizeof(pid),
309 &phash);
310 if (GNUNET_YES ==
311 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
312 &phash))
313 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
314 return GNUNET_BLOCK_REPLY_OK_MORE;
315 }
316 default:
317 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
288 } 318 }
289 GNUNET_CRYPTO_hash (&pid,
290 sizeof(pid),
291 &phash);
292 if (GNUNET_YES ==
293 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
294 &phash))
295 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
296 return GNUNET_BLOCK_REPLY_OK_MORE;
297} 319}
298 320
299 321
@@ -315,41 +337,47 @@ block_plugin_dht_get_key (void *cls,
315 size_t block_size, 337 size_t block_size,
316 struct GNUNET_HashCode *key) 338 struct GNUNET_HashCode *key)
317{ 339{
318 const struct GNUNET_MessageHeader *msg; 340 switch (type)
319 const struct GNUNET_HELLO_Message *hello;
320 struct GNUNET_PeerIdentity *pid;
321
322 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
323 return GNUNET_SYSERR;
324 if (block_size < sizeof(struct GNUNET_MessageHeader))
325 {
326 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
327 "block-dht",
328 _ ("Block not of type %u\n"),
329 GNUNET_BLOCK_TYPE_DHT_HELLO);
330 return GNUNET_NO;
331 }
332 msg = block;
333 if (block_size != ntohs (msg->size))
334 {
335 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
336 "block-dht",
337 _ ("Size mismatch for block with type %u\n"),
338 GNUNET_BLOCK_TYPE_DHT_HELLO);
339 return GNUNET_NO;
340 }
341 hello = block;
342 memset (key, 0, sizeof(*key));
343 pid = (struct GNUNET_PeerIdentity *) key;
344 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
345 { 341 {
346 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 342 case GNUNET_BLOCK_TYPE_DHT_HELLO:
347 "block-dht", 343 {
348 _ ("Block of type %u is malformed\n"), 344 const struct GNUNET_MessageHeader *msg;
349 GNUNET_BLOCK_TYPE_DHT_HELLO); 345 const struct GNUNET_HELLO_Message *hello;
350 return GNUNET_NO; 346 struct GNUNET_PeerIdentity *pid;
347
348 if (block_size < sizeof(struct GNUNET_MessageHeader))
349 {
350 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
351 "block-dht",
352 _ ("Block not of type %u\n"),
353 GNUNET_BLOCK_TYPE_DHT_HELLO);
354 return GNUNET_NO;
355 }
356 msg = block;
357 if (block_size != ntohs (msg->size))
358 {
359 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
360 "block-dht",
361 _ ("Size mismatch for block with type %u\n"),
362 GNUNET_BLOCK_TYPE_DHT_HELLO);
363 return GNUNET_NO;
364 }
365 hello = block;
366 memset (key, 0, sizeof(*key));
367 pid = (struct GNUNET_PeerIdentity *) key;
368 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
369 {
370 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
371 "block-dht",
372 _ ("Block of type %u is malformed\n"),
373 GNUNET_BLOCK_TYPE_DHT_HELLO);
374 return GNUNET_NO;
375 }
376 return GNUNET_OK;
377 }
378 default:
379 return GNUNET_SYSERR;
351 } 380 }
352 return GNUNET_OK;
353} 381}
354 382
355 383
@@ -361,6 +389,7 @@ libgnunet_plugin_block_dht_init (void *cls)
361{ 389{
362 static enum GNUNET_BLOCK_Type types[] = { 390 static enum GNUNET_BLOCK_Type types[] = {
363 GNUNET_BLOCK_TYPE_DHT_HELLO, 391 GNUNET_BLOCK_TYPE_DHT_HELLO,
392 // FIXME: add GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
364 GNUNET_BLOCK_TYPE_ANY /* end of list */ 393 GNUNET_BLOCK_TYPE_ANY /* end of list */
365 }; 394 };
366 struct GNUNET_BLOCK_PluginFunctions *api; 395 struct GNUNET_BLOCK_PluginFunctions *api;
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 */
245static void 236static void
246ip_try_connect (void *cls, 237ip_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 */
239static struct GNUNET_DHTU_Target * 240static struct GNUNET_DHTU_Target *
240create_target (struct Plugin *plugin, 241create_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 */
329static struct GNUNET_DHTU_Target * 306static struct GNUNET_DHTU_Target *
330find_target (struct Plugin *plugin, 307find_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 */
375static void 355static void
376ip_try_connect (void *cls, 356ip_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 */
600static int 579static enum GNUNET_GenericReturnValue
601process_ifcs (void *cls, 580process_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 ==
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index e4b02b8ee..8808f6802 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -57,6 +57,7 @@ gnunetinclude_HEADERS = \
57 gnunet_gnsrecord_plugin.h \ 57 gnunet_gnsrecord_plugin.h \
58 gnu_name_system_record_types.h \ 58 gnu_name_system_record_types.h \
59 gnunet_hello_lib.h \ 59 gnunet_hello_lib.h \
60 gnunet_hello_uri_lib.h \
60 gnunet_helper_lib.h \ 61 gnunet_helper_lib.h \
61 gnunet_identity_service.h \ 62 gnunet_identity_service.h \
62 gnunet_abe_lib.h \ 63 gnunet_abe_lib.h \
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 5640209a6..f6db8d642 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -119,6 +119,12 @@ enum GNUNET_BLOCK_Type
119 GNUNET_BLOCK_TYPE_REVOCATION = 12, 119 GNUNET_BLOCK_TYPE_REVOCATION = 12,
120 120
121 /** 121 /**
122 * Type of a block that contains a DHT-NG HELLO for a peer (for
123 * DHT and CADET find-peer operations).
124 */
125 GNUNET_BLOCK_TYPE_DHT_URL_HELLO = 13,
126
127 /**
122 * Block to store a cadet regex state 128 * Block to store a cadet regex state
123 */ 129 */
124 GNUNET_BLOCK_TYPE_REGEX = 22, 130 GNUNET_BLOCK_TYPE_REGEX = 22,
diff --git a/src/include/gnunet_dhtu_plugin.h b/src/include/gnunet_dhtu_plugin.h
index 2c97d5848..b709ce9ae 100644
--- a/src/include/gnunet_dhtu_plugin.h
+++ b/src/include/gnunet_dhtu_plugin.h
@@ -59,15 +59,6 @@ struct GNUNET_DHTU_PreferenceHandle;
59 59
60 60
61/** 61/**
62 * Key used to identify peer's position in the DHT.
63 */
64struct GNUNET_DHTU_HashKey
65{
66 struct GNUNET_HashCode sha512;
67};
68
69
70/**
71 * The datastore service will pass a pointer to a struct 62 * The datastore service will pass a pointer to a struct
72 * of this type as the first and only argument to the 63 * of this type as the first and only argument to the
73 * entry point of each datastore plugin. 64 * entry point of each datastore plugin.
@@ -88,7 +79,6 @@ struct GNUNET_DHTU_PluginEnvironment
88 * Function to call with new addresses of this peer. 79 * Function to call with new addresses of this peer.
89 * 80 *
90 * @param cls the closure 81 * @param cls the closure
91 * @param key hash position of this address in the DHT
92 * @param address address under which we are likely reachable, 82 * @param address address under which we are likely reachable,
93 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/" 83 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/"
94 * @param source handle for sending from this address, NULL if we can only receive 84 * @param source handle for sending from this address, NULL if we can only receive
@@ -96,7 +86,6 @@ struct GNUNET_DHTU_PluginEnvironment
96 */ 86 */
97 void 87 void
98 (*address_add_cb)(void *cls, 88 (*address_add_cb)(void *cls,
99 struct GNUNET_DHTU_HashKey *key,
100 const char *address, 89 const char *address,
101 struct GNUNET_DHTU_Source *source, 90 struct GNUNET_DHTU_Source *source,
102 void **ctx); 91 void **ctx);
@@ -128,18 +117,16 @@ struct GNUNET_DHTU_PluginEnvironment
128 * that peer. 117 * that peer.
129 * 118 *
130 * @param cls the closure 119 * @param cls the closure
131 * @param pk public key of the target,
132 * pointer will remain valid until @e disconnect_cb is called
133 * @para peer_id hash position of the peer,
134 * pointer will remain valid until @e disconnect_cb is called
135 * @param target handle to the target, 120 * @param target handle to the target,
136 * pointer will remain valid until @e disconnect_cb is called 121 * pointer will remain valid until @e disconnect_cb is called
122 * @para pid peer identity,
123 * pointer will remain valid until @e disconnect_cb is called
137 * @param[out] ctx storage space for DHT to use in association with this target 124 * @param[out] ctx storage space for DHT to use in association with this target
138 */ 125 */
139 void 126 void
140 (*connect_cb)(void *cls, 127 (*connect_cb)(void *cls,
141 struct GNUNET_DHTU_Target *target, 128 struct GNUNET_DHTU_Target *target,
142 struct GNUNET_DHTU_HashKey *key, 129 const struct GNUNET_PeerIdentity *pid,
143 void **ctx); 130 void **ctx);
144 131
145 /** 132 /**
@@ -185,10 +172,12 @@ struct GNUNET_DHTU_PluginFunctions
185 * Request creation of a session with a peer at the given @a address. 172 * Request creation of a session with a peer at the given @a address.
186 * 173 *
187 * @param cls closure (internal context for the plugin) 174 * @param cls closure (internal context for the plugin)
188 * @param address target address to connect to 175 * @param pid target identity of the peer to connect to
176 * @param address target address URI to connect to
189 */ 177 */
190 void 178 void
191 (*try_connect) (void *cls, 179 (*try_connect) (void *cls,
180 struct GNUNET_PeerIdentity *pid,
192 const char *address); 181 const char *address);
193 182
194 183
diff --git a/src/include/gnunet_hello_uri_lib.h b/src/include/gnunet_hello_uri_lib.h
new file mode 100644
index 000000000..0f61384d1
--- /dev/null
+++ b/src/include/gnunet_hello_uri_lib.h
@@ -0,0 +1,169 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
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
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 * @file
24 * Helper library for handling HELLO URIs
25 *
26 * @defgroup hello_uri Hello_Uri library
27 * Helper library for handling HELLO URIs
28 *
29 * @{
30 */
31
32#ifndef GNUNET_HELLO_URI_LIB_H
33#define GNUNET_HELLO_URI_LIB_H
34
35#ifdef __cplusplus
36extern "C" {
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42#include "gnunet_util_lib.h"
43
44
45/**
46 * Context for building (or parsing) HELLO URIs.
47 */
48struct GNUNET_HELLO_Builder;
49
50
51/**
52 * Allocate builder.
53 *
54 * @param pid peer the builder is for
55 * @return new builder
56 */
57struct GNUNET_HELLO_Builder *
58GNUNET_HELLO_builder_new (const struct GNUNET_PeerIdentity *pid);
59
60
61/**
62 * Release resources of a @a builder.
63 *
64 * @param[in] builder to free
65 */
66void
67GNUNET_HELLO_builder_free (struct GNUNET_HELLO_Builder *builder);
68
69
70/**
71 * Parse @a msg into builder.
72 *
73 * @param msg message to parse
74 * @return builder, NULL on failure
75 */
76struct GNUNET_HELLO_Builder *
77GNUNET_HELLO_builder_from_msg (const struct GNUNET_MessageHeader *msg);
78
79
80/**
81 * Parse GNUnet HELLO @a url into builder.
82 *
83 * @param url URL to parse
84 * @return builder, NULL on failure
85 */
86struct GNUNET_HELLO_Builder *
87GNUNET_HELLO_builder_from_url (const char *url);
88
89
90/**
91 * Generate HELLO message from a @a builder
92 *
93 * @param builder builder to serialize
94 * @return HELLO message matching @a builder
95 */
96struct GNUNET_MQ_Envelope *
97GNUNET_HELLO_builder_to_env (struct GNUNET_HELLO_Builder *builder);
98
99
100/**
101 * Generate GNUnet HELLO URI from a @a builder
102 *
103 * @param builder builder to serialize
104 * @return hello URI
105 */
106char *
107GNUNET_HELLO_builder_to_url (struct GNUNET_HELLO_Builder *builder);
108
109
110/**
111 * Add individual @a address to the @a builder
112 *
113 * @param[in,out] builder to update
114 * @param address address URI to add
115 */
116enum GNUNET_GenericReturnValue
117GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder,
118 const char *address);
119
120
121/**
122 * Remove individual @a address from the @a builder
123 *
124 * @param[in,out] builder to update
125 * @param address address URI to remove
126 */
127enum GNUNET_GenericReturnValue
128GNUNET_HELLO_builder_del_address (struct GNUNET_HELLO_Builder *builder,
129 const char *address);
130
131
132/**
133 * Callback function used to extract URIs from a builder.
134 *
135 * @param cls closure
136 * @param uri one of the URIs
137 */
138typedef void
139(*GNUNET_HELLO_UriCallback) (void *cls,
140 const char *uri);
141
142
143/**
144 * Iterate over URIs in a builder.
145 *
146 * @param builder builder to iterate over
147 * @param[out] pid set to the peer the @a builder is for
148 * @param uc callback invoked for each URI, can be NULL
149 * @param uc_cls closure for @a addrgen
150 */
151void
152GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder,
153 struct GNUNET_PeerIdentity *pid,
154 GNUNET_HELLO_UriCallback uc,
155 void *uc_cls);
156
157#if 0 /* keep Emacsens' auto-indent happy */
158{
159#endif
160#ifdef __cplusplus
161}
162#endif
163
164/* ifndef GNUNET_HELLO_URI_LIB_H */
165#endif
166
167/** @} */ /* end of group */
168
169/* end of gnunet_hello_uri_lib.h */