aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-06-10 12:08:20 +0000
committerBart Polot <bart@net.in.tum.de>2015-06-10 12:08:20 +0000
commit7cc01327be9a215ed817c462c3ee44c3db131398 (patch)
tree74ca4960246c632bcc3864c75fff518cbc6e9757 /src
parent4f7ed80998cfe391c6453d57401becdc3598c9dd (diff)
downloadgnunet-7cc01327be9a215ed817c462c3ee44c3db131398.tar.gz
gnunet-7cc01327be9a215ed817c462c3ee44c3db131398.zip
- refactor connection timeout into one implementation
- always send CONNECTION_BROKEN to alert of the timeout
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index b257ab53d..969a307cc 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -1375,39 +1375,42 @@ resend_messages_and_destroy (struct CadetConnection *c, int fwd)
1375 1375
1376 1376
1377/** 1377/**
1378 * Timeout function due to lack of keepalive/traffic from the owner. 1378 * Generic connection timeout implementation.
1379 *
1380 * Timeout function due to lack of keepalive/traffic from an endpoint.
1379 * Destroys connection if called. 1381 * Destroys connection if called.
1380 * 1382 *
1381 * @param cls Closure (connection to destroy). 1383 * @param c Connection to destroy.
1382 * @param tc TaskContext. 1384 * @param fwd Was the timeout from the origin? (FWD timeout)
1383 */ 1385 */
1384static void 1386static void
1385connection_fwd_timeout (void *cls, 1387connection_timeout (struct CadetConnection *c, int fwd)
1386 const struct GNUNET_SCHEDULER_TaskContext *tc)
1387{ 1388{
1388 struct CadetConnection *c = cls; 1389 struct CadetFlowControl *reverse_fc;
1389 1390
1390 c->fwd_maintenance_task = NULL; 1391 reverse_fc = fwd ? c->bck_fc : c->fwd_fc;
1391 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1392 return;
1393 1392
1394 LOG (GNUNET_ERROR_TYPE_INFO, 1393 LOG (GNUNET_ERROR_TYPE_INFO,
1395 "Connection %s FWD timed out. Destroying.\n", 1394 "Connection %s %s timed out. Destroying.\n",
1396 GCC_2s (c)); 1395 GCC_2s (c),
1396 GC_f2s (fwd));
1397 GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); 1397 GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG);
1398 1398
1399 if (GCC_is_origin (c, GNUNET_YES)) /* If local, leave. */ 1399 if (GCC_is_origin (c, fwd)) /* Loopback? Something is wrong! */
1400 { 1400 {
1401 GNUNET_break (0); 1401 GNUNET_break (0);
1402 return; 1402 return;
1403 } 1403 }
1404 1404
1405 /* If dest, salvage queued traffic. */ 1405 /* If dest, salvage queued traffic. */
1406 if (GCC_is_origin (c, GNUNET_NO) && 0 < c->bck_fc.queue_n) 1406 if (GCC_is_origin (c, !fwd))
1407 { 1407 {
1408 send_broken_unknown (&c->id, &my_full_id, NULL, 1408 struct GNUNET_PeerIdentity *next_hop;
1409 GCP_get_id( get_prev_hop (c))); 1409
1410 resend_messages_and_destroy (c, GNUNET_NO); 1410 next_hop = fwd ? get_prev_hop (c) : get_next_hop (c);
1411 send_broken_unknown (&c->id, &my_full_id, NULL, GCP_get_id (next_hop));
1412 if (0 < reverse_fc->queue_n)
1413 resend_messages_and_destroy (c, !fwd);
1411 return; 1414 return;
1412 } 1415 }
1413 1416
@@ -1416,43 +1419,45 @@ connection_fwd_timeout (void *cls,
1416 1419
1417 1420
1418/** 1421/**
1419 * Timeout function due to lack of keepalive/traffic from the destination. 1422 * Timeout function due to lack of keepalive/traffic from the owner.
1420 * Destroys connection if called. 1423 * Destroys connection if called.
1421 * 1424 *
1422 * FIXME refactor and merge with connection_fwd_timeout.
1423 *
1424 * @param cls Closure (connection to destroy). 1425 * @param cls Closure (connection to destroy).
1425 * @param tc TaskContext 1426 * @param tc TaskContext.
1426 */ 1427 */
1427static void 1428static void
1428connection_bck_timeout (void *cls, 1429connection_fwd_timeout (void *cls,
1429 const struct GNUNET_SCHEDULER_TaskContext *tc) 1430 const struct GNUNET_SCHEDULER_TaskContext *tc)
1430{ 1431{
1431 struct CadetConnection *c = cls; 1432 struct CadetConnection *c = cls;
1433 struct CadetFlowControl *fc;
1432 1434
1433 c->bck_maintenance_task = NULL; 1435 c->fwd_maintenance_task = NULL;
1434 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1436 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1435 return; 1437 return;
1436 1438
1437 LOG (GNUNET_ERROR_TYPE_INFO, "Connection %s BCK timed out. Destroying.\n", 1439 connection_timeout (c, GNUNET_YES);
1438 GCC_2s (c)); 1440}
1439 1441
1440 if (GCC_is_origin (c, GNUNET_NO)) /* If local, leave. */
1441 {
1442 GNUNET_break (0);
1443 return;
1444 }
1445 1442
1446 /* If dest, salvage queued traffic. */ 1443/**
1447 if (GCC_is_origin (c, GNUNET_YES) && 0 < c->fwd_fc.queue_n) 1444 * Timeout function due to lack of keepalive/traffic from the destination.
1448 { 1445 * Destroys connection if called.
1449 send_broken_unknown (&c->id, &my_full_id, NULL, 1446 *
1450 GCP_get_id (get_next_hop (c))); 1447 * @param cls Closure (connection to destroy).
1451 resend_messages_and_destroy (c, GNUNET_YES); 1448 * @param tc TaskContext
1449 */
1450static void
1451connection_bck_timeout (void *cls,
1452 const struct GNUNET_SCHEDULER_TaskContext *tc)
1453{
1454 struct CadetConnection *c = cls;
1455
1456 c->bck_maintenance_task = NULL;
1457 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1452 return; 1458 return;
1453 }
1454 1459
1455 GCC_destroy (c); 1460 connection_timeout (c, GNUNET_NO);
1456} 1461}
1457 1462
1458 1463