aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c463
1 files changed, 218 insertions, 245 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 3024d8bc1..a0f6e2e42 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -190,22 +190,22 @@ struct MessageQueue
190enum State 190enum State
191{ 191{
192 /** 192 /**
193 * fresh peer or completely disconnected 193 * fresh peer or completely disconnected
194 */ 194 */
195 S_NOT_CONNECTED, 195 S_NOT_CONNECTED,
196 196
197 /** 197 /**
198 * sent CONNECT message to other peer, waiting for CONNECT_ACK 198 * sent CONNECT message to other peer, waiting for CONNECT_ACK
199 */ 199 */
200 S_CONNECT_SENT, 200 S_CONNECT_SENT,
201 201
202 /** 202 /**
203 * received CONNECT message to other peer, sending CONNECT_ACK 203 * received CONNECT message to other peer, sending CONNECT_ACK
204 */ 204 */
205 S_CONNECT_RECV, 205 S_CONNECT_RECV,
206 206
207 /** 207 /**
208 * received ACK or payload 208 * received ACK or payload
209 */ 209 */
210 S_CONNECTED, 210 S_CONNECTED,
211 211
@@ -215,7 +215,7 @@ enum State
215 S_FAST_RECONNECT, 215 S_FAST_RECONNECT,
216 216
217 /** 217 /**
218 * Disconnect in progress 218 * Disconnect in progress
219 */ 219 */
220 S_DISCONNECT 220 S_DISCONNECT
221}; 221};
@@ -452,6 +452,7 @@ static void
452reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 452reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
453{ 453{
454 struct NeighbourMapEntry *n = cls; 454 struct NeighbourMapEntry *n = cls;
455
455 if (n == NULL) 456 if (n == NULL)
456 return; 457 return;
457 458
@@ -472,7 +473,7 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
472 /* destroying address */ 473 /* destroying address */
473 if (n->address != NULL) 474 if (n->address != NULL)
474 { 475 {
475 GNUNET_assert (strlen(n->address->transport_name) > 0); 476 GNUNET_assert (strlen (n->address->transport_name) > 0);
476 GNUNET_ATS_address_destroyed (GST_ats, n->address, n->session); 477 GNUNET_ATS_address_destroyed (GST_ats, n->address, n->session);
477 } 478 }
478 479
@@ -522,6 +523,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
522 { 523 {
523 char *old = GNUNET_strdup (print_state (n->state)); 524 char *old = GNUNET_strdup (print_state (n->state));
524 char *new = GNUNET_strdup (print_state (state)); 525 char *new = GNUNET_strdup (print_state (state));
526
525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 "Illegal state transition from `%s' to `%s' in line %u \n", old, 528 "Illegal state transition from `%s' to `%s' in line %u \n", old,
527 new, line); 529 new, line);
@@ -534,6 +536,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
534 { 536 {
535 char *old = GNUNET_strdup (print_state (n->state)); 537 char *old = GNUNET_strdup (print_state (n->state));
536 char *new = GNUNET_strdup (print_state (state)); 538 char *new = GNUNET_strdup (print_state (state));
539
537 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 540 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
538 "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", 541 "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n",
539 GNUNET_i2s (&n->id), n, old, new, line); 542 GNUNET_i2s (&n->id), n, old, new, line);
@@ -551,8 +554,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
551 if (n->state_reset != GNUNET_SCHEDULER_NO_TASK) 554 if (n->state_reset != GNUNET_SCHEDULER_NO_TASK)
552 GNUNET_SCHEDULER_cancel (n->state_reset); 555 GNUNET_SCHEDULER_cancel (n->state_reset);
553 n->state_reset = 556 n->state_reset =
554 GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, 557 GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n);
555 n);
556 break; 558 break;
557 case S_CONNECTED: 559 case S_CONNECTED:
558 case S_NOT_CONNECTED: 560 case S_NOT_CONNECTED:
@@ -562,10 +564,10 @@ change (struct NeighbourMapEntry *n, int state, int line)
562#if DEBUG_TRANSPORT 564#if DEBUG_TRANSPORT
563 char *old = GNUNET_strdup (print_state (n->state)); 565 char *old = GNUNET_strdup (print_state (n->state));
564 char *new = GNUNET_strdup (print_state (state)); 566 char *new = GNUNET_strdup (print_state (state));
567
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 569 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
567 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), 570 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), old, new);
568 old, new);
569 GNUNET_free (old); 571 GNUNET_free (old);
570 GNUNET_free (new); 572 GNUNET_free (new);
571#endif 573#endif
@@ -578,7 +580,7 @@ change (struct NeighbourMapEntry *n, int state, int line)
578 default: 580 default:
579 GNUNET_assert (0); 581 GNUNET_assert (0);
580 } 582 }
581 583
582 584
583 585
584 return GNUNET_OK; 586 return GNUNET_OK;
@@ -588,9 +590,8 @@ static ssize_t
588send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, 590send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
589 size_t msgbuf_size, uint32_t priority, 591 size_t msgbuf_size, uint32_t priority,
590 struct GNUNET_TIME_Relative timeout, struct Session *session, 592 struct GNUNET_TIME_Relative timeout, struct Session *session,
591 const struct GNUNET_HELLO_Address *address, 593 const struct GNUNET_HELLO_Address *address, int force_address,
592 int force_address, GNUNET_TRANSPORT_TransmitContinuation cont, 594 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
593 void *cont_cls)
594{ 595{
595 struct GNUNET_TRANSPORT_PluginFunctions *papi; 596 struct GNUNET_TRANSPORT_PluginFunctions *papi;
596 size_t ret = GNUNET_SYSERR; 597 size_t ret = GNUNET_SYSERR;
@@ -620,8 +621,8 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
620 621
621 ret = 622 ret =
622 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session, 623 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session,
623 address->address, 624 address->address, address->address_length, GNUNET_YES, cont,
624 address->address_length, GNUNET_YES, cont, cont_cls); 625 cont_cls);
625 626
626 if (ret == -1) 627 if (ret == -1)
627 { 628 {
@@ -657,7 +658,7 @@ transmit_send_continuation (void *cls,
657 struct NeighbourMapEntry *n; 658 struct NeighbourMapEntry *n;
658 struct NeighbourMapEntry *tmp; 659 struct NeighbourMapEntry *tmp;
659 660
660 tmp = lookup_neighbour(receiver); 661 tmp = lookup_neighbour (receiver);
661 662
662 mq = cls; 663 mq = cls;
663 n = mq->n; 664 n = mq->n;
@@ -720,8 +721,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
720 721
721 if (n->address == NULL) 722 if (n->address == NULL)
722 { 723 {
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n",
724 "No address for peer `%s'\n",
725 GNUNET_i2s (&n->id)); 725 GNUNET_i2s (&n->id));
726 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); 726 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
727 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK); 727 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
@@ -740,8 +740,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
740 740
741 if ((n->address->address_length == 0) && (n->session == NULL)) 741 if ((n->address->address_length == 0) && (n->session == NULL))
742 { 742 {
743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n",
744 "No address for peer `%s'\n",
745 GNUNET_i2s (&n->id)); 744 GNUNET_i2s (&n->id));
746 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); 745 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
747 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK); 746 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
@@ -751,9 +750,8 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
751 750
752 ret = 751 ret =
753 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, 752 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0,
754 timeout, n->session, n->address, 753 timeout, n->session, n->address, GNUNET_YES,
755 GNUNET_YES, &transmit_send_continuation, 754 &transmit_send_continuation, mq);
756 mq);
757 if (ret == -1) 755 if (ret == -1)
758 { 756 {
759 /* failure, but 'send' would not call continuation in this case, 757 /* failure, but 'send' would not call continuation in this case,
@@ -826,7 +824,8 @@ send_disconnect (const struct GNUNET_PeerIdentity *target,
826#endif 824#endif
827 825
828 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); 826 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
829 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 827 disconnect_msg.header.type =
828 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
830 disconnect_msg.reserved = htonl (0); 829 disconnect_msg.reserved = htonl (0);
831 disconnect_msg.purpose.size = 830 disconnect_msg.purpose.size =
832 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 831 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
@@ -846,8 +845,7 @@ send_disconnect (const struct GNUNET_PeerIdentity *target,
846 send_with_plugin (target, (const char *) &disconnect_msg, 845 send_with_plugin (target, (const char *) &disconnect_msg,
847 sizeof (disconnect_msg), UINT32_MAX, 846 sizeof (disconnect_msg), UINT32_MAX,
848 GNUNET_TIME_UNIT_FOREVER_REL, session, address, 847 GNUNET_TIME_UNIT_FOREVER_REL, session, address,
849 GNUNET_YES, 848 GNUNET_YES, &send_disconnect_cont, NULL);
850 &send_disconnect_cont, NULL);
851 849
852 if (ret == GNUNET_SYSERR) 850 if (ret == GNUNET_SYSERR)
853 return GNUNET_SYSERR; 851 return GNUNET_SYSERR;
@@ -880,9 +878,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
880 /* send DISCONNECT MESSAGE */ 878 /* send DISCONNECT MESSAGE */
881 if ((previous_state == S_CONNECTED) || is_connecting (n)) 879 if ((previous_state == S_CONNECTED) || is_connecting (n))
882 { 880 {
883 if (GNUNET_OK == 881 if (GNUNET_OK == send_disconnect (&n->id, n->address, n->session))
884 send_disconnect (&n->id, n->address,
885 n->session))
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", 882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
887 GNUNET_i2s (&n->id)); 883 GNUNET_i2s (&n->id));
888 else 884 else
@@ -898,9 +894,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
898 GNUNET_assert (NULL != n->address); 894 GNUNET_assert (NULL != n->address);
899 if (n->address_state == USED) 895 if (n->address_state == USED)
900 { 896 {
901 GST_validation_set_address_use (&n->id, 897 GST_validation_set_address_use (&n->id, n->address, n->session,
902 n->address,
903 n->session,
904 GNUNET_NO); 898 GNUNET_NO);
905 899
906 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); 900 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO);
@@ -911,6 +905,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
911 if (n->address != NULL) 905 if (n->address != NULL)
912 { 906 {
913 struct GNUNET_TRANSPORT_PluginFunctions *papi; 907 struct GNUNET_TRANSPORT_PluginFunctions *papi;
908
914 papi = GST_plugins_find (n->address->transport_name); 909 papi = GST_plugins_find (n->address->transport_name);
915 if (papi != NULL) 910 if (papi != NULL)
916 papi->disconnect (papi->cls, &n->id); 911 papi->disconnect (papi->cls, &n->id);
@@ -928,27 +923,27 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
928 n->is_active = NULL; 923 n->is_active = NULL;
929 } 924 }
930 925
931 switch (previous_state) { 926 switch (previous_state)
932 case S_CONNECTED: 927 {
928 case S_CONNECTED:
933// GNUNET_assert (neighbours_connected > 0); 929// GNUNET_assert (neighbours_connected > 0);
934 neighbours_connected--; 930 neighbours_connected--;
935 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); 931 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
936 GNUNET_SCHEDULER_cancel (n->keepalive_task); 932 GNUNET_SCHEDULER_cancel (n->keepalive_task);
937 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; 933 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
938 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, 934 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
939 GNUNET_NO); 935 GNUNET_NO);
940 disconnect_notify_cb (callback_cls, &n->id); 936 disconnect_notify_cb (callback_cls, &n->id);
941 break; 937 break;
942 case S_FAST_RECONNECT: 938 case S_FAST_RECONNECT:
943 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, 939 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
944 GNUNET_NO); 940 GNUNET_NO);
945 GNUNET_STATISTICS_update (GST_stats, 941 GNUNET_STATISTICS_update (GST_stats,
946 gettext_noop 942 gettext_noop ("# fast reconnects failed"), 1,
947 ("# fast reconnects failed"), 943 GNUNET_NO);
948 1, GNUNET_NO); 944 disconnect_notify_cb (callback_cls, &n->id);
949 disconnect_notify_cb (callback_cls, &n->id); 945 default:
950 default: 946 break;
951 break;
952 } 947 }
953 948
954 GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id); 949 GNUNET_ATS_suggest_address_cancel (GST_ats, &n->id);
@@ -1030,17 +1025,18 @@ neighbour_keepalive_task (void *cls,
1030 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1025 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1031 1026
1032 1027
1033 ret = send_with_plugin (&n->id, (const void *) &m, sizeof (m), 1028 ret =
1034 UINT32_MAX /* priority */ , 1029 send_with_plugin (&n->id, (const void *) &m, sizeof (m),
1035 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, 1030 UINT32_MAX /* priority */ ,
1036 GNUNET_YES, NULL, NULL); 1031 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address,
1032 GNUNET_YES, NULL, NULL);
1037 1033
1038 n->expect_latency_response = GNUNET_NO; 1034 n->expect_latency_response = GNUNET_NO;
1039 n->keep_alive_sent = GNUNET_TIME_absolute_get_zero(); 1035 n->keep_alive_sent = GNUNET_TIME_absolute_get_zero ();
1040 if (ret != GNUNET_SYSERR) 1036 if (ret != GNUNET_SYSERR)
1041 { 1037 {
1042 n->expect_latency_response = GNUNET_YES; 1038 n->expect_latency_response = GNUNET_YES;
1043 n->keep_alive_sent = GNUNET_TIME_absolute_get(); 1039 n->keep_alive_sent = GNUNET_TIME_absolute_get ();
1044 } 1040 }
1045 1041
1046} 1042}
@@ -1115,19 +1111,22 @@ struct ContinutionContext
1115 struct Session *session; 1111 struct Session *session;
1116}; 1112};
1117 1113
1118static void send_outbound_quota (const struct GNUNET_PeerIdentity *target, struct GNUNET_BANDWIDTH_Value32NBO quota) 1114static void
1115send_outbound_quota (const struct GNUNET_PeerIdentity *target,
1116 struct GNUNET_BANDWIDTH_Value32NBO quota)
1119{ 1117{
1120 struct QuotaSetMessage q_msg; 1118 struct QuotaSetMessage q_msg;
1119
1121#if DEBUG_TRANSPORT 1120#if DEBUG_TRANSPORT
1122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1123 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 1122 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
1124 ntohl (quota.value__), GNUNET_i2s (target)); 1123 ntohl (quota.value__), GNUNET_i2s (target));
1125#endif 1124#endif
1126 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 1125 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
1127 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 1126 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
1128 q_msg.quota = quota; 1127 q_msg.quota = quota;
1129 q_msg.peer = (*target); 1128 q_msg.peer = (*target);
1130 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 1129 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
1131} 1130}
1132 1131
1133/** 1132/**
@@ -1143,17 +1142,15 @@ static void
1143send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target, 1142send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1144 int success) 1143 int success)
1145{ 1144{
1146 struct ContinutionContext * cc = cls; 1145 struct ContinutionContext *cc = cls;
1147 struct NeighbourMapEntry *n = lookup_neighbour (&cc->address->peer); 1146 struct NeighbourMapEntry *n = lookup_neighbour (&cc->address->peer);
1148 1147
1149 if (GNUNET_YES != success) 1148 if (GNUNET_YES != success)
1150 { 1149 {
1151 GNUNET_assert (strlen(cc->address->transport_name) > 0); 1150 GNUNET_assert (strlen (cc->address->transport_name) > 0);
1152 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session); 1151 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session);
1153 } 1152 }
1154 if ( (NULL == neighbours) || 1153 if ((NULL == neighbours) || (NULL == n) || (n->state == S_DISCONNECT))
1155 (NULL == n) ||
1156 (n->state == S_DISCONNECT))
1157 { 1154 {
1158 GNUNET_HELLO_address_free (cc->address); 1155 GNUNET_HELLO_address_free (cc->address);
1159 GNUNET_free (cc); 1156 GNUNET_free (cc);
@@ -1161,7 +1158,7 @@ send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1161 } 1158 }
1162 1159
1163 if ((GNUNET_YES == success) && 1160 if ((GNUNET_YES == success) &&
1164 ((n->state == S_NOT_CONNECTED) || (n->state == S_CONNECT_SENT))) 1161 ((n->state == S_NOT_CONNECTED) || (n->state == S_CONNECT_SENT)))
1165 { 1162 {
1166 change_state (n, S_CONNECT_SENT); 1163 change_state (n, S_CONNECT_SENT);
1167 GNUNET_HELLO_address_free (cc->address); 1164 GNUNET_HELLO_address_free (cc->address);
@@ -1170,21 +1167,19 @@ send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1170 } 1167 }
1171 1168
1172 if ((GNUNET_NO == success) && 1169 if ((GNUNET_NO == success) &&
1173 ((n->state == S_NOT_CONNECTED) || (n->state == S_CONNECT_SENT))) 1170 ((n->state == S_NOT_CONNECTED) || (n->state == S_CONNECT_SENT)))
1174 { 1171 {
1175#if DEBUG_TRANSPORT 1172#if DEBUG_TRANSPORT
1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1177 "Failed to send CONNECT_MSG to peer `%4s' with address '%s' session %p, asking ATS for new address \n", 1174 "Failed to send CONNECT_MSG to peer `%4s' with address '%s' session %p, asking ATS for new address \n",
1178 GNUNET_i2s (&n->id), 1175 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session);
1179 GST_plugins_a2s (n->address),
1180 n->session);
1181#endif 1176#endif
1182 change_state (n, S_NOT_CONNECTED); 1177 change_state (n, S_NOT_CONNECTED);
1183 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1178 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1184 GNUNET_SCHEDULER_cancel (n->ats_suggest); 1179 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1185 n->ats_suggest = 1180 n->ats_suggest =
1186 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, &ats_suggest_cancel, 1181 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, &ats_suggest_cancel,
1187 n); 1182 n);
1188 GNUNET_ATS_suggest_address (GST_ats, &n->id); 1183 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1189 } 1184 }
1190 GNUNET_HELLO_address_free (cc->address); 1185 GNUNET_HELLO_address_free (cc->address);
@@ -1205,7 +1200,7 @@ send_switch_address_continuation (void *cls,
1205 const struct GNUNET_PeerIdentity *target, 1200 const struct GNUNET_PeerIdentity *target,
1206 int success) 1201 int success)
1207{ 1202{
1208 struct ContinutionContext * cc = cls; 1203 struct ContinutionContext *cc = cls;
1209 struct NeighbourMapEntry *n; 1204 struct NeighbourMapEntry *n;
1210 1205
1211 if (neighbours == NULL) 1206 if (neighbours == NULL)
@@ -1215,7 +1210,7 @@ send_switch_address_continuation (void *cls,
1215 return; /* neighbour is going away */ 1210 return; /* neighbour is going away */
1216 } 1211 }
1217 1212
1218 n = lookup_neighbour(&cc->address->peer); 1213 n = lookup_neighbour (&cc->address->peer);
1219 if ((n == NULL) || (is_disconnecting (n))) 1214 if ((n == NULL) || (is_disconnecting (n)))
1220 { 1215 {
1221 GNUNET_HELLO_address_free (cc->address); 1216 GNUNET_HELLO_address_free (cc->address);
@@ -1229,10 +1224,9 @@ send_switch_address_continuation (void *cls,
1229#if DEBUG_TRANSPORT 1224#if DEBUG_TRANSPORT
1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1231 "Failed to switch connected peer `%s' to address '%s' session %X, asking ATS for new address \n", 1226 "Failed to switch connected peer `%s' to address '%s' session %X, asking ATS for new address \n",
1232 GNUNET_i2s (&n->id), 1227 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session);
1233 GST_plugins_a2s (n->address), n->session);
1234#endif 1228#endif
1235 GNUNET_assert (strlen(cc->address->transport_name) > 0); 1229 GNUNET_assert (strlen (cc->address->transport_name) > 0);
1236 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session); 1230 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session);
1237 1231
1238 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1232 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
@@ -1246,49 +1240,48 @@ send_switch_address_continuation (void *cls,
1246 return; 1240 return;
1247 } 1241 }
1248 /* Tell ATS that switching addresses was successful */ 1242 /* Tell ATS that switching addresses was successful */
1249 switch (n->state) { 1243 switch (n->state)
1250 case S_CONNECTED: 1244 {
1251 if (n->address_state == FRESH) 1245 case S_CONNECTED:
1252 { 1246 if (n->address_state == FRESH)
1253 GST_validation_set_address_use (&n->id, 1247 {
1254 cc->address, 1248 GST_validation_set_address_use (&n->id, cc->address, cc->session,
1255 cc->session, 1249 GNUNET_YES);
1256 GNUNET_YES); 1250 GNUNET_ATS_address_update (GST_ats, cc->address, cc->session, NULL, 0);
1257 GNUNET_ATS_address_update (GST_ats, cc->address, cc->session, NULL, 0); 1251 GNUNET_ATS_address_in_use (GST_ats, cc->address, cc->session, GNUNET_YES);
1258 GNUNET_ATS_address_in_use (GST_ats, cc->address, cc->session, GNUNET_YES); 1252 n->address_state = USED;
1259 n->address_state = USED; 1253 }
1260 } 1254 break;
1261 break; 1255 case S_FAST_RECONNECT:
1262 case S_FAST_RECONNECT:
1263#if DEBUG_TRANSPORT 1256#if DEBUG_TRANSPORT
1264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1265 "Successful fast reconnect to peer `%s'\n", GNUNET_i2s (&n->id)); 1258 "Successful fast reconnect to peer `%s'\n",
1259 GNUNET_i2s (&n->id));
1266#endif 1260#endif
1267 change_state (n, S_CONNECTED); 1261 change_state (n, S_CONNECTED);
1268 neighbours_connected++; 1262 neighbours_connected++;
1269 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 1263 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
1270 GNUNET_NO); 1264 GNUNET_NO);
1271 1265
1272 if (n->address_state == FRESH) 1266 if (n->address_state == FRESH)
1273 { 1267 {
1274 GST_validation_set_address_use (&n->id, 1268 GST_validation_set_address_use (&n->id, cc->address, cc->session,
1275 cc->address, 1269 GNUNET_YES);
1276 cc->session, 1270 GNUNET_ATS_address_update (GST_ats, cc->address, cc->session, NULL, 0);
1277 GNUNET_YES); 1271 GNUNET_ATS_address_in_use (GST_ats, cc->address, cc->session, GNUNET_YES);
1278 GNUNET_ATS_address_update (GST_ats, cc->address, cc->session, NULL, 0); 1272 n->address_state = USED;
1279 GNUNET_ATS_address_in_use (GST_ats, cc->address, cc->session, GNUNET_YES); 1273 }
1280 n->address_state = USED; 1274
1281 } 1275 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
1282 1276 n->keepalive_task =
1283 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 1277 GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n);
1284 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n); 1278
1285 1279 /* Updating quotas */
1286 /* Updating quotas */ 1280 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
1287 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); 1281 send_outbound_quota (target, n->bandwidth_out);
1288 send_outbound_quota(target, n->bandwidth_out); 1282
1289 1283 default:
1290 default: 1284 break;
1291 break;
1292 } 1285 }
1293 GNUNET_HELLO_address_free (cc->address); 1286 GNUNET_HELLO_address_free (cc->address);
1294 GNUNET_free (cc); 1287 GNUNET_free (cc);
@@ -1309,7 +1302,7 @@ send_connect_ack_continuation (void *cls,
1309 const struct GNUNET_PeerIdentity *target, 1302 const struct GNUNET_PeerIdentity *target,
1310 int success) 1303 int success)
1311{ 1304{
1312 struct ContinutionContext * cc = cls; 1305 struct ContinutionContext *cc = cls;
1313 struct NeighbourMapEntry *n; 1306 struct NeighbourMapEntry *n;
1314 1307
1315 if (neighbours == NULL) 1308 if (neighbours == NULL)
@@ -1319,7 +1312,7 @@ send_connect_ack_continuation (void *cls,
1319 return; /* neighbour is going away */ 1312 return; /* neighbour is going away */
1320 } 1313 }
1321 1314
1322 n = lookup_neighbour(&cc->address->peer); 1315 n = lookup_neighbour (&cc->address->peer);
1323 if ((n == NULL) || (is_disconnecting (n))) 1316 if ((n == NULL) || (is_disconnecting (n)))
1324 { 1317 {
1325 GNUNET_HELLO_address_free (cc->address); 1318 GNUNET_HELLO_address_free (cc->address);
@@ -1338,12 +1331,10 @@ send_connect_ack_continuation (void *cls,
1338#if DEBUG_TRANSPORT 1331#if DEBUG_TRANSPORT
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1340 "Failed to send CONNECT_MSG to peer `%4s' with address '%s' session %X, asking ATS for new address \n", 1333 "Failed to send CONNECT_MSG to peer `%4s' with address '%s' session %X, asking ATS for new address \n",
1341 GNUNET_i2s (&n->id), 1334 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session);
1342 GST_plugins_a2s (n->address),
1343 n->session);
1344#endif 1335#endif
1345 change_state (n, S_NOT_CONNECTED); 1336 change_state (n, S_NOT_CONNECTED);
1346 GNUNET_assert (strlen(cc->address->transport_name) > 0); 1337 GNUNET_assert (strlen (cc->address->transport_name) > 0);
1347 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session); 1338 GNUNET_ATS_address_destroyed (GST_ats, cc->address, cc->session);
1348 1339
1349 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1340 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
@@ -1372,8 +1363,8 @@ send_connect_ack_continuation (void *cls,
1372 */ 1363 */
1373int 1364int
1374GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, 1365GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1375 const struct GNUNET_HELLO_Address *address, 1366 const struct GNUNET_HELLO_Address
1376 struct Session *session, 1367 *address, struct Session *session,
1377 const struct GNUNET_ATS_Information *ats, 1368 const struct GNUNET_ATS_Information *ats,
1378 uint32_t ats_count, 1369 uint32_t ats_count,
1379 struct GNUNET_BANDWIDTH_Value32NBO 1370 struct GNUNET_BANDWIDTH_Value32NBO
@@ -1383,7 +1374,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1383{ 1374{
1384 struct NeighbourMapEntry *n; 1375 struct NeighbourMapEntry *n;
1385 struct SessionConnectMessage connect_msg; 1376 struct SessionConnectMessage connect_msg;
1386 struct ContinutionContext * cc; 1377 struct ContinutionContext *cc;
1387 size_t msg_len; 1378 size_t msg_len;
1388 size_t ret; 1379 size_t ret;
1389 1380
@@ -1401,11 +1392,11 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1401 return GNUNET_NO; 1392 return GNUNET_NO;
1402 } 1393 }
1403 GNUNET_assert (address->transport_name != NULL); 1394 GNUNET_assert (address->transport_name != NULL);
1404 if ( (session == NULL) && (0 == address->address_length) ) 1395 if ((session == NULL) && (0 == address->address_length))
1405 { 1396 {
1406 GNUNET_break_op (0); 1397 GNUNET_break_op (0);
1407 /* FIXME: is this actually possible? When does this happen? */ 1398 /* FIXME: is this actually possible? When does this happen? */
1408 if (strlen(address->transport_name) > 0) 1399 if (strlen (address->transport_name) > 0)
1409 GNUNET_ATS_address_destroyed (GST_ats, address, session); 1400 GNUNET_ATS_address_destroyed (GST_ats, address, session);
1410 GNUNET_ATS_suggest_address (GST_ats, peer); 1401 GNUNET_ATS_suggest_address (GST_ats, peer);
1411 return GNUNET_NO; 1402 return GNUNET_NO;
@@ -1415,10 +1406,8 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1415#if DEBUG_TRANSPORT 1406#if DEBUG_TRANSPORT
1416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1407 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1417 "ATS tells us to switch to address '%s' session %p for peer `%s' in state `%s'\n", 1408 "ATS tells us to switch to address '%s' session %p for peer `%s' in state `%s'\n",
1418 GST_plugins_a2s (address), 1409 GST_plugins_a2s (address), session, GNUNET_i2s (peer),
1419 session, 1410 print_state (n->state));
1420 GNUNET_i2s (peer),
1421 print_state(n->state));
1422#endif 1411#endif
1423 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1412 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1424 { 1413 {
@@ -1426,17 +1415,15 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1426 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; 1415 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK;
1427 } 1416 }
1428 /* do not switch addresses just update quotas */ 1417 /* do not switch addresses just update quotas */
1429 if ( (n->state == S_CONNECTED) && 1418 if ((n->state == S_CONNECTED) && (NULL != n->address) &&
1430 (NULL != n->address) && 1419 (0 == GNUNET_HELLO_address_cmp (address, n->address)) &&
1431 (0 == GNUNET_HELLO_address_cmp (address, 1420 (n->session == session))
1432 n->address)) &&
1433 (n->session == session) )
1434 { 1421 {
1435 n->bandwidth_in = bandwidth_in; 1422 n->bandwidth_in = bandwidth_in;
1436 n->bandwidth_out = bandwidth_out; 1423 n->bandwidth_out = bandwidth_out;
1437 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); 1424 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
1438 send_outbound_quota(peer, n->bandwidth_out); 1425 send_outbound_quota (peer, n->bandwidth_out);
1439 return GNUNET_NO; 1426 return GNUNET_NO;
1440 } 1427 }
1441 if (n->state == S_CONNECTED) 1428 if (n->state == S_CONNECTED)
1442 { 1429 {
@@ -1444,9 +1431,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1444 GNUNET_assert (NULL != n->address); 1431 GNUNET_assert (NULL != n->address);
1445 if (n->address_state == USED) 1432 if (n->address_state == USED)
1446 { 1433 {
1447 GST_validation_set_address_use (&n->id, 1434 GST_validation_set_address_use (&n->id, n->address, n->session,
1448 n->address,
1449 n->session,
1450 GNUNET_NO); 1435 GNUNET_NO);
1451 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); 1436 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO);
1452 n->address_state = UNUSED; 1437 n->address_state = UNUSED;
@@ -1468,7 +1453,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1468 &neighbour_timeout_task, n); 1453 &neighbour_timeout_task, n);
1469 switch (n->state) 1454 switch (n->state)
1470 { 1455 {
1471 case S_NOT_CONNECTED: 1456 case S_NOT_CONNECTED:
1472 case S_CONNECT_SENT: 1457 case S_CONNECT_SENT:
1473 msg_len = sizeof (struct SessionConnectMessage); 1458 msg_len = sizeof (struct SessionConnectMessage);
1474 connect_msg.header.size = htons (msg_len); 1459 connect_msg.header.size = htons (msg_len);
@@ -1478,15 +1463,13 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1478 connect_msg.timestamp = 1463 connect_msg.timestamp =
1479 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1464 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1480 1465
1481 cc = GNUNET_malloc(sizeof (struct ContinutionContext)); 1466 cc = GNUNET_malloc (sizeof (struct ContinutionContext));
1482 cc->session = session; 1467 cc->session = session;
1483 cc->address = GNUNET_HELLO_address_copy (address); 1468 cc->address = GNUNET_HELLO_address_copy (address);
1484 ret = 1469 ret =
1485 send_with_plugin (peer, (const char *) &connect_msg, msg_len, 1470 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1486 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1471 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1487 address, GNUNET_YES, 1472 address, GNUNET_YES, &send_connect_continuation, cc);
1488 &send_connect_continuation,
1489 cc);
1490 return GNUNET_NO; 1473 return GNUNET_NO;
1491 case S_CONNECT_RECV: 1474 case S_CONNECT_RECV:
1492 /* We received a CONNECT message and asked ATS for an address */ 1475 /* We received a CONNECT message and asked ATS for an address */
@@ -1497,18 +1480,18 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1497 connect_msg.reserved = htonl (0); 1480 connect_msg.reserved = htonl (0);
1498 connect_msg.timestamp = 1481 connect_msg.timestamp =
1499 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1482 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1500 cc = GNUNET_malloc(sizeof (struct ContinutionContext)); 1483 cc = GNUNET_malloc (sizeof (struct ContinutionContext));
1501 cc->session = session; 1484 cc->session = session;
1502 cc->address = GNUNET_HELLO_address_copy (address); 1485 cc->address = GNUNET_HELLO_address_copy (address);
1503 ret = 1486 ret =
1504 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, 1487 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len,
1505 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, 1488 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1506 address, GNUNET_YES, 1489 address, GNUNET_YES, &send_connect_ack_continuation,
1507 &send_connect_ack_continuation, cc); 1490 cc);
1508 return GNUNET_NO; 1491 return GNUNET_NO;
1509 case S_CONNECTED: 1492 case S_CONNECTED:
1510 case S_FAST_RECONNECT: 1493 case S_FAST_RECONNECT:
1511 /* connected peer is switching addresses or tries fast reconnect*/ 1494 /* connected peer is switching addresses or tries fast reconnect */
1512 msg_len = sizeof (struct SessionConnectMessage); 1495 msg_len = sizeof (struct SessionConnectMessage);
1513 connect_msg.header.size = htons (msg_len); 1496 connect_msg.header.size = htons (msg_len);
1514 connect_msg.header.type = 1497 connect_msg.header.type =
@@ -1516,7 +1499,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1516 connect_msg.reserved = htonl (0); 1499 connect_msg.reserved = htonl (0);
1517 connect_msg.timestamp = 1500 connect_msg.timestamp =
1518 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1501 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1519 cc = GNUNET_malloc(sizeof (struct ContinutionContext)); 1502 cc = GNUNET_malloc (sizeof (struct ContinutionContext));
1520 cc->session = session; 1503 cc->session = session;
1521 cc->address = GNUNET_HELLO_address_copy (address); 1504 cc->address = GNUNET_HELLO_address_copy (address);
1522 ret = 1505 ret =
@@ -1528,13 +1511,12 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1528 { 1511 {
1529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1530 "Failed to send CONNECT_MESSAGE to `%4s' using address '%s' session %X\n", 1513 "Failed to send CONNECT_MESSAGE to `%4s' using address '%s' session %X\n",
1531 GNUNET_i2s (peer), 1514 GNUNET_i2s (peer), GST_plugins_a2s (address), session);
1532 GST_plugins_a2s (address), session);
1533 } 1515 }
1534 return GNUNET_NO; 1516 return GNUNET_NO;
1535 default: 1517 default:
1536 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1518 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1537 "Invalid connection state to switch addresses %u \n", n->state); 1519 "Invalid connection state to switch addresses %u \n", n->state);
1538 GNUNET_break_op (0); 1520 GNUNET_break_op (0);
1539 return GNUNET_NO; 1521 return GNUNET_NO;
1540 } 1522 }
@@ -1544,7 +1526,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1544/** 1526/**
1545 * Obtain current latency information for the given neighbour. 1527 * Obtain current latency information for the given neighbour.
1546 * 1528 *
1547 * @param peer 1529 * @param peer
1548 * @return observed latency of the address, FOREVER if the address was 1530 * @return observed latency of the address, FOREVER if the address was
1549 * never successfully validated 1531 * never successfully validated
1550 */ 1532 */
@@ -1554,8 +1536,7 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer)
1554 struct NeighbourMapEntry *n; 1536 struct NeighbourMapEntry *n;
1555 1537
1556 n = lookup_neighbour (peer); 1538 n = lookup_neighbour (peer);
1557 if ( (NULL == n) || 1539 if ((NULL == n) || ((n->address == NULL) && (n->session == NULL)))
1558 ( (n->address == NULL) && (n->session == NULL) ) )
1559 return GNUNET_TIME_UNIT_FOREVER_REL; 1540 return GNUNET_TIME_UNIT_FOREVER_REL;
1560 1541
1561 return n->latency; 1542 return n->latency;
@@ -1573,8 +1554,7 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
1573 struct NeighbourMapEntry *n; 1554 struct NeighbourMapEntry *n;
1574 1555
1575 n = lookup_neighbour (peer); 1556 n = lookup_neighbour (peer);
1576 if ( (NULL == n) || 1557 if ((NULL == n) || ((n->address == NULL) && (n->session == NULL)))
1577 ( (n->address == NULL) && (n->session == NULL) ) )
1578 return NULL; 1558 return NULL;
1579 1559
1580 return n->address; 1560 return n->address;
@@ -1600,7 +1580,7 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
1600 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 1580 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
1601 n->id = *peer; 1581 n->id = *peer;
1602 n->state = S_NOT_CONNECTED; 1582 n->state = S_NOT_CONNECTED;
1603 n->latency = GNUNET_TIME_relative_get_forever(); 1583 n->latency = GNUNET_TIME_relative_get_forever ();
1604 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 1584 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
1605 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 1585 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
1606 MAX_BANDWIDTH_CARRY_S); 1586 MAX_BANDWIDTH_CARRY_S);
@@ -1718,11 +1698,9 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1718 { 1698 {
1719 if (n->address_state == USED) 1699 if (n->address_state == USED)
1720 { 1700 {
1721 GST_validation_set_address_use (&n->id, 1701 GST_validation_set_address_use (&n->id, n->address, n->session,
1722 n->address,
1723 n->session,
1724 GNUNET_NO); 1702 GNUNET_NO);
1725 GNUNET_ATS_address_in_use (GST_ats,n->address, n->session, GNUNET_NO); 1703 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO);
1726 n->address_state = UNUSED; 1704 n->address_state = UNUSED;
1727 } 1705 }
1728 } 1706 }
@@ -1733,15 +1711,15 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1733 n->address = NULL; 1711 n->address = NULL;
1734 } 1712 }
1735 n->session = NULL; 1713 n->session = NULL;
1736 1714
1737 /* not connected anymore anyway, shouldn't matter */ 1715 /* not connected anymore anyway, shouldn't matter */
1738 if (S_CONNECTED != n->state) 1716 if (S_CONNECTED != n->state)
1739 return; 1717 return;
1740 1718
1741 /* connected, try fast reconnect */ 1719 /* connected, try fast reconnect */
1742#if DEBUG_TRANSPORT 1720#if DEBUG_TRANSPORT
1743 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying fast reconnect to peer `%s'\n",
1744 "Trying fast reconnect to peer `%s'\n", GNUNET_i2s (peer)); 1722 GNUNET_i2s (peer));
1745#endif 1723#endif
1746 change_state (n, S_FAST_RECONNECT); 1724 change_state (n, S_FAST_RECONNECT);
1747 GNUNET_assert (neighbours_connected > 0); 1725 GNUNET_assert (neighbours_connected > 0);
@@ -1814,7 +1792,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1814 return; 1792 return;
1815 } 1793 }
1816 1794
1817 if ((n->session == NULL) && (n->address == NULL) ) 1795 if ((n->session == NULL) && (n->address == NULL))
1818 { 1796 {
1819 GNUNET_STATISTICS_update (GST_stats, 1797 GNUNET_STATISTICS_update (GST_stats,
1820 gettext_noop 1798 gettext_noop
@@ -1983,6 +1961,7 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
1983 return; 1961 return;
1984 1962
1985 struct GNUNET_MessageHeader m; 1963 struct GNUNET_MessageHeader m;
1964
1986 m.size = htons (sizeof (struct GNUNET_MessageHeader)); 1965 m.size = htons (sizeof (struct GNUNET_MessageHeader));
1987 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 1966 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1988 1967
@@ -2002,11 +1981,11 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
2002 */ 1981 */
2003void 1982void
2004GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, 1983GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
2005 const struct GNUNET_ATS_Information * ats, 1984 const struct GNUNET_ATS_Information *ats,
2006 uint32_t ats_count) 1985 uint32_t ats_count)
2007{ 1986{
2008 struct NeighbourMapEntry *n; 1987 struct NeighbourMapEntry *n;
2009 struct GNUNET_ATS_Information * ats_new; 1988 struct GNUNET_ATS_Information *ats_new;
2010 uint32_t latency; 1989 uint32_t latency;
2011 1990
2012 if (neighbours == NULL) 1991 if (neighbours == NULL)
@@ -2034,22 +2013,26 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
2034 } 2013 }
2035 n->expect_latency_response = GNUNET_NO; 2014 n->expect_latency_response = GNUNET_NO;
2036 2015
2037 GNUNET_assert (n->keep_alive_sent.abs_value != GNUNET_TIME_absolute_get_zero().abs_value); 2016 GNUNET_assert (n->keep_alive_sent.abs_value !=
2038 n->latency = GNUNET_TIME_absolute_get_difference(n->keep_alive_sent, GNUNET_TIME_absolute_get()); 2017 GNUNET_TIME_absolute_get_zero ().abs_value);
2018 n->latency =
2019 GNUNET_TIME_absolute_get_difference (n->keep_alive_sent,
2020 GNUNET_TIME_absolute_get ());
2039#if DEBUG_TRANSPORT 2021#if DEBUG_TRANSPORT
2040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Latency for peer `%s' is %llu ms\n",
2041 "Latency for peer `%s' is %llu ms\n",
2042 GNUNET_i2s (&n->id), n->latency.rel_value); 2023 GNUNET_i2s (&n->id), n->latency.rel_value);
2043#endif 2024#endif
2044 2025
2045 2026
2046 if (n->latency.rel_value == GNUNET_TIME_relative_get_forever().rel_value) 2027 if (n->latency.rel_value == GNUNET_TIME_relative_get_forever ().rel_value)
2047 { 2028 {
2048 GNUNET_ATS_address_update (GST_ats, n->address, n->session, ats, ats_count); 2029 GNUNET_ATS_address_update (GST_ats, n->address, n->session, ats, ats_count);
2049 } 2030 }
2050 else 2031 else
2051 { 2032 {
2052 ats_new = GNUNET_malloc (sizeof (struct GNUNET_ATS_Information) * (ats_count + 1)); 2033 ats_new =
2034 GNUNET_malloc (sizeof (struct GNUNET_ATS_Information) *
2035 (ats_count + 1));
2053 memcpy (ats_new, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); 2036 memcpy (ats_new, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2054 2037
2055 /* add latency */ 2038 /* add latency */
@@ -2060,7 +2043,8 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
2060 latency = n->latency.rel_value; 2043 latency = n->latency.rel_value;
2061 ats_new[ats_count].value = htonl (latency); 2044 ats_new[ats_count].value = htonl (latency);
2062 2045
2063 GNUNET_ATS_address_update (GST_ats, n->address, n->session, ats_new, ats_count + 1); 2046 GNUNET_ATS_address_update (GST_ats, n->address, n->session, ats_new,
2047 ats_count + 1);
2064 GNUNET_free (ats_new); 2048 GNUNET_free (ats_new);
2065 } 2049 }
2066} 2050}
@@ -2314,10 +2298,11 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2314 { 2298 {
2315 /* we did not send 'CONNECT' -- at least not recently */ 2299 /* we did not send 'CONNECT' -- at least not recently */
2316 GNUNET_STATISTICS_update (GST_stats, 2300 GNUNET_STATISTICS_update (GST_stats,
2317 gettext_noop ("# unexpected CONNECT_ACK messages (no peer)"), 1, 2301 gettext_noop
2318 GNUNET_NO); 2302 ("# unexpected CONNECT_ACK messages (no peer)"),
2303 1, GNUNET_NO);
2319 return; 2304 return;
2320 } 2305 }
2321 2306
2322 /* Additional check 2307 /* Additional check
2323 * 2308 *
@@ -2326,11 +2311,13 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2326 * We also received an CONNECT message, switched from SENDT to RECV and 2311 * We also received an CONNECT message, switched from SENDT to RECV and
2327 * ATS already suggested us an address after a successful blacklist check 2312 * ATS already suggested us an address after a successful blacklist check
2328 */ 2313 */
2329 if ((n->state != S_CONNECT_SENT) && ((n->state != S_CONNECT_RECV) && (n->address != NULL))) 2314 if ((n->state != S_CONNECT_SENT) &&
2315 ((n->state != S_CONNECT_RECV) && (n->address != NULL)))
2330 { 2316 {
2331 GNUNET_STATISTICS_update (GST_stats, 2317 GNUNET_STATISTICS_update (GST_stats,
2332 gettext_noop ("# unexpected CONNECT_ACK messages"), 1, 2318 gettext_noop
2333 GNUNET_NO); 2319 ("# unexpected CONNECT_ACK messages"), 1,
2320 GNUNET_NO);
2334 return; 2321 return;
2335 } 2322 }
2336 2323
@@ -2347,10 +2334,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2347 GNUNET_assert (NULL != n->address); 2334 GNUNET_assert (NULL != n->address);
2348 if (n->address_state == FRESH) 2335 if (n->address_state == FRESH)
2349 { 2336 {
2350 GST_validation_set_address_use (&n->id, 2337 GST_validation_set_address_use (&n->id, n->address, n->session, GNUNET_YES);
2351 n->address,
2352 n->session,
2353 GNUNET_YES);
2354 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES); 2338 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES);
2355 n->address_state = USED; 2339 n->address_state = USED;
2356 } 2340 }
@@ -2364,32 +2348,29 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2364 2348
2365 ret = 2349 ret =
2366 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, 2350 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
2367 GNUNET_TIME_UNIT_FOREVER_REL, n->session, 2351 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address,
2368 n->address, GNUNET_YES, NULL, 2352 GNUNET_YES, NULL, NULL);
2369 NULL);
2370 2353
2371 if (ret == GNUNET_SYSERR) 2354 if (ret == GNUNET_SYSERR)
2372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2373 "Failed to send SESSION_ACK to `%4s' using address '%s' session %X\n", 2356 "Failed to send SESSION_ACK to `%4s' using address '%s' session %X\n",
2374 GNUNET_i2s (&n->id), 2357 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session);
2375 GST_plugins_a2s (n->address), n->session);
2376 2358
2377 2359
2378 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2360 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2379 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n); 2361 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n);
2380 2362
2381 neighbours_connected++; 2363 neighbours_connected++;
2382 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2364 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2383 GNUNET_NO); 2365 GNUNET_NO);
2384#if DEBUG_TRANSPORT 2366#if DEBUG_TRANSPORT
2385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2386 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", 2368 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n",
2387 GNUNET_i2s (&n->id), 2369 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session,
2388 GST_plugins_a2s (n->address), n->session, 2370 __LINE__);
2389 __LINE__);
2390#endif 2371#endif
2391 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2372 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2392 send_outbound_quota(peer, n->bandwidth_out); 2373 send_outbound_quota (peer, n->bandwidth_out);
2393 2374
2394} 2375}
2395 2376
@@ -2398,15 +2379,14 @@ void
2398GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, 2379GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2399 const struct GNUNET_PeerIdentity *peer, 2380 const struct GNUNET_PeerIdentity *peer,
2400 const struct GNUNET_HELLO_Address *address, 2381 const struct GNUNET_HELLO_Address *address,
2401 struct Session *session, 2382 struct Session *session,
2402 const struct GNUNET_ATS_Information *ats, 2383 const struct GNUNET_ATS_Information *ats,
2403 uint32_t ats_count) 2384 uint32_t ats_count)
2404{ 2385{
2405 struct NeighbourMapEntry *n; 2386 struct NeighbourMapEntry *n;
2406 2387
2407#if DEBUG_TRANSPORT 2388#if DEBUG_TRANSPORT
2408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK message from peer `%s'\n",
2409 "Received ACK message from peer `%s'\n",
2410 GNUNET_i2s (peer)); 2390 GNUNET_i2s (peer));
2411#endif 2391#endif
2412 2392
@@ -2418,16 +2398,16 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2418 n = lookup_neighbour (peer); 2398 n = lookup_neighbour (peer);
2419 if (NULL == n) 2399 if (NULL == n)
2420 { 2400 {
2421 send_disconnect (peer, address, 2401 send_disconnect (peer, address, session);
2422 session);
2423 GNUNET_break (0); 2402 GNUNET_break (0);
2424 return; 2403 return;
2425 } 2404 }
2426 if (S_CONNECTED == n->state) 2405 if (S_CONNECTED == n->state)
2427 return; 2406 return;
2428 if (!is_connecting(n)) 2407 if (!is_connecting (n))
2429 { 2408 {
2430 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# unexpected ACK messages"), 1, 2409 GNUNET_STATISTICS_update (GST_stats,
2410 gettext_noop ("# unexpected ACK messages"), 1,
2431 GNUNET_NO); 2411 GNUNET_NO);
2432 return; 2412 return;
2433 } 2413 }
@@ -2441,30 +2421,26 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2441 GNUNET_assert (n->address != NULL); 2421 GNUNET_assert (n->address != NULL);
2442 if (n->address_state == FRESH) 2422 if (n->address_state == FRESH)
2443 { 2423 {
2444 GST_validation_set_address_use (&n->id, 2424 GST_validation_set_address_use (&n->id, n->address, n->session, GNUNET_YES);
2445 n->address,
2446 n->session,
2447 GNUNET_YES);
2448 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES); 2425 GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES);
2449 n->address_state = USED; 2426 n->address_state = USED;
2450 } 2427 }
2451 2428
2452 neighbours_connected++; 2429 neighbours_connected++;
2453 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2430 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2454 GNUNET_NO); 2431 GNUNET_NO);
2455 2432
2456 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); 2433 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2457 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2434 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2458 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n); 2435 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, n);
2459#if DEBUG_TRANSPORT 2436#if DEBUG_TRANSPORT
2460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2461 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", 2438 "Notify about connect of `%4s' using address '%s' session %X LINE %u\n",
2462 GNUNET_i2s (&n->id), 2439 GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), n->session,
2463 GST_plugins_a2s (n->address), n->session, 2440 __LINE__);
2464 __LINE__);
2465#endif 2441#endif
2466 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2442 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2467 send_outbound_quota(peer, n->bandwidth_out); 2443 send_outbound_quota (peer, n->bandwidth_out);
2468} 2444}
2469 2445
2470struct BlackListCheckContext 2446struct BlackListCheckContext
@@ -2514,15 +2490,11 @@ handle_connect_blacklist_cont (void *cls,
2514 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2490 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2515 "transport-ats", 2491 "transport-ats",
2516 "Giving ATS session %p of address `%s' for peer %s\n", 2492 "Giving ATS session %p of address `%s' for peer %s\n",
2517 bcc->session, 2493 bcc->session, GST_plugins_a2s (bcc->address),
2518 GST_plugins_a2s (bcc->address),
2519 GNUNET_i2s (peer)); 2494 GNUNET_i2s (peer));
2520 /* Tell ATS about the session, so ATS can suggest it if it likes it. */ 2495 /* Tell ATS about the session, so ATS can suggest it if it likes it. */
2521 2496
2522 GNUNET_ATS_address_update (GST_ats, 2497 GNUNET_ATS_address_update (GST_ats, bcc->address, bcc->session, bcc->ats,
2523 bcc->address,
2524 bcc->session,
2525 bcc->ats,
2526 bcc->ats_count); 2498 bcc->ats_count);
2527 n->connect_ts = bcc->ts; 2499 n->connect_ts = bcc->ts;
2528 } 2500 }
@@ -2584,10 +2556,10 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2584 GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); 2556 GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count);
2585 2557
2586 n = lookup_neighbour (peer); 2558 n = lookup_neighbour (peer);
2587 if ( (n != NULL) && (S_CONNECTED == n->state) ) 2559 if ((n != NULL) && (S_CONNECTED == n->state))
2588 { 2560 {
2589 /* connected peer switches addresses */ 2561 /* connected peer switches addresses */
2590 return; 2562 return;
2591 } 2563 }
2592 2564
2593 2565
@@ -2603,9 +2575,10 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2603 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; 2575 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
2604 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); 2576 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2605 bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 2577 bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
2606 bcc->ats[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value); 2578 bcc->ats[ats_count].value =
2607 GST_blacklist_test_allowed (peer, address->transport_name, handle_connect_blacklist_cont, 2579 htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value);
2608 bcc); 2580 GST_blacklist_test_allowed (peer, address->transport_name,
2581 handle_connect_blacklist_cont, bcc);
2609} 2582}
2610 2583
2611 2584