diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-09 11:00:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-09 11:00:19 +0000 |
commit | 8d7f44bd4f713296f4fc12b70836795ea75f8b7a (patch) | |
tree | 3fedff0637961d4c94d0d3f0ac3e12cc8545e37f /src | |
parent | 88eef96dc5f311b07c2fba7bdf9dee8ab6886e83 (diff) | |
download | gnunet-8d7f44bd4f713296f4fc12b70836795ea75f8b7a.tar.gz gnunet-8d7f44bd4f713296f4fc12b70836795ea75f8b7a.zip |
cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 393 |
1 files changed, 165 insertions, 228 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 51382048d..332260e40 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -184,22 +184,36 @@ struct MessageQueue | |||
184 | 184 | ||
185 | }; | 185 | }; |
186 | 186 | ||
187 | |||
187 | enum State | 188 | enum State |
188 | { | 189 | { |
189 | /* fresh peer or completely disconnected */ | 190 | /** |
190 | S_NOT_CONNECTED = 0, | 191 | * fresh peer or completely disconnected |
191 | /* sent CONNECT message to other peer, waiting for CONNECT_ACK */ | 192 | */ |
192 | S_CONNECT_SENT = 1, | 193 | S_NOT_CONNECTED, |
193 | /* received CONNECT message to other peer, sending CONNECT_ACK */ | 194 | |
194 | S_CONNECT_RECV = 4, | 195 | /** |
195 | /* sent CONNECT_ACK message to other peer, wait for ACK or payload */ | 196 | * sent CONNECT message to other peer, waiting for CONNECT_ACK |
196 | S_CONNECT_RECV_ACK_SENT = 8, | 197 | */ |
197 | /* received ACK or payload */ | 198 | S_CONNECT_SENT, |
198 | S_CONNECTED = 16, | 199 | |
199 | /* Disconnect in progress */ | 200 | /** |
200 | S_DISCONNECT = 32 | 201 | * received CONNECT message to other peer, sending CONNECT_ACK |
202 | */ | ||
203 | S_CONNECT_RECV, | ||
204 | |||
205 | /** | ||
206 | * received ACK or payload | ||
207 | */ | ||
208 | S_CONNECTED, | ||
209 | |||
210 | /** | ||
211 | * Disconnect in progress | ||
212 | */ | ||
213 | S_DISCONNECT | ||
201 | }; | 214 | }; |
202 | 215 | ||
216 | |||
203 | /** | 217 | /** |
204 | * Entry in neighbours. | 218 | * Entry in neighbours. |
205 | */ | 219 | */ |
@@ -383,9 +397,6 @@ print_state (int state) | |||
383 | case S_CONNECT_RECV: | 397 | case S_CONNECT_RECV: |
384 | return "S_CONNECT_RECV"; | 398 | return "S_CONNECT_RECV"; |
385 | break; | 399 | break; |
386 | case S_CONNECT_RECV_ACK_SENT: | ||
387 | return "S_CONNECT_RECV_ACK_SENT"; | ||
388 | break; | ||
389 | case S_CONNECT_SENT: | 400 | case S_CONNECT_SENT: |
390 | return "S_CONNECT_SENT"; | 401 | return "S_CONNECT_SENT"; |
391 | break; | 402 | break; |
@@ -448,9 +459,6 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
448 | static int | 459 | static int |
449 | change (struct NeighbourMapEntry *n, int state, int line) | 460 | change (struct NeighbourMapEntry *n, int state, int line) |
450 | { | 461 | { |
451 | char *old = strdup (print_state (n->state)); | ||
452 | char *new = strdup (print_state (state)); | ||
453 | |||
454 | /* allowed transitions */ | 462 | /* allowed transitions */ |
455 | int allowed = GNUNET_NO; | 463 | int allowed = GNUNET_NO; |
456 | 464 | ||
@@ -459,89 +467,28 @@ change (struct NeighbourMapEntry *n, int state, int line) | |||
459 | case S_NOT_CONNECTED: | 467 | case S_NOT_CONNECTED: |
460 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || | 468 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || |
461 | (state == S_DISCONNECT)) | 469 | (state == S_DISCONNECT)) |
462 | { | ||
463 | allowed = GNUNET_YES; | 470 | allowed = GNUNET_YES; |
464 | |||
465 | /* Schedule reset task */ | ||
466 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT)) | ||
467 | { | ||
468 | GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK); | ||
469 | n->state_reset = | ||
470 | GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, | ||
471 | n); | ||
472 | } | ||
473 | break; | ||
474 | } | ||
475 | break; | 471 | break; |
476 | case S_CONNECT_RECV: | 472 | case S_CONNECT_RECV: |
477 | if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || | 473 | allowed = GNUNET_YES; |
478 | (state == S_CONNECTED) || | ||
479 | /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_SENT)) | ||
480 | { | ||
481 | if ((state == S_CONNECTED) || (state == S_DISCONNECT) || | ||
482 | (state == S_NOT_CONNECTED)) | ||
483 | { | ||
484 | #if DEBUG_TRANSPORT | ||
485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
486 | "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", | ||
487 | GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), | ||
488 | print_state (n->state), print_state (state)); | ||
489 | #endif | ||
490 | GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); | ||
491 | GNUNET_SCHEDULER_cancel (n->state_reset); | ||
492 | n->state_reset = GNUNET_SCHEDULER_NO_TASK; | ||
493 | } | ||
494 | |||
495 | allowed = GNUNET_YES; | ||
496 | break; | ||
497 | } | ||
498 | break; | 474 | break; |
499 | case S_CONNECT_SENT: | 475 | case S_CONNECT_SENT: |
500 | if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || | 476 | allowed = GNUNET_YES; |
501 | (state == S_DISCONNECT) || | ||
502 | /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_RECV)) | ||
503 | { | ||
504 | if ((state == S_CONNECTED) || (state == S_DISCONNECT) || | ||
505 | (state == S_NOT_CONNECTED)) | ||
506 | { | ||
507 | #if DEBUG_TRANSPORT | ||
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
509 | "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", | ||
510 | GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), | ||
511 | print_state (n->state), print_state (state)); | ||
512 | #endif | ||
513 | GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); | ||
514 | GNUNET_SCHEDULER_cancel (n->state_reset); | ||
515 | n->state_reset = GNUNET_SCHEDULER_NO_TASK; | ||
516 | } | ||
517 | |||
518 | allowed = GNUNET_YES; | ||
519 | break; | ||
520 | } | ||
521 | break; | 477 | break; |
522 | case S_CONNECTED: | 478 | case S_CONNECTED: |
523 | if (state == S_DISCONNECT) | 479 | if (state == S_DISCONNECT) |
524 | { | ||
525 | allowed = GNUNET_YES; | 480 | allowed = GNUNET_YES; |
526 | break; | ||
527 | } | ||
528 | break; | 481 | break; |
529 | case S_DISCONNECT: | 482 | case S_DISCONNECT: |
530 | /* | ||
531 | * if (state == S_NOT_CONNECTED) | ||
532 | * { | ||
533 | * allowed = GNUNET_YES; | ||
534 | * break; | ||
535 | * } */ | ||
536 | break; | 483 | break; |
537 | default: | 484 | default: |
538 | GNUNET_break (0); | 485 | GNUNET_break (0); |
539 | break; | 486 | break; |
540 | |||
541 | } | 487 | } |
542 | |||
543 | if (allowed == GNUNET_NO) | 488 | if (allowed == GNUNET_NO) |
544 | { | 489 | { |
490 | char *old = GNUNET_strdup (print_state (n->state)); | ||
491 | char *new = GNUNET_strdup (print_state (state)); | ||
545 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
546 | "Illegal state transition from `%s' to `%s' in line %u \n", old, | 493 | "Illegal state transition from `%s' to `%s' in line %u \n", old, |
547 | new, line); | 494 | new, line); |
@@ -553,12 +500,52 @@ change (struct NeighbourMapEntry *n, int state, int line) | |||
553 | 500 | ||
554 | n->state = state; | 501 | n->state = state; |
555 | #if DEBUG_TRANSPORT | 502 | #if DEBUG_TRANSPORT |
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | { |
557 | "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", | 504 | char *old = GNUNET_strdup (print_state (n->state)); |
558 | GNUNET_i2s (&n->id), n, old, new, line); | 505 | char *new = GNUNET_strdup (print_state (state)); |
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
507 | "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", | ||
508 | GNUNET_i2s (&n->id), n, old, new, line); | ||
509 | GNUNET_free (old); | ||
510 | GNUNET_free (new); | ||
511 | } | ||
559 | #endif | 512 | #endif |
560 | GNUNET_free (old); | 513 | switch (n->state) |
561 | GNUNET_free (new); | 514 | { |
515 | case S_CONNECT_RECV: | ||
516 | case S_CONNECT_SENT: | ||
517 | if (n->state_reset != GNUNET_SCHEDULER_NO_TASK) | ||
518 | GNUNET_SCHEDULER_cancel (n->state_reset); | ||
519 | n->state_reset = | ||
520 | GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, | ||
521 | n); | ||
522 | break; | ||
523 | case S_CONNECTED: | ||
524 | case S_NOT_CONNECTED: | ||
525 | case S_DISCONNECT: | ||
526 | if (GNUNET_SCHEDULER_NO_TASK != n->state_reset) | ||
527 | { | ||
528 | #if DEBUG_TRANSPORT | ||
529 | char *old = GNUNET_strdup (print_state (n->state)); | ||
530 | char *new = GNUNET_strdup (print_state (state)); | ||
531 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
532 | "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", | ||
533 | GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), | ||
534 | old, new); | ||
535 | GNUNET_free (old); | ||
536 | GNUNET_free (new); | ||
537 | #endif | ||
538 | GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); | ||
539 | GNUNET_SCHEDULER_cancel (n->state_reset); | ||
540 | n->state_reset = GNUNET_SCHEDULER_NO_TASK; | ||
541 | } | ||
542 | break; | ||
543 | default: | ||
544 | GNUNET_assert (0); | ||
545 | } | ||
546 | |||
547 | |||
548 | |||
562 | return GNUNET_OK; | 549 | return GNUNET_OK; |
563 | } | 550 | } |
564 | 551 | ||
@@ -1042,45 +1029,41 @@ GST_neighbours_stop () | |||
1042 | * succeeded, we change the state. If it failed, we should tell | 1029 | * succeeded, we change the state. If it failed, we should tell |
1043 | * ATS to not use this address anymore (until it is re-validated). | 1030 | * ATS to not use this address anymore (until it is re-validated). |
1044 | * | 1031 | * |
1045 | * @param cls the 'struct NeighbourMapEntry' | 1032 | * @param cls the 'struct GNUNET_HELLO_Address' of the address that was tried |
1046 | * @param success GNUNET_OK on success | 1033 | * @param success GNUNET_OK on success |
1047 | */ | 1034 | */ |
1048 | static void | 1035 | static void |
1049 | send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target, | 1036 | send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target, |
1050 | int success) | 1037 | int success) |
1051 | { | 1038 | { |
1052 | struct NeighbourMapEntry *n = cls; | 1039 | struct GNUNET_HELLO_Address *address = cls; |
1053 | 1040 | struct NeighbourMapEntry *n; | |
1054 | GNUNET_assert (n != NULL); | 1041 | |
1055 | GNUNET_assert (!is_connected (n)); | ||
1056 | |||
1057 | if (is_disconnecting (n)) | ||
1058 | return; /* neighbour is going away */ | ||
1059 | |||
1060 | if (GNUNET_YES != success) | 1042 | if (GNUNET_YES != success) |
1043 | GNUNET_ATS_address_destroyed (GST_ats, address, NULL); | ||
1044 | if ( (NULL == neighbours) || | ||
1045 | (NULL == (n = lookup_neighbour (&address->peer))) || | ||
1046 | (n->state == S_DISCONNECT) || | ||
1047 | (GNUNET_YES == success) ) | ||
1061 | { | 1048 | { |
1062 | #if DEBUG_TRANSPORT | 1049 | GNUNET_HELLO_address_free (address); |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1064 | "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", | ||
1065 | GNUNET_i2s (&n->id), n->address->transport_name, | ||
1066 | (n->addrlen == | ||
1067 | 0) ? "<inbound>" : GST_plugins_a2s (n->address), n->session); | ||
1068 | #endif | ||
1069 | |||
1070 | GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL); | ||
1071 | |||
1072 | change_state (n, S_NOT_CONNECTED); | ||
1073 | |||
1074 | if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) | ||
1075 | GNUNET_SCHEDULER_cancel (n->ats_suggest); | ||
1076 | n->ats_suggest = | ||
1077 | GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, | ||
1078 | n); | ||
1079 | GNUNET_ATS_suggest_address (GST_ats, &n->id); | ||
1080 | return; | 1050 | return; |
1081 | } | 1051 | } |
1082 | 1052 | #if DEBUG_TRANSPORT | |
1083 | 1053 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
1054 | "Failed to send CONNECT_MSG to peer `%4s' with address '%s' session %p, asking ATS for new address \n", | ||
1055 | GNUNET_i2s (&n->id), | ||
1056 | GST_plugins_a2s (n->address), | ||
1057 | n->session); | ||
1058 | #endif | ||
1059 | change_state (n, S_NOT_CONNECTED); | ||
1060 | if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) | ||
1061 | GNUNET_SCHEDULER_cancel (n->ats_suggest); | ||
1062 | n->ats_suggest = | ||
1063 | GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, &ats_suggest_cancel, | ||
1064 | n); | ||
1065 | GNUNET_ATS_suggest_address (GST_ats, &n->id); | ||
1066 | GNUNET_HELLO_address_free (address); | ||
1084 | } | 1067 | } |
1085 | 1068 | ||
1086 | 1069 | ||
@@ -1167,6 +1150,7 @@ send_connect_ack_continuation (void *cls, | |||
1167 | GNUNET_ATS_suggest_address (GST_ats, &n->id); | 1150 | GNUNET_ATS_suggest_address (GST_ats, &n->id); |
1168 | } | 1151 | } |
1169 | 1152 | ||
1153 | |||
1170 | /** | 1154 | /** |
1171 | * For an existing neighbour record, set the active connection to | 1155 | * For an existing neighbour record, set the active connection to |
1172 | * the given address. | 1156 | * the given address. |
@@ -1195,61 +1179,44 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1195 | struct SessionConnectMessage connect_msg; | 1179 | struct SessionConnectMessage connect_msg; |
1196 | size_t msg_len; | 1180 | size_t msg_len; |
1197 | size_t ret; | 1181 | size_t ret; |
1198 | int checks_failed; | ||
1199 | 1182 | ||
1200 | // This can happen during shutdown | ||
1201 | if (neighbours == NULL) | 1183 | if (neighbours == NULL) |
1202 | { | 1184 | { |
1185 | /* This can happen during shutdown */ | ||
1203 | return GNUNET_NO; | 1186 | return GNUNET_NO; |
1204 | } | 1187 | } |
1205 | 1188 | n = lookup_neighbour (peer); | |
1206 | checks_failed = GNUNET_NO; | 1189 | if (NULL == n) |
1207 | 1190 | return GNUNET_NO; | |
1208 | if (address == NULL) | 1191 | if (n->state == S_DISCONNECT) |
1209 | { | 1192 | { |
1210 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1193 | /* We are disconnecting, nothing to do here */ |
1211 | "ATS offered suggested us empty address: plugin NULL"); | 1194 | return GNUNET_NO; |
1212 | GNUNET_break_op (0); | ||
1213 | checks_failed = GNUNET_YES; | ||
1214 | } | 1195 | } |
1215 | if ( (session == NULL) && (address == NULL) ) | 1196 | GNUNET_assert (address->transport_name != NULL); |
1197 | if ( (session == NULL) && (0 == address->address_length) ) | ||
1216 | { | 1198 | { |
1217 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1218 | "ATS offered suggested us empty address: address NULL & session NULL"); | ||
1219 | GNUNET_break_op (0); | 1199 | GNUNET_break_op (0); |
1220 | checks_failed = GNUNET_YES; | ||
1221 | } | ||
1222 | |||
1223 | n = lookup_neighbour (peer); | ||
1224 | if (NULL == n) | ||
1225 | checks_failed = GNUNET_YES; | ||
1226 | |||
1227 | if (checks_failed == GNUNET_YES) | ||
1228 | { | ||
1229 | GNUNET_ATS_address_destroyed (GST_ats, address, session); | 1200 | GNUNET_ATS_address_destroyed (GST_ats, address, session); |
1230 | if (n != NULL) | 1201 | GNUNET_ATS_suggest_address (GST_ats, peer); |
1231 | GNUNET_ATS_suggest_address (GST_ats, peer); | ||
1232 | return GNUNET_NO; | 1202 | return GNUNET_NO; |
1233 | } | 1203 | } |
1234 | 1204 | ||
1235 | /* checks successful and neighbour != NULL */ | 1205 | /* checks successful and neighbour != NULL */ |
1236 | #if DEBUG_TRANSPORT | 1206 | #if DEBUG_TRANSPORT |
1237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1238 | "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n", | 1208 | "ATS tells us to switch to address '%s' session %p for %s peer `%s'\n", |
1239 | address->transport_name, | 1209 | GST_plugins_a2s (address), |
1240 | (address_len == 0) ? "<inbound>" : GST_plugins_a2s (address), | ||
1241 | session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"), | 1210 | session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"), |
1242 | GNUNET_i2s (peer)); | 1211 | GNUNET_i2s (peer)); |
1243 | #endif | 1212 | #endif |
1244 | |||
1245 | if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) | 1213 | if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) |
1246 | { | 1214 | { |
1247 | GNUNET_SCHEDULER_cancel (n->ats_suggest); | 1215 | GNUNET_SCHEDULER_cancel (n->ats_suggest); |
1248 | n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; | 1216 | n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; |
1249 | } | 1217 | } |
1250 | 1218 | /* do not switch addresses just update quotas */ | |
1251 | // do not switch addresses just update quotas | 1219 | if ( (n->state == S_CONNECTED) && |
1252 | if ( (is_connected (n)) && | ||
1253 | (NULL != n->address) && | 1220 | (NULL != n->address) && |
1254 | (0 == GNUNET_HELLO_address_cmp (address, | 1221 | (0 == GNUNET_HELLO_address_cmp (address, |
1255 | n->address)) && | 1222 | n->address)) && |
@@ -1276,42 +1243,30 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1276 | return GNUNET_NO; | 1243 | return GNUNET_NO; |
1277 | } | 1244 | } |
1278 | if (n->state == S_CONNECTED) | 1245 | if (n->state == S_CONNECTED) |
1246 | { | ||
1247 | /* mark old address as no longer used */ | ||
1279 | GST_validation_set_address_use (&n->id, | 1248 | GST_validation_set_address_use (&n->id, |
1280 | n->address, | 1249 | n->address, |
1281 | n->session, | 1250 | n->session, |
1282 | GNUNET_NO); | 1251 | GNUNET_NO); |
1283 | /* This will be a connection switch, tell ATS about it */ | ||
1284 | if (n->state == S_CONNECTED) | ||
1285 | { | ||
1286 | GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); | 1252 | GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); |
1287 | } | 1253 | } |
1288 | 1254 | ||
1289 | /* set new address */ | 1255 | /* set new address */ |
1290 | if (NULL != n->address) | 1256 | if (NULL != n->address) |
1291 | GNUNET_HELLO_address_free (n->address); | 1257 | GNUNET_HELLO_address_free (n->address); |
1292 | n->address = GNUNET_HELLO_address_copy (address); | 1258 | n->address = GNUNET_HELLO_address_copy (address); |
1259 | n->session = session; | ||
1293 | n->bandwidth_in = bandwidth_in; | 1260 | n->bandwidth_in = bandwidth_in; |
1294 | n->bandwidth_out = bandwidth_out; | 1261 | n->bandwidth_out = bandwidth_out; |
1295 | n->session = session; | ||
1296 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 1262 | GNUNET_SCHEDULER_cancel (n->timeout_task); |
1297 | n->timeout_task = | 1263 | n->timeout_task = |
1298 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1264 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1299 | &neighbour_timeout_task, n); | 1265 | &neighbour_timeout_task, n); |
1300 | if (n->state == S_CONNECTED) | 1266 | switch (n->state) |
1301 | GST_validation_set_address_use (&n->id, | ||
1302 | n->address, | ||
1303 | n->session, | ||
1304 | GNUNET_YES); | ||
1305 | |||
1306 | |||
1307 | if (n->state == S_DISCONNECT) | ||
1308 | { | ||
1309 | /* We are disconnecting, nothing to do here */ | ||
1310 | return GNUNET_NO; | ||
1311 | } | ||
1312 | /* We are not connected/connecting and initiate a fresh connect */ | ||
1313 | if (n->state == S_NOT_CONNECTED) | ||
1314 | { | 1267 | { |
1268 | case S_NOT_CONNECTED: | ||
1269 | case S_CONNECT_SENT: | ||
1315 | msg_len = sizeof (struct SessionConnectMessage); | 1270 | msg_len = sizeof (struct SessionConnectMessage); |
1316 | connect_msg.header.size = htons (msg_len); | 1271 | connect_msg.header.size = htons (msg_len); |
1317 | connect_msg.header.type = | 1272 | connect_msg.header.type = |
@@ -1319,21 +1274,16 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1319 | connect_msg.reserved = htonl (0); | 1274 | connect_msg.reserved = htonl (0); |
1320 | connect_msg.timestamp = | 1275 | connect_msg.timestamp = |
1321 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1276 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1322 | |||
1323 | change_state (n, S_CONNECT_SENT); | 1277 | change_state (n, S_CONNECT_SENT); |
1324 | |||
1325 | ret = | 1278 | ret = |
1326 | send_with_plugin (peer, (const char *) &connect_msg, msg_len, | 1279 | send_with_plugin (peer, (const char *) &connect_msg, msg_len, |
1327 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, | 1280 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, |
1328 | address, GNUNET_YES, | 1281 | address, GNUNET_YES, |
1329 | &send_connect_continuation, n); | 1282 | &send_connect_continuation, |
1330 | 1283 | GNUNET_HELLO_address_copy (address)); | |
1331 | |||
1332 | return GNUNET_NO; | 1284 | return GNUNET_NO; |
1333 | } | 1285 | case S_CONNECT_RECV: |
1334 | /* We received a CONNECT message and asked ATS for an address */ | 1286 | /* We received a CONNECT message and asked ATS for an address */ |
1335 | else if (n->state == S_CONNECT_RECV) | ||
1336 | { | ||
1337 | msg_len = sizeof (struct SessionConnectMessage); | 1287 | msg_len = sizeof (struct SessionConnectMessage); |
1338 | connect_msg.header.size = htons (msg_len); | 1288 | connect_msg.header.size = htons (msg_len); |
1339 | connect_msg.header.type = | 1289 | connect_msg.header.type = |
@@ -1341,17 +1291,18 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1341 | connect_msg.reserved = htonl (0); | 1291 | connect_msg.reserved = htonl (0); |
1342 | connect_msg.timestamp = | 1292 | connect_msg.timestamp = |
1343 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1293 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1344 | |||
1345 | ret = | 1294 | ret = |
1346 | send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, | 1295 | send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, |
1347 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, | 1296 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, |
1348 | address, GNUNET_YES, | 1297 | address, GNUNET_YES, |
1349 | &send_connect_ack_continuation, n); | 1298 | &send_connect_ack_continuation, n); |
1350 | return GNUNET_NO; | 1299 | return GNUNET_NO; |
1351 | } | 1300 | case S_CONNECTED: |
1352 | /* connected peer is switching addresses */ | 1301 | /* connected peer is switching addresses */ |
1353 | else if (n->state == S_CONNECTED) | 1302 | GST_validation_set_address_use (&n->id, |
1354 | { | 1303 | n->address, |
1304 | n->session, | ||
1305 | GNUNET_YES); | ||
1355 | msg_len = sizeof (struct SessionConnectMessage); | 1306 | msg_len = sizeof (struct SessionConnectMessage); |
1356 | connect_msg.header.size = htons (msg_len); | 1307 | connect_msg.header.size = htons (msg_len); |
1357 | connect_msg.header.type = | 1308 | connect_msg.header.type = |
@@ -1359,7 +1310,6 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1359 | connect_msg.reserved = htonl (0); | 1310 | connect_msg.reserved = htonl (0); |
1360 | connect_msg.timestamp = | 1311 | connect_msg.timestamp = |
1361 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1312 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1362 | |||
1363 | ret = | 1313 | ret = |
1364 | send_with_plugin (peer, (const char *) &connect_msg, msg_len, | 1314 | send_with_plugin (peer, (const char *) &connect_msg, msg_len, |
1365 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, | 1315 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, |
@@ -1373,15 +1323,12 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1373 | GST_plugins_a2s (address), session); | 1323 | GST_plugins_a2s (address), session); |
1374 | } | 1324 | } |
1375 | return GNUNET_NO; | 1325 | return GNUNET_NO; |
1376 | } | 1326 | default: |
1377 | else if (n->state == S_CONNECT_SENT) | 1327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1378 | { | 1328 | "Invalid connection state to switch addresses %u \n", n->state); |
1329 | GNUNET_break_op (0); | ||
1379 | return GNUNET_NO; | 1330 | return GNUNET_NO; |
1380 | } | 1331 | } |
1381 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1382 | "Invalid connection state to switch addresses %u \n", n->state); | ||
1383 | GNUNET_break_op (0); | ||
1384 | return GNUNET_NO; | ||
1385 | } | 1332 | } |
1386 | 1333 | ||
1387 | 1334 | ||
@@ -2011,53 +1958,46 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
2011 | struct NeighbourMapEntry *n; | 1958 | struct NeighbourMapEntry *n; |
2012 | size_t msg_len; | 1959 | size_t msg_len; |
2013 | size_t ret; | 1960 | size_t ret; |
2014 | int was_connected; | ||
2015 | 1961 | ||
2016 | #if DEBUG_TRANSPORT | 1962 | #if DEBUG_TRANSPORT |
2017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2018 | "Received CONNECT_ACK message from peer `%s'\n", | 1964 | "Received CONNECT_ACK message from peer `%s'\n", |
2019 | GNUNET_i2s (peer)); | 1965 | GNUNET_i2s (peer)); |
2020 | #endif | 1966 | #endif |
2021 | |||
2022 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) | 1967 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) |
2023 | { | 1968 | { |
2024 | GNUNET_break_op (0); | 1969 | GNUNET_break_op (0); |
2025 | return; | 1970 | return; |
2026 | } | 1971 | } |
2027 | |||
2028 | scm = (const struct SessionConnectMessage *) message; | 1972 | scm = (const struct SessionConnectMessage *) message; |
2029 | GNUNET_break_op (ntohl (scm->reserved) == 0); | 1973 | GNUNET_break_op (ntohl (scm->reserved) == 0); |
2030 | n = lookup_neighbour (peer); | 1974 | n = lookup_neighbour (peer); |
2031 | if (NULL == n) | 1975 | if (NULL == n) |
2032 | n = setup_neighbour (peer); | 1976 | { |
2033 | 1977 | /* we did not send 'CONNECT' (how could we? no record for this peer!) */ | |
2034 | if (!is_connecting(n)) | 1978 | GNUNET_break_op (0); |
1979 | return; | ||
1980 | } | ||
1981 | if (n->state != S_CONNECT_SENT) | ||
2035 | { | 1982 | { |
2036 | GNUNET_STATISTICS_update (GST_stats, | 1983 | GNUNET_STATISTICS_update (GST_stats, |
2037 | gettext_noop ("# unexpected CONNECT_ACK messages"), 1, | 1984 | gettext_noop ("# unexpected CONNECT_ACK messages"), 1, |
2038 | GNUNET_NO); | 1985 | GNUNET_NO); |
2039 | return; | 1986 | return; |
2040 | } | 1987 | } |
2041 | |||
2042 | if (NULL != session) | 1988 | if (NULL != session) |
2043 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1989 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
2044 | "transport-ats", | 1990 | "transport-ats", |
2045 | "Giving ATS session %p of plugin %s for peer %s\n", | 1991 | "Giving ATS session %p of plugin %s for peer %s\n", |
2046 | session, address->transport_name, GNUNET_i2s (peer)); | 1992 | session, address->transport_name, GNUNET_i2s (peer)); |
2047 | GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); | 1993 | GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); |
2048 | 1994 | GNUNET_assert (NULL != n->address); | |
2049 | was_connected = is_connected (n); | 1995 | change_state (n, S_CONNECTED); |
2050 | if (!is_connected (n)) | 1996 | GST_validation_set_address_use (&n->id, |
2051 | { | 1997 | n->address, |
2052 | change_state (n, S_CONNECTED); | 1998 | n->session, |
2053 | GST_validation_set_address_use (&n->id, | 1999 | GNUNET_YES); |
2054 | n->address, | 2000 | GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES); |
2055 | n->session, | ||
2056 | GNUNET_YES); | ||
2057 | } | ||
2058 | |||
2059 | GNUNET_ATS_address_in_use (GST_ats, n->address, NULL, GNUNET_YES); | ||
2060 | |||
2061 | #if DEBUG_TRANSPORT | 2001 | #if DEBUG_TRANSPORT |
2062 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2063 | "Setting inbound quota of %u for peer `%s' to \n", | 2003 | "Setting inbound quota of %u for peer `%s' to \n", |
@@ -2083,25 +2023,22 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | |||
2083 | GST_plugins_a2s (n->address), n->session); | 2023 | GST_plugins_a2s (n->address), n->session); |
2084 | 2024 | ||
2085 | 2025 | ||
2086 | if (!was_connected) | 2026 | if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) |
2087 | { | 2027 | n->keepalive_task = |
2088 | if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) | 2028 | GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, |
2089 | n->keepalive_task = | 2029 | &neighbour_keepalive_task, n); |
2090 | GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, | 2030 | |
2091 | &neighbour_keepalive_task, n); | 2031 | neighbours_connected++; |
2092 | 2032 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, | |
2093 | neighbours_connected++; | 2033 | GNUNET_NO); |
2094 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, | ||
2095 | GNUNET_NO); | ||
2096 | #if DEBUG_TRANSPORT | 2034 | #if DEBUG_TRANSPORT |
2097 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2098 | "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", | 2036 | "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", |
2099 | GNUNET_i2s (&n->id), | 2037 | GNUNET_i2s (&n->id), |
2100 | GST_plugins_a2s (n->address), n->session, | 2038 | GST_plugins_a2s (n->address), n->session, |
2101 | __LINE__); | 2039 | __LINE__); |
2102 | #endif | 2040 | #endif |
2103 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); | 2041 | connect_notify_cb (callback_cls, &n->id, ats, ats_count); |
2104 | } | ||
2105 | 2042 | ||
2106 | #if DEBUG_TRANSPORT | 2043 | #if DEBUG_TRANSPORT |
2107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2044 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |