From 51ac8f0d836806a499bdb8988d80380a78e736de Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Tue, 25 Jun 2019 18:06:44 +0200 Subject: added per message GNUNET_MQ_PriorityPreferences --- src/set/gnunet-service-set.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/set') diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 71f74594f..f1d94bef7 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -741,6 +741,8 @@ handle_incoming_msg (void *cls, env = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, op->context_msg); + GNUNET_MQ_env_set_options(env, + GNUNET_MQ_PREF_RELIABLE); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggesting incoming request with accept id %u to listener %p of client %p\n", op->suggest_id, @@ -1628,7 +1630,6 @@ handle_client_evaluate (void *cls, op, &msg->target_peer, &msg->app_id, - GNUNET_CADET_OPTION_RELIABLE, &channel_window_cb, &channel_end_cb, cadet_handlers); -- cgit v1.2.3 From a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 17 Jul 2019 10:50:45 +0200 Subject: remove duplication MQ options, make conversation build --- src/cadet/gnunet-service-cadet_channel.c | 555 ++--- src/cadet/gnunet-service-cadet_connection.c | 269 +-- src/cadet/gnunet-service-cadet_core.c | 501 ++-- src/conversation/gnunet-service-conversation.c | 415 ++-- src/fs/gnunet-service-fs_cadet_client.c | 243 +- src/include/gnunet_mq_lib.h | 33 +- .../gnunet-service-scalarproduct-ecc_alice.c | 363 ++- .../gnunet-service-scalarproduct_alice.c | 379 ++- src/set/gnunet-service-set.c | 772 +++--- src/util/mq.c | 22 + src/vpn/gnunet-service-vpn.c | 2466 ++++++++++---------- 11 files changed, 2695 insertions(+), 3323 deletions(-) (limited to 'src/set') diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 847a217c7..664b8a7c1 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c @@ -41,23 +41,26 @@ #include "gnunet-service-cadet_tunnels.h" #include "gnunet-service-cadet_paths.h" -#define LOG(level,...) GNUNET_log_from (level,"cadet-chn",__VA_ARGS__) +#define LOG(level, ...) GNUNET_log_from (level, "cadet-chn", __VA_ARGS__) /** * How long do we initially wait before retransmitting? */ -#define CADET_INITIAL_RETRANSMIT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) +#define CADET_INITIAL_RETRANSMIT_TIME \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) /** * How long do we wait before dropping state about incoming * connection to closed port? */ -#define TIMEOUT_CLOSED_PORT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT_CLOSED_PORT \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * How long do we wait at least before retransmitting ever? */ -#define MIN_RTT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) +#define MIN_RTT_DELAY \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75) /** * Maximum message ID into the future we accept for out-of-order messages. @@ -164,7 +167,6 @@ struct CadetReliableMessage * yet transmitted ever, otherwise the number of (re) transmissions. */ int num_transmissions; - }; @@ -193,7 +195,6 @@ struct CadetOutOfOrderMessage * The envelope with the payload of the out-of-order message */ struct GNUNET_MQ_Envelope *env; - }; @@ -238,7 +239,6 @@ struct CadetChannelClient * Can we send data to the client? */ int client_ready; - }; @@ -368,7 +368,7 @@ struct CadetChannel * Is the tunnel out-of-order? */ int out_of_order; - + /** * Is this channel a loopback channel, where the destination is us again? */ @@ -380,7 +380,6 @@ struct CadetChannel * empty. */ int destroy; - }; @@ -400,12 +399,16 @@ GCCH_2s (const struct CadetChannel *ch) sizeof (buf), "Channel %s:%s ctn:%X(%X/%X)", (GNUNET_YES == ch->is_loopback) - ? "loopback" - : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), + ? "loopback" + : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), GNUNET_h2s (&ch->port), ch->ctn, - (NULL == ch->owner) ? 0 : ntohl (ch->owner->ccn.channel_of_client), - (NULL == ch->dest) ? 0 : ntohl (ch->dest->ccn.channel_of_client)); + (NULL == ch->owner) + ? 0 + : ntohl (ch->owner->ccn.channel_of_client), + (NULL == ch->dest) + ? 0 + : ntohl (ch->dest->ccn.channel_of_client)); return buf; } @@ -421,20 +424,15 @@ GCCH_2s (const struct CadetChannel *ch) */ void GCCH_hash_port (struct GNUNET_HashCode *h_port, - const struct GNUNET_HashCode *port, - const struct GNUNET_PeerIdentity *listener) + const struct GNUNET_HashCode *port, + const struct GNUNET_PeerIdentity *listener) { struct GNUNET_HashContext *hc; hc = GNUNET_CRYPTO_hash_context_start (); - GNUNET_CRYPTO_hash_context_read (hc, - port, - sizeof (*port)); - GNUNET_CRYPTO_hash_context_read (hc, - listener, - sizeof (*listener)); - GNUNET_CRYPTO_hash_context_finish (hc, - h_port); + GNUNET_CRYPTO_hash_context_read (hc, port, sizeof (*port)); + GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof (*listener)); + GNUNET_CRYPTO_hash_context_finish (hc, h_port); LOG (GNUNET_ERROR_TYPE_DEBUG, "Calculated port hash %s\n", GNUNET_h2s (h_port)); @@ -467,9 +465,7 @@ free_channel_client (struct CadetChannelClient *ccc) while (NULL != (com = ccc->head_recv)) { - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - com); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); ccc->num_recv--; GNUNET_MQ_discard (com->env); GNUNET_free (com); @@ -496,16 +492,13 @@ channel_destroy (struct CadetChannel *ch) GCT_send_cancel (crm->qe); crm->qe = NULL; } - GNUNET_CONTAINER_DLL_remove (ch->head_sent, - ch->tail_sent, - crm); + GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); GNUNET_free (crm->data_message); GNUNET_free (crm); } if (CADET_CHANNEL_LOOSE == ch->state) { - GSC_drop_loose_channel (&ch->h_port, - ch); + GSC_drop_loose_channel (&ch->h_port, ch); } if (NULL != ch->owner) { @@ -534,9 +527,7 @@ channel_destroy (struct CadetChannel *ch) } if (GNUNET_NO == ch->is_loopback) { - GCT_remove_channel (ch->t, - ch, - ch->ctn); + GCT_remove_channel (ch->t, ch, ch->ctn); ch->t = NULL; } GNUNET_free (ch); @@ -572,12 +563,9 @@ channel_open_sent_cb (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", GCCH_2s (ch), - GNUNET_STRINGS_relative_time_to_string (ch->retry_time, - GNUNET_YES)); - ch->retry_control_task - = GNUNET_SCHEDULER_add_delayed (ch->retry_time, - &send_channel_open, - ch); + GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES)); + ch->retry_control_task = + GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch); } @@ -598,17 +586,15 @@ send_channel_open (void *cls) GCCH_2s (ch)); msgcc.header.size = htons (sizeof (msgcc)); msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); - //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced options. - msgcc.opt = GNUNET_MQ_PREF_RELIABLE >> 10; + //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed. + msgcc.opt = 2; msgcc.h_port = ch->h_port; msgcc.ctn = ch->ctn; ch->state = CADET_CHANNEL_OPEN_SENT; if (NULL != ch->last_control_qe) GCT_send_cancel (ch->last_control_qe); - ch->last_control_qe = GCT_send (ch->t, - &msgcc.header, - &channel_open_sent_cb, - ch); + ch->last_control_qe = + GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); GNUNET_assert (NULL == ch->retry_control_task); } @@ -630,9 +616,7 @@ GCCH_tunnel_up (struct CadetChannel *ch) LOG (GNUNET_ERROR_TYPE_DEBUG, "Tunnel up, sending CHANNEL_OPEN on %s now\n", GCCH_2s (ch)); - ch->retry_control_task - = GNUNET_SCHEDULER_add_now (&send_channel_open, - ch); + ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch); } @@ -663,54 +647,45 @@ GCCH_channel_local_new (struct CadetClient *owner, ch = GNUNET_new (struct CadetChannel); ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ - ch->nobuffer = GNUNET_NO ; + ch->nobuffer = GNUNET_NO; ch->reliable = GNUNET_YES; - ch->out_of_order = GNUNET_NO ; - ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ + ch->out_of_order = GNUNET_NO; + ch->max_pending_messages = + (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ ch->owner = ccco; ch->port = *port; - GCCH_hash_port (&ch->h_port, - port, - GCP_get_id (destination)); - if (0 == GNUNET_memcmp (&my_full_id, - GCP_get_id (destination))) + GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination)); + if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination))) { struct OpenPort *op; ch->is_loopback = GNUNET_YES; - op = GNUNET_CONTAINER_multihashmap_get (open_ports, - &ch->h_port); + op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port); if (NULL == op) { /* port closed, wait for it to possibly open */ ch->state = CADET_CHANNEL_LOOSE; - (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, - &ch->h_port, - ch, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + (void) GNUNET_CONTAINER_multihashmap_put ( + loose_channels, + &ch->h_port, + ch, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); LOG (GNUNET_ERROR_TYPE_DEBUG, "Created loose incoming loopback channel to port %s\n", GNUNET_h2s (&ch->port)); } else { - GCCH_bind (ch, - op->c, - &op->port); + GCCH_bind (ch, op->c, &op->port); } } else { - ch->t = GCP_get_tunnel (destination, - GNUNET_YES); + ch->t = GCP_get_tunnel (destination, GNUNET_YES); ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; - ch->ctn = GCT_add_channel (ch->t, - ch); + ch->ctn = GCT_add_channel (ch->t, ch); } - GNUNET_STATISTICS_update (stats, - "# channels", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, "Created channel to port %s at peer %s for %s using %s\n", GNUNET_h2s (port), @@ -767,27 +742,24 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, ch->nobuffer = GNUNET_NO; ch->reliable = GNUNET_YES; ch->out_of_order = GNUNET_NO; - ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ - GNUNET_STATISTICS_update (stats, - "# channels", - 1, - GNUNET_NO); - - op = GNUNET_CONTAINER_multihashmap_get (open_ports, - h_port); + ch->max_pending_messages = + (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ + GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); + + op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port); if (NULL == op) { /* port closed, wait for it to possibly open */ ch->state = CADET_CHANNEL_LOOSE; - (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, - &ch->h_port, - ch, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + (void) GNUNET_CONTAINER_multihashmap_put ( + loose_channels, + &ch->h_port, + ch, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); GNUNET_assert (NULL == ch->retry_control_task); - ch->retry_control_task - = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, - &timeout_closed_cb, - ch); + ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, + &timeout_closed_cb, + ch); LOG (GNUNET_ERROR_TYPE_DEBUG, "Created loose incoming channel to port %s from peer %s\n", GNUNET_h2s (&ch->port), @@ -795,14 +767,9 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, } else { - GCCH_bind (ch, - op->c, - &op->port); + GCCH_bind (ch, op->c, &op->port); } - GNUNET_STATISTICS_update (stats, - "# channels", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); return ch; } @@ -851,10 +818,7 @@ send_channel_data_ack (struct CadetChannel *ch) GCCH_2s (ch)); if (NULL != ch->last_control_qe) GCT_send_cancel (ch->last_control_qe); - ch->last_control_qe = GCT_send (ch->t, - &msg.header, - &send_ack_cb, - ch); + ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); } @@ -881,10 +845,7 @@ send_open_ack (void *cls) msg.port = ch->port; if (NULL != ch->last_control_qe) GCT_send_cancel (ch->last_control_qe); - ch->last_control_qe = GCT_send (ch->t, - &msg.header, - &send_ack_cb, - ch); + ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); } @@ -897,8 +858,9 @@ send_open_ack (void *cls) * @param cti identifier of the connection that delivered the message */ void -GCCH_handle_duplicate_open (struct CadetChannel *ch, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) +GCCH_handle_duplicate_open ( + struct CadetChannel *ch, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) { if (NULL == ch->dest) { @@ -917,9 +879,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, LOG (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting CHANNEL_OPEN_ACK on %s\n", GCCH_2s (ch)); - ch->retry_control_task - = GNUNET_SCHEDULER_add_now (&send_open_ack, - ch); + ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); } @@ -931,8 +891,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, * #GNUNET_NO to send to dest */ static void -send_ack_to_client (struct CadetChannel *ch, - int to_owner) +send_ack_to_client (struct CadetChannel *ch, int to_owner) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalAck *ack; @@ -946,8 +905,7 @@ send_ack_to_client (struct CadetChannel *ch, GNUNET_assert (GNUNET_YES == ch->destroy); return; } - env = GNUNET_MQ_msg (ack, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); + env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); ack->ccn = ccc->ccn; LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", @@ -956,8 +914,7 @@ send_ack_to_client (struct CadetChannel *ch, ntohl (ack->ccn.channel_of_client), ch->pending_messages, ch->max_pending_messages); - GSC_send_to_client (ccc->c, - env); + GSC_send_to_client (ccc->c, env); } @@ -973,7 +930,7 @@ send_ack_to_client (struct CadetChannel *ch, void GCCH_bind (struct CadetChannel *ch, struct CadetClient *c, - const struct GNUNET_HashCode *port) + const struct GNUNET_HashCode *port) { uint32_t options; struct CadetChannelClient *cccd; @@ -1000,9 +957,8 @@ GCCH_bind (struct CadetChannel *ch, cccd->ccn = GSC_bind (c, ch, (GNUNET_YES == ch->is_loopback) - ? GCP_get (&my_full_id, - GNUNET_YES) - : GCT_get_destination (ch->t), + ? GCP_get (&my_full_id, GNUNET_YES) + : GCT_get_destination (ch->t), port, options); GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < @@ -1011,24 +967,19 @@ GCCH_bind (struct CadetChannel *ch, if (GNUNET_YES == ch->is_loopback) { ch->state = CADET_CHANNEL_OPEN_SENT; - GCCH_handle_channel_open_ack (ch, - NULL, - port); + GCCH_handle_channel_open_ack (ch, NULL, port); } else { /* notify other peer that we accepted the connection */ ch->state = CADET_CHANNEL_READY; - ch->retry_control_task - = GNUNET_SCHEDULER_add_now (&send_open_ack, - ch); + ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); } /* give client it's initial supply of ACKs */ GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); - for (unsigned int i=0;imax_pending_messages;i++) - send_ack_to_client (ch, - GNUNET_NO); + for (unsigned int i = 0; i < ch->max_pending_messages; i++) + send_ack_to_client (ch, GNUNET_NO); } @@ -1048,9 +999,7 @@ signal_remote_destroy_cb (void *cls) /* Find which end is left... */ ch->retry_control_task = NULL; ccc = (NULL != ch->owner) ? ch->owner : ch->dest; - GSC_handle_remote_channel_destroy (ccc->c, - ccc->ccn, - ch); + GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); channel_destroy (ch); } @@ -1073,16 +1022,14 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, GSC_2s (c), GCCH_2s (ch)); GNUNET_assert (NULL != c); - if ( (NULL != ch->owner) && - (c == ch->owner->c) && - (ccn.channel_of_client == ch->owner->ccn.channel_of_client) ) + if ((NULL != ch->owner) && (c == ch->owner->c) && + (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) { free_channel_client (ch->owner); ch->owner = NULL; } - else if ( (NULL != ch->dest) && - (c == ch->dest->c) && - (ccn.channel_of_client == ch->dest->ccn.channel_of_client) ) + else if ((NULL != ch->dest) && (c == ch->dest->c) && + (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) { free_channel_client (ch->dest); ch->dest = NULL; @@ -1099,24 +1046,20 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, channel_destroy (ch); return; } - if ( (NULL != ch->head_sent) && - ( (NULL != ch->owner) || - (NULL != ch->dest) ) ) + if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) { /* Wait for other end to destroy us as well, and otherwise allow send queue to be transmitted first */ ch->destroy = GNUNET_YES; return; } - if ( (GNUNET_YES == ch->is_loopback) && - ( (NULL != ch->owner) || - (NULL != ch->dest) ) ) + if ((GNUNET_YES == ch->is_loopback) && + ((NULL != ch->owner) || (NULL != ch->dest))) { if (NULL != ch->retry_control_task) GNUNET_SCHEDULER_cancel (ch->retry_control_task); - ch->retry_control_task - = GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, - ch); + ch->retry_control_task = + GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch); return; } if (GNUNET_NO == ch->is_loopback) @@ -1131,8 +1074,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, case CADET_CHANNEL_LOOSE: break; default: - GCT_send_channel_destroy (ch->t, - ch->ctn); + GCT_send_channel_destroy (ch->t, ch->ctn); } } /* Nothing left to do, just finish destruction */ @@ -1150,9 +1092,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, * @param port port number (needed to verify receiver knows the port) */ void -GCCH_handle_channel_open_ack (struct CadetChannel *ch, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, - const struct GNUNET_HashCode *port) +GCCH_handle_channel_open_ack ( + struct CadetChannel *ch, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, + const struct GNUNET_HashCode *port) { switch (ch->state) { @@ -1171,8 +1114,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, GNUNET_break_op (0); return; } - if (0 != GNUNET_memcmp (&ch->port, - port)) + if (0 != GNUNET_memcmp (&ch->port, port)) { /* Other peer failed to provide the right port, refuse connection. */ @@ -1190,19 +1132,15 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, ch->state = CADET_CHANNEL_READY; /* On first connect, send client as many ACKs as we allow messages to be buffered! */ - for (unsigned int i=0;imax_pending_messages;i++) - send_ack_to_client (ch, - GNUNET_YES); + for (unsigned int i = 0; i < ch->max_pending_messages; i++) + send_ack_to_client (ch, GNUNET_YES); break; case CADET_CHANNEL_READY: /* duplicate ACK, maybe we retried the CREATE. Ignore. */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received duplicate channel OPEN_ACK for %s\n", GCCH_2s (ch)); - GNUNET_STATISTICS_update (stats, - "# duplicate CREATE_ACKs", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); break; } } @@ -1251,9 +1189,10 @@ is_before (void *cls, * @param msg message that was received */ void -GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, - const struct GNUNET_CADET_ChannelAppDataMessage *msg) +GCCH_handle_channel_plaintext_data ( + struct CadetChannel *ch, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, + const struct GNUNET_CADET_ChannelAppDataMessage *msg) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalData *ld; @@ -1267,8 +1206,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, uint32_t delta; GNUNET_assert (GNUNET_NO == ch->is_loopback); - if ( (NULL == ch->owner) && - (NULL == ch->dest) ) + if ((NULL == ch->owner) && (NULL == ch->dest)) { /* This client is gone, but we still have messages to send to the other end (which is why @a ch is not yet dead). However, @@ -1278,8 +1216,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, GCCH_2s (ch)); /* send back DESTROY notification to stop further retransmissions! */ if (GNUNET_YES == ch->destroy) - GCT_send_channel_destroy (ch->t, - ch->ctn); + GCT_send_channel_destroy (ch->t, ch->ctn); return; } payload_size = ntohs (msg->header.size) - sizeof (*msg); @@ -1287,9 +1224,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, payload_size, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; - GNUNET_memcpy (&ld[1], - &msg[1], - payload_size); + GNUNET_memcpy (&ld[1], &msg[1], payload_size); ccc = (NULL != ch->owner) ? ch->owner : ch->dest; if (GNUNET_YES == ccc->client_ready) { @@ -1299,13 +1234,12 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, * - The channel is reliable and MID matches next expected MID * - The channel is unreliable and MID is before lowest seen MID */ - if ( (GNUNET_YES == ch->out_of_order) || - ((msg->mid.mid == ch->mid_recv.mid) && - (GNUNET_YES == ch->reliable)) || - ((GNUNET_NO == ch->reliable) && - (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && - ((NULL == ccc->head_recv) || - (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))) ) + if ((GNUNET_YES == ch->out_of_order) || + ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || + ((GNUNET_NO == ch->reliable) && + (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && + ((NULL == ccc->head_recv) || + (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid))))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u bytes of payload with MID %u from %s to client %s\n", @@ -1314,24 +1248,22 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, GCCH_2s (ch), GSC_2s (ccc->c)); ccc->client_ready = GNUNET_NO; - GSC_send_to_client (ccc->c, - env); + GSC_send_to_client (ccc->c, env); if (GNUNET_NO == ch->out_of_order) ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); else ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); ch->mid_futures >>= 1; - if ( (GNUNET_YES == ch->out_of_order) && - (GNUNET_NO == ch->reliable) ) + if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) { - /* possibly shift by more if we skipped messages */ - uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); - - if (delta > 63) - ch->mid_futures = 0; - else - ch->mid_futures >>= delta; - ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); + /* possibly shift by more if we skipped messages */ + uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); + + if (delta > 63) + ch->mid_futures = 0; + else + ch->mid_futures >>= delta; + ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); } send_channel_data_ack (ch); return; @@ -1344,8 +1276,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, mid_min = ntohl (ch->mid_recv.mid); mid_max = mid_min + ch->max_pending_messages; mid_msg = ntohl (msg->mid.mid); - if ( ( (uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || - ( (uint32_t) (mid_max - mid_msg) > ch->max_pending_messages) ) + if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || + ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "%s at %u drops ancient or far-future message %u\n", @@ -1373,10 +1305,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, (unsigned int) payload_size, GCCH_2s (ch), ntohl (msg->mid.mid)); - GNUNET_STATISTICS_update (stats, - "# duplicate DATA", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); GNUNET_MQ_discard (env); send_channel_data_ack (ch); return; @@ -1398,8 +1327,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, * We always send if possible in this case. * It is guaranteed that the queued MID < received MID **/ - if ((NULL != ccc->head_recv) && - (GNUNET_YES == ccc->client_ready)) + if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) { next_msg = ccc->head_recv; LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1408,14 +1336,11 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, GCCH_2s (ch), GSC_2s (ccc->c)); ccc->client_ready = GNUNET_NO; - GSC_send_to_client (ccc->c, - next_msg->env); + GSC_send_to_client (ccc->c, next_msg->env); ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); ch->mid_futures >>= 1; send_channel_data_ack (ch); - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - next_msg); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg); ccc->num_recv--; /* Do not process duplicate MID */ if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ @@ -1460,9 +1385,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, GNUNET_NO); drop = ccc->head_recv; GNUNET_assert (NULL != drop); - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - drop); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop); ccc->num_recv--; GNUNET_MQ_discard (drop->env); GNUNET_free (drop); @@ -1493,13 +1416,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, (unsigned int) payload_size, GCCH_2s (ch), ntohl (msg->mid.mid)); - GNUNET_STATISTICS_update (stats, - "# duplicate DATA", - 1, - GNUNET_NO); - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - com); + GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); ccc->num_recv--; GNUNET_MQ_discard (com->env); GNUNET_free (com); @@ -1508,9 +1426,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, } LOG (GNUNET_ERROR_TYPE_DEBUG, "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", - (GNUNET_YES == ccc->client_ready) - ? "out-of-order" - : "client-not-ready", + (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", (unsigned int) payload_size, GCCH_2s (ch), ntohl (ccc->ccn.channel_of_client), @@ -1558,10 +1474,7 @@ retry_transmission (void *cls) "Retrying transmission on %s of message %u\n", GCCH_2s (ch), (unsigned int) ntohl (crm->data_message->mid.mid)); - crm->qe = GCT_send (ch->t, - &crm->data_message->header, - &data_sent_cb, - crm); + crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); GNUNET_assert (NULL == ch->retry_data_task); } @@ -1579,9 +1492,7 @@ handle_matching_ack (struct CadetChannel *ch, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, struct CadetReliableMessage *crm) { - GNUNET_CONTAINER_DLL_remove (ch->head_sent, - ch->tail_sent, - crm); + GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); ch->pending_messages--; GNUNET_assert (ch->pending_messages < ch->max_pending_messages); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1594,23 +1505,19 @@ handle_matching_ack (struct CadetChannel *ch, GCT_send_cancel (crm->qe); crm->qe = NULL; } - if ( (1 == crm->num_transmissions) && - (NULL != cti) ) + if ((1 == crm->num_transmissions) && (NULL != cti)) { GCC_ack_observed (cti); - if (0 == GNUNET_memcmp (cti, - &crm->connection_taken)) + if (0 == GNUNET_memcmp (cti, &crm->connection_taken)) { GCC_latency_observed (cti, - GNUNET_TIME_absolute_get_duration (crm->first_transmission_time)); + GNUNET_TIME_absolute_get_duration ( + crm->first_transmission_time)); } } GNUNET_free (crm->data_message); GNUNET_free (crm); - send_ack_to_client (ch, - (NULL == ch->owner) - ? GNUNET_NO - : GNUNET_YES); + send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); } @@ -1623,9 +1530,10 @@ handle_matching_ack (struct CadetChannel *ch, * @param ack details about what was received */ void -GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, - const struct GNUNET_CADET_ChannelDataAckMessage *ack) +GCCH_handle_channel_plaintext_data_ack ( + struct CadetChannel *ch, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, + const struct GNUNET_CADET_ChannelDataAckMessage *ack) { struct CadetReliableMessage *crm; struct CadetReliableMessage *crmn; @@ -1647,9 +1555,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, mid_base = ntohl (ack->mid.mid); mid_mask = GNUNET_htonll (ack->futures); found = GNUNET_NO; - for (crm = ch->head_sent; - NULL != crm; - crm = crmn) + for (crm = ch->head_sent; NULL != crm; crm = crmn) { crmn = crm->next; delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); @@ -1661,9 +1567,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, (unsigned int) mid_base, ntohl (crm->data_message->mid.mid), GCCH_2s (ch)); - handle_matching_ack (ch, - cti, - crm); + handle_matching_ack (ch, cti, crm); found = GNUNET_YES; continue; } @@ -1681,9 +1585,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, "Got DATA_ACK with mask for %u on %s\n", ntohl (crm->data_message->mid.mid), GCCH_2s (ch)); - handle_matching_ack (ch, - cti, - crm); + handle_matching_ack (ch, cti, crm); found = GNUNET_YES; } } @@ -1694,10 +1596,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, LOG (GNUNET_ERROR_TYPE_DEBUG, "Duplicate DATA_ACK on %s, ignoring\n", GCCH_2s (ch)); - GNUNET_STATISTICS_update (stats, - "# duplicate DATA_ACKs", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); return; } if (NULL != ch->retry_data_task) @@ -1705,12 +1604,10 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, GNUNET_SCHEDULER_cancel (ch->retry_data_task); ch->retry_data_task = NULL; } - if ( (NULL != ch->head_sent) && - (NULL == ch->head_sent->qe) ) - ch->retry_data_task - = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, - &retry_transmission, - ch); + if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) + ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, + &retry_transmission, + ch); } @@ -1724,8 +1621,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, * NULL if we are simulating receiving a destroy due to shutdown */ void -GCCH_handle_remote_destroy (struct CadetChannel *ch, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) +GCCH_handle_remote_destroy ( + struct CadetChannel *ch, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) { struct CadetChannelClient *ccc; @@ -1740,8 +1638,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, return; } ccc = (NULL != ch->owner) ? ch->owner : ch->dest; - if ( (NULL != ccc) && - (NULL != ccc->head_recv) ) + if ((NULL != ccc) && (NULL != ccc->head_recv)) { LOG (GNUNET_ERROR_TYPE_WARNING, "Lost end of transmission due to remote shutdown on %s\n", @@ -1750,9 +1647,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, } ch->destroy = GNUNET_YES; if (NULL != ccc) - GSC_handle_remote_channel_destroy (ccc->c, - ccc->ccn, - ch); + GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); channel_destroy (ch); } @@ -1770,8 +1665,7 @@ cmp_crm_by_next_retry (void *cls, struct CadetReliableMessage *crm1, struct CadetReliableMessage *crm2) { - if (crm1->next_retry.abs_value_us < - crm2->next_retry.abs_value_us) + if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) return GNUNET_YES; return GNUNET_NO; } @@ -1797,18 +1691,13 @@ data_sent_cb (void *cls, GNUNET_assert (GNUNET_NO == ch->is_loopback); GNUNET_assert (NULL != crm->qe); crm->qe = NULL; - GNUNET_CONTAINER_DLL_remove (ch->head_sent, - ch->tail_sent, - crm); + GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); if (GNUNET_NO == ch->reliable) { GNUNET_free (crm->data_message); GNUNET_free (crm); ch->pending_messages--; - send_ack_to_client (ch, - (NULL == ch->owner) - ? GNUNET_NO - : GNUNET_YES); + send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); return; } if (NULL == cid) @@ -1828,8 +1717,7 @@ data_sent_cb (void *cls, GCC_ack_expected (cid); } } - if ( (0 == crm->retry_delay.rel_value_us) && - (NULL != cid) ) + if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) { struct CadetConnection *cc = GCC_lookup (cid); @@ -1839,8 +1727,7 @@ data_sent_cb (void *cls, crm->retry_delay = ch->retry_time; } crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); - crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, - MIN_RTT_DELAY); + crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY); crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, @@ -1853,16 +1740,16 @@ data_sent_cb (void *cls, "Message %u sent, next transmission on %s in %s\n", (unsigned int) ntohl (crm->data_message->mid.mid), GCCH_2s (ch), - GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (ch->head_sent->next_retry), + GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( + ch->head_sent->next_retry), GNUNET_YES)); if (NULL == ch->head_sent->qe) { if (NULL != ch->retry_data_task) GNUNET_SCHEDULER_cancel (ch->retry_data_task); - ch->retry_data_task - = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, - &retry_transmission, - ch); + ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, + &retry_transmission, + ch); } } @@ -1908,19 +1795,16 @@ GCCH_handle_local_data (struct CadetChannel *ch, struct GNUNET_CADET_LocalData *ld; int ack_to_owner; - env = GNUNET_MQ_msg_extra (ld, - buf_len, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); - if ( (NULL != ch->owner) && - (sender_ccn.channel_of_client == - ch->owner->ccn.channel_of_client) ) + env = + GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); + if ((NULL != ch->owner) && + (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) { receiver = ch->dest; ack_to_owner = GNUNET_YES; } - else if ( (NULL != ch->dest) && - (sender_ccn.channel_of_client == - ch->dest->ccn.channel_of_client) ) + else if ((NULL != ch->dest) && + (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) { receiver = ch->owner; ack_to_owner = GNUNET_NO; @@ -1932,16 +1816,12 @@ GCCH_handle_local_data (struct CadetChannel *ch, } GNUNET_assert (NULL != receiver); ld->ccn = receiver->ccn; - GNUNET_memcpy (&ld[1], - buf, - buf_len); + GNUNET_memcpy (&ld[1], buf, buf_len); if (GNUNET_YES == receiver->client_ready) { ch->pending_messages--; - GSC_send_to_client (receiver->c, - env); - send_ack_to_client (ch, - ack_to_owner); + GSC_send_to_client (receiver->c, env); + send_ack_to_client (ch, ack_to_owner); } else { @@ -1960,19 +1840,17 @@ GCCH_handle_local_data (struct CadetChannel *ch, /* Everything is correct, send the message. */ crm = GNUNET_malloc (sizeof (*crm)); crm->ch = ch; - crm->data_message = GNUNET_malloc (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) - + buf_len); - crm->data_message->header.size = htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); - crm->data_message->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); + crm->data_message = GNUNET_malloc ( + sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); + crm->data_message->header.size = + htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); + crm->data_message->header.type = + htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); crm->data_message->mid = ch->mid_send; crm->data_message->ctn = ch->ctn; - GNUNET_memcpy (&crm->data_message[1], - buf, - buf_len); - GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, - ch->tail_sent, - crm); + GNUNET_memcpy (&crm->data_message[1], buf, buf_len); + GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u from local client to %s with %u bytes\n", ntohl (crm->data_message->mid.mid), @@ -1983,10 +1861,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, GNUNET_SCHEDULER_cancel (ch->retry_data_task); ch->retry_data_task = NULL; } - crm->qe = GCT_send (ch->t, - &crm->data_message->header, - &data_sent_cb, - crm); + crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); GNUNET_assert (NULL == ch->retry_data_task); return GNUNET_OK; } @@ -2006,11 +1881,11 @@ GCCH_handle_local_ack (struct CadetChannel *ch, struct CadetChannelClient *ccc; struct CadetOutOfOrderMessage *com; - if ( (NULL != ch->owner) && - (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client) ) + if ((NULL != ch->owner) && + (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client)) ccc = ch->owner; - else if ( (NULL != ch->dest) && - (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client) ) + else if ((NULL != ch->dest) && + (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) ccc = ch->dest; else GNUNET_assert (0); @@ -2032,35 +1907,28 @@ GCCH_handle_local_ack (struct CadetChannel *ch, int to_owner; /* Messages are always in-order, just send */ - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - com); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); ccc->num_recv--; - GSC_send_to_client (ccc->c, - com->env); + GSC_send_to_client (ccc->c, com->env); /* Notify sender that we can receive more */ - if ( (NULL != ch->owner) && - (ccc->ccn.channel_of_client == - ch->owner->ccn.channel_of_client) ) + if ((NULL != ch->owner) && + (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) { to_owner = GNUNET_NO; } else { - GNUNET_assert ( (NULL != ch->dest) && - (ccc->ccn.channel_of_client == - ch->dest->ccn.channel_of_client) ); + GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client == + ch->dest->ccn.channel_of_client)); to_owner = GNUNET_YES; } - send_ack_to_client (ch, - to_owner); + send_ack_to_client (ch, to_owner); GNUNET_free (com); return; } - if ( (com->mid.mid != ch->mid_recv.mid) && - (GNUNET_NO == ch->out_of_order) && - (GNUNET_YES == ch->reliable) ) + if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && + (GNUNET_YES == ch->reliable)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", @@ -2079,9 +1947,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch, GCCH_2s (ch)); /* all good, pass next message to client */ - GNUNET_CONTAINER_DLL_remove (ccc->head_recv, - ccc->tail_recv, - com); + GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); ccc->num_recv--; /* FIXME: if unreliable, this is not aggressive enough, as it would be OK to have lost some! */ @@ -2089,21 +1955,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch, ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); ch->mid_futures >>= 1; /* equivalent to division by 2 */ ccc->client_ready = GNUNET_NO; - GSC_send_to_client (ccc->c, - com->env); + GSC_send_to_client (ccc->c, com->env); GNUNET_free (com); send_channel_data_ack (ch); if (NULL != ccc->head_recv) return; if (GNUNET_NO == ch->destroy) return; - GCT_send_channel_destroy (ch->t, - ch->ctn); + GCT_send_channel_destroy (ch->t, ch->ctn); channel_destroy (ch); } -#define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-chn",__VA_ARGS__) +#define LOG2(level, ...) \ + GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__) /** @@ -2113,15 +1978,16 @@ GCCH_handle_local_ack (struct CadetChannel *ch, * @param level Debug level to use. */ void -GCCH_debug (struct CadetChannel *ch, - enum GNUNET_ErrorType level) +GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) { -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) int do_log; do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), "cadet-chn", - __FILE__, __FUNCTION__, __LINE__); + __FILE__, + __FUNCTION__, + __LINE__); if (0 == do_log) return; @@ -2130,11 +1996,7 @@ GCCH_debug (struct CadetChannel *ch, LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); return; } - LOG2 (level, - "CHN %s:%X (%p)\n", - GCT_2s (ch->t), - ch->ctn, - ch); + LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); if (NULL != ch->owner) { LOG2 (level, @@ -2160,5 +2022,4 @@ GCCH_debug (struct CadetChannel *ch, } - /* end of gnunet-service-cadet-new_channel.c */ diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 7214dad97..8849e563f 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -35,14 +35,15 @@ #include "cadet_protocol.h" -#define LOG(level, ...) GNUNET_log_from(level,"cadet-con",__VA_ARGS__) +#define LOG(level, ...) GNUNET_log_from (level, "cadet-con", __VA_ARGS__) /** * How long do we wait initially before retransmitting the KX? * TODO: replace by 2 RTT if/once we have connection-level RTT data! */ -#define INITIAL_CONNECTION_CREATE_RETRY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) +#define INITIAL_CONNECTION_CREATE_RETRY_DELAY \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) /** @@ -174,7 +175,6 @@ struct CadetConnection * Are we ready to transmit via @e mq_man right now? */ int mqm_ready; - }; @@ -208,18 +208,16 @@ update_state (struct CadetConnection *cc, int old_ready; int new_ready; - if ( (new_state == cc->state) && - (new_mqm_ready == cc->mqm_ready) ) + if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready)) return; /* no change, nothing to do */ - old_ready = ( (CADET_CONNECTION_READY == cc->state) && - (GNUNET_YES == cc->mqm_ready) ); - new_ready = ( (CADET_CONNECTION_READY == new_state) && - (GNUNET_YES == new_mqm_ready) ); + old_ready = + ((CADET_CONNECTION_READY == cc->state) && (GNUNET_YES == cc->mqm_ready)); + new_ready = + ((CADET_CONNECTION_READY == new_state) && (GNUNET_YES == new_mqm_ready)); cc->state = new_state; cc->mqm_ready = new_mqm_ready; if (old_ready != new_ready) - cc->ready_cb (cc->ready_cb_cls, - new_ready); + cc->ready_cb (cc->ready_cb_cls, new_ready); } @@ -232,13 +230,10 @@ update_state (struct CadetConnection *cc, static void GCC_destroy (struct CadetConnection *cc) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying %s\n", - GCC_2s (cc)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying %s\n", GCC_2s (cc)); if (NULL != cc->mq_man) { - GCP_request_mq_cancel (cc->mq_man, - NULL); + GCP_request_mq_cancel (cc->mq_man, NULL); cc->mq_man = NULL; } if (NULL != cc->task) @@ -251,22 +246,19 @@ GCC_destroy (struct CadetConnection *cc) GCT_send_cancel (cc->keepalive_qe); cc->keepalive_qe = NULL; } - GCPP_del_connection (cc->path, - cc->off, - cc); - for (unsigned int i=0;ioff;i++) - GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, - i), - cc); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multishortmap_remove (connections, - &GCC_get_id (cc)->connection_of_tunnel, - cc)); + GCPP_del_connection (cc->path, cc->off, cc); + for (unsigned int i = 0; i < cc->off; i++) + GCP_remove_connection (GCPP_get_peer_at_offset (cc->path, i), cc); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multishortmap_remove (connections, + &GCC_get_id (cc) + ->connection_of_tunnel, + cc)); GNUNET_free (cc); } - /** * Destroy a connection, called when the CORE layer is already done * (i.e. has received a BROKEN message), but if we still have to @@ -298,18 +290,16 @@ void GCC_destroy_without_tunnel (struct CadetConnection *cc) { cc->ct = NULL; - if ( (CADET_CONNECTION_SENDING_CREATE != cc->state) && - (NULL != cc->mq_man) ) + if ((CADET_CONNECTION_SENDING_CREATE != cc->state) && (NULL != cc->mq_man)) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_ConnectionDestroyMessage *destroy_msg; /* Need to notify next hop that we are down. */ - env = GNUNET_MQ_msg (destroy_msg, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); + env = + GNUNET_MQ_msg (destroy_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); destroy_msg->cid = cc->cid; - GCP_request_mq_cancel (cc->mq_man, - env); + GCP_request_mq_cancel (cc->mq_man, env); cc->mq_man = NULL; } GCC_destroy (cc); @@ -367,11 +357,9 @@ keepalive_done (void *cls, struct CadetConnection *cc = cls; cc->keepalive_qe = NULL; - if ( (GNUNET_YES == cc->mqm_ready) && - (NULL == cc->task) ) - cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, - &send_keepalive, - cc); + if ((GNUNET_YES == cc->mqm_ready) && (NULL == cc->task)) + cc->task = + GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); } @@ -391,9 +379,8 @@ send_keepalive (void *cls) if (CADET_TUNNEL_KEY_OK != GCT_get_estate (cc->ct->t)) { /* Tunnel not yet ready, wait with keepalives... */ - cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, - &send_keepalive, - cc); + cc->task = + GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); return; } GNUNET_assert (NULL != cc->ct); @@ -403,18 +390,11 @@ send_keepalive (void *cls) "Sending KEEPALIVE on behalf of %s via %s\n", GCC_2s (cc), GCT_2s (cc->ct->t)); - GNUNET_STATISTICS_update (stats, - "# keepalives sent", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO); msg.size = htons (sizeof (msg)); msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); - cc->keepalive_qe - = GCT_send (cc->ct->t, - &msg, - &keepalive_done, - cc); + cc->keepalive_qe = GCT_send (cc->ct->t, &msg, &keepalive_done, cc); } @@ -475,10 +455,7 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, cc = GCC_lookup (cid); if (NULL == cc) return; /* whopise, connection alredy down? */ - GNUNET_STATISTICS_update (stats, - "# latencies observed", - 1, - GNUNET_NO); + GNUNET_STATISTICS_update (stats, "# latencies observed", 1, GNUNET_NO); cc->latency_datapoints++; if (cc->latency_datapoints >= 7) weight = 7.0; @@ -487,7 +464,8 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, /* Compute weighted average, giving at MOST weight 7 to the existing values, or less if that value is based on fewer than 7 measurements. */ - result = (weight * cc->metrics.aged_latency.rel_value_us) + 1.0 * latency.rel_value_us; + result = (weight * cc->metrics.aged_latency.rel_value_us) + + 1.0 * latency.rel_value_us; result /= (weight + 1.0); cc->metrics.aged_latency.rel_value_us = (uint64_t) result; } @@ -516,15 +494,11 @@ GCC_handle_connection_create_ack (struct CadetConnection *cc) cc->task = NULL; } cc->metrics.age = GNUNET_TIME_absolute_get (); - update_state (cc, - CADET_CONNECTION_READY, - cc->mqm_ready); - if ( (NULL == cc->keepalive_qe) && - (GNUNET_YES == cc->mqm_ready) && - (NULL == cc->task) ) - cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, - &send_keepalive, - cc); + update_state (cc, CADET_CONNECTION_READY, cc->mqm_ready); + if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && + (NULL == cc->task)) + cc->task = + GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); } @@ -552,8 +526,7 @@ GCC_handle_kx (struct CadetConnection *cc, GCC_2s (cc)); GCC_handle_connection_create_ack (cc); } - GCT_handle_kx (cc->ct, - msg); + GCT_handle_kx (cc->ct, msg); } @@ -581,8 +554,7 @@ GCC_handle_kx_auth (struct CadetConnection *cc, GCC_2s (cc)); GCC_handle_connection_create_ack (cc); } - GCT_handle_kx_auth (cc->ct, - msg); + GCT_handle_kx_auth (cc->ct, msg); } @@ -606,8 +578,7 @@ GCC_handle_encrypted (struct CadetConnection *cc, GCC_handle_connection_create_ack (cc); } cc->metrics.last_use = GNUNET_TIME_absolute_get (); - GCT_handle_encrypted (cc->ct, - msg); + GCT_handle_encrypted (cc->ct, msg); } @@ -627,17 +598,17 @@ send_create (void *cls) cc->task = NULL; GNUNET_assert (GNUNET_YES == cc->mqm_ready); - env = GNUNET_MQ_msg_extra (create_msg, - (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); - //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced options. - create_msg->options = GNUNET_MQ_PREF_RELIABLE >> 10; + env = + GNUNET_MQ_msg_extra (create_msg, + (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); + //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated 'reliable' bit here that was removed. + create_msg->options = 2; create_msg->cid = cc->cid; pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; pids[0] = my_full_id; - for (unsigned int i=0;i<=cc->off;i++) - pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, - i)); + for (unsigned int i = 0; i <= cc->off; i++) + pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, i)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", GCC_2s (cc), @@ -645,11 +616,8 @@ send_create (void *cls) cc->env = env; cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); - update_state (cc, - CADET_CONNECTION_SENT, - GNUNET_NO); - GCP_send (cc->mq_man, - env); + update_state (cc, CADET_CONNECTION_SENT, GNUNET_NO); + GCP_send (cc->mq_man, env); } @@ -670,22 +638,18 @@ send_create_ack (void *cls) "Sending CONNECTION_CREATE_ACK message for %s\n", GCC_2s (cc)); GNUNET_assert (GNUNET_YES == cc->mqm_ready); - env = GNUNET_MQ_msg (ack_msg, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); + env = + GNUNET_MQ_msg (ack_msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); ack_msg->cid = cc->cid; cc->env = env; cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) - update_state (cc, - CADET_CONNECTION_READY, - GNUNET_NO); + update_state (cc, CADET_CONNECTION_READY, GNUNET_NO); if (CADET_CONNECTION_READY == cc->state) - cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, - &send_keepalive, - cc); - GCP_send (cc->mq_man, - env); + cc->task = + GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); + GCP_send (cc->mq_man, env); } @@ -707,14 +671,11 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy"); /* Revert back to the state of having only received the 'CREATE', and immediately proceed to send the CREATE_ACK. */ - update_state (cc, - CADET_CONNECTION_CREATE_RECEIVED, - cc->mqm_ready); + update_state (cc, CADET_CONNECTION_CREATE_RECEIVED, cc->mqm_ready); if (NULL != cc->task) GNUNET_SCHEDULER_cancel (cc->task); - cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, - &send_create_ack, - cc); + cc->task = + GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); } else { @@ -739,20 +700,15 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) * and the last envelope was discarded */ static void -manage_first_hop_mq (void *cls, - int available) +manage_first_hop_mq (void *cls, int available) { struct CadetConnection *cc = cls; if (GNUNET_YES != available) { /* Connection is down, for now... */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Core MQ for %s went down\n", - GCC_2s (cc)); - update_state (cc, - CADET_CONNECTION_NEW, - GNUNET_NO); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s went down\n", GCC_2s (cc)); + update_state (cc, CADET_CONNECTION_NEW, GNUNET_NO); cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; if (NULL != cc->task) { @@ -762,9 +718,7 @@ manage_first_hop_mq (void *cls, return; } - update_state (cc, - cc->state, - GNUNET_YES); + update_state (cc, cc->state, GNUNET_YES); LOG (GNUNET_ERROR_TYPE_DEBUG, "Core MQ for %s became available in state %d\n", GCC_2s (cc), @@ -773,9 +727,7 @@ manage_first_hop_mq (void *cls, { case CADET_CONNECTION_NEW: /* Transmit immediately */ - cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, - &send_create, - cc); + cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); break; case CADET_CONNECTION_SENDING_CREATE: /* Should not be possible to be called in this state. */ @@ -783,30 +735,25 @@ manage_first_hop_mq (void *cls, break; case CADET_CONNECTION_SENT: /* Retry a bit later... */ - cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, - &send_create, - cc); + cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, &send_create, cc); break; case CADET_CONNECTION_CREATE_RECEIVED: /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ cc->metrics.age = GNUNET_TIME_absolute_get (); - cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, - &send_create_ack, - cc); + cc->task = + GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc); break; case CADET_CONNECTION_READY: - if ( (NULL == cc->keepalive_qe) && - (GNUNET_YES == cc->mqm_ready) && - (NULL == cc->task) ) + if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) && + (NULL == cc->task)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling keepalive for %s in %s\n", GCC_2s (cc), GNUNET_STRINGS_relative_time_to_string (keepalive_period, GNUNET_YES)); - cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, - &send_keepalive, - cc); + cc->task = + GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc); } break; } @@ -844,13 +791,14 @@ connection_create (struct CadetPeer *destination, cc->state = init_state; cc->ct = ct; cc->cid = *cid; - cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, - off); + cc->retry_delay = + GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, off); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multishortmap_put (connections, - &GCC_get_id (cc)->connection_of_tunnel, - cc, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multishortmap_put ( + connections, + &GCC_get_id (cc)->connection_of_tunnel, + cc, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); cc->ready_cb = ready_cb; cc->ready_cb_cls = ready_cb_cls; cc->path = path; @@ -860,18 +808,11 @@ connection_create (struct CadetPeer *destination, GCC_2s (cc), GCPP_2s (path), off); - GCPP_add_connection (path, - off, - cc); - for (unsigned int i=0;imq_man = GCP_request_mq (first_hop, - &manage_first_hop_mq, - cc); + GCPP_add_connection (path, off, cc); + for (unsigned int i = 0; i < off; i++) + GCP_add_connection (GCPP_get_peer_at_offset (path, i), cc); + first_hop = GCPP_get_peer_at_offset (path, 0); + cc->mq_man = GCP_request_mq (first_hop, &manage_first_hop_mq, cc); return cc; } @@ -900,18 +841,14 @@ GCC_create_inbound (struct CadetPeer *destination, struct CadetConnection *cc; unsigned int off; - off = GCPP_find_peer (path, - destination); + off = GCPP_find_peer (path, destination); GNUNET_assert (UINT_MAX != off); - cc = GCPP_get_connection (path, - destination, - off); + cc = GCPP_get_connection (path, destination, off); if (NULL != cc) { int cmp; - cmp = GNUNET_memcmp (cid, - &cc->cid); + cmp = GNUNET_memcmp (cid, &cc->cid); if (0 == cmp) { /* Two peers picked the SAME random connection identifier at the @@ -977,9 +914,7 @@ GCC_create (struct CadetPeer *destination, { struct GNUNET_CADET_ConnectionTunnelIdentifier cid; - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &cid, - sizeof (cid)); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof (cid)); return connection_create (destination, path, off, @@ -1002,8 +937,7 @@ GCC_create (struct CadetPeer *destination, * yet have a #GNUNET_MQ_notify_sent() callback attached to it */ void -GCC_transmit (struct CadetConnection *cc, - struct GNUNET_MQ_Envelope *env) +GCC_transmit (struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling message for transmission on %s\n", @@ -1017,8 +951,7 @@ GCC_transmit (struct CadetConnection *cc, GNUNET_SCHEDULER_cancel (cc->task); cc->task = NULL; } - GCP_send (cc->mq_man, - env); + GCP_send (cc->mq_man, env); } @@ -1030,8 +963,7 @@ GCC_transmit (struct CadetConnection *cc, * @return path to @a cc */ struct CadetPeerPath * -GCC_get_path (struct CadetConnection *cc, - unsigned int *off) +GCC_get_path (struct CadetConnection *cc, unsigned int *off) { *off = cc->off; return cc->path; @@ -1081,7 +1013,8 @@ GCC_2s (const struct CadetConnection *cc) } -#define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-con",__VA_ARGS__) +#define LOG2(level, ...) \ + GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__) /** @@ -1091,21 +1024,21 @@ GCC_2s (const struct CadetConnection *cc) * @param level Debug level to use. */ void -GCC_debug (struct CadetConnection *cc, - enum GNUNET_ErrorType level) +GCC_debug (struct CadetConnection *cc, enum GNUNET_ErrorType level) { -#if !defined(GNUNET_CULL_LOGGING) +#if ! defined(GNUNET_CULL_LOGGING) int do_log; do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), "cadet-con", - __FILE__, __FUNCTION__, __LINE__); + __FILE__, + __FUNCTION__, + __LINE__); if (0 == do_log) return; if (NULL == cc) { - LOG2 (level, - "Connection (NULL)\n"); + LOG2 (level, "Connection (NULL)\n"); return; } LOG2 (level, diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index 220a2b3cd..ec70a968b 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -39,7 +39,7 @@ #include "gnunet_statistics_service.h" #include "cadet_protocol.h" -#define LOG(level, ...) GNUNET_log_from(level,"cadet-cor",__VA_ARGS__) +#define LOG(level, ...) GNUNET_log_from (level, "cadet-cor", __VA_ARGS__) /** * Information we keep per direction for a route. @@ -138,7 +138,6 @@ struct RouteDirection * Is @e mqm currently ready for transmission? */ int is_ready; - }; @@ -177,8 +176,6 @@ struct CadetRoute * Position of this route in the #route_heap. */ struct GNUNET_CONTAINER_HeapNode *hn; - - }; @@ -258,24 +255,17 @@ lower_rung (struct RouteDirection *dir) struct Rung *rung = dir->rung; struct Rung *prev; - GNUNET_CONTAINER_DLL_remove (rung->rd_head, - rung->rd_tail, - dir); + GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); prev = rung->prev; GNUNET_assert (NULL != prev); if (prev->rung_off != rung->rung_off - 1) { prev = GNUNET_new (struct Rung); prev->rung_off = rung->rung_off - 1; - GNUNET_CONTAINER_DLL_insert_after (rung_head, - rung_tail, - rung->prev, - prev); + GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung->prev, prev); } GNUNET_assert (NULL != prev); - GNUNET_CONTAINER_DLL_insert (prev->rd_head, - prev->rd_tail, - dir); + GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir); dir->rung = prev; } @@ -288,19 +278,13 @@ lower_rung (struct RouteDirection *dir) * @param env envelope to discard */ static void -discard_buffer (struct RouteDirection *dir, - struct GNUNET_MQ_Envelope *env) +discard_buffer (struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env) { - GNUNET_MQ_dll_remove (&dir->env_head, - &dir->env_tail, - env); + GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); cur_buffers--; GNUNET_MQ_discard (env); lower_rung (dir); - GNUNET_STATISTICS_set (stats, - "# buffer use", - cur_buffers, - GNUNET_NO); + GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); } @@ -322,12 +306,9 @@ discard_all_from_rung_tail () "# messages dropped due to full buffer", 1, GNUNET_NO); - discard_buffer (dir, - dir->env_head); + discard_buffer (dir, dir->env_head); } - GNUNET_CONTAINER_DLL_remove (rung_head, - rung_tail, - tail); + GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail); GNUNET_free (tail); } @@ -345,7 +326,7 @@ static void route_message (struct CadetPeer *prev, const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, const struct GNUNET_MessageHeader *msg, - const enum GNUNET_MQ_PriorityPreferences priority) + const enum GNUNET_MQ_PriorityPreferences priority) { struct CadetRoute *route; struct RouteDirection *dir; @@ -371,17 +352,14 @@ route_message (struct CadetPeer *prev, /* No need to respond to these! */ return; } - env = GNUNET_MQ_msg (bm, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); + env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); bm->cid = *cid; bm->peer1 = my_full_id; - GCP_send_ooo (prev, - env); + GCP_send_ooo (prev, env); return; } route->last_use = GNUNET_TIME_absolute_get (); - GNUNET_CONTAINER_heap_update_cost (route->hn, - route->last_use.abs_value_us); + GNUNET_CONTAINER_heap_update_cost (route->hn, route->last_use.abs_value_us); dir = (prev == route->prev.hop) ? &route->next : &route->prev; if (GNUNET_YES == dir->is_ready) { @@ -392,27 +370,24 @@ route_message (struct CadetPeer *prev, GNUNET_i2s (GCP_get_id (dir->hop)), GNUNET_sh2s (&cid->connection_of_tunnel)); dir->is_ready = GNUNET_NO; - GCP_send (dir->mqm, - GNUNET_MQ_msg_copy (msg)); + GCP_send (dir->mqm, GNUNET_MQ_msg_copy (msg)); return; } - /* Check if buffering is disallowed, and if so, make sure we only queue - one message per direction. */ - if ( (0 != (priority & GNUNET_MQ_PREF_NO_BUFFER)) && - (NULL != dir->env_head) ) - discard_buffer (dir, - dir->env_head); + /* Check if low latency is required and if the previous message was + unreliable; if so, make sure we only queue one message per + direction (no buffering). */ + if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && + (NULL != dir->env_head) && + (0 == + (GNUNET_MQ_env_get_options (dir->env_head) & GNUNET_MQ_PREF_UNRELIABLE))) + discard_buffer (dir, dir->env_head); /* Check for duplicates */ - for (const struct GNUNET_MQ_Envelope *env = dir->env_head; - NULL != env; + for (const struct GNUNET_MQ_Envelope *env = dir->env_head; NULL != env; env = GNUNET_MQ_env_next (env)) { const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); - if ( (hdr->size == msg->size) && - (0 == memcmp (hdr, - msg, - ntohs (msg->size))) ) + if ((hdr->size == msg->size) && (0 == memcmp (hdr, msg, ntohs (msg->size)))) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Received duplicate of message already in buffer, dropping\n"); @@ -443,31 +418,22 @@ route_message (struct CadetPeer *prev, "# messages dropped due to full buffer", 1, GNUNET_NO); - discard_buffer (dir, - dir->env_head); + discard_buffer (dir, dir->env_head); rung = dir->rung; } } /* remove 'dir' from current rung */ - GNUNET_CONTAINER_DLL_remove (rung->rd_head, - rung->rd_tail, - dir); + GNUNET_CONTAINER_DLL_remove (rung->rd_head, rung->rd_tail, dir); /* make 'nxt' point to the next higher rung, create if necessary */ nxt = rung->next; - if ( (NULL == nxt) || - (rung->rung_off + 1 != nxt->rung_off) ) + if ((NULL == nxt) || (rung->rung_off + 1 != nxt->rung_off)) { nxt = GNUNET_new (struct Rung); nxt->rung_off = rung->rung_off + 1; - GNUNET_CONTAINER_DLL_insert_after (rung_head, - rung_tail, - rung, - nxt); + GNUNET_CONTAINER_DLL_insert_after (rung_head, rung_tail, rung, nxt); } /* insert 'dir' into next higher rung */ - GNUNET_CONTAINER_DLL_insert (nxt->rd_head, - nxt->rd_tail, - dir); + GNUNET_CONTAINER_DLL_insert (nxt->rd_head, nxt->rd_tail, dir); dir->rung = nxt; /* add message into 'dir' buffer */ @@ -478,21 +444,21 @@ route_message (struct CadetPeer *prev, GNUNET_i2s (GCP_get_id (dir->hop)), GNUNET_sh2s (&cid->connection_of_tunnel)); env = GNUNET_MQ_msg_copy (msg); - GNUNET_MQ_dll_insert_tail (&dir->env_head, - &dir->env_tail, - env); + GNUNET_MQ_env_set_options (env, priority); + if ((0 != (priority & GNUNET_MQ_PREF_LOW_LATENCY)) && + (0 != (priority & GNUNET_MQ_PREF_OUT_OF_ORDER)) && + (NULL != dir->env_head) && + (0 == (GNUNET_MQ_env_get_options (dir->env_head) & + GNUNET_MQ_PREF_LOW_LATENCY))) + GNUNET_MQ_dll_insert_head (&dir->env_head, &dir->env_tail, env); + else + GNUNET_MQ_dll_insert_tail (&dir->env_head, &dir->env_tail, env); cur_buffers++; - GNUNET_STATISTICS_set (stats, - "# buffer use", - cur_buffers, - GNUNET_NO); + GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); /* Clean up 'rung' if now empty (and not head) */ - if ( (NULL == rung->rd_head) && - (rung != rung_head) ) + if ((NULL == rung->rd_head) && (rung != rung_head)) { - GNUNET_CONTAINER_DLL_remove (rung_head, - rung_tail, - rung); + GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung); GNUNET_free (rung); } } @@ -537,18 +503,14 @@ destroy_direction (struct RouteDirection *dir) "# messages dropped due to route destruction", 1, GNUNET_NO); - discard_buffer (dir, - env); + discard_buffer (dir, env); } if (NULL != dir->mqm) { - GCP_request_mq_cancel (dir->mqm, - NULL); + GCP_request_mq_cancel (dir->mqm, NULL); dir->mqm = NULL; } - GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, - rung_head->rd_tail, - dir); + GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir); } @@ -562,15 +524,15 @@ destroy_route (struct CadetRoute *route) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying route from %s to %s of connection %s\n", - GNUNET_i2s (GCP_get_id (route->prev.hop)), + GNUNET_i2s (GCP_get_id (route->prev.hop)), GNUNET_i2s2 (GCP_get_id (route->next.hop)), GNUNET_sh2s (&route->cid.connection_of_tunnel)); - GNUNET_assert (route == - GNUNET_CONTAINER_heap_remove_node (route->hn)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multishortmap_remove (routes, - &route->cid.connection_of_tunnel, - route)); + GNUNET_assert (route == GNUNET_CONTAINER_heap_remove_node (route->hn)); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multishortmap_remove (routes, + &route->cid.connection_of_tunnel, + route)); GNUNET_STATISTICS_set (stats, "# routes", GNUNET_CONTAINER_multishortmap_size (routes), @@ -607,15 +569,13 @@ send_broken (struct RouteDirection *target, GNUNET_i2s2 (peer2), GNUNET_sh2s (&cid->connection_of_tunnel)); - env = GNUNET_MQ_msg (bm, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); + env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); bm->cid = *cid; if (NULL != peer1) bm->peer1 = *peer1; if (NULL != peer2) bm->peer2 = *peer2; - GCP_request_mq_cancel (target->mqm, - env); + GCP_request_mq_cancel (target->mqm, env); target->mqm = NULL; } @@ -635,33 +595,22 @@ timeout_cb (void *cls) struct GNUNET_TIME_Absolute exp; timeout_task = NULL; - linger = GNUNET_TIME_relative_multiply (keepalive_period, - 3); + linger = GNUNET_TIME_relative_multiply (keepalive_period, 3); while (NULL != (r = GNUNET_CONTAINER_heap_peek (route_heap))) { - exp = GNUNET_TIME_absolute_add (r->last_use, - linger); + exp = GNUNET_TIME_absolute_add (r->last_use, linger); if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us) { /* Route not yet timed out, wait until it does. */ - timeout_task = GNUNET_SCHEDULER_add_at (exp, - &timeout_cb, - NULL); + timeout_task = GNUNET_SCHEDULER_add_at (exp, &timeout_cb, NULL); return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Sending BROKEN due to timeout (%s was last use, %s linger)\n", - GNUNET_STRINGS_absolute_time_to_string (r->last_use), - GNUNET_STRINGS_relative_time_to_string (linger, - GNUNET_YES)); - send_broken (&r->prev, - &r->cid, - NULL, - NULL); - send_broken (&r->next, - &r->cid, - NULL, - NULL); + "Sending BROKEN due to timeout (%s was last use, %s linger)\n", + GNUNET_STRINGS_absolute_time_to_string (r->last_use), + GNUNET_STRINGS_relative_time_to_string (linger, GNUNET_YES)); + send_broken (&r->prev, &r->cid, NULL, NULL); + send_broken (&r->next, &r->cid, NULL, NULL); destroy_route (r); } /* No more routes left, so no need for a #timeout_task */ @@ -681,8 +630,7 @@ timeout_cb (void *cls) * and the last envelope was discarded */ static void -dir_ready_cb (void *cls, - int ready) +dir_ready_cb (void *cls, int ready) { struct RouteDirection *dir = cls; struct CadetRoute *route = dir->my_route; @@ -695,28 +643,18 @@ dir_ready_cb (void *cls, dir->is_ready = GNUNET_YES; if (NULL != (env = dir->env_head)) { - GNUNET_MQ_dll_remove (&dir->env_head, - &dir->env_tail, - env); + GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env); cur_buffers--; - GNUNET_STATISTICS_set (stats, - "# buffer use", - cur_buffers, - GNUNET_NO); + GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO); lower_rung (dir); dir->is_ready = GNUNET_NO; - GCP_send (dir->mqm, - env); + GCP_send (dir->mqm, env); } return; } odir = (dir == &route->next) ? &route->prev : &route->next; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending BROKEN due to MQ going down\n"); - send_broken (&route->next, - &route->cid, - GCP_get_id (odir->hop), - &my_full_id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending BROKEN due to MQ going down\n"); + send_broken (&route->next, &route->cid, GCP_get_id (odir->hop), &my_full_id); destroy_route (route); } @@ -735,12 +673,8 @@ dir_init (struct RouteDirection *dir, { dir->hop = hop; dir->my_route = route; - dir->mqm = GCP_request_mq (hop, - &dir_ready_cb, - dir); - GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, - rung_head->rd_tail, - dir); + dir->mqm = GCP_request_mq (hop, &dir_ready_cb, dir); + GNUNET_CONTAINER_DLL_insert (rung_head->rd_head, rung_head->rd_tail, dir); dir->rung = rung_head; GNUNET_assert (GNUNET_YES == dir->is_ready); } @@ -757,21 +691,20 @@ dir_init (struct RouteDirection *dir, * or NULL. */ static void -send_broken_without_mqm (struct CadetPeer *target, - const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, - const struct GNUNET_PeerIdentity *failure_at) +send_broken_without_mqm ( + struct CadetPeer *target, + const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, + const struct GNUNET_PeerIdentity *failure_at) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_ConnectionBrokenMessage *bm; - env = GNUNET_MQ_msg (bm, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); + env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); bm->cid = *cid; bm->peer1 = my_full_id; if (NULL != failure_at) bm->peer2 = *failure_at; - GCP_send_ooo (target, - env); + GCP_send_ooo (target, env); } @@ -782,12 +715,14 @@ send_broken_without_mqm (struct CadetPeer *target, * @param msg Message itself. */ static void -handle_connection_create (void *cls, - const struct GNUNET_CADET_ConnectionCreateMessage *msg) +handle_connection_create ( + void *cls, + const struct GNUNET_CADET_ConnectionCreateMessage *msg) { struct CadetPeer *sender = cls; struct CadetPeer *next; - const struct GNUNET_PeerIdentity *pids = (const struct GNUNET_PeerIdentity *) &msg[1]; + const struct GNUNET_PeerIdentity *pids = + (const struct GNUNET_PeerIdentity *) &msg[1]; struct CadetRoute *route; uint16_t size = ntohs (msg->header.size) - sizeof (*msg); unsigned int path_length; @@ -810,20 +745,19 @@ handle_connection_create (void *cls, { struct GNUNET_CONTAINER_MultiPeerMap *map; - map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, - GNUNET_YES); + map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES); GNUNET_assert (NULL != map); - for (unsigned int i=0;icid))) + if (NULL != (route = get_route (&msg->cid))) { /* Duplicate CREATE, pass it on, previous one might have been lost! */ @@ -867,7 +798,8 @@ handle_connection_create (void *cls, route_message (sender, &msg->cid, &msg->header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + GNUNET_MQ_PRIO_CRITICAL_CONTROL | + GNUNET_MQ_PREF_LOW_LATENCY); return; } if (off == path_length - 1) @@ -887,17 +819,14 @@ handle_connection_create (void *cls, return; } - origin = GCP_get (&pids[0], - GNUNET_YES); + origin = GCP_get (&pids[0], GNUNET_YES); LOG (GNUNET_ERROR_TYPE_DEBUG, "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", GCP_2s (origin), GNUNET_sh2s (&msg->cid.connection_of_tunnel)); - path = GCPP_get_path_from_route (path_length - 1, - pids); + path = GCPP_get_path_from_route (path_length - 1, pids); if (GNUNET_OK != - GCT_add_inbound_connection (GCP_get_tunnel (origin, - GNUNET_YES), + GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES), &msg->cid, path)) { @@ -908,18 +837,14 @@ handle_connection_create (void *cls, GCP_2s (sender), GNUNET_sh2s (&msg->cid.connection_of_tunnel), GCPP_2s (path)); - send_broken_without_mqm (sender, - &msg->cid, - NULL); + send_broken_without_mqm (sender, &msg->cid, NULL); return; } return; } /* We are merely a hop on the way, check if we can support the route */ - next = GCP_get (&pids[off + 1], - GNUNET_NO); - if ( (NULL == next) || - (GNUNET_NO == GCP_has_core_connection (next)) ) + next = GCP_get (&pids[off + 1], GNUNET_NO); + if ((NULL == next) || (GNUNET_NO == GCP_has_core_connection (next))) { /* unworkable, send back BROKEN notification */ LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -928,9 +853,7 @@ handle_connection_create (void *cls, GNUNET_sh2s (&msg->cid.connection_of_tunnel), GNUNET_i2s (&pids[off + 1]), off + 1); - send_broken_without_mqm (sender, - &msg->cid, - &pids[off + 1]); + send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]); return; } if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes)) @@ -939,9 +862,7 @@ handle_connection_create (void *cls, "Received CADET_CONNECTION_CREATE from %s for %s. We have reached our route limit. Sending BROKEN\n", GCP_2s (sender), GNUNET_sh2s (&msg->cid.connection_of_tunnel)); - send_broken_without_mqm (sender, - &msg->cid, - &pids[off - 1]); + send_broken_without_mqm (sender, &msg->cid, &pids[off - 1]); return; } @@ -955,17 +876,14 @@ handle_connection_create (void *cls, route = GNUNET_new (struct CadetRoute); route->cid = msg->cid; route->last_use = GNUNET_TIME_absolute_get (); - dir_init (&route->prev, - route, - sender); - dir_init (&route->next, - route, - next); + dir_init (&route->prev, route, sender); + dir_init (&route->next, route, next); GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multishortmap_put (routes, - &route->cid.connection_of_tunnel, - route, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multishortmap_put ( + routes, + &route->cid.connection_of_tunnel, + route, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); GNUNET_STATISTICS_set (stats, "# routes", GNUNET_CONTAINER_multishortmap_size (routes), @@ -974,15 +892,16 @@ handle_connection_create (void *cls, route, route->last_use.abs_value_us); if (NULL == timeout_task) - timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, - 3), - &timeout_cb, - NULL); + timeout_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (keepalive_period, + 3), + &timeout_cb, + NULL); /* also pass CREATE message along to next hop */ route_message (sender, &msg->cid, &msg->header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); } @@ -993,8 +912,9 @@ handle_connection_create (void *cls, * @param msg Message itself. */ static void -handle_connection_create_ack (void *cls, - const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) +handle_connection_create_ack ( + void *cls, + const struct GNUNET_CADET_ConnectionCreateAckMessage *msg) { struct CadetPeer *peer = cls; struct CadetConnection *cc; @@ -1005,12 +925,9 @@ handle_connection_create_ack (void *cls, { /* verify ACK came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received ACK from unexpected direction, ignore! */ GNUNET_break_op (0); @@ -1027,7 +944,7 @@ handle_connection_create_ack (void *cls, route_message (peer, &msg->cid, &msg->header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); } @@ -1039,8 +956,9 @@ handle_connection_create_ack (void *cls, * @deprecated duplicate logic with #handle_destroy(); dedup! */ static void -handle_connection_broken (void *cls, - const struct GNUNET_CADET_ConnectionBrokenMessage *msg) +handle_connection_broken ( + void *cls, + const struct GNUNET_CADET_ConnectionBrokenMessage *msg) { struct CadetPeer *peer = cls; struct CadetConnection *cc; @@ -1052,12 +970,9 @@ handle_connection_broken (void *cls, { /* verify message came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received message from unexpected direction, ignore! */ GNUNET_break_op (0); @@ -1076,7 +991,7 @@ handle_connection_broken (void *cls, route_message (peer, &msg->cid, &msg->header, - GNUNET_MQ_PREF_NO_BUFFER); + GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); route = get_route (&msg->cid); if (NULL != route) destroy_route (route); @@ -1091,8 +1006,9 @@ handle_connection_broken (void *cls, * @param msg Message itself. */ static void -handle_connection_destroy (void *cls, - const struct GNUNET_CADET_ConnectionDestroyMessage *msg) +handle_connection_destroy ( + void *cls, + const struct GNUNET_CADET_ConnectionDestroyMessage *msg) { struct CadetPeer *peer = cls; struct CadetConnection *cc; @@ -1104,12 +1020,9 @@ handle_connection_destroy (void *cls, { /* verify message came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received message from unexpected direction, ignore! */ GNUNET_break_op (0); @@ -1130,7 +1043,7 @@ handle_connection_destroy (void *cls, route_message (peer, &msg->cid, &msg->header, - GNUNET_MQ_PREF_NO_BUFFER); + GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL); route = get_route (&msg->cid); if (NULL != route) destroy_route (route); @@ -1162,19 +1075,15 @@ handle_tunnel_kx (void *cls, { /* verify message came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received message from unexpected direction, ignore! */ GNUNET_break_op (0); return; } - GCC_handle_kx (cc, - msg); + GCC_handle_kx (cc, msg); return; } @@ -1182,7 +1091,7 @@ handle_tunnel_kx (void *cls, route_message (peer, &msg->cid, &msg->header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); } @@ -1193,8 +1102,9 @@ handle_tunnel_kx (void *cls, * @param msg Message itself. */ static void -handle_tunnel_kx_auth (void *cls, - const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) +handle_tunnel_kx_auth ( + void *cls, + const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) { struct CadetPeer *peer = cls; struct CadetConnection *cc; @@ -1205,19 +1115,15 @@ handle_tunnel_kx_auth (void *cls, { /* verify message came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received message from unexpected direction, ignore! */ GNUNET_break_op (0); return; } - GCC_handle_kx_auth (cc, - msg); + GCC_handle_kx_auth (cc, msg); return; } @@ -1225,7 +1131,7 @@ handle_tunnel_kx_auth (void *cls, route_message (peer, &msg->kx.cid, &msg->kx.header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY); } @@ -1264,26 +1170,19 @@ handle_tunnel_encrypted (void *cls, { /* verify message came from the right direction */ unsigned int len; - struct CadetPeerPath *path = GCC_get_path (cc, - &len); + struct CadetPeerPath *path = GCC_get_path (cc, &len); - if (peer != - GCPP_get_peer_at_offset (path, - 0)) + if (peer != GCPP_get_peer_at_offset (path, 0)) { /* received message from unexpected direction, ignore! */ GNUNET_break_op (0); return; } - GCC_handle_encrypted (cc, - msg); + GCC_handle_encrypted (cc, msg); return; } /* We're just an intermediary peer, route the message along its path */ - route_message (peer, - &msg->cid, - &msg->header, - GNUNET_MQ_PRIO_CRITICAL_CONTROL); + route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT); } @@ -1300,17 +1199,14 @@ handle_tunnel_encrypted (void *cls, * @param my_identity ID of this peer, NULL if we failed */ static void -core_init_cb (void *cls, - const struct GNUNET_PeerIdentity *my_identity) +core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) { if (NULL == my_identity) { GNUNET_break (0); return; } - GNUNET_break (0 == - GNUNET_memcmp (my_identity, - &my_full_id)); + GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id)); } @@ -1330,10 +1226,8 @@ core_connect_cb (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "CORE connection to peer %s was established.\n", GNUNET_i2s (peer)); - cp = GCP_get (peer, - GNUNET_YES); - GCP_set_mq (cp, - mq); + cp = GCP_get (peer, GNUNET_YES); + GCP_set_mq (cp, mq); return cp; } @@ -1354,8 +1248,7 @@ core_disconnect_cb (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "CORE connection to peer %s went down.\n", GNUNET_i2s (peer)); - GCP_set_mq (cp, - NULL); + GCP_set_mq (cp, NULL); } @@ -1367,52 +1260,48 @@ core_disconnect_cb (void *cls, void GCO_init (const struct GNUNET_CONFIGURATION_Handle *c) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (connection_create, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, - struct GNUNET_CADET_ConnectionCreateMessage, - NULL), - GNUNET_MQ_hd_fixed_size (connection_create_ack, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, - struct GNUNET_CADET_ConnectionCreateAckMessage, - NULL), - GNUNET_MQ_hd_fixed_size (connection_broken, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, - struct GNUNET_CADET_ConnectionBrokenMessage, - NULL), - GNUNET_MQ_hd_fixed_size (connection_destroy, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, - struct GNUNET_CADET_ConnectionDestroyMessage, - NULL), - GNUNET_MQ_hd_fixed_size (tunnel_kx, - GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, - struct GNUNET_CADET_TunnelKeyExchangeMessage, - NULL), - GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, - GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, - struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, - NULL), - GNUNET_MQ_hd_var_size (tunnel_encrypted, - GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, - struct GNUNET_CADET_TunnelEncryptedMessage, - NULL), - GNUNET_MQ_handler_end () - }; - - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (c, - "CADET", - "MAX_ROUTES", - &max_routes)) - max_routes = 5000; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (c, - "CADET", - "MAX_MSGS_QUEUE", - &max_buffers)) - max_buffers = 10000; - routes = GNUNET_CONTAINER_multishortmap_create (1024, - GNUNET_NO); + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (connection_create, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, + struct GNUNET_CADET_ConnectionCreateMessage, + NULL), + GNUNET_MQ_hd_fixed_size (connection_create_ack, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, + struct GNUNET_CADET_ConnectionCreateAckMessage, + NULL), + GNUNET_MQ_hd_fixed_size (connection_broken, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, + struct GNUNET_CADET_ConnectionBrokenMessage, + NULL), + GNUNET_MQ_hd_fixed_size (connection_destroy, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, + struct GNUNET_CADET_ConnectionDestroyMessage, + NULL), + GNUNET_MQ_hd_fixed_size (tunnel_kx, + GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, + struct GNUNET_CADET_TunnelKeyExchangeMessage, + NULL), + GNUNET_MQ_hd_fixed_size (tunnel_kx_auth, + GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH, + struct GNUNET_CADET_TunnelKeyExchangeAuthMessage, + NULL), + GNUNET_MQ_hd_var_size (tunnel_encrypted, + GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED, + struct GNUNET_CADET_TunnelEncryptedMessage, + NULL), + GNUNET_MQ_handler_end ()}; + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, + "CADET", + "MAX_ROUTES", + &max_routes)) + max_routes = 5000; + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, + "CADET", + "MAX_MSGS_QUEUE", + &max_buffers)) + max_buffers = 10000; + routes = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_NO); route_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); core = GNUNET_CORE_connect (c, NULL, diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index ad449a309..3e531e202 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -150,7 +150,6 @@ struct Channel * #GNUNET_YES if the channel was suspended by the local client. */ int8_t suspended_local; - }; @@ -194,7 +193,6 @@ struct Line * Generator for channel IDs. */ uint32_t cid_gen; - }; @@ -223,12 +221,9 @@ static struct GNUNET_PeerIdentity my_identity; * @return NULL for not found */ static struct Channel * -find_channel_by_line (struct Line *line, - uint32_t cid) +find_channel_by_line (struct Line *line, uint32_t cid) { - for (struct Channel *ch = line->channel_head; - NULL != ch; - ch = ch->next) + for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next) if (cid == ch->cid) return ch; return NULL; @@ -263,9 +258,7 @@ handle_client_pickup_message (void *cls, if (NULL == ch) { /* could have been destroyed asynchronously, ignore message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel %u not found\n", - msg->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); GNUNET_SERVICE_client_continue (line->client); return; } @@ -294,12 +287,10 @@ handle_client_pickup_message (void *cls, return; } GNUNET_break (CS_CALLEE_CONNECTED == ch->status); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending PICK_UP message to cadet\n"); - env = GNUNET_MQ_msg (mppm, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); - GNUNET_MQ_send (ch->mq, - env); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n"); + env = + GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); + GNUNET_MQ_send (ch->mq, env); GNUNET_SERVICE_client_continue (line->client); } @@ -329,18 +320,15 @@ clean_up_channel (struct Channel *ch) case CS_CALLER_CONNECTED: if (NULL != line) { - env = GNUNET_MQ_msg (hup, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); + env = + GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); hup->cid = ch->cid; - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } break; } if (NULL != line) - GNUNET_CONTAINER_DLL_remove (line->channel_head, - line->channel_tail, - ch); + GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch); GNUNET_free (ch); } @@ -353,8 +341,7 @@ clean_up_channel (struct Channel *ch) static void destroy_line_cadet_channels (struct Channel *ch) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying cadet channels\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n"); if (NULL != ch->channel) { GNUNET_CADET_channel_destroy (ch->channel); @@ -423,9 +410,7 @@ handle_client_hangup_message (void *cls, if (NULL == ch) { /* could have been destroyed asynchronously, ignore message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel %u not found\n", - msg->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); GNUNET_SERVICE_client_continue (line->client); return; } @@ -460,15 +445,11 @@ handle_client_hangup_message (void *cls, GNUNET_SERVICE_client_continue (line->client); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending HANG_UP message via cadet\n"); - e = GNUNET_MQ_msg (mhum, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); - GNUNET_MQ_notify_sent (e, - &mq_done_finish_caller_shutdown, - ch); - GNUNET_MQ_send (ch->mq, - e); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n"); + e = + GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); + GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch); + GNUNET_MQ_send (ch->mq, e); GNUNET_SERVICE_client_continue (line->client); } @@ -494,9 +475,7 @@ handle_client_suspend_message (void *cls, if (NULL == ch) { /* could have been destroyed asynchronously, ignore message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel %u not found\n", - msg->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); GNUNET_SERVICE_client_continue (line->client); return; } @@ -539,12 +518,10 @@ handle_client_suspend_message (void *cls, GNUNET_SERVICE_client_continue (line->client); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending SUSPEND message via cadet\n"); - e = GNUNET_MQ_msg (mhum, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); - GNUNET_MQ_send (ch->mq, - e); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n"); + e = + GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); + GNUNET_MQ_send (ch->mq, e); GNUNET_SERVICE_client_continue (line->client); } @@ -570,9 +547,7 @@ handle_client_resume_message (void *cls, if (NULL == ch) { /* could have been destroyed asynchronously, ignore message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel %u not found\n", - msg->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); GNUNET_SERVICE_client_continue (line->client); return; } @@ -615,12 +590,9 @@ handle_client_resume_message (void *cls, GNUNET_SERVICE_client_drop (line->client); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending RESUME message via cadet\n"); - e = GNUNET_MQ_msg (mhum, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); - GNUNET_MQ_send (ch->mq, - e); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n"); + e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME); + GNUNET_MQ_send (ch->mq, e); GNUNET_SERVICE_client_continue (line->client); } @@ -647,8 +619,7 @@ channel_audio_sent_notify (void *cls) * @return #GNUNET_OK (any data is ok) */ static int -check_client_audio_message (void *cls, - const struct ClientAudioMessage *msg) +check_client_audio_message (void *cls, const struct ClientAudioMessage *msg) { (void) cls; (void) msg; @@ -663,8 +634,7 @@ check_client_audio_message (void *cls, * @param msg the message from the client */ static void -handle_client_audio_message (void *cls, - const struct ClientAudioMessage *msg) +handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg) { struct Line *line = cls; struct CadetAudioMessage *mam; @@ -672,14 +642,11 @@ handle_client_audio_message (void *cls, size_t size; size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage); - ch = find_channel_by_line (line, - msg->cid); + ch = find_channel_by_line (line, msg->cid); if (NULL == ch) { /* could have been destroyed asynchronously, ignore message */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel %u not found\n", - msg->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid); GNUNET_SERVICE_client_continue (line->client); return; } @@ -726,15 +693,10 @@ handle_client_audio_message (void *cls, ch->env = GNUNET_MQ_msg_extra (mam, size, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); - GNUNET_memcpy (&mam[1], - &msg[1], - size); + GNUNET_memcpy (&mam[1], &msg[1], size); /* FIXME: set options for unreliable transmission */ - GNUNET_MQ_notify_sent (ch->env, - &channel_audio_sent_notify, - ch); - GNUNET_MQ_send (ch->mq, - ch->env); + GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch); + GNUNET_MQ_send (ch->mq, ch->env); GNUNET_SERVICE_client_continue (line->client); } @@ -746,8 +708,7 @@ handle_client_audio_message (void *cls, * @param msg the incoming message */ static void -handle_cadet_ring_message (void *cls, - const struct CadetPhoneRingMessage *msg) +handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) { struct Channel *ch = cls; struct Line *line = ch->line; @@ -771,7 +732,9 @@ handle_cadet_ring_message (void *cls, destroy_line_cadet_channels (ch); return; } - if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (msg->expiration_time)).rel_value_us) + if (0 == GNUNET_TIME_absolute_get_remaining ( + GNUNET_TIME_absolute_ntoh (msg->expiration_time)) + .rel_value_us) { /* ancient call, replay? */ GNUNET_break_op (0); @@ -789,15 +752,13 @@ handle_cadet_ring_message (void *cls, } GNUNET_CADET_receive_done (ch->channel); ch->status = CS_CALLEE_RINGING; - env = GNUNET_MQ_msg (cring, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); + env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING); cring->cid = ch->cid; cring->caller_id = msg->caller_id; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message to client. CID is %u\n", (unsigned int) ch->cid); - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } @@ -839,13 +800,10 @@ handle_cadet_hangup_message (void *cls, case CS_CALLER_SHUTDOWN: return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending HANG UP message to client\n"); - env = GNUNET_MQ_msg (hup, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n"); + env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); hup->cid = cid; - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } @@ -889,13 +847,11 @@ handle_cadet_pickup_message (void *cls, mq_done_finish_caller_shutdown (ch); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending PICKED UP message to client\n"); - env = GNUNET_MQ_msg (pick, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n"); + env = + GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP); pick->cid = ch->cid; - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } @@ -916,9 +872,7 @@ handle_cadet_suspend_message (void *cls, (void) message; GNUNET_CADET_receive_done (ch->channel); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Suspending channel CID: %u\n", - ch->cid); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid); switch (ch->status) { case CS_CALLEE_INIT: @@ -941,11 +895,10 @@ handle_cadet_suspend_message (void *cls, case CS_CALLER_SHUTDOWN: return; } - env = GNUNET_MQ_msg (suspend, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); + env = + GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); suspend->cid = ch->cid; - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } @@ -969,8 +922,9 @@ handle_cadet_resume_message (void *cls, GNUNET_CADET_receive_done (ch->channel); if (GNUNET_YES != ch->suspended_remote) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "RESUME message received for non-suspended channel, dropping channel.\n"); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "RESUME message received for non-suspended channel, dropping channel.\n"); destroy_line_cadet_channels (ch); return; } @@ -996,11 +950,10 @@ handle_cadet_resume_message (void *cls, case CS_CALLER_SHUTDOWN: return; } - env = GNUNET_MQ_msg (resume, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); + env = + GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); resume->cid = ch->cid; - GNUNET_MQ_send (line->mq, - env); + GNUNET_MQ_send (line->mq, env); } @@ -1012,8 +965,7 @@ handle_cadet_resume_message (void *cls, * @return #GNUNET_OK (always) */ static int -check_cadet_audio_message (void *cls, - const struct CadetAudioMessage *msg) +check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) { (void) cls; (void) msg; @@ -1028,8 +980,7 @@ check_cadet_audio_message (void *cls, * @param msg the incoming message */ static void -handle_cadet_audio_message (void *cls, - const struct CadetAudioMessage *msg) +handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg) { struct Channel *ch = cls; size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage); @@ -1037,28 +988,25 @@ handle_cadet_audio_message (void *cls, struct ClientAudioMessage *cam; GNUNET_CADET_receive_done (ch->channel); - if ( (GNUNET_YES == ch->suspended_local) || - (GNUNET_YES == ch->suspended_remote) ) + if ((GNUNET_YES == ch->suspended_local) || + (GNUNET_YES == ch->suspended_remote)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", - (unsigned int) msize, - ch->cid); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", + (unsigned int) msize, + ch->cid); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding %u bytes of AUDIO data to client CID %u\n", (unsigned int) msize, ch->cid); - env = GNUNET_MQ_msg_extra (cam, - msize, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); + env = + GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); cam->cid = ch->cid; - GNUNET_memcpy (&cam[1], - &msg[1], - msize); - GNUNET_MQ_send (ch->line->mq, - env); + GNUNET_memcpy (&cam[1], &msg[1], msize); + GNUNET_MQ_send (ch->line->mq, env); } @@ -1070,15 +1018,14 @@ handle_cadet_audio_message (void *cls, * @param channel connection to the other end (henceforth invalid) */ static void -inbound_end (void *cls, - const struct GNUNET_CADET_Channel *channel) +inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel) { struct Channel *ch = cls; GNUNET_assert (channel == ch->channel); ch->channel = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Channel destroyed by CADET in state %d\n", + "Channel destroyed by CADET in state %d\n", ch->status); clean_up_channel (ch); } @@ -1091,34 +1038,32 @@ inbound_end (void *cls, * @param msg the message from the client */ static void -handle_client_call_message (void *cls, - const struct ClientCallMessage *msg) +handle_client_call_message (void *cls, const struct ClientCallMessage *msg) { struct Line *line = cls; struct Channel *ch = GNUNET_new (struct Channel); - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_fixed_size (cadet_hangup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, - struct CadetPhoneHangupMessage, - ch), - GNUNET_MQ_hd_fixed_size (cadet_pickup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, - struct CadetPhonePickupMessage, - ch), - GNUNET_MQ_hd_fixed_size (cadet_suspend_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, - struct CadetPhoneSuspendMessage, - ch), - GNUNET_MQ_hd_fixed_size (cadet_resume_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, - struct CadetPhoneResumeMessage, - ch), - GNUNET_MQ_hd_var_size (cadet_audio_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, - struct CadetAudioMessage, - ch), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_fixed_size (cadet_hangup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, + struct CadetPhoneHangupMessage, + ch), + GNUNET_MQ_hd_fixed_size (cadet_pickup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, + struct CadetPhonePickupMessage, + ch), + GNUNET_MQ_hd_fixed_size (cadet_suspend_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, + struct CadetPhoneSuspendMessage, + ch), + GNUNET_MQ_hd_fixed_size (cadet_resume_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, + struct CadetPhoneResumeMessage, + ch), + GNUNET_MQ_hd_var_size (cadet_audio_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, + struct CadetAudioMessage, + ch), + GNUNET_MQ_handler_end ()}; struct GNUNET_MQ_Envelope *e; struct CadetPhoneRingMessage *ring; struct CadetPhoneRingInfoPS rs; @@ -1128,35 +1073,27 @@ handle_client_call_message (void *cls, rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); rs.line_port = line->line_port; rs.target_peer = msg->target; - rs.expiration_time - = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); + rs.expiration_time = + GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); ch->line = line; - GNUNET_CONTAINER_DLL_insert (line->channel_head, - line->channel_tail, - ch); + GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); ch->status = CS_CALLER_CALLING; ch->channel = GNUNET_CADET_channel_create (cadet, ch, &msg->target, &msg->line_port, - GNUNET_CADET_OPTION_RELIABLE, NULL, &inbound_end, cadet_handlers); ch->mq = GNUNET_CADET_get_mq (ch->channel); - e = GNUNET_MQ_msg (ring, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); - GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, - &ring->caller_id); + e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); + GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id); ring->expiration_time = rs.expiration_time; - GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, - &rs.purpose, - &ring->signature)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending RING message via CADET\n"); - GNUNET_MQ_send (ch->mq, - e); + GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, + &rs.purpose, + &ring->signature)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); + GNUNET_MQ_send (ch->mq, e); GNUNET_SERVICE_client_continue (line->client); } @@ -1188,9 +1125,7 @@ inbound_channel (void *cls, ch->channel = channel; ch->mq = GNUNET_CADET_get_mq (ch->channel); ch->cid = line->cid_gen++; - GNUNET_CONTAINER_DLL_insert (line->channel_head, - line->channel_tail, - ch); + GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch); return ch; } @@ -1235,8 +1170,7 @@ client_disconnect_cb (void *cls, (void) cls; (void) client; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected, closing line\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n"); if (NULL != line->port) { GNUNET_CADET_close_port (line->port); @@ -1263,33 +1197,32 @@ handle_client_register_message (void *cls, const struct ClientPhoneRegisterMessage *msg) { struct Line *line = cls; - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_fixed_size (cadet_ring_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, - struct CadetPhoneRingMessage, - NULL), - GNUNET_MQ_hd_fixed_size (cadet_hangup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, - struct CadetPhoneHangupMessage, - NULL), - GNUNET_MQ_hd_fixed_size (cadet_pickup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, - struct CadetPhonePickupMessage, - NULL), - GNUNET_MQ_hd_fixed_size (cadet_suspend_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, - struct CadetPhoneSuspendMessage, - NULL), - GNUNET_MQ_hd_fixed_size (cadet_resume_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, - struct CadetPhoneResumeMessage, - NULL), - GNUNET_MQ_hd_var_size (cadet_audio_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, - struct CadetAudioMessage, - NULL), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_fixed_size (cadet_ring_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, + struct CadetPhoneRingMessage, + NULL), + GNUNET_MQ_hd_fixed_size (cadet_hangup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, + struct CadetPhoneHangupMessage, + NULL), + GNUNET_MQ_hd_fixed_size (cadet_pickup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, + struct CadetPhonePickupMessage, + NULL), + GNUNET_MQ_hd_fixed_size (cadet_suspend_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, + struct CadetPhoneSuspendMessage, + NULL), + GNUNET_MQ_hd_fixed_size (cadet_resume_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, + struct CadetPhoneResumeMessage, + NULL), + GNUNET_MQ_hd_var_size (cadet_audio_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, + struct CadetAudioMessage, + NULL), + GNUNET_MQ_handler_end ()}; line->line_port = msg->line_port; line->port = GNUNET_CADET_open_port (cadet, @@ -1302,7 +1235,7 @@ handle_client_register_message (void *cls, if (NULL == line->port) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not open line, port %s already in use!\n"), + _ ("Could not open line, port %s already in use!\n"), GNUNET_h2s (&msg->line_port)); GNUNET_SERVICE_client_drop (line->client); return; @@ -1344,8 +1277,7 @@ run (void *cls, (void) service; cfg = c; GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_get_peer_identity (cfg, - &my_identity)); + GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity)); cadet = GNUNET_CADET_connect (cfg); if (NULL == cadet) { @@ -1353,50 +1285,49 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, - NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("conversation", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (client_register_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, - struct ClientPhoneRegisterMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_pickup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, - struct ClientPhonePickupMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_suspend_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, - struct ClientPhoneSuspendMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_resume_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, - struct ClientPhoneResumeMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_hangup_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, - struct ClientPhoneHangupMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_call_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, - struct ClientCallMessage, - NULL), - GNUNET_MQ_hd_var_size (client_audio_message, - GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, - struct ClientAudioMessage, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ( + "conversation", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (client_register_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, + struct ClientPhoneRegisterMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_pickup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, + struct ClientPhonePickupMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_suspend_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, + struct ClientPhoneSuspendMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_resume_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, + struct ClientPhoneResumeMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_hangup_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, + struct ClientPhoneHangupMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_call_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, + struct ClientCallMessage, + NULL), + GNUNET_MQ_hd_var_size (client_audio_message, + GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, + struct ClientAudioMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-conversation.c */ diff --git a/src/fs/gnunet-service-fs_cadet_client.c b/src/fs/gnunet-service-fs_cadet_client.c index 9f654849d..81afe0411 100644 --- a/src/fs/gnunet-service-fs_cadet_client.c +++ b/src/fs/gnunet-service-fs_cadet_client.c @@ -41,7 +41,8 @@ /** * After how long do we reset connections without replies? */ -#define CLIENT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) +#define CLIENT_RETRY_TIMEOUT \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** @@ -143,7 +144,6 @@ struct CadetHandle * callback from the cadet API). */ struct GNUNET_SCHEDULER_Task *reset_task; - }; @@ -181,20 +181,15 @@ transmit_pending (void *cls); * @return #GNUNET_YES (continue to iterate) */ static int -move_to_pending (void *cls, - const struct GNUNET_HashCode *key, - void *value) +move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value) { struct CadetHandle *mh = cls; struct GSF_CadetRequest *sr = value; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, - key, - value)); - GNUNET_CONTAINER_DLL_insert (mh->pending_head, - mh->pending_tail, - sr); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, key, value)); + GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); sr->was_transmitted = GNUNET_NO; return GNUNET_YES; } @@ -209,8 +204,7 @@ move_to_pending (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing */ static int -check_reply (void *cls, - const struct CadetReplyMessage *srm) +check_reply (void *cls, const struct CadetReplyMessage *srm) { /* We check later... */ return GNUNET_OK; @@ -237,8 +231,7 @@ reset_cadet_async (struct CadetHandle *mh) { if (NULL != mh->reset_task) GNUNET_SCHEDULER_cancel (mh->reset_task); - mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, - mh); + mh->reset_task = GNUNET_SCHEDULER_add_now (&reset_cadet_task, mh); } @@ -285,18 +278,16 @@ struct HandleReplyClosure * @return #GNUNET_YES (continue to iterate) */ static int -process_reply (void *cls, - const struct GNUNET_HashCode *key, - void *value) +process_reply (void *cls, const struct GNUNET_HashCode *key, void *value) { struct HandleReplyClosure *hrc = cls; struct GSF_CadetRequest *sr = value; sr->proc (sr->proc_cls, - hrc->type, - hrc->expiration, - hrc->data_size, - hrc->data); + hrc->type, + hrc->expiration, + hrc->data_size, + hrc->data); sr->proc = NULL; GSF_cadet_query_cancel (sr); hrc->found = GNUNET_YES; @@ -315,9 +306,7 @@ process_reply (void *cls, * @return #GNUNET_YES (continue to iterate) */ static int -free_waiting_entry (void *cls, - const struct GNUNET_HashCode *key, - void *value) +free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GSF_CadetRequest *sr = value; @@ -334,8 +323,7 @@ free_waiting_entry (void *cls, * @param srm the actual message */ static void -handle_reply (void *cls, - const struct CadetReplyMessage *srm) +handle_reply (void *cls, const struct CadetReplyMessage *srm) { struct CadetHandle *mh = cls; struct HandleReplyClosure hrc; @@ -346,43 +334,43 @@ handle_reply (void *cls, msize = ntohs (srm->header.size) - sizeof (struct CadetReplyMessage); type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); if (GNUNET_YES != - GNUNET_BLOCK_get_key (GSF_block_ctx, - type, - &srm[1], - msize, - &query)) + GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query)) { GNUNET_break_op (0); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", - type, - msize, - GNUNET_i2s (&mh->target)); + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + "Received bogus reply of type %u with %u bytes via cadet from peer %s\n", + type, + msize, + GNUNET_i2s (&mh->target)); reset_cadet_async (mh); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received reply `%s' via cadet from peer %s\n", - GNUNET_h2s (&query), - GNUNET_i2s (&mh->target)); + "Received reply `%s' via cadet from peer %s\n", + GNUNET_h2s (&query), + GNUNET_i2s (&mh->target)); GNUNET_CADET_receive_done (mh->channel); GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# replies received via cadet"), 1, - GNUNET_NO); + gettext_noop ("# replies received via cadet"), + 1, + GNUNET_NO); hrc.data = &srm[1]; hrc.data_size = msize; hrc.expiration = GNUNET_TIME_absolute_ntoh (srm->expiration); hrc.type = type; hrc.found = GNUNET_NO; GNUNET_CONTAINER_multihashmap_get_multiple (mh->waiting_map, - &query, - &process_reply, - &hrc); + &query, + &process_reply, + &hrc); if (GNUNET_NO == hrc.found) { GNUNET_STATISTICS_update (GSF_stats, - gettext_noop ("# replies received via cadet dropped"), 1, - GNUNET_NO); + gettext_noop ( + "# replies received via cadet dropped"), + 1, + GNUNET_NO); } } @@ -395,8 +383,7 @@ handle_reply (void *cls, * @param channel channel of the disconnecting client */ static void -disconnect_cb (void *cls, - const struct GNUNET_CADET_Channel *channel) +disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel) { struct CadetHandle *mh = cls; struct GSF_CadetRequest *sr; @@ -411,19 +398,17 @@ disconnect_cb (void *cls, callback from `free_waiting_entry()` happens to re-issue the request, we don't immediately have it back in the `waiting_map`. */ - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_remove (cadet_map, - &mh->target, - mh)); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (cadet_map, + &mh->target, + mh)); GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, - &free_waiting_entry, - mh); + &free_waiting_entry, + mh); if (NULL != mh->timeout_task) GNUNET_SCHEDULER_cancel (mh->timeout_task); if (NULL != mh->reset_task) GNUNET_SCHEDULER_cancel (mh->reset_task); - GNUNET_assert (0 == - GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)); + GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)); GNUNET_CONTAINER_multihashmap_destroy (mh->waiting_map); GNUNET_free (mh); } @@ -467,24 +452,21 @@ static void reset_cadet (struct CadetHandle *mh) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resetting cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + "Resetting cadet channel to %s\n", + GNUNET_i2s (&mh->target)); if (NULL != mh->channel) { GNUNET_CADET_channel_destroy (mh->channel); mh->channel = NULL; } - GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, - &move_to_pending, - mh); + GNUNET_CONTAINER_multihashmap_iterate (mh->waiting_map, &move_to_pending, mh); { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (reply, - GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, - struct CadetReplyMessage, - mh), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (reply, + GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, + struct CadetReplyMessage, + mh), + GNUNET_MQ_handler_end ()}; struct GNUNET_HashCode port; GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, @@ -514,8 +496,8 @@ cadet_timeout (void *cls) struct GNUNET_CADET_Channel *tun; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout on cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + "Timeout on cadet channel to %s\n", + GNUNET_i2s (&mh->target)); mh->timeout_task = NULL; tun = mh->channel; mh->channel = NULL; @@ -553,33 +535,28 @@ transmit_pending (void *cls) struct GNUNET_MQ_Envelope *env; struct CadetQueryMessage *sqm; - if ( (0 != GNUNET_MQ_get_length (mq)) || - (NULL == (sr = mh->pending_head)) ) + if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head))) return; - GNUNET_CONTAINER_DLL_remove (mh->pending_head, - mh->pending_tail, - sr); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (mh->waiting_map, - &sr->query, - sr, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( + mh->waiting_map, + &sr->query, + sr, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); sr->was_transmitted = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending query for %s via cadet to %s\n", - GNUNET_h2s (&sr->query), - GNUNET_i2s (&mh->target)); - env = GNUNET_MQ_msg (sqm, - GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); - GNUNET_MQ_env_set_options(env, - GNUNET_MQ_PREF_RELIABLE); + "Sending query for %s via cadet to %s\n", + GNUNET_h2s (&sr->query), + GNUNET_i2s (&mh->target)); + env = GNUNET_MQ_msg (sqm, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY); + GNUNET_MQ_env_set_options (env, + GNUNET_MQ_PREF_GOODPUT | + GNUNET_MQ_PREF_CORK_ALLOWED | + GNUNET_MQ_PREF_OUT_OF_ORDER); sqm->type = htonl (sr->type); sqm->query = sr->query; - GNUNET_MQ_notify_sent (env, - &transmit_pending, - mh); - GNUNET_MQ_send (mq, - env); + GNUNET_MQ_notify_sent (env, &transmit_pending, mh); + GNUNET_MQ_send (mq, env); } @@ -593,8 +570,7 @@ get_cadet (const struct GNUNET_PeerIdentity *target) { struct CadetHandle *mh; - mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, - target); + mh = GNUNET_CONTAINER_multipeermap_get (cadet_map, target); if (NULL != mh) { if (NULL != mh->timeout_task) @@ -605,27 +581,26 @@ get_cadet (const struct GNUNET_PeerIdentity *target) return mh; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating cadet channel to %s\n", - GNUNET_i2s (target)); + "Creating cadet channel to %s\n", + GNUNET_i2s (target)); mh = GNUNET_new (struct CadetHandle); - mh->reset_task = GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, - &reset_cadet_task, - mh); + mh->reset_task = + GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, &reset_cadet_task, mh); mh->waiting_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); mh->target = *target; GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (cadet_map, - &mh->target, - mh, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multipeermap_put ( + cadet_map, + &mh->target, + mh, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (reply, - GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, - struct CadetReplyMessage, - mh), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (reply, + GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, + struct CadetReplyMessage, + mh), + GNUNET_MQ_handler_end ()}; struct GNUNET_HashCode port; GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, @@ -664,9 +639,9 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target, struct GSF_CadetRequest *sr; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Preparing to send query for %s via cadet to %s\n", - GNUNET_h2s (query), - GNUNET_i2s (target)); + "Preparing to send query for %s via cadet to %s\n", + GNUNET_h2s (query), + GNUNET_i2s (target)); mh = get_cadet (target); sr = GNUNET_new (struct GSF_CadetRequest); sr->mh = mh; @@ -674,9 +649,7 @@ GSF_cadet_query (const struct GNUNET_PeerIdentity *target, sr->proc_cls = proc_cls; sr->type = type; sr->query = *query; - GNUNET_CONTAINER_DLL_insert (mh->pending_head, - mh->pending_tail, - sr); + GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr); transmit_pending (mh); return sr; } @@ -699,29 +672,24 @@ GSF_cadet_query_cancel (struct GSF_CadetRequest *sr) if (NULL != p) { /* signal failure / cancellation to callback */ - p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, - GNUNET_TIME_UNIT_ZERO_ABS, - 0, NULL); + p (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_UNIT_ZERO_ABS, 0, NULL); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cancelled query for %s via cadet to %s\n", - GNUNET_h2s (&sr->query), - GNUNET_i2s (&sr->mh->target)); + "Cancelled query for %s via cadet to %s\n", + GNUNET_h2s (&sr->query), + GNUNET_i2s (&sr->mh->target)); if (GNUNET_YES == sr->was_transmitted) - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, - &sr->query, - sr)); + GNUNET_assert ( + GNUNET_OK == + GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr)); else - GNUNET_CONTAINER_DLL_remove (mh->pending_head, - mh->pending_tail, - sr); + GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr); GNUNET_free (sr); - if ( (0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && - (NULL == mh->pending_head) ) + if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) && + (NULL == mh->pending_head)) mh->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &cadet_timeout, - mh); + &cadet_timeout, + mh); } @@ -741,8 +709,8 @@ GSF_cadet_release_clients (void *cls, struct CadetHandle *mh = value; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout on cadet channel to %s\n", - GNUNET_i2s (&mh->target)); + "Timeout on cadet channel to %s\n", + GNUNET_i2s (&mh->target)); if (NULL != mh->channel) { struct GNUNET_CADET_Channel *channel = mh->channel; @@ -759,5 +727,4 @@ GSF_cadet_release_clients (void *cls, } - /* end of gnunet-service-fs_cadet_client.c */ diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index d3f4c9717..f3073d54b 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h @@ -298,21 +298,6 @@ enum GNUNET_MQ_PriorityPreferences */ GNUNET_MQ_PREF_OUT_OF_ORDER = 256, - /** - * Flag to indicate no buffering. - */ - GNUNET_MQ_PREF_NO_BUFFER = 512, - - /** - * Flag to indicate default - */ - GNUNET_MQ_PREF_DEFAULT = 1024, - - /** - * Flag to indicate reliable - */ - GNUNET_MQ_PREF_RELIABLE = 2048 - }; @@ -388,6 +373,24 @@ typedef void (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq, typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error); +/** + * Insert @a env into the envelope DLL starting at @a env_head + * Note that @a env must not be in any MQ while this function + * is used with DLLs defined outside of the MQ module. This + * is just in case some application needs to also manage a + * FIFO of envelopes independent of MQ itself and wants to + * re-use the pointers internal to @a env. Use with caution. + * + * @param[in|out] env_head of envelope DLL + * @param[in|out] env_tail tail of envelope DLL + * @param[in|out] env element to insert at the tail + */ +void +GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, + struct GNUNET_MQ_Envelope **env_tail, + struct GNUNET_MQ_Envelope *env); + + /** * Insert @a env into the envelope DLL starting at @a env_head * Note that @a env must not be in any MQ while this function diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index 123a02188..dc2763943 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -36,7 +36,8 @@ #include "scalarproduct.h" #include "gnunet-service-scalarproduct-ecc.h" -#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) /** * Maximum allowed result value for the scalarproduct computation. @@ -69,7 +70,6 @@ struct MpiElement * a_i value, not disclosed to Bob. */ gcry_mpi_t value; - }; @@ -175,7 +175,6 @@ struct AliceServiceSession * doing harm. */ int in_destroy; - }; @@ -214,9 +213,7 @@ static struct GNUNET_CADET_Handle *my_cadet; * @return #GNUNET_OK (continue to iterate) */ static int -free_element_cb (void *cls, - const struct GNUNET_HashCode *key, - void *value) +free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_SCALARPRODUCT_Element *e = value; @@ -265,8 +262,7 @@ destroy_service_session (struct AliceServiceSession *s) } if (NULL != s->intersection_op) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Set intersection, op still ongoing!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); GNUNET_SET_operation_cancel (s->intersection_op); s->intersection_op = NULL; } @@ -277,7 +273,7 @@ destroy_service_session (struct AliceServiceSession *s) } if (NULL != s->sorted_elements) { - for (i=0;iused_element_count;i++) + for (i = 0; i < s->used_element_count; i++) gcry_mpi_release (s->sorted_elements[i].value); GNUNET_free (s->sorted_elements); s->sorted_elements = NULL; @@ -305,16 +301,15 @@ prepare_client_end_notification (struct AliceServiceSession *session) if (NULL == session->client_mq) return; /* no client left to be notified */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending session-end notification with status %d to client for session %s\n", - session->status, - GNUNET_h2s (&session->session_id)); - e = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Sending session-end notification with status %d to client for session %s\n", + session->status, + GNUNET_h2s (&session->session_id)); + e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); msg->product_length = htonl (0); msg->status = htonl (session->status); - GNUNET_MQ_send (session->client_mq, - e); + GNUNET_MQ_send (session->client_mq, e); } @@ -347,9 +342,7 @@ transmit_client_response (struct AliceServiceSession *s) if (0 > sign) { range = -1; - gcry_mpi_sub (value, - value, - s->product); + gcry_mpi_sub (value, value, s->product); } else if (0 < sign) { @@ -364,15 +357,12 @@ transmit_client_response (struct AliceServiceSession *s) gcry_mpi_release (s->product); s->product = NULL; - if ( (0 != range) && - (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, - &product_exported, - &product_length, - value)))) + if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, + &product_exported, + &product_length, + value)))) { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, - "gcry_mpi_scan", - rc); + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); prepare_client_end_notification (s); return; } @@ -385,13 +375,10 @@ transmit_client_response (struct AliceServiceSession *s) msg->product_length = htonl (product_length); if (NULL != product_exported) { - GNUNET_memcpy (&msg[1], - product_exported, - product_length); + GNUNET_memcpy (&msg[1], product_exported, product_length); GNUNET_free (product_exported); } - GNUNET_MQ_send (s->client_mq, - e); + GNUNET_MQ_send (s->client_mq, e); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent result to client, session %s has ended!\n", GNUNET_h2s (&s->session_id)); @@ -408,8 +395,7 @@ transmit_client_response (struct AliceServiceSession *s) * @param channel connection to the other end (henceforth invalid) */ static void -cb_channel_destruction (void *cls, - const struct GNUNET_CADET_Channel *channel) +cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) { struct AliceServiceSession *s = cls; @@ -445,15 +431,11 @@ compute_scalar_product (struct AliceServiceSession *session, int ai_bi; gcry_mpi_t ret; - g_i_b_i_a_inv = GNUNET_CRYPTO_ecc_pmul_mpi (edc, - prod_g_i_b_i, - my_privkey_inv); - g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, - g_i_b_i_a_inv, - prod_h_i_b_i); + g_i_b_i_a_inv = + GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv); + g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i); gcry_mpi_point_release (g_i_b_i_a_inv); - ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, - g_ai_bi); + ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi); gcry_mpi_point_release (g_ai_bi); if (INT_MAX == ai_bi) { @@ -469,7 +451,7 @@ compute_scalar_product (struct AliceServiceSession *session, } else { - gcry_mpi_set_ui (ret, - ai_bi); + gcry_mpi_set_ui (ret, -ai_bi); gcry_mpi_neg (ret, ret); } return ret; @@ -518,13 +500,9 @@ handle_bobs_cryptodata_message (void *cls, "Received %u crypto values from Bob\n", (unsigned int) contained); GNUNET_CADET_receive_done (s->channel); - prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, - &msg->prod_g_i_b_i); - prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, - &msg->prod_h_i_b_i); - s->product = compute_scalar_product (s, - prod_g_i_b_i, - prod_h_i_b_i); + prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i); + prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_h_i_b_i); + s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i); gcry_mpi_point_release (prod_g_i_b_i); gcry_mpi_point_release (prod_h_i_b_i); transmit_client_response (s); @@ -540,9 +518,7 @@ handle_bobs_cryptodata_message (void *cls, * @param value the `struct GNUNET_SCALARPRODUCT_Element *` */ static int -copy_element_cb (void *cls, - const struct GNUNET_HashCode *key, - void *value) +copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) { struct AliceServiceSession *s = cls; struct GNUNET_SCALARPRODUCT_Element *e = value; @@ -555,8 +531,8 @@ copy_element_cb (void *cls, gcry_mpi_sub_ui (mval, mval, -val); else gcry_mpi_add_ui (mval, mval, val); - s->sorted_elements [s->used_element_count].value = mval; - s->sorted_elements [s->used_element_count].key = &e->key; + s->sorted_elements[s->used_element_count].value = mval; + s->sorted_elements[s->used_element_count].key = &e->key; s->used_element_count++; return GNUNET_OK; } @@ -570,14 +546,12 @@ copy_element_cb (void *cls, * @return -1 for a < b, 0 for a=b, 1 for a > b. */ static int -element_cmp (const void *a, - const void *b) +element_cmp (const void *a, const void *b) { const struct MpiElement *ma = a; const struct MpiElement *mb = b; - return GNUNET_CRYPTO_hash_cmp (ma->key, - mb->key); + return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); } @@ -585,7 +559,10 @@ element_cmp (const void *a, * Maximum number of elements we can put into a single cryptodata * message */ -#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct EccAliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_EccPoint)) +#define ELEMENT_CAPACITY \ + ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ + sizeof (struct EccAliceCryptodataMessage)) / \ + sizeof (struct GNUNET_CRYPTO_EccPoint)) /** @@ -606,9 +583,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) unsigned int off; unsigned int todo_count; - s->sorted_elements - = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), - struct MpiElement); + s->sorted_elements = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size ( + s->intersected_elements), + struct MpiElement); s->used_element_count = 0; GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, ©_element_cb, @@ -631,11 +608,11 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) (unsigned int) todo_count, (unsigned int) s->used_element_count); - e = GNUNET_MQ_msg_extra (msg, - todo_count * 2 * sizeof (struct GNUNET_CRYPTO_EccPoint), - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); - GNUNET_MQ_env_set_options(e, - GNUNET_MQ_PREF_RELIABLE); + e = + GNUNET_MQ_msg_extra (msg, + todo_count * 2 * + sizeof (struct GNUNET_CRYPTO_EccPoint), + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); msg->contained_element_count = htonl (todo_count); payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; r_ia = gcry_mpi_new (0); @@ -647,33 +624,22 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) gcry_mpi_point_t h_i; r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); - g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, - r_i); + g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i); /* r_ia = r_i * a */ - gcry_mpi_mul (r_ia, - r_i, - my_privkey); + gcry_mpi_mul (r_ia, r_i, my_privkey); gcry_mpi_release (r_i); /* r_ia_ai = r_ia + a_i */ - gcry_mpi_add (r_ia_ai, - r_ia, - s->sorted_elements[i].value); - h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, - r_ia_ai); - GNUNET_CRYPTO_ecc_point_to_bin (edc, - g_i, - &payload[(i - off) * 2]); - GNUNET_CRYPTO_ecc_point_to_bin (edc, - h_i, - &payload[(i - off) * 2 + 1]); + gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value); + h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai); + GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]); + GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]); gcry_mpi_point_release (g_i); gcry_mpi_point_release (h_i); } gcry_mpi_release (r_ia); gcry_mpi_release (r_ia_ai); off += todo_count; - GNUNET_MQ_send (s->cadet_mq, - e); + GNUNET_MQ_send (s->cadet_mq, e); } } @@ -708,10 +674,11 @@ cb_intersection_element_removed (void *cls, "Intersection removed element with key %s and value %lld\n", GNUNET_h2s (&se->key), (long long) GNUNET_ntohll (se->value)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, - element->data, - se)); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, + element->data, + se)); GNUNET_free (se); return; case GNUNET_SET_STATUS_DONE: @@ -729,8 +696,7 @@ cb_intersection_element_removed (void *cls, return; case GNUNET_SET_STATUS_FAILURE: /* unhandled status code */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Set intersection failed!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); if (NULL != s->intersection_listen) { GNUNET_SET_listen_cancel (s->intersection_listen); @@ -778,18 +744,16 @@ cb_intersection_request_alice (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received intersection request from %s!\n", GNUNET_i2s (other_peer)); - if (0 != GNUNET_memcmp (other_peer, - &s->peer)) + if (0 != GNUNET_memcmp (other_peer, &s->peer)) { GNUNET_break_op (0); return; } - s->intersection_op - = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_REMOVED, - (struct GNUNET_SET_Option[]) {{ 0 }}, - &cb_intersection_element_removed, - s); + s->intersection_op = GNUNET_SET_accept (request, + GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]){{0}}, + &cb_intersection_element_removed, + s); if (NULL == s->intersection_op) { GNUNET_break (0); @@ -797,9 +761,7 @@ cb_intersection_request_alice (void *cls, prepare_client_end_notification (s); return; } - if (GNUNET_OK != - GNUNET_SET_commit (s->intersection_op, - s->intersection_set)) + if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) { GNUNET_break (0); s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -817,13 +779,12 @@ cb_intersection_request_alice (void *cls, static void client_request_complete_alice (struct AliceServiceSession *s) { - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, - struct EccBobCryptodataMessage, - s), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, + struct EccBobCryptodataMessage, + s), + GNUNET_MQ_handler_end ()}; struct EccServiceRequestMessage *msg; struct GNUNET_MQ_Envelope *e; struct GNUNET_HashCode set_sid; @@ -834,14 +795,13 @@ client_request_complete_alice (struct AliceServiceSession *s) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating new channel for session with key %s.\n", GNUNET_h2s (&s->session_id)); - s->channel - = GNUNET_CADET_channel_create (my_cadet, - s, - &s->peer, - &s->session_id, - NULL, - &cb_channel_destruction, - cadet_handlers); + s->channel = GNUNET_CADET_channel_create (my_cadet, + s, + &s->peer, + &s->session_id, + NULL, + &cb_channel_destruction, + cadet_handlers); if (NULL == s->channel) { s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -849,12 +809,11 @@ client_request_complete_alice (struct AliceServiceSession *s) return; } s->cadet_mq = GNUNET_CADET_get_mq (s->channel); - s->intersection_listen - = GNUNET_SET_listen (cfg, - GNUNET_SET_OPERATION_INTERSECTION, - &set_sid, - &cb_intersection_request_alice, - s); + s->intersection_listen = GNUNET_SET_listen (cfg, + GNUNET_SET_OPERATION_INTERSECTION, + &set_sid, + &cb_intersection_request_alice, + s); if (NULL == s->intersection_listen) { s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -864,13 +823,12 @@ client_request_complete_alice (struct AliceServiceSession *s) return; } - e = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); - GNUNET_MQ_env_set_options(e, - GNUNET_MQ_PREF_RELIABLE); + e = + GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); + GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL); msg->session_id = s->session_id; - GNUNET_MQ_send (s->cadet_mq, - e); + GNUNET_MQ_send (s->cadet_mq, e); } @@ -883,8 +841,9 @@ client_request_complete_alice (struct AliceServiceSession *s) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_alice_client_message_multipart (void *cls, - const struct ComputationBobCryptodataMultipartMessage *msg) +check_alice_client_message_multipart ( + void *cls, + const struct ComputationBobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -892,11 +851,12 @@ check_alice_client_message_multipart (void *cls, msize = ntohs (msg->header.size); contained_count = ntohl (msg->element_count_contained); - if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + - contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || - (0 == contained_count) || - (s->total == s->client_received_element_count) || - (s->total < s->client_received_element_count + contained_count) ) + if ((msize != + (sizeof (struct ComputationBobCryptodataMultipartMessage) + + contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || + (0 == contained_count) || + (s->total == s->client_received_element_count) || + (s->total < s->client_received_element_count + contained_count)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -913,8 +873,9 @@ check_alice_client_message_multipart (void *cls, * @param msg the actual message */ static void -handle_alice_client_message_multipart (void *cls, - const struct ComputationBobCryptodataMultipartMessage *msg) +handle_alice_client_message_multipart ( + void *cls, + const struct ComputationBobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -929,13 +890,13 @@ handle_alice_client_message_multipart (void *cls, { elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); GNUNET_memcpy (elem, - &elements[i], - sizeof (struct GNUNET_SCALARPRODUCT_Element)); - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, - &elem->key, - elem, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + &elements[i], + sizeof (struct GNUNET_SCALARPRODUCT_Element)); + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( + s->intersected_elements, + &elem->key, + elem, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_break (0); GNUNET_free (elem); @@ -944,9 +905,7 @@ handle_alice_client_message_multipart (void *cls, set_elem.data = &elem->key; set_elem.size = sizeof (elem->key); set_elem.element_type = 0; - GNUNET_SET_add_element (s->intersection_set, - &set_elem, - NULL, NULL); + GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); s->used_element_count++; } GNUNET_SERVICE_client_continue (s->client); @@ -957,8 +916,7 @@ handle_alice_client_message_multipart (void *cls, "Received client multipart data, waiting for more!\n"); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Launching computation\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); client_request_complete_alice (s); } @@ -973,7 +931,7 @@ handle_alice_client_message_multipart (void *cls, */ static int check_alice_client_message (void *cls, - const struct AliceComputationMessage *msg) + const struct AliceComputationMessage *msg) { struct AliceServiceSession *s = cls; uint16_t msize; @@ -990,10 +948,10 @@ check_alice_client_message (void *cls, msize = ntohs (msg->header.size); total_count = ntohl (msg->element_count_total); contained_count = ntohl (msg->element_count_contained); - if ( (0 == total_count) || - (0 == contained_count) || - (msize != (sizeof (struct AliceComputationMessage) + - contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) + if ((0 == total_count) || (0 == contained_count) || + (msize != + (sizeof (struct AliceComputationMessage) + + contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1011,7 +969,7 @@ check_alice_client_message (void *cls, */ static void handle_alice_client_message (void *cls, - const struct AliceComputationMessage *msg) + const struct AliceComputationMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -1028,23 +986,23 @@ handle_alice_client_message (void *cls, s->client_received_element_count = contained_count; s->session_id = msg->session_key; elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; - s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, - GNUNET_YES); - s->intersection_set = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_INTERSECTION); + s->intersected_elements = + GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); + s->intersection_set = + GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); for (uint32_t i = 0; i < contained_count; i++) { if (0 == GNUNET_ntohll (elements[i].value)) continue; elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); GNUNET_memcpy (elem, - &elements[i], - sizeof (struct GNUNET_SCALARPRODUCT_Element)); - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, - &elem->key, - elem, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + &elements[i], + sizeof (struct GNUNET_SCALARPRODUCT_Element)); + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( + s->intersected_elements, + &elem->key, + elem, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { /* element with same key encountered twice! */ GNUNET_break (0); @@ -1054,9 +1012,7 @@ handle_alice_client_message (void *cls, set_elem.data = &elem->key; set_elem.size = sizeof (elem->key); set_elem.element_type = 0; - GNUNET_SET_add_element (s->intersection_set, - &set_elem, - NULL, NULL); + GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); s->used_element_count++; } GNUNET_SERVICE_client_continue (s->client); @@ -1067,8 +1023,7 @@ handle_alice_client_message (void *cls, "Received partial client request, waiting for more!\n"); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Launching computation\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); client_request_complete_alice (s); } @@ -1082,8 +1037,7 @@ handle_alice_client_message (void *cls, static void shutdown_task (void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down, initiating cleanup.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); // FIXME: we have to cut our connections to CADET first! if (NULL != my_cadet) { @@ -1110,8 +1064,8 @@ shutdown_task (void *cls) */ static void * client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct AliceServiceSession *s; @@ -1134,8 +1088,8 @@ client_connect_cb (void *cls, */ static void client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_cls) + struct GNUNET_SERVICE_Client *client, + void *app_cls) { struct AliceServiceSession *s = app_cls; @@ -1161,45 +1115,40 @@ run (void *cls, struct GNUNET_SERVICE_Handle *service) { cfg = c; - edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, - MAX_RAM); + edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM); /* Select a random 'a' value for Alice */ - GNUNET_CRYPTO_ecc_rnd_mpi (edc, - &my_privkey, - &my_privkey_inv); + GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv); my_cadet = GNUNET_CADET_connect (cfg); if (NULL == my_cadet) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Connect to CADET failed\n")); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); - + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("scalarproduct-alice", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_var_size (alice_client_message, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, - struct AliceComputationMessage, - NULL), - GNUNET_MQ_hd_var_size (alice_client_message_multipart, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, - struct ComputationBobCryptodataMultipartMessage, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ( + "scalarproduct-alice", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_var_size (alice_client_message, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, + struct AliceComputationMessage, + NULL), + GNUNET_MQ_hd_var_size ( + alice_client_message_multipart, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, + struct ComputationBobCryptodataMultipartMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-scalarproduct-ecc_alice.c */ diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index 18c5cc49a..e138876f5 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -36,7 +36,8 @@ #include "scalarproduct.h" #include "gnunet-service-scalarproduct.h" -#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) +#define LOG(kind, ...) \ + GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) /** * An encrypted element key-value pair. @@ -185,7 +186,6 @@ struct AliceServiceSession * doing harm. */ int in_destroy; - }; @@ -224,9 +224,7 @@ static struct GNUNET_CADET_Handle *my_cadet; * @return #GNUNET_OK (continue to iterate) */ static int -free_element_cb (void *cls, - const struct GNUNET_HashCode *key, - void *value) +free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_SCALARPRODUCT_Element *e = value; @@ -283,7 +281,7 @@ destroy_service_session (struct AliceServiceSession *s) } if (NULL != s->sorted_elements) { - for (unsigned int i=0;iused_element_count;i++) + for (unsigned int i = 0; i < s->used_element_count; i++) gcry_mpi_release (s->sorted_elements[i].value); GNUNET_free (s->sorted_elements); s->sorted_elements = NULL; @@ -321,16 +319,15 @@ prepare_client_end_notification (struct AliceServiceSession *session) if (NULL == session->client_mq) return; /* no client left to be notified */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending session-end notification with status %d to client for session %s\n", - session->status, - GNUNET_h2s (&session->session_id)); - e = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Sending session-end notification with status %d to client for session %s\n", + session->status, + GNUNET_h2s (&session->session_id)); + e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); msg->product_length = htonl (0); msg->status = htonl (session->status); - GNUNET_MQ_send (session->client_mq, - e); + GNUNET_MQ_send (session->client_mq, e); } @@ -363,9 +360,7 @@ transmit_client_response (struct AliceServiceSession *s) if (0 > sign) { range = -1; - gcry_mpi_sub (value, - value, - s->product); + gcry_mpi_sub (value, value, s->product); } else if (0 < sign) { @@ -380,15 +375,12 @@ transmit_client_response (struct AliceServiceSession *s) gcry_mpi_release (s->product); s->product = NULL; - if ( (0 != range) && - (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, - &product_exported, - &product_length, - value)))) + if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, + &product_exported, + &product_length, + value)))) { - LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, - "gcry_mpi_scan", - rc); + LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); prepare_client_end_notification (s); return; } @@ -401,20 +393,16 @@ transmit_client_response (struct AliceServiceSession *s) msg->product_length = htonl (product_length); if (NULL != product_exported) { - GNUNET_memcpy (&msg[1], - product_exported, - product_length); + GNUNET_memcpy (&msg[1], product_exported, product_length); GNUNET_free (product_exported); } - GNUNET_MQ_send (s->client_mq, - e); + GNUNET_MQ_send (s->client_mq, e); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent result to client, session %s has ended!\n", GNUNET_h2s (&s->session_id)); } - /** * Function called whenever a channel is destroyed. Should clean up * any associated state. @@ -425,8 +413,7 @@ transmit_client_response (struct AliceServiceSession *s) * @param channel connection to the other end (henceforth invalid) */ static void -cb_channel_destruction (void *cls, - const struct GNUNET_CADET_Channel *channel) +cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) { struct AliceServiceSession *s = cls; @@ -479,8 +466,7 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector, * @return an MPI value containing the calculated sum, never NULL */ static gcry_mpi_t -compute_square_sum (const gcry_mpi_t *vector, - uint32_t length) +compute_square_sum (const gcry_mpi_t *vector, uint32_t length) { gcry_mpi_t elem; gcry_mpi_t sum; @@ -531,28 +517,19 @@ compute_scalar_product (struct AliceServiceSession *session) &my_pubkey, &session->r[i], r[i]); - gcry_mpi_sub (r[i], - r[i], - my_offset); - gcry_mpi_sub (r[i], - r[i], - my_offset); + gcry_mpi_sub (r[i], r[i], my_offset); + gcry_mpi_sub (r[i], r[i], my_offset); r_prime[i] = gcry_mpi_new (0); GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->r_prime[i], r_prime[i]); - gcry_mpi_sub (r_prime[i], - r_prime[i], - my_offset); - gcry_mpi_sub (r_prime[i], - r_prime[i], - my_offset); + gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); + gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); } // calculate t = sum(ai) - t = compute_square_sum_mpi_elements (session->sorted_elements, - count); + t = compute_square_sum_mpi_elements (session->sorted_elements, count); // calculate U u = gcry_mpi_new (0); tmp = compute_square_sum (r, count); @@ -570,10 +547,7 @@ compute_scalar_product (struct AliceServiceSession *session) GNUNET_assert (s_prime = gcry_mpi_new (0)); // compute P - GNUNET_CRYPTO_paillier_decrypt (&my_privkey, - &my_pubkey, - &session->s, - s); + GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s); GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s_prime, @@ -627,8 +601,9 @@ compute_scalar_product (struct AliceServiceSession *session) * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_bobs_cryptodata_multipart (void *cls, - const struct BobCryptodataMultipartMessage *msg) +check_bobs_cryptodata_multipart ( + void *cls, + const struct BobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained; @@ -637,10 +612,11 @@ check_bobs_cryptodata_multipart (void *cls, msg_size = ntohs (msg->header.size); contained = ntohl (msg->contained_element_count); - required_size = sizeof (struct BobCryptodataMultipartMessage) - + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); - if ( (required_size != msg_size) || - (s->cadet_received_element_count + contained > s->used_element_count) ) + required_size = + sizeof (struct BobCryptodataMultipartMessage) + + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); + if ((required_size != msg_size) || + (s->cadet_received_element_count + contained > s->used_element_count)) { GNUNET_break (0); return GNUNET_SYSERR; @@ -656,8 +632,9 @@ check_bobs_cryptodata_multipart (void *cls, * @param msg the actual message */ static void -handle_bobs_cryptodata_multipart (void *cls, - const struct BobCryptodataMultipartMessage *msg) +handle_bobs_cryptodata_multipart ( + void *cls, + const struct BobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; const struct GNUNET_CRYPTO_PaillierCiphertext *payload; @@ -710,12 +687,12 @@ check_bobs_cryptodata_message (void *cls, msg_size = ntohs (msg->header.size); contained = ntohl (msg->contained_element_count); - required_size = sizeof (struct BobCryptodataMessage) - + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) - + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); - if ( (msg_size != required_size) || - (contained > UINT16_MAX) || - (s->used_element_count < contained) ) + required_size = + sizeof (struct BobCryptodataMessage) + + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) + + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); + if ((msg_size != required_size) || (contained > UINT16_MAX) || + (s->used_element_count < contained)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -800,9 +777,7 @@ handle_bobs_cryptodata_message (void *cls, * @param value the `struct GNUNET_SCALARPRODUCT_Element *` */ static int -copy_element_cb (void *cls, - const struct GNUNET_HashCode *key, - void *value) +copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) { struct AliceServiceSession *s = cls; struct GNUNET_SCALARPRODUCT_Element *e = value; @@ -815,8 +790,8 @@ copy_element_cb (void *cls, gcry_mpi_sub_ui (mval, mval, -val); else gcry_mpi_add_ui (mval, mval, val); - s->sorted_elements [s->used_element_count].value = mval; - s->sorted_elements [s->used_element_count].key = &e->key; + s->sorted_elements[s->used_element_count].value = mval; + s->sorted_elements[s->used_element_count].key = &e->key; s->used_element_count++; return GNUNET_OK; } @@ -830,14 +805,12 @@ copy_element_cb (void *cls, * @return -1 for a < b, 0 for a=b, 1 for a > b. */ static int -element_cmp (const void *a, - const void *b) +element_cmp (const void *a, const void *b) { const struct MpiElement *ma = a; const struct MpiElement *mb = b; - return GNUNET_CRYPTO_hash_cmp (ma->key, - mb->key); + return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); } @@ -845,7 +818,10 @@ element_cmp (const void *a, * Maximum number of elements we can put into a single cryptodata * message */ -#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) +#define ELEMENT_CAPACITY \ + ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ + sizeof (struct AliceCryptodataMessage)) / \ + sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) /** @@ -865,9 +841,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) gcry_mpi_t a; uint32_t off; - s->sorted_elements - = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * - sizeof (struct MpiElement)); + s->sorted_elements = GNUNET_malloc ( + GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * + sizeof (struct MpiElement)); s->used_element_count = 0; GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, ©_element_cb, @@ -890,29 +866,24 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) (unsigned int) todo_count, (unsigned int) s->used_element_count); - e = GNUNET_MQ_msg_extra (msg, - todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); - GNUNET_MQ_env_set_options(e, - GNUNET_MQ_PREF_RELIABLE); + e = + GNUNET_MQ_msg_extra (msg, + todo_count * + sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); msg->contained_element_count = htonl (todo_count); payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; a = gcry_mpi_new (0); for (i = off; i < off + todo_count; i++) { - gcry_mpi_add (a, - s->sorted_elements[i].value, - my_offset); - GNUNET_assert (3 == - GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, - a, - 3, - &payload[i - off])); + gcry_mpi_add (a, s->sorted_elements[i].value, my_offset); + GNUNET_assert ( + 3 == + GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off])); } gcry_mpi_release (a); off += todo_count; - GNUNET_MQ_send (s->cadet_mq, - e); + GNUNET_MQ_send (s->cadet_mq, e); } } @@ -947,10 +918,11 @@ cb_intersection_element_removed (void *cls, "Intersection removed element with key %s and value %lld\n", GNUNET_h2s (&se->key), (long long) GNUNET_ntohll (se->value)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, - element->data, - se)); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, + element->data, + se)); GNUNET_free (se); return; case GNUNET_SET_STATUS_DONE: @@ -968,8 +940,7 @@ cb_intersection_element_removed (void *cls, return; case GNUNET_SET_STATUS_FAILURE: /* unhandled status code */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Set intersection failed!\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); if (NULL != s->intersection_listen) { GNUNET_SET_listen_cancel (s->intersection_listen); @@ -1014,18 +985,16 @@ cb_intersection_request_alice (void *cls, { struct AliceServiceSession *s = cls; - if (0 != GNUNET_memcmp (other_peer, - &s->peer)) + if (0 != GNUNET_memcmp (other_peer, &s->peer)) { GNUNET_break_op (0); return; } - s->intersection_op - = GNUNET_SET_accept (request, - GNUNET_SET_RESULT_REMOVED, - (struct GNUNET_SET_Option[]) {{ 0 }}, - &cb_intersection_element_removed, - s); + s->intersection_op = GNUNET_SET_accept (request, + GNUNET_SET_RESULT_REMOVED, + (struct GNUNET_SET_Option[]){{0}}, + &cb_intersection_element_removed, + s); if (NULL == s->intersection_op) { GNUNET_break (0); @@ -1033,9 +1002,7 @@ cb_intersection_request_alice (void *cls, prepare_client_end_notification (s); return; } - if (GNUNET_OK != - GNUNET_SET_commit (s->intersection_op, - s->intersection_set)) + if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) { GNUNET_break (0); s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -1053,31 +1020,30 @@ cb_intersection_request_alice (void *cls, static void client_request_complete_alice (struct AliceServiceSession *s) { - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_var_size (bobs_cryptodata_message, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, - struct BobCryptodataMessage, - s), - GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, - struct BobCryptodataMultipartMessage, - s), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_var_size (bobs_cryptodata_message, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, + struct BobCryptodataMessage, + s), + GNUNET_MQ_hd_var_size ( + bobs_cryptodata_multipart, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, + struct BobCryptodataMultipartMessage, + s), + GNUNET_MQ_handler_end ()}; struct ServiceRequestMessage *msg; struct GNUNET_MQ_Envelope *e; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating new channel for session with key %s.\n", GNUNET_h2s (&s->session_id)); - s->channel - = GNUNET_CADET_channel_create (my_cadet, - s, - &s->peer, - &s->session_id, - NULL, - &cb_channel_destruction, - cadet_handlers); + s->channel = GNUNET_CADET_channel_create (my_cadet, + s, + &s->peer, + &s->session_id, + NULL, + &cb_channel_destruction, + cadet_handlers); if (NULL == s->channel) { s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -1085,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s) return; } s->cadet_mq = GNUNET_CADET_get_mq (s->channel); - s->intersection_listen - = GNUNET_SET_listen (cfg, - GNUNET_SET_OPERATION_INTERSECTION, - &s->session_id, - &cb_intersection_request_alice, - s); + s->intersection_listen = GNUNET_SET_listen (cfg, + GNUNET_SET_OPERATION_INTERSECTION, + &s->session_id, + &cb_intersection_request_alice, + s); if (NULL == s->intersection_listen) { s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; @@ -1102,12 +1067,9 @@ client_request_complete_alice (struct AliceServiceSession *s) e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); - GNUNET_MQ_env_set_options(e, - GNUNET_MQ_PREF_RELIABLE); msg->session_id = s->session_id; msg->public_key = my_pubkey; - GNUNET_MQ_send (s->cadet_mq, - e); + GNUNET_MQ_send (s->cadet_mq, e); } @@ -1120,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_alice_client_message_multipart (void *cls, - const struct ComputationBobCryptodataMultipartMessage *msg) +check_alice_client_message_multipart ( + void *cls, + const struct ComputationBobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -1129,11 +1092,12 @@ check_alice_client_message_multipart (void *cls, msize = ntohs (msg->header.size); contained_count = ntohl (msg->element_count_contained); - if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + - contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || - (0 == contained_count) || - (s->total == s->client_received_element_count) || - (s->total < s->client_received_element_count + contained_count) ) + if ((msize != + (sizeof (struct ComputationBobCryptodataMultipartMessage) + + contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || + (0 == contained_count) || + (s->total == s->client_received_element_count) || + (s->total < s->client_received_element_count + contained_count)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1150,8 +1114,9 @@ check_alice_client_message_multipart (void *cls, * @param msg the actual message */ static void -handle_alice_client_message_multipart (void *cls, - const struct ComputationBobCryptodataMultipartMessage *msg) +handle_alice_client_message_multipart ( + void *cls, + const struct ComputationBobCryptodataMultipartMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -1166,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls, { elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); GNUNET_memcpy (elem, - &elements[i], - sizeof (struct GNUNET_SCALARPRODUCT_Element)); - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, - &elem->key, - elem, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + &elements[i], + sizeof (struct GNUNET_SCALARPRODUCT_Element)); + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( + s->intersected_elements, + &elem->key, + elem, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { GNUNET_break (0); GNUNET_free (elem); @@ -1181,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls, set_elem.data = &elem->key; set_elem.size = sizeof (elem->key); set_elem.element_type = 0; - GNUNET_SET_add_element (s->intersection_set, - &set_elem, - NULL, NULL); + GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); s->used_element_count++; } GNUNET_SERVICE_client_continue (s->client); @@ -1206,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls, */ static int check_alice_client_message (void *cls, - const struct AliceComputationMessage *msg) + const struct AliceComputationMessage *msg) { struct AliceServiceSession *s = cls; uint16_t msize; @@ -1223,10 +1186,10 @@ check_alice_client_message (void *cls, msize = ntohs (msg->header.size); total_count = ntohl (msg->element_count_total); contained_count = ntohl (msg->element_count_contained); - if ( (0 == total_count) || - (0 == contained_count) || - (msize != (sizeof (struct AliceComputationMessage) + - contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) + if ((0 == total_count) || (0 == contained_count) || + (msize != + (sizeof (struct AliceComputationMessage) + + contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -1244,7 +1207,7 @@ check_alice_client_message (void *cls, */ static void handle_alice_client_message (void *cls, - const struct AliceComputationMessage *msg) + const struct AliceComputationMessage *msg) { struct AliceServiceSession *s = cls; uint32_t contained_count; @@ -1261,10 +1224,10 @@ handle_alice_client_message (void *cls, s->client_received_element_count = contained_count; s->session_id = msg->session_key; elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; - s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, - GNUNET_YES); - s->intersection_set = GNUNET_SET_create (cfg, - GNUNET_SET_OPERATION_INTERSECTION); + s->intersected_elements = + GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); + s->intersection_set = + GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); for (uint32_t i = 0; i < contained_count; i++) { @@ -1272,13 +1235,13 @@ handle_alice_client_message (void *cls, continue; elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); GNUNET_memcpy (elem, - &elements[i], - sizeof (struct GNUNET_SCALARPRODUCT_Element)); - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, - &elem->key, - elem, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + &elements[i], + sizeof (struct GNUNET_SCALARPRODUCT_Element)); + if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( + s->intersected_elements, + &elem->key, + elem, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { /* element with same key encountered twice! */ GNUNET_break (0); @@ -1288,9 +1251,7 @@ handle_alice_client_message (void *cls, set_elem.data = &elem->key; set_elem.size = sizeof (elem->key); set_elem.element_type = 0; - GNUNET_SET_add_element (s->intersection_set, - &set_elem, - NULL, NULL); + GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); s->used_element_count++; } GNUNET_SERVICE_client_continue (s->client); @@ -1311,8 +1272,7 @@ handle_alice_client_message (void *cls, static void shutdown_task (void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down, initiating cleanup.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); // FIXME: we have to cut our connections to CADET first! if (NULL != my_cadet) { @@ -1334,8 +1294,8 @@ shutdown_task (void *cls) */ static void * client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct AliceServiceSession *s; @@ -1358,8 +1318,8 @@ client_connect_cb (void *cls, */ static void client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_cls) + struct GNUNET_SERVICE_Client *client, + void *app_cls) { struct AliceServiceSession *s = app_cls; @@ -1390,17 +1350,13 @@ run (void *cls, m1+m2 mod n == (S + a) + (S + b) mod n, if we have more complex operations, this factor needs to be lowered */ my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); - gcry_mpi_set_bit (my_offset, - GNUNET_CRYPTO_PAILLIER_BITS / 3); - GNUNET_CRYPTO_paillier_create (&my_pubkey, - &my_privkey); + gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3); + GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey); my_cadet = GNUNET_CADET_connect (cfg); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); if (NULL == my_cadet) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Connect to CADET failed\n")); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -1410,22 +1366,23 @@ run (void *cls, /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("scalarproduct-alice", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_var_size (alice_client_message, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, - struct AliceComputationMessage, - NULL), - GNUNET_MQ_hd_var_size (alice_client_message_multipart, - GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, - struct ComputationBobCryptodataMultipartMessage, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ( + "scalarproduct-alice", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_var_size (alice_client_message, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, + struct AliceComputationMessage, + NULL), + GNUNET_MQ_hd_var_size ( + alice_client_message_multipart, + GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, + struct ComputationBobCryptodataMultipartMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-scalarproduct_alice.c */ diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index f1d94bef7..5becd7bd9 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -60,7 +60,6 @@ struct LazyCopyRequest * Cookie identifying the request. */ uint32_t cookie; - }; @@ -185,8 +184,7 @@ static uint32_t suggest_id; static struct Operation * get_incoming (uint32_t id) { - for (struct Listener *listener = listener_head; - NULL != listener; + for (struct Listener *listener = listener_head; NULL != listener; listener = listener->next) { for (struct Operation *op = listener->op_head; NULL != op; op = op->next) @@ -212,9 +210,7 @@ incoming_destroy (struct Operation *op) op); if (NULL != (listener = op->listener)) { - GNUNET_CONTAINER_DLL_remove (listener->op_head, - listener->op_tail, - op); + GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); op->listener = NULL; } if (NULL != op->timeout_task) @@ -246,7 +242,6 @@ struct GarbageContext * Largest generation for which an operation is still pending. */ unsigned int max_op_generation; - }; @@ -260,9 +255,7 @@ struct GarbageContext * @return #GNUNET_OK (continue to iterate) */ static int -garbage_collect_cb (void *cls, - const struct GNUNET_HashCode *key, - void *value) +garbage_collect_cb (void *cls, const struct GNUNET_HashCode *key, void *value) { //struct GarbageContext *gc = cls; //struct ElementEntry *ee = value; @@ -298,10 +291,10 @@ collect_generation_garbage (struct Set *set) gc.max_op_generation = 0; for (struct Operation *op = set->ops_head; NULL != op; op = op->next) { - gc.min_op_generation = GNUNET_MIN (gc.min_op_generation, - op->generation_created); - gc.max_op_generation = GNUNET_MAX (gc.max_op_generation, - op->generation_created); + gc.min_op_generation = + GNUNET_MIN (gc.min_op_generation, op->generation_created); + gc.max_op_generation = + GNUNET_MAX (gc.max_op_generation, op->generation_created); } gc.map = set->content->elements; GNUNET_CONTAINER_multihashmap_iterate (set->content->elements, @@ -324,8 +317,7 @@ is_excluded_generation (unsigned int generation, unsigned int excluded_size) { for (unsigned int i = 0; i < excluded_size; i++) - if ( (generation >= excluded[i].start) && - (generation < excluded[i].end) ) + if ((generation >= excluded[i].start) && (generation < excluded[i].end)) return GNUNET_YES; return GNUNET_NO; } @@ -351,9 +343,7 @@ is_element_of_generation (struct ElementEntry *ee, GNUNET_assert (NULL != ee->mutations); if (GNUNET_YES == - is_excluded_generation (query_generation, - excluded, - excluded_size)) + is_excluded_generation (query_generation, excluded, excluded_size)) { GNUNET_break (0); return GNUNET_NO; @@ -376,9 +366,7 @@ is_element_of_generation (struct ElementEntry *ee, } if (GNUNET_YES == - is_excluded_generation (mut->generation, - excluded, - excluded_size)) + is_excluded_generation (mut->generation, excluded, excluded_size)) { /* The generation is excluded (because it belongs to another fork via a lazy copy) and thus mutations aren't considered @@ -387,12 +375,10 @@ is_element_of_generation (struct ElementEntry *ee, } /* This would be an inconsistency in how we manage mutations. */ - if ( (GNUNET_YES == is_present) && - (GNUNET_YES == mut->added) ) + if ((GNUNET_YES == is_present) && (GNUNET_YES == mut->added)) GNUNET_assert (0); /* Likewise. */ - if ( (GNUNET_NO == is_present) && - (GNUNET_NO == mut->added) ) + if ((GNUNET_NO == is_present) && (GNUNET_NO == mut->added)) GNUNET_assert (0); is_present = mut->added; @@ -410,8 +396,7 @@ is_element_of_generation (struct ElementEntry *ee, * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not */ int -_GSS_is_element_of_operation (struct ElementEntry *ee, - struct Operation *op) +_GSS_is_element_of_operation (struct ElementEntry *ee, struct Operation *op) { return is_element_of_generation (ee, op->generation_created, @@ -434,15 +419,12 @@ _GSS_is_element_of_operation (struct ElementEntry *ee, * @param gc #GNUNET_YES to perform garbage collection on the set */ void -_GSS_operation_destroy (struct Operation *op, - int gc) +_GSS_operation_destroy (struct Operation *op, int gc) { struct Set *set = op->set; struct GNUNET_CADET_Channel *channel; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying operation %p\n", - op); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying operation %p\n", op); GNUNET_assert (NULL == op->listener); if (NULL != op->state) { @@ -451,9 +433,7 @@ _GSS_operation_destroy (struct Operation *op, } if (NULL != set) { - GNUNET_CONTAINER_DLL_remove (set->ops_head, - set->ops_tail, - op); + GNUNET_CONTAINER_DLL_remove (set->ops_head, set->ops_tail, op); op->set = NULL; } if (NULL != op->context_msg) @@ -468,8 +448,7 @@ _GSS_operation_destroy (struct Operation *op, op->channel = NULL; GNUNET_CADET_channel_destroy (channel); } - if ( (NULL != set) && - (GNUNET_YES == gc) ) + if ((NULL != set) && (GNUNET_YES == gc)) collect_generation_garbage (set); /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL, * there was a channel end handler that will free 'op' on the call stack. */ @@ -486,8 +465,8 @@ _GSS_operation_destroy (struct Operation *op, */ static void * client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - struct GNUNET_MQ_Handle *mq) + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) { struct ClientState *cs; @@ -537,8 +516,7 @@ client_disconnect_cb (void *cls, struct Listener *listener; struct Set *set; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Client disconnected, cleaning up\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, cleaning up\n"); if (NULL != (set = cs->set)) { struct SetContent *content = set->content; @@ -546,12 +524,10 @@ client_disconnect_cb (void *cls, struct PendingMutation *pm_current; struct LazyCopyRequest *lcr; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying client's set\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's set\n"); /* Destroy pending set operations */ while (NULL != set->ops_head) - _GSS_operation_destroy (set->ops_head, - GNUNET_NO); + _GSS_operation_destroy (set->ops_head, GNUNET_NO); /* Destroy operation-specific state */ GNUNET_assert (NULL != set->state); @@ -618,8 +594,7 @@ client_disconnect_cb (void *cls, if (NULL != (listener = cs->listener)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Destroying client's listener\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying client's listener\n"); GNUNET_CADET_close_port (listener->open_port); listener->open_port = NULL; while (NULL != (op = listener->op_head)) @@ -630,15 +605,12 @@ client_disconnect_cb (void *cls, GNUNET_i2s (&op->peer)); incoming_destroy (op); } - GNUNET_CONTAINER_DLL_remove (listener_head, - listener_tail, - listener); + GNUNET_CONTAINER_DLL_remove (listener_head, listener_tail, listener); GNUNET_free (listener); } GNUNET_free (cs); num_clients--; - if ( (GNUNET_YES == in_shutdown) && - (0 == num_clients) ) + if ((GNUNET_YES == in_shutdown) && (0 == num_clients)) { if (NULL != cadet) { @@ -658,8 +630,7 @@ client_disconnect_cb (void *cls, * #GNUNET_SYSERR to destroy the channel */ static int -check_incoming_msg (void *cls, - const struct OperationRequestMessage *msg) +check_incoming_msg (void *cls, const struct OperationRequestMessage *msg) { struct Operation *op = cls; struct Listener *listener = op->listener; @@ -677,14 +648,15 @@ check_incoming_msg (void *cls, GNUNET_break (0); return GNUNET_SYSERR; } - if (listener->operation != (enum GNUNET_SET_OperationType) ntohl (msg->operation)) + if (listener->operation != + (enum GNUNET_SET_OperationType) ntohl (msg->operation)) { GNUNET_break_op (0); return GNUNET_SYSERR; } nested_context = GNUNET_MQ_extract_nested_mh (msg); - if ( (NULL != nested_context) && - (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) ) + if ((NULL != nested_context) && + (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE)) { GNUNET_break_op (0); return GNUNET_SYSERR; @@ -711,8 +683,7 @@ check_incoming_msg (void *cls, * #GNUNET_SYSERR to destroy the channel */ static void -handle_incoming_msg (void *cls, - const struct OperationRequestMessage *msg) +handle_incoming_msg (void *cls, const struct OperationRequestMessage *msg) { struct Operation *op = cls; struct Listener *listener = op->listener; @@ -727,10 +698,11 @@ handle_incoming_msg (void *cls, if (NULL != nested_context) op->context_msg = GNUNET_copy_message (nested_context); op->remote_element_count = ntohl (msg->element_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received P2P operation request (op %u, port %s) for active listener\n", - (uint32_t) ntohl (msg->operation), - GNUNET_h2s (&op->listener->app_id)); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received P2P operation request (op %u, port %s) for active listener\n", + (uint32_t) ntohl (msg->operation), + GNUNET_h2s (&op->listener->app_id)); GNUNET_assert (0 == op->suggest_id); if (0 == suggest_id) suggest_id++; @@ -741,17 +713,15 @@ handle_incoming_msg (void *cls, env = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, op->context_msg); - GNUNET_MQ_env_set_options(env, - GNUNET_MQ_PREF_RELIABLE); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Suggesting incoming request with accept id %u to listener %p of client %p\n", - op->suggest_id, - listener, - listener->cs); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Suggesting incoming request with accept id %u to listener %p of client %p\n", + op->suggest_id, + listener, + listener->cs); cmsg->accept_id = htonl (op->suggest_id); cmsg->peer_id = op->peer; - GNUNET_MQ_send (listener->cs->mq, - env); + GNUNET_MQ_send (listener->cs->mq, env); /* NOTE: GNUNET_CADET_receive_done() will be called in #handle_client_accept() */ } @@ -764,8 +734,7 @@ handle_incoming_msg (void *cls, * @param msg message specifying the change */ static void -execute_add (struct Set *set, - const struct GNUNET_SET_ElementMessage *msg) +execute_add (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { struct GNUNET_SET_Element el; struct ElementEntry *ee; @@ -775,10 +744,8 @@ execute_add (struct Set *set, el.size = ntohs (msg->header.size) - sizeof (*msg); el.data = &msg[1]; el.element_type = ntohs (msg->element_type); - GNUNET_SET_element_hash (&el, - &hash); - ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, - &hash); + GNUNET_SET_element_hash (&el, &hash); + ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); if (NULL == ee) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -787,9 +754,7 @@ execute_add (struct Set *set, el.size); ee = GNUNET_malloc (el.size + sizeof (*ee)); ee->element.size = el.size; - GNUNET_memcpy (&ee[1], - el.data, - el.size); + GNUNET_memcpy (&ee[1], el.data, el.size); ee->element.data = &ee[1]; ee->element.element_type = el.element_type; ee->remote = GNUNET_NO; @@ -797,10 +762,11 @@ execute_add (struct Set *set, ee->mutations_size = 0; ee->element_hash = hash; GNUNET_break (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (set->content->elements, - &ee->element_hash, - ee, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put ( + set->content->elements, + &ee->element_hash, + ee, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); } else if (GNUNET_YES == is_element_of_generation (ee, @@ -818,16 +784,11 @@ execute_add (struct Set *set, } { - struct MutationEvent mut = { - .generation = set->current_generation, - .added = GNUNET_YES - }; - GNUNET_array_append (ee->mutations, - ee->mutations_size, - mut); + struct MutationEvent mut = {.generation = set->current_generation, + .added = GNUNET_YES}; + GNUNET_array_append (ee->mutations, ee->mutations_size, mut); } - set->vt->add (set->state, - ee); + set->vt->add (set->state, ee); } @@ -838,8 +799,7 @@ execute_add (struct Set *set, * @param msg message specifying the change */ static void -execute_remove (struct Set *set, - const struct GNUNET_SET_ElementMessage *msg) +execute_remove (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { struct GNUNET_SET_Element el; struct ElementEntry *ee; @@ -850,8 +810,7 @@ execute_remove (struct Set *set, el.data = &msg[1]; el.element_type = ntohs (msg->element_type); GNUNET_SET_element_hash (&el, &hash); - ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, - &hash); + ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements, &hash); if (NULL == ee) { /* Client tried to remove non-existing element. */ @@ -860,11 +819,10 @@ execute_remove (struct Set *set, el.size); return; } - if (GNUNET_NO == - is_element_of_generation (ee, - set->current_generation, - set->excluded_generations, - set->excluded_generations_size)) + if (GNUNET_NO == is_element_of_generation (ee, + set->current_generation, + set->excluded_generations, + set->excluded_generations_size)) { /* Client tried to remove element twice */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -874,21 +832,16 @@ execute_remove (struct Set *set, } else { - struct MutationEvent mut = { - .generation = set->current_generation, - .added = GNUNET_NO - }; + struct MutationEvent mut = {.generation = set->current_generation, + .added = GNUNET_NO}; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client removes element of size %u\n", el.size); - GNUNET_array_append (ee->mutations, - ee->mutations_size, - mut); + GNUNET_array_append (ee->mutations, ee->mutations_size, mut); } - set->vt->remove (set->state, - ee); + set->vt->remove (set->state, ee); } @@ -899,19 +852,18 @@ execute_remove (struct Set *set, * @param msg specification of what to change */ static void -execute_mutation (struct Set *set, - const struct GNUNET_SET_ElementMessage *msg) +execute_mutation (struct Set *set, const struct GNUNET_SET_ElementMessage *msg) { switch (ntohs (msg->header.type)) { - case GNUNET_MESSAGE_TYPE_SET_ADD: - execute_add (set, msg); - break; - case GNUNET_MESSAGE_TYPE_SET_REMOVE: - execute_remove (set, msg); - break; - default: - GNUNET_break (0); + case GNUNET_MESSAGE_TYPE_SET_ADD: + execute_add (set, msg); + break; + case GNUNET_MESSAGE_TYPE_SET_REMOVE: + execute_remove (set, msg); + break; + default: + GNUNET_break (0); } } @@ -937,8 +889,7 @@ execute_delayed_mutations (struct Set *set) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing pending mutation on %p.\n", pm->set); - execute_mutation (pm->set, - pm->msg); + execute_mutation (pm->set, pm->msg); GNUNET_free (pm->msg); GNUNET_free (pm); } @@ -967,15 +918,14 @@ send_client_element (struct Set *set) struct GNUNET_SET_IterResponseMessage *msg; GNUNET_assert (NULL != set->iter); - do { + do + { ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter, NULL, (const void **) &ee); if (GNUNET_NO == ret) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Iteration on %p done.\n", - set); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration on %p done.\n", set); ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE); GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter); set->iter = NULL; @@ -983,8 +933,7 @@ send_client_element (struct Set *set) GNUNET_assert (set->content->iterator_count > 0); set->content->iterator_count--; execute_delayed_mutations (set); - GNUNET_MQ_send (set->cs->mq, - ev); + GNUNET_MQ_send (set->cs->mq, ev); return; } GNUNET_assert (NULL != ee); @@ -999,13 +948,10 @@ send_client_element (struct Set *set) ev = GNUNET_MQ_msg_extra (msg, ee->element.size, GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT); - GNUNET_memcpy (&msg[1], - ee->element.data, - ee->element.size); + GNUNET_memcpy (&msg[1], ee->element.data, ee->element.size); msg->element_type = htons (ee->element.element_type); msg->iteration_id = htons (set->iteration_id); - GNUNET_MQ_send (set->cs->mq, - ev); + GNUNET_MQ_send (set->cs->mq, ev); } @@ -1019,8 +965,7 @@ send_client_element (struct Set *set) * @param m message sent by the client */ static void -handle_client_iterate (void *cls, - const struct GNUNET_MessageHeader *m) +handle_client_iterate (void *cls, const struct GNUNET_MessageHeader *m) { struct ClientState *cs = cls; struct Set *set; @@ -1046,7 +991,8 @@ handle_client_iterate (void *cls, GNUNET_CONTAINER_multihashmap_size (set->content->elements)); GNUNET_SERVICE_client_continue (cs->client); set->content->iterator_count++; - set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); + set->iter = + GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements); set->iter_generation = set->current_generation; send_client_element (set); } @@ -1061,8 +1007,7 @@ handle_client_iterate (void *cls, * @param m message sent by the client */ static void -handle_client_create_set (void *cls, - const struct GNUNET_SET_CreateMessage *msg) +handle_client_create_set (void *cls, const struct GNUNET_SET_CreateMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1103,8 +1048,7 @@ handle_client_create_set (void *cls, } set->content = GNUNET_new (struct SetContent); set->content->refcount = 1; - set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, - GNUNET_YES); + set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); set->cs = cs; cs->set = set; GNUNET_SERVICE_client_continue (cs->client); @@ -1156,22 +1100,17 @@ channel_new_cb (void *cls, struct Listener *listener = cls; struct Operation *op; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "New incoming channel\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New incoming channel\n"); op = GNUNET_new (struct Operation); op->listener = listener; op->peer = *source; op->channel = channel; op->mq = GNUNET_CADET_get_mq (op->channel); - op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT32_MAX); - op->timeout_task - = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, - &incoming_timeout_cb, - op); - GNUNET_CONTAINER_DLL_insert (listener->op_head, - listener->op_tail, - op); + op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + op->timeout_task = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT, + &incoming_timeout_cb, + op); + GNUNET_CONTAINER_DLL_insert (listener->op_head, listener->op_tail, op); return op; } @@ -1193,8 +1132,7 @@ channel_new_cb (void *cls, * @param channel connection to the other end (henceforth invalid) */ static void -channel_end_cb (void *channel_ctx, - const struct GNUNET_CADET_Channel *channel) +channel_end_cb (void *channel_ctx, const struct GNUNET_CADET_Channel *channel) { struct Operation *op = channel_ctx; @@ -1213,8 +1151,7 @@ _GSS_operation_destroy2 (struct Operation *op) { struct GNUNET_CADET_Channel *channel; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "channel_end_cb called\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel_end_cb called\n"); if (NULL != (channel = op->channel)) { /* This will free op; called conditionally as this helper function @@ -1230,8 +1167,7 @@ _GSS_operation_destroy2 (struct Operation *op) if (NULL != op->set) op->set->vt->channel_death (op); else - _GSS_operation_destroy (op, - GNUNET_YES); + _GSS_operation_destroy (op, GNUNET_YES); GNUNET_free (op); } @@ -1266,77 +1202,75 @@ channel_window_cb (void *cls, * @param msg message sent by the client */ static void -handle_client_listen (void *cls, - const struct GNUNET_SET_ListenMessage *msg) +handle_client_listen (void *cls, const struct GNUNET_SET_ListenMessage *msg) { struct ClientState *cs = cls; - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_var_size (incoming_msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - struct OperationRequestMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_ibf, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, - struct IBFMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_elements, - GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_offer, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_inquiry, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, - struct InquiryMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_demand, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_over, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_full_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (union_p2p_request_full, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, - struct StrataEstimatorMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, - struct StrataEstimatorMessage, - NULL), - GNUNET_MQ_hd_var_size (union_p2p_full_element, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, - struct IntersectionElementInfoMessage, - NULL), - GNUNET_MQ_hd_var_size (intersection_p2p_bf, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, - struct BFMessage, - NULL), - GNUNET_MQ_hd_fixed_size (intersection_p2p_done, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, - struct IntersectionDoneMessage, - NULL), - GNUNET_MQ_handler_end () - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_var_size (incoming_msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + struct OperationRequestMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_ibf, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, + struct IBFMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_elements, + GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_offer, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_inquiry, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, + struct InquiryMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_demand, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (union_p2p_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (union_p2p_over, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (union_p2p_full_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (union_p2p_request_full, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, + struct StrataEstimatorMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, + struct StrataEstimatorMessage, + NULL), + GNUNET_MQ_hd_var_size (union_p2p_full_element, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, + struct IntersectionElementInfoMessage, + NULL), + GNUNET_MQ_hd_var_size (intersection_p2p_bf, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, + struct BFMessage, + NULL), + GNUNET_MQ_hd_fixed_size (intersection_p2p_done, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, + struct IntersectionDoneMessage, + NULL), + GNUNET_MQ_handler_end ()}; struct Listener *listener; if (NULL != cs->listener) @@ -1351,21 +1285,18 @@ handle_client_listen (void *cls, cs->listener = listener; listener->app_id = msg->app_id; listener->operation = (enum GNUNET_SET_OperationType) ntohl (msg->operation); - GNUNET_CONTAINER_DLL_insert (listener_head, - listener_tail, - listener); + GNUNET_CONTAINER_DLL_insert (listener_head, listener_tail, listener); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New listener created (op %u, port %s)\n", listener->operation, GNUNET_h2s (&listener->app_id)); - listener->open_port - = GNUNET_CADET_open_port (cadet, - &msg->app_id, - &channel_new_cb, - listener, - &channel_window_cb, - &channel_end_cb, - cadet_handlers); + listener->open_port = GNUNET_CADET_open_port (cadet, + &msg->app_id, + &channel_new_cb, + listener, + &channel_window_cb, + &channel_end_cb, + cadet_handlers); GNUNET_SERVICE_client_continue (cs->client); } @@ -1378,8 +1309,7 @@ handle_client_listen (void *cls, * @param msg message sent by the client */ static void -handle_client_reject (void *cls, - const struct GNUNET_SET_RejectMessage *msg) +handle_client_reject (void *cls, const struct GNUNET_SET_RejectMessage *msg) { struct ClientState *cs = cls; struct Operation *op; @@ -1411,8 +1341,7 @@ handle_client_reject (void *cls, * @param msg message sent by the client */ static int -check_client_mutation (void *cls, - const struct GNUNET_SET_ElementMessage *msg) +check_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) { /* NOTE: Technically, we should probably check with the block library whether the element we are given is well-formed */ @@ -1427,8 +1356,7 @@ check_client_mutation (void *cls, * @param msg message sent by the client */ static void -handle_client_mutation (void *cls, - const struct GNUNET_SET_ElementMessage *msg) +handle_client_mutation (void *cls, const struct GNUNET_SET_ElementMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1446,20 +1374,18 @@ handle_client_mutation (void *cls, { struct PendingMutation *pm; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling mutation on set\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling mutation on set\n"); pm = GNUNET_new (struct PendingMutation); - pm->msg = (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); + pm->msg = + (struct GNUNET_SET_ElementMessage *) GNUNET_copy_message (&msg->header); pm->set = set; GNUNET_CONTAINER_DLL_insert_tail (set->content->pending_mutations_head, set->content->pending_mutations_tail, pm); return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Executing mutation on set\n"); - execute_mutation (set, - msg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing mutation on set\n"); + execute_mutation (set, msg); } @@ -1503,8 +1429,7 @@ advance_generation (struct Set *set) * @return #GNUNET_OK if the message is well-formed */ static int -check_client_evaluate (void *cls, - const struct GNUNET_SET_EvaluateMessage *msg) +check_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) { /* FIXME: suboptimal, even if the context below could be NULL, there are malformed messages this does not check for... */ @@ -1521,78 +1446,76 @@ check_client_evaluate (void *cls, * @param msg message sent by the client */ static void -handle_client_evaluate (void *cls, - const struct GNUNET_SET_EvaluateMessage *msg) +handle_client_evaluate (void *cls, const struct GNUNET_SET_EvaluateMessage *msg) { struct ClientState *cs = cls; struct Operation *op = GNUNET_new (struct Operation); - const struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_var_size (incoming_msg, - GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, - struct OperationRequestMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_ibf, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, - struct IBFMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_elements, - GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, - struct GNUNET_SET_ElementMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_offer, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_var_size (union_p2p_inquiry, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, - struct InquiryMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_demand, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_over, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_full_done, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_fixed_size (union_p2p_request_full, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, - struct GNUNET_MessageHeader, - op), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, - struct StrataEstimatorMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, - struct StrataEstimatorMessage, - op), - GNUNET_MQ_hd_var_size (union_p2p_full_element, - GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, - struct GNUNET_SET_ElementMessage, - op), - GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, - struct IntersectionElementInfoMessage, - op), - GNUNET_MQ_hd_var_size (intersection_p2p_bf, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, - struct BFMessage, - op), - GNUNET_MQ_hd_fixed_size (intersection_p2p_done, - GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, - struct IntersectionDoneMessage, - op), - GNUNET_MQ_handler_end () - }; + const struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_var_size (incoming_msg, + GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, + struct OperationRequestMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_ibf, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, + struct IBFMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_elements, + GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, + struct GNUNET_SET_ElementMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_offer, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_var_size (union_p2p_inquiry, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, + struct InquiryMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_demand, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_fixed_size (union_p2p_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_fixed_size (union_p2p_over, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OVER, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_fixed_size (union_p2p_full_done, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_DONE, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_fixed_size (union_p2p_request_full, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_REQUEST_FULL, + struct GNUNET_MessageHeader, + op), + GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, + struct StrataEstimatorMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_strata_estimator, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, + struct StrataEstimatorMessage, + op), + GNUNET_MQ_hd_var_size (union_p2p_full_element, + GNUNET_MESSAGE_TYPE_SET_UNION_P2P_FULL_ELEMENT, + struct GNUNET_SET_ElementMessage, + op), + GNUNET_MQ_hd_fixed_size (intersection_p2p_element_info, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, + struct IntersectionElementInfoMessage, + op), + GNUNET_MQ_hd_var_size (intersection_p2p_bf, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, + struct BFMessage, + op), + GNUNET_MQ_hd_fixed_size (intersection_p2p_done, + GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, + struct IntersectionDoneMessage, + op), + GNUNET_MQ_handler_end ()}; struct Set *set; const struct GNUNET_MessageHeader *context; @@ -1603,8 +1526,7 @@ handle_client_evaluate (void *cls, GNUNET_SERVICE_client_drop (cs->client); return; } - op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, - UINT32_MAX); + op->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); op->peer = msg->target_peer; op->result_mode = ntohl (msg->result_mode); op->client_request_id = ntohl (msg->request_id); @@ -1619,9 +1541,7 @@ handle_client_evaluate (void *cls, op->set = set; op->generation_created = set->current_generation; advance_generation (set); - GNUNET_CONTAINER_DLL_insert (set->ops_head, - set->ops_tail, - op); + GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating new CADET channel to port %s for set operation type %u\n", GNUNET_h2s (&msg->app_id), @@ -1634,8 +1554,7 @@ handle_client_evaluate (void *cls, &channel_end_cb, cadet_handlers); op->mq = GNUNET_CADET_get_mq (op->channel); - op->state = set->vt->evaluate (op, - context); + op->state = set->vt->evaluate (op, context); if (NULL == op->state) { GNUNET_break (0); @@ -1655,8 +1574,7 @@ handle_client_evaluate (void *cls, * @param ack the message */ static void -handle_client_iter_ack (void *cls, - const struct GNUNET_SET_IterAckMessage *ack) +handle_client_iter_ack (void *cls, const struct GNUNET_SET_IterAckMessage *ack) { struct ClientState *cs = cls; struct Set *set; @@ -1718,14 +1636,10 @@ handle_client_copy_lazy_prepare (void *cls, cr = GNUNET_new (struct LazyCopyRequest); cr->cookie = ++lazy_copy_cookie; cr->source_set = set; - GNUNET_CONTAINER_DLL_insert (lazy_copy_head, - lazy_copy_tail, - cr); - ev = GNUNET_MQ_msg (resp_msg, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); + GNUNET_CONTAINER_DLL_insert (lazy_copy_head, lazy_copy_tail, cr); + ev = GNUNET_MQ_msg (resp_msg, GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE); resp_msg->cookie = cr->cookie; - GNUNET_MQ_send (set->cs->mq, - ev); + GNUNET_MQ_send (set->cs->mq, ev); GNUNET_SERVICE_client_continue (cs->client); } @@ -1737,8 +1651,9 @@ handle_client_copy_lazy_prepare (void *cls, * @param msg the message */ static void -handle_client_copy_lazy_connect (void *cls, - const struct GNUNET_SET_CopyLazyConnectMessage *msg) +handle_client_copy_lazy_connect ( + void *cls, + const struct GNUNET_SET_CopyLazyConnectMessage *msg) { struct ClientState *cs = cls; struct LazyCopyRequest *cr; @@ -1768,9 +1683,7 @@ handle_client_copy_lazy_connect (void *cls, GNUNET_SERVICE_client_drop (cs->client); return; } - GNUNET_CONTAINER_DLL_remove (lazy_copy_head, - lazy_copy_tail, - cr); + GNUNET_CONTAINER_DLL_remove (lazy_copy_head, lazy_copy_tail, cr); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p requested use of lazy copy\n", cs); @@ -1805,9 +1718,10 @@ handle_client_copy_lazy_connect (void *cls, set->current_generation = cr->source_set->current_generation; set->excluded_generations_size = cr->source_set->excluded_generations_size; - set->excluded_generations - = GNUNET_memdup (cr->source_set->excluded_generations, - set->excluded_generations_size * sizeof (struct GenerationRange)); + set->excluded_generations = + GNUNET_memdup (cr->source_set->excluded_generations, + set->excluded_generations_size * + sizeof (struct GenerationRange)); /* Advance the generation of the new set, so that mutations to the of the cloned set and the source set are independent. */ @@ -1826,8 +1740,7 @@ handle_client_copy_lazy_connect (void *cls, * @param msg the message */ static void -handle_client_cancel (void *cls, - const struct GNUNET_SET_CancelMessage *msg) +handle_client_cancel (void *cls, const struct GNUNET_SET_CancelMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1866,8 +1779,7 @@ handle_client_cancel (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client requested cancel for op %u\n", (uint32_t) ntohl (msg->request_id)); - _GSS_operation_destroy (op, - GNUNET_YES); + _GSS_operation_destroy (op, GNUNET_YES); } GNUNET_SERVICE_client_continue (cs->client); } @@ -1882,8 +1794,7 @@ handle_client_cancel (void *cls, * @param msg the message */ static void -handle_client_accept (void *cls, - const struct GNUNET_SET_AcceptMessage *msg) +handle_client_accept (void *cls, const struct GNUNET_SET_AcceptMessage *msg) { struct ClientState *cs = cls; struct Set *set; @@ -1904,17 +1815,16 @@ handle_client_accept (void *cls, { /* It is not an error if the set op does not exist -- it may * have been destroyed when the partner peer disconnected. */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Client %p accepted request %u of listener %p that is no longer active\n", - cs, - ntohl (msg->accept_reject_id), - cs->listener); - ev = GNUNET_MQ_msg (result_message, - GNUNET_MESSAGE_TYPE_SET_RESULT); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + "Client %p accepted request %u of listener %p that is no longer active\n", + cs, + ntohl (msg->accept_reject_id), + cs->listener); + ev = GNUNET_MQ_msg (result_message, GNUNET_MESSAGE_TYPE_SET_RESULT); result_message->request_id = msg->request_id; result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE); - GNUNET_MQ_send (set->cs->mq, - ev); + GNUNET_MQ_send (set->cs->mq, ev); GNUNET_SERVICE_client_continue (cs->client); return; } @@ -1923,13 +1833,9 @@ handle_client_accept (void *cls, (uint32_t) ntohl (msg->accept_reject_id)); listener = op->listener; op->listener = NULL; - GNUNET_CONTAINER_DLL_remove (listener->op_head, - listener->op_tail, - op); + GNUNET_CONTAINER_DLL_remove (listener->op_head, listener->op_tail, op); op->set = set; - GNUNET_CONTAINER_DLL_insert (set->ops_head, - set->ops_tail, - op); + GNUNET_CONTAINER_DLL_insert (set->ops_head, set->ops_tail, op); op->client_request_id = ntohl (msg->request_id); op->result_mode = ntohl (msg->result_mode); op->byzantine = msg->byzantine; @@ -1975,10 +1881,8 @@ shutdown_task (void *cls) cadet = NULL; } } - GNUNET_STATISTICS_destroy (_GSS_statistics, - GNUNET_YES); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "handled shutdown request\n"); + GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n"); } @@ -1998,15 +1902,13 @@ run (void *cls, /* FIXME: need to modify SERVICE (!) API to allow us to run a shutdown task *after* clients were forcefully disconnected! */ - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); - _GSS_statistics = GNUNET_STATISTICS_create ("set", - cfg); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg); cadet = GNUNET_CADET_connect (cfg); if (NULL == cadet) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not connect to CADET service\n")); + _ ("Could not connect to CADET service\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -2016,62 +1918,62 @@ run (void *cls, /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("set", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (client_accept, - GNUNET_MESSAGE_TYPE_SET_ACCEPT, - struct GNUNET_SET_AcceptMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_iter_ack, - GNUNET_MESSAGE_TYPE_SET_ITER_ACK, - struct GNUNET_SET_IterAckMessage, - NULL), - GNUNET_MQ_hd_var_size (client_mutation, - GNUNET_MESSAGE_TYPE_SET_ADD, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_create_set, - GNUNET_MESSAGE_TYPE_SET_CREATE, - struct GNUNET_SET_CreateMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_iterate, - GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (client_evaluate, - GNUNET_MESSAGE_TYPE_SET_EVALUATE, - struct GNUNET_SET_EvaluateMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_listen, - GNUNET_MESSAGE_TYPE_SET_LISTEN, - struct GNUNET_SET_ListenMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_reject, - GNUNET_MESSAGE_TYPE_SET_REJECT, - struct GNUNET_SET_RejectMessage, - NULL), - GNUNET_MQ_hd_var_size (client_mutation, - GNUNET_MESSAGE_TYPE_SET_REMOVE, - struct GNUNET_SET_ElementMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_cancel, - GNUNET_MESSAGE_TYPE_SET_CANCEL, - struct GNUNET_SET_CancelMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, - GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, - struct GNUNET_SET_CopyLazyConnectMessage, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ( + "set", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (client_accept, + GNUNET_MESSAGE_TYPE_SET_ACCEPT, + struct GNUNET_SET_AcceptMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_iter_ack, + GNUNET_MESSAGE_TYPE_SET_ITER_ACK, + struct GNUNET_SET_IterAckMessage, + NULL), + GNUNET_MQ_hd_var_size (client_mutation, + GNUNET_MESSAGE_TYPE_SET_ADD, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_create_set, + GNUNET_MESSAGE_TYPE_SET_CREATE, + struct GNUNET_SET_CreateMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_iterate, + GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size (client_evaluate, + GNUNET_MESSAGE_TYPE_SET_EVALUATE, + struct GNUNET_SET_EvaluateMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_listen, + GNUNET_MESSAGE_TYPE_SET_LISTEN, + struct GNUNET_SET_ListenMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_reject, + GNUNET_MESSAGE_TYPE_SET_REJECT, + struct GNUNET_SET_RejectMessage, + NULL), + GNUNET_MQ_hd_var_size (client_mutation, + GNUNET_MESSAGE_TYPE_SET_REMOVE, + struct GNUNET_SET_ElementMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_cancel, + GNUNET_MESSAGE_TYPE_SET_CANCEL, + struct GNUNET_SET_CancelMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_copy_lazy_prepare, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_fixed_size (client_copy_lazy_connect, + GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT, + struct GNUNET_SET_CopyLazyConnectMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-set.c */ diff --git a/src/util/mq.c b/src/util/mq.c index c9cfad2bd..03b0f3a2a 100644 --- a/src/util/mq.c +++ b/src/util/mq.c @@ -1137,6 +1137,28 @@ GNUNET_MQ_destroy_notify_cancel ( } +/** + * Insert @a env into the envelope DLL starting at @a env_head + * Note that @a env must not be in any MQ while this function + * is used with DLLs defined outside of the MQ module. This + * is just in case some application needs to also manage a + * FIFO of envelopes independent of MQ itself and wants to + * re-use the pointers internal to @a env. Use with caution. + * + * @param[in|out] env_head of envelope DLL + * @param[in|out] env_tail tail of envelope DLL + * @param[in|out] env element to insert at the tail + */ +void +GNUNET_MQ_dll_insert_head (struct GNUNET_MQ_Envelope **env_head, + struct GNUNET_MQ_Envelope **env_tail, + struct GNUNET_MQ_Envelope *env) +{ + + GNUNET_CONTAINER_DLL_insert (*env_head, *env_tail, env); +} + + /** * Insert @a env into the envelope DLL starting at @a env_head * Note that @a env must not be in any MQ while this function diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 7bd26798e..e2d8a8e50 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -87,7 +87,6 @@ struct DestinationChannel * Destination port this channel state is used for. */ uint16_t destination_port; - }; @@ -158,21 +157,20 @@ struct DestinationEntry */ union { - /** + /** * Address if af is AF_INET. */ - struct in_addr v4; + struct in_addr v4; - /** + /** * Address if af is AF_INET6. */ - struct in6_addr v6; + struct in6_addr v6; } ip; } exit_destination; } details; - }; @@ -309,7 +307,6 @@ struct ChannelState * Destination port used by the sender on our end; 0 for uninitialized. */ uint16_t destination_port; - }; @@ -394,20 +391,16 @@ static unsigned long long max_channel_mappings; */ static void get_destination_key_from_ip (int af, - const void *address, - struct GNUNET_HashCode *key) + const void *address, + struct GNUNET_HashCode *key) { switch (af) { case AF_INET: - GNUNET_CRYPTO_hash (address, - sizeof (struct in_addr), - key); + GNUNET_CRYPTO_hash (address, sizeof (struct in_addr), key); break; case AF_INET6: - GNUNET_CRYPTO_hash (address, - sizeof (struct in6_addr), - key); + GNUNET_CRYPTO_hash (address, sizeof (struct in6_addr), key); break; default: GNUNET_assert (0); @@ -442,7 +435,7 @@ get_channel_key_from_ips (int af, memset (key, 0, sizeof (struct GNUNET_HashCode)); /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, so we put the ports in there (and hope for few collisions) */ - off = (char*) key; + off = (char *) key; GNUNET_memcpy (off, &source_port, sizeof (uint16_t)); off += sizeof (uint16_t); GNUNET_memcpy (off, &destination_port, sizeof (uint16_t)); @@ -480,9 +473,9 @@ get_channel_key_from_ips (int af, */ static void send_client_reply (struct GNUNET_SERVICE_Client *client, - uint64_t request_id, - int result_af, - const void *addr) + uint64_t request_id, + int result_af, + const void *addr) { struct GNUNET_MQ_Envelope *env; struct RedirectToIpResponseMessage *res; @@ -503,16 +496,11 @@ send_client_reply (struct GNUNET_SERVICE_Client *client, GNUNET_assert (0); return; } - env = GNUNET_MQ_msg_extra (res, - rlen, - GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP); + env = GNUNET_MQ_msg_extra (res, rlen, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP); res->result_af = htonl (result_af); res->request_id = request_id; - GNUNET_memcpy (&res[1], - addr, - rlen); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), - env); + GNUNET_memcpy (&res[1], addr, rlen); + GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); } @@ -528,8 +516,7 @@ free_channel_state (struct ChannelState *ts) struct ChannelMessageQueueEntry *tnq; struct GNUNET_CADET_Channel *channel; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up channel state\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up channel state\n"); if (NULL != (channel = ts->channel)) { ts->channel = NULL; @@ -537,13 +524,12 @@ free_channel_state (struct ChannelState *ts) return; } GNUNET_STATISTICS_update (stats, - gettext_noop ("# Active channels"), - -1, GNUNET_NO); + gettext_noop ("# Active channels"), + -1, + GNUNET_NO); while (NULL != (tnq = ts->tmq_head)) { - GNUNET_CONTAINER_DLL_remove (ts->tmq_head, - ts->tmq_tail, - tnq); + GNUNET_CONTAINER_DLL_remove (ts->tmq_head, ts->tmq_tail, tnq); ts->tmq_length--; GNUNET_free (tnq); } @@ -559,16 +545,15 @@ free_channel_state (struct ChannelState *ts) GNUNET_CONTAINER_heap_remove_node (ts->heap_node); ts->heap_node = NULL; get_channel_key_from_ips (ts->af, - ts->protocol, - &ts->source_ip, - ts->source_port, - &ts->destination_ip, - ts->destination_port, - &key); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (channel_map, - &key, - ts)); + ts->protocol, + &ts->source_ip, + ts->source_port, + &ts->destination_ip, + ts->destination_port, + &key); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (channel_map, &key, ts)); } GNUNET_free (ts); } @@ -582,25 +567,25 @@ free_channel_state (struct ChannelState *ts) * @param env message to queue */ static void -send_to_channel (struct ChannelState *ts, - struct GNUNET_MQ_Envelope *env) +send_to_channel (struct ChannelState *ts, struct GNUNET_MQ_Envelope *env) { struct GNUNET_MQ_Handle *mq; GNUNET_assert (NULL != ts->channel); mq = GNUNET_CADET_get_mq (ts->channel); - GNUNET_MQ_env_set_options(env, - GNUNET_MQ_PREF_DEFAULT); - GNUNET_MQ_send (mq, - env); + GNUNET_MQ_env_set_options (env, + GNUNET_MQ_PRIO_BEST_EFFORT | + GNUNET_MQ_PREF_OUT_OF_ORDER); + GNUNET_MQ_send (mq, env); if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE) { env = GNUNET_MQ_unsent_head (mq); GNUNET_assert (NULL != env); GNUNET_STATISTICS_update (stats, - gettext_noop ("# Messages dropped in cadet queue (overflow)"), - 1, - GNUNET_NO); + gettext_noop ( + "# Messages dropped in cadet queue (overflow)"), + 1, + GNUNET_NO); GNUNET_MQ_discard (env); } } @@ -623,7 +608,8 @@ print_channel_destination (const struct DestinationEntry *de) sizeof (dest), "HS: %s-%s", GNUNET_i2s (&de->details.service_destination.target), - GNUNET_h2s (&de->details.service_destination.service_descriptor)); + GNUNET_h2s ( + &de->details.service_destination.service_descriptor)); } else { @@ -644,14 +630,14 @@ print_channel_destination (const struct DestinationEntry *de) * @param channel connection to the other end (henceforth invalid) */ static void -channel_cleaner (void *cls, - const struct GNUNET_CADET_Channel *channel) +channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel) { struct ChannelState *ts = cls; - ts->channel = NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ + ts->channel = + NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "CADET notified us about death of channel to `%s'\n", + "CADET notified us about death of channel to `%s'\n", print_channel_destination (&ts->destination)); free_channel_state (ts); } @@ -668,14 +654,14 @@ channel_cleaner (void *cls, */ static void make_up_icmpv4_payload (struct ChannelState *ts, - struct GNUNET_TUN_IPv4Header *ipp, - struct GNUNET_TUN_UdpHeader *udp) + struct GNUNET_TUN_IPv4Header *ipp, + struct GNUNET_TUN_UdpHeader *udp) { GNUNET_TUN_initialize_ipv4_header (ipp, - ts->protocol, - sizeof (struct GNUNET_TUN_TcpHeader), - &ts->source_ip.v4, - &ts->destination_ip.v4); + ts->protocol, + sizeof (struct GNUNET_TUN_TcpHeader), + &ts->source_ip.v4, + &ts->destination_ip.v4); udp->source_port = htons (ts->source_port); udp->destination_port = htons (ts->destination_port); udp->len = htons (0); @@ -694,14 +680,14 @@ make_up_icmpv4_payload (struct ChannelState *ts, */ static void make_up_icmpv6_payload (struct ChannelState *ts, - struct GNUNET_TUN_IPv6Header *ipp, - struct GNUNET_TUN_UdpHeader *udp) + struct GNUNET_TUN_IPv6Header *ipp, + struct GNUNET_TUN_UdpHeader *udp) { GNUNET_TUN_initialize_ipv6_header (ipp, - ts->protocol, - sizeof (struct GNUNET_TUN_TcpHeader), - &ts->source_ip.v6, - &ts->destination_ip.v6); + ts->protocol, + sizeof (struct GNUNET_TUN_TcpHeader), + &ts->source_ip.v6, + &ts->destination_ip.v6); udp->source_port = htons (ts->source_port); udp->destination_port = htons (ts->destination_port); udp->len = htons (0); @@ -718,8 +704,7 @@ make_up_icmpv6_payload (struct ChannelState *ts, * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_icmp_back (void *cls, - const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) +check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) { struct ChannelState *ts = cls; @@ -745,309 +730,323 @@ check_icmp_back (void *cls, * @param message the actual message */ static void -handle_icmp_back (void *cls, - const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) +handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) { struct ChannelState *ts = cls; size_t mlen; GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMP packets received from cadet"), - 1, + gettext_noop ("# ICMP packets received from cadet"), + 1, GNUNET_NO); - mlen = ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage); + mlen = + ntohs (i2v->header.size) - sizeof (struct GNUNET_EXIT_IcmpToVPNMessage); { char sbuf[INET6_ADDRSTRLEN]; char dbuf[INET6_ADDRSTRLEN]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", - (unsigned int) mlen, - inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), - inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf))); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", + (unsigned int) mlen, + inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), + inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf))); } switch (ts->af) { - case AF_INET: + case AF_INET: { + size_t size = sizeof (struct GNUNET_TUN_IPv4Header) + + sizeof (struct GNUNET_TUN_IcmpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv4Header) - + sizeof (struct GNUNET_TUN_IcmpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - /* reserve some extra space in case we have an ICMP type here where + /* reserve some extra space in case we have an ICMP type here where we will need to make up the payload ourselves */ - char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; - struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV4); - GNUNET_TUN_initialize_ipv4_header (ipv4, - IPPROTO_ICMP, - sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, - &ts->destination_ip.v4, - &ts->source_ip.v4); - *icmp = i2v->icmp_header; - GNUNET_memcpy (&icmp[1], - &i2v[1], - mlen); - /* For some ICMP types, we need to adjust (make up) the payload here. + char buf[size + sizeof (struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv4Header *ipv4 = + (struct GNUNET_TUN_IPv4Header *) &tun[1]; + struct GNUNET_TUN_IcmpHeader *icmp = + (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV4); + GNUNET_TUN_initialize_ipv4_header (ipv4, + IPPROTO_ICMP, + sizeof (struct GNUNET_TUN_IcmpHeader) + + mlen, + &ts->destination_ip.v4, + &ts->source_ip.v4); + *icmp = i2v->icmp_header; + GNUNET_memcpy (&icmp[1], &i2v[1], mlen); + /* For some ICMP types, we need to adjust (make up) the payload here. Also, depending on the AF used on the other side, we have to do ICMP PT (translate ICMP types) */ - switch (ntohl (i2v->af)) - { - case AF_INET: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: - case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: - break; - case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: - case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: - case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: - { - struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv4_payload (ts, ipp, udp); - } - break; - default: - GNUNET_break_op (0); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end AF_INET */ - break; - case AF_INET6: - /* ICMP PT 6-to-4 and possibly making up payloads */ - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: - icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; - { - struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv4_payload (ts, ipp, udp); - } - break; - case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: - icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; - { - struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv4_payload (ts, ipp, udp); - } - break; - case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: - case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), - 1, GNUNET_NO); - return; - case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: - icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; - break; - case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: - icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; - break; - default: - GNUNET_break_op (0); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end AF_INET6 */ - break; - default: - GNUNET_break_op (0); - return; - } - msg->size = htons (size); - GNUNET_TUN_calculate_icmp_checksum (icmp, - &i2v[1], - mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); + switch (ntohl (i2v->af)) + { + case AF_INET: + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: + case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: + break; + case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: + case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: + case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: { + struct GNUNET_TUN_IPv4Header *ipp = + (struct GNUNET_TUN_IPv4Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv4_payload (ts, ipp, udp); + } + break; + default: + GNUNET_break_op (0); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end AF_INET */ + break; + case AF_INET6: + /* ICMP PT 6-to-4 and possibly making up payloads */ + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: + icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; + { + struct GNUNET_TUN_IPv4Header *ipp = + (struct GNUNET_TUN_IPv4Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv4_payload (ts, ipp, udp); + } + break; + case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: + icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; + { + struct GNUNET_TUN_IPv4Header *ipp = + (struct GNUNET_TUN_IPv4Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv4Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv4_payload (ts, ipp, udp); + } + break; + case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: + case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), + 1, + GNUNET_NO); + return; + case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: + icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; + break; + case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: + icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; + break; + default: + GNUNET_break_op (0); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end AF_INET6 */ + break; + default: + GNUNET_break_op (0); + return; } + msg->size = htons (size); + GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; - case AF_INET6: + } + break; + case AF_INET6: { + size_t size = sizeof (struct GNUNET_TUN_IPv6Header) + + sizeof (struct GNUNET_TUN_IcmpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv6Header) - + sizeof (struct GNUNET_TUN_IcmpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; - struct GNUNET_TUN_IcmpHeader *icmp = (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV6); - GNUNET_TUN_initialize_ipv6_header (ipv6, - IPPROTO_ICMPV6, - sizeof (struct GNUNET_TUN_IcmpHeader) + mlen, - &ts->destination_ip.v6, - &ts->source_ip.v6); - *icmp = i2v->icmp_header; - GNUNET_memcpy (&icmp[1], - &i2v[1], - mlen); - - /* For some ICMP types, we need to adjust (make up) the payload here. + char buf[size + sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv6Header *ipv6 = + (struct GNUNET_TUN_IPv6Header *) &tun[1]; + struct GNUNET_TUN_IcmpHeader *icmp = + (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV6); + GNUNET_TUN_initialize_ipv6_header (ipv6, + IPPROTO_ICMPV6, + sizeof (struct GNUNET_TUN_IcmpHeader) + + mlen, + &ts->destination_ip.v6, + &ts->source_ip.v6); + *icmp = i2v->icmp_header; + GNUNET_memcpy (&icmp[1], &i2v[1], mlen); + + /* For some ICMP types, we need to adjust (make up) the payload here. Also, depending on the AF used on the other side, we have to do ICMP PT (translate ICMP types) */ - switch (ntohl (i2v->af)) - { - case AF_INET: - /* ICMP PT 4-to-6 and possibly making up payloads */ - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: - icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; - break; - case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: - icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; - break; - case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: - icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; - { - struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv6_payload (ts, ipp, udp); - } - break; - case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: - icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; - { - struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv6_payload (ts, ipp, udp); - } - break; - case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), - 1, GNUNET_NO); - return; - default: - GNUNET_break_op (0); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end AF_INET */ - break; - case AF_INET6: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: - case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: - case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: - case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: - { - struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; - - if (mlen != 0) - { - /* sender did not strip ICMP payload? */ - GNUNET_break_op (0); - return; - } - size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; - GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); - make_up_icmpv6_payload (ts, ipp, udp); - } - break; - case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: - break; - default: - GNUNET_break_op (0); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end AF_INET6 */ - break; - default: - GNUNET_break_op (0); - return; - } - msg->size = htons (size); - GNUNET_TUN_calculate_icmp_checksum (icmp, - &i2v[1], mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); + switch (ntohl (i2v->af)) + { + case AF_INET: + /* ICMP PT 4-to-6 and possibly making up payloads */ + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: + icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; + break; + case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: + icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; + break; + case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: + icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; + { + struct GNUNET_TUN_IPv6Header *ipp = + (struct GNUNET_TUN_IPv6Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv6_payload (ts, ipp, udp); + } + break; + case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: + icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; + { + struct GNUNET_TUN_IPv6Header *ipp = + (struct GNUNET_TUN_IPv6Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv6_payload (ts, ipp, udp); + } + break; + case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), + 1, + GNUNET_NO); + return; + default: + GNUNET_break_op (0); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end AF_INET */ + break; + case AF_INET6: + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: + case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: + case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: + case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: { + struct GNUNET_TUN_IPv6Header *ipp = + (struct GNUNET_TUN_IPv6Header *) &icmp[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipp[1]; + + if (mlen != 0) + { + /* sender did not strip ICMP payload? */ + GNUNET_break_op (0); + return; + } + size += sizeof (struct GNUNET_TUN_IPv6Header) + 8; + GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader)); + make_up_icmpv6_payload (ts, ipp, udp); + } + break; + case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: + break; + default: + GNUNET_break_op (0); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end AF_INET6 */ + break; + default: + GNUNET_break_op (0); + return; } + msg->size = htons (size); + GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; + } + break; default: GNUNET_assert (0); } GNUNET_CONTAINER_heap_update_cost (ts->heap_node, - GNUNET_TIME_absolute_get ().abs_value_us); + GNUNET_TIME_absolute_get ().abs_value_us); GNUNET_CADET_receive_done (ts->channel); } @@ -1061,8 +1060,7 @@ handle_icmp_back (void *cls, * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_udp_back (void *cls, - const struct GNUNET_EXIT_UdpReplyMessage *reply) +check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) { struct ChannelState *ts = cls; @@ -1088,125 +1086,115 @@ check_udp_back (void *cls, * @param reply the actual message */ static void -handle_udp_back (void *cls, - const struct GNUNET_EXIT_UdpReplyMessage *reply) +handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) { struct ChannelState *ts = cls; size_t mlen; GNUNET_STATISTICS_update (stats, - gettext_noop ("# UDP packets received from cadet"), - 1, + gettext_noop ("# UDP packets received from cadet"), + 1, GNUNET_NO); - mlen = ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage); + mlen = + ntohs (reply->header.size) - sizeof (struct GNUNET_EXIT_UdpReplyMessage); { char sbuf[INET6_ADDRSTRLEN]; char dbuf[INET6_ADDRSTRLEN]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", - (unsigned int) mlen, - inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), - ts->destination_port, - inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), - ts->source_port); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", + (unsigned int) mlen, + inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), + ts->destination_port, + inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), + ts->source_port); } switch (ts->af) { - case AF_INET: + case AF_INET: { + size_t size = sizeof (struct GNUNET_TUN_IPv4Header) + + sizeof (struct GNUNET_TUN_UdpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv4Header) - + sizeof (struct GNUNET_TUN_UdpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - char buf[size] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - msg->size = htons (size); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV4); - GNUNET_TUN_initialize_ipv4_header (ipv4, - IPPROTO_UDP, - sizeof (struct GNUNET_TUN_UdpHeader) + mlen, - &ts->destination_ip.v4, - &ts->source_ip.v4); - if (0 == ntohs (reply->source_port)) - udp->source_port = htons (ts->destination_port); - else - udp->source_port = reply->source_port; - if (0 == ntohs (reply->destination_port)) - udp->destination_port = htons (ts->source_port); - else - udp->destination_port = reply->destination_port; - udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); - GNUNET_TUN_calculate_udp4_checksum (ipv4, - udp, - &reply[1], - mlen); - GNUNET_memcpy (&udp[1], - &reply[1], - mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); - } + char buf[size] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv4Header *ipv4 = + (struct GNUNET_TUN_IPv4Header *) &tun[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + msg->size = htons (size); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV4); + GNUNET_TUN_initialize_ipv4_header (ipv4, + IPPROTO_UDP, + sizeof (struct GNUNET_TUN_UdpHeader) + + mlen, + &ts->destination_ip.v4, + &ts->source_ip.v4); + if (0 == ntohs (reply->source_port)) + udp->source_port = htons (ts->destination_port); + else + udp->source_port = reply->source_port; + if (0 == ntohs (reply->destination_port)) + udp->destination_port = htons (ts->source_port); + else + udp->destination_port = reply->destination_port; + udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); + GNUNET_TUN_calculate_udp4_checksum (ipv4, udp, &reply[1], mlen); + GNUNET_memcpy (&udp[1], &reply[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; - case AF_INET6: + } + break; + case AF_INET6: { + size_t size = sizeof (struct GNUNET_TUN_IPv6Header) + + sizeof (struct GNUNET_TUN_UdpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv6Header) - + sizeof (struct GNUNET_TUN_UdpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - char buf[size] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; - struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - msg->size = htons (size); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV6); - GNUNET_TUN_initialize_ipv6_header (ipv6, - IPPROTO_UDP, - sizeof (struct GNUNET_TUN_UdpHeader) + mlen, - &ts->destination_ip.v6, - &ts->source_ip.v6); - if (0 == ntohs (reply->source_port)) - udp->source_port = htons (ts->destination_port); - else - udp->source_port = reply->source_port; - if (0 == ntohs (reply->destination_port)) - udp->destination_port = htons (ts->source_port); - else - udp->destination_port = reply->destination_port; - udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); - GNUNET_TUN_calculate_udp6_checksum (ipv6, - udp, - &reply[1], mlen); - GNUNET_memcpy (&udp[1], - &reply[1], - mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); - } + char buf[size] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv6Header *ipv6 = + (struct GNUNET_TUN_IPv6Header *) &tun[1]; + struct GNUNET_TUN_UdpHeader *udp = + (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + msg->size = htons (size); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV6); + GNUNET_TUN_initialize_ipv6_header (ipv6, + IPPROTO_UDP, + sizeof (struct GNUNET_TUN_UdpHeader) + + mlen, + &ts->destination_ip.v6, + &ts->source_ip.v6); + if (0 == ntohs (reply->source_port)) + udp->source_port = htons (ts->destination_port); + else + udp->source_port = reply->source_port; + if (0 == ntohs (reply->destination_port)) + udp->destination_port = htons (ts->source_port); + else + udp->destination_port = reply->destination_port; + udp->len = htons (mlen + sizeof (struct GNUNET_TUN_UdpHeader)); + GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen); + GNUNET_memcpy (&udp[1], &reply[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; + } + break; default: GNUNET_assert (0); } GNUNET_CONTAINER_heap_update_cost (ts->heap_node, - GNUNET_TIME_absolute_get ().abs_value_us); + GNUNET_TIME_absolute_get ().abs_value_us); GNUNET_CADET_receive_done (ts->channel); } @@ -1220,8 +1208,7 @@ handle_udp_back (void *cls, * #GNUNET_SYSERR to close it (signal serious error) */ static int -check_tcp_back (void *cls, - const struct GNUNET_EXIT_TcpDataMessage *data) +check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) { struct ChannelState *ts = cls; @@ -1247,112 +1234,100 @@ check_tcp_back (void *cls, * @param data the actual message */ static void -handle_tcp_back (void *cls, - const struct GNUNET_EXIT_TcpDataMessage *data) +handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) { struct ChannelState *ts = cls; size_t mlen; GNUNET_STATISTICS_update (stats, - gettext_noop ("# TCP packets received from cadet"), - 1, + gettext_noop ("# TCP packets received from cadet"), + 1, GNUNET_NO); mlen = ntohs (data->header.size) - sizeof (struct GNUNET_EXIT_TcpDataMessage); { char sbuf[INET6_ADDRSTRLEN]; char dbuf[INET6_ADDRSTRLEN]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", - (unsigned int) mlen, - inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), - ts->destination_port, - inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), - ts->source_port); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", + (unsigned int) mlen, + inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)), + ts->destination_port, + inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)), + ts->source_port); } switch (ts->af) { - case AF_INET: + case AF_INET: { + size_t size = sizeof (struct GNUNET_TUN_IPv4Header) + + sizeof (struct GNUNET_TUN_TcpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv4Header) - + sizeof (struct GNUNET_TUN_TcpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - char buf[size] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv4Header *ipv4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; - struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - msg->size = htons (size); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV4); - GNUNET_TUN_initialize_ipv4_header (ipv4, - IPPROTO_TCP, - sizeof (struct GNUNET_TUN_TcpHeader) + mlen, - &ts->destination_ip.v4, - &ts->source_ip.v4); - *tcp = data->tcp_header; - tcp->source_port = htons (ts->destination_port); - tcp->destination_port = htons (ts->source_port); - GNUNET_TUN_calculate_tcp4_checksum (ipv4, - tcp, - &data[1], - mlen); - GNUNET_memcpy (&tcp[1], - &data[1], - mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); - } + char buf[size] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv4Header *ipv4 = + (struct GNUNET_TUN_IPv4Header *) &tun[1]; + struct GNUNET_TUN_TcpHeader *tcp = + (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + msg->size = htons (size); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV4); + GNUNET_TUN_initialize_ipv4_header (ipv4, + IPPROTO_TCP, + sizeof (struct GNUNET_TUN_TcpHeader) + + mlen, + &ts->destination_ip.v4, + &ts->source_ip.v4); + *tcp = data->tcp_header; + tcp->source_port = htons (ts->destination_port); + tcp->destination_port = htons (ts->source_port); + GNUNET_TUN_calculate_tcp4_checksum (ipv4, tcp, &data[1], mlen); + GNUNET_memcpy (&tcp[1], &data[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; - case AF_INET6: + } + break; + case AF_INET6: { + size_t size = sizeof (struct GNUNET_TUN_IPv6Header) + + sizeof (struct GNUNET_TUN_TcpHeader) + + sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader) + mlen; { - size_t size = sizeof (struct GNUNET_TUN_IPv6Header) - + sizeof (struct GNUNET_TUN_TcpHeader) - + sizeof (struct GNUNET_MessageHeader) + - sizeof (struct GNUNET_TUN_Layer2PacketHeader) + - mlen; - { - char buf[size] GNUNET_ALIGN; - struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; - struct GNUNET_TUN_Layer2PacketHeader *tun = (struct GNUNET_TUN_Layer2PacketHeader*) &msg[1]; - struct GNUNET_TUN_IPv6Header *ipv6 = (struct GNUNET_TUN_IPv6Header *) &tun[1]; - struct GNUNET_TUN_TcpHeader *tcp = (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; - msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); - msg->size = htons (size); - tun->flags = htons (0); - tun->proto = htons (ETH_P_IPV6); - GNUNET_TUN_initialize_ipv6_header (ipv6, - IPPROTO_TCP, - sizeof (struct GNUNET_TUN_TcpHeader) + mlen, - &ts->destination_ip.v6, - &ts->source_ip.v6); - *tcp = data->tcp_header; - tcp->source_port = htons (ts->destination_port); - tcp->destination_port = htons (ts->source_port); - GNUNET_TUN_calculate_tcp6_checksum (ipv6, - tcp, - &data[1], - mlen); - GNUNET_memcpy (&tcp[1], - &data[1], - mlen); - (void) GNUNET_HELPER_send (helper_handle, - msg, - GNUNET_YES, - NULL, NULL); - } + char buf[size] GNUNET_ALIGN; + struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; + struct GNUNET_TUN_Layer2PacketHeader *tun = + (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; + struct GNUNET_TUN_IPv6Header *ipv6 = + (struct GNUNET_TUN_IPv6Header *) &tun[1]; + struct GNUNET_TUN_TcpHeader *tcp = + (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; + msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); + msg->size = htons (size); + tun->flags = htons (0); + tun->proto = htons (ETH_P_IPV6); + GNUNET_TUN_initialize_ipv6_header (ipv6, + IPPROTO_TCP, + sizeof (struct GNUNET_TUN_TcpHeader) + + mlen, + &ts->destination_ip.v6, + &ts->source_ip.v6); + *tcp = data->tcp_header; + tcp->source_port = htons (ts->destination_port); + tcp->destination_port = htons (ts->source_port); + GNUNET_TUN_calculate_tcp6_checksum (ipv6, tcp, &data[1], mlen); + GNUNET_memcpy (&tcp[1], &data[1], mlen); + (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); } - break; + } + break; } GNUNET_CONTAINER_heap_update_cost (ts->heap_node, - GNUNET_TIME_absolute_get ().abs_value_us); + GNUNET_TIME_absolute_get ().abs_value_us); GNUNET_CADET_receive_done (ts->channel); } @@ -1370,21 +1345,20 @@ create_channel (struct ChannelState *ts, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *port) { - struct GNUNET_MQ_MessageHandler cadet_handlers[] = { - GNUNET_MQ_hd_var_size (udp_back, - GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, - struct GNUNET_EXIT_UdpReplyMessage, - ts), - GNUNET_MQ_hd_var_size (tcp_back, - GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, - struct GNUNET_EXIT_TcpDataMessage, - ts), - GNUNET_MQ_hd_var_size (icmp_back, - GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, - struct GNUNET_EXIT_IcmpToVPNMessage, - ts), - GNUNET_MQ_handler_end() - }; + struct GNUNET_MQ_MessageHandler cadet_handlers[] = + {GNUNET_MQ_hd_var_size (udp_back, + GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, + struct GNUNET_EXIT_UdpReplyMessage, + ts), + GNUNET_MQ_hd_var_size (tcp_back, + GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, + struct GNUNET_EXIT_TcpDataMessage, + ts), + GNUNET_MQ_hd_var_size (icmp_back, + GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, + struct GNUNET_EXIT_IcmpToVPNMessage, + ts), + GNUNET_MQ_handler_end ()}; return GNUNET_CADET_channel_create (cadet_handle, ts, @@ -1408,11 +1382,11 @@ create_channel (struct ChannelState *ts, */ static void handle_regex_result (void *cls, - const struct GNUNET_PeerIdentity *id, - const struct GNUNET_PeerIdentity *get_path, - unsigned int get_path_length, - const struct GNUNET_PeerIdentity *put_path, - unsigned int put_path_length) + const struct GNUNET_PeerIdentity *id, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length) { struct ChannelState *ts = cls; struct GNUNET_HashCode port; @@ -1445,9 +1419,7 @@ handle_regex_result (void *cls, "Creating tunnel to %s for destination %s!\n", GNUNET_i2s (id), print_channel_destination (&ts->destination)); - ts->channel = create_channel (ts, - id, - &port); + ts->channel = create_channel (ts, id, &port); } @@ -1459,14 +1431,13 @@ handle_regex_result (void *cls, * @return channel state of the channel that was created */ static struct ChannelState * -create_channel_to_destination (struct DestinationChannel *dt, - int client_af) +create_channel_to_destination (struct DestinationChannel *dt, int client_af) { struct ChannelState *ts; GNUNET_STATISTICS_update (stats, - gettext_noop ("# Cadet channels created"), - 1, + gettext_noop ("# Cadet channels created"), + 1, GNUNET_NO); ts = GNUNET_new (struct ChannelState); ts->af = client_af; @@ -1477,12 +1448,15 @@ create_channel_to_destination (struct DestinationChannel *dt, { struct GNUNET_HashCode cadet_port; - GNUNET_TUN_compute_service_cadet_port (&ts->destination.details.service_destination.service_descriptor, + GNUNET_TUN_compute_service_cadet_port (&ts->destination.details + .service_destination + .service_descriptor, ts->destination_port, &cadet_port); - ts->channel = create_channel (ts, - &dt->destination->details.service_destination.target, - &cadet_port); + ts->channel = + create_channel (ts, + &dt->destination->details.service_destination.target, + &cadet_port); if (NULL == ts->channel) { @@ -1491,9 +1465,11 @@ create_channel_to_destination (struct DestinationChannel *dt, return NULL; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Creating channel to peer %s offering service %s on port %u\n", - GNUNET_i2s (&dt->destination->details.service_destination.target), - GNUNET_h2s (&ts->destination.details.service_destination.service_descriptor), + "Creating channel to peer %s offering service %s on port %u\n", + GNUNET_i2s ( + &dt->destination->details.service_destination.target), + GNUNET_h2s (&ts->destination.details.service_destination + .service_descriptor), (unsigned int) ts->destination_port); } else @@ -1502,25 +1478,25 @@ create_channel_to_destination (struct DestinationChannel *dt, switch (dt->destination->details.exit_destination.af) { - case AF_INET: - { + case AF_INET: { char address[GNUNET_TUN_IPV4_REGEXLEN]; - GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, - dt->destination_port, - address); + GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination + .ip.v4, + dt->destination_port, + address); GNUNET_asprintf (&policy, "%s%s", GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, address); break; } - case AF_INET6: - { + case AF_INET6: { char address[GNUNET_TUN_IPV6_REGEXLEN]; - GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, - dt->destination_port, + GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination + .ip.v6, + dt->destination_port, address); GNUNET_asprintf (&policy, "%s%s", @@ -1534,12 +1510,9 @@ create_channel_to_destination (struct DestinationChannel *dt, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Requesting connect by string: %s\n", - policy); - ts->search = GNUNET_REGEX_search (cfg, - policy, - &handle_regex_result, - ts); + "Requesting connect by string: %s\n", + policy); + ts->search = GNUNET_REGEX_search (cfg, policy, &handle_regex_result, ts); GNUNET_free (policy); } return ts; @@ -1580,12 +1553,12 @@ expire_channel (struct ChannelState *except) */ static void route_packet (struct DestinationEntry *destination, - int af, - uint8_t protocol, - const void *source_ip, - const void *destination_ip, - const void *payload, - size_t payload_length) + int af, + uint8_t protocol, + const void *source_ip, + const void *destination_ip, + const void *payload, + size_t payload_length) { struct GNUNET_HashCode key; struct ChannelState *ts; @@ -1601,92 +1574,89 @@ route_packet (struct DestinationEntry *destination, switch (protocol) { - case IPPROTO_UDP: + case IPPROTO_UDP: { + if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader)) { - if (payload_length < sizeof (struct GNUNET_TUN_UdpHeader)) - { - /* blame kernel? */ - GNUNET_break (0); - return; - } - tcp = NULL; /* make compiler happy */ - icmp = NULL; /* make compiler happy */ - udp = payload; - if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader)) - { - GNUNET_break_op (0); - return; - } - source_port = ntohs (udp->source_port); - destination_port = ntohs (udp->destination_port); - get_channel_key_from_ips (af, - IPPROTO_UDP, - source_ip, - source_port, - destination_ip, - destination_port, - &key); + /* blame kernel? */ + GNUNET_break (0); + return; } - break; - case IPPROTO_TCP: + tcp = NULL; /* make compiler happy */ + icmp = NULL; /* make compiler happy */ + udp = payload; + if (udp->len < sizeof (struct GNUNET_TUN_UdpHeader)) { - if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader)) - { - /* blame kernel? */ - GNUNET_break (0); - return; - } - udp = NULL; /* make compiler happy */ - icmp = NULL; /* make compiler happy */ - tcp = payload; - if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader)) - { - GNUNET_break_op (0); - return; - } - source_port = ntohs (tcp->source_port); - destination_port = ntohs (tcp->destination_port); - get_channel_key_from_ips (af, - IPPROTO_TCP, - source_ip, - source_port, - destination_ip, - destination_port, - &key); + GNUNET_break_op (0); + return; } - break; + source_port = ntohs (udp->source_port); + destination_port = ntohs (udp->destination_port); + get_channel_key_from_ips (af, + IPPROTO_UDP, + source_ip, + source_port, + destination_ip, + destination_port, + &key); + } + break; + case IPPROTO_TCP: { + if (payload_length < sizeof (struct GNUNET_TUN_TcpHeader)) + { + /* blame kernel? */ + GNUNET_break (0); + return; + } + udp = NULL; /* make compiler happy */ + icmp = NULL; /* make compiler happy */ + tcp = payload; + if (tcp->off * 4 < sizeof (struct GNUNET_TUN_TcpHeader)) + { + GNUNET_break_op (0); + return; + } + source_port = ntohs (tcp->source_port); + destination_port = ntohs (tcp->destination_port); + get_channel_key_from_ips (af, + IPPROTO_TCP, + source_ip, + source_port, + destination_ip, + destination_port, + &key); + } + break; case IPPROTO_ICMP: - case IPPROTO_ICMPV6: + case IPPROTO_ICMPV6: { + if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP)) { - if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) - { - GNUNET_break (0); - return; - } - if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader)) - { - /* blame kernel? */ - GNUNET_break (0); - return; - } - tcp = NULL; /* make compiler happy */ - udp = NULL; /* make compiler happy */ - icmp = payload; - source_port = 0; - destination_port = 0; - get_channel_key_from_ips (af, - protocol, - source_ip, - 0, - destination_ip, - 0, - &key); + GNUNET_break (0); + return; } - break; + if (payload_length < sizeof (struct GNUNET_TUN_IcmpHeader)) + { + /* blame kernel? */ + GNUNET_break (0); + return; + } + tcp = NULL; /* make compiler happy */ + udp = NULL; /* make compiler happy */ + icmp = payload; + source_port = 0; + destination_port = 0; + get_channel_key_from_ips (af, + protocol, + source_ip, + 0, + destination_ip, + 0, + &key); + } + break; default: GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Protocol %u not supported, dropping\n"), - (unsigned int) protocol); + _ ("Protocol %u not supported, dropping\n"), + (unsigned int) protocol); return; } alen = 0; @@ -1696,7 +1666,7 @@ route_packet (struct DestinationEntry *destination, { case AF_INET: alen = sizeof (struct in_addr); - break; + break; case AF_INET6: alen = sizeof (struct in6_addr); break; @@ -1709,27 +1679,23 @@ route_packet (struct DestinationEntry *destination, char dbuf[INET6_ADDRSTRLEN]; char xbuf[INET6_ADDRSTRLEN]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", - (protocol == IPPROTO_TCP) ? "TCP" : "UDP", - inet_ntop (af, - source_ip, - sbuf, - sizeof (sbuf)), - source_port, - inet_ntop (af, - destination_ip, - dbuf, - sizeof (dbuf)), - destination_port, - inet_ntop (destination->details.exit_destination.af, - &destination->details.exit_destination.ip, - xbuf, sizeof (xbuf)), - destination_port); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", + (protocol == IPPROTO_TCP) ? "TCP" : "UDP", + inet_ntop (af, source_ip, sbuf, sizeof (sbuf)), + source_port, + inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)), + destination_port, + inet_ntop (destination->details.exit_destination.af, + &destination->details.exit_destination.ip, + xbuf, + sizeof (xbuf)), + destination_port); } for (dt = destination->dt_head; NULL != dt; dt = dt->next) if (dt->destination_port == destination_port) - break; + break; } else { @@ -1737,39 +1703,34 @@ route_packet (struct DestinationEntry *destination, char sbuf[INET6_ADDRSTRLEN]; char dbuf[INET6_ADDRSTRLEN]; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", - (protocol == IPPROTO_TCP) ? "TCP" : "UDP", - inet_ntop (af, - source_ip, - sbuf, - sizeof (sbuf)), - source_port, - inet_ntop (af, - destination_ip, - dbuf, - sizeof (dbuf)), - destination_port, - GNUNET_h2s (&destination->details.service_destination.service_descriptor), - GNUNET_i2s (&destination->details.service_destination.target)); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", + (protocol == IPPROTO_TCP) ? "TCP" : "UDP", + inet_ntop (af, source_ip, sbuf, sizeof (sbuf)), + source_port, + inet_ntop (af, destination_ip, dbuf, sizeof (dbuf)), + destination_port, + GNUNET_h2s ( + &destination->details.service_destination.service_descriptor), + GNUNET_i2s (&destination->details.service_destination.target)); } for (dt = destination->dt_head; NULL != dt; dt = dt->next) if (dt->destination_port == destination_port) - break; + break; } if (NULL == dt) { dt = GNUNET_new (struct DestinationChannel); dt->destination = destination; GNUNET_CONTAINER_DLL_insert (destination->dt_head, - destination->dt_tail, - dt); + destination->dt_tail, + dt); dt->destination_port = destination_port; } /* see if we have an existing channel for this destination */ - ts = GNUNET_CONTAINER_multihashmap_get (channel_map, - &key); + ts = GNUNET_CONTAINER_multihashmap_get (channel_map, &key); if (NULL == ts) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1777,8 +1738,7 @@ route_packet (struct DestinationEntry *destination, GNUNET_h2s (&key)); /* need to either use the existing channel from the destination (if still available) or create a fresh one */ - ts = create_channel_to_destination (dt, - af); + ts = create_channel_to_destination (dt, af); if (NULL == ts) return; /* now bind existing "unbound" channel to our IP/port tuple */ @@ -1786,46 +1746,51 @@ route_packet (struct DestinationEntry *destination, ts->af = af; if (AF_INET == af) { - ts->source_ip.v4 = * (const struct in_addr *) source_ip; - ts->destination_ip.v4 = * (const struct in_addr *) destination_ip; + ts->source_ip.v4 = *(const struct in_addr *) source_ip; + ts->destination_ip.v4 = *(const struct in_addr *) destination_ip; } else { - ts->source_ip.v6 = * (const struct in6_addr *) source_ip; - ts->destination_ip.v6 = * (const struct in6_addr *) destination_ip; + ts->source_ip.v6 = *(const struct in6_addr *) source_ip; + ts->destination_ip.v6 = *(const struct in6_addr *) destination_ip; } ts->source_port = source_port; ts->destination_port = destination_port; - ts->heap_node = GNUNET_CONTAINER_heap_insert (channel_heap, - ts, - GNUNET_TIME_absolute_get ().abs_value_us); + ts->heap_node = + GNUNET_CONTAINER_heap_insert (channel_heap, + ts, + GNUNET_TIME_absolute_get ().abs_value_us); GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put (channel_map, - &key, - ts, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + GNUNET_CONTAINER_multihashmap_put ( + channel_map, + &key, + ts, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); GNUNET_STATISTICS_update (stats, - gettext_noop ("# Active channels"), - 1, GNUNET_NO); - while (GNUNET_CONTAINER_multihashmap_size (channel_map) > max_channel_mappings) + gettext_noop ("# Active channels"), + 1, + GNUNET_NO); + while (GNUNET_CONTAINER_multihashmap_size (channel_map) > + max_channel_mappings) expire_channel (ts); } else { GNUNET_CONTAINER_heap_update_cost (ts->heap_node, - GNUNET_TIME_absolute_get ().abs_value_us); + GNUNET_TIME_absolute_get () + .abs_value_us); } if (NULL == ts->channel) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Packet dropped, channel to %s not yet ready (%s)\n", print_channel_destination (&ts->destination), - (NULL == ts->search) - ? "EXIT search failed" - : "EXIT search active"); + (NULL == ts->search) ? "EXIT search failed" + : "EXIT search active"); GNUNET_STATISTICS_update (stats, - gettext_noop ("# Packets dropped (channel not yet online)"), - 1, + gettext_noop ( + "# Packets dropped (channel not yet online)"), + 1, GNUNET_NO); return; } @@ -1838,19 +1803,21 @@ route_packet (struct DestinationEntry *destination, { struct GNUNET_EXIT_UdpServiceMessage *usm; - mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + - payload_length - sizeof (struct GNUNET_TUN_UdpHeader); + mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + payload_length - + sizeof (struct GNUNET_TUN_UdpHeader); if (mlen >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } env = GNUNET_MQ_msg_extra (usm, - payload_length - sizeof (struct GNUNET_TUN_UdpHeader), + payload_length - + sizeof (struct GNUNET_TUN_UdpHeader), GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); /* if the source port is below 32000, we assume it has a special meaning; if not, we pick a random port (this is a heuristic) */ - usm->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; + usm->source_port = + (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; usm->destination_port = udp->destination_port; GNUNET_memcpy (&usm[1], &udp[1], @@ -1863,33 +1830,35 @@ route_packet (struct DestinationEntry *destination, struct in6_addr *ip6dst; void *payload; - mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + - alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); + mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + alen + + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); if (mlen >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } env = GNUNET_MQ_msg_extra (uim, - payload_length + alen - sizeof (struct GNUNET_TUN_UdpHeader), + payload_length + alen - + sizeof (struct GNUNET_TUN_UdpHeader), GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); uim->af = htonl (destination->details.exit_destination.af); - uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; + uim->source_port = + (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; uim->destination_port = udp->destination_port; switch (destination->details.exit_destination.af) { case AF_INET: - ip4dst = (struct in_addr *) &uim[1]; - *ip4dst = destination->details.exit_destination.ip.v4; - payload = &ip4dst[1]; - break; + ip4dst = (struct in_addr *) &uim[1]; + *ip4dst = destination->details.exit_destination.ip.v4; + payload = &ip4dst[1]; + break; case AF_INET6: - ip6dst = (struct in6_addr *) &uim[1]; - *ip6dst = destination->details.exit_destination.ip.v6; - payload = &ip6dst[1]; - break; + ip6dst = (struct in6_addr *) &uim[1]; + *ip6dst = destination->details.exit_destination.ip.v6; + payload = &ip6dst[1]; + break; default: - GNUNET_assert (0); + GNUNET_assert (0); } GNUNET_memcpy (payload, &udp[1], @@ -1901,59 +1870,63 @@ route_packet (struct DestinationEntry *destination, { if (destination->is_service) { - struct GNUNET_EXIT_TcpServiceStartMessage *tsm; - - mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + - payload_length - sizeof (struct GNUNET_TUN_TcpHeader); - if (mlen >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } - env = GNUNET_MQ_msg_extra (tsm, - payload_length - sizeof (struct GNUNET_TUN_TcpHeader), - GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); - tsm->reserved = htonl (0); - tsm->tcp_header = *tcp; - GNUNET_memcpy (&tsm[1], + struct GNUNET_EXIT_TcpServiceStartMessage *tsm; + + mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); + if (mlen >= GNUNET_MAX_MESSAGE_SIZE) + { + GNUNET_break (0); + return; + } + env = + GNUNET_MQ_msg_extra (tsm, + payload_length - + sizeof (struct GNUNET_TUN_TcpHeader), + GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); + tsm->reserved = htonl (0); + tsm->tcp_header = *tcp; + GNUNET_memcpy (&tsm[1], &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); } else { - struct GNUNET_EXIT_TcpInternetStartMessage *tim; - struct in_addr *ip4dst; - struct in6_addr *ip6dst; - void *payload; - - mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + - alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); - if (mlen >= GNUNET_MAX_MESSAGE_SIZE) - { - GNUNET_break (0); - return; - } - env = GNUNET_MQ_msg_extra (tim, - payload_length + alen - sizeof (struct GNUNET_TUN_TcpHeader), - GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); - tim->af = htonl (destination->details.exit_destination.af); - tim->tcp_header = *tcp; - switch (destination->details.exit_destination.af) - { - case AF_INET: - ip4dst = (struct in_addr *) &tim[1]; - *ip4dst = destination->details.exit_destination.ip.v4; - payload = &ip4dst[1]; - break; - case AF_INET6: - ip6dst = (struct in6_addr *) &tim[1]; - *ip6dst = destination->details.exit_destination.ip.v6; - payload = &ip6dst[1]; - break; - default: - GNUNET_assert (0); - } - GNUNET_memcpy (payload, + struct GNUNET_EXIT_TcpInternetStartMessage *tim; + struct in_addr *ip4dst; + struct in6_addr *ip6dst; + void *payload; + + mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + alen + + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); + if (mlen >= GNUNET_MAX_MESSAGE_SIZE) + { + GNUNET_break (0); + return; + } + env = + GNUNET_MQ_msg_extra (tim, + payload_length + alen - + sizeof (struct GNUNET_TUN_TcpHeader), + GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); + tim->af = htonl (destination->details.exit_destination.af); + tim->tcp_header = *tcp; + switch (destination->details.exit_destination.af) + { + case AF_INET: + ip4dst = (struct in_addr *) &tim[1]; + *ip4dst = destination->details.exit_destination.ip.v4; + payload = &ip4dst[1]; + break; + case AF_INET6: + ip6dst = (struct in6_addr *) &tim[1]; + *ip6dst = destination->details.exit_destination.ip.v6; + payload = &ip6dst[1]; + break; + default: + GNUNET_assert (0); + } + GNUNET_memcpy (payload, &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); } @@ -1962,22 +1935,23 @@ route_packet (struct DestinationEntry *destination, { struct GNUNET_EXIT_TcpDataMessage *tdm; - mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + - payload_length - sizeof (struct GNUNET_TUN_TcpHeader); + mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + payload_length - + sizeof (struct GNUNET_TUN_TcpHeader); if (mlen >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } env = GNUNET_MQ_msg_extra (tdm, - payload_length - sizeof (struct GNUNET_TUN_TcpHeader), + payload_length - + sizeof (struct GNUNET_TUN_TcpHeader), GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); tdm->reserved = htonl (0); tdm->tcp_header = *tcp; GNUNET_memcpy (&tdm[1], &tcp[1], payload_length - sizeof (struct GNUNET_TUN_TcpHeader)); - } + } break; case IPPROTO_ICMP: case IPPROTO_ICMPV6: @@ -1991,62 +1965,67 @@ route_packet (struct DestinationEntry *destination, switch (af) { case AF_INET: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: - case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: - break; - case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: - case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: - case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: - /* throw away ICMP payload, won't be useful for the other side anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - default: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (not allowed)"), - 1, GNUNET_NO); - return; - } - /* end of AF_INET */ - break; + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: + case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: + break; + case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: + case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: + case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: + /* throw away ICMP payload, won't be useful for the other side anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + default: + GNUNET_STATISTICS_update (stats, + gettext_noop ( + "# ICMPv4 packets dropped (not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end of AF_INET */ + break; case AF_INET6: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: - case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: - case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: - case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: - /* throw away ICMP payload, won't be useful for the other side anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: - case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: - break; - default: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (not allowed)"), - 1, GNUNET_NO); - return; - } - /* end of AF_INET6 */ - break; + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: + case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: + case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: + case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: + /* throw away ICMP payload, won't be useful for the other side anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: + case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: + break; + default: + GNUNET_STATISTICS_update (stats, + gettext_noop ( + "# ICMPv6 packets dropped (not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end of AF_INET6 */ + break; default: - GNUNET_assert (0); - break; + GNUNET_assert (0); + break; } /* update length calculations, as payload_length may have changed */ - mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + - alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); + mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + alen + + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); if (mlen >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } env = GNUNET_MQ_msg_extra (ism, - payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), + payload_length - + sizeof (struct GNUNET_TUN_IcmpHeader), GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); ism->af = htonl (af); /* need to tell destination ICMP protocol family! */ ism->icmp_header = *icmp; @@ -2068,114 +2047,125 @@ route_packet (struct DestinationEntry *destination, switch (af) { case AF_INET: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: - if (destination->details.exit_destination.af == AF_INET6) - new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; - break; - case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: - if (destination->details.exit_destination.af == AF_INET6) - new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; - break; - case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: - if (destination->details.exit_destination.af == AF_INET6) - new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: - if (destination->details.exit_destination.af == AF_INET6) - new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: - if (destination->details.exit_destination.af == AF_INET6) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), - 1, GNUNET_NO); - return; - } - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - default: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end of AF_INET */ - break; + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: + if (destination->details.exit_destination.af == AF_INET6) + new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; + break; + case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: + if (destination->details.exit_destination.af == AF_INET6) + new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; + break; + case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: + if (destination->details.exit_destination.af == AF_INET6) + new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: + if (destination->details.exit_destination.af == AF_INET6) + new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: + if (destination->details.exit_destination.af == AF_INET6) + { + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), + 1, + GNUNET_NO); + return; + } + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + default: + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end of AF_INET */ + break; case AF_INET6: - switch (icmp->type) - { - case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: - if (destination->details.exit_destination.af == AF_INET) - new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: - if (destination->details.exit_destination.af == AF_INET) - new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: - if (destination->details.exit_destination.af == AF_INET) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), - 1, GNUNET_NO); - return; - } - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: - if (destination->details.exit_destination.af == AF_INET) - { - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), - 1, GNUNET_NO); - return; - } - /* throw away IP-payload, exit will have to make it up anyway */ - payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); - break; - case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: - if (destination->details.exit_destination.af == AF_INET) - new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; - break; - case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: - if (destination->details.exit_destination.af == AF_INET) - new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; - break; - default: - GNUNET_STATISTICS_update (stats, - gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), - 1, GNUNET_NO); - return; - } - /* end of AF_INET6 */ - break; + switch (icmp->type) + { + case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: + if (destination->details.exit_destination.af == AF_INET) + new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: + if (destination->details.exit_destination.af == AF_INET) + new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: + if (destination->details.exit_destination.af == AF_INET) + { + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), + 1, + GNUNET_NO); + return; + } + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: + if (destination->details.exit_destination.af == AF_INET) + { + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), + 1, + GNUNET_NO); + return; + } + /* throw away IP-payload, exit will have to make it up anyway */ + payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); + break; + case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: + if (destination->details.exit_destination.af == AF_INET) + new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; + break; + case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: + if (destination->details.exit_destination.af == AF_INET) + new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; + break; + default: + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), + 1, + GNUNET_NO); + return; + } + /* end of AF_INET6 */ + break; default: - GNUNET_assert (0); + GNUNET_assert (0); } /* update length calculations, as payload_length may have changed */ - mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + - alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); + mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + alen + + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); if (mlen >= GNUNET_MAX_MESSAGE_SIZE) { - GNUNET_break (0); - return; + GNUNET_break (0); + return; } env = GNUNET_MQ_msg_extra (iim, - alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader), + alen + payload_length - + sizeof (struct GNUNET_TUN_IcmpHeader), GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); iim->icmp_header = *icmp; iim->icmp_header.type = new_type; @@ -2183,17 +2173,17 @@ route_packet (struct DestinationEntry *destination, switch (destination->details.exit_destination.af) { case AF_INET: - ip4dst = (struct in_addr *) &iim[1]; - *ip4dst = destination->details.exit_destination.ip.v4; - payload = &ip4dst[1]; - break; + ip4dst = (struct in_addr *) &iim[1]; + *ip4dst = destination->details.exit_destination.ip.v4; + payload = &ip4dst[1]; + break; case AF_INET6: - ip6dst = (struct in6_addr *) &iim[1]; - *ip6dst = destination->details.exit_destination.ip.v6; - payload = &ip6dst[1]; - break; + ip6dst = (struct in6_addr *) &iim[1]; + *ip6dst = destination->details.exit_destination.ip.v6; + payload = &ip6dst[1]; + break; default: - GNUNET_assert (0); + GNUNET_assert (0); } GNUNET_memcpy (payload, &icmp[1], @@ -2206,8 +2196,7 @@ route_packet (struct DestinationEntry *destination, break; } ts->is_established = GNUNET_YES; - send_to_channel (ts, - env); + send_to_channel (ts, env); } @@ -2224,8 +2213,7 @@ route_packet (struct DestinationEntry *destination, * #GNUNET_SYSERR to stop further processing with error */ static int -message_token (void *cls, - const struct GNUNET_MessageHeader *message) +message_token (void *cls, const struct GNUNET_MessageHeader *message) { const struct GNUNET_TUN_Layer2PacketHeader *tun; size_t mlen; @@ -2233,101 +2221,96 @@ message_token (void *cls, struct DestinationEntry *de; GNUNET_STATISTICS_update (stats, - gettext_noop ("# Packets received from TUN interface"), - 1, GNUNET_NO); + gettext_noop ( + "# Packets received from TUN interface"), + 1, + GNUNET_NO); mlen = ntohs (message->size); - if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || - (mlen < sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)) ) + if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || + (mlen < sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader))) { GNUNET_break (0); return GNUNET_OK; } tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; - mlen -= (sizeof (struct GNUNET_MessageHeader) + sizeof (struct GNUNET_TUN_Layer2PacketHeader)); + mlen -= (sizeof (struct GNUNET_MessageHeader) + + sizeof (struct GNUNET_TUN_Layer2PacketHeader)); switch (ntohs (tun->proto)) { - case ETH_P_IPV6: + case ETH_P_IPV6: { + const struct GNUNET_TUN_IPv6Header *pkt6; + + if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) + { + /* blame kernel */ + GNUNET_break (0); + return GNUNET_OK; + } + pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1]; + get_destination_key_from_ip (AF_INET6, &pkt6->destination_address, &key); + de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); + if (NULL == de) { - const struct GNUNET_TUN_IPv6Header *pkt6; + char buf[INET6_ADDRSTRLEN]; - if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) - { - /* blame kernel */ - GNUNET_break (0); - return GNUNET_OK; - } - pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1]; - get_destination_key_from_ip (AF_INET6, - &pkt6->destination_address, - &key); - de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); - if (NULL == de) - { - char buf[INET6_ADDRSTRLEN]; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Packet received for unmapped destination `%s' (dropping it)\n"), - inet_ntop (AF_INET6, - &pkt6->destination_address, - buf, - sizeof (buf))); - return GNUNET_OK; - } - route_packet (de, - AF_INET6, - pkt6->next_header, - &pkt6->source_address, - &pkt6->destination_address, - &pkt6[1], - mlen - sizeof (struct GNUNET_TUN_IPv6Header)); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Packet received for unmapped destination `%s' (dropping it)\n"), + inet_ntop (AF_INET6, &pkt6->destination_address, buf, sizeof (buf))); + return GNUNET_OK; } - break; - case ETH_P_IPV4: + route_packet (de, + AF_INET6, + pkt6->next_header, + &pkt6->source_address, + &pkt6->destination_address, + &pkt6[1], + mlen - sizeof (struct GNUNET_TUN_IPv6Header)); + } + break; + case ETH_P_IPV4: { + struct GNUNET_TUN_IPv4Header *pkt4; + + if (mlen < sizeof (struct GNUNET_TUN_IPv4Header)) { - struct GNUNET_TUN_IPv4Header *pkt4; + /* blame kernel */ + GNUNET_break (0); + return GNUNET_OK; + } + pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; + get_destination_key_from_ip (AF_INET, &pkt4->destination_address, &key); + de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); + if (NULL == de) + { + char buf[INET_ADDRSTRLEN]; - if (mlen < sizeof (struct GNUNET_TUN_IPv4Header)) - { - /* blame kernel */ - GNUNET_break (0); - return GNUNET_OK; - } - pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; - get_destination_key_from_ip (AF_INET, - &pkt4->destination_address, - &key); - de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); - if (NULL == de) - { - char buf[INET_ADDRSTRLEN]; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Packet received for unmapped destination `%s' (dropping it)\n"), - inet_ntop (AF_INET, - &pkt4->destination_address, - buf, - sizeof (buf))); - return GNUNET_OK; - } - if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Received IPv4 packet with options (dropping it)\n")); - return GNUNET_OK; - } - route_packet (de, - AF_INET, - pkt4->protocol, - &pkt4->source_address, - &pkt4->destination_address, - &pkt4[1], - mlen - sizeof (struct GNUNET_TUN_IPv4Header)); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Packet received for unmapped destination `%s' (dropping it)\n"), + inet_ntop (AF_INET, &pkt4->destination_address, buf, sizeof (buf))); + return GNUNET_OK; } - break; + if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Received IPv4 packet with options (dropping it)\n")); + return GNUNET_OK; + } + route_packet (de, + AF_INET, + pkt4->protocol, + &pkt4->source_address, + &pkt4->destination_address, + &pkt4[1], + mlen - sizeof (struct GNUNET_TUN_IPv4Header)); + } + break; default: - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Received packet of unknown protocol %d from TUN (dropping it)\n"), - (unsigned int) ntohs (tun->proto)); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Received packet of unknown protocol %d from TUN (dropping it)\n"), + (unsigned int) ntohs (tun->proto)); break; } return GNUNET_OK; @@ -2360,27 +2343,23 @@ allocate_v4_address (struct in_addr *v4) mask.s_addr = addr.s_addr | ~mask.s_addr; tries = 0; do + { + tries++; + if (tries > 16) { - tries++; - if (tries > 16) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to find unallocated IPv4 address in VPN's range\n")); - return GNUNET_SYSERR; - } - /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ - rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT32_MAX); - v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; - get_destination_key_from_ip (AF_INET, - v4, - &key); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Failed to find unallocated IPv4 address in VPN's range\n")); + return GNUNET_SYSERR; } - while ( (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (destination_map, - &key)) || - (v4->s_addr == addr.s_addr) || - (v4->s_addr == mask.s_addr) ); + /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ + rnd.s_addr = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); + v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; + get_destination_key_from_ip (AF_INET, v4, &key); + } while ((GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) || + (v4->s_addr == addr.s_addr) || (v4->s_addr == mask.s_addr)); return GNUNET_OK; } @@ -2409,39 +2388,33 @@ allocate_v6_address (struct in6_addr *v6) /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, thus: */ mask = addr; - for (i=127;i>=ipv6prefix;i--) + for (i = 127; i >= ipv6prefix; i--) mask.s6_addr[i / 8] |= (1 << (i % 8)); /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ tries = 0; do + { + tries++; + if (tries > 16) { - tries++; - if (tries > 16) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to find unallocated IPv6 address in VPN's range\n")); - return GNUNET_SYSERR; - - } - for (i=0;i<16;i++) - { - rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - 256); - v6->s6_addr[i] - = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; - } - get_destination_key_from_ip (AF_INET6, - v6, - &key); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _ ( + "Failed to find unallocated IPv6 address in VPN's range\n")); + return GNUNET_SYSERR; } - while ( (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_contains (destination_map, - &key)) || - (0 == GNUNET_memcmp (v6, - &addr)) || - (0 == GNUNET_memcmp (v6, - &mask)) ); + for (i = 0; i < 16; i++) + { + rnd.s6_addr[i] = + (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + 256); + v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; + } + get_destination_key_from_ip (AF_INET6, v6, &key); + } while ((GNUNET_YES == + GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) || + (0 == GNUNET_memcmp (v6, &addr)) || + (0 == GNUNET_memcmp (v6, &mask))); return GNUNET_OK; } @@ -2457,26 +2430,24 @@ free_destination_entry (struct DestinationEntry *de) struct DestinationChannel *dt; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up destination entry `%s'\n", + "Cleaning up destination entry `%s'\n", print_channel_destination (de)); GNUNET_STATISTICS_update (stats, - gettext_noop ("# Active destinations"), - -1, GNUNET_NO); + gettext_noop ("# Active destinations"), + -1, + GNUNET_NO); while (NULL != (dt = de->dt_head)) { - GNUNET_CONTAINER_DLL_remove (de->dt_head, - de->dt_tail, - dt); + GNUNET_CONTAINER_DLL_remove (de->dt_head, de->dt_tail, dt); GNUNET_free (dt); } if (NULL != de->heap_node) { GNUNET_CONTAINER_heap_remove_node (de->heap_node); de->heap_node = NULL; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (destination_map, - &de->key, - de)); + GNUNET_assert ( + GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (destination_map, &de->key, de)); } GNUNET_free (de); } @@ -2516,36 +2487,32 @@ expire_destination (struct DestinationEntry *except) */ static int allocate_response_ip (int *result_af, - void **addr, - struct in_addr *v4, - struct in6_addr *v6) + void **addr, + struct in_addr *v4, + struct in6_addr *v6) { *addr = NULL; switch (*result_af) { case AF_INET: - if (GNUNET_OK != - allocate_v4_address (v4)) + if (GNUNET_OK != allocate_v4_address (v4)) *result_af = AF_UNSPEC; else *addr = v4; break; case AF_INET6: - if (GNUNET_OK != - allocate_v6_address (v6)) + if (GNUNET_OK != allocate_v6_address (v6)) *result_af = AF_UNSPEC; else *addr = v6; break; case AF_UNSPEC: - if (GNUNET_OK == - allocate_v4_address (v4)) + if (GNUNET_OK == allocate_v4_address (v4)) { *addr = v4; *result_af = AF_INET; } - else if (GNUNET_OK == - allocate_v6_address (v6)) + else if (GNUNET_OK == allocate_v6_address (v6)) { *addr = v6; *result_af = AF_INET6; @@ -2627,18 +2594,13 @@ handle_client_redirect_to_ip (void *cls, addr_af = (int) htonl (msg->addr_af); /* allocate response IP */ result_af = (int) htonl (msg->result_af); - if (GNUNET_OK != allocate_response_ip (&result_af, - &addr, - &v4, &v6)) + if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6)) { GNUNET_SERVICE_client_drop (client); return; } /* send reply with our IP address */ - send_client_reply (client, - msg->request_id, - result_af, - addr); + send_client_reply (client, msg->request_id, result_af, addr); if (result_af == AF_UNSPEC) { /* failure, we're done */ @@ -2651,40 +2613,34 @@ handle_client_redirect_to_ip (void *cls, char dbuf[INET6_ADDRSTRLEN]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Allocated address %s for redirection via exit to %s\n", - inet_ntop (result_af, - addr, - sbuf, - sizeof (sbuf)), - inet_ntop (addr_af, - &msg[1], - dbuf, - sizeof (dbuf))); + "Allocated address %s for redirection via exit to %s\n", + inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), + inet_ntop (addr_af, &msg[1], dbuf, sizeof (dbuf))); } /* setup destination record */ de = GNUNET_new (struct DestinationEntry); de->is_service = GNUNET_NO; de->details.exit_destination.af = addr_af; - GNUNET_memcpy (&de->details.exit_destination.ip, - &msg[1], - alen); - get_destination_key_from_ip (result_af, - addr, - &key); + GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen); + get_destination_key_from_ip (result_af, addr, &key); de->key = key; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (destination_map, - &key, - de, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( + destination_map, + &key, + de, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, - de, - GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); + de, + GNUNET_TIME_absolute_ntoh ( + msg->expiration_time) + .abs_value_us); GNUNET_STATISTICS_update (stats, - gettext_noop ("# Active destinations"), - 1, GNUNET_NO); - while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) + gettext_noop ("# Active destinations"), + 1, + GNUNET_NO); + while (GNUNET_CONTAINER_multihashmap_size (destination_map) > + max_destination_mappings) expire_destination (de); GNUNET_SERVICE_client_continue (client); } @@ -2699,8 +2655,9 @@ handle_client_redirect_to_ip (void *cls, * @param msg redirection request */ static void -handle_client_redirect_to_service (void *cls, - const struct RedirectToServiceRequestMessage *msg) +handle_client_redirect_to_service ( + void *cls, + const struct RedirectToServiceRequestMessage *msg) { struct GNUNET_SERVICE_Client *client = cls; int result_af; @@ -2713,25 +2670,18 @@ handle_client_redirect_to_service (void *cls, /* allocate response IP */ result_af = (int) htonl (msg->result_af); - if (GNUNET_OK != - allocate_response_ip (&result_af, - &addr, - &v4, - &v6)) + if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6)) { GNUNET_break (0); GNUNET_SERVICE_client_drop (client); return; } - send_client_reply (client, - msg->request_id, - result_af, - addr); + send_client_reply (client, msg->request_id, result_af, addr); if (result_af == AF_UNSPEC) { /* failure, we're done */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to allocate IP address for new destination\n")); + _ ("Failed to allocate IP address for new destination\n")); GNUNET_SERVICE_client_continue (client); return; } @@ -2740,13 +2690,10 @@ handle_client_redirect_to_service (void *cls, char sbuf[INET6_ADDRSTRLEN]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Allocated address %s for redirection to service %s on peer %s\n", - inet_ntop (result_af, - addr, - sbuf, - sizeof (sbuf)), - GNUNET_h2s (&msg->service_descriptor), - GNUNET_i2s (&msg->target)); + "Allocated address %s for redirection to service %s on peer %s\n", + inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), + GNUNET_h2s (&msg->service_descriptor), + GNUNET_i2s (&msg->target)); } /* setup destination record */ @@ -2754,33 +2701,30 @@ handle_client_redirect_to_service (void *cls, de->is_service = GNUNET_YES; de->details.service_destination.target = msg->target; de->details.service_destination.service_descriptor = msg->service_descriptor; - get_destination_key_from_ip (result_af, - addr, - &key); + get_destination_key_from_ip (result_af, addr, &key); de->key = key; - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multihashmap_put (destination_map, - &key, - de, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - de->heap_node - = GNUNET_CONTAINER_heap_insert (destination_heap, - de, - GNUNET_TIME_absolute_ntoh (msg->expiration_time).abs_value_us); - while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) + GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( + destination_map, + &key, + de, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, + de, + GNUNET_TIME_absolute_ntoh ( + msg->expiration_time) + .abs_value_us); + while (GNUNET_CONTAINER_multihashmap_size (destination_map) > + max_destination_mappings) expire_destination (de); dt = GNUNET_new (struct DestinationChannel); dt->destination = de; - GNUNET_CONTAINER_DLL_insert (de->dt_head, - de->dt_tail, - dt); + GNUNET_CONTAINER_DLL_insert (de->dt_head, de->dt_tail, dt); /* we're done */ GNUNET_SERVICE_client_continue (client); } - /** * Free memory occupied by an entry in the destination map. * @@ -2790,9 +2734,7 @@ handle_client_redirect_to_service (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -cleanup_destination (void *cls, - const struct GNUNET_HashCode *key, - void *value) +cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value) { struct DestinationEntry *de = value; @@ -2810,14 +2752,12 @@ cleanup_destination (void *cls, * @return #GNUNET_OK (continue to iterate) */ static int -cleanup_channel (void *cls, - const struct GNUNET_HashCode *key, - void *value) +cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value) { struct ChannelState *ts = value; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Tearing down channel to `%s' during cleanup\n", + "Tearing down channel to `%s' during cleanup\n", print_channel_destination (&ts->destination)); free_channel_state (ts); return GNUNET_OK; @@ -2834,13 +2774,12 @@ cleanup (void *cls) { unsigned int i; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "VPN is shutting down\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n"); if (NULL != destination_map) { GNUNET_CONTAINER_multihashmap_iterate (destination_map, - &cleanup_destination, - NULL); + &cleanup_destination, + NULL); GNUNET_CONTAINER_multihashmap_destroy (destination_map); destination_map = NULL; } @@ -2851,9 +2790,7 @@ cleanup (void *cls) } if (NULL != channel_map) { - GNUNET_CONTAINER_multihashmap_iterate (channel_map, - &cleanup_channel, - NULL); + GNUNET_CONTAINER_multihashmap_iterate (channel_map, &cleanup_channel, NULL); GNUNET_CONTAINER_multihashmap_destroy (channel_map); channel_map = NULL; } @@ -2878,7 +2815,7 @@ cleanup (void *cls) GNUNET_STATISTICS_destroy (stats, GNUNET_NO); stats = NULL; } - for (i=0;i<5;i++) + for (i = 0; i < 5; i++) GNUNET_free_non_null (vpn_argv[i]); } @@ -2893,8 +2830,8 @@ cleanup (void *cls) */ static void * client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - struct GNUNET_MQ_Handle *mq) + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) { return c; } @@ -2909,8 +2846,8 @@ client_connect_cb (void *cls, */ static void client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *c, - void *internal_cls) + struct GNUNET_SERVICE_Client *c, + void *internal_cls) { GNUNET_assert (c == internal_cls); } @@ -2940,9 +2877,10 @@ run (void *cls, binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); if (GNUNET_YES != - GNUNET_OS_check_helper_binary (binary, - GNUNET_YES, - "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please! + GNUNET_OS_check_helper_binary ( + binary, + GNUNET_YES, + "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please! { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "`%s' is not SUID, refusing to run.\n", @@ -2961,18 +2899,22 @@ run (void *cls, GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", "MAX_MAPPING", - &max_destination_mappings)) + &max_destination_mappings)) max_destination_mappings = 200; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", "MAX_TUNNELS", - &max_channel_mappings)) + &max_channel_mappings)) max_channel_mappings = 200; - destination_map = GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, GNUNET_NO); - destination_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); - channel_map = GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); + destination_map = + GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, + GNUNET_NO); + destination_heap = + GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + channel_map = + GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); @@ -2988,22 +2930,26 @@ run (void *cls, ipv6addr = NULL; if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) { - if ( (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6ADDR", - &ipv6addr) || - (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) + if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + "VPN", + "IPV6ADDR", + &ipv6addr) || + (1 != inet_pton (AF_INET6, ipv6addr, &v6)))) { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", - _("Must specify valid IPv6 address")); + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "VPN", + "IPV6ADDR", + _ ("Must specify valid IPv6 address")); GNUNET_SCHEDULER_shutdown (); GNUNET_free_non_null (ipv6addr); return; } vpn_argv[2] = ipv6addr; ipv6prefix_s = NULL; - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IPV6PREFIX", - &ipv6prefix_s)) + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + "VPN", + "IPV6PREFIX", + &ipv6prefix_s)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX"); GNUNET_SCHEDULER_shutdown (); @@ -3011,14 +2957,16 @@ run (void *cls, return; } vpn_argv[3] = ipv6prefix_s; - if ( (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (cfg, "VPN", - "IPV6PREFIX", - &ipv6prefix)) || - (ipv6prefix >= 127) ) + if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, + "VPN", + "IPV6PREFIX", + &ipv6prefix)) || + (ipv6prefix >= 127)) { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", - _("Must specify valid IPv6 mask")); + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "VPN", + "IPV4MASK", + _ ("Must specify valid IPv6 mask")); GNUNET_SCHEDULER_shutdown (); return; } @@ -3026,33 +2974,40 @@ run (void *cls, else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("IPv6 support disabled as this system does not support IPv6\n")); + _ ( + "IPv6 support disabled as this system does not support IPv6\n")); vpn_argv[2] = GNUNET_strdup ("-"); vpn_argv[3] = GNUNET_strdup ("-"); } if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET)) { ipv4addr = NULL; - if ( (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", - &ipv4addr) || - (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) + if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + "vpn", + "IPV4ADDR", + &ipv4addr) || + (1 != inet_pton (AF_INET, ipv4addr, &v4)))) { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", - _("Must specify valid IPv4 address")); + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "VPN", + "IPV4ADDR", + _ ("Must specify valid IPv4 address")); GNUNET_SCHEDULER_shutdown (); GNUNET_free_non_null (ipv4addr); return; } vpn_argv[4] = ipv4addr; ipv4mask = NULL; - if ( (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK", - &ipv4mask) || - (1 != inet_pton (AF_INET, ipv4mask, &v4))) ) + if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + "vpn", + "IPV4MASK", + &ipv4mask) || + (1 != inet_pton (AF_INET, ipv4mask, &v4)))) { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4MASK", - _("Must specify valid IPv4 mask")); + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + "VPN", + "IPV4MASK", + _ ("Must specify valid IPv4 mask")); GNUNET_SCHEDULER_shutdown (); GNUNET_free_non_null (ipv4mask); return; @@ -3062,41 +3017,44 @@ run (void *cls, else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("IPv4 support disabled as this system does not support IPv4\n")); + _ ( + "IPv4 support disabled as this system does not support IPv4\n")); vpn_argv[4] = GNUNET_strdup ("-"); vpn_argv[5] = GNUNET_strdup ("-"); } vpn_argv[6] = NULL; cadet_handle = GNUNET_CADET_connect (cfg_); - // FIXME never opens ports??? + // FIXME never opens ports??? helper_handle = GNUNET_HELPER_start (GNUNET_NO, - "gnunet-helper-vpn", vpn_argv, - &message_token, NULL, NULL); - GNUNET_SCHEDULER_add_shutdown (&cleanup, - NULL); + "gnunet-helper-vpn", + vpn_argv, + &message_token, + NULL, + NULL); + GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN -("vpn", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_var_size (client_redirect_to_ip, - GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, - struct RedirectToIpRequestMessage, - NULL), - GNUNET_MQ_hd_fixed_size (client_redirect_to_service, - GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, - struct RedirectToServiceRequestMessage, - NULL), - GNUNET_MQ_handler_end ()); +GNUNET_SERVICE_MAIN ( + "vpn", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_var_size (client_redirect_to_ip, + GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, + struct RedirectToIpRequestMessage, + NULL), + GNUNET_MQ_hd_fixed_size (client_redirect_to_service, + GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, + struct RedirectToServiceRequestMessage, + NULL), + GNUNET_MQ_handler_end ()); /* end of gnunet-service-vpn.c */ -- cgit v1.2.3