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.c282
1 files changed, 101 insertions, 181 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 1f7e86d60..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/**
@@ -161,11 +162,6 @@ struct CadetConnection
161 enum CadetConnectionState state; 162 enum CadetConnectionState state;
162 163
163 /** 164 /**
164 * Options for the route, control buffering.
165 */
166 enum GNUNET_CADET_ChannelOption options;
167
168 /**
169 * How many latency observations did we make for this connection? 165 * How many latency observations did we make for this connection?
170 */ 166 */
171 unsigned int latency_datapoints; 167 unsigned int latency_datapoints;
@@ -179,7 +175,6 @@ struct CadetConnection
179 * Are we ready to transmit via @e mq_man right now? 175 * Are we ready to transmit via @e mq_man right now?
180 */ 176 */
181 int mqm_ready; 177 int mqm_ready;
182
183}; 178};
184 179
185 180
@@ -213,18 +208,16 @@ update_state (struct CadetConnection *cc,
213 int old_ready; 208 int old_ready;
214 int new_ready; 209 int new_ready;
215 210
216 if ( (new_state == cc->state) && 211 if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
217 (new_mqm_ready == cc->mqm_ready) )
218 return; /* no change, nothing to do */ 212 return; /* no change, nothing to do */
219 old_ready = ( (CADET_CONNECTION_READY == cc->state) && 213 old_ready =
220 (GNUNET_YES == cc->mqm_ready) ); 214 ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready));
221 new_ready = ( (CADET_CONNECTION_READY == new_state) && 215 new_ready =
222 (GNUNET_YES == new_mqm_ready) ); 216 ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready));
223 cc->state = new_state; 217 cc->state = new_state;
224 cc->mqm_ready = new_mqm_ready; 218 cc->mqm_ready = new_mqm_ready;
225 if (old_ready != new_ready) 219 if (old_ready != new_ready)
226 cc->ready_cb (cc->ready_cb_cls, 220 cc->ready_cb (cc->ready_cb_cls, new_ready);
227 new_ready);
228} 221}
229 222
230 223
@@ -237,13 +230,10 @@ update_state (struct CadetConnection *cc,
237static void 230static void
238GCC_destroy (struct CadetConnection *cc) 231GCC_destroy (struct CadetConnection *cc)
239{ 232{
240 LOG (GNUNET_ERROR_TYPE_DEBUG, 233 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc));
241 "Destroying %s\n",
242 GCC_2s (cc));
243 if (NULL != cc->mq_man) 234 if (NULL != cc->mq_man)
244 { 235 {
245 GCP_request_mq_cancel (cc->mq_man, 236 GCP_request_mq_cancel (cc->mq_man, NULL);
246 NULL);
247 cc->mq_man = NULL; 237 cc->mq_man = NULL;
248 } 238 }
249 if (NULL != cc->task) 239 if (NULL != cc->task)
@@ -256,22 +246,19 @@ GCC_destroy (struct CadetConnection *cc)
256 GCT_send_cancel (cc->keepalive_qe); 246 GCT_send_cancel (cc->keepalive_qe);
257 cc->keepalive_qe = NULL; 247 cc->keepalive_qe = NULL;
258 } 248 }
259 GCPP_del_connection (cc->path, 249 GCPP_del_connection (cc->path, cc->off, cc);
260 cc->off, 250 for (unsigned int i = 0; i < cc->off; i++)
261 cc); 251 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc);
262 for (unsigned int i=0;i<cc->off;i++) 252 GNUNET_assert (
263 GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, 253 GNUNET_YES ==
264 i), 254 GNUNET_CONTAINER_multishortmap_remove (connections,
265 cc); 255 &GCC_get_id (cc)
266 GNUNET_assert (GNUNET_YES == 256 ->connection_of_tunnel,
267 GNUNET_CONTAINER_multishortmap_remove (connections, 257 cc));
268 &GCC_get_id (cc)->connection_of_tunnel,
269 cc));
270 GNUNET_free (cc); 258 GNUNET_free (cc);
271} 259}
272 260
273 261
274
275/** 262/**
276 * Destroy a connection, called when the CORE layer is already done 263 * Destroy a connection, called when the CORE layer is already done
277 * (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
@@ -303,18 +290,16 @@ void
303GCC_destroy_without_tunnel (struct CadetConnection *cc) 290GCC_destroy_without_tunnel (struct CadetConnection *cc)
304{ 291{
305 cc->ct = NULL; 292 cc->ct = NULL;
306 if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) && 293 if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man))
307 (NULL != cc->mq_man) )
308 { 294 {
309 struct GNUNET_MQ_Envelope *env; 295 struct GNUNET_MQ_Envelope *env;
310 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; 296 struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg;
311 297
312 /* Need to notify next hop that we are down. */ 298 /* Need to notify next hop that we are down. */
313 env = GNUNET_MQ_msg (destroy_msg, 299 env =
314 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); 300 GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
315 destroy_msg->cid = cc->cid; 301 destroy_msg->cid = cc->cid;
316 GCP_request_mq_cancel (cc->mq_man, 302 GCP_request_mq_cancel (cc->mq_man, env);
317 env);
318 cc->mq_man = NULL; 303 cc->mq_man = NULL;
319 } 304 }
320 GCC_destroy (cc); 305 GCC_destroy (cc);
@@ -372,11 +357,9 @@ keepalive_done (void *cls,
372 struct CadetConnection *cc = cls; 357 struct CadetConnection *cc = cls;
373 358
374 cc->keepalive_qe = NULL; 359 cc->keepalive_qe = NULL;
375 if ( (GNUNET_YES == cc->mqm_ready) && 360 if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task))
376 (NULL == cc->task) ) 361 cc->task =
377 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 362 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
378 &send_keepalive,
379 cc);
380} 363}
381 364
382 365
@@ -396,9 +379,8 @@ send_keepalive (void *cls)
396 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) 379 if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t))
397 { 380 {
398 /* Tunnel not yet ready, wait with keepalives... */ 381 /* Tunnel not yet ready, wait with keepalives... */
399 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 382 cc->task =
400 &send_keepalive, 383 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
401 cc);
402 return; 384 return;
403 } 385 }
404 GNUNET_assert (NULL != cc->ct); 386 GNUNET_assert (NULL != cc->ct);
@@ -408,18 +390,11 @@ send_keepalive (void *cls)
408 "Sending KEEPALIVE on behalf of %s via %s\n", 390 "Sending KEEPALIVE on behalf of %s via %s\n",
409 GCC_2s (cc), 391 GCC_2s (cc),
410 GCT_2s (cc->ct->t)); 392 GCT_2s (cc->ct->t));
411 GNUNET_STATISTICS_update (stats, 393 GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
412 "# keepalives sent",
413 1,
414 GNUNET_NO);
415 msg.size = htons (sizeof (msg)); 394 msg.size = htons (sizeof (msg));
416 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); 395 msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE);
417 396
418 cc->keepalive_qe 397 cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc);
419 = GCT_send (cc->ct->t,
420 &msg,
421 &keepalive_done,
422 cc);
423} 398}
424 399
425 400
@@ -480,10 +455,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
480 cc = GCC_lookup (cid); 455 cc = GCC_lookup (cid);
481 if (NULL == cc) 456 if (NULL == cc)
482 return; /* whopise, connection alredy down? */ 457 return; /* whopise, connection alredy down? */
483 GNUNET_STATISTICS_update (stats, 458 GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO);
484 "# latencies observed",
485 1,
486 GNUNET_NO);
487 cc->latency_datapoints++; 459 cc->latency_datapoints++;
488 if (cc->latency_datapoints >= 7) 460 if (cc->latency_datapoints >= 7)
489 weight = 7.0; 461 weight = 7.0;
@@ -492,7 +464,8 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
492 /* Compute weighted average, giving at MOST weight 7 to the 464 /* Compute weighted average, giving at MOST weight 7 to the
493 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
494 measurements. */ 466 measurements. */
495 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;
496 result /= (weight + 1.0); 469 result /= (weight + 1.0);
497 cc->metrics.aged_latency.rel_value_us = (uint64_t) result; 470 cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
498} 471}
@@ -521,15 +494,11 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc)
521 cc->task = NULL; 494 cc->task = NULL;
522 } 495 }
523 cc->metrics.age = GNUNET_TIME_absolute_get (); 496 cc->metrics.age = GNUNET_TIME_absolute_get ();
524 update_state (cc, 497 update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready);
525 CADET_CONNECTION_READY, 498 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
526 cc->mqm_ready); 499 (NULL == cc->task))
527 if ( (NULL == cc->keepalive_qe) && 500 cc->task =
528 (GNUNET_YES == cc->mqm_ready) && 501 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
529 (NULL == cc->task) )
530 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period,
531 &send_keepalive,
532 cc);
533} 502}
534 503
535 504
@@ -557,8 +526,7 @@ GCC_handle_kx (struct CadetConnection *cc,
557 GCC_2s (cc)); 526 GCC_2s (cc));
558 GCC_handle_connection_create_ack (cc); 527 GCC_handle_connection_create_ack (cc);
559 } 528 }
560 GCT_handle_kx (cc->ct, 529 GCT_handle_kx (cc->ct, msg);
561 msg);
562} 530}
563 531
564 532
@@ -586,8 +554,7 @@ GCC_handle_kx_auth (struct CadetConnection *cc,
586 GCC_2s (cc)); 554 GCC_2s (cc));
587 GCC_handle_connection_create_ack (cc); 555 GCC_handle_connection_create_ack (cc);
588 } 556 }
589 GCT_handle_kx_auth (cc->ct, 557 GCT_handle_kx_auth (cc->ct, msg);
590 msg);
591} 558}
592 559
593 560
@@ -611,8 +578,7 @@ GCC_handle_encrypted (struct CadetConnection *cc,
611 GCC_handle_connection_create_ack (cc); 578 GCC_handle_connection_create_ack (cc);
612 } 579 }
613 cc->metrics.last_use = GNUNET_TIME_absolute_get (); 580 cc->metrics.last_use = GNUNET_TIME_absolute_get ();
614 GCT_handle_encrypted (cc->ct, 581 GCT_handle_encrypted (cc->ct, msg);
615 msg);
616} 582}
617 583
618 584
@@ -632,16 +598,17 @@ send_create (void *cls)
632 598
633 cc->task = NULL; 599 cc->task = NULL;
634 GNUNET_assert (GNUNET_YES == cc->mqm_ready); 600 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
635 env = GNUNET_MQ_msg_extra (create_msg, 601 env =
636 (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), 602 GNUNET_MQ_msg_extra (create_msg,
637 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); 603 (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity),
638 create_msg->options = htonl ((uint32_t) cc->options); 604 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.
606 create_msg->options = 2;
639 create_msg->cid = cc->cid; 607 create_msg->cid = cc->cid;
640 pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; 608 pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
641 pids[0] = my_full_id; 609 pids[0] = my_full_id;
642 for (unsigned int i=0;i<=cc->off;i++) 610 for (unsigned int i = 0; i <= cc->off; i++)
643 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));
644 i));
645 LOG (GNUNET_ERROR_TYPE_DEBUG, 612 LOG (GNUNET_ERROR_TYPE_DEBUG,
646 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", 613 "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
647 GCC_2s (cc), 614 GCC_2s (cc),
@@ -649,11 +616,8 @@ send_create (void *cls)
649 cc->env = env; 616 cc->env = env;
650 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); 617 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
651 cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); 618 cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay);
652 update_state (cc, 619 update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO);
653 CADET_CONNECTION_SENT, 620 GCP_send (cc->mq_man, env);
654 GNUNET_NO);
655 GCP_send (cc->mq_man,
656 env);
657} 621}
658 622
659 623
@@ -674,22 +638,18 @@ send_create_ack (void *cls)
674 "Sending CONNECTION_CREATE_ACK message for %s\n", 638 "Sending CONNECTION_CREATE_ACK message for %s\n",
675 GCC_2s (cc)); 639 GCC_2s (cc));
676 GNUNET_assert (GNUNET_YES == cc->mqm_ready); 640 GNUNET_assert (GNUNET_YES == cc->mqm_ready);
677 env = GNUNET_MQ_msg (ack_msg, 641 env =
678 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); 642 GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK);
679 ack_msg->cid = cc->cid; 643 ack_msg->cid = cc->cid;
680 cc->env = env; 644 cc->env = env;
681 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); 645 cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay);
682 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);
683 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) 647 if (CADET_CONNECTION_CREATE_RECEIVED == cc->state)
684 update_state (cc, 648 update_state (cc, CADET_CONNECTION_READY, GNUNET_NO);
685 CADET_CONNECTION_READY,
686 GNUNET_NO);
687 if (CADET_CONNECTION_READY == cc->state) 649 if (CADET_CONNECTION_READY == cc->state)
688 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 650 cc->task =
689 &send_keepalive, 651 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
690 cc); 652 GCP_send (cc->mq_man, env);
691 GCP_send (cc->mq_man,
692 env);
693} 653}
694 654
695 655
@@ -711,14 +671,11 @@ GCC_handle_duplicate_create (struct CadetConnection *cc)
711 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); 671 (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
712 /* Revert back to the state of having only received the 'CREATE', 672 /* Revert back to the state of having only received the 'CREATE',
713 and immediately proceed to send the CREATE_ACK. */ 673 and immediately proceed to send the CREATE_ACK. */
714 update_state (cc, 674 update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready);
715 CADET_CONNECTION_CREATE_RECEIVED,
716 cc->mqm_ready);
717 if (NULL != cc->task) 675 if (NULL != cc->task)
718 GNUNET_SCHEDULER_cancel (cc->task); 676 GNUNET_SCHEDULER_cancel (cc->task);
719 cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, 677 cc->task =
720 &send_create_ack, 678 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
721 cc);
722 } 679 }
723 else 680 else
724 { 681 {
@@ -743,20 +700,15 @@ GCC_handle_duplicate_create (struct CadetConnection *cc)
743 * and the last envelope was discarded 700 * and the last envelope was discarded
744 */ 701 */
745static void 702static void
746manage_first_hop_mq (void *cls, 703manage_first_hop_mq (void *cls, int available)
747 int available)
748{ 704{
749 struct CadetConnection *cc = cls; 705 struct CadetConnection *cc = cls;
750 706
751 if (GNUNET_YES != available) 707 if (GNUNET_YES != available)
752 { 708 {
753 /* Connection is down, for now... */ 709 /* Connection is down, for now... */
754 LOG (GNUNET_ERROR_TYPE_DEBUG, 710 LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc));
755 "Core MQ for %s went down\n", 711 update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO);
756 GCC_2s (cc));
757 update_state (cc,
758 CADET_CONNECTION_NEW,
759 GNUNET_NO);
760 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; 712 cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
761 if (NULL != cc->task) 713 if (NULL != cc->task)
762 { 714 {
@@ -766,9 +718,7 @@ manage_first_hop_mq (void *cls,
766 return; 718 return;
767 } 719 }
768 720
769 update_state (cc, 721 update_state (cc, cc->state, GNUNET_YES);
770 cc->state,
771 GNUNET_YES);
772 LOG (GNUNET_ERROR_TYPE_DEBUG, 722 LOG (GNUNET_ERROR_TYPE_DEBUG,
773 "Core MQ for %s became available in state %d\n", 723 "Core MQ for %s became available in state %d\n",
774 GCC_2s (cc), 724 GCC_2s (cc),
@@ -777,9 +727,7 @@ manage_first_hop_mq (void *cls,
777 { 727 {
778 case CADET_CONNECTION_NEW: 728 case CADET_CONNECTION_NEW:
779 /* Transmit immediately */ 729 /* Transmit immediately */
780 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, 730 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
781 &send_create,
782 cc);
783 break; 731 break;
784 case CADET_CONNECTION_SENDING_CREATE: 732 case CADET_CONNECTION_SENDING_CREATE:
785 /* Should not be possible to be called in this state. */ 733 /* Should not be possible to be called in this state. */
@@ -787,30 +735,25 @@ manage_first_hop_mq (void *cls,
787 break; 735 break;
788 case CADET_CONNECTION_SENT: 736 case CADET_CONNECTION_SENT:
789 /* Retry a bit later... */ 737 /* Retry a bit later... */
790 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, 738 cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc);
791 &send_create,
792 cc);
793 break; 739 break;
794 case CADET_CONNECTION_CREATE_RECEIVED: 740 case CADET_CONNECTION_CREATE_RECEIVED:
795 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ 741 /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */
796 cc->metrics.age = GNUNET_TIME_absolute_get (); 742 cc->metrics.age = GNUNET_TIME_absolute_get ();
797 cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, 743 cc->task =
798 &send_create_ack, 744 GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
799 cc);
800 break; 745 break;
801 case CADET_CONNECTION_READY: 746 case CADET_CONNECTION_READY:
802 if ( (NULL == cc->keepalive_qe) && 747 if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
803 (GNUNET_YES == cc->mqm_ready) && 748 (NULL == cc->task))
804 (NULL == cc->task) )
805 { 749 {
806 LOG (GNUNET_ERROR_TYPE_DEBUG, 750 LOG (GNUNET_ERROR_TYPE_DEBUG,
807 "Scheduling keepalive for %s in %s\n", 751 "Scheduling keepalive for %s in %s\n",
808 GCC_2s (cc), 752 GCC_2s (cc),
809 GNUNET_STRINGS_relative_time_to_string (keepalive_period, 753 GNUNET_STRINGS_relative_time_to_string (keepalive_period,
810 GNUNET_YES)); 754 GNUNET_YES));
811 cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, 755 cc->task =
812 &send_keepalive, 756 GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
813 cc);
814 } 757 }
815 break; 758 break;
816 } 759 }
@@ -825,7 +768,6 @@ manage_first_hop_mq (void *cls,
825 * @param destination where to go 768 * @param destination where to go
826 * @param path which path to take (may not be the full path) 769 * @param path which path to take (may not be the full path)
827 * @param off offset of @a destination on @a path 770 * @param off offset of @a destination on @a path
828 * @param options options for the connection
829 * @param ct which tunnel uses this connection 771 * @param ct which tunnel uses this connection
830 * @param init_state initial state for the connection 772 * @param init_state initial state for the connection
831 * @param ready_cb function to call when ready to transmit 773 * @param ready_cb function to call when ready to transmit
@@ -836,7 +778,6 @@ static struct CadetConnection *
836connection_create (struct CadetPeer *destination, 778connection_create (struct CadetPeer *destination,
837 struct CadetPeerPath *path, 779 struct CadetPeerPath *path,
838 unsigned int off, 780 unsigned int off,
839 enum GNUNET_CADET_ChannelOption options,
840 struct CadetTConnection *ct, 781 struct CadetTConnection *ct,
841 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 782 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
842 enum CadetConnectionState init_state, 783 enum CadetConnectionState init_state,
@@ -847,17 +788,17 @@ connection_create (struct CadetPeer *destination,
847 struct CadetPeer *first_hop; 788 struct CadetPeer *first_hop;
848 789
849 cc = GNUNET_new (struct CadetConnection); 790 cc = GNUNET_new (struct CadetConnection);
850 cc->options = options;
851 cc->state = init_state; 791 cc->state = init_state;
852 cc->ct = ct; 792 cc->ct = ct;
853 cc->cid = *cid; 793 cc->cid = *cid;
854 cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, 794 cc->retry_delay =
855 off); 795 GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off);
856 GNUNET_assert (GNUNET_OK == 796 GNUNET_assert (GNUNET_OK ==
857 GNUNET_CONTAINER_multishortmap_put (connections, 797 GNUNET_CONTAINER_multishortmap_put (
858 &GCC_get_id (cc)->connection_of_tunnel, 798 connections,
859 cc, 799 &GCC_get_id (cc)->connection_of_tunnel,
860 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 800 cc,
801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
861 cc->ready_cb = ready_cb; 802 cc->ready_cb = ready_cb;
862 cc->ready_cb_cls = ready_cb_cls; 803 cc->ready_cb_cls = ready_cb_cls;
863 cc->path = path; 804 cc->path = path;
@@ -867,18 +808,11 @@ connection_create (struct CadetPeer *destination,
867 GCC_2s (cc), 808 GCC_2s (cc),
868 GCPP_2s (path), 809 GCPP_2s (path),
869 off); 810 off);
870 GCPP_add_connection (path, 811 GCPP_add_connection (path, off, cc);
871 off, 812 for (unsigned int i = 0; i < off; i++)
872 cc); 813 GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc);
873 for (unsigned int i=0;i<off;i++) 814 first_hop = GCPP_get_peer_at_offset (path, 0);
874 GCP_add_connection (GCPP_get_peer_at_offset (path, 815 cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc);
875 i),
876 cc);
877 first_hop = GCPP_get_peer_at_offset (path,
878 0);
879 cc->mq_man = GCP_request_mq (first_hop,
880 &manage_first_hop_mq,
881 cc);
882 return cc; 816 return cc;
883} 817}
884 818
@@ -890,7 +824,6 @@ connection_create (struct CadetPeer *destination,
890 * 824 *
891 * @param destination where to go 825 * @param destination where to go
892 * @param path which path to take (may not be the full path) 826 * @param path which path to take (may not be the full path)
893 * @param options options for the connection
894 * @param ct which tunnel uses this connection 827 * @param ct which tunnel uses this connection
895 * @param ready_cb function to call when ready to transmit 828 * @param ready_cb function to call when ready to transmit
896 * @param ready_cb_cls closure for @a cb 829 * @param ready_cb_cls closure for @a cb
@@ -900,7 +833,6 @@ connection_create (struct CadetPeer *destination,
900struct CadetConnection * 833struct CadetConnection *
901GCC_create_inbound (struct CadetPeer *destination, 834GCC_create_inbound (struct CadetPeer *destination,
902 struct CadetPeerPath *path, 835 struct CadetPeerPath *path,
903 enum GNUNET_CADET_ChannelOption options,
904 struct CadetTConnection *ct, 836 struct CadetTConnection *ct,
905 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, 837 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
906 GCC_ReadyCallback ready_cb, 838 GCC_ReadyCallback ready_cb,
@@ -909,18 +841,14 @@ GCC_create_inbound (struct CadetPeer *destination,
909 struct CadetConnection *cc; 841 struct CadetConnection *cc;
910 unsigned int off; 842 unsigned int off;
911 843
912 off = GCPP_find_peer (path, 844 off = GCPP_find_peer (path, destination);
913 destination);
914 GNUNET_assert (UINT_MAX != off); 845 GNUNET_assert (UINT_MAX != off);
915 cc = GCPP_get_connection (path, 846 cc = GCPP_get_connection (path, destination, off);
916 destination,
917 off);
918 if (NULL != cc) 847 if (NULL != cc)
919 { 848 {
920 int cmp; 849 int cmp;
921 850
922 cmp = GNUNET_memcmp (cid, 851 cmp = GNUNET_memcmp (cid, &cc->cid);
923 &cc->cid);
924 if (0 == cmp) 852 if (0 == cmp)
925 { 853 {
926 /* Two peers picked the SAME random connection identifier at the 854 /* Two peers picked the SAME random connection identifier at the
@@ -956,7 +884,6 @@ GCC_create_inbound (struct CadetPeer *destination,
956 return connection_create (destination, 884 return connection_create (destination,
957 path, 885 path,
958 off, 886 off,
959 options,
960 ct, 887 ct,
961 cid, 888 cid,
962 CADET_CONNECTION_CREATE_RECEIVED, 889 CADET_CONNECTION_CREATE_RECEIVED,
@@ -972,7 +899,6 @@ GCC_create_inbound (struct CadetPeer *destination,
972 * @param destination where to go 899 * @param destination where to go
973 * @param path which path to take (may not be the full path) 900 * @param path which path to take (may not be the full path)
974 * @param off offset of @a destination on @a path 901 * @param off offset of @a destination on @a path
975 * @param options options for the connection
976 * @param ct tunnel that uses the connection 902 * @param ct tunnel that uses the connection
977 * @param ready_cb function to call when ready to transmit 903 * @param ready_cb function to call when ready to transmit
978 * @param ready_cb_cls closure for @a cb 904 * @param ready_cb_cls closure for @a cb
@@ -982,20 +908,16 @@ struct CadetConnection *
982GCC_create (struct CadetPeer *destination, 908GCC_create (struct CadetPeer *destination,
983 struct CadetPeerPath *path, 909 struct CadetPeerPath *path,
984 unsigned int off, 910 unsigned int off,
985 enum GNUNET_CADET_ChannelOption options,
986 struct CadetTConnection *ct, 911 struct CadetTConnection *ct,
987 GCC_ReadyCallback ready_cb, 912 GCC_ReadyCallback ready_cb,
988 void *ready_cb_cls) 913 void *ready_cb_cls)
989{ 914{
990 struct GNUNET_CADET_ConnectionTunnelIdentifier cid; 915 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
991 916
992 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 917 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid));
993 &cid,
994 sizeof (cid));
995 return connection_create (destination, 918 return connection_create (destination,
996 path, 919 path,
997 off, 920 off,
998 options,
999 ct, 921 ct,
1000 &cid, 922 &cid,
1001 CADET_CONNECTION_NEW, 923 CADET_CONNECTION_NEW,
@@ -1015,8 +937,7 @@ GCC_create (struct CadetPeer *destination,
1015 * yet have a #GNUNET_MQ_notify_sent() callback attached to it 937 * yet have a #GNUNET_MQ_notify_sent() callback attached to it
1016 */ 938 */
1017void 939void
1018GCC_transmit (struct CadetConnection *cc, 940GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
1019 struct GNUNET_MQ_Envelope *env)
1020{ 941{
1021 LOG (GNUNET_ERROR_TYPE_DEBUG, 942 LOG (GNUNET_ERROR_TYPE_DEBUG,
1022 "Scheduling message for transmission on %s\n", 943 "Scheduling message for transmission on %s\n",
@@ -1030,8 +951,7 @@ GCC_transmit (struct CadetConnection *cc,
1030 GNUNET_SCHEDULER_cancel (cc->task); 951 GNUNET_SCHEDULER_cancel (cc->task);
1031 cc->task = NULL; 952 cc->task = NULL;
1032 } 953 }
1033 GCP_send (cc->mq_man, 954 GCP_send (cc->mq_man, env);
1034 env);
1035} 955}
1036 956
1037 957
@@ -1043,8 +963,7 @@ GCC_transmit (struct CadetConnection *cc,
1043 * @return path to @a cc 963 * @return path to @a cc
1044 */ 964 */
1045struct CadetPeerPath * 965struct CadetPeerPath *
1046GCC_get_path (struct CadetConnection *cc, 966GCC_get_path (struct CadetConnection *cc, unsigned int *off)
1047 unsigned int *off)
1048{ 967{
1049 *off = cc->off; 968 *off = cc->off;
1050 return cc->path; 969 return cc->path;
@@ -1094,7 +1013,8 @@ GCC_2s (const struct CadetConnection *cc)
1094} 1013}
1095 1014
1096 1015
1097#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__)
1098 1018
1099 1019
1100/** 1020/**
@@ -1104,21 +1024,21 @@ GCC_2s (const struct CadetConnection *cc)
1104 * @param level Debug level to use. 1024 * @param level Debug level to use.
1105 */ 1025 */
1106void 1026void
1107GCC_debug (struct CadetConnection *cc, 1027GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level)
1108 enum GNUNET_ErrorType level)
1109{ 1028{
1110#if !defined(GNUNET_CULL_LOGGING) 1029#if ! defined(GNUNET_CULL_LOGGING)
1111 int do_log; 1030 int do_log;
1112 1031
1113 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),
1114 "cadet-con", 1033 "cadet-con",
1115 __FILE__, __FUNCTION__, __LINE__); 1034 __FILE__,
1035 __FUNCTION__,
1036 __LINE__);
1116 if (0 == do_log) 1037 if (0 == do_log)
1117 return; 1038 return;
1118 if (NULL == cc) 1039 if (NULL == cc)
1119 { 1040 {
1120 LOG2 (level, 1041 LOG2 (level, "Connection (NULL)\n");
1121 "Connection (NULL)\n");
1122 return; 1042 return;
1123 } 1043 }
1124 LOG2 (level, 1044 LOG2 (level,