diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 15:13:19 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 15:13:19 +0000 |
commit | becfc361467337f5f577cd6a1a31eb4806859de6 (patch) | |
tree | dd198a086d64633342c51f9c658ae614468fbb7c /src | |
parent | e2aa0db692a2731942663762e09298004656efc0 (diff) | |
download | gnunet-becfc361467337f5f577cd6a1a31eb4806859de6.tar.gz gnunet-becfc361467337f5f577cd6a1a31eb4806859de6.zip |
complete state reset functionality
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 3 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours_3way.c | 116 |
2 files changed, 101 insertions, 18 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index a45e49fc5..7e75b4499 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -181,7 +181,7 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
181 | GST_clients_broadcast (&im->header, GNUNET_YES); | 181 | GST_clients_broadcast (&im->header, GNUNET_YES); |
182 | break; | 182 | break; |
183 | case GNUNET_NO: | 183 | case GNUNET_NO: |
184 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
185 | _("Discarded %u bytes of type %u from %s: quota violated or no neighbour record!\n"), | 185 | _("Discarded %u bytes of type %u from %s: quota violated or no neighbour record!\n"), |
186 | ntohs (message->size), | 186 | ntohs (message->size), |
187 | ntohs (message->type), | 187 | ntohs (message->type), |
@@ -285,6 +285,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
285 | GST_neighbours_keepalive (peer); | 285 | GST_neighbours_keepalive (peer); |
286 | break; | 286 | break; |
287 | default: | 287 | default: |
288 | |||
288 | /* should be payload */ | 289 | /* should be payload */ |
289 | ret = process_payload (peer, | 290 | ret = process_payload (peer, |
290 | message, | 291 | message, |
diff --git a/src/transport/gnunet-service-transport_neighbours_3way.c b/src/transport/gnunet-service-transport_neighbours_3way.c index 117ea5ee1..516ef6b70 100644 --- a/src/transport/gnunet-service-transport_neighbours_3way.c +++ b/src/transport/gnunet-service-transport_neighbours_3way.c | |||
@@ -58,6 +58,10 @@ | |||
58 | 58 | ||
59 | #define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | 59 | #define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) |
60 | 60 | ||
61 | |||
62 | #define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
63 | |||
64 | |||
61 | /** | 65 | /** |
62 | * Entry in neighbours. | 66 | * Entry in neighbours. |
63 | */ | 67 | */ |
@@ -286,27 +290,30 @@ struct NeighbourMapEntry | |||
286 | */ | 290 | */ |
287 | struct GNUNET_TIME_Absolute connect_ts; | 291 | struct GNUNET_TIME_Absolute connect_ts; |
288 | 292 | ||
293 | /** | ||
294 | * Timeout for ATS | ||
295 | * We asked ATS for a new address for this peer | ||
296 | */ | ||
289 | GNUNET_SCHEDULER_TaskIdentifier ats_suggest; | 297 | GNUNET_SCHEDULER_TaskIdentifier ats_suggest; |
290 | 298 | ||
291 | /** | 299 | /** |
300 | * Task the resets the peer state after due to an pending | ||
301 | * unsuccessful connection setup | ||
302 | */ | ||
303 | GNUNET_SCHEDULER_TaskIdentifier state_reset; | ||
304 | |||
305 | /** | ||
292 | * How often has the other peer (recently) violated the inbound | 306 | * How often has the other peer (recently) violated the inbound |
293 | * traffic limit? Incremented by 10 per violation, decremented by 1 | 307 | * traffic limit? Incremented by 10 per violation, decremented by 1 |
294 | * per non-violation (for each time interval). | 308 | * per non-violation (for each time interval). |
295 | */ | 309 | */ |
296 | unsigned int quota_violation_count; | 310 | unsigned int quota_violation_count; |
297 | 311 | ||
298 | /** | ||
299 | * Number of values in 'ats' array. | ||
300 | */ | ||
301 | //unsigned int ats_count; | ||
302 | |||
303 | 312 | ||
304 | /** | 313 | /** |
305 | * Do we currently consider this neighbour connected? (as far as | 314 | * The current state of the peer |
306 | * the connect/disconnect callbacks are concerned)? | 315 | * Element of enum State |
307 | */ | 316 | */ |
308 | //int is_connected; | ||
309 | |||
310 | int state; | 317 | int state; |
311 | 318 | ||
312 | }; | 319 | }; |
@@ -405,6 +412,49 @@ print_state (int state) | |||
405 | } | 412 | } |
406 | 413 | ||
407 | static int | 414 | static int |
415 | change (struct NeighbourMapEntry * n, int state, int line); | ||
416 | |||
417 | static void | ||
418 | ats_suggest_cancel (void *cls, | ||
419 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
420 | |||
421 | static void | ||
422 | reset_task (void *cls, | ||
423 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
424 | { | ||
425 | struct NeighbourMapEntry * n = cls; | ||
426 | |||
427 | n->state_reset = GNUNET_SCHEDULER_NO_TASK; | ||
428 | |||
429 | #if DEBUG_TRANSPORT | ||
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
431 | "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", | ||
432 | GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state)); | ||
433 | #endif | ||
434 | GNUNET_STATISTICS_update (GST_stats, | ||
435 | gettext_noop ("# failed connection attempts due to timeout"), | ||
436 | 1, | ||
437 | GNUNET_NO); | ||
438 | |||
439 | /* resetting state */ | ||
440 | n->state = S_NOT_CONNECTED; | ||
441 | |||
442 | /* destroying address */ | ||
443 | GNUNET_ATS_address_destroyed (GST_ats, | ||
444 | &n->id, | ||
445 | n->plugin_name, | ||
446 | n->addr, | ||
447 | n->addrlen, | ||
448 | NULL); | ||
449 | |||
450 | /* request new address */ | ||
451 | if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) | ||
452 | GNUNET_SCHEDULER_cancel(n->ats_suggest); | ||
453 | n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); | ||
454 | GNUNET_ATS_suggest_address(GST_ats, &n->id); | ||
455 | } | ||
456 | |||
457 | static int | ||
408 | change (struct NeighbourMapEntry * n, int state, int line) | 458 | change (struct NeighbourMapEntry * n, int state, int line) |
409 | { | 459 | { |
410 | char * old = strdup(print_state(n->state)); | 460 | char * old = strdup(print_state(n->state)); |
@@ -418,6 +468,14 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
418 | (state == S_DISCONNECT)) | 468 | (state == S_DISCONNECT)) |
419 | { | 469 | { |
420 | allowed = GNUNET_YES; | 470 | allowed = GNUNET_YES; |
471 | |||
472 | /* Schedule reset task */ | ||
473 | if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ) | ||
474 | { | ||
475 | GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK); | ||
476 | n->state_reset = GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n); | ||
477 | } | ||
478 | |||
421 | break; | 479 | break; |
422 | } | 480 | } |
423 | break; | 481 | break; |
@@ -425,6 +483,18 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
425 | if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || | 483 | if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || |
426 | (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT)) | 484 | (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT)) |
427 | { | 485 | { |
486 | if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) | ||
487 | { | ||
488 | #if DEBUG_TRANSPORT | ||
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
490 | "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", | ||
491 | GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); | ||
492 | #endif | ||
493 | GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); | ||
494 | GNUNET_SCHEDULER_cancel (n->state_reset); | ||
495 | n->state_reset = GNUNET_SCHEDULER_NO_TASK; | ||
496 | } | ||
497 | |||
428 | allowed = GNUNET_YES; | 498 | allowed = GNUNET_YES; |
429 | break; | 499 | break; |
430 | } | 500 | } |
@@ -433,6 +503,18 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
433 | if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || | 503 | if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || |
434 | (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV)) | 504 | (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV)) |
435 | { | 505 | { |
506 | if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) | ||
507 | { | ||
508 | #if DEBUG_TRANSPORT | ||
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
510 | "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", | ||
511 | GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), 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 | |||
436 | allowed = GNUNET_YES; | 518 | allowed = GNUNET_YES; |
437 | break; | 519 | break; |
438 | } | 520 | } |
@@ -470,8 +552,10 @@ change (struct NeighbourMapEntry * n, int state, int line) | |||
470 | } | 552 | } |
471 | 553 | ||
472 | n->state = state; | 554 | n->state = state; |
555 | #if DEBUG_TRANSPORT | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", | 556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", |
474 | GNUNET_i2s (&n->id), n, old, new, line); | 557 | GNUNET_i2s (&n->id), n, old, new, line); |
558 | #endif | ||
475 | GNUNET_free (old); | 559 | GNUNET_free (old); |
476 | GNUNET_free (new); | 560 | GNUNET_free (new); |
477 | return GNUNET_OK; | 561 | return GNUNET_OK; |
@@ -736,9 +820,6 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
736 | struct MessageQueue *mq; | 820 | struct MessageQueue *mq; |
737 | int was_connected = is_connected(n); | 821 | int was_connected = is_connected(n); |
738 | 822 | ||
739 | if (is_disconnecting(n) == GNUNET_YES) | ||
740 | return; | ||
741 | |||
742 | /* send DISCONNECT MESSAGE */ | 823 | /* send DISCONNECT MESSAGE */ |
743 | if (is_connected(n) || is_connecting(n)) | 824 | if (is_connected(n) || is_connecting(n)) |
744 | { | 825 | { |
@@ -900,7 +981,7 @@ ats_suggest_cancel (void *cls, | |||
900 | 981 | ||
901 | n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; | 982 | n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; |
902 | 983 | ||
903 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
904 | " ATS did not suggested address to connect to peer `%s'\n", | 985 | " ATS did not suggested address to connect to peer `%s'\n", |
905 | GNUNET_i2s (&n->id)); | 986 | GNUNET_i2s (&n->id)); |
906 | 987 | ||
@@ -1210,7 +1291,11 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, | |||
1210 | } | 1291 | } |
1211 | return GNUNET_NO; | 1292 | return GNUNET_NO; |
1212 | } | 1293 | } |
1213 | 1294 | else if (n->state == S_CONNECT_SENT) | |
1295 | { | ||
1296 | //FIXME | ||
1297 | return GNUNET_NO; | ||
1298 | } | ||
1214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state); | 1299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state); |
1215 | GNUNET_break_op (0); | 1300 | GNUNET_break_op (0); |
1216 | return GNUNET_NO; | 1301 | return GNUNET_NO; |
@@ -1477,9 +1562,6 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity | |||
1477 | } | 1562 | } |
1478 | if (!is_connected(n)) | 1563 | if (!is_connected(n)) |
1479 | { | 1564 | { |
1480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1481 | _("Plugin gave us %d bytes of data but somehow the session is not marked as UP yet!\n"), | ||
1482 | (int) size); | ||
1483 | *do_forward = GNUNET_SYSERR; | 1565 | *do_forward = GNUNET_SYSERR; |
1484 | return GNUNET_TIME_UNIT_ZERO; | 1566 | return GNUNET_TIME_UNIT_ZERO; |
1485 | } | 1567 | } |