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