diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-27 16:10:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-27 16:10:59 +0000 |
commit | 3d3292c7884b7ce1b7332e121c773c9330346240 (patch) | |
tree | 8ebe170684d6ea65836892d7ec76404d949b19bd | |
parent | e30ac844b6227d13a431c9377625852b97a6472f (diff) | |
download | gnunet-3d3292c7884b7ce1b7332e121c773c9330346240.tar.gz gnunet-3d3292c7884b7ce1b7332e121c773c9330346240.zip |
quota propagation
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours_fsm.c | 212 |
1 files changed, 146 insertions, 66 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours_fsm.c b/src/transport/gnunet-service-transport_neighbours_fsm.c index 862608004..6923ae1e7 100644 --- a/src/transport/gnunet-service-transport_neighbours_fsm.c +++ b/src/transport/gnunet-service-transport_neighbours_fsm.c | |||
@@ -270,6 +270,16 @@ struct NeighbourMapEntry | |||
270 | struct GNUNET_BANDWIDTH_Tracker in_tracker; | 270 | struct GNUNET_BANDWIDTH_Tracker in_tracker; |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Inbound bandwidth from ATS, activated when connection is up | ||
274 | */ | ||
275 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
276 | |||
277 | /** | ||
278 | * Inbound bandwidth from ATS, activated when connection is up | ||
279 | */ | ||
280 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
281 | |||
282 | /** | ||
273 | * Timestamp of the 'SESSION_CONNECT' message we got from the other peer | 283 | * Timestamp of the 'SESSION_CONNECT' message we got from the other peer |
274 | */ | 284 | */ |
275 | struct GNUNET_TIME_Absolute connect_ts; | 285 | struct GNUNET_TIME_Absolute connect_ts; |
@@ -286,10 +296,6 @@ struct NeighbourMapEntry | |||
286 | */ | 296 | */ |
287 | //unsigned int ats_count; | 297 | //unsigned int ats_count; |
288 | 298 | ||
289 | /** | ||
290 | * Are we already in the process of disconnecting this neighbour? | ||
291 | */ | ||
292 | int in_disconnect; | ||
293 | 299 | ||
294 | /** | 300 | /** |
295 | * Do we currently consider this neighbour connected? (as far as | 301 | * Do we currently consider this neighbour connected? (as far as |
@@ -404,15 +410,16 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
404 | int allowed = GNUNET_NO; | 410 | int allowed = GNUNET_NO; |
405 | switch (n->state) { | 411 | switch (n->state) { |
406 | case S_NOT_CONNECTED: | 412 | case S_NOT_CONNECTED: |
407 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT)) | 413 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || |
414 | (state == S_DISCONNECT)) | ||
408 | { | 415 | { |
409 | allowed = GNUNET_YES; | 416 | allowed = GNUNET_YES; |
410 | break; | 417 | break; |
411 | } | 418 | } |
412 | break; | 419 | break; |
413 | case S_CONNECT_RECV: | 420 | case S_CONNECT_RECV: |
414 | if ((state == S_CONNECT_RECV_ACK_SENT) || (state == S_NOT_CONNECTED) || | 421 | if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || |
415 | (state == S_DISCONNECT) || (state == S_CONNECTED)) | 422 | (state == S_CONNECTED)) |
416 | { | 423 | { |
417 | allowed = GNUNET_YES; | 424 | allowed = GNUNET_YES; |
418 | break; | 425 | break; |
@@ -427,18 +434,19 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
427 | } | 434 | } |
428 | break; | 435 | break; |
429 | case S_CONNECTED: | 436 | case S_CONNECTED: |
430 | if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT)) | 437 | if (state == S_DISCONNECT) |
431 | { | 438 | { |
432 | allowed = GNUNET_YES; | 439 | allowed = GNUNET_YES; |
433 | break; | 440 | break; |
434 | } | 441 | } |
435 | break; | 442 | break; |
436 | case S_DISCONNECT: | 443 | case S_DISCONNECT: |
444 | /* | ||
437 | if (state == S_NOT_CONNECTED) | 445 | if (state == S_NOT_CONNECTED) |
438 | { | 446 | { |
439 | allowed = GNUNET_YES; | 447 | allowed = GNUNET_YES; |
440 | break; | 448 | break; |
441 | } | 449 | }*/ |
442 | break; | 450 | break; |
443 | default: | 451 | default: |
444 | GNUNET_break (0); | 452 | GNUNET_break (0); |
@@ -546,10 +554,11 @@ transmit_send_continuation (void *cls, | |||
546 | n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n); | 554 | n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n); |
547 | } | 555 | } |
548 | } | 556 | } |
549 | 557 | #if DEBUG_TRANSPORT | |
550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending message of type %u had result: %u\n", | 558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message of type %u was %s\n", |
551 | ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), success); | 559 | ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), |
552 | 560 | (success == GNUNET_OK) ? "successful" : "FAILED"); | |
561 | #endif | ||
553 | if (NULL != mq->cont) | 562 | if (NULL != mq->cont) |
554 | mq->cont (mq->cont_cls, success); | 563 | mq->cont (mq->cont_cls, success); |
555 | GNUNET_free (mq); | 564 | GNUNET_free (mq); |
@@ -660,6 +669,7 @@ GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb, | |||
660 | neighbours = GNUNET_CONTAINER_multihashmap_create (NEIGHBOUR_TABLE_SIZE); | 669 | neighbours = GNUNET_CONTAINER_multihashmap_create (NEIGHBOUR_TABLE_SIZE); |
661 | } | 670 | } |
662 | 671 | ||
672 | /* | ||
663 | static void | 673 | static void |
664 | send_disconnect_cont (void *cls, | 674 | send_disconnect_cont (void *cls, |
665 | const struct GNUNET_PeerIdentity * target, | 675 | const struct GNUNET_PeerIdentity * target, |
@@ -667,11 +677,7 @@ send_disconnect_cont (void *cls, | |||
667 | { | 677 | { |
668 | struct NeighbourMapEntry *n = cls; | 678 | struct NeighbourMapEntry *n = cls; |
669 | 679 | ||
670 | if (result == GNUNET_OK) | 680 | }*/ |
671 | change_state (n, S_DISCONNECT); | ||
672 | else | ||
673 | change_state (n, S_NOT_CONNECTED); | ||
674 | } | ||
675 | 681 | ||
676 | static int | 682 | static int |
677 | send_disconnect (struct NeighbourMapEntry *n) | 683 | send_disconnect (struct NeighbourMapEntry *n) |
@@ -679,8 +685,10 @@ send_disconnect (struct NeighbourMapEntry *n) | |||
679 | size_t ret; | 685 | size_t ret; |
680 | struct SessionDisconnectMessage disconnect_msg; | 686 | struct SessionDisconnectMessage disconnect_msg; |
681 | 687 | ||
682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sending DISCONNECT to peer `%4s'\n", | 688 | #if DEBUG_TRANSPORT |
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s'\n", | ||
683 | GNUNET_i2s (&n->id)); | 690 | GNUNET_i2s (&n->id)); |
691 | #endif | ||
684 | 692 | ||
685 | disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); | 693 | disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); |
686 | disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); | 694 | disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); |
@@ -699,7 +707,7 @@ send_disconnect (struct NeighbourMapEntry *n) | |||
699 | ret = send_with_plugin(&n->id, | 707 | ret = send_with_plugin(&n->id, |
700 | (const char *) &disconnect_msg, sizeof (disconnect_msg), | 708 | (const char *) &disconnect_msg, sizeof (disconnect_msg), |
701 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen, | 709 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, n->addr, n->addrlen, |
702 | GNUNET_YES, &send_disconnect_cont, n); | 710 | GNUNET_YES, NULL, NULL); |
703 | 711 | ||
704 | if (ret == GNUNET_SYSERR) | 712 | if (ret == GNUNET_SYSERR) |
705 | return GNUNET_SYSERR; | 713 | return GNUNET_SYSERR; |
@@ -728,20 +736,18 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
728 | if (is_connected(n) || is_connecting(n)) | 736 | if (is_connected(n) || is_connecting(n)) |
729 | { | 737 | { |
730 | if (GNUNET_OK == send_disconnect(n)) | 738 | if (GNUNET_OK == send_disconnect(n)) |
731 | { | 739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", |
732 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent DISCONNECT_MSG to `%s'\n", | ||
733 | GNUNET_i2s (&n->id)); | 740 | GNUNET_i2s (&n->id)); |
734 | } | ||
735 | else | 741 | else |
736 | { | 742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send DISCONNECT_MSG to `%s'\n", |
737 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not send DISCONNECT_MSG to `%s'\n", | ||
738 | GNUNET_i2s (&n->id)); | 743 | GNUNET_i2s (&n->id)); |
739 | } | ||
740 | } | 744 | } |
741 | 745 | ||
742 | if (GNUNET_YES == n->in_disconnect) | 746 | |
747 | if (is_disconnecting(n)) | ||
743 | return; | 748 | return; |
744 | n->in_disconnect = GNUNET_YES; | 749 | change_state (n, S_DISCONNECT); |
750 | |||
745 | while (NULL != (mq = n->messages_head)) | 751 | while (NULL != (mq = n->messages_head)) |
746 | { | 752 | { |
747 | GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); | 753 | GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); |
@@ -756,8 +762,6 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
756 | } | 762 | } |
757 | if (was_connected) | 763 | if (was_connected) |
758 | { | 764 | { |
759 | if (n->state != S_NOT_CONNECTED) | ||
760 | change_state (n, S_NOT_CONNECTED); | ||
761 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); | 765 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); |
762 | GNUNET_SCHEDULER_cancel (n->keepalive_task); | 766 | GNUNET_SCHEDULER_cancel (n->keepalive_task); |
763 | n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; | 767 | n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -792,7 +796,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
792 | n->addrlen = 0; | 796 | n->addrlen = 0; |
793 | } | 797 | } |
794 | n->session = NULL; | 798 | n->session = NULL; |
795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting peer `%4s', %X\n", | 799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting peer `%4s', %X\n", |
796 | GNUNET_i2s (&n->id), n); | 800 | GNUNET_i2s (&n->id), n); |
797 | GNUNET_free (n); | 801 | GNUNET_free (n); |
798 | } | 802 | } |
@@ -914,7 +918,7 @@ send_connect_continuation (void *cls, | |||
914 | GNUNET_assert (n != NULL); | 918 | GNUNET_assert (n != NULL); |
915 | GNUNET_assert (!is_connected(n)); | 919 | GNUNET_assert (!is_connected(n)); |
916 | 920 | ||
917 | if (GNUNET_YES == n->in_disconnect) | 921 | if (is_disconnecting(n)) |
918 | return; /* neighbour is going away */ | 922 | return; /* neighbour is going away */ |
919 | if (GNUNET_YES != success) | 923 | if (GNUNET_YES != success) |
920 | { | 924 | { |
@@ -958,7 +962,7 @@ send_switch_address_continuation (void *cls, | |||
958 | struct NeighbourMapEntry *n = cls; | 962 | struct NeighbourMapEntry *n = cls; |
959 | 963 | ||
960 | GNUNET_assert (n != NULL); | 964 | GNUNET_assert (n != NULL); |
961 | if (GNUNET_YES == n->in_disconnect) | 965 | if (is_disconnecting(n)) |
962 | return; /* neighbour is going away */ | 966 | return; /* neighbour is going away */ |
963 | 967 | ||
964 | GNUNET_assert (n->state == S_CONNECTED); | 968 | GNUNET_assert (n->state == S_CONNECTED); |
@@ -966,14 +970,20 @@ send_switch_address_continuation (void *cls, | |||
966 | { | 970 | { |
967 | #if DEBUG_TRANSPORT | 971 | #if DEBUG_TRANSPORT |
968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
969 | "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", | 973 | "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", |
970 | GNUNET_i2s (&n->id), n->plugin_name, | 974 | GNUNET_i2s (&n->id), n->plugin_name, |
971 | (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, | 975 | (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, |
972 | n->addr, | 976 | n->addr, |
973 | n->addrlen), | 977 | n->addrlen), |
974 | n->session); | 978 | n->session); |
975 | #endif | 979 | #endif |
976 | change_state(n, S_NOT_CONNECTED); | 980 | |
981 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Do not forget to fix this!\n"); | ||
982 | /* FIXME: We have to change the state away from connected: | ||
983 | * If ATS can not suggest another address we do not get a callback | ||
984 | * but we still think we are connected | ||
985 | */ | ||
986 | //change_state(n, S_NOT_CONNECTED); | ||
977 | 987 | ||
978 | GNUNET_ATS_address_destroyed (GST_ats, | 988 | GNUNET_ATS_address_destroyed (GST_ats, |
979 | &n->id, | 989 | &n->id, |
@@ -1004,10 +1014,11 @@ send_connect_ack_continuation (void *cls, | |||
1004 | struct NeighbourMapEntry *n = cls; | 1014 | struct NeighbourMapEntry *n = cls; |
1005 | 1015 | ||
1006 | GNUNET_assert (n != NULL); | 1016 | GNUNET_assert (n != NULL); |
1007 | if (GNUNET_YES == n->in_disconnect) | 1017 | |
1008 | return; /* neighbour is going away */ | 1018 | if (GNUNET_YES == success) |
1009 | if (GNUNET_YES != success) | 1019 | return; /* sending successful */ |
1010 | { | 1020 | |
1021 | /* sending failed, ask for next address */ | ||
1011 | #if DEBUG_TRANSPORT | 1022 | #if DEBUG_TRANSPORT |
1012 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1013 | "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", | 1024 | "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", |
@@ -1027,9 +1038,6 @@ send_connect_ack_continuation (void *cls, | |||
1027 | NULL); | 1038 | NULL); |
1028 | 1039 | ||
1029 | GNUNET_ATS_suggest_address(GST_ats, &n->id); | 1040 | GNUNET_ATS_suggest_address(GST_ats, &n->id); |
1030 | return; | ||
1031 | } | ||
1032 | //change_state(n, S_CONNECT_SENT); | ||
1033 | } | 1041 | } |
1034 | 1042 | ||
1035 | /** | 1043 | /** |
@@ -1043,7 +1051,7 @@ send_connect_ack_continuation (void *cls, | |||
1043 | * @param address_len number of bytes in address | 1051 | * @param address_len number of bytes in address |
1044 | * @param session session to use (or NULL) | 1052 | * @param session session to use (or NULL) |
1045 | * @param ats performance data | 1053 | * @param ats performance data |
1046 | * @param ats_count number of entries in ats (excluding 0-termination) | 1054 | * @param ats_count number of entries in ats |
1047 | * @return GNUNET_YES if we are currently connected, GNUNET_NO if the | 1055 | * @return GNUNET_YES if we are currently connected, GNUNET_NO if the |
1048 | * connection is not up (yet) | 1056 | * connection is not up (yet) |
1049 | */ | 1057 | */ |
@@ -1052,7 +1060,9 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
1052 | const char *plugin_name, const void *address, | 1060 | const char *plugin_name, const void *address, |
1053 | size_t address_len, struct Session *session, | 1061 | size_t address_len, struct Session *session, |
1054 | const struct GNUNET_ATS_Information | 1062 | const struct GNUNET_ATS_Information |
1055 | *ats, uint32_t ats_count) | 1063 | *ats, uint32_t ats_count, |
1064 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
1065 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | ||
1056 | { | 1066 | { |
1057 | struct NeighbourMapEntry *n; | 1067 | struct NeighbourMapEntry *n; |
1058 | struct SessionConnectMessage connect_msg; | 1068 | struct SessionConnectMessage connect_msg; |
@@ -1072,8 +1082,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
1072 | } | 1082 | } |
1073 | 1083 | ||
1074 | #if DEBUG_TRANSPORT | 1084 | #if DEBUG_TRANSPORT |
1075 | #endif | 1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1076 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1077 | "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n", | 1086 | "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n", |
1078 | plugin_name, | 1087 | plugin_name, |
1079 | (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, | 1088 | (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, |
@@ -1081,10 +1090,13 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
1081 | address_len), | 1090 | address_len), |
1082 | session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"), | 1091 | session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"), |
1083 | GNUNET_i2s (peer)); | 1092 | GNUNET_i2s (peer)); |
1093 | #endif | ||
1084 | 1094 | ||
1085 | GNUNET_free_non_null (n->addr); | 1095 | GNUNET_free_non_null (n->addr); |
1086 | n->addr = GNUNET_malloc (address_len); | 1096 | n->addr = GNUNET_malloc (address_len); |
1087 | memcpy (n->addr, address, address_len); | 1097 | memcpy (n->addr, address, address_len); |
1098 | n->bandwidth_in = bandwidth_in; | ||
1099 | n->bandwidth_out = bandwidth_out; | ||
1088 | n->addrlen = address_len; | 1100 | n->addrlen = address_len; |
1089 | n->session = session; | 1101 | n->session = session; |
1090 | GNUNET_free_non_null (n->plugin_name); | 1102 | GNUNET_free_non_null (n->plugin_name); |
@@ -1094,6 +1106,11 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
1094 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1106 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1095 | &neighbour_timeout_task, n); | 1107 | &neighbour_timeout_task, n); |
1096 | 1108 | ||
1109 | if (n->state == S_DISCONNECT) | ||
1110 | { | ||
1111 | /* We are disconnecting, nothing to do here */ | ||
1112 | return GNUNET_NO; | ||
1113 | } | ||
1097 | /* We are not connected/connecting and initiate a fresh connect */ | 1114 | /* We are not connected/connecting and initiate a fresh connect */ |
1098 | if (n->state == S_NOT_CONNECTED) | 1115 | if (n->state == S_NOT_CONNECTED) |
1099 | { | 1116 | { |
@@ -1162,7 +1179,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
1162 | } | 1179 | } |
1163 | 1180 | ||
1164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid connection state to switch addresses "); | 1181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid connection state to switch addresses "); |
1165 | GNUNET_break (0); | 1182 | GNUNET_break_op (0); |
1166 | return GNUNET_NO; | 1183 | return GNUNET_NO; |
1167 | } | 1184 | } |
1168 | 1185 | ||
@@ -1219,8 +1236,15 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
1219 | memcmp (target, &GST_my_identity, | 1236 | memcmp (target, &GST_my_identity, |
1220 | sizeof (struct GNUNET_PeerIdentity))); | 1237 | sizeof (struct GNUNET_PeerIdentity))); |
1221 | n = lookup_neighbour (target); | 1238 | n = lookup_neighbour (target); |
1222 | if ((NULL != n) && (n->state != S_NOT_CONNECTED) ) | 1239 | |
1223 | return; /* already connecting or connected */ | 1240 | if (NULL != n) |
1241 | { | ||
1242 | if ((is_connected(n)) || (is_connecting(n))) | ||
1243 | return; /* already connecting or connected */ | ||
1244 | if (is_disconnecting(n)) | ||
1245 | change_state (n, S_NOT_CONNECTED); | ||
1246 | } | ||
1247 | |||
1224 | 1248 | ||
1225 | if (n == NULL) | 1249 | if (n == NULL) |
1226 | n = setup_neighbour (target); | 1250 | n = setup_neighbour (target); |
@@ -1269,10 +1293,10 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
1269 | GNUNET_assert (neighbours != NULL); | 1293 | GNUNET_assert (neighbours != NULL); |
1270 | 1294 | ||
1271 | #if DEBUG_TRANSPORT | 1295 | #if DEBUG_TRANSPORT |
1272 | #endif | 1296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1273 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1274 | "Session %X to peer `%s' ended \n", | 1297 | "Session %X to peer `%s' ended \n", |
1275 | session, GNUNET_i2s (peer)); | 1298 | session, GNUNET_i2s (peer)); |
1299 | #endif | ||
1276 | 1300 | ||
1277 | n = lookup_neighbour (peer); | 1301 | n = lookup_neighbour (peer); |
1278 | if (NULL == n) | 1302 | if (NULL == n) |
@@ -1285,16 +1309,19 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
1285 | n->addr = NULL; | 1309 | n->addr = NULL; |
1286 | n->addrlen = 0; | 1310 | n->addrlen = 0; |
1287 | 1311 | ||
1312 | /* not connected anymore anyway, shouldn't matter */ | ||
1313 | if ((!is_connected(n)) && (!is_connecting(n))) | ||
1314 | return; | ||
1288 | 1315 | ||
1289 | if (!is_connected(n)) | 1316 | // FIXME: switch address what is the state |
1290 | return; /* not connected anymore anyway, shouldn't matter */ | 1317 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Do not forget to fix this!\n"); |
1291 | /* fast disconnect unless ATS suggests a new address */ | 1318 | |
1319 | /* We are connected, so ask ATS to switch addresses */ | ||
1292 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 1320 | GNUNET_SCHEDULER_cancel (n->timeout_task); |
1293 | n->timeout_task = | 1321 | n->timeout_task = |
1294 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, | 1322 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, |
1295 | &neighbour_timeout_task, n); | 1323 | &neighbour_timeout_task, n); |
1296 | /* try QUICKLY to re-establish a connection, reduce timeout! */ | 1324 | /* try QUICKLY to re-establish a connection, reduce timeout! */ |
1297 | // change_state (n, S_NOT_CONNECTED); | ||
1298 | GNUNET_ATS_suggest_address (GST_ats, peer); | 1325 | GNUNET_ATS_suggest_address (GST_ats, peer); |
1299 | } | 1326 | } |
1300 | 1327 | ||
@@ -1639,6 +1666,11 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer | |||
1639 | const struct SessionDisconnectMessage *sdm; | 1666 | const struct SessionDisconnectMessage *sdm; |
1640 | GNUNET_HashCode hc; | 1667 | GNUNET_HashCode hc; |
1641 | 1668 | ||
1669 | #if DEBUG_TRANSPORT | ||
1670 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1671 | "Received DISCONNECT message from peer `%s'\n", GNUNET_i2s (peer)); | ||
1672 | #endif | ||
1673 | |||
1642 | if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) | 1674 | if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) |
1643 | { | 1675 | { |
1644 | // GNUNET_break_op (0); | 1676 | // GNUNET_break_op (0); |
@@ -1713,14 +1745,18 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
1713 | uint32_t ats_count) | 1745 | uint32_t ats_count) |
1714 | { | 1746 | { |
1715 | const struct SessionConnectMessage *scm; | 1747 | const struct SessionConnectMessage *scm; |
1748 | struct QuotaSetMessage q_msg; | ||
1716 | struct GNUNET_MessageHeader msg; | 1749 | struct GNUNET_MessageHeader msg; |
1717 | struct GNUNET_TIME_Absolute ts; | 1750 | struct GNUNET_TIME_Absolute ts; |
1718 | struct NeighbourMapEntry *n; | 1751 | struct NeighbourMapEntry *n; |
1719 | size_t msg_len; | 1752 | size_t msg_len; |
1720 | size_t ret; | 1753 | size_t ret; |
1721 | 1754 | ||
1722 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1755 | #if DEBUG_TRANSPORT |
1723 | "GST_neighbours_handle_connect_ack SYN/ACK\n"); | 1756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1757 | "Received CONNECT_ACK message from peer `%s'\n", GNUNET_i2s (peer)); | ||
1758 | #endif | ||
1759 | |||
1724 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) | 1760 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) |
1725 | { | 1761 | { |
1726 | GNUNET_break_op (0); | 1762 | GNUNET_break_op (0); |
@@ -1742,7 +1778,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
1742 | } | 1778 | } |
1743 | 1779 | ||
1744 | if (NULL != session) | 1780 | if (NULL != session) |
1745 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1781 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1746 | "transport-ats", | 1782 | "transport-ats", |
1747 | "Giving ATS session %p of plugin %s for peer %s\n", | 1783 | "Giving ATS session %p of plugin %s for peer %s\n", |
1748 | session, | 1784 | session, |
@@ -1754,6 +1790,14 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
1754 | session, ats, ats_count); | 1790 | session, ats, ats_count); |
1755 | 1791 | ||
1756 | change_state (n, S_CONNECTED); | 1792 | change_state (n, S_CONNECTED); |
1793 | |||
1794 | #if DEBUG_TRANSPORT | ||
1795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1796 | "Setting inbound quota of %u for peer `%s' to \n", | ||
1797 | ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id)); | ||
1798 | #endif | ||
1799 | GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); | ||
1800 | |||
1757 | n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, | 1801 | n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, |
1758 | &neighbour_keepalive_task, | 1802 | &neighbour_keepalive_task, |
1759 | n); | 1803 | n); |
@@ -1780,6 +1824,17 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
1780 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, | 1824 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, |
1781 | GNUNET_NO); | 1825 | GNUNET_NO); |
1782 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); | 1826 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); |
1827 | |||
1828 | #if DEBUG_TRANSPORT | ||
1829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1830 | "Sending outbound quota of %u Bps for peer `%s' to all clients\n", | ||
1831 | ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); | ||
1832 | #endif | ||
1833 | q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); | ||
1834 | q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); | ||
1835 | q_msg.quota = n->bandwidth_out; | ||
1836 | q_msg.peer = (*peer); | ||
1837 | GST_clients_broadcast (&q_msg.header, GNUNET_NO); | ||
1783 | } | 1838 | } |
1784 | 1839 | ||
1785 | void | 1840 | void |
@@ -1792,8 +1847,13 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | |||
1792 | uint32_t ats_count) | 1847 | uint32_t ats_count) |
1793 | { | 1848 | { |
1794 | struct NeighbourMapEntry *n; | 1849 | struct NeighbourMapEntry *n; |
1795 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1850 | struct QuotaSetMessage q_msg; |
1796 | "GST_neighbours_handle_ack ACK\n"); | 1851 | |
1852 | #if DEBUG_TRANSPORT | ||
1853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1854 | "Received ACK message from peer `%s'\n", GNUNET_i2s (peer)); | ||
1855 | #endif | ||
1856 | |||
1797 | if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) | 1857 | if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) |
1798 | { | 1858 | { |
1799 | GNUNET_break_op (0); | 1859 | GNUNET_break_op (0); |
@@ -1819,7 +1879,7 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | |||
1819 | return; | 1879 | return; |
1820 | 1880 | ||
1821 | if (NULL != session) | 1881 | if (NULL != session) |
1822 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1882 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1823 | "transport-ats", | 1883 | "transport-ats", |
1824 | "Giving ATS session %p of plugin %s for peer %s\n", | 1884 | "Giving ATS session %p of plugin %s for peer %s\n", |
1825 | session, | 1885 | session, |
@@ -1831,6 +1891,9 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | |||
1831 | session, ats, ats_count); | 1891 | session, ats, ats_count); |
1832 | 1892 | ||
1833 | change_state (n, S_CONNECTED); | 1893 | change_state (n, S_CONNECTED); |
1894 | |||
1895 | GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); | ||
1896 | |||
1834 | n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, | 1897 | n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, |
1835 | &neighbour_keepalive_task, | 1898 | &neighbour_keepalive_task, |
1836 | n); | 1899 | n); |
@@ -1839,6 +1902,18 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | |||
1839 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, | 1902 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, |
1840 | GNUNET_NO); | 1903 | GNUNET_NO); |
1841 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); | 1904 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); |
1905 | |||
1906 | #if DEBUG_TRANSPORT | ||
1907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1908 | "Sending outbound quota of %u Bps for peer `%s' to all clients\n", | ||
1909 | ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); | ||
1910 | #endif | ||
1911 | |||
1912 | q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); | ||
1913 | q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); | ||
1914 | q_msg.quota = n->bandwidth_out; | ||
1915 | q_msg.peer = (*peer); | ||
1916 | GST_clients_broadcast (&q_msg.header, GNUNET_NO); | ||
1842 | } | 1917 | } |
1843 | 1918 | ||
1844 | struct BlackListCheckContext | 1919 | struct BlackListCheckContext |
@@ -1867,8 +1942,10 @@ handle_connect_blacklist_cont (void *cls, | |||
1867 | struct NeighbourMapEntry *n; | 1942 | struct NeighbourMapEntry *n; |
1868 | struct BlackListCheckContext * bcc = cls; | 1943 | struct BlackListCheckContext * bcc = cls; |
1869 | 1944 | ||
1870 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1945 | #if DEBUG_TRANSPORT |
1871 | "Result Connect blacklist check `%s': %s\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "OK" : "NO"); | 1946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1947 | "Blacklist check due to CONNECT message: `%s'\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN"); | ||
1948 | #endif | ||
1872 | 1949 | ||
1873 | /* not allowed */ | 1950 | /* not allowed */ |
1874 | if (GNUNET_OK != result) | 1951 | if (GNUNET_OK != result) |
@@ -1884,7 +1961,7 @@ handle_connect_blacklist_cont (void *cls, | |||
1884 | if (bcc->ts.abs_value > n->connect_ts.abs_value) | 1961 | if (bcc->ts.abs_value > n->connect_ts.abs_value) |
1885 | { | 1962 | { |
1886 | if (NULL != bcc->session) | 1963 | if (NULL != bcc->session) |
1887 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1964 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1888 | "transport-ats", | 1965 | "transport-ats", |
1889 | "Giving ATS session %p of plugin %s address `%s' for peer %s\n", | 1966 | "Giving ATS session %p of plugin %s address `%s' for peer %s\n", |
1890 | bcc->session, | 1967 | bcc->session, |
@@ -1934,8 +2011,11 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, | |||
1934 | const struct SessionConnectMessage *scm; | 2011 | const struct SessionConnectMessage *scm; |
1935 | struct NeighbourMapEntry * n; | 2012 | struct NeighbourMapEntry * n; |
1936 | struct BlackListCheckContext * bcc = NULL; | 2013 | struct BlackListCheckContext * bcc = NULL; |
1937 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2014 | |
1938 | "GST_neighbours_handle_connect SYN\n"); | 2015 | #if DEBUG_TRANSPORT |
2016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2017 | "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer)); | ||
2018 | #endif | ||
1939 | 2019 | ||
1940 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) | 2020 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) |
1941 | { | 2021 | { |