diff options
author | Julius Bünger <buenger@mytum.de> | 2018-08-07 16:02:36 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-08-07 16:02:36 +0200 |
commit | b3932f39b028d5db0d2e641e8593679c657b6bd1 (patch) | |
tree | 5ca204e6ca715860a3c8ac075072d4e0b968ca2c /src | |
parent | fcaa5854af792cad00c36ed1fd1c4e7fc2602f65 (diff) | |
download | gnunet-b3932f39b028d5db0d2e641e8593679c657b6bd1.tar.gz gnunet-b3932f39b028d5db0d2e641e8593679c657b6bd1.zip |
Restructure removal of peers during shutdown (rps service)
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 114 |
1 files changed, 64 insertions, 50 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index f48b3d85d..21963ee42 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -68,6 +68,7 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
68 | */ | 68 | */ |
69 | static struct GNUNET_PeerIdentity own_identity; | 69 | static struct GNUNET_PeerIdentity own_identity; |
70 | 70 | ||
71 | static int in_shutdown = GNUNET_NO; | ||
71 | 72 | ||
72 | /** | 73 | /** |
73 | * @brief Port used for cadet. | 74 | * @brief Port used for cadet. |
@@ -1271,7 +1272,30 @@ destroy_channel (void *cls); | |||
1271 | 1272 | ||
1272 | 1273 | ||
1273 | static void | 1274 | static void |
1274 | schedule_channel_destruction (struct ChannelCtx *channel_ctx); | 1275 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) |
1276 | { | ||
1277 | GNUNET_assert (NULL != channel_ctx); | ||
1278 | if (NULL != channel_ctx->destruction_task && | ||
1279 | GNUNET_NO == in_shutdown) | ||
1280 | { | ||
1281 | channel_ctx->destruction_task = | ||
1282 | GNUNET_SCHEDULER_add_now (destroy_channel, channel_ctx); | ||
1283 | } | ||
1284 | } | ||
1285 | |||
1286 | |||
1287 | static void | ||
1288 | schedule_peer_destruction (struct PeerContext *peer_ctx) | ||
1289 | { | ||
1290 | GNUNET_assert (NULL != peer_ctx); | ||
1291 | if (NULL != peer_ctx->destruction_task && | ||
1292 | GNUNET_NO == in_shutdown) | ||
1293 | { | ||
1294 | peer_ctx->destruction_task = | ||
1295 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1296 | } | ||
1297 | } | ||
1298 | |||
1275 | 1299 | ||
1276 | /** | 1300 | /** |
1277 | * @brief Remove peer | 1301 | * @brief Remove peer |
@@ -1285,6 +1309,8 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1285 | { | 1309 | { |
1286 | struct PeerContext *peer_ctx; | 1310 | struct PeerContext *peer_ctx; |
1287 | 1311 | ||
1312 | GNUNET_assert (NULL != peer_map); | ||
1313 | |||
1288 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) | 1314 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) |
1289 | { | 1315 | { |
1290 | return GNUNET_NO; | 1316 | return GNUNET_NO; |
@@ -1296,35 +1322,13 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1296 | "Going to remove peer %s\n", | 1322 | "Going to remove peer %s\n", |
1297 | GNUNET_i2s (&peer_ctx->peer_id)); | 1323 | GNUNET_i2s (&peer_ctx->peer_id)); |
1298 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 1324 | Peers_unset_peer_flag (peer, Peers_ONLINE); |
1299 | /* Do we still have to wait for destruction of channels | ||
1300 | * or issue the destruction? */ | ||
1301 | if (NULL != peer_ctx->send_channel_ctx && | ||
1302 | NULL != peer_ctx->send_channel_ctx->destruction_task) | ||
1303 | { | ||
1304 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1305 | return GNUNET_NO; | ||
1306 | } | ||
1307 | if (NULL != peer_ctx->recv_channel_ctx && | ||
1308 | NULL != peer_ctx->recv_channel_ctx->destruction_task) | ||
1309 | { | ||
1310 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1311 | return GNUNET_NO; | ||
1312 | } | ||
1313 | if (NULL != peer_ctx->recv_channel_ctx) | ||
1314 | { | ||
1315 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
1316 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1317 | return GNUNET_NO; | ||
1318 | } | ||
1319 | if (NULL != peer_ctx->send_channel_ctx) | ||
1320 | { | ||
1321 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
1322 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1323 | return GNUNET_NO; | ||
1324 | } | ||
1325 | 1325 | ||
1326 | /* Clear list of pending operations */ | ||
1326 | // TODO this probably leaks memory | 1327 | // TODO this probably leaks memory |
1328 | // ('only' the cls to the function. Not sure what to do with it) | ||
1327 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | 1329 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); |
1330 | |||
1331 | /* Remove all pending messages */ | ||
1328 | while (NULL != peer_ctx->pending_messages_head) | 1332 | while (NULL != peer_ctx->pending_messages_head) |
1329 | { | 1333 | { |
1330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1334 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1341,6 +1345,7 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1341 | } | 1345 | } |
1342 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); | 1346 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); |
1343 | } | 1347 | } |
1348 | |||
1344 | /* If we are still waiting for notification whether this peer is live | 1349 | /* If we are still waiting for notification whether this peer is live |
1345 | * cancel the according task */ | 1350 | * cancel the according task */ |
1346 | if (NULL != peer_ctx->liveliness_check_pending) | 1351 | if (NULL != peer_ctx->liveliness_check_pending) |
@@ -1354,6 +1359,35 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1354 | peer_ctx->liveliness_check_pending = NULL; | 1359 | peer_ctx->liveliness_check_pending = NULL; |
1355 | } | 1360 | } |
1356 | 1361 | ||
1362 | |||
1363 | /* Do we still have to wait for destruction of channels | ||
1364 | * or issue the destruction? */ | ||
1365 | if (NULL != peer_ctx->send_channel_ctx && | ||
1366 | NULL != peer_ctx->send_channel_ctx->destruction_task | ||
1367 | ) | ||
1368 | { | ||
1369 | schedule_peer_destruction (peer_ctx); | ||
1370 | return GNUNET_NO; | ||
1371 | } | ||
1372 | if (NULL != peer_ctx->recv_channel_ctx && | ||
1373 | NULL != peer_ctx->recv_channel_ctx->destruction_task) | ||
1374 | { | ||
1375 | schedule_peer_destruction (peer_ctx); | ||
1376 | return GNUNET_NO; | ||
1377 | } | ||
1378 | if (NULL != peer_ctx->recv_channel_ctx) | ||
1379 | { | ||
1380 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
1381 | schedule_peer_destruction (peer_ctx); | ||
1382 | return GNUNET_NO; | ||
1383 | } | ||
1384 | if (NULL != peer_ctx->send_channel_ctx) | ||
1385 | { | ||
1386 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
1387 | schedule_peer_destruction (peer_ctx); | ||
1388 | return GNUNET_NO; | ||
1389 | } | ||
1390 | |||
1357 | if (NULL != peer_ctx->destruction_task) | 1391 | if (NULL != peer_ctx->destruction_task) |
1358 | { | 1392 | { |
1359 | GNUNET_SCHEDULER_cancel (peer_ctx->destruction_task); | 1393 | GNUNET_SCHEDULER_cancel (peer_ctx->destruction_task); |
@@ -1367,16 +1401,6 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
1367 | return GNUNET_YES; | 1401 | return GNUNET_YES; |
1368 | } | 1402 | } |
1369 | 1403 | ||
1370 | static void | ||
1371 | schedule_peer_ctx_destruction (struct PeerContext *peer_ctx) | ||
1372 | { | ||
1373 | GNUNET_assert (NULL != peer_ctx); | ||
1374 | if (NULL == peer_ctx->destruction_task) | ||
1375 | { | ||
1376 | GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx); | ||
1377 | } | ||
1378 | } | ||
1379 | |||
1380 | /** | 1404 | /** |
1381 | * @brief set flags on a given peer. | 1405 | * @brief set flags on a given peer. |
1382 | * | 1406 | * |
@@ -1668,18 +1692,6 @@ destroy_channel (void *cls) | |||
1668 | remove_channel_ctx (peer_ctx->send_channel_ctx); | 1692 | remove_channel_ctx (peer_ctx->send_channel_ctx); |
1669 | } | 1693 | } |
1670 | 1694 | ||
1671 | static void | ||
1672 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
1673 | { | ||
1674 | GNUNET_assert (NULL != channel_ctx); | ||
1675 | if (NULL != channel_ctx->destruction_task) | ||
1676 | { | ||
1677 | channel_ctx->destruction_task = | ||
1678 | GNUNET_SCHEDULER_add_now (destroy_channel, channel_ctx); | ||
1679 | } | ||
1680 | } | ||
1681 | |||
1682 | |||
1683 | /** | 1695 | /** |
1684 | * This is called when a channel is destroyed. | 1696 | * This is called when a channel is destroyed. |
1685 | * | 1697 | * |
@@ -2609,7 +2621,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
2609 | CustomPeerMap_remove_peer (push_map, peer); | 2621 | CustomPeerMap_remove_peer (push_map, peer); |
2610 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); | 2622 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); |
2611 | RPS_sampler_reinitialise_by_value (client_sampler, peer); | 2623 | RPS_sampler_reinitialise_by_value (client_sampler, peer); |
2612 | schedule_peer_ctx_destruction (get_peer_ctx (peer)); | 2624 | schedule_peer_destruction (get_peer_ctx (peer)); |
2613 | } | 2625 | } |
2614 | 2626 | ||
2615 | 2627 | ||
@@ -4085,6 +4097,8 @@ shutdown_task (void *cls) | |||
4085 | struct ClientContext *client_ctx; | 4097 | struct ClientContext *client_ctx; |
4086 | struct ReplyCls *reply_cls; | 4098 | struct ReplyCls *reply_cls; |
4087 | 4099 | ||
4100 | in_shutdown = GNUNET_YES; | ||
4101 | |||
4088 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4102 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4089 | "RPS is going down\n"); | 4103 | "RPS is going down\n"); |
4090 | 4104 | ||