From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/cadet/gnunet-service-cadet.c | 1174 +++++++++++++++++++------------------- 1 file changed, 586 insertions(+), 588 deletions(-) (limited to 'src/cadet/gnunet-service-cadet.c') diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index 209f7d392..a06cd184f 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file cadet/gnunet-service-cadet.c @@ -46,14 +46,13 @@ #include "gnunet-service-cadet_peer.h" #include "gnunet-service-cadet_paths.h" -#define LOG(level, ...) GNUNET_log (level,__VA_ARGS__) +#define LOG(level, ...) GNUNET_log(level, __VA_ARGS__) /** * Struct containing information about a client of the service */ -struct CadetClient -{ +struct CadetClient { /** * Linked list next */ @@ -202,11 +201,11 @@ unsigned long long drop_percent; * @param env envelope with the message */ void -GSC_send_to_client (struct CadetClient *c, - struct GNUNET_MQ_Envelope *env) +GSC_send_to_client(struct CadetClient *c, + struct GNUNET_MQ_Envelope *env) { - GNUNET_MQ_send (c->mq, - env); + GNUNET_MQ_send(c->mq, + env); } @@ -217,14 +216,14 @@ GSC_send_to_client (struct CadetClient *c, * @return string for debugging */ const char * -GSC_2s (struct CadetClient *c) +GSC_2s(struct CadetClient *c) { static char buf[32]; - GNUNET_snprintf (buf, - sizeof (buf), - "Client(%u)", - c->id); + GNUNET_snprintf(buf, + sizeof(buf), + "Client(%u)", + c->id); return buf; } @@ -237,11 +236,11 @@ GSC_2s (struct CadetClient *c) * @return NULL if no such channel exists */ static struct CadetChannel * -lookup_channel (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber ccn) +lookup_channel(struct CadetClient *c, + struct GNUNET_CADET_ClientChannelNumber ccn) { - return GNUNET_CONTAINER_multihashmap32_get (c->channels, - ntohl (ccn.channel_of_client)); + return GNUNET_CONTAINER_multihashmap32_get(c->channels, + ntohl(ccn.channel_of_client)); } @@ -252,23 +251,23 @@ lookup_channel (struct CadetClient *c, * @param c client handle */ static struct GNUNET_CADET_ClientChannelNumber -client_get_next_ccn (struct CadetClient *c) +client_get_next_ccn(struct CadetClient *c) { struct GNUNET_CADET_ClientChannelNumber ccn = c->next_ccn; /* increment until we have a free one... */ while (NULL != - lookup_channel (c, - ccn)) - { - ccn.channel_of_client - = htonl (1 + (ntohl (ccn.channel_of_client))); - if (ntohl (ccn.channel_of_client) >= - GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) - ccn.channel_of_client = htonl (0); - } + lookup_channel(c, + ccn)) + { + ccn.channel_of_client + = htonl(1 + (ntohl(ccn.channel_of_client))); + if (ntohl(ccn.channel_of_client) >= + GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + ccn.channel_of_client = htonl(0); + } c->next_ccn.channel_of_client - = htonl (1 + (ntohl (ccn.channel_of_client))); + = htonl(1 + (ntohl(ccn.channel_of_client))); return ccn; } @@ -286,38 +285,38 @@ client_get_next_ccn (struct CadetClient *c) * @return local channel number assigned to the new client */ struct GNUNET_CADET_ClientChannelNumber -GSC_bind (struct CadetClient *c, - struct CadetChannel *ch, - struct CadetPeer *dest, - const struct GNUNET_HashCode *port, - uint32_t options) +GSC_bind(struct CadetClient *c, + struct CadetChannel *ch, + struct CadetPeer *dest, + const struct GNUNET_HashCode *port, + uint32_t options) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalChannelCreateMessage *cm; struct GNUNET_CADET_ClientChannelNumber ccn; - ccn = client_get_next_ccn (c); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_put (c->channels, - ntohl (ccn.channel_of_client), - ch, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Accepting incoming %s from %s on open port %s (%u), assigning ccn %X\n", - GCCH_2s (ch), - GCP_2s (dest), - GNUNET_h2s (port), - (uint32_t) ntohl (options), - (uint32_t) ntohl (ccn.channel_of_client)); + ccn = client_get_next_ccn(c); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_put(c->channels, + ntohl(ccn.channel_of_client), + ch, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Accepting incoming %s from %s on open port %s (%u), assigning ccn %X\n", + GCCH_2s(ch), + GCP_2s(dest), + GNUNET_h2s(port), + (uint32_t)ntohl(options), + (uint32_t)ntohl(ccn.channel_of_client)); /* notify local client about incoming connection! */ - env = GNUNET_MQ_msg (cm, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); + env = GNUNET_MQ_msg(cm, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); cm->ccn = ccn; cm->port = *port; - cm->opt = htonl (options); - cm->peer = *GCP_get_id (dest); - GSC_send_to_client (c, - env); + cm->opt = htonl(options); + cm->peer = *GCP_get_id(dest); + GSC_send_to_client(c, + env); return ccn; } @@ -332,16 +331,16 @@ GSC_bind (struct CadetClient *c, * @return #GNUNET_OK (iterate over all entries) */ static int -destroy_tunnels_now (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +destroy_tunnels_now(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CadetPeer *cp = value; - struct CadetTunnel *t = GCP_get_tunnel (cp, - GNUNET_NO); + struct CadetTunnel *t = GCP_get_tunnel(cp, + GNUNET_NO); if (NULL != t) - GCT_destroy_tunnel_now (t); + GCT_destroy_tunnel_now(t); return GNUNET_OK; } @@ -356,13 +355,13 @@ destroy_tunnels_now (void *cls, * @return #GNUNET_OK (iterate over all entries) */ static int -destroy_paths_now (void *cls, - const struct GNUNET_PeerIdentity *pid, - void *value) +destroy_paths_now(void *cls, + const struct GNUNET_PeerIdentity *pid, + void *value) { struct CadetPeer *cp = value; - GCP_drop_owned_paths (cp); + GCP_drop_owned_paths(cp); return GNUNET_OK; } @@ -371,50 +370,50 @@ destroy_paths_now (void *cls, * Shutdown everything once the clients have disconnected. */ static void -shutdown_rest () +shutdown_rest() { if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, - GNUNET_NO); - stats = NULL; - } + { + GNUNET_STATISTICS_destroy(stats, + GNUNET_NO); + stats = NULL; + } /* Destroy tunnels. Note that all channels must be destroyed first! */ - GCP_iterate_all (&destroy_tunnels_now, - NULL); + GCP_iterate_all(&destroy_tunnels_now, + NULL); /* All tunnels, channels, connections and CORE must be down before this point. */ - GCP_iterate_all (&destroy_paths_now, - NULL); + GCP_iterate_all(&destroy_paths_now, + NULL); /* All paths, tunnels, channels, connections and CORE must be down before this point. */ - GCP_destroy_all_peers (); + GCP_destroy_all_peers(); if (NULL != open_ports) - { - GNUNET_CONTAINER_multihashmap_destroy (open_ports); - open_ports = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy(open_ports); + open_ports = NULL; + } if (NULL != loose_channels) - { - GNUNET_CONTAINER_multihashmap_destroy (loose_channels); - loose_channels = NULL; - } + { + GNUNET_CONTAINER_multihashmap_destroy(loose_channels); + loose_channels = NULL; + } if (NULL != peers) - { - GNUNET_CONTAINER_multipeermap_destroy (peers); - peers = NULL; - } + { + GNUNET_CONTAINER_multipeermap_destroy(peers); + peers = NULL; + } if (NULL != connections) - { - GNUNET_CONTAINER_multishortmap_destroy (connections); - connections = NULL; - } + { + GNUNET_CONTAINER_multishortmap_destroy(connections); + connections = NULL; + } if (NULL != ats_ch) - { - GNUNET_ATS_connectivity_done (ats_ch); - ats_ch = NULL; - } - GCD_shutdown (); - GCH_shutdown (); - GNUNET_free_non_null (my_private_key); + { + GNUNET_ATS_connectivity_done(ats_ch); + ats_ch = NULL; + } + GCD_shutdown(); + GCH_shutdown(); + GNUNET_free_non_null(my_private_key); my_private_key = NULL; } @@ -425,14 +424,14 @@ shutdown_rest () * @param cls unused */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Shutting down\n"); shutting_down = GNUNET_YES; - GCO_shutdown (); + GCO_shutdown(); if (NULL == clients_head) - shutdown_rest (); + shutdown_rest(); } @@ -446,20 +445,20 @@ shutdown_task (void *cls) * @return #GNUNET_YES (iterate over all such channels) */ static int -bind_loose_channel (void *cls, - const struct GNUNET_HashCode *port, - void *value) +bind_loose_channel(void *cls, + const struct GNUNET_HashCode *port, + void *value) { struct OpenPort *op = cls; struct CadetChannel *ch = value; - GCCH_bind (ch, - op->c, - &op->port); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (loose_channels, - &op->h_port, - ch)); + GCCH_bind(ch, + op->c, + &op->port); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(loose_channels, + &op->h_port, + ch)); return GNUNET_YES; } @@ -474,44 +473,44 @@ bind_loose_channel (void *cls, * @param pmsg The actual message. */ static void -handle_port_open (void *cls, - const struct GNUNET_CADET_PortMessage *pmsg) +handle_port_open(void *cls, + const struct GNUNET_CADET_PortMessage *pmsg) { struct CadetClient *c = cls; struct OpenPort *op; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Open port %s requested by %s\n", - GNUNET_h2s (&pmsg->port), - GSC_2s (c)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Open port %s requested by %s\n", + GNUNET_h2s(&pmsg->port), + GSC_2s(c)); if (NULL == c->ports) - c->ports = GNUNET_CONTAINER_multihashmap_create (4, - GNUNET_NO); - op = GNUNET_new (struct OpenPort); + c->ports = GNUNET_CONTAINER_multihashmap_create(4, + GNUNET_NO); + op = GNUNET_new(struct OpenPort); op->c = c; op->port = pmsg->port; - GCCH_hash_port (&op->h_port, - &pmsg->port, - &my_full_id); + GCCH_hash_port(&op->h_port, + &pmsg->port, + &my_full_id); if (GNUNET_OK != - GNUNET_CONTAINER_multihashmap_put (c->ports, - &op->port, - op, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - (void) GNUNET_CONTAINER_multihashmap_put (open_ports, - &op->h_port, - op, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels, - &op->h_port, - &bind_loose_channel, - op); - GNUNET_SERVICE_client_continue (c->client); + GNUNET_CONTAINER_multihashmap_put(c->ports, + &op->port, + op, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + (void)GNUNET_CONTAINER_multihashmap_put(open_ports, + &op->h_port, + op, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_CONTAINER_multihashmap_get_multiple(loose_channels, + &op->h_port, + &bind_loose_channel, + op); + GNUNET_SERVICE_client_continue(c->client); } @@ -525,41 +524,41 @@ handle_port_open (void *cls, * @param pmsg The actual message. */ static void -handle_port_close (void *cls, - const struct GNUNET_CADET_PortMessage *pmsg) +handle_port_close(void *cls, + const struct GNUNET_CADET_PortMessage *pmsg) { struct CadetClient *c = cls; struct OpenPort *op; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Closing port %s as requested by %s\n", - GNUNET_h2s (&pmsg->port), - GSC_2s (c)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Closing port %s as requested by %s\n", + GNUNET_h2s(&pmsg->port), + GSC_2s(c)); if (NULL == c->ports) - { - /* Client closed a port despite _never_ having opened one? */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - op = GNUNET_CONTAINER_multihashmap_get (c->ports, - &pmsg->port); + { + /* Client closed a port despite _never_ having opened one? */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + op = GNUNET_CONTAINER_multihashmap_get(c->ports, + &pmsg->port); if (NULL == op) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (c->ports, - &op->port, - op)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (open_ports, - &op->h_port, - op)); - GNUNET_free (op); - GNUNET_SERVICE_client_continue (c->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(c->ports, + &op->port, + op)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(open_ports, + &op->h_port, + op)); + GNUNET_free(op); + GNUNET_SERVICE_client_continue(c->client); } @@ -570,54 +569,54 @@ handle_port_close (void *cls, * @param tcm The actual message. */ static void -handle_channel_create (void *cls, - const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) +handle_channel_create(void *cls, + const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) { struct CadetClient *c = cls; struct CadetChannel *ch; - if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) - { - /* Channel ID not in allowed range. */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - ch = lookup_channel (c, - tcm->ccn); + if (ntohl(tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) + { + /* Channel ID not in allowed range. */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + ch = lookup_channel(c, + tcm->ccn); if (NULL != ch) - { - /* Channel ID already in use. Not allowed. */ - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "New channel to %s at port %s requested by %s\n", - GNUNET_i2s (&tcm->peer), - GNUNET_h2s (&tcm->port), - GSC_2s (c)); + { + /* Channel ID already in use. Not allowed. */ + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "New channel to %s at port %s requested by %s\n", + GNUNET_i2s(&tcm->peer), + GNUNET_h2s(&tcm->port), + GSC_2s(c)); /* Create channel */ - ch = GCCH_channel_local_new (c, - tcm->ccn, - GCP_get (&tcm->peer, - GNUNET_YES), - &tcm->port, - ntohl (tcm->opt)); + ch = GCCH_channel_local_new(c, + tcm->ccn, + GCP_get(&tcm->peer, + GNUNET_YES), + &tcm->port, + ntohl(tcm->opt)); if (NULL == ch) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_put (c->channels, - ntohl (tcm->ccn.channel_of_client), - ch, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - - GNUNET_SERVICE_client_continue (c->client); + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_put(c->channels, + ntohl(tcm->ccn.channel_of_client), + ch, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + + GNUNET_SERVICE_client_continue(c->client); } @@ -628,37 +627,37 @@ handle_channel_create (void *cls, * @param msg the actual message */ static void -handle_channel_destroy (void *cls, - const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) +handle_channel_destroy(void *cls, + const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) { struct CadetClient *c = cls; struct CadetChannel *ch; - ch = lookup_channel (c, - msg->ccn); + ch = lookup_channel(c, + msg->ccn); if (NULL == ch) - { - /* Client attempted to destroy unknown channel. - Can happen if the other side went down at the same time.*/ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "%s tried to destroy unknown channel %X\n", - GSC_2s(c), - (uint32_t) ntohl (msg->ccn.channel_of_client)); - GNUNET_SERVICE_client_continue (c->client); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "%s is destroying %s\n", - GSC_2s(c), - GCCH_2s (ch)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->channels, - ntohl (msg->ccn.channel_of_client), - ch)); - GCCH_channel_local_destroy (ch, - c, - msg->ccn); - GNUNET_SERVICE_client_continue (c->client); + { + /* Client attempted to destroy unknown channel. + Can happen if the other side went down at the same time.*/ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "%s tried to destroy unknown channel %X\n", + GSC_2s(c), + (uint32_t)ntohl(msg->ccn.channel_of_client)); + GNUNET_SERVICE_client_continue(c->client); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "%s is destroying %s\n", + GSC_2s(c), + GCCH_2s(ch)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(c->channels, + ntohl(msg->ccn.channel_of_client), + ch)); + GCCH_channel_local_destroy(ch, + c, + msg->ccn); + GNUNET_SERVICE_client_continue(c->client); } @@ -670,8 +669,8 @@ handle_channel_destroy (void *cls, * @return #GNUNET_OK if @a msg is OK, #GNUNET_SYSERR if not */ static int -check_local_data (void *cls, - const struct GNUNET_CADET_LocalData *msg) +check_local_data(void *cls, + const struct GNUNET_CADET_LocalData *msg) { size_t payload_size; size_t payload_claimed_size; @@ -684,36 +683,36 @@ check_local_data (void *cls, cadet_api will likely no more, so we could then simplify this mess again. */ /* Sanity check for message size */ - payload_size = ntohs (msg->header.size) - sizeof (*msg); - buf = (const char *) &msg[1]; - while (payload_size >= sizeof (struct GNUNET_MessageHeader)) - { - /* need to memcpy() for alignment */ - GNUNET_memcpy (&pa, - buf, - sizeof (pa)); - payload_claimed_size = ntohs (pa.size); - if ( (payload_size < payload_claimed_size) || - (payload_claimed_size < sizeof (struct GNUNET_MessageHeader)) || - (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size) ) + payload_size = ntohs(msg->header.size) - sizeof(*msg); + buf = (const char *)&msg[1]; + while (payload_size >= sizeof(struct GNUNET_MessageHeader)) { - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Local data of %u total size had sub-message %u at %u with %u bytes\n", - ntohs (msg->header.size), - ntohs (pa.type), - (unsigned int) (buf - (const char *) &msg[1]), - (unsigned int) payload_claimed_size); - return GNUNET_SYSERR; + /* need to memcpy() for alignment */ + GNUNET_memcpy(&pa, + buf, + sizeof(pa)); + payload_claimed_size = ntohs(pa.size); + if ((payload_size < payload_claimed_size) || + (payload_claimed_size < sizeof(struct GNUNET_MessageHeader)) || + (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size)) + { + GNUNET_break(0); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Local data of %u total size had sub-message %u at %u with %u bytes\n", + ntohs(msg->header.size), + ntohs(pa.type), + (unsigned int)(buf - (const char *)&msg[1]), + (unsigned int)payload_claimed_size); + return GNUNET_SYSERR; + } + payload_size -= payload_claimed_size; + buf += payload_claimed_size; } - payload_size -= payload_claimed_size; - buf += payload_claimed_size; - } if (0 != payload_size) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } + { + GNUNET_break_op(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -726,47 +725,47 @@ check_local_data (void *cls, * @param msg the actual message */ static void -handle_local_data (void *cls, - const struct GNUNET_CADET_LocalData *msg) +handle_local_data(void *cls, + const struct GNUNET_CADET_LocalData *msg) { struct CadetClient *c = cls; struct CadetChannel *ch; size_t payload_size; const char *buf; - ch = lookup_channel (c, - msg->ccn); + ch = lookup_channel(c, + msg->ccn); if (NULL == ch) - { - /* Channel does not exist (anymore) */ - LOG (GNUNET_ERROR_TYPE_WARNING, - "Dropping payload for channel %u from client (channel unknown, other endpoint may have disconnected)\n", - (unsigned int) ntohl (msg->ccn.channel_of_client)); - GNUNET_SERVICE_client_continue (c->client); - return; - } - payload_size = ntohs (msg->header.size) - sizeof (*msg); - GNUNET_STATISTICS_update (stats, - "# payload received from clients", - payload_size, - GNUNET_NO); - buf = (const char *) &msg[1]; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received %u bytes payload from %s for %s\n", - (unsigned int) payload_size, - GSC_2s (c), - GCCH_2s (ch)); + { + /* Channel does not exist (anymore) */ + LOG(GNUNET_ERROR_TYPE_WARNING, + "Dropping payload for channel %u from client (channel unknown, other endpoint may have disconnected)\n", + (unsigned int)ntohl(msg->ccn.channel_of_client)); + GNUNET_SERVICE_client_continue(c->client); + return; + } + payload_size = ntohs(msg->header.size) - sizeof(*msg); + GNUNET_STATISTICS_update(stats, + "# payload received from clients", + payload_size, + GNUNET_NO); + buf = (const char *)&msg[1]; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received %u bytes payload from %s for %s\n", + (unsigned int)payload_size, + GSC_2s(c), + GCCH_2s(ch)); if (GNUNET_OK != - GCCH_handle_local_data (ch, - msg->ccn, - buf, - payload_size)) - { - GNUNET_break (0); - GNUNET_SERVICE_client_drop (c->client); - return; - } - GNUNET_SERVICE_client_continue (c->client); + GCCH_handle_local_data(ch, + msg->ccn, + buf, + payload_size)) + { + GNUNET_break(0); + GNUNET_SERVICE_client_drop(c->client); + return; + } + GNUNET_SERVICE_client_continue(c->client); } @@ -777,30 +776,30 @@ handle_local_data (void *cls, * @param msg The actual message. */ static void -handle_local_ack (void *cls, - const struct GNUNET_CADET_LocalAck *msg) +handle_local_ack(void *cls, + const struct GNUNET_CADET_LocalAck *msg) { struct CadetClient *c = cls; struct CadetChannel *ch; - ch = lookup_channel (c, - msg->ccn); + ch = lookup_channel(c, + msg->ccn); if (NULL == ch) - { - /* Channel does not exist (anymore) */ - LOG (GNUNET_ERROR_TYPE_WARNING, - "Ignoring local ACK for channel %u from client (channel unknown, other endpoint may have disconnected)\n", - (unsigned int) ntohl (msg->ccn.channel_of_client)); - GNUNET_SERVICE_client_continue (c->client); - return; - } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Got a local ACK from %s for %s\n", - GSC_2s(c), - GCCH_2s (ch)); - GCCH_handle_local_ack (ch, - msg->ccn); - GNUNET_SERVICE_client_continue (c->client); + { + /* Channel does not exist (anymore) */ + LOG(GNUNET_ERROR_TYPE_WARNING, + "Ignoring local ACK for channel %u from client (channel unknown, other endpoint may have disconnected)\n", + (unsigned int)ntohl(msg->ccn.channel_of_client)); + GNUNET_SERVICE_client_continue(c->client); + return; + } + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Got a local ACK from %s for %s\n", + GSC_2s(c), + GCCH_2s(ch)); + GCCH_handle_local_ack(ch, + msg->ccn); + GNUNET_SERVICE_client_continue(c->client); } @@ -813,24 +812,24 @@ handle_local_ack (void *cls, * @return #GNUNET_YES, to keep iterating. */ static int -get_all_peers_iterator (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +get_all_peers_iterator(void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct CadetClient *c = cls; struct CadetPeer *p = value; struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalInfoPeers *msg; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS); msg->destination = *peer; - msg->paths = htons (GCP_count_paths (p)); - msg->tunnel = htons (NULL != GCP_get_tunnel (p, - GNUNET_NO)); - msg->best_path_length = htonl (0); // FIXME: get length of shortest known path! - GNUNET_MQ_send (c->mq, - env); + msg->paths = htons(GCP_count_paths(p)); + msg->tunnel = htons(NULL != GCP_get_tunnel(p, + GNUNET_NO)); + msg->best_path_length = htonl(0); // FIXME: get length of shortest known path! + GNUNET_MQ_send(c->mq, + env); return GNUNET_YES; } @@ -842,20 +841,20 @@ get_all_peers_iterator (void *cls, * @param message The actual message. */ static void -handle_get_peers (void *cls, - const struct GNUNET_MessageHeader *message) +handle_get_peers(void *cls, + const struct GNUNET_MessageHeader *message) { struct CadetClient *c = cls; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *reply; - GCP_iterate_all (&get_all_peers_iterator, - c); - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END); - GNUNET_MQ_send (c->mq, - env); - GNUNET_SERVICE_client_continue (c->client); + GCP_iterate_all(&get_all_peers_iterator, + c); + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END); + GNUNET_MQ_send(c->mq, + env); + GNUNET_SERVICE_client_continue(c->client); } @@ -870,9 +869,9 @@ handle_get_peers (void *cls, * #GNUNET_NO otherwise. */ static int -path_info_iterator (void *cls, - struct CadetPeerPath *path, - unsigned int off) +path_info_iterator(void *cls, + struct CadetPeerPath *path, + unsigned int off) { struct GNUNET_MQ_Handle *mq = cls; struct GNUNET_MQ_Envelope *env; @@ -881,36 +880,36 @@ path_info_iterator (void *cls, size_t path_size; unsigned int path_length; - path_length = GCPP_get_length (path); - path_size = sizeof (struct GNUNET_PeerIdentity) * path_length; - if (sizeof (*resp) + path_size > UINT16_MAX) - { - /* try just giving the relevant path */ - path_length = GNUNET_MIN ((UINT16_MAX - sizeof (*resp)) / sizeof (struct GNUNET_PeerIdentity), - off); - path_size = sizeof (struct GNUNET_PeerIdentity) * path_length; - } - if (sizeof (*resp) + path_size > UINT16_MAX) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Path of %u entries is too long for info message\n", - path_length); - return GNUNET_YES; - } - env = GNUNET_MQ_msg_extra (resp, - path_size, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH); - id = (struct GNUNET_PeerIdentity *) &resp[1]; + path_length = GCPP_get_length(path); + path_size = sizeof(struct GNUNET_PeerIdentity) * path_length; + if (sizeof(*resp) + path_size > UINT16_MAX) + { + /* try just giving the relevant path */ + path_length = GNUNET_MIN((UINT16_MAX - sizeof(*resp)) / sizeof(struct GNUNET_PeerIdentity), + off); + path_size = sizeof(struct GNUNET_PeerIdentity) * path_length; + } + if (sizeof(*resp) + path_size > UINT16_MAX) + { + LOG(GNUNET_ERROR_TYPE_WARNING, + "Path of %u entries is too long for info message\n", + path_length); + return GNUNET_YES; + } + env = GNUNET_MQ_msg_extra(resp, + path_size, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH); + id = (struct GNUNET_PeerIdentity *)&resp[1]; /* Don't copy first peer. First peer is always the local one. Last * peer is always the destination (leave as 0, EOL). */ for (unsigned int i = 0; i < path_length; i++) - id[i] = *GCP_get_id (GCPP_get_peer_at_offset (path, - i)); - resp->off = htonl (off); - GNUNET_MQ_send (mq, - env); + id[i] = *GCP_get_id(GCPP_get_peer_at_offset(path, + i)); + resp->off = htonl(off); + GNUNET_MQ_send(mq, + env); return GNUNET_YES; } @@ -922,25 +921,25 @@ path_info_iterator (void *cls, * @param msg The actual message. */ static void -handle_show_path (void *cls, - const struct GNUNET_CADET_RequestPathInfoMessage *msg) +handle_show_path(void *cls, + const struct GNUNET_CADET_RequestPathInfoMessage *msg) { struct CadetClient *c = cls; struct CadetPeer *p; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *resp; - p = GCP_get (&msg->peer, - GNUNET_NO); + p = GCP_get(&msg->peer, + GNUNET_NO); if (NULL != p) - GCP_iterate_indirect_paths (p, - &path_info_iterator, - c->mq); - env = GNUNET_MQ_msg (resp, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END); - GNUNET_MQ_send (c->mq, - env); - GNUNET_SERVICE_client_continue (c->client); + GCP_iterate_indirect_paths(p, + &path_info_iterator, + c->mq); + env = GNUNET_MQ_msg(resp, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END); + GNUNET_MQ_send(c->mq, + env); + GNUNET_SERVICE_client_continue(c->client); } @@ -953,9 +952,9 @@ handle_show_path (void *cls, * @return #GNUNET_YES, to keep iterating. */ static int -get_all_tunnels_iterator (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *value) +get_all_tunnels_iterator(void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) { struct CadetClient *c = cls; struct CadetPeer *p = value; @@ -963,19 +962,19 @@ get_all_tunnels_iterator (void *cls, struct GNUNET_CADET_LocalInfoTunnel *msg; struct CadetTunnel *t; - t = GCP_get_tunnel (p, - GNUNET_NO); + t = GCP_get_tunnel(p, + GNUNET_NO); if (NULL == t) return GNUNET_YES; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); + env = GNUNET_MQ_msg(msg, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); msg->destination = *peer; - msg->channels = htonl (GCT_count_channels (t)); - msg->connections = htonl (GCT_count_any_connections (t)); - msg->cstate = htons (0); - msg->estate = htons ((uint16_t) GCT_get_estate (t)); - GNUNET_MQ_send (c->mq, - env); + msg->channels = htonl(GCT_count_channels(t)); + msg->connections = htonl(GCT_count_any_connections(t)); + msg->cstate = htons(0); + msg->estate = htons((uint16_t)GCT_get_estate(t)); + GNUNET_MQ_send(c->mq, + env); return GNUNET_YES; } @@ -987,20 +986,20 @@ get_all_tunnels_iterator (void *cls, * @param message The actual message. */ static void -handle_info_tunnels (void *cls, - const struct GNUNET_MessageHeader *message) +handle_info_tunnels(void *cls, + const struct GNUNET_MessageHeader *message) { struct CadetClient *c = cls; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *reply; - GCP_iterate_all (&get_all_tunnels_iterator, - c); - env = GNUNET_MQ_msg (reply, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END); - GNUNET_MQ_send (c->mq, - env); - GNUNET_SERVICE_client_continue (c->client); + GCP_iterate_all(&get_all_tunnels_iterator, + c); + env = GNUNET_MQ_msg(reply, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END); + GNUNET_MQ_send(c->mq, + env); + GNUNET_SERVICE_client_continue(c->client); } @@ -1013,28 +1012,28 @@ handle_info_tunnels (void *cls, * @return @a c */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { struct CadetClient *c; - c = GNUNET_new (struct CadetClient); + c = GNUNET_new(struct CadetClient); c->client = client; c->mq = mq; c->id = next_client_id++; /* overflow not important: just for debug */ c->channels - = GNUNET_CONTAINER_multihashmap32_create (32); - GNUNET_CONTAINER_DLL_insert (clients_head, - clients_tail, - c); - GNUNET_STATISTICS_update (stats, - "# clients", - +1, - GNUNET_NO); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "%s connected\n", - GSC_2s (c)); + = GNUNET_CONTAINER_multihashmap32_create(32); + GNUNET_CONTAINER_DLL_insert(clients_head, + clients_tail, + c); + GNUNET_STATISTICS_update(stats, + "# clients", + +1, + GNUNET_NO); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "%s connected\n", + GSC_2s(c)); return c; } @@ -1047,22 +1046,22 @@ client_connect_cb (void *cls, * @param ch the channel object */ void -GSC_handle_remote_channel_destroy (struct CadetClient *c, - struct GNUNET_CADET_ClientChannelNumber ccn, - struct CadetChannel *ch) +GSC_handle_remote_channel_destroy(struct CadetClient *c, + struct GNUNET_CADET_ClientChannelNumber ccn, + struct CadetChannel *ch) { struct GNUNET_MQ_Envelope *env; struct GNUNET_CADET_LocalChannelDestroyMessage *tdm; - env = GNUNET_MQ_msg (tdm, - GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); + env = GNUNET_MQ_msg(tdm, + GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); tdm->ccn = ccn; - GSC_send_to_client (c, - env); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->channels, - ntohl (ccn.channel_of_client), - ch)); + GSC_send_to_client(c, + env); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(c->channels, + ntohl(ccn.channel_of_client), + ch)); } @@ -1074,13 +1073,13 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c, * @param ch the channel that was lost */ void -GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port, - struct CadetChannel *ch) +GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port, + struct CadetChannel *ch) { - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (loose_channels, - h_port, - ch)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(loose_channels, + h_port, + ch)); } @@ -1093,26 +1092,26 @@ GSC_drop_loose_channel (const struct GNUNET_HashCode *h_port, * @return #GNUNET_OK, keep iterating. */ static int -channel_destroy_iterator (void *cls, - uint32_t key, - void *value) +channel_destroy_iterator(void *cls, + uint32_t key, + void *value) { struct CadetClient *c = cls; struct GNUNET_CADET_ClientChannelNumber ccn; struct CadetChannel *ch = value; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying %s, due to %s disconnecting.\n", - GCCH_2s (ch), - GSC_2s (c)); - ccn.channel_of_client = htonl (key); - GCCH_channel_local_destroy (ch, - c, - ccn); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap32_remove (c->channels, - key, - ch)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Destroying %s, due to %s disconnecting.\n", + GCCH_2s(ch), + GSC_2s(c)); + ccn.channel_of_client = htonl(key); + GCCH_channel_local_destroy(ch, + c, + ccn); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap32_remove(c->channels, + key, + ch)); return GNUNET_OK; } @@ -1126,27 +1125,27 @@ channel_destroy_iterator (void *cls, * @return #GNUNET_OK, keep iterating. */ static int -client_release_ports (void *cls, - const struct GNUNET_HashCode *port, - void *value) +client_release_ports(void *cls, + const struct GNUNET_HashCode *port, + void *value) { struct CadetClient *c = cls; struct OpenPort *op = value; - GNUNET_assert (c == op->c); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Closing port %s due to %s disconnect.\n", - GNUNET_h2s (port), - GSC_2s (c)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (open_ports, - &op->h_port, - op)); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (c->ports, - port, - op)); - GNUNET_free (op); + GNUNET_assert(c == op->c); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Closing port %s due to %s disconnect.\n", + GNUNET_h2s(port), + GSC_2s(c)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(open_ports, + &op->h_port, + op)); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(c->ports, + port, + op)); + GNUNET_free(op); return GNUNET_OK; } @@ -1159,42 +1158,42 @@ client_release_ports (void *cls, * @param internal_cls should be equal to @a c */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *internal_cls) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *internal_cls) { struct CadetClient *c = internal_cls; - GNUNET_assert (c->client == client); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "%s is disconnecting.\n", - GSC_2s (c)); + GNUNET_assert(c->client == client); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "%s is disconnecting.\n", + GSC_2s(c)); if (NULL != c->channels) - { - GNUNET_CONTAINER_multihashmap32_iterate (c->channels, - &channel_destroy_iterator, - c); - GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (c->channels)); - GNUNET_CONTAINER_multihashmap32_destroy (c->channels); - } + { + GNUNET_CONTAINER_multihashmap32_iterate(c->channels, + &channel_destroy_iterator, + c); + GNUNET_assert(0 == GNUNET_CONTAINER_multihashmap32_size(c->channels)); + GNUNET_CONTAINER_multihashmap32_destroy(c->channels); + } if (NULL != c->ports) - { - GNUNET_CONTAINER_multihashmap_iterate (c->ports, - &client_release_ports, - c); - GNUNET_CONTAINER_multihashmap_destroy (c->ports); - } - GNUNET_CONTAINER_DLL_remove (clients_head, - clients_tail, - c); - GNUNET_STATISTICS_update (stats, - "# clients", - -1, - GNUNET_NO); - GNUNET_free (c); - if ( (NULL == clients_head) && - (GNUNET_YES == shutting_down) ) - shutdown_rest (); + { + GNUNET_CONTAINER_multihashmap_iterate(c->ports, + &client_release_ports, + c); + GNUNET_CONTAINER_multihashmap_destroy(c->ports); + } + GNUNET_CONTAINER_DLL_remove(clients_head, + clients_tail, + c); + GNUNET_STATISTICS_update(stats, + "# clients", + -1, + GNUNET_NO); + GNUNET_free(c); + if ((NULL == clients_head) && + (GNUNET_YES == shutting_down)) + shutdown_rest(); } @@ -1206,93 +1205,92 @@ client_disconnect_cb (void *cls, * @param c configuration to use */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { cfg = c; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (c, - "CADET", - "RATCHET_MESSAGES", - &ratchet_messages)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, - "CADET", - "RATCHET_MESSAGES", - "needs to be a number"); - ratchet_messages = 64; - } + GNUNET_CONFIGURATION_get_value_number(c, + "CADET", + "RATCHET_MESSAGES", + &ratchet_messages)) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, + "CADET", + "RATCHET_MESSAGES", + "needs to be a number"); + ratchet_messages = 64; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (c, - "CADET", - "RATCHET_TIME", - &ratchet_time)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, - "CADET", - "RATCHET_TIME", - "need delay value"); - ratchet_time = GNUNET_TIME_UNIT_HOURS; - } + GNUNET_CONFIGURATION_get_value_time(c, + "CADET", + "RATCHET_TIME", + &ratchet_time)) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, + "CADET", + "RATCHET_TIME", + "need delay value"); + ratchet_time = GNUNET_TIME_UNIT_HOURS; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (c, - "CADET", - "REFRESH_CONNECTION_TIME", - &keepalive_period)) - { - GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, - "CADET", - "REFRESH_CONNECTION_TIME", - "need delay value"); - keepalive_period = GNUNET_TIME_UNIT_MINUTES; - } + GNUNET_CONFIGURATION_get_value_time(c, + "CADET", + "REFRESH_CONNECTION_TIME", + &keepalive_period)) + { + GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, + "CADET", + "REFRESH_CONNECTION_TIME", + "need delay value"); + keepalive_period = GNUNET_TIME_UNIT_MINUTES; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (c, - "CADET", - "DROP_PERCENT", - &drop_percent)) - { - drop_percent = 0; - } + GNUNET_CONFIGURATION_get_value_number(c, + "CADET", + "DROP_PERCENT", + &drop_percent)) + { + drop_percent = 0; + } else - { - LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); - LOG (GNUNET_ERROR_TYPE_WARNING, "Cadet is running with DROP enabled.\n"); - LOG (GNUNET_ERROR_TYPE_WARNING, "This is NOT a good idea!\n"); - LOG (GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); - LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); - } - my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c); + { + LOG(GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Cadet is running with DROP enabled.\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "This is NOT a good idea!\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); + } + my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(c); if (NULL == my_private_key) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, - &my_full_id.public_key); - stats = GNUNET_STATISTICS_create ("cadet", - c); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, - NULL); - ats_ch = GNUNET_ATS_connectivity_init (c); + { + GNUNET_break(0); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, + &my_full_id.public_key); + stats = GNUNET_STATISTICS_create("cadet", + c); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, + NULL); + ats_ch = GNUNET_ATS_connectivity_init(c); /* FIXME: optimize code to allow GNUNET_YES here! */ - open_ports = GNUNET_CONTAINER_multihashmap_create (16, - GNUNET_NO); - loose_channels = GNUNET_CONTAINER_multihashmap_create (16, - GNUNET_NO); - peers = GNUNET_CONTAINER_multipeermap_create (16, - GNUNET_YES); - connections = GNUNET_CONTAINER_multishortmap_create (256, - GNUNET_YES); - GCH_init (c); - GCD_init (c); - GCO_init (c); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "CADET started for peer %s\n", - GNUNET_i2s (&my_full_id)); - + open_ports = GNUNET_CONTAINER_multihashmap_create(16, + GNUNET_NO); + loose_channels = GNUNET_CONTAINER_multihashmap_create(16, + GNUNET_NO); + peers = GNUNET_CONTAINER_multipeermap_create(16, + GNUNET_YES); + connections = GNUNET_CONTAINER_multishortmap_create(256, + GNUNET_YES); + GCH_init(c); + GCD_init(c); + GCO_init(c); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "CADET started for peer %s\n", + GNUNET_i2s(&my_full_id)); } @@ -1300,48 +1298,48 @@ run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -("cadet", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size (port_open, + ("cadet", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size(port_open, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, struct GNUNET_CADET_PortMessage, NULL), - GNUNET_MQ_hd_fixed_size (port_close, + GNUNET_MQ_hd_fixed_size(port_close, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, struct GNUNET_CADET_PortMessage, NULL), - GNUNET_MQ_hd_fixed_size (channel_create, + GNUNET_MQ_hd_fixed_size(channel_create, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, struct GNUNET_CADET_LocalChannelCreateMessage, NULL), - GNUNET_MQ_hd_fixed_size (channel_destroy, + GNUNET_MQ_hd_fixed_size(channel_destroy, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, struct GNUNET_CADET_LocalChannelDestroyMessage, NULL), - GNUNET_MQ_hd_var_size (local_data, + GNUNET_MQ_hd_var_size(local_data, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, struct GNUNET_CADET_LocalData, NULL), - GNUNET_MQ_hd_fixed_size (local_ack, + GNUNET_MQ_hd_fixed_size(local_ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, struct GNUNET_CADET_LocalAck, NULL), - GNUNET_MQ_hd_fixed_size (get_peers, + GNUNET_MQ_hd_fixed_size(get_peers, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_hd_fixed_size (show_path, + GNUNET_MQ_hd_fixed_size(show_path, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH, struct GNUNET_CADET_RequestPathInfoMessage, NULL), - GNUNET_MQ_hd_fixed_size (info_tunnels, + GNUNET_MQ_hd_fixed_size(info_tunnels, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, struct GNUNET_MessageHeader, NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_handler_end()); /* end of gnunet-service-cadet-new.c */ -- cgit v1.2.3