diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_core.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_core.c | 1162 |
1 files changed, 583 insertions, 579 deletions
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index a08c80aae..7d1791f3c 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c | |||
@@ -39,7 +39,7 @@ | |||
39 | #include "gnunet_statistics_service.h" | 39 | #include "gnunet_statistics_service.h" |
40 | #include "cadet_protocol.h" | 40 | #include "cadet_protocol.h" |
41 | 41 | ||
42 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-cor", __VA_ARGS__) | 42 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Information we keep per direction for a route. | 45 | * Information we keep per direction for a route. |
@@ -52,7 +52,8 @@ struct RouteDirection; | |||
52 | * routes that have the current maximum of messages in the buffer (in | 52 | * routes that have the current maximum of messages in the buffer (in |
53 | * case we have to purge). | 53 | * case we have to purge). |
54 | */ | 54 | */ |
55 | struct Rung { | 55 | struct Rung |
56 | { | ||
56 | /** | 57 | /** |
57 | * Rung of RouteDirections with one more buffer entry each. | 58 | * Rung of RouteDirections with one more buffer entry each. |
58 | */ | 59 | */ |
@@ -89,7 +90,8 @@ struct Rung { | |||
89 | /** | 90 | /** |
90 | * Information we keep per direction for a route. | 91 | * Information we keep per direction for a route. |
91 | */ | 92 | */ |
92 | struct RouteDirection { | 93 | struct RouteDirection |
94 | { | ||
93 | /** | 95 | /** |
94 | * DLL of other route directions within the same `struct Rung`. | 96 | * DLL of other route directions within the same `struct Rung`. |
95 | */ | 97 | */ |
@@ -145,7 +147,8 @@ struct RouteDirection { | |||
145 | * the complete `struct CadetPath` that is formed by the individual | 147 | * the complete `struct CadetPath` that is formed by the individual |
146 | * routes. | 148 | * routes. |
147 | */ | 149 | */ |
148 | struct CadetRoute { | 150 | struct CadetRoute |
151 | { | ||
149 | /** | 152 | /** |
150 | * Information about the next hop on this route. | 153 | * Information about the next hop on this route. |
151 | */ | 154 | */ |
@@ -231,10 +234,10 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
231 | * @param cid hash generated from the connection identifier | 234 | * @param cid hash generated from the connection identifier |
232 | */ | 235 | */ |
233 | static struct CadetRoute * | 236 | static struct CadetRoute * |
234 | get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 237 | get_route (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
235 | { | 238 | { |
236 | return GNUNET_CONTAINER_multishortmap_get(routes, | 239 | return GNUNET_CONTAINER_multishortmap_get (routes, |
237 | &cid->connection_of_tunnel); | 240 | &cid->connection_of_tunnel); |
238 | } | 241 | } |
239 | 242 | ||
240 | 243 | ||
@@ -244,22 +247,22 @@ get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | |||
244 | * @param dir direction to lower in rung. | 247 | * @param dir direction to lower in rung. |
245 | */ | 248 | */ |
246 | static void | 249 | static void |
247 | lower_rung(struct RouteDirection *dir) | 250 | lower_rung (struct RouteDirection *dir) |
248 | { | 251 | { |
249 | struct Rung *rung = dir->rung; | 252 | struct Rung *rung = dir->rung; |
250 | struct Rung *prev; | 253 | struct Rung *prev; |
251 | 254 | ||
252 | GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir); | 255 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); |
253 | prev = rung->prev; | 256 | prev = rung->prev; |
254 | GNUNET_assert(NULL != prev); | 257 | GNUNET_assert (NULL != prev); |
255 | if (prev->rung_off != rung->rung_off - 1) | 258 | if (prev->rung_off != rung->rung_off - 1) |
256 | { | 259 | { |
257 | prev = GNUNET_new(struct Rung); | 260 | prev = GNUNET_new (struct Rung); |
258 | prev->rung_off = rung->rung_off - 1; | 261 | prev->rung_off = rung->rung_off - 1; |
259 | GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung->prev, prev); | 262 | GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev); |
260 | } | 263 | } |
261 | GNUNET_assert(NULL != prev); | 264 | GNUNET_assert (NULL != prev); |
262 | GNUNET_CONTAINER_DLL_insert(prev->rd_head, prev->rd_tail, dir); | 265 | GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir); |
263 | dir->rung = prev; | 266 | dir->rung = prev; |
264 | } | 267 | } |
265 | 268 | ||
@@ -272,13 +275,13 @@ lower_rung(struct RouteDirection *dir) | |||
272 | * @param env envelope to discard | 275 | * @param env envelope to discard |
273 | */ | 276 | */ |
274 | static void | 277 | static void |
275 | discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) | 278 | discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) |
276 | { | 279 | { |
277 | GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env); | 280 | GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); |
278 | cur_buffers--; | 281 | cur_buffers--; |
279 | GNUNET_MQ_discard(env); | 282 | GNUNET_MQ_discard (env); |
280 | lower_rung(dir); | 283 | lower_rung (dir); |
281 | GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO); | 284 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
282 | } | 285 | } |
283 | 286 | ||
284 | 287 | ||
@@ -286,24 +289,24 @@ discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) | |||
286 | * Discard all messages from the highest rung, to make space. | 289 | * Discard all messages from the highest rung, to make space. |
287 | */ | 290 | */ |
288 | static void | 291 | static void |
289 | discard_all_from_rung_tail() | 292 | discard_all_from_rung_tail () |
290 | { | 293 | { |
291 | struct Rung *tail = rung_tail; | 294 | struct Rung *tail = rung_tail; |
292 | struct RouteDirection *dir; | 295 | struct RouteDirection *dir; |
293 | 296 | ||
294 | while (NULL != (dir = tail->rd_head)) | 297 | while (NULL != (dir = tail->rd_head)) |
295 | { | 298 | { |
296 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 299 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
297 | "Queue full due new message %s on connection %s, dropping old message\n", | 300 | "Queue full due new message %s on connection %s, dropping old message\n", |
298 | GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel)); | 301 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); |
299 | GNUNET_STATISTICS_update(stats, | 302 | GNUNET_STATISTICS_update (stats, |
300 | "# messages dropped due to full buffer", | 303 | "# messages dropped due to full buffer", |
301 | 1, | 304 | 1, |
302 | GNUNET_NO); | 305 | GNUNET_NO); |
303 | discard_buffer(dir, dir->env_head); | 306 | discard_buffer (dir, dir->env_head); |
304 | } | 307 | } |
305 | GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, tail); | 308 | GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail); |
306 | GNUNET_free(tail); | 309 | GNUNET_free (tail); |
307 | } | 310 | } |
308 | 311 | ||
309 | 312 | ||
@@ -317,10 +320,10 @@ discard_all_from_rung_tail() | |||
317 | * @param msg the message to forward | 320 | * @param msg the message to forward |
318 | */ | 321 | */ |
319 | static void | 322 | static void |
320 | route_message(struct CadetPeer *prev, | 323 | route_message (struct CadetPeer *prev, |
321 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 324 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
322 | const struct GNUNET_MessageHeader *msg, | 325 | const struct GNUNET_MessageHeader *msg, |
323 | const enum GNUNET_MQ_PriorityPreferences priority) | 326 | const enum GNUNET_MQ_PriorityPreferences priority) |
324 | { | 327 | { |
325 | struct CadetRoute *route; | 328 | struct CadetRoute *route; |
326 | struct RouteDirection *dir; | 329 | struct RouteDirection *dir; |
@@ -328,133 +331,133 @@ route_message(struct CadetPeer *prev, | |||
328 | struct Rung *nxt; | 331 | struct Rung *nxt; |
329 | struct GNUNET_MQ_Envelope *env; | 332 | struct GNUNET_MQ_Envelope *env; |
330 | 333 | ||
331 | route = get_route(cid); | 334 | route = get_route (cid); |
332 | if (NULL == route) | 335 | if (NULL == route) |
336 | { | ||
337 | struct GNUNET_MQ_Envelope *env; | ||
338 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; | ||
339 | |||
340 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
341 | "Failed to route message of type %u from %s on connection %s: no route\n", | ||
342 | ntohs (msg->type), | ||
343 | GCP_2s (prev), | ||
344 | GNUNET_sh2s (&cid->connection_of_tunnel)); | ||
345 | switch (ntohs (msg->type)) | ||
333 | { | 346 | { |
334 | struct GNUNET_MQ_Envelope *env; | 347 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: |
335 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; | 348 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: |
336 | 349 | /* No need to respond to these! */ | |
337 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
338 | "Failed to route message of type %u from %s on connection %s: no route\n", | ||
339 | ntohs(msg->type), | ||
340 | GCP_2s(prev), | ||
341 | GNUNET_sh2s(&cid->connection_of_tunnel)); | ||
342 | switch (ntohs(msg->type)) | ||
343 | { | ||
344 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: | ||
345 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: | ||
346 | /* No need to respond to these! */ | ||
347 | return; | ||
348 | } | ||
349 | env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | ||
350 | bm->cid = *cid; | ||
351 | bm->peer1 = my_full_id; | ||
352 | GCP_send_ooo(prev, env); | ||
353 | return; | 350 | return; |
354 | } | 351 | } |
355 | route->last_use = GNUNET_TIME_absolute_get(); | 352 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
356 | GNUNET_CONTAINER_heap_update_cost(route->hn, route->last_use.abs_value_us); | 353 | bm->cid = *cid; |
354 | bm->peer1 = my_full_id; | ||
355 | GCP_send_ooo (prev, env); | ||
356 | return; | ||
357 | } | ||
358 | route->last_use = GNUNET_TIME_absolute_get (); | ||
359 | GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us); | ||
357 | dir = (prev == route->prev.hop) ? &route->next : &route->prev; | 360 | dir = (prev == route->prev.hop) ? &route->next : &route->prev; |
358 | if (GNUNET_YES == dir->is_ready) | 361 | if (GNUNET_YES == dir->is_ready) |
359 | { | 362 | { |
360 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 363 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
361 | "Routing message of type %u from %s to %s on connection %s\n", | 364 | "Routing message of type %u from %s to %s on connection %s\n", |
362 | ntohs(msg->type), | 365 | ntohs (msg->type), |
363 | GCP_2s(prev), | 366 | GCP_2s (prev), |
364 | GNUNET_i2s(GCP_get_id(dir->hop)), | 367 | GNUNET_i2s (GCP_get_id (dir->hop)), |
365 | GNUNET_sh2s(&cid->connection_of_tunnel)); | 368 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
366 | dir->is_ready = GNUNET_NO; | 369 | dir->is_ready = GNUNET_NO; |
367 | GCP_send(dir->mqm, GNUNET_MQ_msg_copy(msg)); | 370 | GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg)); |
368 | return; | 371 | return; |
369 | } | 372 | } |
370 | /* Check if low latency is required and if the previous message was | 373 | /* Check if low latency is required and if the previous message was |
371 | unreliable; if so, make sure we only queue one message per | 374 | unreliable; if so, make sure we only queue one message per |
372 | direction (no buffering). */ | 375 | direction (no buffering). */ |
373 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && | 376 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && |
374 | (NULL != dir->env_head) && | 377 | (NULL != dir->env_head) && |
375 | (0 == | 378 | (0 == |
376 | (GNUNET_MQ_env_get_options(dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) | 379 | (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) |
377 | discard_buffer(dir, dir->env_head); | 380 | discard_buffer (dir, dir->env_head); |
378 | /* Check for duplicates */ | 381 | /* Check for duplicates */ |
379 | for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; | 382 | for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; |
380 | env = GNUNET_MQ_env_next(env)) | 383 | env = GNUNET_MQ_env_next (env)) |
384 | { | ||
385 | const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); | ||
386 | |||
387 | if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size)))) | ||
381 | { | 388 | { |
382 | const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg(env); | 389 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
383 | 390 | "Received duplicate of message already in buffer, dropping\n"); | |
384 | if ((hdr->size == msg->size) && (0 == memcmp(hdr, msg, ntohs(msg->size)))) | 391 | GNUNET_STATISTICS_update (stats, |
385 | { | 392 | "# messages dropped due to duplicate in buffer", |
386 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 393 | 1, |
387 | "Received duplicate of message already in buffer, dropping\n"); | 394 | GNUNET_NO); |
388 | GNUNET_STATISTICS_update(stats, | 395 | return; |
389 | "# messages dropped due to duplicate in buffer", | ||
390 | 1, | ||
391 | GNUNET_NO); | ||
392 | return; | ||
393 | } | ||
394 | } | 396 | } |
397 | } | ||
395 | 398 | ||
396 | rung = dir->rung; | 399 | rung = dir->rung; |
397 | if (cur_buffers == max_buffers) | 400 | if (cur_buffers == max_buffers) |
401 | { | ||
402 | /* Need to make room. */ | ||
403 | if (NULL != rung->next) | ||
398 | { | 404 | { |
399 | /* Need to make room. */ | 405 | /* Easy case, drop messages from route directions in highest rung */ |
400 | if (NULL != rung->next) | 406 | discard_all_from_rung_tail (); |
401 | { | ||
402 | /* Easy case, drop messages from route directions in highest rung */ | ||
403 | discard_all_from_rung_tail(); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | /* We are in the highest rung, drop our own! */ | ||
408 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
409 | "Queue full due new message %s on connection %s, dropping old message\n", | ||
410 | GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel)); | ||
411 | GNUNET_STATISTICS_update(stats, | ||
412 | "# messages dropped due to full buffer", | ||
413 | 1, | ||
414 | GNUNET_NO); | ||
415 | discard_buffer(dir, dir->env_head); | ||
416 | rung = dir->rung; | ||
417 | } | ||
418 | } | 407 | } |
408 | else | ||
409 | { | ||
410 | /* We are in the highest rung, drop our own! */ | ||
411 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
412 | "Queue full due new message %s on connection %s, dropping old message\n", | ||
413 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); | ||
414 | GNUNET_STATISTICS_update (stats, | ||
415 | "# messages dropped due to full buffer", | ||
416 | 1, | ||
417 | GNUNET_NO); | ||
418 | discard_buffer (dir, dir->env_head); | ||
419 | rung = dir->rung; | ||
420 | } | ||
421 | } | ||
419 | /* remove 'dir' from current rung */ | 422 | /* remove 'dir' from current rung */ |
420 | GNUNET_CONTAINER_DLL_remove(rung->rd_head, rung->rd_tail, dir); | 423 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); |
421 | /* make 'nxt' point to the next higher rung, create if necessary */ | 424 | /* make 'nxt' point to the next higher rung, create if necessary */ |
422 | nxt = rung->next; | 425 | nxt = rung->next; |
423 | if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) | 426 | if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) |
424 | { | 427 | { |
425 | nxt = GNUNET_new(struct Rung); | 428 | nxt = GNUNET_new (struct Rung); |
426 | nxt->rung_off = rung->rung_off + 1; | 429 | nxt->rung_off = rung->rung_off + 1; |
427 | GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung, nxt); | 430 | GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt); |
428 | } | 431 | } |
429 | /* insert 'dir' into next higher rung */ | 432 | /* insert 'dir' into next higher rung */ |
430 | GNUNET_CONTAINER_DLL_insert(nxt->rd_head, nxt->rd_tail, dir); | 433 | GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir); |
431 | dir->rung = nxt; | 434 | dir->rung = nxt; |
432 | 435 | ||
433 | /* add message into 'dir' buffer */ | 436 | /* add message into 'dir' buffer */ |
434 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 437 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
435 | "Queueing new message of type %u from %s to %s on connection %s\n", | 438 | "Queueing new message of type %u from %s to %s on connection %s\n", |
436 | ntohs(msg->type), | 439 | ntohs (msg->type), |
437 | GCP_2s(prev), | 440 | GCP_2s (prev), |
438 | GNUNET_i2s(GCP_get_id(dir->hop)), | 441 | GNUNET_i2s (GCP_get_id (dir->hop)), |
439 | GNUNET_sh2s(&cid->connection_of_tunnel)); | 442 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
440 | env = GNUNET_MQ_msg_copy(msg); | 443 | env = GNUNET_MQ_msg_copy (msg); |
441 | GNUNET_MQ_env_set_options(env, priority); | 444 | GNUNET_MQ_env_set_options (env, priority); |
442 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && | 445 | if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && |
443 | (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && | 446 | (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && |
444 | (NULL != dir->env_head) && | 447 | (NULL != dir->env_head) && |
445 | (0 == (GNUNET_MQ_env_get_options(dir->env_head) & | 448 | (0 == (GNUNET_MQ_env_get_options (dir->env_head) |
446 | GNUNET_MQ_PREF_LOW_LATENCY))) | 449 | & GNUNET_MQ_PREF_LOW_LATENCY))) |
447 | GNUNET_MQ_dll_insert_head(&dir->env_head, &dir->env_tail, env); | 450 | GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env); |
448 | else | 451 | else |
449 | GNUNET_MQ_dll_insert_tail(&dir->env_head, &dir->env_tail, env); | 452 | GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env); |
450 | cur_buffers++; | 453 | cur_buffers++; |
451 | GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO); | 454 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
452 | /* Clean up 'rung' if now empty (and not head) */ | 455 | /* Clean up 'rung' if now empty (and not head) */ |
453 | if ((NULL == rung->rd_head) && (rung != rung_head)) | 456 | if ((NULL == rung->rd_head) && (rung != rung_head)) |
454 | { | 457 | { |
455 | GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, rung); | 458 | GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung); |
456 | GNUNET_free(rung); | 459 | GNUNET_free (rung); |
457 | } | 460 | } |
458 | } | 461 | } |
459 | 462 | ||
460 | 463 | ||
@@ -467,16 +470,16 @@ route_message(struct CadetPeer *prev, | |||
467 | * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. | 470 | * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. |
468 | */ | 471 | */ |
469 | static int | 472 | static int |
470 | check_connection_create(void *cls, | 473 | check_connection_create (void *cls, |
471 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | 474 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) |
472 | { | 475 | { |
473 | uint16_t size = ntohs(msg->header.size) - sizeof(*msg); | 476 | uint16_t size = ntohs (msg->header.size) - sizeof(*msg); |
474 | 477 | ||
475 | if (0 != (size % sizeof(struct GNUNET_PeerIdentity))) | 478 | if (0 != (size % sizeof(struct GNUNET_PeerIdentity))) |
476 | { | 479 | { |
477 | GNUNET_break_op(0); | 480 | GNUNET_break_op (0); |
478 | return GNUNET_NO; | 481 | return GNUNET_NO; |
479 | } | 482 | } |
480 | return GNUNET_YES; | 483 | return GNUNET_YES; |
481 | } | 484 | } |
482 | 485 | ||
@@ -487,24 +490,24 @@ check_connection_create(void *cls, | |||
487 | * @param dir direction to destroy (do NOT free memory of 'dir' itself) | 490 | * @param dir direction to destroy (do NOT free memory of 'dir' itself) |
488 | */ | 491 | */ |
489 | static void | 492 | static void |
490 | destroy_direction(struct RouteDirection *dir) | 493 | destroy_direction (struct RouteDirection *dir) |
491 | { | 494 | { |
492 | struct GNUNET_MQ_Envelope *env; | 495 | struct GNUNET_MQ_Envelope *env; |
493 | 496 | ||
494 | while (NULL != (env = dir->env_head)) | 497 | while (NULL != (env = dir->env_head)) |
495 | { | 498 | { |
496 | GNUNET_STATISTICS_update(stats, | 499 | GNUNET_STATISTICS_update (stats, |
497 | "# messages dropped due to route destruction", | 500 | "# messages dropped due to route destruction", |
498 | 1, | 501 | 1, |
499 | GNUNET_NO); | 502 | GNUNET_NO); |
500 | discard_buffer(dir, env); | 503 | discard_buffer (dir, env); |
501 | } | 504 | } |
502 | if (NULL != dir->mqm) | 505 | if (NULL != dir->mqm) |
503 | { | 506 | { |
504 | GCP_request_mq_cancel(dir->mqm, NULL); | 507 | GCP_request_mq_cancel (dir->mqm, NULL); |
505 | dir->mqm = NULL; | 508 | dir->mqm = NULL; |
506 | } | 509 | } |
507 | GNUNET_CONTAINER_DLL_remove(rung_head->rd_head, rung_head->rd_tail, dir); | 510 | GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir); |
508 | } | 511 | } |
509 | 512 | ||
510 | 513 | ||
@@ -514,26 +517,26 @@ destroy_direction(struct RouteDirection *dir) | |||
514 | * @param route route to destroy | 517 | * @param route route to destroy |
515 | */ | 518 | */ |
516 | static void | 519 | static void |
517 | destroy_route(struct CadetRoute *route) | 520 | destroy_route (struct CadetRoute *route) |
518 | { | 521 | { |
519 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 522 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
520 | "Destroying route from %s to %s of connection %s\n", | 523 | "Destroying route from %s to %s of connection %s\n", |
521 | GNUNET_i2s(GCP_get_id(route->prev.hop)), | 524 | GNUNET_i2s (GCP_get_id (route->prev.hop)), |
522 | GNUNET_i2s2(GCP_get_id(route->next.hop)), | 525 | GNUNET_i2s2 (GCP_get_id (route->next.hop)), |
523 | GNUNET_sh2s(&route->cid.connection_of_tunnel)); | 526 | GNUNET_sh2s (&route->cid.connection_of_tunnel)); |
524 | GNUNET_assert(route == GNUNET_CONTAINER_heap_remove_node(route->hn)); | 527 | GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn)); |
525 | GNUNET_assert( | 528 | GNUNET_assert ( |
526 | GNUNET_YES == | 529 | GNUNET_YES == |
527 | GNUNET_CONTAINER_multishortmap_remove(routes, | 530 | GNUNET_CONTAINER_multishortmap_remove (routes, |
528 | &route->cid.connection_of_tunnel, | 531 | &route->cid.connection_of_tunnel, |
529 | route)); | 532 | route)); |
530 | GNUNET_STATISTICS_set(stats, | 533 | GNUNET_STATISTICS_set (stats, |
531 | "# routes", | 534 | "# routes", |
532 | GNUNET_CONTAINER_multishortmap_size(routes), | 535 | GNUNET_CONTAINER_multishortmap_size (routes), |
533 | GNUNET_NO); | 536 | GNUNET_NO); |
534 | destroy_direction(&route->prev); | 537 | destroy_direction (&route->prev); |
535 | destroy_direction(&route->next); | 538 | destroy_direction (&route->next); |
536 | GNUNET_free(route); | 539 | GNUNET_free (route); |
537 | } | 540 | } |
538 | 541 | ||
539 | 542 | ||
@@ -546,30 +549,30 @@ destroy_route(struct CadetRoute *route) | |||
546 | * @param peer2 another one of the peers where a link is broken | 549 | * @param peer2 another one of the peers where a link is broken |
547 | */ | 550 | */ |
548 | static void | 551 | static void |
549 | send_broken(struct RouteDirection *target, | 552 | send_broken (struct RouteDirection *target, |
550 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 553 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
551 | const struct GNUNET_PeerIdentity *peer1, | 554 | const struct GNUNET_PeerIdentity *peer1, |
552 | const struct GNUNET_PeerIdentity *peer2) | 555 | const struct GNUNET_PeerIdentity *peer2) |
553 | { | 556 | { |
554 | struct GNUNET_MQ_Envelope *env; | 557 | struct GNUNET_MQ_Envelope *env; |
555 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; | 558 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; |
556 | 559 | ||
557 | if (NULL == target->mqm) | 560 | if (NULL == target->mqm) |
558 | return; /* Can't send notification, connection is down! */ | 561 | return; /* Can't send notification, connection is down! */ |
559 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 562 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
560 | "Notifying %s about BROKEN route at %s-%s of connection %s\n", | 563 | "Notifying %s about BROKEN route at %s-%s of connection %s\n", |
561 | GCP_2s(target->hop), | 564 | GCP_2s (target->hop), |
562 | GNUNET_i2s(peer1), | 565 | GNUNET_i2s (peer1), |
563 | GNUNET_i2s2(peer2), | 566 | GNUNET_i2s2 (peer2), |
564 | GNUNET_sh2s(&cid->connection_of_tunnel)); | 567 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
565 | 568 | ||
566 | env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 569 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
567 | bm->cid = *cid; | 570 | bm->cid = *cid; |
568 | if (NULL != peer1) | 571 | if (NULL != peer1) |
569 | bm->peer1 = *peer1; | 572 | bm->peer1 = *peer1; |
570 | if (NULL != peer2) | 573 | if (NULL != peer2) |
571 | bm->peer2 = *peer2; | 574 | bm->peer2 = *peer2; |
572 | GCP_request_mq_cancel(target->mqm, env); | 575 | GCP_request_mq_cancel (target->mqm, env); |
573 | target->mqm = NULL; | 576 | target->mqm = NULL; |
574 | } | 577 | } |
575 | 578 | ||
@@ -582,31 +585,31 @@ send_broken(struct RouteDirection *target, | |||
582 | * @param cls NULL | 585 | * @param cls NULL |
583 | */ | 586 | */ |
584 | static void | 587 | static void |
585 | timeout_cb(void *cls) | 588 | timeout_cb (void *cls) |
586 | { | 589 | { |
587 | struct CadetRoute *r; | 590 | struct CadetRoute *r; |
588 | struct GNUNET_TIME_Relative linger; | 591 | struct GNUNET_TIME_Relative linger; |
589 | struct GNUNET_TIME_Absolute exp; | 592 | struct GNUNET_TIME_Absolute exp; |
590 | 593 | ||
591 | timeout_task = NULL; | 594 | timeout_task = NULL; |
592 | linger = GNUNET_TIME_relative_multiply(keepalive_period, 3); | 595 | linger = GNUNET_TIME_relative_multiply (keepalive_period, 3); |
593 | while (NULL != (r = GNUNET_CONTAINER_heap_peek(route_heap))) | 596 | while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) |
597 | { | ||
598 | exp = GNUNET_TIME_absolute_add (r->last_use, linger); | ||
599 | if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) | ||
594 | { | 600 | { |
595 | exp = GNUNET_TIME_absolute_add(r->last_use, linger); | 601 | /* Route not yet timed out, wait until it does. */ |
596 | if (0 != GNUNET_TIME_absolute_get_remaining(exp).rel_value_us) | 602 | timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL); |
597 | { | 603 | return; |
598 | /* Route not yet timed out, wait until it does. */ | ||
599 | timeout_task = GNUNET_SCHEDULER_add_at(exp, &timeout_cb, NULL); | ||
600 | return; | ||
601 | } | ||
602 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
603 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", | ||
604 | GNUNET_STRINGS_absolute_time_to_string(r->last_use), | ||
605 | GNUNET_STRINGS_relative_time_to_string(linger, GNUNET_YES)); | ||
606 | send_broken(&r->prev, &r->cid, NULL, NULL); | ||
607 | send_broken(&r->next, &r->cid, NULL, NULL); | ||
608 | destroy_route(r); | ||
609 | } | 604 | } |
605 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
606 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", | ||
607 | GNUNET_STRINGS_absolute_time_to_string (r->last_use), | ||
608 | GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES)); | ||
609 | send_broken (&r->prev, &r->cid, NULL, NULL); | ||
610 | send_broken (&r->next, &r->cid, NULL, NULL); | ||
611 | destroy_route (r); | ||
612 | } | ||
610 | /* No more routes left, so no need for a #timeout_task */ | 613 | /* No more routes left, so no need for a #timeout_task */ |
611 | } | 614 | } |
612 | 615 | ||
@@ -624,32 +627,32 @@ timeout_cb(void *cls) | |||
624 | * and the last envelope was discarded | 627 | * and the last envelope was discarded |
625 | */ | 628 | */ |
626 | static void | 629 | static void |
627 | dir_ready_cb(void *cls, int ready) | 630 | dir_ready_cb (void *cls, int ready) |
628 | { | 631 | { |
629 | struct RouteDirection *dir = cls; | 632 | struct RouteDirection *dir = cls; |
630 | struct CadetRoute *route = dir->my_route; | 633 | struct CadetRoute *route = dir->my_route; |
631 | struct RouteDirection *odir; | 634 | struct RouteDirection *odir; |
632 | 635 | ||
633 | if (GNUNET_YES == ready) | 636 | if (GNUNET_YES == ready) |
637 | { | ||
638 | struct GNUNET_MQ_Envelope *env; | ||
639 | |||
640 | dir->is_ready = GNUNET_YES; | ||
641 | if (NULL != (env = dir->env_head)) | ||
634 | { | 642 | { |
635 | struct GNUNET_MQ_Envelope *env; | 643 | GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); |
636 | 644 | cur_buffers--; | |
637 | dir->is_ready = GNUNET_YES; | 645 | GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); |
638 | if (NULL != (env = dir->env_head)) | 646 | lower_rung (dir); |
639 | { | 647 | dir->is_ready = GNUNET_NO; |
640 | GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env); | 648 | GCP_send (dir->mqm, env); |
641 | cur_buffers--; | ||
642 | GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO); | ||
643 | lower_rung(dir); | ||
644 | dir->is_ready = GNUNET_NO; | ||
645 | GCP_send(dir->mqm, env); | ||
646 | } | ||
647 | return; | ||
648 | } | 649 | } |
650 | return; | ||
651 | } | ||
649 | odir = (dir == &route->next) ? &route->prev : &route->next; | 652 | odir = (dir == &route->next) ? &route->prev : &route->next; |
650 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); | 653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); |
651 | send_broken(&route->next, &route->cid, GCP_get_id(odir->hop), &my_full_id); | 654 | send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id); |
652 | destroy_route(route); | 655 | destroy_route (route); |
653 | } | 656 | } |
654 | 657 | ||
655 | 658 | ||
@@ -661,16 +664,16 @@ dir_ready_cb(void *cls, int ready) | |||
661 | * @param hop next hop on in the @a dir | 664 | * @param hop next hop on in the @a dir |
662 | */ | 665 | */ |
663 | static void | 666 | static void |
664 | dir_init(struct RouteDirection *dir, | 667 | dir_init (struct RouteDirection *dir, |
665 | struct CadetRoute *route, | 668 | struct CadetRoute *route, |
666 | struct CadetPeer *hop) | 669 | struct CadetPeer *hop) |
667 | { | 670 | { |
668 | dir->hop = hop; | 671 | dir->hop = hop; |
669 | dir->my_route = route; | 672 | dir->my_route = route; |
670 | dir->mqm = GCP_request_mq(hop, &dir_ready_cb, dir); | 673 | dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir); |
671 | GNUNET_CONTAINER_DLL_insert(rung_head->rd_head, rung_head->rd_tail, dir); | 674 | GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir); |
672 | dir->rung = rung_head; | 675 | dir->rung = rung_head; |
673 | GNUNET_assert(GNUNET_YES == dir->is_ready); | 676 | GNUNET_assert (GNUNET_YES == dir->is_ready); |
674 | } | 677 | } |
675 | 678 | ||
676 | 679 | ||
@@ -685,7 +688,7 @@ dir_init(struct RouteDirection *dir, | |||
685 | * or NULL. | 688 | * or NULL. |
686 | */ | 689 | */ |
687 | static void | 690 | static void |
688 | send_broken_without_mqm( | 691 | send_broken_without_mqm ( |
689 | struct CadetPeer *target, | 692 | struct CadetPeer *target, |
690 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 693 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
691 | const struct GNUNET_PeerIdentity *failure_at) | 694 | const struct GNUNET_PeerIdentity *failure_at) |
@@ -693,12 +696,12 @@ send_broken_without_mqm( | |||
693 | struct GNUNET_MQ_Envelope *env; | 696 | struct GNUNET_MQ_Envelope *env; |
694 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; | 697 | struct GNUNET_CADET_ConnectionBrokenMessage *bm; |
695 | 698 | ||
696 | env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 699 | env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
697 | bm->cid = *cid; | 700 | bm->cid = *cid; |
698 | bm->peer1 = my_full_id; | 701 | bm->peer1 = my_full_id; |
699 | if (NULL != failure_at) | 702 | if (NULL != failure_at) |
700 | bm->peer2 = *failure_at; | 703 | bm->peer2 = *failure_at; |
701 | GCP_send_ooo(target, env); | 704 | GCP_send_ooo (target, env); |
702 | } | 705 | } |
703 | 706 | ||
704 | 707 | ||
@@ -709,193 +712,194 @@ send_broken_without_mqm( | |||
709 | * @param msg Message itself. | 712 | * @param msg Message itself. |
710 | */ | 713 | */ |
711 | static void | 714 | static void |
712 | handle_connection_create( | 715 | handle_connection_create ( |
713 | void *cls, | 716 | void *cls, |
714 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | 717 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) |
715 | { | 718 | { |
716 | struct CadetPeer *sender = cls; | 719 | struct CadetPeer *sender = cls; |
717 | struct CadetPeer *next; | 720 | struct CadetPeer *next; |
718 | const struct GNUNET_PeerIdentity *pids = | 721 | const struct GNUNET_PeerIdentity *pids = |
719 | (const struct GNUNET_PeerIdentity *)&msg[1]; | 722 | (const struct GNUNET_PeerIdentity *) &msg[1]; |
720 | struct CadetRoute *route; | 723 | struct CadetRoute *route; |
721 | uint16_t size = ntohs(msg->header.size) - sizeof(*msg); | 724 | uint16_t size = ntohs (msg->header.size) - sizeof(*msg); |
722 | unsigned int path_length; | 725 | unsigned int path_length; |
723 | unsigned int off; | 726 | unsigned int off; |
724 | 727 | ||
725 | path_length = size / sizeof(struct GNUNET_PeerIdentity); | 728 | path_length = size / sizeof(struct GNUNET_PeerIdentity); |
726 | if (0 == path_length) | 729 | if (0 == path_length) |
727 | { | 730 | { |
728 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 731 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
729 | "Dropping CADET_CONNECTION_CREATE with empty path\n"); | 732 | "Dropping CADET_CONNECTION_CREATE with empty path\n"); |
730 | GNUNET_break_op(0); | 733 | GNUNET_break_op (0); |
731 | return; | 734 | return; |
732 | } | 735 | } |
733 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 736 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
734 | "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n", | 737 | "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n", |
735 | GCP_2s(sender), | 738 | GCP_2s (sender), |
736 | GNUNET_sh2s(&msg->cid.connection_of_tunnel), | 739 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), |
737 | path_length); | 740 | path_length); |
738 | /* Check for loops */ | 741 | /* Check for loops */ |
739 | { | 742 | { |
740 | struct GNUNET_CONTAINER_MultiPeerMap *map; | 743 | struct GNUNET_CONTAINER_MultiPeerMap *map; |
741 | 744 | ||
742 | map = GNUNET_CONTAINER_multipeermap_create(path_length * 2, GNUNET_YES); | 745 | map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES); |
743 | GNUNET_assert(NULL != map); | 746 | GNUNET_assert (NULL != map); |
744 | for (unsigned int i = 0; i < path_length; i++) | 747 | for (unsigned int i = 0; i < path_length; i++) |
748 | { | ||
749 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
750 | "CADET_CONNECTION_CREATE has peer %s at offset %u\n", | ||
751 | GNUNET_i2s (&pids[i]), | ||
752 | i); | ||
753 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put ( | ||
754 | map, | ||
755 | &pids[i], | ||
756 | NULL, | ||
757 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
745 | { | 758 | { |
746 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 759 | /* bogus request */ |
747 | "CADET_CONNECTION_CREATE has peer %s at offset %u\n", | 760 | GNUNET_CONTAINER_multipeermap_destroy (map); |
748 | GNUNET_i2s(&pids[i]), | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
749 | i); | 762 | "Dropping CADET_CONNECTION_CREATE with cyclic path\n"); |
750 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put( | 763 | GNUNET_break_op (0); |
751 | map, | 764 | return; |
752 | &pids[i], | ||
753 | NULL, | ||
754 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
755 | { | ||
756 | /* bogus request */ | ||
757 | GNUNET_CONTAINER_multipeermap_destroy(map); | ||
758 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
759 | "Dropping CADET_CONNECTION_CREATE with cyclic path\n"); | ||
760 | GNUNET_break_op(0); | ||
761 | return; | ||
762 | } | ||
763 | } | 765 | } |
764 | GNUNET_CONTAINER_multipeermap_destroy(map); | 766 | } |
767 | GNUNET_CONTAINER_multipeermap_destroy (map); | ||
765 | } | 768 | } |
766 | /* Initiator is at offset 0, find us */ | 769 | /* Initiator is at offset 0, find us */ |
767 | for (off = 1; off < path_length; off++) | 770 | for (off = 1; off < path_length; off++) |
768 | if (0 == GNUNET_memcmp(&my_full_id, &pids[off])) | 771 | if (0 == GNUNET_memcmp (&my_full_id, &pids[off])) |
769 | break; | 772 | break; |
770 | if (off == path_length) | 773 | if (off == path_length) |
771 | { | 774 | { |
772 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 775 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
773 | "Dropping CADET_CONNECTION_CREATE without us in the path\n"); | 776 | "Dropping CADET_CONNECTION_CREATE without us in the path\n"); |
774 | GNUNET_break_op(0); | 777 | GNUNET_break_op (0); |
775 | return; | 778 | return; |
776 | } | 779 | } |
777 | /* Check previous hop */ | 780 | /* Check previous hop */ |
778 | if (sender != GCP_get(&pids[off - 1], GNUNET_NO)) | 781 | if (sender != GCP_get (&pids[off - 1], GNUNET_NO)) |
779 | { | 782 | { |
780 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 783 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
781 | "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); | 784 | "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); |
782 | GNUNET_break_op(0); | 785 | GNUNET_break_op (0); |
783 | return; | 786 | return; |
784 | } | 787 | } |
785 | if (NULL != (route = get_route(&msg->cid))) | 788 | if (NULL != (route = get_route (&msg->cid))) |
786 | { | 789 | { |
787 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ | 790 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ |
788 | 791 | ||
789 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 792 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
790 | "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n", | 793 | "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n", |
791 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | 794 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
792 | route_message(sender, | 795 | route_message (sender, |
793 | &msg->cid, | 796 | &msg->cid, |
794 | &msg->header, | 797 | &msg->header, |
795 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | | 798 | GNUNET_MQ_PRIO_CRITICAL_CONTROL |
796 | GNUNET_MQ_PREF_LOW_LATENCY); | 799 | | GNUNET_MQ_PREF_LOW_LATENCY); |
797 | return; | 800 | return; |
798 | } | 801 | } |
799 | if (off == path_length - 1) | 802 | if (off == path_length - 1) |
803 | { | ||
804 | /* We are the destination, create connection */ | ||
805 | struct CadetConnection *cc; | ||
806 | struct CadetPeerPath *path; | ||
807 | struct CadetPeer *origin; | ||
808 | |||
809 | cc = GCC_lookup (&msg->cid); | ||
810 | if (NULL != cc) | ||
800 | { | 811 | { |
801 | /* We are the destination, create connection */ | 812 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
802 | struct CadetConnection *cc; | 813 | "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n", |
803 | struct CadetPeerPath *path; | 814 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
804 | struct CadetPeer *origin; | 815 | GCC_handle_duplicate_create (cc); |
805 | |||
806 | cc = GCC_lookup(&msg->cid); | ||
807 | if (NULL != cc) | ||
808 | { | ||
809 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
810 | "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n", | ||
811 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
812 | GCC_handle_duplicate_create(cc); | ||
813 | return; | ||
814 | } | ||
815 | |||
816 | origin = GCP_get(&pids[0], GNUNET_YES); | ||
817 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
818 | "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", | ||
819 | GCP_2s(origin), | ||
820 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
821 | path = GCPP_get_path_from_route(path_length - 1, pids); | ||
822 | if (GNUNET_OK != | ||
823 | GCT_add_inbound_connection(GCP_get_tunnel(origin, GNUNET_YES), | ||
824 | &msg->cid, | ||
825 | path)) | ||
826 | { | ||
827 | /* Send back BROKEN: duplicate connection on the same path, | ||
828 | we will use the other one. */ | ||
829 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
830 | "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n", | ||
831 | GCP_2s(sender), | ||
832 | GNUNET_sh2s(&msg->cid.connection_of_tunnel), | ||
833 | GCPP_2s(path)); | ||
834 | send_broken_without_mqm(sender, &msg->cid, NULL); | ||
835 | return; | ||
836 | } | ||
837 | return; | ||
838 | } | ||
839 | /* We are merely a hop on the way, check if we can support the route */ | ||
840 | next = GCP_get(&pids[off + 1], GNUNET_NO); | ||
841 | if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection(next))) | ||
842 | { | ||
843 | /* unworkable, send back BROKEN notification */ | ||
844 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
845 | "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n", | ||
846 | GCP_2s(sender), | ||
847 | GNUNET_sh2s(&msg->cid.connection_of_tunnel), | ||
848 | GNUNET_i2s(&pids[off + 1]), | ||
849 | off + 1); | ||
850 | send_broken_without_mqm(sender, &msg->cid, &pids[off + 1]); | ||
851 | return; | 816 | return; |
852 | } | 817 | } |
853 | if (max_routes <= GNUNET_CONTAINER_multishortmap_size(routes)) | 818 | |
819 | origin = GCP_get (&pids[0], GNUNET_YES); | ||
820 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
821 | "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", | ||
822 | GCP_2s (origin), | ||
823 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
824 | path = GCPP_get_path_from_route (path_length - 1, pids); | ||
825 | if (GNUNET_OK != | ||
826 | GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES), | ||
827 | &msg->cid, | ||
828 | path)) | ||
854 | { | 829 | { |
855 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 830 | /* Send back BROKEN: duplicate connection on the same path, |
856 | "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", | 831 | we will use the other one. */ |
857 | GCP_2s(sender), | 832 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
858 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | 833 | "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n", |
859 | send_broken_without_mqm(sender, &msg->cid, &pids[off - 1]); | 834 | GCP_2s (sender), |
835 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), | ||
836 | GCPP_2s (path)); | ||
837 | send_broken_without_mqm (sender, &msg->cid, NULL); | ||
860 | return; | 838 | return; |
861 | } | 839 | } |
840 | return; | ||
841 | } | ||
842 | /* We are merely a hop on the way, check if we can support the route */ | ||
843 | next = GCP_get (&pids[off + 1], GNUNET_NO); | ||
844 | if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next))) | ||
845 | { | ||
846 | /* unworkable, send back BROKEN notification */ | ||
847 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
848 | "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n", | ||
849 | GCP_2s (sender), | ||
850 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), | ||
851 | GNUNET_i2s (&pids[off + 1]), | ||
852 | off + 1); | ||
853 | send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]); | ||
854 | return; | ||
855 | } | ||
856 | if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) | ||
857 | { | ||
858 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
859 | "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", | ||
860 | GCP_2s (sender), | ||
861 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
862 | send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]); | ||
863 | return; | ||
864 | } | ||
862 | 865 | ||
863 | /* Workable route, create routing entry */ | 866 | /* Workable route, create routing entry */ |
864 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 867 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
865 | "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n", | 868 | "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n", |
866 | GCP_2s(sender), | 869 | GCP_2s (sender), |
867 | GNUNET_sh2s(&msg->cid.connection_of_tunnel), | 870 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), |
868 | GNUNET_i2s(&pids[off + 1]), | 871 | GNUNET_i2s (&pids[off + 1]), |
869 | off + 1); | 872 | off + 1); |
870 | route = GNUNET_new(struct CadetRoute); | 873 | route = GNUNET_new (struct CadetRoute); |
871 | route->cid = msg->cid; | 874 | route->cid = msg->cid; |
872 | route->last_use = GNUNET_TIME_absolute_get(); | 875 | route->last_use = GNUNET_TIME_absolute_get (); |
873 | dir_init(&route->prev, route, sender); | 876 | dir_init (&route->prev, route, sender); |
874 | dir_init(&route->next, route, next); | 877 | dir_init (&route->next, route, next); |
875 | GNUNET_assert(GNUNET_OK == | 878 | GNUNET_assert (GNUNET_OK == |
876 | GNUNET_CONTAINER_multishortmap_put( | 879 | GNUNET_CONTAINER_multishortmap_put ( |
877 | routes, | 880 | routes, |
878 | &route->cid.connection_of_tunnel, | 881 | &route->cid.connection_of_tunnel, |
879 | route, | 882 | route, |
880 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 883 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
881 | GNUNET_STATISTICS_set(stats, | 884 | GNUNET_STATISTICS_set (stats, |
882 | "# routes", | 885 | "# routes", |
883 | GNUNET_CONTAINER_multishortmap_size(routes), | 886 | GNUNET_CONTAINER_multishortmap_size (routes), |
884 | GNUNET_NO); | 887 | GNUNET_NO); |
885 | route->hn = GNUNET_CONTAINER_heap_insert(route_heap, | 888 | route->hn = GNUNET_CONTAINER_heap_insert (route_heap, |
886 | route, | 889 | route, |
887 | route->last_use.abs_value_us); | 890 | route->last_use.abs_value_us); |
888 | if (NULL == timeout_task) | 891 | if (NULL == timeout_task) |
889 | timeout_task = | 892 | timeout_task = |
890 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(keepalive_period, | 893 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( |
891 | 3), | 894 | keepalive_period, |
892 | &timeout_cb, | 895 | 3), |
893 | NULL); | 896 | &timeout_cb, |
897 | NULL); | ||
894 | /* also pass CREATE message along to next hop */ | 898 | /* also pass CREATE message along to next hop */ |
895 | route_message(sender, | 899 | route_message (sender, |
896 | &msg->cid, | 900 | &msg->cid, |
897 | &msg->header, | 901 | &msg->header, |
898 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); | 902 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
899 | } | 903 | } |
900 | 904 | ||
901 | 905 | ||
@@ -906,7 +910,7 @@ handle_connection_create( | |||
906 | * @param msg Message itself. | 910 | * @param msg Message itself. |
907 | */ | 911 | */ |
908 | static void | 912 | static void |
909 | handle_connection_create_ack( | 913 | handle_connection_create_ack ( |
910 | void *cls, | 914 | void *cls, |
911 | const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) | 915 | const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) |
912 | { | 916 | { |
@@ -914,31 +918,31 @@ handle_connection_create_ack( | |||
914 | struct CadetConnection *cc; | 918 | struct CadetConnection *cc; |
915 | 919 | ||
916 | /* First, check if ACK belongs to a connection that ends here. */ | 920 | /* First, check if ACK belongs to a connection that ends here. */ |
917 | cc = GCC_lookup(&msg->cid); | 921 | cc = GCC_lookup (&msg->cid); |
918 | if (NULL != cc) | 922 | if (NULL != cc) |
923 | { | ||
924 | /* verify ACK came from the right direction */ | ||
925 | unsigned int len; | ||
926 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
927 | |||
928 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
919 | { | 929 | { |
920 | /* verify ACK came from the right direction */ | 930 | /* received ACK from unexpected direction, ignore! */ |
921 | unsigned int len; | 931 | GNUNET_break_op (0); |
922 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
923 | |||
924 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
925 | { | ||
926 | /* received ACK from unexpected direction, ignore! */ | ||
927 | GNUNET_break_op(0); | ||
928 | return; | ||
929 | } | ||
930 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
931 | "Received CONNECTION_CREATE_ACK for connection %s.\n", | ||
932 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
933 | GCC_handle_connection_create_ack(cc); | ||
934 | return; | 932 | return; |
935 | } | 933 | } |
934 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
935 | "Received CONNECTION_CREATE_ACK for connection %s.\n", | ||
936 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
937 | GCC_handle_connection_create_ack (cc); | ||
938 | return; | ||
939 | } | ||
936 | 940 | ||
937 | /* We're just an intermediary peer, route the message along its path */ | 941 | /* We're just an intermediary peer, route the message along its path */ |
938 | route_message(peer, | 942 | route_message (peer, |
939 | &msg->cid, | 943 | &msg->cid, |
940 | &msg->header, | 944 | &msg->header, |
941 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); | 945 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
942 | } | 946 | } |
943 | 947 | ||
944 | 948 | ||
@@ -950,7 +954,7 @@ handle_connection_create_ack( | |||
950 | * @deprecated duplicate logic with #handle_destroy(); dedup! | 954 | * @deprecated duplicate logic with #handle_destroy(); dedup! |
951 | */ | 955 | */ |
952 | static void | 956 | static void |
953 | handle_connection_broken( | 957 | handle_connection_broken ( |
954 | void *cls, | 958 | void *cls, |
955 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) | 959 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) |
956 | { | 960 | { |
@@ -959,36 +963,36 @@ handle_connection_broken( | |||
959 | struct CadetRoute *route; | 963 | struct CadetRoute *route; |
960 | 964 | ||
961 | /* First, check if message belongs to a connection that ends here. */ | 965 | /* First, check if message belongs to a connection that ends here. */ |
962 | cc = GCC_lookup(&msg->cid); | 966 | cc = GCC_lookup (&msg->cid); |
963 | if (NULL != cc) | 967 | if (NULL != cc) |
968 | { | ||
969 | /* verify message came from the right direction */ | ||
970 | unsigned int len; | ||
971 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
972 | |||
973 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
964 | { | 974 | { |
965 | /* verify message came from the right direction */ | 975 | /* received message from unexpected direction, ignore! */ |
966 | unsigned int len; | 976 | GNUNET_break_op (0); |
967 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
968 | |||
969 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
970 | { | ||
971 | /* received message from unexpected direction, ignore! */ | ||
972 | GNUNET_break_op(0); | ||
973 | return; | ||
974 | } | ||
975 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
976 | "Received CONNECTION_BROKEN for connection %s. Destroying it.\n", | ||
977 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
978 | GCC_destroy_without_core(cc); | ||
979 | |||
980 | /* FIXME: also destroy the path up to the specified link! */ | ||
981 | return; | 977 | return; |
982 | } | 978 | } |
979 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
980 | "Received CONNECTION_BROKEN for connection %s. Destroying it.\n", | ||
981 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
982 | GCC_destroy_without_core (cc); | ||
983 | |||
984 | /* FIXME: also destroy the path up to the specified link! */ | ||
985 | return; | ||
986 | } | ||
983 | 987 | ||
984 | /* We're just an intermediary peer, route the message along its path */ | 988 | /* We're just an intermediary peer, route the message along its path */ |
985 | route_message(peer, | 989 | route_message (peer, |
986 | &msg->cid, | 990 | &msg->cid, |
987 | &msg->header, | 991 | &msg->header, |
988 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 992 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
989 | route = get_route(&msg->cid); | 993 | route = get_route (&msg->cid); |
990 | if (NULL != route) | 994 | if (NULL != route) |
991 | destroy_route(route); | 995 | destroy_route (route); |
992 | /* FIXME: also destroy paths we MAY have up to the specified link! */ | 996 | /* FIXME: also destroy paths we MAY have up to the specified link! */ |
993 | } | 997 | } |
994 | 998 | ||
@@ -1000,7 +1004,7 @@ handle_connection_broken( | |||
1000 | * @param msg Message itself. | 1004 | * @param msg Message itself. |
1001 | */ | 1005 | */ |
1002 | static void | 1006 | static void |
1003 | handle_connection_destroy( | 1007 | handle_connection_destroy ( |
1004 | void *cls, | 1008 | void *cls, |
1005 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) | 1009 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) |
1006 | { | 1010 | { |
@@ -1009,38 +1013,38 @@ handle_connection_destroy( | |||
1009 | struct CadetRoute *route; | 1013 | struct CadetRoute *route; |
1010 | 1014 | ||
1011 | /* First, check if message belongs to a connection that ends here. */ | 1015 | /* First, check if message belongs to a connection that ends here. */ |
1012 | cc = GCC_lookup(&msg->cid); | 1016 | cc = GCC_lookup (&msg->cid); |
1013 | if (NULL != cc) | 1017 | if (NULL != cc) |
1018 | { | ||
1019 | /* verify message came from the right direction */ | ||
1020 | unsigned int len; | ||
1021 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
1022 | |||
1023 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
1014 | { | 1024 | { |
1015 | /* verify message came from the right direction */ | 1025 | /* received message from unexpected direction, ignore! */ |
1016 | unsigned int len; | 1026 | GNUNET_break_op (0); |
1017 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
1018 | |||
1019 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
1020 | { | ||
1021 | /* received message from unexpected direction, ignore! */ | ||
1022 | GNUNET_break_op(0); | ||
1023 | return; | ||
1024 | } | ||
1025 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1026 | "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n", | ||
1027 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | ||
1028 | |||
1029 | GCC_destroy_without_core(cc); | ||
1030 | return; | 1027 | return; |
1031 | } | 1028 | } |
1029 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1030 | "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n", | ||
1031 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
1032 | |||
1033 | GCC_destroy_without_core (cc); | ||
1034 | return; | ||
1035 | } | ||
1032 | 1036 | ||
1033 | /* We're just an intermediary peer, route the message along its path */ | 1037 | /* We're just an intermediary peer, route the message along its path */ |
1034 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1038 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1035 | "Received CONNECTION_DESTROY for connection %s. Destroying route.\n", | 1039 | "Received CONNECTION_DESTROY for connection %s. Destroying route.\n", |
1036 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | 1040 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
1037 | route_message(peer, | 1041 | route_message (peer, |
1038 | &msg->cid, | 1042 | &msg->cid, |
1039 | &msg->header, | 1043 | &msg->header, |
1040 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 1044 | GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
1041 | route = get_route(&msg->cid); | 1045 | route = get_route (&msg->cid); |
1042 | if (NULL != route) | 1046 | if (NULL != route) |
1043 | destroy_route(route); | 1047 | destroy_route (route); |
1044 | } | 1048 | } |
1045 | 1049 | ||
1046 | 1050 | ||
@@ -1051,41 +1055,41 @@ handle_connection_destroy( | |||
1051 | * @param msg Message itself. | 1055 | * @param msg Message itself. |
1052 | */ | 1056 | */ |
1053 | static void | 1057 | static void |
1054 | handle_tunnel_kx(void *cls, | 1058 | handle_tunnel_kx (void *cls, |
1055 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) | 1059 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) |
1056 | { | 1060 | { |
1057 | struct CadetPeer *peer = cls; | 1061 | struct CadetPeer *peer = cls; |
1058 | struct CadetConnection *cc; | 1062 | struct CadetConnection *cc; |
1059 | 1063 | ||
1060 | /* First, check if message belongs to a connection that ends here. */ | 1064 | /* First, check if message belongs to a connection that ends here. */ |
1061 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1065 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1062 | "Routing KX with ephemeral %s on CID %s\n", | 1066 | "Routing KX with ephemeral %s on CID %s\n", |
1063 | GNUNET_e2s(&msg->ephemeral_key), | 1067 | GNUNET_e2s (&msg->ephemeral_key), |
1064 | GNUNET_sh2s(&msg->cid.connection_of_tunnel)); | 1068 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
1065 | 1069 | ||
1066 | 1070 | ||
1067 | cc = GCC_lookup(&msg->cid); | 1071 | cc = GCC_lookup (&msg->cid); |
1068 | if (NULL != cc) | 1072 | if (NULL != cc) |
1073 | { | ||
1074 | /* verify message came from the right direction */ | ||
1075 | unsigned int len; | ||
1076 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
1077 | |||
1078 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
1069 | { | 1079 | { |
1070 | /* verify message came from the right direction */ | 1080 | /* received message from unexpected direction, ignore! */ |
1071 | unsigned int len; | 1081 | GNUNET_break_op (0); |
1072 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
1073 | |||
1074 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
1075 | { | ||
1076 | /* received message from unexpected direction, ignore! */ | ||
1077 | GNUNET_break_op(0); | ||
1078 | return; | ||
1079 | } | ||
1080 | GCC_handle_kx(cc, msg); | ||
1081 | return; | 1082 | return; |
1082 | } | 1083 | } |
1084 | GCC_handle_kx (cc, msg); | ||
1085 | return; | ||
1086 | } | ||
1083 | 1087 | ||
1084 | /* We're just an intermediary peer, route the message along its path */ | 1088 | /* We're just an intermediary peer, route the message along its path */ |
1085 | route_message(peer, | 1089 | route_message (peer, |
1086 | &msg->cid, | 1090 | &msg->cid, |
1087 | &msg->header, | 1091 | &msg->header, |
1088 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); | 1092 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
1089 | } | 1093 | } |
1090 | 1094 | ||
1091 | 1095 | ||
@@ -1096,7 +1100,7 @@ handle_tunnel_kx(void *cls, | |||
1096 | * @param msg Message itself. | 1100 | * @param msg Message itself. |
1097 | */ | 1101 | */ |
1098 | static void | 1102 | static void |
1099 | handle_tunnel_kx_auth( | 1103 | handle_tunnel_kx_auth ( |
1100 | void *cls, | 1104 | void *cls, |
1101 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) | 1105 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) |
1102 | { | 1106 | { |
@@ -1104,28 +1108,28 @@ handle_tunnel_kx_auth( | |||
1104 | struct CadetConnection *cc; | 1108 | struct CadetConnection *cc; |
1105 | 1109 | ||
1106 | /* First, check if message belongs to a connection that ends here. */ | 1110 | /* First, check if message belongs to a connection that ends here. */ |
1107 | cc = GCC_lookup(&msg->kx.cid); | 1111 | cc = GCC_lookup (&msg->kx.cid); |
1108 | if (NULL != cc) | 1112 | if (NULL != cc) |
1113 | { | ||
1114 | /* verify message came from the right direction */ | ||
1115 | unsigned int len; | ||
1116 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
1117 | |||
1118 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
1109 | { | 1119 | { |
1110 | /* verify message came from the right direction */ | 1120 | /* received message from unexpected direction, ignore! */ |
1111 | unsigned int len; | 1121 | GNUNET_break_op (0); |
1112 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
1113 | |||
1114 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
1115 | { | ||
1116 | /* received message from unexpected direction, ignore! */ | ||
1117 | GNUNET_break_op(0); | ||
1118 | return; | ||
1119 | } | ||
1120 | GCC_handle_kx_auth(cc, msg); | ||
1121 | return; | 1122 | return; |
1122 | } | 1123 | } |
1124 | GCC_handle_kx_auth (cc, msg); | ||
1125 | return; | ||
1126 | } | ||
1123 | 1127 | ||
1124 | /* We're just an intermediary peer, route the message along its path */ | 1128 | /* We're just an intermediary peer, route the message along its path */ |
1125 | route_message(peer, | 1129 | route_message (peer, |
1126 | &msg->kx.cid, | 1130 | &msg->kx.cid, |
1127 | &msg->kx.header, | 1131 | &msg->kx.header, |
1128 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); | 1132 | GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); |
1129 | } | 1133 | } |
1130 | 1134 | ||
1131 | 1135 | ||
@@ -1138,8 +1142,8 @@ handle_tunnel_kx_auth( | |||
1138 | * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. | 1142 | * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. |
1139 | */ | 1143 | */ |
1140 | static int | 1144 | static int |
1141 | check_tunnel_encrypted(void *cls, | 1145 | check_tunnel_encrypted (void *cls, |
1142 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) | 1146 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) |
1143 | { | 1147 | { |
1144 | return GNUNET_YES; | 1148 | return GNUNET_YES; |
1145 | } | 1149 | } |
@@ -1152,31 +1156,31 @@ check_tunnel_encrypted(void *cls, | |||
1152 | * @param msg Message itself. | 1156 | * @param msg Message itself. |
1153 | */ | 1157 | */ |
1154 | static void | 1158 | static void |
1155 | handle_tunnel_encrypted(void *cls, | 1159 | handle_tunnel_encrypted (void *cls, |
1156 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) | 1160 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) |
1157 | { | 1161 | { |
1158 | struct CadetPeer *peer = cls; | 1162 | struct CadetPeer *peer = cls; |
1159 | struct CadetConnection *cc; | 1163 | struct CadetConnection *cc; |
1160 | 1164 | ||
1161 | /* First, check if message belongs to a connection that ends here. */ | 1165 | /* First, check if message belongs to a connection that ends here. */ |
1162 | cc = GCC_lookup(&msg->cid); | 1166 | cc = GCC_lookup (&msg->cid); |
1163 | if (NULL != cc) | 1167 | if (NULL != cc) |
1168 | { | ||
1169 | /* verify message came from the right direction */ | ||
1170 | unsigned int len; | ||
1171 | struct CadetPeerPath *path = GCC_get_path (cc, &len); | ||
1172 | |||
1173 | if (peer != GCPP_get_peer_at_offset (path, 0)) | ||
1164 | { | 1174 | { |
1165 | /* verify message came from the right direction */ | 1175 | /* received message from unexpected direction, ignore! */ |
1166 | unsigned int len; | 1176 | GNUNET_break_op (0); |
1167 | struct CadetPeerPath *path = GCC_get_path(cc, &len); | ||
1168 | |||
1169 | if (peer != GCPP_get_peer_at_offset(path, 0)) | ||
1170 | { | ||
1171 | /* received message from unexpected direction, ignore! */ | ||
1172 | GNUNET_break_op(0); | ||
1173 | return; | ||
1174 | } | ||
1175 | GCC_handle_encrypted(cc, msg); | ||
1176 | return; | 1177 | return; |
1177 | } | 1178 | } |
1179 | GCC_handle_encrypted (cc, msg); | ||
1180 | return; | ||
1181 | } | ||
1178 | /* We're just an intermediary peer, route the message along its path */ | 1182 | /* We're just an intermediary peer, route the message along its path */ |
1179 | route_message(peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); | 1183 | route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); |
1180 | } | 1184 | } |
1181 | 1185 | ||
1182 | 1186 | ||
@@ -1193,14 +1197,14 @@ handle_tunnel_encrypted(void *cls, | |||
1193 | * @param my_identity ID of this peer, NULL if we failed | 1197 | * @param my_identity ID of this peer, NULL if we failed |
1194 | */ | 1198 | */ |
1195 | static void | 1199 | static void |
1196 | core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) | 1200 | core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
1197 | { | 1201 | { |
1198 | if (NULL == my_identity) | 1202 | if (NULL == my_identity) |
1199 | { | 1203 | { |
1200 | GNUNET_break(0); | 1204 | GNUNET_break (0); |
1201 | return; | 1205 | return; |
1202 | } | 1206 | } |
1203 | GNUNET_break(0 == GNUNET_memcmp(my_identity, &my_full_id)); | 1207 | GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id)); |
1204 | } | 1208 | } |
1205 | 1209 | ||
1206 | 1210 | ||
@@ -1211,17 +1215,17 @@ core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity) | |||
1211 | * @param peer peer identity this notification is about | 1215 | * @param peer peer identity this notification is about |
1212 | */ | 1216 | */ |
1213 | static void * | 1217 | static void * |
1214 | core_connect_cb(void *cls, | 1218 | core_connect_cb (void *cls, |
1215 | const struct GNUNET_PeerIdentity *peer, | 1219 | const struct GNUNET_PeerIdentity *peer, |
1216 | struct GNUNET_MQ_Handle *mq) | 1220 | struct GNUNET_MQ_Handle *mq) |
1217 | { | 1221 | { |
1218 | struct CadetPeer *cp; | 1222 | struct CadetPeer *cp; |
1219 | 1223 | ||
1220 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1224 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1221 | "CORE connection to peer %s was established.\n", | 1225 | "CORE connection to peer %s was established.\n", |
1222 | GNUNET_i2s(peer)); | 1226 | GNUNET_i2s (peer)); |
1223 | cp = GCP_get(peer, GNUNET_YES); | 1227 | cp = GCP_get (peer, GNUNET_YES); |
1224 | GCP_set_mq(cp, mq); | 1228 | GCP_set_mq (cp, mq); |
1225 | return cp; | 1229 | return cp; |
1226 | } | 1230 | } |
1227 | 1231 | ||
@@ -1233,16 +1237,16 @@ core_connect_cb(void *cls, | |||
1233 | * @param peer peer identity this notification is about | 1237 | * @param peer peer identity this notification is about |
1234 | */ | 1238 | */ |
1235 | static void | 1239 | static void |
1236 | core_disconnect_cb(void *cls, | 1240 | core_disconnect_cb (void *cls, |
1237 | const struct GNUNET_PeerIdentity *peer, | 1241 | const struct GNUNET_PeerIdentity *peer, |
1238 | void *peer_cls) | 1242 | void *peer_cls) |
1239 | { | 1243 | { |
1240 | struct CadetPeer *cp = peer_cls; | 1244 | struct CadetPeer *cp = peer_cls; |
1241 | 1245 | ||
1242 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1246 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1243 | "CORE connection to peer %s went down.\n", | 1247 | "CORE connection to peer %s went down.\n", |
1244 | GNUNET_i2s(peer)); | 1248 | GNUNET_i2s (peer)); |
1245 | GCP_set_mq(cp, NULL); | 1249 | GCP_set_mq (cp, NULL); |
1246 | } | 1250 | } |
1247 | 1251 | ||
1248 | 1252 | ||
@@ -1252,57 +1256,57 @@ core_disconnect_cb(void *cls, | |||
1252 | * @param c Configuration. | 1256 | * @param c Configuration. |
1253 | */ | 1257 | */ |
1254 | void | 1258 | void |
1255 | GCO_init(const struct GNUNET_CONFIGURATION_Handle *c) | 1259 | GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) |
1256 | { | 1260 | { |
1257 | struct GNUNET_MQ_MessageHandler handlers[] = | 1261 | struct GNUNET_MQ_MessageHandler handlers[] = |
1258 | { GNUNET_MQ_hd_var_size(connection_create, | 1262 | { GNUNET_MQ_hd_var_size (connection_create, |
1259 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, | 1263 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, |
1260 | struct GNUNET_CADET_ConnectionCreateMessage, | 1264 | struct GNUNET_CADET_ConnectionCreateMessage, |
1261 | NULL), | 1265 | NULL), |
1262 | GNUNET_MQ_hd_fixed_size(connection_create_ack, | 1266 | GNUNET_MQ_hd_fixed_size (connection_create_ack, |
1263 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, | 1267 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, |
1264 | struct GNUNET_CADET_ConnectionCreateAckMessage, | 1268 | struct GNUNET_CADET_ConnectionCreateAckMessage, |
1265 | NULL), | 1269 | NULL), |
1266 | GNUNET_MQ_hd_fixed_size(connection_broken, | 1270 | GNUNET_MQ_hd_fixed_size (connection_broken, |
1267 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, | 1271 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, |
1268 | struct GNUNET_CADET_ConnectionBrokenMessage, | 1272 | struct GNUNET_CADET_ConnectionBrokenMessage, |
1269 | NULL), | 1273 | NULL), |
1270 | GNUNET_MQ_hd_fixed_size(connection_destroy, | 1274 | GNUNET_MQ_hd_fixed_size (connection_destroy, |
1271 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, | 1275 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, |
1272 | struct GNUNET_CADET_ConnectionDestroyMessage, | 1276 | struct GNUNET_CADET_ConnectionDestroyMessage, |
1273 | NULL), | 1277 | NULL), |
1274 | GNUNET_MQ_hd_fixed_size(tunnel_kx, | 1278 | GNUNET_MQ_hd_fixed_size (tunnel_kx, |
1275 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, | 1279 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, |
1276 | struct GNUNET_CADET_TunnelKeyExchangeMessage, | 1280 | struct GNUNET_CADET_TunnelKeyExchangeMessage, |
1277 | NULL), | 1281 | NULL), |
1278 | GNUNET_MQ_hd_fixed_size(tunnel_kx_auth, | 1282 | GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, |
1279 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, | 1283 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, |
1280 | struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, | 1284 | struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, |
1281 | NULL), | 1285 | NULL), |
1282 | GNUNET_MQ_hd_var_size(tunnel_encrypted, | 1286 | GNUNET_MQ_hd_var_size (tunnel_encrypted, |
1283 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, | 1287 | GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, |
1284 | struct GNUNET_CADET_TunnelEncryptedMessage, | 1288 | struct GNUNET_CADET_TunnelEncryptedMessage, |
1285 | NULL), | 1289 | NULL), |
1286 | GNUNET_MQ_handler_end() }; | 1290 | GNUNET_MQ_handler_end () }; |
1287 | 1291 | ||
1288 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c, | 1292 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, |
1289 | "CADET", | 1293 | "CADET", |
1290 | "MAX_ROUTES", | 1294 | "MAX_ROUTES", |
1291 | &max_routes)) | 1295 | &max_routes)) |
1292 | max_routes = 5000; | 1296 | max_routes = 5000; |
1293 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(c, | 1297 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, |
1294 | "CADET", | 1298 | "CADET", |
1295 | "MAX_MSGS_QUEUE", | 1299 | "MAX_MSGS_QUEUE", |
1296 | &max_buffers)) | 1300 | &max_buffers)) |
1297 | max_buffers = 10000; | 1301 | max_buffers = 10000; |
1298 | routes = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_NO); | 1302 | routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO); |
1299 | route_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1303 | route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1300 | core = GNUNET_CORE_connect(c, | 1304 | core = GNUNET_CORE_connect (c, |
1301 | NULL, | 1305 | NULL, |
1302 | &core_init_cb, | 1306 | &core_init_cb, |
1303 | &core_connect_cb, | 1307 | &core_connect_cb, |
1304 | &core_disconnect_cb, | 1308 | &core_disconnect_cb, |
1305 | handlers); | 1309 | handlers); |
1306 | } | 1310 | } |
1307 | 1311 | ||
1308 | 1312 | ||
@@ -1310,23 +1314,23 @@ GCO_init(const struct GNUNET_CONFIGURATION_Handle *c) | |||
1310 | * Shut down the CORE subsystem. | 1314 | * Shut down the CORE subsystem. |
1311 | */ | 1315 | */ |
1312 | void | 1316 | void |
1313 | GCO_shutdown() | 1317 | GCO_shutdown () |
1314 | { | 1318 | { |
1315 | if (NULL != core) | 1319 | if (NULL != core) |
1316 | { | 1320 | { |
1317 | GNUNET_CORE_disconnect(core); | 1321 | GNUNET_CORE_disconnect (core); |
1318 | core = NULL; | 1322 | core = NULL; |
1319 | } | 1323 | } |
1320 | GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(routes)); | 1324 | GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (routes)); |
1321 | GNUNET_CONTAINER_multishortmap_destroy(routes); | 1325 | GNUNET_CONTAINER_multishortmap_destroy (routes); |
1322 | routes = NULL; | 1326 | routes = NULL; |
1323 | GNUNET_CONTAINER_heap_destroy(route_heap); | 1327 | GNUNET_CONTAINER_heap_destroy (route_heap); |
1324 | route_heap = NULL; | 1328 | route_heap = NULL; |
1325 | if (NULL != timeout_task) | 1329 | if (NULL != timeout_task) |
1326 | { | 1330 | { |
1327 | GNUNET_SCHEDULER_cancel(timeout_task); | 1331 | GNUNET_SCHEDULER_cancel (timeout_task); |
1328 | timeout_task = NULL; | 1332 | timeout_task = NULL; |
1329 | } | 1333 | } |
1330 | } | 1334 | } |
1331 | 1335 | ||
1332 | /* end of gnunet-cadet-service_core.c */ | 1336 | /* end of gnunet-cadet-service_core.c */ |