diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-08-09 17:01:48 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-08-09 17:01:48 +0200 |
commit | a988ac21cb6b8e321a6b5b29a1429d8c9848fd35 (patch) | |
tree | 2343e693902d690d9e9309df08c77ac319e10da2 /src | |
parent | 5b7ed686d4a6c4ecb8e0302a42e85bb9bff42cac (diff) | |
download | gnunet-a988ac21cb6b8e321a6b5b29a1429d8c9848fd35.tar.gz gnunet-a988ac21cb6b8e321a6b5b29a1429d8c9848fd35.zip |
adjust RPS to new CADET API semantic, dead code elimination
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 109 |
1 files changed, 22 insertions, 87 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index d601ac7d4..76c5b10f9 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -1590,6 +1590,7 @@ Peers_handle_inbound_channel (void *cls, | |||
1590 | "Already got one receive channel. Destroying old one.\n"); | 1590 | "Already got one receive channel. Destroying old one.\n"); |
1591 | GNUNET_break_op (0); | 1591 | GNUNET_break_op (0); |
1592 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel); | 1592 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel); |
1593 | peer_ctx->recv_channel_ctx->channel = NULL; | ||
1593 | remove_channel_ctx (peer_ctx->recv_channel_ctx); | 1594 | remove_channel_ctx (peer_ctx->recv_channel_ctx); |
1594 | peer_ctx->recv_channel_ctx = channel_ctx; | 1595 | peer_ctx->recv_channel_ctx = channel_ctx; |
1595 | /* return the channel context */ | 1596 | /* return the channel context */ |
@@ -1716,58 +1717,6 @@ destroy_channel (void *cls) | |||
1716 | remove_channel_ctx (peer_ctx->send_channel_ctx); | 1717 | remove_channel_ctx (peer_ctx->send_channel_ctx); |
1717 | } | 1718 | } |
1718 | 1719 | ||
1719 | /** | ||
1720 | * This is called when a channel is destroyed. | ||
1721 | * | ||
1722 | * @param cls The closure | ||
1723 | * @param channel The channel being closed | ||
1724 | */ | ||
1725 | void | ||
1726 | Peers_cleanup_destroyed_channel (void *cls, | ||
1727 | const struct GNUNET_CADET_Channel *channel) | ||
1728 | { | ||
1729 | struct ChannelCtx *channel_ctx = cls; | ||
1730 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
1731 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
1732 | |||
1733 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1734 | {/* We don't want to implicitly create a context that we're about to kill */ | ||
1735 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1736 | "channel (%s) without associated context was destroyed\n", | ||
1737 | GNUNET_i2s (peer)); | ||
1738 | return; | ||
1739 | } | ||
1740 | |||
1741 | /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY | ||
1742 | * flag will be set. In this case simply make sure that the channels are | ||
1743 | * cleaned. */ | ||
1744 | /* The distinction seems to be redundant */ | ||
1745 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1746 | "Peer is NOT in the process of being destroyed\n"); | ||
1747 | if ( (NULL != peer_ctx->send_channel_ctx) && | ||
1748 | (channel == peer_ctx->send_channel_ctx->channel) ) | ||
1749 | { /* Something (but us) killd the channel - clean up peer */ | ||
1750 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1751 | "send channel (%s) was destroyed - cleaning up\n", | ||
1752 | GNUNET_i2s (peer)); | ||
1753 | remove_channel_ctx (peer_ctx->send_channel_ctx); | ||
1754 | } | ||
1755 | else if ( (NULL != peer_ctx->recv_channel_ctx) && | ||
1756 | (channel == peer_ctx->recv_channel_ctx->channel) ) | ||
1757 | { /* Other peer doesn't want to send us messages anymore */ | ||
1758 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1759 | "Peer %s destroyed recv channel - cleaning up channel\n", | ||
1760 | GNUNET_i2s (peer)); | ||
1761 | remove_channel_ctx (peer_ctx->send_channel_ctx); | ||
1762 | } | ||
1763 | else | ||
1764 | { | ||
1765 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1766 | "unknown channel (%s) was destroyed\n", | ||
1767 | GNUNET_i2s (peer)); | ||
1768 | } | ||
1769 | (void) Peers_check_connected (peer); | ||
1770 | } | ||
1771 | 1720 | ||
1772 | /** | 1721 | /** |
1773 | * @brief Send a message to another peer. | 1722 | * @brief Send a message to another peer. |
@@ -2704,6 +2653,7 @@ add_channel_ctx (struct PeerContext *peer_ctx) | |||
2704 | return channel_ctx; | 2653 | return channel_ctx; |
2705 | } | 2654 | } |
2706 | 2655 | ||
2656 | |||
2707 | /** | 2657 | /** |
2708 | * @brief Remove the channel context from the DLL and free the memory. | 2658 | * @brief Remove the channel context from the DLL and free the memory. |
2709 | * | 2659 | * |
@@ -2713,12 +2663,12 @@ static void | |||
2713 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | 2663 | remove_channel_ctx (struct ChannelCtx *channel_ctx) |
2714 | { | 2664 | { |
2715 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 2665 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2666 | |||
2716 | if (NULL != channel_ctx->destruction_task) | 2667 | if (NULL != channel_ctx->destruction_task) |
2717 | { | 2668 | { |
2718 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | 2669 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); |
2719 | } | 2670 | } |
2720 | GNUNET_free (channel_ctx); | 2671 | GNUNET_free (channel_ctx); |
2721 | |||
2722 | if (channel_ctx == peer_ctx->send_channel_ctx) | 2672 | if (channel_ctx == peer_ctx->send_channel_ctx) |
2723 | { | 2673 | { |
2724 | peer_ctx->send_channel_ctx = NULL; | 2674 | peer_ctx->send_channel_ctx = NULL; |
@@ -2730,16 +2680,11 @@ remove_channel_ctx (struct ChannelCtx *channel_ctx) | |||
2730 | } | 2680 | } |
2731 | else | 2681 | else |
2732 | { | 2682 | { |
2733 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2734 | "Trying to remove channel_ctx that is not associated with a peer\n"); | ||
2735 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2736 | "\trecv: %p\n", peer_ctx->recv_channel_ctx); | ||
2737 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2738 | "\tsend: %p\n", peer_ctx->send_channel_ctx); | ||
2739 | GNUNET_assert (0); | 2683 | GNUNET_assert (0); |
2740 | } | 2684 | } |
2741 | } | 2685 | } |
2742 | 2686 | ||
2687 | |||
2743 | /** | 2688 | /** |
2744 | * @brief This is called when a channel is destroyed. | 2689 | * @brief This is called when a channel is destroyed. |
2745 | * | 2690 | * |
@@ -2757,21 +2702,7 @@ cleanup_destroyed_channel (void *cls, | |||
2757 | const struct GNUNET_CADET_Channel *channel) | 2702 | const struct GNUNET_CADET_Channel *channel) |
2758 | { | 2703 | { |
2759 | struct ChannelCtx *channel_ctx = cls; | 2704 | struct ChannelCtx *channel_ctx = cls; |
2760 | struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | 2705 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2761 | struct PeerContext *peer_ctx; | ||
2762 | |||
2763 | GNUNET_assert (NULL != peer); | ||
2764 | |||
2765 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
2766 | { /* We don't know a context to that peer */ | ||
2767 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2768 | "channel (%s) without associated context was destroyed\n", | ||
2769 | GNUNET_i2s (peer)); | ||
2770 | remove_channel_ctx (channel_ctx); | ||
2771 | return; | ||
2772 | } | ||
2773 | |||
2774 | peer_ctx = get_peer_ctx (peer); | ||
2775 | 2706 | ||
2776 | // What should be done here: | 2707 | // What should be done here: |
2777 | // * cleanup everything related to the channel | 2708 | // * cleanup everything related to the channel |
@@ -4235,6 +4166,7 @@ client_disconnect_cb (void *cls, | |||
4235 | { | 4166 | { |
4236 | struct ClientContext *cli_ctx = internal_cls; | 4167 | struct ClientContext *cli_ctx = internal_cls; |
4237 | 4168 | ||
4169 | (void) cls; | ||
4238 | GNUNET_assert (client == cli_ctx->client); | 4170 | GNUNET_assert (client == cli_ctx->client); |
4239 | if (NULL == client) | 4171 | if (NULL == client) |
4240 | {/* shutdown task - destroy all clients */ | 4172 | {/* shutdown task - destroy all clients */ |
@@ -4262,28 +4194,31 @@ run (void *cls, | |||
4262 | const struct GNUNET_CONFIGURATION_Handle *c, | 4194 | const struct GNUNET_CONFIGURATION_Handle *c, |
4263 | struct GNUNET_SERVICE_Handle *service) | 4195 | struct GNUNET_SERVICE_Handle *service) |
4264 | { | 4196 | { |
4265 | char* fn_valid_peers; | 4197 | char *fn_valid_peers; |
4266 | 4198 | ||
4267 | GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL); | 4199 | (void) cls; |
4200 | (void) service; | ||
4201 | GNUNET_log_setup ("rps", | ||
4202 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), | ||
4203 | NULL); | ||
4268 | cfg = c; | 4204 | cfg = c; |
4269 | |||
4270 | |||
4271 | /* Get own ID */ | 4205 | /* Get own ID */ |
4272 | GNUNET_CRYPTO_get_peer_identity (cfg, &own_identity); // TODO check return value | 4206 | GNUNET_CRYPTO_get_peer_identity (cfg, |
4207 | &own_identity); // TODO check return value | ||
4273 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4274 | "STARTING SERVICE (rps) for peer [%s]\n", | 4209 | "STARTING SERVICE (rps) for peer [%s]\n", |
4275 | GNUNET_i2s (&own_identity)); | 4210 | GNUNET_i2s (&own_identity)); |
4276 | #ifdef ENABLE_MALICIOUS | 4211 | #ifdef ENABLE_MALICIOUS |
4277 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 4212 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4278 | "Malicious execution compiled in.\n"); | 4213 | "Malicious execution compiled in.\n"); |
4279 | #endif /* ENABLE_MALICIOUS */ | 4214 | #endif /* ENABLE_MALICIOUS */ |
4280 | |||
4281 | |||
4282 | 4215 | ||
4283 | /* Get time interval from the configuration */ | 4216 | /* Get time interval from the configuration */ |
4284 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "RPS", | 4217 | if (GNUNET_OK != |
4285 | "ROUNDINTERVAL", | 4218 | GNUNET_CONFIGURATION_get_value_time (cfg, |
4286 | &round_interval)) | 4219 | "RPS", |
4220 | "ROUNDINTERVAL", | ||
4221 | &round_interval)) | ||
4287 | { | 4222 | { |
4288 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 4223 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
4289 | "RPS", "ROUNDINTERVAL"); | 4224 | "RPS", "ROUNDINTERVAL"); |
@@ -4365,7 +4300,7 @@ run (void *cls, | |||
4365 | &Peers_handle_inbound_channel, /* Connect handler */ | 4300 | &Peers_handle_inbound_channel, /* Connect handler */ |
4366 | NULL, /* cls */ | 4301 | NULL, /* cls */ |
4367 | NULL, /* WindowSize handler */ | 4302 | NULL, /* WindowSize handler */ |
4368 | cleanup_destroyed_channel, /* Disconnect handler */ | 4303 | &cleanup_destroyed_channel, /* Disconnect handler */ |
4369 | cadet_handlers); | 4304 | cadet_handlers); |
4370 | if (NULL == cadet_port) | 4305 | if (NULL == cadet_port) |
4371 | { | 4306 | { |