diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 21:51:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-19 12:39:55 +0100 |
commit | ba9296269617c157baffb59a6240c87ae5935e95 (patch) | |
tree | 7f82470cce894be0b3441f8150baea36d7138834 /src/dht | |
parent | 25ef40ef768743a10b7b29881c267e0fdc9fc677 (diff) | |
download | gnunet-ba9296269617c157baffb59a6240c87ae5935e95.tar.gz gnunet-ba9296269617c157baffb59a6240c87ae5935e95.zip |
first steps towards usable dhtu
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/Makefile.am | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 286 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.h | 8 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 235 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.h | 46 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_nse.c | 121 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_nse.h | 52 | ||||
-rw-r--r-- | src/dht/plugin_block_dht.c | 325 |
8 files changed, 598 insertions, 476 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 |
65 | gnunet_service_dht_LDADD = \ | 64 | gnunet_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 | */ | ||
43 | struct 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 | */ | ||
81 | struct 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 | */ |
45 | struct GNUNET_MessageHeader *GDS_my_hello; | 113 | struct GNUNET_MessageHeader *GDS_my_hello; |
46 | 114 | ||
47 | /** | 115 | /** |
48 | * Handle to get our current HELLO. | 116 | * Handles for the DHT underlays. |
117 | */ | ||
118 | static struct Underlay *u_head; | ||
119 | |||
120 | /** | ||
121 | * Handles for the DHT underlays. | ||
122 | */ | ||
123 | static struct Underlay *u_tail; | ||
124 | |||
125 | /** | ||
126 | * Head of addresses of this peer. | ||
127 | */ | ||
128 | static struct MyAddress *a_head; | ||
129 | |||
130 | /** | ||
131 | * Tail of addresses of this peer. | ||
49 | */ | 132 | */ |
50 | static struct GNUNET_TRANSPORT_HelloGetHandle *ghh; | 133 | static struct MyAddress *a_tail; |
51 | 134 | ||
52 | /** | 135 | /** |
53 | * Hello address expiration | 136 | * Hello address expiration |
54 | */ | 137 | */ |
55 | struct GNUNET_TIME_Relative hello_expiration; | 138 | struct 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 | */ | ||
144 | static 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 | */ | ||
156 | static void | ||
157 | update_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 | */ |
187 | double | ||
188 | GDS_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 | */ |
68 | static void | 200 | static void |
69 | process_hello (void *cls, | 201 | update_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 | */ | ||
217 | static void | ||
218 | u_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 | */ | ||
243 | static void | ||
244 | u_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, | |||
85 | static void | 262 | static void |
86 | shutdown_task (void *cls) | 263 | shutdown_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 | */ | ||
293 | static void | ||
294 | load_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 | */ | ||
136 | double | ||
137 | GDS_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; | |||
400 | struct GNUNET_HashCode my_identity_hash; | 397 | struct GNUNET_HashCode my_identity_hash; |
401 | 398 | ||
402 | /** | 399 | /** |
403 | * Handle to CORE. | ||
404 | */ | ||
405 | static struct GNUNET_CORE_Handle *core_api; | ||
406 | |||
407 | /** | ||
408 | * Handle to ATS connectivity. | ||
409 | */ | ||
410 | static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | ||
411 | |||
412 | /** | ||
413 | * Our private key. | 400 | * Our private key. |
414 | */ | 401 | */ |
415 | static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key; | 402 | static 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 | /** | 758 | void |
768 | * Method called whenever a peer connects. | 759 | GDS_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 | */ | ||
775 | static void * | ||
776 | handle_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 | */ |
843 | static void | 825 | void |
844 | handle_core_disconnect (void *cls, | 826 | GDS_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 | */ | ||
1688 | static void | ||
1689 | core_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 | ||
2426 | enum GNUNET_GenericReturnValue | 2394 | void |
2427 | GDS_NEIGHBOURS_init () | 2395 | GDS_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 | |||
2441 | enum GNUNET_GenericReturnValue | ||
2442 | GDS_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 () | |||
2503 | void | 2500 | void |
2504 | GDS_NEIGHBOURS_done () | 2501 | GDS_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 | */ | ||
151 | void | ||
152 | GDS_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 | */ | ||
163 | void | ||
164 | GDS_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 | */ | ||
177 | void | ||
178 | GDS_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 | */ | ||
37 | static double log_of_network_size_estimate = 4.0; | ||
38 | |||
39 | /** | ||
40 | * Network size estimation handle. | ||
41 | */ | ||
42 | static 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 | */ | ||
54 | static void | ||
55 | update_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 | */ | ||
73 | double | ||
74 | GDS_NSE_get () | ||
75 | { | ||
76 | return log_of_network_size_estimate; | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Initialize NSE subsystem. | ||
82 | */ | ||
83 | void | ||
84 | GDS_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 | */ | ||
110 | void | ||
111 | GDS_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 | */ | ||
35 | double | ||
36 | GDS_NSE_get (void); | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Initialize NSE subsystem. | ||
41 | */ | ||
42 | void | ||
43 | GDS_NSE_init (void); | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Shutdown NSE subsystem. | ||
48 | */ | ||
49 | void | ||
50 | GDS_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 | */ |
172 | static enum GNUNET_GenericReturnValue | 178 | static enum GNUNET_GenericReturnValue |
173 | block_plugin_dht_check_query (void *cls, | 179 | block_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 | */ |
200 | static enum GNUNET_GenericReturnValue | 210 | static enum GNUNET_GenericReturnValue |
201 | block_plugin_dht_check_block (void *cls, | 211 | block_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 | */ |
252 | static enum GNUNET_BLOCK_ReplyEvaluationResult | 268 | static enum GNUNET_BLOCK_ReplyEvaluationResult |
253 | block_plugin_dht_check_reply ( | 269 | block_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; |