diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_connection.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 269 |
1 files changed, 101 insertions, 168 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 7214dad97..8849e563f 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -35,14 +35,15 @@ | |||
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 | /** |
42 | * How long do we wait initially before retransmitting the KX? | 42 | * How long do we wait initially before retransmitting the KX? |
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 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) | 45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ |
46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) | ||
46 | 47 | ||
47 | 48 | ||
48 | /** | 49 | /** |
@@ -174,7 +175,6 @@ struct CadetConnection | |||
174 | * Are we ready to transmit via @e mq_man right now? | 175 | * Are we ready to transmit via @e mq_man right now? |
175 | */ | 176 | */ |
176 | int mqm_ready; | 177 | int mqm_ready; |
177 | |||
178 | }; | 178 | }; |
179 | 179 | ||
180 | 180 | ||
@@ -208,18 +208,16 @@ update_state (struct CadetConnection *cc, | |||
208 | int old_ready; | 208 | int old_ready; |
209 | int new_ready; | 209 | int new_ready; |
210 | 210 | ||
211 | if ( (new_state == cc->state) && | 211 | if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) |
212 | (new_mqm_ready == cc->mqm_ready) ) | ||
213 | return; /* no change, nothing to do */ | 212 | return; /* no change, nothing to do */ |
214 | old_ready = ( (CADET_CONNECTION_READY == cc->state) && | 213 | old_ready = |
215 | (GNUNET_YES == cc->mqm_ready) ); | 214 | ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready)); |
216 | new_ready = ( (CADET_CONNECTION_READY == new_state) && | 215 | new_ready = |
217 | (GNUNET_YES == new_mqm_ready) ); | 216 | ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); |
218 | cc->state = new_state; | 217 | cc->state = new_state; |
219 | cc->mqm_ready = new_mqm_ready; | 218 | cc->mqm_ready = new_mqm_ready; |
220 | if (old_ready != new_ready) | 219 | if (old_ready != new_ready) |
221 | cc->ready_cb (cc->ready_cb_cls, | 220 | cc->ready_cb (cc->ready_cb_cls, new_ready); |
222 | new_ready); | ||
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
@@ -232,13 +230,10 @@ update_state (struct CadetConnection *cc, | |||
232 | static void | 230 | static void |
233 | GCC_destroy (struct CadetConnection *cc) | 231 | GCC_destroy (struct CadetConnection *cc) |
234 | { | 232 | { |
235 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 233 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc)); |
236 | "Destroying %s\n", | ||
237 | GCC_2s (cc)); | ||
238 | if (NULL != cc->mq_man) | 234 | if (NULL != cc->mq_man) |
239 | { | 235 | { |
240 | GCP_request_mq_cancel (cc->mq_man, | 236 | GCP_request_mq_cancel (cc->mq_man, NULL); |
241 | NULL); | ||
242 | cc->mq_man = NULL; | 237 | cc->mq_man = NULL; |
243 | } | 238 | } |
244 | if (NULL != cc->task) | 239 | if (NULL != cc->task) |
@@ -251,22 +246,19 @@ GCC_destroy (struct CadetConnection *cc) | |||
251 | GCT_send_cancel (cc->keepalive_qe); | 246 | GCT_send_cancel (cc->keepalive_qe); |
252 | cc->keepalive_qe = NULL; | 247 | cc->keepalive_qe = NULL; |
253 | } | 248 | } |
254 | GCPP_del_connection (cc->path, | 249 | GCPP_del_connection (cc->path, cc->off, cc); |
255 | cc->off, | 250 | for (unsigned int i = 0; i < cc->off; i++) |
256 | cc); | 251 | GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc); |
257 | for (unsigned int i=0;i<cc->off;i++) | 252 | GNUNET_assert ( |
258 | GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, | 253 | GNUNET_YES == |
259 | i), | 254 | GNUNET_CONTAINER_multishortmap_remove (connections, |
260 | cc); | 255 | &GCC_get_id (cc) |
261 | GNUNET_assert (GNUNET_YES == | 256 | ->connection_of_tunnel, |
262 | GNUNET_CONTAINER_multishortmap_remove (connections, | 257 | cc)); |
263 | &GCC_get_id (cc)->connection_of_tunnel, | ||
264 | cc)); | ||
265 | GNUNET_free (cc); | 258 | GNUNET_free (cc); |
266 | } | 259 | } |
267 | 260 | ||
268 | 261 | ||
269 | |||
270 | /** | 262 | /** |
271 | * Destroy a connection, called when the CORE layer is already done | 263 | * Destroy a connection, called when the CORE layer is already done |
272 | * (i.e. has received a BROKEN message), but if we still have to | 264 | * (i.e. has received a BROKEN message), but if we still have to |
@@ -298,18 +290,16 @@ void | |||
298 | GCC_destroy_without_tunnel (struct CadetConnection *cc) | 290 | GCC_destroy_without_tunnel (struct CadetConnection *cc) |
299 | { | 291 | { |
300 | cc->ct = NULL; | 292 | cc->ct = NULL; |
301 | if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) && | 293 | if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) |
302 | (NULL != cc->mq_man) ) | ||
303 | { | 294 | { |
304 | struct GNUNET_MQ_Envelope *env; | 295 | struct GNUNET_MQ_Envelope *env; |
305 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; | 296 | struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; |
306 | 297 | ||
307 | /* Need to notify next hop that we are down. */ | 298 | /* Need to notify next hop that we are down. */ |
308 | env = GNUNET_MQ_msg (destroy_msg, | 299 | env = |
309 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); | 300 | GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); |
310 | destroy_msg->cid = cc->cid; | 301 | destroy_msg->cid = cc->cid; |
311 | GCP_request_mq_cancel (cc->mq_man, | 302 | GCP_request_mq_cancel (cc->mq_man, env); |
312 | env); | ||
313 | cc->mq_man = NULL; | 303 | cc->mq_man = NULL; |
314 | } | 304 | } |
315 | GCC_destroy (cc); | 305 | GCC_destroy (cc); |
@@ -367,11 +357,9 @@ keepalive_done (void *cls, | |||
367 | struct CadetConnection *cc = cls; | 357 | struct CadetConnection *cc = cls; |
368 | 358 | ||
369 | cc->keepalive_qe = NULL; | 359 | cc->keepalive_qe = NULL; |
370 | if ( (GNUNET_YES == cc->mqm_ready) && | 360 | if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) |
371 | (NULL == cc->task) ) | 361 | cc->task = |
372 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 362 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
373 | &send_keepalive, | ||
374 | cc); | ||
375 | } | 363 | } |
376 | 364 | ||
377 | 365 | ||
@@ -391,9 +379,8 @@ send_keepalive (void *cls) | |||
391 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) | 379 | if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) |
392 | { | 380 | { |
393 | /* Tunnel not yet ready, wait with keepalives... */ | 381 | /* Tunnel not yet ready, wait with keepalives... */ |
394 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 382 | cc->task = |
395 | &send_keepalive, | 383 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
396 | cc); | ||
397 | return; | 384 | return; |
398 | } | 385 | } |
399 | GNUNET_assert (NULL != cc->ct); | 386 | GNUNET_assert (NULL != cc->ct); |
@@ -403,18 +390,11 @@ send_keepalive (void *cls) | |||
403 | "Sending KEEPALIVE on behalf of %s via %s\n", | 390 | "Sending KEEPALIVE on behalf of %s via %s\n", |
404 | GCC_2s (cc), | 391 | GCC_2s (cc), |
405 | GCT_2s (cc->ct->t)); | 392 | GCT_2s (cc->ct->t)); |
406 | GNUNET_STATISTICS_update (stats, | 393 | GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO); |
407 | "# keepalives sent", | ||
408 | 1, | ||
409 | GNUNET_NO); | ||
410 | msg.size = htons (sizeof (msg)); | 394 | msg.size = htons (sizeof (msg)); |
411 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); | 395 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); |
412 | 396 | ||
413 | cc->keepalive_qe | 397 | cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); |
414 | = GCT_send (cc->ct->t, | ||
415 | &msg, | ||
416 | &keepalive_done, | ||
417 | cc); | ||
418 | } | 398 | } |
419 | 399 | ||
420 | 400 | ||
@@ -475,10 +455,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
475 | cc = GCC_lookup (cid); | 455 | cc = GCC_lookup (cid); |
476 | if (NULL == cc) | 456 | if (NULL == cc) |
477 | return; /* whopise, connection alredy down? */ | 457 | return; /* whopise, connection alredy down? */ |
478 | GNUNET_STATISTICS_update (stats, | 458 | GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO); |
479 | "# latencies observed", | ||
480 | 1, | ||
481 | GNUNET_NO); | ||
482 | cc->latency_datapoints++; | 459 | cc->latency_datapoints++; |
483 | if (cc->latency_datapoints >= 7) | 460 | if (cc->latency_datapoints >= 7) |
484 | weight = 7.0; | 461 | weight = 7.0; |
@@ -487,7 +464,8 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
487 | /* Compute weighted average, giving at MOST weight 7 to the | 464 | /* Compute weighted average, giving at MOST weight 7 to the |
488 | existing values, or less if that value is based on fewer than 7 | 465 | existing values, or less if that value is based on fewer than 7 |
489 | measurements. */ | 466 | measurements. */ |
490 | result = (weight * cc->metrics.aged_latency.rel_value_us) + 1.0 * latency.rel_value_us; | 467 | result = (weight * cc->metrics.aged_latency.rel_value_us) + |
468 | 1.0 * latency.rel_value_us; | ||
491 | result /= (weight + 1.0); | 469 | result /= (weight + 1.0); |
492 | cc->metrics.aged_latency.rel_value_us = (uint64_t) result; | 470 | cc->metrics.aged_latency.rel_value_us = (uint64_t) result; |
493 | } | 471 | } |
@@ -516,15 +494,11 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc) | |||
516 | cc->task = NULL; | 494 | cc->task = NULL; |
517 | } | 495 | } |
518 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 496 | cc->metrics.age = GNUNET_TIME_absolute_get (); |
519 | update_state (cc, | 497 | update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready); |
520 | CADET_CONNECTION_READY, | 498 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && |
521 | cc->mqm_ready); | 499 | (NULL == cc->task)) |
522 | if ( (NULL == cc->keepalive_qe) && | 500 | cc->task = |
523 | (GNUNET_YES == cc->mqm_ready) && | 501 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
524 | (NULL == cc->task) ) | ||
525 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | ||
526 | &send_keepalive, | ||
527 | cc); | ||
528 | } | 502 | } |
529 | 503 | ||
530 | 504 | ||
@@ -552,8 +526,7 @@ GCC_handle_kx (struct CadetConnection *cc, | |||
552 | GCC_2s (cc)); | 526 | GCC_2s (cc)); |
553 | GCC_handle_connection_create_ack (cc); | 527 | GCC_handle_connection_create_ack (cc); |
554 | } | 528 | } |
555 | GCT_handle_kx (cc->ct, | 529 | GCT_handle_kx (cc->ct, msg); |
556 | msg); | ||
557 | } | 530 | } |
558 | 531 | ||
559 | 532 | ||
@@ -581,8 +554,7 @@ GCC_handle_kx_auth (struct CadetConnection *cc, | |||
581 | GCC_2s (cc)); | 554 | GCC_2s (cc)); |
582 | GCC_handle_connection_create_ack (cc); | 555 | GCC_handle_connection_create_ack (cc); |
583 | } | 556 | } |
584 | GCT_handle_kx_auth (cc->ct, | 557 | GCT_handle_kx_auth (cc->ct, msg); |
585 | msg); | ||
586 | } | 558 | } |
587 | 559 | ||
588 | 560 | ||
@@ -606,8 +578,7 @@ GCC_handle_encrypted (struct CadetConnection *cc, | |||
606 | GCC_handle_connection_create_ack (cc); | 578 | GCC_handle_connection_create_ack (cc); |
607 | } | 579 | } |
608 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); | 580 | cc->metrics.last_use = GNUNET_TIME_absolute_get (); |
609 | GCT_handle_encrypted (cc->ct, | 581 | GCT_handle_encrypted (cc->ct, msg); |
610 | msg); | ||
611 | } | 582 | } |
612 | 583 | ||
613 | 584 | ||
@@ -627,17 +598,17 @@ send_create (void *cls) | |||
627 | 598 | ||
628 | cc->task = NULL; | 599 | cc->task = NULL; |
629 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 600 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
630 | env = GNUNET_MQ_msg_extra (create_msg, | 601 | env = |
631 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), | 602 | GNUNET_MQ_msg_extra (create_msg, |
632 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 603 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), |
633 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced options. | 604 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
634 | create_msg->options = GNUNET_MQ_PREF_RELIABLE >> 10; | 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. |
606 | create_msg->options = 2; | ||
635 | create_msg->cid = cc->cid; | 607 | create_msg->cid = cc->cid; |
636 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; | 608 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; |
637 | pids[0] = my_full_id; | 609 | pids[0] = my_full_id; |
638 | for (unsigned int i=0;i<=cc->off;i++) | 610 | for (unsigned int i = 0; i <= cc->off; i++) |
639 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, | 611 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i)); |
640 | i)); | ||
641 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 612 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
642 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", | 613 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", |
643 | GCC_2s (cc), | 614 | GCC_2s (cc), |
@@ -645,11 +616,8 @@ send_create (void *cls) | |||
645 | cc->env = env; | 616 | cc->env = env; |
646 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 617 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); |
647 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 618 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); |
648 | update_state (cc, | 619 | update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO); |
649 | CADET_CONNECTION_SENT, | 620 | GCP_send (cc->mq_man, env); |
650 | GNUNET_NO); | ||
651 | GCP_send (cc->mq_man, | ||
652 | env); | ||
653 | } | 621 | } |
654 | 622 | ||
655 | 623 | ||
@@ -670,22 +638,18 @@ send_create_ack (void *cls) | |||
670 | "Sending CONNECTION_CREATE_ACK message for %s\n", | 638 | "Sending CONNECTION_CREATE_ACK message for %s\n", |
671 | GCC_2s (cc)); | 639 | GCC_2s (cc)); |
672 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 640 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
673 | env = GNUNET_MQ_msg (ack_msg, | 641 | env = |
674 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); | 642 | GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); |
675 | ack_msg->cid = cc->cid; | 643 | ack_msg->cid = cc->cid; |
676 | cc->env = env; | 644 | cc->env = env; |
677 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 645 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); |
678 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | 646 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); |
679 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) | 647 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) |
680 | update_state (cc, | 648 | update_state (cc, CADET_CONNECTION_READY, GNUNET_NO); |
681 | CADET_CONNECTION_READY, | ||
682 | GNUNET_NO); | ||
683 | if (CADET_CONNECTION_READY == cc->state) | 649 | if (CADET_CONNECTION_READY == cc->state) |
684 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 650 | cc->task = |
685 | &send_keepalive, | 651 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
686 | cc); | 652 | GCP_send (cc->mq_man, env); |
687 | GCP_send (cc->mq_man, | ||
688 | env); | ||
689 | } | 653 | } |
690 | 654 | ||
691 | 655 | ||
@@ -707,14 +671,11 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
707 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); | 671 | (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); |
708 | /* Revert back to the state of having only received the 'CREATE', | 672 | /* Revert back to the state of having only received the 'CREATE', |
709 | and immediately proceed to send the CREATE_ACK. */ | 673 | and immediately proceed to send the CREATE_ACK. */ |
710 | update_state (cc, | 674 | update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); |
711 | CADET_CONNECTION_CREATE_RECEIVED, | ||
712 | cc->mqm_ready); | ||
713 | if (NULL != cc->task) | 675 | if (NULL != cc->task) |
714 | GNUNET_SCHEDULER_cancel (cc->task); | 676 | GNUNET_SCHEDULER_cancel (cc->task); |
715 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, | 677 | cc->task = |
716 | &send_create_ack, | 678 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); |
717 | cc); | ||
718 | } | 679 | } |
719 | else | 680 | else |
720 | { | 681 | { |
@@ -739,20 +700,15 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
739 | * and the last envelope was discarded | 700 | * and the last envelope was discarded |
740 | */ | 701 | */ |
741 | static void | 702 | static void |
742 | manage_first_hop_mq (void *cls, | 703 | manage_first_hop_mq (void *cls, int available) |
743 | int available) | ||
744 | { | 704 | { |
745 | struct CadetConnection *cc = cls; | 705 | struct CadetConnection *cc = cls; |
746 | 706 | ||
747 | if (GNUNET_YES != available) | 707 | if (GNUNET_YES != available) |
748 | { | 708 | { |
749 | /* Connection is down, for now... */ | 709 | /* Connection is down, for now... */ |
750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 710 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc)); |
751 | "Core MQ for %s went down\n", | 711 | update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO); |
752 | GCC_2s (cc)); | ||
753 | update_state (cc, | ||
754 | CADET_CONNECTION_NEW, | ||
755 | GNUNET_NO); | ||
756 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; | 712 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; |
757 | if (NULL != cc->task) | 713 | if (NULL != cc->task) |
758 | { | 714 | { |
@@ -762,9 +718,7 @@ manage_first_hop_mq (void *cls, | |||
762 | return; | 718 | return; |
763 | } | 719 | } |
764 | 720 | ||
765 | update_state (cc, | 721 | update_state (cc, cc->state, GNUNET_YES); |
766 | cc->state, | ||
767 | GNUNET_YES); | ||
768 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 722 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
769 | "Core MQ for %s became available in state %d\n", | 723 | "Core MQ for %s became available in state %d\n", |
770 | GCC_2s (cc), | 724 | GCC_2s (cc), |
@@ -773,9 +727,7 @@ manage_first_hop_mq (void *cls, | |||
773 | { | 727 | { |
774 | case CADET_CONNECTION_NEW: | 728 | case CADET_CONNECTION_NEW: |
775 | /* Transmit immediately */ | 729 | /* Transmit immediately */ |
776 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, | 730 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); |
777 | &send_create, | ||
778 | cc); | ||
779 | break; | 731 | break; |
780 | case CADET_CONNECTION_SENDING_CREATE: | 732 | case CADET_CONNECTION_SENDING_CREATE: |
781 | /* Should not be possible to be called in this state. */ | 733 | /* Should not be possible to be called in this state. */ |
@@ -783,30 +735,25 @@ manage_first_hop_mq (void *cls, | |||
783 | break; | 735 | break; |
784 | case CADET_CONNECTION_SENT: | 736 | case CADET_CONNECTION_SENT: |
785 | /* Retry a bit later... */ | 737 | /* Retry a bit later... */ |
786 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, | 738 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); |
787 | &send_create, | ||
788 | cc); | ||
789 | break; | 739 | break; |
790 | case CADET_CONNECTION_CREATE_RECEIVED: | 740 | case CADET_CONNECTION_CREATE_RECEIVED: |
791 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ | 741 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ |
792 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 742 | cc->metrics.age = GNUNET_TIME_absolute_get (); |
793 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, | 743 | cc->task = |
794 | &send_create_ack, | 744 | GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); |
795 | cc); | ||
796 | break; | 745 | break; |
797 | case CADET_CONNECTION_READY: | 746 | case CADET_CONNECTION_READY: |
798 | if ( (NULL == cc->keepalive_qe) && | 747 | if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && |
799 | (GNUNET_YES == cc->mqm_ready) && | 748 | (NULL == cc->task)) |
800 | (NULL == cc->task) ) | ||
801 | { | 749 | { |
802 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
803 | "Scheduling keepalive for %s in %s\n", | 751 | "Scheduling keepalive for %s in %s\n", |
804 | GCC_2s (cc), | 752 | GCC_2s (cc), |
805 | GNUNET_STRINGS_relative_time_to_string (keepalive_period, | 753 | GNUNET_STRINGS_relative_time_to_string (keepalive_period, |
806 | GNUNET_YES)); | 754 | GNUNET_YES)); |
807 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | 755 | cc->task = |
808 | &send_keepalive, | 756 | GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); |
809 | cc); | ||
810 | } | 757 | } |
811 | break; | 758 | break; |
812 | } | 759 | } |
@@ -844,13 +791,14 @@ connection_create (struct CadetPeer *destination, | |||
844 | cc->state = init_state; | 791 | cc->state = init_state; |
845 | cc->ct = ct; | 792 | cc->ct = ct; |
846 | cc->cid = *cid; | 793 | cc->cid = *cid; |
847 | cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, | 794 | cc->retry_delay = |
848 | off); | 795 | GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); |
849 | GNUNET_assert (GNUNET_OK == | 796 | GNUNET_assert (GNUNET_OK == |
850 | GNUNET_CONTAINER_multishortmap_put (connections, | 797 | GNUNET_CONTAINER_multishortmap_put ( |
851 | &GCC_get_id (cc)->connection_of_tunnel, | 798 | connections, |
852 | cc, | 799 | &GCC_get_id (cc)->connection_of_tunnel, |
853 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 800 | cc, |
801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
854 | cc->ready_cb = ready_cb; | 802 | cc->ready_cb = ready_cb; |
855 | cc->ready_cb_cls = ready_cb_cls; | 803 | cc->ready_cb_cls = ready_cb_cls; |
856 | cc->path = path; | 804 | cc->path = path; |
@@ -860,18 +808,11 @@ connection_create (struct CadetPeer *destination, | |||
860 | GCC_2s (cc), | 808 | GCC_2s (cc), |
861 | GCPP_2s (path), | 809 | GCPP_2s (path), |
862 | off); | 810 | off); |
863 | GCPP_add_connection (path, | 811 | GCPP_add_connection (path, off, cc); |
864 | off, | 812 | for (unsigned int i = 0; i < off; i++) |
865 | cc); | 813 | GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc); |
866 | for (unsigned int i=0;i<off;i++) | 814 | first_hop = GCPP_get_peer_at_offset (path, 0); |
867 | GCP_add_connection (GCPP_get_peer_at_offset (path, | 815 | cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc); |
868 | i), | ||
869 | cc); | ||
870 | first_hop = GCPP_get_peer_at_offset (path, | ||
871 | 0); | ||
872 | cc->mq_man = GCP_request_mq (first_hop, | ||
873 | &manage_first_hop_mq, | ||
874 | cc); | ||
875 | return cc; | 816 | return cc; |
876 | } | 817 | } |
877 | 818 | ||
@@ -900,18 +841,14 @@ GCC_create_inbound (struct CadetPeer *destination, | |||
900 | struct CadetConnection *cc; | 841 | struct CadetConnection *cc; |
901 | unsigned int off; | 842 | unsigned int off; |
902 | 843 | ||
903 | off = GCPP_find_peer (path, | 844 | off = GCPP_find_peer (path, destination); |
904 | destination); | ||
905 | GNUNET_assert (UINT_MAX != off); | 845 | GNUNET_assert (UINT_MAX != off); |
906 | cc = GCPP_get_connection (path, | 846 | cc = GCPP_get_connection (path, destination, off); |
907 | destination, | ||
908 | off); | ||
909 | if (NULL != cc) | 847 | if (NULL != cc) |
910 | { | 848 | { |
911 | int cmp; | 849 | int cmp; |
912 | 850 | ||
913 | cmp = GNUNET_memcmp (cid, | 851 | cmp = GNUNET_memcmp (cid, &cc->cid); |
914 | &cc->cid); | ||
915 | if (0 == cmp) | 852 | if (0 == cmp) |
916 | { | 853 | { |
917 | /* Two peers picked the SAME random connection identifier at the | 854 | /* Two peers picked the SAME random connection identifier at the |
@@ -977,9 +914,7 @@ GCC_create (struct CadetPeer *destination, | |||
977 | { | 914 | { |
978 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; | 915 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; |
979 | 916 | ||
980 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, | 917 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid)); |
981 | &cid, | ||
982 | sizeof (cid)); | ||
983 | return connection_create (destination, | 918 | return connection_create (destination, |
984 | path, | 919 | path, |
985 | off, | 920 | off, |
@@ -1002,8 +937,7 @@ GCC_create (struct CadetPeer *destination, | |||
1002 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it | 937 | * yet have a #GNUNET_MQ_notify_sent() callback attached to it |
1003 | */ | 938 | */ |
1004 | void | 939 | void |
1005 | GCC_transmit (struct CadetConnection *cc, | 940 | GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) |
1006 | struct GNUNET_MQ_Envelope *env) | ||
1007 | { | 941 | { |
1008 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 942 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1009 | "Scheduling message for transmission on %s\n", | 943 | "Scheduling message for transmission on %s\n", |
@@ -1017,8 +951,7 @@ GCC_transmit (struct CadetConnection *cc, | |||
1017 | GNUNET_SCHEDULER_cancel (cc->task); | 951 | GNUNET_SCHEDULER_cancel (cc->task); |
1018 | cc->task = NULL; | 952 | cc->task = NULL; |
1019 | } | 953 | } |
1020 | GCP_send (cc->mq_man, | 954 | GCP_send (cc->mq_man, env); |
1021 | env); | ||
1022 | } | 955 | } |
1023 | 956 | ||
1024 | 957 | ||
@@ -1030,8 +963,7 @@ GCC_transmit (struct CadetConnection *cc, | |||
1030 | * @return path to @a cc | 963 | * @return path to @a cc |
1031 | */ | 964 | */ |
1032 | struct CadetPeerPath * | 965 | struct CadetPeerPath * |
1033 | GCC_get_path (struct CadetConnection *cc, | 966 | GCC_get_path (struct CadetConnection *cc, unsigned int *off) |
1034 | unsigned int *off) | ||
1035 | { | 967 | { |
1036 | *off = cc->off; | 968 | *off = cc->off; |
1037 | return cc->path; | 969 | return cc->path; |
@@ -1081,7 +1013,8 @@ GCC_2s (const struct CadetConnection *cc) | |||
1081 | } | 1013 | } |
1082 | 1014 | ||
1083 | 1015 | ||
1084 | #define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-con",__VA_ARGS__) | 1016 | #define LOG2(level, ...) \ |
1017 | GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__) | ||
1085 | 1018 | ||
1086 | 1019 | ||
1087 | /** | 1020 | /** |
@@ -1091,21 +1024,21 @@ GCC_2s (const struct CadetConnection *cc) | |||
1091 | * @param level Debug level to use. | 1024 | * @param level Debug level to use. |
1092 | */ | 1025 | */ |
1093 | void | 1026 | void |
1094 | GCC_debug (struct CadetConnection *cc, | 1027 | GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level) |
1095 | enum GNUNET_ErrorType level) | ||
1096 | { | 1028 | { |
1097 | #if !defined(GNUNET_CULL_LOGGING) | 1029 | #if ! defined(GNUNET_CULL_LOGGING) |
1098 | int do_log; | 1030 | int do_log; |
1099 | 1031 | ||
1100 | 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), |
1101 | "cadet-con", | 1033 | "cadet-con", |
1102 | __FILE__, __FUNCTION__, __LINE__); | 1034 | __FILE__, |
1035 | __FUNCTION__, | ||
1036 | __LINE__); | ||
1103 | if (0 == do_log) | 1037 | if (0 == do_log) |
1104 | return; | 1038 | return; |
1105 | if (NULL == cc) | 1039 | if (NULL == cc) |
1106 | { | 1040 | { |
1107 | LOG2 (level, | 1041 | LOG2 (level, "Connection (NULL)\n"); |
1108 | "Connection (NULL)\n"); | ||
1109 | return; | 1042 | return; |
1110 | } | 1043 | } |
1111 | LOG2 (level, | 1044 | LOG2 (level, |