diff options
author | Bart Polot <bart@net.in.tum.de> | 2014-12-15 07:17:42 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2014-12-15 07:17:42 +0000 |
commit | 6c270d3d3218d0baee344ed2edb2bd6d77ea6c9e (patch) | |
tree | 03e6cb0a621aab7b7493a0ae99c4ae8392b2fc26 /src | |
parent | e15c8c18bbf8735b000043ce785904680210d789 (diff) | |
download | gnunet-6c270d3d3218d0baee344ed2edb2bd6d77ea6c9e.tar.gz gnunet-6c270d3d3218d0baee344ed2edb2bd6d77ea6c9e.zip |
- refactor resend_messages_and_destroy for popping and sending messages of a dead connection
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 116 |
1 files changed, 40 insertions, 76 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 47fb40151..31b880fd5 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -1258,6 +1258,43 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1258 | 1258 | ||
1259 | 1259 | ||
1260 | /** | 1260 | /** |
1261 | * Resend all queued messages for a connection on other connections of the | ||
1262 | * same tunnel, if possible. The connection WILL BE DESTROYED by this function. | ||
1263 | * | ||
1264 | * @param c Connection whose messages to resend. | ||
1265 | * @param fwd Resend fwd messages? | ||
1266 | */ | ||
1267 | static void | ||
1268 | resend_messages_and_destroy (struct CadetConnection *c, int fwd) | ||
1269 | { | ||
1270 | struct GNUNET_MessageHeader *out_msg; | ||
1271 | struct CadetTunnel *t = c->t; | ||
1272 | struct CadetPeer *neighbor; | ||
1273 | int destroyed; | ||
1274 | |||
1275 | c->state = CADET_CONNECTION_DESTROYED; | ||
1276 | c->destroy = GNUNET_YES; | ||
1277 | |||
1278 | destroyed = GNUNET_NO; | ||
1279 | neighbor = get_hop (c, fwd); | ||
1280 | |||
1281 | while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) | ||
1282 | GCT_resend_message (out_msg, t); | ||
1283 | |||
1284 | /* All pending messages should have been popped, | ||
1285 | * and the connection destroyed by the continuation. | ||
1286 | */ | ||
1287 | if (GNUNET_YES != destroyed) | ||
1288 | { | ||
1289 | GNUNET_break (0); | ||
1290 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); | ||
1291 | GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); | ||
1292 | GCC_destroy (c); | ||
1293 | } | ||
1294 | } | ||
1295 | |||
1296 | |||
1297 | /** | ||
1261 | * Timeout function due to lack of keepalive/traffic from the owner. | 1298 | * Timeout function due to lack of keepalive/traffic from the owner. |
1262 | * Destroys connection if called. | 1299 | * Destroys connection if called. |
1263 | * | 1300 | * |
@@ -1287,31 +1324,7 @@ connection_fwd_timeout (void *cls, | |||
1287 | /* If dest, salvage queued traffic. */ | 1324 | /* If dest, salvage queued traffic. */ |
1288 | if (GCC_is_origin (c, GNUNET_NO) && 0 < c->bck_fc.queue_n) | 1325 | if (GCC_is_origin (c, GNUNET_NO) && 0 < c->bck_fc.queue_n) |
1289 | { | 1326 | { |
1290 | struct GNUNET_MessageHeader *out_msg; | 1327 | resend_messages_and_destroy (c, GNUNET_NO); |
1291 | struct CadetPeer *neighbor; | ||
1292 | struct CadetTunnel *t; | ||
1293 | int destroyed; | ||
1294 | |||
1295 | t = c->t; | ||
1296 | c->destroy = GNUNET_YES; | ||
1297 | c->state = CADET_CONNECTION_DESTROYED; | ||
1298 | destroyed = GNUNET_NO; | ||
1299 | neighbor = get_hop (c, GNUNET_NO); | ||
1300 | |||
1301 | /* GCP_connection_pop could destroy the connection! */ | ||
1302 | while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) | ||
1303 | { | ||
1304 | GCT_resend_message (out_msg, t); | ||
1305 | } | ||
1306 | /* All pending messages should have been popped, | ||
1307 | * and the connection destroyed by the continuation. | ||
1308 | */ | ||
1309 | if (GNUNET_YES != destroyed) | ||
1310 | { | ||
1311 | GNUNET_break (0); | ||
1312 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); | ||
1313 | GCC_destroy (c); | ||
1314 | } | ||
1315 | return; | 1328 | return; |
1316 | } | 1329 | } |
1317 | 1330 | ||
@@ -1350,30 +1363,7 @@ connection_bck_timeout (void *cls, | |||
1350 | /* If dest, salvage queued traffic. */ | 1363 | /* If dest, salvage queued traffic. */ |
1351 | if (GCC_is_origin (c, GNUNET_YES) && 0 < c->fwd_fc.queue_n) | 1364 | if (GCC_is_origin (c, GNUNET_YES) && 0 < c->fwd_fc.queue_n) |
1352 | { | 1365 | { |
1353 | struct GNUNET_MessageHeader *out_msg; | 1366 | resend_messages_and_destroy (c, GNUNET_YES); |
1354 | struct CadetPeer *neighbor; | ||
1355 | struct CadetTunnel *t; | ||
1356 | int destroyed; | ||
1357 | |||
1358 | t = c->t; | ||
1359 | c->destroy = GNUNET_YES; | ||
1360 | destroyed = GNUNET_NO; | ||
1361 | neighbor = get_hop (c, GNUNET_YES); | ||
1362 | |||
1363 | /* GCP_connection_pop could destroy the connection! */ | ||
1364 | while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) | ||
1365 | { | ||
1366 | GCT_resend_message (out_msg, t); | ||
1367 | } | ||
1368 | /* All pending messages should have been popped, | ||
1369 | * and the connection destroyed by the continuation. | ||
1370 | */ | ||
1371 | if (GNUNET_YES != destroyed) | ||
1372 | { | ||
1373 | GNUNET_break (0); | ||
1374 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); | ||
1375 | GCC_destroy (c); | ||
1376 | } | ||
1377 | return; | 1367 | return; |
1378 | } | 1368 | } |
1379 | 1369 | ||
@@ -1838,8 +1828,6 @@ GCC_handle_broken (void* cls, | |||
1838 | c->destroy = GNUNET_YES; | 1828 | c->destroy = GNUNET_YES; |
1839 | if (GCC_is_terminal (c, fwd)) | 1829 | if (GCC_is_terminal (c, fwd)) |
1840 | { | 1830 | { |
1841 | struct GNUNET_MessageHeader *out_msg; | ||
1842 | struct CadetPeer *neighbor; | ||
1843 | struct CadetPeer *endpoint; | 1831 | struct CadetPeer *endpoint; |
1844 | 1832 | ||
1845 | if (NULL == t) | 1833 | if (NULL == t) |
@@ -1849,7 +1837,6 @@ GCC_handle_broken (void* cls, | |||
1849 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); | 1837 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); |
1850 | return GNUNET_OK; | 1838 | return GNUNET_OK; |
1851 | } | 1839 | } |
1852 | neighbor = get_hop (c, !fwd); | ||
1853 | endpoint = GCP_get_short (c->path->peers[c->path->length - 1]); | 1840 | endpoint = GCP_get_short (c->path->peers[c->path->length - 1]); |
1854 | path_invalidate (c->path); | 1841 | path_invalidate (c->path); |
1855 | GCP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2); | 1842 | GCP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2); |
@@ -1860,32 +1847,9 @@ GCC_handle_broken (void* cls, | |||
1860 | 1847 | ||
1861 | pending = c->pending_messages; | 1848 | pending = c->pending_messages; |
1862 | if (0 < pending) | 1849 | if (0 < pending) |
1863 | { | 1850 | resend_messages_and_destroy (c, !fwd); |
1864 | int destroyed; | ||
1865 | |||
1866 | destroyed = GNUNET_NO; | ||
1867 | |||
1868 | /* GCP_connection_pop could destroy the connection! */ | ||
1869 | while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) | ||
1870 | { | ||
1871 | GCT_resend_message (out_msg, t); | ||
1872 | } | ||
1873 | |||
1874 | /* All pending messages should have been popped, | ||
1875 | * and the connection destroyed by the continuation, | ||
1876 | * except if the queue was empty. */ | ||
1877 | if (GNUNET_YES != destroyed) | ||
1878 | { | ||
1879 | GNUNET_break (0); | ||
1880 | GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); | ||
1881 | GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); | ||
1882 | GCC_destroy (c); | ||
1883 | } | ||
1884 | } | ||
1885 | else | 1851 | else |
1886 | { | ||
1887 | GCC_destroy (c); | 1852 | GCC_destroy (c); |
1888 | } | ||
1889 | } | 1853 | } |
1890 | else | 1854 | else |
1891 | { | 1855 | { |