diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_connection.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 760 |
1 files changed, 380 insertions, 380 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 8849e563f..e3c1a4124 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file cadet/gnunet-service-cadet_connection.c | 22 | * @file cadet/gnunet-service-cadet_connection.c |
@@ -35,7 +35,7 @@ | |||
35 | #include "cadet_protocol.h" | 35 | #include "cadet_protocol.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__) | 38 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-con", __VA_ARGS__) |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
@@ -43,14 +43,13 @@ | |||
43 | * TODO: replace by 2 RTT if/once we have connection-level RTT data! | 43 | * TODO: replace by 2 RTT if/once we have connection-level RTT data! |
44 | */ | 44 | */ |
45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ | 45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ |
46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) | 46 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) |
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
50 | * All the states a connection can be in. | 50 | * All the states a connection can be in. |
51 | */ | 51 | */ |
52 | enum CadetConnectionState | 52 | enum CadetConnectionState { |
53 | { | ||
54 | /** | 53 | /** |
55 | * Uninitialized status, we have not yet even gotten the message queue. | 54 | * Uninitialized status, we have not yet even gotten the message queue. |
56 | */ | 55 | */ |
@@ -76,16 +75,13 @@ enum CadetConnectionState | |||
76 | * Connection confirmed, ready to carry traffic. | 75 | * Connection confirmed, ready to carry traffic. |
77 | */ | 76 | */ |
78 | CADET_CONNECTION_READY | 77 | CADET_CONNECTION_READY |
79 | |||
80 | }; | 78 | }; |
81 | 79 | ||
82 | 80 | ||
83 | /** | 81 | /** |
84 | * Low-level connection to a destination. | 82 | * Low-level connection to a destination. |
85 | */ | 83 | */ |
86 | struct CadetConnection | 84 | struct CadetConnection { |
87 | { | ||
88 | |||
89 | /** | 85 | /** |
90 | * ID of the connection. | 86 | * ID of the connection. |
91 | */ | 87 | */ |
@@ -185,10 +181,10 @@ struct CadetConnection | |||
185 | * @return NULL if connection was not found | 181 | * @return NULL if connection was not found |
186 | */ | 182 | */ |
187 | struct CadetConnection * | 183 | struct CadetConnection * |
188 | GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 184 | GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
189 | { | 185 | { |
190 | return GNUNET_CONTAINER_multishortmap_get (connections, | 186 | return GNUNET_CONTAINER_multishortmap_get(connections, |
191 | &cid->connection_of_tunnel); | 187 | &cid->connection_of_tunnel); |
192 | } | 188 | } |
193 | 189 | ||
194 | 190 | ||
@@ -201,9 +197,9 @@ GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | |||
201 | * @param new_mqm_ready new `mqm_ready` state for @a cc | 197 | * @param new_mqm_ready new `mqm_ready` state for @a cc |
202 | */ | 198 | */ |
203 | static void | 199 | static void |
204 | update_state (struct CadetConnection *cc, | 200 | update_state(struct CadetConnection *cc, |
205 | enum CadetConnectionState new_state, | 201 | enum CadetConnectionState new_state, |
206 | int new_mqm_ready) | 202 | int new_mqm_ready) |
207 | { | 203 | { |
208 | int old_ready; | 204 | int old_ready; |
209 | int new_ready; | 205 | int new_ready; |
@@ -217,7 +213,7 @@ update_state (struct CadetConnection *cc, | |||
217 | cc->state = new_state; | 213 | cc->state = new_state; |
218 | cc->mqm_ready = new_mqm_ready; | 214 | cc->mqm_ready = new_mqm_ready; |
219 | if (old_ready != new_ready) | 215 | if (old_ready != new_ready) |
220 | cc->ready_cb (cc->ready_cb_cls, new_ready); | 216 | cc->ready_cb(cc->ready_cb_cls, new_ready); |
221 | } | 217 | } |
222 | 218 | ||
223 | 219 | ||
@@ -228,34 +224,34 @@ update_state (struct CadetConnection *cc, | |||
228 | * @param cc connection to destroy | 224 | * @param cc connection to destroy |
229 | */ | 225 | */ |
230 | static void | 226 | static void |
231 | GCC_destroy (struct CadetConnection *cc) | 227 | GCC_destroy(struct CadetConnection *cc) |
232 | { | 228 | { |
233 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc)); | 229 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s(cc)); |
234 | if (NULL != cc->mq_man) | 230 | if (NULL != cc->mq_man) |
235 | { | 231 | { |
236 | GCP_request_mq_cancel (cc->mq_man, NULL); | 232 | GCP_request_mq_cancel(cc->mq_man, NULL); |
237 | cc->mq_man = NULL; | 233 | cc->mq_man = NULL; |
238 | } | 234 | } |
239 | if (NULL != cc->task) | 235 | if (NULL != cc->task) |
240 | { | 236 | { |
241 | GNUNET_SCHEDULER_cancel (cc->task); | 237 | GNUNET_SCHEDULER_cancel(cc->task); |
242 | cc->task = NULL; | 238 | cc->task = NULL; |
243 | } | 239 | } |
244 | if (NULL != cc->keepalive_qe) | 240 | if (NULL != cc->keepalive_qe) |
245 | { | 241 | { |
246 | GCT_send_cancel (cc->keepalive_qe); | 242 | GCT_send_cancel(cc->keepalive_qe); |
247 | cc->keepalive_qe = NULL; | 243 | cc->keepalive_qe = NULL; |
248 | } | 244 | } |
249 | GCPP_del_connection (cc->path, cc->off, cc); | 245 | GCPP_del_connection(cc->path, cc->off, cc); |
250 | for (unsigned int i = 0; i < cc->off; i++) | 246 | for (unsigned int i = 0; i < cc->off; i++) |
251 | GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc); | 247 | GCP_remove_connection(GCPP_get_peer_at_offset(cc->path, i), cc); |
252 | GNUNET_assert ( | 248 | GNUNET_assert( |
253 | GNUNET_YES == | 249 | GNUNET_YES == |
254 | GNUNET_CONTAINER_multishortmap_remove (connections, | 250 | GNUNET_CONTAINER_multishortmap_remove(connections, |
255 | &GCC_get_id (cc) | 251 | &GCC_get_id(cc) |
256 | ->connection_of_tunnel, | 252 | ->connection_of_tunnel, |
257 | cc)); | 253 | cc)); |
258 | GNUNET_free (cc); | 254 | GNUNET_free(cc); |
259 | } | 255 | } |
260 | 256 | ||
261 | 257 | ||
@@ -268,14 +264,14 @@ GCC_destroy (struct CadetConnection *cc) | |||
268 | * @param cc connection to destroy | 264 | * @param cc connection to destroy |
269 | */ | 265 | */ |
270 | void | 266 | void |
271 | GCC_destroy_without_core (struct CadetConnection *cc) | 267 | GCC_destroy_without_core(struct CadetConnection *cc) |
272 | { | 268 | { |
273 | if (NULL != cc->ct) | 269 | if (NULL != cc->ct) |
274 | { | 270 | { |
275 | GCT_connection_lost (cc->ct); | 271 | GCT_connection_lost(cc->ct); |
276 | cc->ct = NULL; | 272 | cc->ct = NULL; |
277 | } | 273 | } |
278 | GCC_destroy (cc); | 274 | GCC_destroy(cc); |
279 | } | 275 | } |
280 | 276 | ||
281 | 277 | ||
@@ -287,22 +283,22 @@ GCC_destroy_without_core (struct CadetConnection *cc) | |||
287 | * @param cc connection to destroy | 283 | * @param cc connection to destroy |
288 | */ | 284 | */ |
289 | void | 285 | void |
290 | GCC_destroy_without_tunnel (struct CadetConnection *cc) | 286 | GCC_destroy_without_tunnel(struct CadetConnection *cc) |
291 | { | 287 | { |
292 | cc->ct = NULL; | 288 | cc->ct = NULL; |
293 | if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) | 289 | if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) |
294 | { | 290 | { |
295 | struct GNUNET_MQ_Envelope *env; | 291 | struct GNUNET_MQ_Envelope *env; |
296 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; | 292 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; |
297 | 293 | ||
298 | /* Need to notify next hop that we are down. */ | 294 | /* Need to notify next hop that we are down. */ |
299 | env = | 295 | env = |
300 | GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); | 296 | GNUNET_MQ_msg(destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); |
301 | destroy_msg->cid = cc->cid; | 297 | destroy_msg->cid = cc->cid; |
302 | GCP_request_mq_cancel (cc->mq_man, env); | 298 | GCP_request_mq_cancel(cc->mq_man, env); |
303 | cc->mq_man = NULL; | 299 | cc->mq_man = NULL; |
304 | } | 300 | } |
305 | GCC_destroy (cc); | 301 | GCC_destroy(cc); |
306 | } | 302 | } |
307 | 303 | ||
308 | 304 | ||
@@ -313,7 +309,7 @@ GCC_destroy_without_tunnel (struct CadetConnection *cc) | |||
313 | * @return corresponding entry in the tunnel's connection list | 309 | * @return corresponding entry in the tunnel's connection list |
314 | */ | 310 | */ |
315 | struct CadetTConnection * | 311 | struct CadetTConnection * |
316 | GCC_get_ct (struct CadetConnection *cc) | 312 | GCC_get_ct(struct CadetConnection *cc) |
317 | { | 313 | { |
318 | return cc->ct; | 314 | return cc->ct; |
319 | } | 315 | } |
@@ -326,7 +322,7 @@ GCC_get_ct (struct CadetConnection *cc) | |||
326 | * @return the metrics | 322 | * @return the metrics |
327 | */ | 323 | */ |
328 | const struct CadetConnectionMetrics * | 324 | const struct CadetConnectionMetrics * |
329 | GCC_get_metrics (struct CadetConnection *cc) | 325 | GCC_get_metrics(struct CadetConnection *cc) |
330 | { | 326 | { |
331 | return &cc->metrics; | 327 | return &cc->metrics; |
332 | } | 328 | } |
@@ -339,7 +335,7 @@ GCC_get_metrics (struct CadetConnection *cc) | |||
339 | * @param cls the `struct CadetConnection` to keep alive. | 335 | * @param cls the `struct CadetConnection` to keep alive. |
340 | */ | 336 | */ |
341 | static void | 337 | static void |
342 | send_keepalive (void *cls); | 338 | send_keepalive(void *cls); |
343 | 339 | ||
344 | 340 | ||
345 | /** | 341 | /** |
@@ -351,15 +347,15 @@ send_keepalive (void *cls); | |||
351 | * if transmission failed | 347 | * if transmission failed |
352 | */ | 348 | */ |
353 | static void | 349 | static void |
354 | keepalive_done (void *cls, | 350 | keepalive_done(void *cls, |
355 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 351 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
356 | { | 352 | { |
357 | struct CadetConnection *cc = cls; | 353 | struct CadetConnection *cc = cls; |
358 | 354 | ||
359 | cc->keepalive_qe = NULL; | 355 | cc->keepalive_qe = NULL; |
360 | if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) | 356 | if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) |
361 | cc->task = | 357 | cc->task = |
362 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); | 358 | GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); |
363 | } | 359 | } |
364 | 360 | ||
365 | 361 | ||
@@ -370,31 +366,31 @@ keepalive_done (void *cls, | |||
370 | * @param cls the `struct CadetConnection` to keep alive. | 366 | * @param cls the `struct CadetConnection` to keep alive. |
371 | */ | 367 | */ |
372 | static void | 368 | static void |
373 | send_keepalive (void *cls) | 369 | send_keepalive(void *cls) |
374 | { | 370 | { |
375 | struct CadetConnection *cc = cls; | 371 | struct CadetConnection *cc = cls; |
376 | struct GNUNET_MessageHeader msg; | 372 | struct GNUNET_MessageHeader msg; |
377 | 373 | ||
378 | cc->task = NULL; | 374 | cc->task = NULL; |
379 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) | 375 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate(cc->ct->t)) |
380 | { | 376 | { |
381 | /* Tunnel not yet ready, wait with keepalives... */ | 377 | /* Tunnel not yet ready, wait with keepalives... */ |
382 | cc->task = | 378 | cc->task = |
383 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); | 379 | GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); |
384 | return; | 380 | return; |
385 | } | 381 | } |
386 | GNUNET_assert (NULL != cc->ct); | 382 | GNUNET_assert(NULL != cc->ct); |
387 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 383 | GNUNET_assert(GNUNET_YES == cc->mqm_ready); |
388 | GNUNET_assert (NULL == cc->keepalive_qe); | 384 | GNUNET_assert(NULL == cc->keepalive_qe); |
389 | LOG (GNUNET_ERROR_TYPE_INFO, | 385 | LOG(GNUNET_ERROR_TYPE_INFO, |
390 | "Sending KEEPALIVE on behalf of %s via %s\n", | 386 | "Sending KEEPALIVE on behalf of %s via %s\n", |
391 | GCC_2s (cc), | 387 | GCC_2s(cc), |
392 | GCT_2s (cc->ct->t)); | 388 | GCT_2s(cc->ct->t)); |
393 | GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO); | 389 | GNUNET_STATISTICS_update(stats, "# keepalives sent", 1, GNUNET_NO); |
394 | msg.size = htons (sizeof (msg)); | 390 | msg.size = htons(sizeof(msg)); |
395 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); | 391 | msg.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); |
396 | 392 | ||
397 | cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); | 393 | cc->keepalive_qe = GCT_send(cc->ct->t, &msg, &keepalive_done, cc); |
398 | } | 394 | } |
399 | 395 | ||
400 | 396 | ||
@@ -405,11 +401,11 @@ send_keepalive (void *cls) | |||
405 | * @param cid connection identifier where we expect an ACK | 401 | * @param cid connection identifier where we expect an ACK |
406 | */ | 402 | */ |
407 | void | 403 | void |
408 | GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 404 | GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
409 | { | 405 | { |
410 | struct CadetConnection *cc; | 406 | struct CadetConnection *cc; |
411 | 407 | ||
412 | cc = GCC_lookup (cid); | 408 | cc = GCC_lookup(cid); |
413 | if (NULL == cc) | 409 | if (NULL == cc) |
414 | return; /* whopise, connection alredy down? */ | 410 | return; /* whopise, connection alredy down? */ |
415 | cc->metrics.num_acked_transmissions++; | 411 | cc->metrics.num_acked_transmissions++; |
@@ -425,11 +421,11 @@ GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | |||
425 | * may have gotten back to us via a different connection). | 421 | * may have gotten back to us via a different connection). |
426 | */ | 422 | */ |
427 | void | 423 | void |
428 | GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | 424 | GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
429 | { | 425 | { |
430 | struct CadetConnection *cc; | 426 | struct CadetConnection *cc; |
431 | 427 | ||
432 | cc = GCC_lookup (cid); | 428 | cc = GCC_lookup(cid); |
433 | if (NULL == cc) | 429 | if (NULL == cc) |
434 | return; /* whopise, connection alredy down? */ | 430 | return; /* whopise, connection alredy down? */ |
435 | cc->metrics.num_successes++; | 431 | cc->metrics.num_successes++; |
@@ -445,17 +441,17 @@ GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) | |||
445 | * @param latency the observed latency | 441 | * @param latency the observed latency |
446 | */ | 442 | */ |
447 | void | 443 | void |
448 | GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 444 | GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
449 | struct GNUNET_TIME_Relative latency) | 445 | struct GNUNET_TIME_Relative latency) |
450 | { | 446 | { |
451 | struct CadetConnection *cc; | 447 | struct CadetConnection *cc; |
452 | double weight; | 448 | double weight; |
453 | double result; | 449 | double result; |
454 | 450 | ||
455 | cc = GCC_lookup (cid); | 451 | cc = GCC_lookup(cid); |
456 | if (NULL == cc) | 452 | if (NULL == cc) |
457 | return; /* whopise, connection alredy down? */ | 453 | return; /* whopise, connection alredy down? */ |
458 | GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO); | 454 | GNUNET_STATISTICS_update(stats, "# latencies observed", 1, GNUNET_NO); |
459 | cc->latency_datapoints++; | 455 | cc->latency_datapoints++; |
460 | if (cc->latency_datapoints >= 7) | 456 | if (cc->latency_datapoints >= 7) |
461 | weight = 7.0; | 457 | weight = 7.0; |
@@ -467,7 +463,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
467 | result = (weight * cc->metrics.aged_latency.rel_value_us) + | 463 | result = (weight * cc->metrics.aged_latency.rel_value_us) + |
468 | 1.0 * latency.rel_value_us; | 464 | 1.0 * latency.rel_value_us; |
469 | result /= (weight + 1.0); | 465 | result /= (weight + 1.0); |
470 | cc->metrics.aged_latency.rel_value_us = (uint64_t) result; | 466 | cc->metrics.aged_latency.rel_value_us = (uint64_t)result; |
471 | } | 467 | } |
472 | 468 | ||
473 | 469 | ||
@@ -479,26 +475,26 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
479 | * @param cc the connection that got the ACK. | 475 | * @param cc the connection that got the ACK. |
480 | */ | 476 | */ |
481 | void | 477 | void |
482 | GCC_handle_connection_create_ack (struct CadetConnection *cc) | 478 | GCC_handle_connection_create_ack(struct CadetConnection *cc) |
483 | { | 479 | { |
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 480 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
485 | "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n", | 481 | "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n", |
486 | GCC_2s (cc), | 482 | GCC_2s(cc), |
487 | cc->state, | 483 | cc->state, |
488 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); | 484 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); |
489 | if (CADET_CONNECTION_READY == cc->state) | 485 | if (CADET_CONNECTION_READY == cc->state) |
490 | return; /* Duplicate ACK, ignore */ | 486 | return; /* Duplicate ACK, ignore */ |
491 | if (NULL != cc->task) | 487 | if (NULL != cc->task) |
492 | { | 488 | { |
493 | GNUNET_SCHEDULER_cancel (cc->task); | 489 | GNUNET_SCHEDULER_cancel(cc->task); |
494 | cc->task = NULL; | 490 | cc->task = NULL; |
495 | } | 491 | } |
496 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 492 | cc->metrics.age = GNUNET_TIME_absolute_get(); |
497 | update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready); | 493 | update_state(cc, CADET_CONNECTION_READY, cc->mqm_ready); |
498 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && | 494 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && |
499 | (NULL == cc->task)) | 495 | (NULL == cc->task)) |
500 | cc->task = | 496 | cc->task = |
501 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); | 497 | GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); |
502 | } | 498 | } |
503 | 499 | ||
504 | 500 | ||
@@ -509,24 +505,24 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc) | |||
509 | * @param msg the key exchange message | 505 | * @param msg the key exchange message |
510 | */ | 506 | */ |
511 | void | 507 | void |
512 | GCC_handle_kx (struct CadetConnection *cc, | 508 | GCC_handle_kx(struct CadetConnection *cc, |
513 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) | 509 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) |
514 | { | 510 | { |
515 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 511 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
516 | "Received KX message with ephermal %s on CC %s in state %d\n", | 512 | "Received KX message with ephermal %s on CC %s in state %d\n", |
517 | GNUNET_e2s (&msg->ephemeral_key), | 513 | GNUNET_e2s(&msg->ephemeral_key), |
518 | GNUNET_sh2s (&cc->cid.connection_of_tunnel), | 514 | GNUNET_sh2s(&cc->cid.connection_of_tunnel), |
519 | cc->state); | 515 | cc->state); |
520 | if (CADET_CONNECTION_SENT == cc->state) | 516 | if (CADET_CONNECTION_SENT == cc->state) |
521 | { | 517 | { |
522 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, | 518 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, |
523 | clearly something is working, so pretend we got an ACK. */ | 519 | clearly something is working, so pretend we got an ACK. */ |
524 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 520 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
525 | "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", | 521 | "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", |
526 | GCC_2s (cc)); | 522 | GCC_2s(cc)); |
527 | GCC_handle_connection_create_ack (cc); | 523 | GCC_handle_connection_create_ack(cc); |
528 | } | 524 | } |
529 | GCT_handle_kx (cc->ct, msg); | 525 | GCT_handle_kx(cc->ct, msg); |
530 | } | 526 | } |
531 | 527 | ||
532 | 528 | ||
@@ -537,24 +533,24 @@ GCC_handle_kx (struct CadetConnection *cc, | |||
537 | * @param msg the key exchange message | 533 | * @param msg the key exchange message |
538 | */ | 534 | */ |
539 | void | 535 | void |
540 | GCC_handle_kx_auth (struct CadetConnection *cc, | 536 | GCC_handle_kx_auth(struct CadetConnection *cc, |
541 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) | 537 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) |
542 | { | 538 | { |
543 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 539 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
544 | "Received KX AUTH message with ephermal %s on CC %s in state %d\n", | 540 | "Received KX AUTH message with ephermal %s on CC %s in state %d\n", |
545 | GNUNET_e2s (&msg->kx.ephemeral_key), | 541 | GNUNET_e2s(&msg->kx.ephemeral_key), |
546 | GNUNET_sh2s (&cc->cid.connection_of_tunnel), | 542 | GNUNET_sh2s(&cc->cid.connection_of_tunnel), |
547 | cc->state); | 543 | cc->state); |
548 | if (CADET_CONNECTION_SENT == cc->state) | 544 | if (CADET_CONNECTION_SENT == cc->state) |
549 | { | 545 | { |
550 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, | 546 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, |
551 | clearly something is working, so pretend we got an ACK. */ | 547 | clearly something is working, so pretend we got an ACK. */ |
552 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 548 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
553 | "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", | 549 | "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n", |
554 | GCC_2s (cc)); | 550 | GCC_2s(cc)); |
555 | GCC_handle_connection_create_ack (cc); | 551 | GCC_handle_connection_create_ack(cc); |
556 | } | 552 | } |
557 | GCT_handle_kx_auth (cc->ct, msg); | 553 | GCT_handle_kx_auth(cc->ct, msg); |
558 | } | 554 | } |
559 | 555 | ||
560 | 556 | ||
@@ -565,20 +561,20 @@ GCC_handle_kx_auth (struct CadetConnection *cc, | |||
565 | * @param msg the encrypted message to decrypt | 561 | * @param msg the encrypted message to decrypt |
566 | */ | 562 | */ |
567 | void | 563 | void |
568 | GCC_handle_encrypted (struct CadetConnection *cc, | 564 | GCC_handle_encrypted(struct CadetConnection *cc, |
569 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) | 565 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) |
570 | { | 566 | { |
571 | if (CADET_CONNECTION_SENT == cc->state) | 567 | if (CADET_CONNECTION_SENT == cc->state) |
572 | { | 568 | { |
573 | /* We didn't get the CREATE_ACK, but instead got payload. That's fine, | 569 | /* We didn't get the CREATE_ACK, but instead got payload. That's fine, |
574 | clearly something is working, so pretend we got an ACK. */ | 570 | clearly something is working, so pretend we got an ACK. */ |
575 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 571 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
576 | "Faking connection ACK for %s due to ENCRYPTED payload\n", | 572 | "Faking connection ACK for %s due to ENCRYPTED payload\n", |
577 | GCC_2s (cc)); | 573 | GCC_2s(cc)); |
578 | GCC_handle_connection_create_ack (cc); | 574 | GCC_handle_connection_create_ack(cc); |
579 | } | 575 | } |
580 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); | 576 | cc->metrics.last_use = GNUNET_TIME_absolute_get(); |
581 | GCT_handle_encrypted (cc->ct, msg); | 577 | GCT_handle_encrypted(cc->ct, msg); |
582 | } | 578 | } |
583 | 579 | ||
584 | 580 | ||
@@ -589,7 +585,7 @@ GCC_handle_encrypted (struct CadetConnection *cc, | |||
589 | * @param cls the `struct CadetConnection` to initiate | 585 | * @param cls the `struct CadetConnection` to initiate |
590 | */ | 586 | */ |
591 | static void | 587 | static void |
592 | send_create (void *cls) | 588 | send_create(void *cls) |
593 | { | 589 | { |
594 | struct CadetConnection *cc = cls; | 590 | struct CadetConnection *cc = cls; |
595 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; | 591 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; |
@@ -597,27 +593,27 @@ send_create (void *cls) | |||
597 | struct GNUNET_MQ_Envelope *env; | 593 | struct GNUNET_MQ_Envelope *env; |
598 | 594 | ||
599 | cc->task = NULL; | 595 | cc->task = NULL; |
600 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 596 | GNUNET_assert(GNUNET_YES == cc->mqm_ready); |
601 | env = | 597 | env = |
602 | GNUNET_MQ_msg_extra (create_msg, | 598 | GNUNET_MQ_msg_extra(create_msg, |
603 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), | 599 | (2 + cc->off) * sizeof(struct GNUNET_PeerIdentity), |
604 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 600 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
605 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. | 601 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. |
606 | create_msg->options = 2; | 602 | create_msg->options = 2; |
607 | create_msg->cid = cc->cid; | 603 | create_msg->cid = cc->cid; |
608 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; | 604 | pids = (struct GNUNET_PeerIdentity *)&create_msg[1]; |
609 | pids[0] = my_full_id; | 605 | pids[0] = my_full_id; |
610 | for (unsigned int i = 0; i <= cc->off; i++) | 606 | for (unsigned int i = 0; i <= cc->off; i++) |
611 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i)); | 607 | pids[i + 1] = *GCP_get_id(GCPP_get_peer_at_offset(cc->path, i)); |
612 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 608 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
613 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", | 609 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", |
614 | GCC_2s (cc), | 610 | GCC_2s(cc), |
615 | cc->off + 2); | 611 | cc->off + 2); |
616 | cc->env = env; | 612 | cc->env = env; |
617 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 613 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF(cc->retry_delay); |
618 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 614 | cc->create_at = GNUNET_TIME_relative_to_absolute(cc->retry_delay); |
619 | update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO); | 615 | update_state(cc, CADET_CONNECTION_SENT, GNUNET_NO); |
620 | GCP_send (cc->mq_man, env); | 616 | GCP_send(cc->mq_man, env); |
621 | } | 617 | } |
622 | 618 | ||
623 | 619 | ||
@@ -627,29 +623,29 @@ send_create (void *cls) | |||
627 | * @param cls the `struct CadetConnection` to initiate | 623 | * @param cls the `struct CadetConnection` to initiate |
628 | */ | 624 | */ |
629 | static void | 625 | static void |
630 | send_create_ack (void *cls) | 626 | send_create_ack(void *cls) |
631 | { | 627 | { |
632 | struct CadetConnection *cc = cls; | 628 | struct CadetConnection *cc = cls; |
633 | struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg; | 629 | struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg; |
634 | struct GNUNET_MQ_Envelope *env; | 630 | struct GNUNET_MQ_Envelope *env; |
635 | 631 | ||
636 | cc->task = NULL; | 632 | cc->task = NULL; |
637 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 633 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
638 | "Sending CONNECTION_CREATE_ACK message for %s\n", | 634 | "Sending CONNECTION_CREATE_ACK message for %s\n", |
639 | GCC_2s (cc)); | 635 | GCC_2s(cc)); |
640 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 636 | GNUNET_assert(GNUNET_YES == cc->mqm_ready); |
641 | env = | 637 | env = |
642 | GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); | 638 | GNUNET_MQ_msg(ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); |
643 | ack_msg->cid = cc->cid; | 639 | ack_msg->cid = cc->cid; |
644 | cc->env = env; | 640 | cc->env = env; |
645 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 641 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF(cc->retry_delay); |
646 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 642 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute(cc->retry_delay); |
647 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) | 643 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) |
648 | update_state (cc, CADET_CONNECTION_READY, GNUNET_NO); | 644 | update_state(cc, CADET_CONNECTION_READY, GNUNET_NO); |
649 | if (CADET_CONNECTION_READY == cc->state) | 645 | if (CADET_CONNECTION_READY == cc->state) |
650 | cc->task = | 646 | cc->task = |
651 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); | 647 | GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); |
652 | GCP_send (cc->mq_man, env); | 648 | GCP_send(cc->mq_man, env); |
653 | } | 649 | } |
654 | 650 | ||
655 | 651 | ||
@@ -661,31 +657,31 @@ send_create_ack (void *cls) | |||
661 | * @param cc connection that got the duplicate CREATE | 657 | * @param cc connection that got the duplicate CREATE |
662 | */ | 658 | */ |
663 | void | 659 | void |
664 | GCC_handle_duplicate_create (struct CadetConnection *cc) | 660 | GCC_handle_duplicate_create(struct CadetConnection *cc) |
665 | { | 661 | { |
666 | if (GNUNET_YES == cc->mqm_ready) | 662 | if (GNUNET_YES == cc->mqm_ready) |
667 | { | 663 | { |
668 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 664 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
669 | "Got duplicate CREATE for %s, scheduling another ACK (%s)\n", | 665 | "Got duplicate CREATE for %s, scheduling another ACK (%s)\n", |
670 | GCC_2s (cc), | 666 | GCC_2s(cc), |
671 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); | 667 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); |
672 | /* Revert back to the state of having only received the 'CREATE', | 668 | /* Revert back to the state of having only received the 'CREATE', |
673 | and immediately proceed to send the CREATE_ACK. */ | 669 | and immediately proceed to send the CREATE_ACK. */ |
674 | update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); | 670 | update_state(cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); |
675 | if (NULL != cc->task) | 671 | if (NULL != cc->task) |
676 | GNUNET_SCHEDULER_cancel (cc->task); | 672 | GNUNET_SCHEDULER_cancel(cc->task); |
677 | cc->task = | 673 | cc->task = |
678 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); | 674 | GNUNET_SCHEDULER_add_at(cc->create_ack_at, &send_create_ack, cc); |
679 | } | 675 | } |
680 | else | 676 | else |
681 | { | 677 | { |
682 | /* We are currently sending something else back, which | 678 | /* We are currently sending something else back, which |
683 | can only be an ACK or payload, either of which would | 679 | can only be an ACK or payload, either of which would |
684 | do. So actually no need to do anything. */ | 680 | do. So actually no need to do anything. */ |
685 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 681 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
686 | "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n", | 682 | "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n", |
687 | GCC_2s (cc)); | 683 | GCC_2s(cc)); |
688 | } | 684 | } |
689 | } | 685 | } |
690 | 686 | ||
691 | 687 | ||
@@ -700,63 +696,67 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
700 | * and the last envelope was discarded | 696 | * and the last envelope was discarded |
701 | */ | 697 | */ |
702 | static void | 698 | static void |
703 | manage_first_hop_mq (void *cls, int available) | 699 | manage_first_hop_mq(void *cls, int available) |
704 | { | 700 | { |
705 | struct CadetConnection *cc = cls; | 701 | struct CadetConnection *cc = cls; |
706 | 702 | ||
707 | if (GNUNET_YES != available) | 703 | if (GNUNET_YES != available) |
708 | { | ||
709 | /* Connection is down, for now... */ | ||
710 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc)); | ||
711 | update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO); | ||
712 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; | ||
713 | if (NULL != cc->task) | ||
714 | { | 704 | { |
715 | GNUNET_SCHEDULER_cancel (cc->task); | 705 | /* Connection is down, for now... */ |
716 | cc->task = NULL; | 706 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s(cc)); |
707 | update_state(cc, CADET_CONNECTION_NEW, GNUNET_NO); | ||
708 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; | ||
709 | if (NULL != cc->task) | ||
710 | { | ||
711 | GNUNET_SCHEDULER_cancel(cc->task); | ||
712 | cc->task = NULL; | ||
713 | } | ||
714 | return; | ||
717 | } | 715 | } |
718 | return; | ||
719 | } | ||
720 | 716 | ||
721 | update_state (cc, cc->state, GNUNET_YES); | 717 | update_state(cc, cc->state, GNUNET_YES); |
722 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 718 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
723 | "Core MQ for %s became available in state %d\n", | 719 | "Core MQ for %s became available in state %d\n", |
724 | GCC_2s (cc), | 720 | GCC_2s(cc), |
725 | cc->state); | 721 | cc->state); |
726 | switch (cc->state) | 722 | switch (cc->state) |
727 | { | ||
728 | case CADET_CONNECTION_NEW: | ||
729 | /* Transmit immediately */ | ||
730 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); | ||
731 | break; | ||
732 | case CADET_CONNECTION_SENDING_CREATE: | ||
733 | /* Should not be possible to be called in this state. */ | ||
734 | GNUNET_assert (0); | ||
735 | break; | ||
736 | case CADET_CONNECTION_SENT: | ||
737 | /* Retry a bit later... */ | ||
738 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); | ||
739 | break; | ||
740 | case CADET_CONNECTION_CREATE_RECEIVED: | ||
741 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ | ||
742 | cc->metrics.age = GNUNET_TIME_absolute_get (); | ||
743 | cc->task = | ||
744 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); | ||
745 | break; | ||
746 | case CADET_CONNECTION_READY: | ||
747 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && | ||
748 | (NULL == cc->task)) | ||
749 | { | 723 | { |
750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 724 | case CADET_CONNECTION_NEW: |
751 | "Scheduling keepalive for %s in %s\n", | 725 | /* Transmit immediately */ |
752 | GCC_2s (cc), | 726 | cc->task = GNUNET_SCHEDULER_add_at(cc->create_at, &send_create, cc); |
753 | GNUNET_STRINGS_relative_time_to_string (keepalive_period, | 727 | break; |
754 | GNUNET_YES)); | 728 | |
729 | case CADET_CONNECTION_SENDING_CREATE: | ||
730 | /* Should not be possible to be called in this state. */ | ||
731 | GNUNET_assert(0); | ||
732 | break; | ||
733 | |||
734 | case CADET_CONNECTION_SENT: | ||
735 | /* Retry a bit later... */ | ||
736 | cc->task = GNUNET_SCHEDULER_add_at(cc->create_at, &send_create, cc); | ||
737 | break; | ||
738 | |||
739 | case CADET_CONNECTION_CREATE_RECEIVED: | ||
740 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ | ||
741 | cc->metrics.age = GNUNET_TIME_absolute_get(); | ||
755 | cc->task = | 742 | cc->task = |
756 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); | 743 | GNUNET_SCHEDULER_add_at(cc->create_ack_at, &send_create_ack, cc); |
744 | break; | ||
745 | |||
746 | case CADET_CONNECTION_READY: | ||
747 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && | ||
748 | (NULL == cc->task)) | ||
749 | { | ||
750 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
751 | "Scheduling keepalive for %s in %s\n", | ||
752 | GCC_2s(cc), | ||
753 | GNUNET_STRINGS_relative_time_to_string(keepalive_period, | ||
754 | GNUNET_YES)); | ||
755 | cc->task = | ||
756 | GNUNET_SCHEDULER_add_delayed(keepalive_period, &send_keepalive, cc); | ||
757 | } | ||
758 | break; | ||
757 | } | 759 | } |
758 | break; | ||
759 | } | ||
760 | } | 760 | } |
761 | 761 | ||
762 | 762 | ||
@@ -775,44 +775,44 @@ manage_first_hop_mq (void *cls, int available) | |||
775 | * @return handle to the connection | 775 | * @return handle to the connection |
776 | */ | 776 | */ |
777 | static struct CadetConnection * | 777 | static struct CadetConnection * |
778 | connection_create (struct CadetPeer *destination, | 778 | connection_create(struct CadetPeer *destination, |
779 | struct CadetPeerPath *path, | 779 | struct CadetPeerPath *path, |
780 | unsigned int off, | 780 | unsigned int off, |
781 | struct CadetTConnection *ct, | 781 | struct CadetTConnection *ct, |
782 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 782 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
783 | enum CadetConnectionState init_state, | 783 | enum CadetConnectionState init_state, |
784 | GCC_ReadyCallback ready_cb, | 784 | GCC_ReadyCallback ready_cb, |
785 | void *ready_cb_cls) | 785 | void *ready_cb_cls) |
786 | { | 786 | { |
787 | struct CadetConnection *cc; | 787 | struct CadetConnection *cc; |
788 | struct CadetPeer *first_hop; | 788 | struct CadetPeer *first_hop; |
789 | 789 | ||
790 | cc = GNUNET_new (struct CadetConnection); | 790 | cc = GNUNET_new(struct CadetConnection); |
791 | cc->state = init_state; | 791 | cc->state = init_state; |
792 | cc->ct = ct; | 792 | cc->ct = ct; |
793 | cc->cid = *cid; | 793 | cc->cid = *cid; |
794 | cc->retry_delay = | 794 | cc->retry_delay = |
795 | GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); | 795 | GNUNET_TIME_relative_multiply(INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); |
796 | GNUNET_assert (GNUNET_OK == | 796 | GNUNET_assert(GNUNET_OK == |
797 | GNUNET_CONTAINER_multishortmap_put ( | 797 | GNUNET_CONTAINER_multishortmap_put( |
798 | connections, | 798 | connections, |
799 | &GCC_get_id (cc)->connection_of_tunnel, | 799 | &GCC_get_id(cc)->connection_of_tunnel, |
800 | cc, | 800 | cc, |
801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
802 | cc->ready_cb = ready_cb; | 802 | cc->ready_cb = ready_cb; |
803 | cc->ready_cb_cls = ready_cb_cls; | 803 | cc->ready_cb_cls = ready_cb_cls; |
804 | cc->path = path; | 804 | cc->path = path; |
805 | cc->off = off; | 805 | cc->off = off; |
806 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 806 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
807 | "Creating %s using path %s (offset: %u)\n", | 807 | "Creating %s using path %s (offset: %u)\n", |
808 | GCC_2s (cc), | 808 | GCC_2s(cc), |
809 | GCPP_2s (path), | 809 | GCPP_2s(path), |
810 | off); | 810 | off); |
811 | GCPP_add_connection (path, off, cc); | 811 | GCPP_add_connection(path, off, cc); |
812 | for (unsigned int i = 0; i < off; i++) | 812 | for (unsigned int i = 0; i < off; i++) |
813 | GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc); | 813 | GCP_add_connection(GCPP_get_peer_at_offset(path, i), cc); |
814 | first_hop = GCPP_get_peer_at_offset (path, 0); | 814 | first_hop = GCPP_get_peer_at_offset(path, 0); |
815 | cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc); | 815 | cc->mq_man = GCP_request_mq(first_hop, &manage_first_hop_mq, cc); |
816 | return cc; | 816 | return cc; |
817 | } | 817 | } |
818 | 818 | ||
@@ -831,64 +831,64 @@ connection_create (struct CadetPeer *destination, | |||
831 | * a connection that takes precedence on @a path | 831 | * a connection that takes precedence on @a path |
832 | */ | 832 | */ |
833 | struct CadetConnection * | 833 | struct CadetConnection * |
834 | GCC_create_inbound (struct CadetPeer *destination, | 834 | GCC_create_inbound(struct CadetPeer *destination, |
835 | struct CadetPeerPath *path, | 835 | struct CadetPeerPath *path, |
836 | struct CadetTConnection *ct, | 836 | struct CadetTConnection *ct, |
837 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | 837 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
838 | GCC_ReadyCallback ready_cb, | 838 | GCC_ReadyCallback ready_cb, |
839 | void *ready_cb_cls) | 839 | void *ready_cb_cls) |
840 | { | 840 | { |
841 | struct CadetConnection *cc; | 841 | struct CadetConnection *cc; |
842 | unsigned int off; | 842 | unsigned int off; |
843 | 843 | ||
844 | off = GCPP_find_peer (path, destination); | 844 | off = GCPP_find_peer(path, destination); |
845 | GNUNET_assert (UINT_MAX != off); | 845 | GNUNET_assert(UINT_MAX != off); |
846 | cc = GCPP_get_connection (path, destination, off); | 846 | cc = GCPP_get_connection(path, destination, off); |
847 | if (NULL != cc) | 847 | if (NULL != cc) |
848 | { | ||
849 | int cmp; | ||
850 | |||
851 | cmp = GNUNET_memcmp (cid, &cc->cid); | ||
852 | if (0 == cmp) | ||
853 | { | ||
854 | /* Two peers picked the SAME random connection identifier at the | ||
855 | same time for the same path? Must be malicious. Drop | ||
856 | connection (existing and inbound), even if it is the only | ||
857 | one. */ | ||
858 | GNUNET_break_op (0); | ||
859 | GCT_connection_lost (cc->ct); | ||
860 | GCC_destroy_without_tunnel (cc); | ||
861 | return NULL; | ||
862 | } | ||
863 | if (0 < cmp) | ||
864 | { | 848 | { |
865 | /* drop existing */ | 849 | int cmp; |
866 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 850 | |
867 | "Got two connections on %s, dropping my existing %s\n", | 851 | cmp = GNUNET_memcmp(cid, &cc->cid); |
868 | GCPP_2s (path), | 852 | if (0 == cmp) |
869 | GCC_2s (cc)); | 853 | { |
870 | GCT_connection_lost (cc->ct); | 854 | /* Two peers picked the SAME random connection identifier at the |
871 | GCC_destroy_without_tunnel (cc); | 855 | same time for the same path? Must be malicious. Drop |
856 | connection (existing and inbound), even if it is the only | ||
857 | one. */ | ||
858 | GNUNET_break_op(0); | ||
859 | GCT_connection_lost(cc->ct); | ||
860 | GCC_destroy_without_tunnel(cc); | ||
861 | return NULL; | ||
862 | } | ||
863 | if (0 < cmp) | ||
864 | { | ||
865 | /* drop existing */ | ||
866 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
867 | "Got two connections on %s, dropping my existing %s\n", | ||
868 | GCPP_2s(path), | ||
869 | GCC_2s(cc)); | ||
870 | GCT_connection_lost(cc->ct); | ||
871 | GCC_destroy_without_tunnel(cc); | ||
872 | } | ||
873 | else | ||
874 | { | ||
875 | /* keep existing */ | ||
876 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
877 | "Got two connections on %s, keeping my existing %s\n", | ||
878 | GCPP_2s(path), | ||
879 | GCC_2s(cc)); | ||
880 | return NULL; | ||
881 | } | ||
872 | } | 882 | } |
873 | else | 883 | |
874 | { | 884 | return connection_create(destination, |
875 | /* keep existing */ | 885 | path, |
876 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 886 | off, |
877 | "Got two connections on %s, keeping my existing %s\n", | 887 | ct, |
878 | GCPP_2s (path), | 888 | cid, |
879 | GCC_2s (cc)); | 889 | CADET_CONNECTION_CREATE_RECEIVED, |
880 | return NULL; | 890 | ready_cb, |
881 | } | 891 | ready_cb_cls); |
882 | } | ||
883 | |||
884 | return connection_create (destination, | ||
885 | path, | ||
886 | off, | ||
887 | ct, | ||
888 | cid, | ||
889 | CADET_CONNECTION_CREATE_RECEIVED, | ||
890 | ready_cb, | ||
891 | ready_cb_cls); | ||
892 | } | 892 | } |
893 | 893 | ||
894 | 894 | ||
@@ -905,24 +905,24 @@ GCC_create_inbound (struct CadetPeer *destination, | |||
905 | * @return handle to the connection | 905 | * @return handle to the connection |
906 | */ | 906 | */ |
907 | struct CadetConnection * | 907 | struct CadetConnection * |
908 | GCC_create (struct CadetPeer *destination, | 908 | GCC_create(struct CadetPeer *destination, |
909 | struct CadetPeerPath *path, | 909 | struct CadetPeerPath *path, |
910 | unsigned int off, | 910 | unsigned int off, |
911 | struct CadetTConnection *ct, | 911 | struct CadetTConnection *ct, |
912 | GCC_ReadyCallback ready_cb, | 912 | GCC_ReadyCallback ready_cb, |
913 | void *ready_cb_cls) | 913 | void *ready_cb_cls) |
914 | { | 914 | { |
915 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; | 915 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; |
916 | 916 | ||
917 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid)); | 917 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof(cid)); |
918 | return connection_create (destination, | 918 | return connection_create(destination, |
919 | path, | 919 | path, |
920 | off, | 920 | off, |
921 | ct, | 921 | ct, |
922 | &cid, | 922 | &cid, |
923 | CADET_CONNECTION_NEW, | 923 | CADET_CONNECTION_NEW, |
924 | ready_cb, | 924 | ready_cb, |
925 | ready_cb_cls); | 925 | ready_cb_cls); |
926 | } | 926 | } |
927 | 927 | ||
928 | 928 | ||
@@ -937,21 +937,21 @@ GCC_create (struct CadetPeer *destination, | |||
937 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it | 937 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it |
938 | */ | 938 | */ |
939 | void | 939 | void |
940 | GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) | 940 | GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) |
941 | { | 941 | { |
942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 942 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
943 | "Scheduling message for transmission on %s\n", | 943 | "Scheduling message for transmission on %s\n", |
944 | GCC_2s (cc)); | 944 | GCC_2s(cc)); |
945 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 945 | GNUNET_assert(GNUNET_YES == cc->mqm_ready); |
946 | GNUNET_assert (CADET_CONNECTION_READY == cc->state); | 946 | GNUNET_assert(CADET_CONNECTION_READY == cc->state); |
947 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); | 947 | cc->metrics.last_use = GNUNET_TIME_absolute_get(); |
948 | cc->mqm_ready = GNUNET_NO; | 948 | cc->mqm_ready = GNUNET_NO; |
949 | if (NULL != cc->task) | 949 | if (NULL != cc->task) |
950 | { | 950 | { |
951 | GNUNET_SCHEDULER_cancel (cc->task); | 951 | GNUNET_SCHEDULER_cancel(cc->task); |
952 | cc->task = NULL; | 952 | cc->task = NULL; |
953 | } | 953 | } |
954 | GCP_send (cc->mq_man, env); | 954 | GCP_send(cc->mq_man, env); |
955 | } | 955 | } |
956 | 956 | ||
957 | 957 | ||
@@ -963,7 +963,7 @@ GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) | |||
963 | * @return path to @a cc | 963 | * @return path to @a cc |
964 | */ | 964 | */ |
965 | struct CadetPeerPath * | 965 | struct CadetPeerPath * |
966 | GCC_get_path (struct CadetConnection *cc, unsigned int *off) | 966 | GCC_get_path(struct CadetConnection *cc, unsigned int *off) |
967 | { | 967 | { |
968 | *off = cc->off; | 968 | *off = cc->off; |
969 | return cc->path; | 969 | return cc->path; |
@@ -977,7 +977,7 @@ GCC_get_path (struct CadetConnection *cc, unsigned int *off) | |||
977 | * @return unique number of the connection | 977 | * @return unique number of the connection |
978 | */ | 978 | */ |
979 | const struct GNUNET_CADET_ConnectionTunnelIdentifier * | 979 | const struct GNUNET_CADET_ConnectionTunnelIdentifier * |
980 | GCC_get_id (struct CadetConnection *cc) | 980 | GCC_get_id(struct CadetConnection *cc) |
981 | { | 981 | { |
982 | return &cc->cid; | 982 | return &cc->cid; |
983 | } | 983 | } |
@@ -989,7 +989,7 @@ GCC_get_id (struct CadetConnection *cc) | |||
989 | * @param cc Connection. | 989 | * @param cc Connection. |
990 | */ | 990 | */ |
991 | const char * | 991 | const char * |
992 | GCC_2s (const struct CadetConnection *cc) | 992 | GCC_2s(const struct CadetConnection *cc) |
993 | { | 993 | { |
994 | static char buf[128]; | 994 | static char buf[128]; |
995 | 995 | ||
@@ -997,24 +997,24 @@ GCC_2s (const struct CadetConnection *cc) | |||
997 | return "Connection(NULL)"; | 997 | return "Connection(NULL)"; |
998 | 998 | ||
999 | if (NULL != cc->ct) | 999 | if (NULL != cc->ct) |
1000 | { | 1000 | { |
1001 | GNUNET_snprintf (buf, | 1001 | GNUNET_snprintf(buf, |
1002 | sizeof (buf), | 1002 | sizeof(buf), |
1003 | "Connection %s (%s)", | 1003 | "Connection %s (%s)", |
1004 | GNUNET_sh2s (&cc->cid.connection_of_tunnel), | 1004 | GNUNET_sh2s(&cc->cid.connection_of_tunnel), |
1005 | GCT_2s (cc->ct->t)); | 1005 | GCT_2s(cc->ct->t)); |
1006 | return buf; | 1006 | return buf; |
1007 | } | 1007 | } |
1008 | GNUNET_snprintf (buf, | 1008 | GNUNET_snprintf(buf, |
1009 | sizeof (buf), | 1009 | sizeof(buf), |
1010 | "Connection %s", | 1010 | "Connection %s", |
1011 | GNUNET_sh2s (&cc->cid.connection_of_tunnel)); | 1011 | GNUNET_sh2s(&cc->cid.connection_of_tunnel)); |
1012 | return buf; | 1012 | return buf; |
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | 1015 | ||
1016 | #define LOG2(level, ...) \ | 1016 | #define LOG2(level, ...) \ |
1017 | GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__) | 1017 | GNUNET_log_from_nocheck(level, "cadet-con", __VA_ARGS__) |
1018 | 1018 | ||
1019 | 1019 | ||
1020 | /** | 1020 | /** |
@@ -1024,30 +1024,30 @@ GCC_2s (const struct CadetConnection *cc) | |||
1024 | * @param level Debug level to use. | 1024 | * @param level Debug level to use. |
1025 | */ | 1025 | */ |
1026 | void | 1026 | void |
1027 | GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level) | 1027 | GCC_debug(struct CadetConnection *cc, enum GNUNET_ErrorType level) |
1028 | { | 1028 | { |
1029 | #if ! defined(GNUNET_CULL_LOGGING) | 1029 | #if !defined(GNUNET_CULL_LOGGING) |
1030 | int do_log; | 1030 | int do_log; |
1031 | 1031 | ||
1032 | do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), | 1032 | do_log = GNUNET_get_log_call_status(level & (~GNUNET_ERROR_TYPE_BULK), |
1033 | "cadet-con", | 1033 | "cadet-con", |
1034 | __FILE__, | 1034 | __FILE__, |
1035 | __FUNCTION__, | 1035 | __FUNCTION__, |
1036 | __LINE__); | 1036 | __LINE__); |
1037 | if (0 == do_log) | 1037 | if (0 == do_log) |
1038 | return; | 1038 | return; |
1039 | if (NULL == cc) | 1039 | if (NULL == cc) |
1040 | { | 1040 | { |
1041 | LOG2 (level, "Connection (NULL)\n"); | 1041 | LOG2(level, "Connection (NULL)\n"); |
1042 | return; | 1042 | return; |
1043 | } | 1043 | } |
1044 | LOG2 (level, | 1044 | LOG2(level, |
1045 | "%s to %s via path %s in state %d is %s\n", | 1045 | "%s to %s via path %s in state %d is %s\n", |
1046 | GCC_2s (cc), | 1046 | GCC_2s(cc), |
1047 | GCP_2s (cc->destination), | 1047 | GCP_2s(cc->destination), |
1048 | GCPP_2s (cc->path), | 1048 | GCPP_2s(cc->path), |
1049 | cc->state, | 1049 | cc->state, |
1050 | (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy"); | 1050 | (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy"); |
1051 | #endif | 1051 | #endif |
1052 | } | 1052 | } |
1053 | 1053 | ||