summaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet.h65
-rw-r--r--src/cadet/cadet_api.c753
-rw-r--r--src/cadet/cadet_api_get_channel.c121
-rw-r--r--src/cadet/cadet_api_get_path.c145
-rw-r--r--src/cadet/cadet_api_helper.c13
-rw-r--r--src/cadet/cadet_api_list_peers.c119
-rw-r--r--src/cadet/cadet_api_list_tunnels.c121
-rw-r--r--src/cadet/cadet_protocol.h48
-rw-r--r--src/cadet/cadet_test_lib.c260
-rw-r--r--src/cadet/cadet_test_lib.h22
-rw-r--r--src/cadet/desirability_table.c34
-rw-r--r--src/cadet/gnunet-cadet-profiler.c834
-rw-r--r--src/cadet/gnunet-cadet.c685
-rw-r--r--src/cadet/gnunet-service-cadet.c1209
-rw-r--r--src/cadet/gnunet-service-cadet.h36
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c1874
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h92
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c766
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h78
-rw-r--r--src/cadet/gnunet-service-cadet_core.c1162
-rw-r--r--src/cadet/gnunet-service-cadet_core.h4
-rw-r--r--src/cadet/gnunet-service-cadet_dht.c303
-rw-r--r--src/cadet/gnunet-service-cadet_dht.h10
-rw-r--r--src/cadet/gnunet-service-cadet_hello.c89
-rw-r--r--src/cadet/gnunet-service-cadet_hello.h6
-rw-r--r--src/cadet/gnunet-service-cadet_paths.c701
-rw-r--r--src/cadet/gnunet-service-cadet_paths.h47
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c1201
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h112
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.c3506
-rw-r--r--src/cadet/gnunet-service-cadet_tunnels.h89
-rw-r--r--src/cadet/test_cadet.c1207
-rw-r--r--src/cadet/test_cadet_flow.c741
-rw-r--r--src/cadet/test_cadet_local_mq.c257
34 files changed, 8414 insertions, 8296 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index 9b2050e67..29400e39f 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -35,18 +35,18 @@ extern "C" {
#include <stdint.h>
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
#define CADET_TIMING_START \
struct GNUNET_TIME_Absolute __timestamp; \
- __timestamp = GNUNET_TIME_absolute_get()
+ __timestamp = GNUNET_TIME_absolute_get ()
#define CADET_TIMING_END \
struct GNUNET_TIME_Relative __duration; \
- __duration = GNUNET_TIME_absolute_get_duration(__timestamp); \
- LOG(GNUNET_ERROR_TYPE_INFO, \
- " %s duration %s\n", \
- __FUNCTION__, \
- GNUNET_STRINGS_relative_time_to_string(__duration, GNUNET_YES));
+ __duration = GNUNET_TIME_absolute_get_duration (__timestamp); \
+ LOG (GNUNET_ERROR_TYPE_INFO, \
+ " %s duration %s\n", \
+ __FUNCTION__, \
+ GNUNET_STRINGS_relative_time_to_string (__duration, GNUNET_YES));
#else
#define CADET_TIMING_START
#define CADET_TIMING_END
@@ -99,7 +99,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* Number uniquely identifying a channel of a client.
*/
-struct GNUNET_CADET_ClientChannelNumber {
+struct GNUNET_CADET_ClientChannelNumber
+{
/**
* Values for channel numbering.
* Local channel numbers given by the service (incoming) are
@@ -114,7 +115,8 @@ struct GNUNET_CADET_ClientChannelNumber {
/**
* Message for a client to create and destroy channels.
*/
-struct GNUNET_CADET_PortMessage {
+struct GNUNET_CADET_PortMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
* or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
@@ -133,7 +135,8 @@ struct GNUNET_CADET_PortMessage {
/**
* Message for a client to create channels.
*/
-struct GNUNET_CADET_LocalChannelCreateMessage {
+struct GNUNET_CADET_LocalChannelCreateMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
*
@@ -166,7 +169,8 @@ struct GNUNET_CADET_LocalChannelCreateMessage {
/**
* Message for or to a client to destroy tunnel.
*/
-struct GNUNET_CADET_LocalChannelDestroyMessage {
+struct GNUNET_CADET_LocalChannelDestroyMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
*/
@@ -182,7 +186,8 @@ struct GNUNET_CADET_LocalChannelDestroyMessage {
/**
* Message for cadet data traffic.
*/
-struct GNUNET_CADET_LocalData {
+struct GNUNET_CADET_LocalData
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
*/
@@ -209,7 +214,8 @@ struct GNUNET_CADET_LocalData {
* Message to allow the client send more data to the service
* (always service -> client).
*/
-struct GNUNET_CADET_LocalAck {
+struct GNUNET_CADET_LocalAck
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
*/
@@ -227,7 +233,8 @@ struct GNUNET_CADET_LocalAck {
*
* TODO: split into two messages!
*/
-struct GNUNET_CADET_LocalInfo {
+struct GNUNET_CADET_LocalInfo
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL or
* #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER
@@ -249,7 +256,8 @@ struct GNUNET_CADET_LocalInfo {
/**
* Message to inform the client about channels in the service.
*/
-struct GNUNET_CADET_RequestPathInfoMessage {
+struct GNUNET_CADET_RequestPathInfoMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH
*/
@@ -270,7 +278,8 @@ struct GNUNET_CADET_RequestPathInfoMessage {
/**
* Message to inform the client about channels in the service.
*/
-struct GNUNET_CADET_ChannelInfoMessage {
+struct GNUNET_CADET_ChannelInfoMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL.
*/
@@ -293,7 +302,8 @@ struct GNUNET_CADET_ChannelInfoMessage {
/**
* Message to as the service about information on a channel.
*/
-struct GNUNET_CADET_RequestChannelInfoMessage {
+struct GNUNET_CADET_RequestChannelInfoMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL.
*/
@@ -309,7 +319,8 @@ struct GNUNET_CADET_RequestChannelInfoMessage {
/**
* Message to inform the client about one of the paths known to the service.
*/
-struct GNUNET_CADET_LocalInfoPath {
+struct GNUNET_CADET_LocalInfoPath
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH.
*/
@@ -325,7 +336,8 @@ struct GNUNET_CADET_LocalInfoPath {
/**
* Message to inform the client about one of the peers in the service.
*/
-struct GNUNET_CADET_LocalInfoPeers {
+struct GNUNET_CADET_LocalInfoPeers
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
*/
@@ -358,7 +370,8 @@ struct GNUNET_CADET_LocalInfoPeers {
*
* TODO: split into two messages!
*/
-struct GNUNET_CADET_LocalInfoTunnel {
+struct GNUNET_CADET_LocalInfoTunnel
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL
* or #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS
@@ -406,7 +419,7 @@ GNUNET_NETWORK_STRUCT_END
* @return String representing FWD or BCK.
*/
char *
-GC_f2s(int fwd);
+GC_f2s (int fwd);
/**
@@ -418,7 +431,7 @@ GC_f2s(int fwd);
* @return True if bigger (arg1) has a higher value than smaller (arg 2).
*/
int
-GC_is_pid_bigger(uint32_t bigger, uint32_t smaller);
+GC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
/**
@@ -430,7 +443,7 @@ GC_is_pid_bigger(uint32_t bigger, uint32_t smaller);
* @return Highest ACK value from the two.
*/
uint32_t
-GC_max_pid(uint32_t a, uint32_t b);
+GC_max_pid (uint32_t a, uint32_t b);
/**
@@ -442,7 +455,7 @@ GC_max_pid(uint32_t a, uint32_t b);
* @return Lowest ACK value from the two.
*/
uint32_t
-GC_min_pid(uint32_t a, uint32_t b);
+GC_min_pid (uint32_t a, uint32_t b);
/**
@@ -455,7 +468,7 @@ GC_min_pid(uint32_t a, uint32_t b);
* @return The size of the output.
*/
size_t
-GC_bin2s(void *bin, unsigned int len, char **output);
+GC_bin2s (void *bin, unsigned int len, char **output);
/**
@@ -469,7 +482,7 @@ GC_bin2s(void *bin, unsigned int len, char **output);
* @return Human readable string description.
*/
const char *
-GC_m2s(uint16_t m);
+GC_m2s (uint16_t m);
#if 0 /* keep Emacsens' auto-indent happy */
{
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 61ff71b31..9aeedb616 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -30,12 +30,13 @@
#include "cadet.h"
#include "cadet_protocol.h"
-#define LOG(kind, ...) GNUNET_log_from(kind, "cadet-api", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "cadet-api", __VA_ARGS__)
/**
* Opaque handle to the service.
*/
-struct GNUNET_CADET_Handle {
+struct GNUNET_CADET_Handle
+{
/**
* Message queue.
*/
@@ -76,7 +77,8 @@ struct GNUNET_CADET_Handle {
/**
* Opaque handle to a channel.
*/
-struct GNUNET_CADET_Channel {
+struct GNUNET_CADET_Channel
+{
/**
* Other end of the channel.
*/
@@ -140,7 +142,8 @@ struct GNUNET_CADET_Channel {
/**
* Opaque handle to a port.
*/
-struct GNUNET_CADET_Port {
+struct GNUNET_CADET_Port
+{
/**
* Port "number"
*/
@@ -191,10 +194,10 @@ struct GNUNET_CADET_Port {
* @return The port handle if known, NULL otherwise.
*/
static struct GNUNET_CADET_Port *
-find_port(const struct GNUNET_CADET_Handle *h,
- const struct GNUNET_HashCode *hash)
+find_port (const struct GNUNET_CADET_Handle *h,
+ const struct GNUNET_HashCode *hash)
{
- return GNUNET_CONTAINER_multihashmap_get(h->ports, hash);
+ return GNUNET_CONTAINER_multihashmap_get (h->ports, hash);
}
@@ -206,11 +209,11 @@ find_port(const struct GNUNET_CADET_Handle *h,
* @return handle to the required channel or NULL if not found
*/
static struct GNUNET_CADET_Channel *
-find_channel(struct GNUNET_CADET_Handle *h,
- struct GNUNET_CADET_ClientChannelNumber ccn)
+find_channel (struct GNUNET_CADET_Handle *h,
+ struct GNUNET_CADET_ClientChannelNumber ccn)
{
- return GNUNET_CONTAINER_multihashmap32_get(h->channels,
- ntohl(ccn.channel_of_client));
+ return GNUNET_CONTAINER_multihashmap32_get (h->channels,
+ ntohl (ccn.channel_of_client));
}
@@ -222,33 +225,33 @@ find_channel(struct GNUNET_CADET_Handle *h,
* @return Handle to the created channel.
*/
static struct GNUNET_CADET_Channel *
-create_channel(struct GNUNET_CADET_Handle *h,
- const struct GNUNET_CADET_ClientChannelNumber *ccnp)
+create_channel (struct GNUNET_CADET_Handle *h,
+ const struct GNUNET_CADET_ClientChannelNumber *ccnp)
{
struct GNUNET_CADET_Channel *ch;
struct GNUNET_CADET_ClientChannelNumber ccn;
- ch = GNUNET_new(struct GNUNET_CADET_Channel);
+ ch = GNUNET_new (struct GNUNET_CADET_Channel);
ch->cadet = h;
if (NULL == ccnp)
- {
- while (NULL != find_channel(h, h->next_ccn))
- h->next_ccn.channel_of_client =
- htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI |
- (1 + ntohl(h->next_ccn.channel_of_client)));
- ccn = h->next_ccn;
- }
+ {
+ while (NULL != find_channel (h, h->next_ccn))
+ h->next_ccn.channel_of_client =
+ htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
+ | (1 + ntohl (h->next_ccn.channel_of_client)));
+ ccn = h->next_ccn;
+ }
else
- {
- ccn = *ccnp;
- }
+ {
+ ccn = *ccnp;
+ }
ch->ccn = ccn;
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap32_put(
- h->channels,
- ntohl(ch->ccn.channel_of_client),
- ch,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap32_put (
+ h->channels,
+ ntohl (ch->ccn.channel_of_client),
+ ch,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return ch;
}
@@ -264,31 +267,31 @@ create_channel(struct GNUNET_CADET_Handle *h,
* @param call_cleaner Whether to call the cleaner handler.
*/
static void
-destroy_channel(struct GNUNET_CADET_Channel *ch)
+destroy_channel (struct GNUNET_CADET_Channel *ch)
{
struct GNUNET_CADET_Handle *h = ch->cadet;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Destroying channel %X of %p\n",
- htonl(ch->ccn.channel_of_client),
- h);
- GNUNET_assert(
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying channel %X of %p\n",
+ htonl (ch->ccn.channel_of_client),
+ h);
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap32_remove(h->channels,
- ntohl(ch->ccn.channel_of_client),
- ch));
+ GNUNET_CONTAINER_multihashmap32_remove (h->channels,
+ ntohl (ch->ccn.channel_of_client),
+ ch));
if (NULL != ch->mq_cont)
- {
- GNUNET_SCHEDULER_cancel(ch->mq_cont);
- ch->mq_cont = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ch->mq_cont);
+ ch->mq_cont = NULL;
+ }
/* signal channel destruction */
if (NULL != ch->disconnects)
- ch->disconnects(ch->ctx, ch);
+ ch->disconnects (ch->ctx, ch);
if (NULL != ch->pending_env)
- GNUNET_MQ_discard(ch->pending_env);
- GNUNET_MQ_destroy(ch->mq);
- GNUNET_free(ch);
+ GNUNET_MQ_discard (ch->pending_env);
+ GNUNET_MQ_destroy (ch->mq);
+ GNUNET_free (ch);
}
@@ -299,7 +302,7 @@ destroy_channel(struct GNUNET_CADET_Channel *ch)
* @param h handle to the cadet
*/
static void
-reconnect(struct GNUNET_CADET_Handle *h);
+reconnect (struct GNUNET_CADET_Handle *h);
/**
@@ -312,17 +315,17 @@ reconnect(struct GNUNET_CADET_Handle *h);
* @return #GNUNET_OK (continue to iterate)
*/
static int
-open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
+open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
{
struct GNUNET_CADET_Handle *h = cls;
struct GNUNET_CADET_Port *port = value;
struct GNUNET_CADET_PortMessage *msg;
struct GNUNET_MQ_Envelope *env;
- (void)id;
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN);
+ (void) id;
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN);
msg->port = port->id;
- GNUNET_MQ_send(h->mq, env);
+ GNUNET_MQ_send (h->mq, env);
return GNUNET_OK;
}
@@ -334,14 +337,14 @@ open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
* @param cls closure (cadet handle)
*/
static void
-reconnect_cbk(void *cls)
+reconnect_cbk (void *cls)
{
struct GNUNET_CADET_Handle *h = cls;
h->reconnect_task = NULL;
- h->reconnect_time = GNUNET_TIME_STD_BACKOFF(h->reconnect_time);
- reconnect(h);
- GNUNET_CONTAINER_multihashmap_iterate(h->ports, &open_port_cb, h);
+ h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time);
+ reconnect (h);
+ GNUNET_CONTAINER_multihashmap_iterate (h->ports, &open_port_cb, h);
}
@@ -351,12 +354,12 @@ reconnect_cbk(void *cls)
* @param ch Channel to notify about.
*/
static void
-notify_window_size(struct GNUNET_CADET_Channel *ch)
+notify_window_size (struct GNUNET_CADET_Channel *ch)
{
if (NULL != ch->window_changes)
- ch->window_changes(ch->ctx,
- ch, /* FIXME: remove 'ch'? */
- ch->allow_send);
+ ch->window_changes (ch->ctx,
+ ch, /* FIXME: remove 'ch'? */
+ ch->allow_send);
}
@@ -366,32 +369,32 @@ notify_window_size(struct GNUNET_CADET_Channel *ch)
* @param cls Closure (channel whose mq to activate).
*/
static void
-cadet_mq_send_now(void *cls)
+cadet_mq_send_now (void *cls)
{
struct GNUNET_CADET_Channel *ch = cls;
struct GNUNET_MQ_Envelope *env = ch->pending_env;
ch->mq_cont = NULL;
if (0 == ch->allow_send)
- {
- /* how did we get here? */
- GNUNET_break(0);
- return;
- }
+ {
+ /* how did we get here? */
+ GNUNET_break (0);
+ return;
+ }
if (NULL == env)
- {
- /* how did we get here? */
- GNUNET_break(0);
- return;
- }
+ {
+ /* how did we get here? */
+ GNUNET_break (0);
+ return;
+ }
ch->allow_send--;
ch->pending_env = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending message on channel %s to CADET, new window size is %u\n",
- GNUNET_i2s(&ch->peer),
- ch->allow_send);
- GNUNET_MQ_send(ch->cadet->mq, env);
- GNUNET_MQ_impl_send_continue(ch->mq);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message on channel %s to CADET, new window size is %u\n",
+ GNUNET_i2s (&ch->peer),
+ ch->allow_send);
+ GNUNET_MQ_send (ch->cadet->mq, env);
+ GNUNET_MQ_impl_send_continue (ch->mq);
}
@@ -408,9 +411,9 @@ cadet_mq_send_now(void *cls)
* @param impl_state state of the implementation
*/
static void
-cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct GNUNET_CADET_Channel *ch = impl_state;
struct GNUNET_CADET_Handle *h = ch->cadet;
@@ -421,31 +424,31 @@ cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq,
enum GNUNET_MQ_PriorityPreferences pp;
if (NULL == h->mq)
- {
- /* We're currently reconnecting, pretend this worked */
- GNUNET_MQ_impl_send_continue(mq);
- return;
- }
- orig_env = GNUNET_MQ_get_current_envelope(mq);
- pp = GNUNET_MQ_env_get_options(orig_env);
+ {
+ /* We're currently reconnecting, pretend this worked */
+ GNUNET_MQ_impl_send_continue (mq);
+ return;
+ }
+ orig_env = GNUNET_MQ_get_current_envelope (mq);
+ pp = GNUNET_MQ_env_get_options (orig_env);
/* check message size for sanity */
- msize = ntohs(msg->size);
+ msize = ntohs (msg->size);
if (msize > GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE)
- {
- GNUNET_break(0);
- GNUNET_MQ_impl_send_continue(mq);
- return;
- }
- env = GNUNET_MQ_msg_nested_mh(cadet_msg,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
- msg);
+ {
+ GNUNET_break (0);
+ GNUNET_MQ_impl_send_continue (mq);
+ return;
+ }
+ env = GNUNET_MQ_msg_nested_mh (cadet_msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
+ msg);
cadet_msg->ccn = ch->ccn;
- cadet_msg->pp = htonl((uint32_t)pp);
- GNUNET_assert(NULL == ch->pending_env);
+ cadet_msg->pp = htonl ((uint32_t) pp);
+ GNUNET_assert (NULL == ch->pending_env);
ch->pending_env = env;
if (0 < ch->allow_send)
- ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch);
+ ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch);
}
@@ -457,11 +460,11 @@ cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq,
* @param impl_state state of the implementation
*/
static void
-cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
+cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct GNUNET_CADET_Channel *ch = impl_state;
- GNUNET_assert(mq == ch->mq);
+ GNUNET_assert (mq == ch->mq);
ch->mq = NULL;
}
@@ -475,25 +478,25 @@ cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param error error code
*/
static void
-cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
+cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_Channel *ch = cls;
if (GNUNET_MQ_ERROR_NO_MATCH == error)
- {
- /* Got a message we did not understand, still try to continue! */
- GNUNET_break_op(0);
- GNUNET_CADET_receive_done(ch);
- }
+ {
+ /* Got a message we did not understand, still try to continue! */
+ GNUNET_break_op (0);
+ GNUNET_CADET_receive_done (ch);
+ }
else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "MQ error in communication with CADET: %d\n",
- error);
- if (NULL != ch->disconnects)
- ch->disconnects(ch->ctx, ch);
- GNUNET_CADET_channel_destroy(ch);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "MQ error in communication with CADET: %d\n",
+ error);
+ if (NULL != ch->disconnects)
+ ch->disconnects (ch->ctx, ch);
+ GNUNET_CADET_channel_destroy (ch);
+ }
}
@@ -505,19 +508,19 @@ cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
* @param impl_state state specific to the implementation
*/
static void
-cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
+cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct GNUNET_CADET_Channel *ch = impl_state;
- (void)mq;
- GNUNET_assert(NULL != ch->pending_env);
- GNUNET_MQ_discard(ch->pending_env);
+ (void) mq;
+ GNUNET_assert (NULL != ch->pending_env);
+ GNUNET_MQ_discard (ch->pending_env);
ch->pending_env = NULL;
if (NULL != ch->mq_cont)
- {
- GNUNET_SCHEDULER_cancel(ch->mq_cont);
- ch->mq_cont = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ch->mq_cont);
+ ch->mq_cont = NULL;
+ }
}
@@ -528,7 +531,7 @@ cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param msg A message with the details of the new incoming channel
*/
static void
-handle_channel_created(
+handle_channel_created (
void *cls,
const struct GNUNET_CADET_LocalChannelCreateMessage *msg)
{
@@ -540,52 +543,52 @@ handle_channel_created(
ccn = msg->ccn;
port_number = &msg->port;
- if (ntohl(ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
- {
- GNUNET_break(0);
- return;
- }
- port = find_port(h, port_number);
+ if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ port = find_port (h, port_number);
if (NULL == port)
- {
- /* We could have closed the port but the service didn't know about it yet
- * This is not an error.
- */
- struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg;
- struct GNUNET_MQ_Envelope *env;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "No handler for incoming channel %X (on port %s, recently closed?)\n",
- ntohl(ccn.channel_of_client),
- GNUNET_h2s(port_number));
- env =
- GNUNET_MQ_msg(d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
- d_msg->ccn = msg->ccn;
- GNUNET_MQ_send(h->mq, env);
- return;
- }
-
- ch = create_channel(h, &ccn);
+ {
+ /* We could have closed the port but the service didn't know about it yet
+ * This is not an error.
+ */
+ struct GNUNET_CADET_LocalChannelDestroyMessage *d_msg;
+ struct GNUNET_MQ_Envelope *env;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "No handler for incoming channel %X (on port %s, recently closed?)\n",
+ ntohl (ccn.channel_of_client),
+ GNUNET_h2s (port_number));
+ env =
+ GNUNET_MQ_msg (d_msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
+ d_msg->ccn = msg->ccn;
+ GNUNET_MQ_send (h->mq, env);
+ return;
+ }
+
+ ch = create_channel (h, &ccn);
ch->peer = msg->peer;
ch->incoming_port = port;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating incoming channel %X [%s] %p\n",
- ntohl(ccn.channel_of_client),
- GNUNET_h2s(port_number),
- ch);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating incoming channel %X [%s] %p\n",
+ ntohl (ccn.channel_of_client),
+ GNUNET_h2s (port_number),
+ ch);
- GNUNET_assert(NULL != port->connects);
+ GNUNET_assert (NULL != port->connects);
ch->window_changes = port->window_changes;
ch->disconnects = port->disconnects;
- ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl,
- &cadet_mq_destroy_impl,
- &cadet_mq_cancel_impl,
- ch,
- port->handlers,
- &cadet_mq_error_handler,
- ch);
- ch->ctx = port->connects(port->cls, ch, &msg->peer);
- GNUNET_MQ_set_handlers_closure(ch->mq, ch->ctx);
+ ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl,
+ &cadet_mq_destroy_impl,
+ &cadet_mq_cancel_impl,
+ ch,
+ port->handlers,
+ &cadet_mq_error_handler,
+ ch);
+ ch->ctx = port->connects (port->cls, ch, &msg->peer);
+ GNUNET_MQ_set_handlers_closure (ch->mq, ch->ctx);
}
@@ -596,25 +599,25 @@ handle_channel_created(
* @param msg A message with the details of the channel being destroyed
*/
static void
-handle_channel_destroy(
+handle_channel_destroy (
void *cls,
const struct GNUNET_CADET_LocalChannelDestroyMessage *msg)
{
struct GNUNET_CADET_Handle *h = cls;
struct GNUNET_CADET_Channel *ch;
- ch = find_channel(h, msg->ccn);
+ ch = find_channel (h, msg->ccn);
if (NULL == ch)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
- ntohl(msg->ccn.channel_of_client));
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received channel destroy for channel %X from CADET service\n",
- ntohl(msg->ccn.channel_of_client));
- destroy_channel(ch);
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
+ ntohl (msg->ccn.channel_of_client));
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received channel destroy for channel %X from CADET service\n",
+ ntohl (msg->ccn.channel_of_client));
+ destroy_channel (ch);
}
@@ -627,17 +630,17 @@ handle_channel_destroy(
* #GNUNET_SYSERR otherwise
*/
static int
-check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
+check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
{
uint16_t size;
- (void)cls;
- size = ntohs(message->header.size);
+ (void) cls;
+ size = ntohs (message->header.size);
if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -649,7 +652,7 @@ check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
* @param message A message encapsulating the data
*/
static void
-handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
+handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
{
struct GNUNET_CADET_Handle *h = cls;
const struct GNUNET_MessageHeader *payload;
@@ -657,25 +660,25 @@ handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
uint16_t type;
int fwd;
- ch = find_channel(h, message->ccn);
+ ch = find_channel (h, message->ccn);
if (NULL == ch)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Unknown channel %X for incoming data (recently closed?)\n",
- ntohl(message->ccn.channel_of_client));
- return;
- }
-
- payload = (const struct GNUNET_MessageHeader *)&message[1];
- type = ntohs(payload->type);
- fwd = ntohl(ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got a %s data on channel %s [%X] of type %u\n",
- fwd ? "FWD" : "BWD",
- GNUNET_i2s(&ch->peer),
- ntohl(message->ccn.channel_of_client),
- type);
- GNUNET_MQ_inject_message(ch->mq, payload);
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Unknown channel %X for incoming data (recently closed?)\n",
+ ntohl (message->ccn.channel_of_client));
+ return;
+ }
+
+ payload = (const struct GNUNET_MessageHeader *) &message[1];
+ type = ntohs (payload->type);
+ fwd = ntohl (ch->ccn.channel_of_client) <= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got a %s data on channel %s [%X] of type %u\n",
+ fwd ? "FWD" : "BWD",
+ GNUNET_i2s (&ch->peer),
+ ntohl (message->ccn.channel_of_client),
+ type);
+ GNUNET_MQ_inject_message (ch->mq, payload);
}
@@ -687,37 +690,37 @@ handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
* @param message Message itself.
*/
static void
-handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message)
+handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message)
{
struct GNUNET_CADET_Handle *h = cls;
struct GNUNET_CADET_Channel *ch;
- ch = find_channel(h, message->ccn);
+ ch = find_channel (h, message->ccn);
if (NULL == ch)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "ACK on unknown channel %X\n",
- ntohl(message->ccn.channel_of_client));
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "ACK on unknown channel %X\n",
+ ntohl (message->ccn.channel_of_client));
+ return;
+ }
ch->allow_send++;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
- ntohl(ch->ccn.channel_of_client),
- GNUNET_i2s(&ch->peer),
- ch->allow_send);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
+ ntohl (ch->ccn.channel_of_client),
+ GNUNET_i2s (&ch->peer),
+ ch->allow_send);
if (NULL == ch->pending_env)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got an ACK on mq channel %X, allow send now %u!\n",
- ntohl(ch->ccn.channel_of_client),
- ch->allow_send);
- notify_window_size(ch);
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got an ACK on mq channel %X, allow send now %u!\n",
+ ntohl (ch->ccn.channel_of_client),
+ ch->allow_send);
+ notify_window_size (ch);
+ return;
+ }
if (NULL != ch->mq_cont)
return; /* already working on it! */
- ch->mq_cont = GNUNET_SCHEDULER_add_now(&cadet_mq_send_now, ch);
+ ch->mq_cont = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, ch);
}
@@ -731,16 +734,16 @@ handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message)
* @return #GNUNET_OK (continue to iterate)
*/
static int
-destroy_channel_cb(void *cls, uint32_t cid, void *value)
+destroy_channel_cb (void *cls, uint32_t cid, void *value)
{
/* struct GNUNET_CADET_Handle *handle = cls; */
struct GNUNET_CADET_Channel *ch = value;
- (void)cls;
- (void)cid;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Destroying channel due to GNUNET_CADET_disconnect()\n");
- destroy_channel(ch);
+ (void) cls;
+ (void) cid;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Destroying channel due to GNUNET_CADET_disconnect()\n");
+ destroy_channel (ch);
return GNUNET_OK;
}
@@ -754,17 +757,17 @@ destroy_channel_cb(void *cls, uint32_t cid, void *value)
* @param error error code
*/
static void
-handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
+handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_Handle *h = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
- GNUNET_CONTAINER_multihashmap32_iterate(h->channels, &destroy_channel_cb, h);
- GNUNET_MQ_destroy(h->mq);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
+ GNUNET_CONTAINER_multihashmap32_iterate (h->channels, &destroy_channel_cb, h);
+ GNUNET_MQ_destroy (h->mq);
h->mq = NULL;
- GNUNET_assert(NULL == h->reconnect_task);
+ GNUNET_assert (NULL == h->reconnect_task);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h);
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
}
@@ -775,30 +778,30 @@ handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
* @param h handle to the cadet
*/
static void
-reconnect(struct GNUNET_CADET_Handle *h)
+reconnect (struct GNUNET_CADET_Handle *h)
{
struct GNUNET_MQ_MessageHandler handlers[] =
- { GNUNET_MQ_hd_fixed_size(channel_created,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
- struct GNUNET_CADET_LocalChannelCreateMessage,
- h),
- GNUNET_MQ_hd_fixed_size(channel_destroy,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
- struct GNUNET_CADET_LocalChannelDestroyMessage,
- h),
- GNUNET_MQ_hd_var_size(local_data,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
- struct GNUNET_CADET_LocalData,
- h),
- GNUNET_MQ_hd_fixed_size(local_ack,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
- struct GNUNET_CADET_LocalAck,
- h),
- GNUNET_MQ_handler_end() };
-
- GNUNET_assert(NULL == h->mq);
+ { GNUNET_MQ_hd_fixed_size (channel_created,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
+ struct GNUNET_CADET_LocalChannelCreateMessage,
+ h),
+ GNUNET_MQ_hd_fixed_size (channel_destroy,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
+ struct GNUNET_CADET_LocalChannelDestroyMessage,
+ h),
+ GNUNET_MQ_hd_var_size (local_data,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA,
+ struct GNUNET_CADET_LocalData,
+ h),
+ GNUNET_MQ_hd_fixed_size (local_ack,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK,
+ struct GNUNET_CADET_LocalAck,
+ h),
+ GNUNET_MQ_handler_end () };
+
+ GNUNET_assert (NULL == h->mq);
h->mq =
- GNUNET_CLIENT_connect(h->cfg, "cadet", handlers, &handle_mq_error, h);
+ GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h);
}
@@ -812,16 +815,16 @@ reconnect(struct GNUNET_CADET_Handle *h)
* @return #GNUNET_OK (continue to iterate)
*/
static int
-destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
+destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
{
/* struct GNUNET_CADET_Handle *handle = cls; */
struct GNUNET_CADET_Port *port = value;
- (void)cls;
- (void)id;
+ (void) cls;
+ (void) id;
/* This is a warning, the app should have cleanly closed all open ports */
- GNUNET_break(0);
- GNUNET_CADET_close_port(port);
+ GNUNET_break (0);
+ GNUNET_CADET_close_port (port);
return GNUNET_OK;
}
@@ -835,29 +838,29 @@ destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
* @param handle connection to cadet to disconnect
*/
void
-GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
+GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
{
- GNUNET_CONTAINER_multihashmap_iterate(handle->ports,
- &destroy_port_cb,
- handle);
- GNUNET_CONTAINER_multihashmap_destroy(handle->ports);
+ GNUNET_CONTAINER_multihashmap_iterate (handle->ports,
+ &destroy_port_cb,
+ handle);
+ GNUNET_CONTAINER_multihashmap_destroy (handle->ports);
handle->ports = NULL;
- GNUNET_CONTAINER_multihashmap32_iterate(handle->channels,
- &destroy_channel_cb,
- handle);
- GNUNET_CONTAINER_multihashmap32_destroy(handle->channels);
+ GNUNET_CONTAINER_multihashmap32_iterate (handle->channels,
+ &destroy_channel_cb,
+ handle);
+ GNUNET_CONTAINER_multihashmap32_destroy (handle->channels);
handle->channels = NULL;
if (NULL != handle->mq)
- {
- GNUNET_MQ_destroy(handle->mq);
- handle->mq = NULL;
- }
+ {
+ GNUNET_MQ_destroy (handle->mq);
+ handle->mq = NULL;
+ }
if (NULL != handle->reconnect_task)
- {
- GNUNET_SCHEDULER_cancel(handle->reconnect_task);
- handle->reconnect_task = NULL;
- }
- GNUNET_free(handle);
+ {
+ GNUNET_SCHEDULER_cancel (handle->reconnect_task);
+ handle->reconnect_task = NULL;
+ }
+ GNUNET_free (handle);
}
@@ -868,22 +871,22 @@ GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
* @param p Port handle.
*/
void
-GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
+GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
{
- GNUNET_assert(
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove(p->cadet->ports, &p->id, p));
+ GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, &p->id, p));
if (NULL != p->cadet->mq)
- {
- struct GNUNET_CADET_PortMessage *msg;
- struct GNUNET_MQ_Envelope *env;
-
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE);
- msg->port = p->id;
- GNUNET_MQ_send(p->cadet->mq, env);
- }
- GNUNET_free_non_null(p->handlers);
- GNUNET_free(p);
+ {
+ struct GNUNET_CADET_PortMessage *msg;
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE);
+ msg->port = p->id;
+ GNUNET_MQ_send (p->cadet->mq, env);
+ }
+ GNUNET_free_non_null (p->handlers);
+ GNUNET_free (p);
}
@@ -897,22 +900,22 @@ GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
* @param channel Channel handle, becomes invalid after this call.
*/
void
-GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
+GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
{
struct GNUNET_CADET_Handle *h = channel->cadet;
struct GNUNET_CADET_LocalChannelDestroyMessage *msg;
struct GNUNET_MQ_Envelope *env;
if (NULL != h->mq)
- {
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
- msg->ccn = channel->ccn;
- GNUNET_MQ_send(h->mq, env);
- }
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
+ {
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
+ msg->ccn = channel->ccn;
+ GNUNET_MQ_send (h->mq, env);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
channel->disconnects = NULL;
- destroy_channel(channel);
+ destroy_channel (channel);
}
@@ -926,19 +929,19 @@ GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
* @return Union with an answer to the query.
*/
const union GNUNET_CADET_ChannelInfo *
-GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel,
- enum GNUNET_CADET_ChannelInfoOption option,
- ...)
+GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
+ enum GNUNET_CADET_ChannelInfoOption option,
+ ...)
{
switch (option)
- {
- case GNUNET_CADET_OPTION_PEER:
- return (const union GNUNET_CADET_ChannelInfo *)&channel->peer;
-
- default:
- GNUNET_break(0);
- return NULL;
- }
+ {
+ case GNUNET_CADET_OPTION_PEER:
+ return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
+
+ default:
+ GNUNET_break (0);
+ return NULL;
+ }
}
@@ -948,17 +951,17 @@ GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel,
* @param ch Channel on which to send the ACK.
*/
void
-GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
+GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel)
{
struct GNUNET_CADET_LocalAck *msg;
struct GNUNET_MQ_Envelope *env;
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending ACK on channel %X\n",
- ntohl(channel->ccn.channel_of_client));
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending ACK on channel %X\n",
+ ntohl (channel->ccn.channel_of_client));
msg->ccn = channel->ccn;
- GNUNET_MQ_send(channel->cadet->mq, env);
+ GNUNET_MQ_send (channel->cadet->mq, env);
}
@@ -970,23 +973,23 @@ GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
* @return Handle to the cadet service NULL on error.
*/
struct GNUNET_CADET_Handle *
-GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
+GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CADET_Handle *h;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
- h = GNUNET_new(struct GNUNET_CADET_Handle);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
+ h = GNUNET_new (struct GNUNET_CADET_Handle);
h->cfg = cfg;
- h->ports = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_YES);
- h->channels = GNUNET_CONTAINER_multihashmap32_create(4);
- reconnect(h);
+ h->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_YES);
+ h->channels = GNUNET_CONTAINER_multihashmap32_create (4);
+ reconnect (h);
if (NULL == h->mq)
- {
- GNUNET_break(0);
- GNUNET_CADET_disconnect(h);
- return NULL;
- }
- h->next_ccn.channel_of_client = htonl(GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
+ {
+ GNUNET_break (0);
+ GNUNET_CADET_disconnect (h);
+ return NULL;
+ }
+ h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
return h;
}
@@ -1004,41 +1007,41 @@ GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
* @return Port handle, NULL if port is in use
*/
struct GNUNET_CADET_Port *
-GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h,
- const struct GNUNET_HashCode *port,
- GNUNET_CADET_ConnectEventHandler connects,
- void *connects_cls,
- GNUNET_CADET_WindowSizeEventHandler window_changes,
- GNUNET_CADET_DisconnectEventHandler disconnects,
- const struct GNUNET_MQ_MessageHandler *handlers)
+GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
+ const struct GNUNET_HashCode *port,
+ GNUNET_CADET_ConnectEventHandler connects,
+ void *connects_cls,
+ GNUNET_CADET_WindowSizeEventHandler window_changes,
+ GNUNET_CADET_DisconnectEventHandler disconnects,
+ const struct GNUNET_MQ_MessageHandler *handlers)
{
struct GNUNET_CADET_Port *p;
- GNUNET_assert(NULL != connects);
- GNUNET_assert(NULL != disconnects);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Listening to CADET port %s\n",
- GNUNET_h2s(port));
+ GNUNET_assert (NULL != connects);
+ GNUNET_assert (NULL != disconnects);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Listening to CADET port %s\n",
+ GNUNET_h2s (port));
- p = GNUNET_new(struct GNUNET_CADET_Port);
+ p = GNUNET_new (struct GNUNET_CADET_Port);
p->cadet = h;
p->id = *port;
- if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (
h->ports,
&p->id,
p,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_free(p);
- return NULL;
- }
+ {
+ GNUNET_free (p);
+ return NULL;
+ }
p->connects = connects;
p->cls = connects_cls;
p->window_changes = window_changes;
p->disconnects = disconnects;
- p->handlers = GNUNET_MQ_copy_handlers(handlers);
+ p->handlers = GNUNET_MQ_copy_handlers (handlers);
- GNUNET_assert(GNUNET_OK == open_port_cb(h, &p->id, p));
+ GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
return p;
}
@@ -1062,45 +1065,45 @@ GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h,
* @return Handle to the channel.
*/
struct GNUNET_CADET_Channel *
-GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h,
- void *channel_cls,
- const struct GNUNET_PeerIdentity *destination,
- const struct GNUNET_HashCode *port,
- GNUNET_CADET_WindowSizeEventHandler window_changes,
- GNUNET_CADET_DisconnectEventHandler disconnects,
- const struct GNUNET_MQ_MessageHandler *handlers)
+GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
+ void *channel_cls,
+ const struct GNUNET_PeerIdentity *destination,
+ const struct GNUNET_HashCode *port,
+ GNUNET_CADET_WindowSizeEventHandler window_changes,
+ GNUNET_CADET_DisconnectEventHandler disconnects,
+ const struct GNUNET_MQ_MessageHandler *handlers)
{
struct GNUNET_CADET_Channel *ch;
struct GNUNET_CADET_LocalChannelCreateMessage *msg;
struct GNUNET_MQ_Envelope *env;
- GNUNET_assert(NULL != disconnects);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Creating channel to peer %s at port %s\n",
- GNUNET_i2s(destination),
- GNUNET_h2s(port));
- ch = create_channel(h, NULL);
+ GNUNET_assert (NULL != disconnects);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating channel to peer %s at port %s\n",
+ GNUNET_i2s (destination),
+ GNUNET_h2s (port));
+ ch = create_channel (h, NULL);
ch->ctx = channel_cls;
ch->peer = *destination;
ch->window_changes = window_changes;
ch->disconnects = disconnects;
/* Create MQ for channel */
- ch->mq = GNUNET_MQ_queue_for_callbacks(&cadet_mq_send_impl,
- &cadet_mq_destroy_impl,
- &cadet_mq_cancel_impl,
- ch,
- handlers,
- &cadet_mq_error_handler,
- ch);
- GNUNET_MQ_set_handlers_closure(ch->mq, channel_cls);
+ ch->mq = GNUNET_MQ_queue_for_callbacks (&cadet_mq_send_impl,
+ &cadet_mq_destroy_impl,
+ &cadet_mq_cancel_impl,
+ ch,
+ handlers,
+ &cadet_mq_error_handler,
+ ch);
+ GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls);
/* Request channel creation to service */
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
msg->ccn = ch->ccn;
msg->port = *port;
msg->peer = *destination;
- GNUNET_MQ_send(h->mq, env);
+ GNUNET_MQ_send (h->mq, env);
return ch;
}
@@ -1113,7 +1116,7 @@ GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h,
* @return NULL if @a channel is not yet connected.
*/
struct GNUNET_MQ_Handle *
-GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
+GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel)
{
return channel->mq;
}
diff --git a/src/cadet/cadet_api_get_channel.c b/src/cadet/cadet_api_get_channel.c
index 5479f4238..6d86e8e81 100644
--- a/src/cadet/cadet_api_get_channel.c
+++ b/src/cadet/cadet_api_get_channel.c
@@ -34,7 +34,8 @@
/**
* Operation handle.
*/
-struct GNUNET_CADET_ChannelMonitor {
+struct GNUNET_CADET_ChannelMonitor
+{
/**
* Channel callback.
*/
@@ -81,10 +82,10 @@ struct GNUNET_CADET_ChannelMonitor {
* #GNUNET_SYSERR otherwise
*/
static int
-check_channel_info(void *cls,
- const struct GNUNET_CADET_ChannelInfoMessage *message)
+check_channel_info (void *cls,
+ const struct GNUNET_CADET_ChannelInfoMessage *message)
{
- (void)cls;
+ (void) cls;
return GNUNET_OK;
}
@@ -97,17 +98,17 @@ check_channel_info(void *cls,
* @param message Message itself.
*/
static void
-handle_channel_info(void *cls,
- const struct GNUNET_CADET_ChannelInfoMessage *message)
+handle_channel_info (void *cls,
+ const struct GNUNET_CADET_ChannelInfoMessage *message)
{
struct GNUNET_CADET_ChannelMonitor *cm = cls;
struct GNUNET_CADET_ChannelInternals ci;
ci.root = message->root;
ci.dest = message->dest;
- cm->channel_cb(cm->channel_cb_cls,
- &ci);
- GNUNET_CADET_get_channel_cancel(cm);
+ cm->channel_cb (cm->channel_cb_cls,
+ &ci);
+ GNUNET_CADET_get_channel_cancel (cm);
}
@@ -118,14 +119,14 @@ handle_channel_info(void *cls,
* @param message Message itself.
*/
static void
-handle_channel_info_end(void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_channel_info_end (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_CADET_ChannelMonitor *cm = cls;
- cm->channel_cb(cm->channel_cb_cls,
- NULL);
- GNUNET_CADET_get_channel_cancel(cm);
+ cm->channel_cb (cm->channel_cb_cls,
+ NULL);
+ GNUNET_CADET_get_channel_cancel (cm);
}
@@ -135,7 +136,7 @@ handle_channel_info_end(void *cls,
* @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
*/
static void
-reconnect(void *cls);
+reconnect (void *cls);
/**
@@ -145,18 +146,18 @@ reconnect(void *cls);
* @param error error code from MQ
*/
static void
-error_handler(void *cls,
- enum GNUNET_MQ_Error error)
+error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_ChannelMonitor *cm = cls;
- GNUNET_MQ_destroy(cm->mq);
+ GNUNET_MQ_destroy (cm->mq);
cm->mq = NULL;
- cm->backoff = GNUNET_TIME_randomized_backoff(cm->backoff,
- GNUNET_TIME_UNIT_MINUTES);
- cm->reconnect_task = GNUNET_SCHEDULER_add_delayed(cm->backoff,
- &reconnect,
- cm);
+ cm->backoff = GNUNET_TIME_randomized_backoff (cm->backoff,
+ GNUNET_TIME_UNIT_MINUTES);
+ cm->reconnect_task = GNUNET_SCHEDULER_add_delayed (cm->backoff,
+ &reconnect,
+ cm);
}
@@ -166,36 +167,36 @@ error_handler(void *cls,
* @param cls a `struct GNUNET_CADET_ChannelMonitor` operation
*/
static void
-reconnect(void *cls)
+reconnect (void *cls)
{
struct GNUNET_CADET_ChannelMonitor *cm = cls;
struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size(channel_info_end,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END,
- struct GNUNET_MessageHeader,
- cm),
- GNUNET_MQ_hd_var_size(channel_info,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL,
- struct GNUNET_CADET_ChannelInfoMessage,
- cm),
- GNUNET_MQ_handler_end()
+ GNUNET_MQ_hd_fixed_size (channel_info_end,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL_END,
+ struct GNUNET_MessageHeader,
+ cm),
+ GNUNET_MQ_hd_var_size (channel_info,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL,
+ struct GNUNET_CADET_ChannelInfoMessage,
+ cm),
+ GNUNET_MQ_handler_end ()
};
struct GNUNET_CADET_RequestChannelInfoMessage *msg;
struct GNUNET_MQ_Envelope *env;
cm->reconnect_task = NULL;
- cm->mq = GNUNET_CLIENT_connect(cm->cfg,
- "cadet",
- handlers,
- &error_handler,
- cm);
+ cm->mq = GNUNET_CLIENT_connect (cm->cfg,
+ "cadet",
+ handlers,
+ &error_handler,
+ cm);
if (NULL == cm->mq)
return;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_CHANNEL);
msg->target = cm->peer;
- GNUNET_MQ_send(cm->mq,
- env);
+ GNUNET_MQ_send (cm->mq,
+ env);
}
@@ -209,29 +210,29 @@ reconnect(void *cls)
* @return NULL on error
*/
struct GNUNET_CADET_ChannelMonitor *
-GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_PeerIdentity *peer,
- GNUNET_CADET_ChannelCB callback,
- void *callback_cls)
+GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_PeerIdentity *peer,
+ GNUNET_CADET_ChannelCB callback,
+ void *callback_cls)
{
struct GNUNET_CADET_ChannelMonitor *cm;
if (NULL == callback)
- {
- GNUNET_break(0);
- return NULL;
- }
- cm = GNUNET_new(struct GNUNET_CADET_ChannelMonitor);
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ cm = GNUNET_new (struct GNUNET_CADET_ChannelMonitor);
cm->channel_cb = callback;
cm->channel_cb_cls = callback_cls;
cm->cfg = cfg;
cm->peer = *peer;
- reconnect(cm);
+ reconnect (cm);
if (NULL == cm->mq)
- {
- GNUNET_free(cm);
- return NULL;
- }
+ {
+ GNUNET_free (cm);
+ return NULL;
+ }
return cm;
}
@@ -243,15 +244,15 @@ GNUNET_CADET_get_channel(const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return Closure that was given to #GNUNET_CADET_get_channel().
*/
void *
-GNUNET_CADET_get_channel_cancel(struct GNUNET_CADET_ChannelMonitor *cm)
+GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
{
void *ret = cm->channel_cb_cls;
if (NULL != cm->mq)
- GNUNET_MQ_destroy(cm->mq);
+ GNUNET_MQ_destroy (cm->mq);
if (NULL != cm->reconnect_task)
- GNUNET_SCHEDULER_cancel(cm->reconnect_task);
- GNUNET_free(cm);
+ GNUNET_SCHEDULER_cancel (cm->reconnect_task);
+ GNUNET_free (cm);
return ret;
}
diff --git a/src/cadet/cadet_api_get_path.c b/src/cadet/cadet_api_get_path.c
index 0f18014c3..68070eab2 100644
--- a/src/cadet/cadet_api_get_path.c
+++ b/src/cadet/cadet_api_get_path.c
@@ -34,7 +34,8 @@
/**
* Operation handle.
*/
-struct GNUNET_CADET_GetPath {
+struct GNUNET_CADET_GetPath
+{
/**
* Monitor callback
*/
@@ -81,24 +82,24 @@ struct GNUNET_CADET_GetPath {
* #GNUNET_SYSERR otherwise
*/
static int
-check_get_path(void *cls,
- const struct GNUNET_CADET_LocalInfoPath *message)
+check_get_path (void *cls,
+ const struct GNUNET_CADET_LocalInfoPath *message)
{
size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath);
size_t esize;
- (void)cls;
- esize = ntohs(message->header.size);
+ (void) cls;
+ esize = ntohs (message->header.size);
if (esize < msize)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity)))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -110,19 +111,19 @@ check_get_path(void *cls,
* @param message Message itself.
*/
static void
-handle_get_path(void *cls,
- const struct GNUNET_CADET_LocalInfoPath *message)
+handle_get_path (void *cls,
+ const struct GNUNET_CADET_LocalInfoPath *message)
{
struct GNUNET_CADET_GetPath *gp = cls;
struct GNUNET_CADET_PeerPathDetail ppd;
ppd.peer = gp->id;
- ppd.path = (const struct GNUNET_PeerIdentity *)&message[1];
- ppd.target_offset = ntohl(message->off);
- ppd.path_length = (ntohs(message->header.size) - sizeof(*message))
+ ppd.path = (const struct GNUNET_PeerIdentity *) &message[1];
+ ppd.target_offset = ntohl (message->off);
+ ppd.path_length = (ntohs (message->header.size) - sizeof(*message))
/ sizeof(struct GNUNET_PeerIdentity);
- gp->path_cb(gp->path_cb_cls,
- &ppd);
+ gp->path_cb (gp->path_cb_cls,
+ &ppd);
}
@@ -133,15 +134,15 @@ handle_get_path(void *cls,
* @param message Message itself.
*/
static void
-handle_get_path_end(void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_get_path_end (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_CADET_GetPath *gp = cls;
- (void)message;
- gp->path_cb(gp->path_cb_cls,
- NULL);
- GNUNET_CADET_get_path_cancel(gp);
+ (void) message;
+ gp->path_cb (gp->path_cb_cls,
+ NULL);
+ GNUNET_CADET_get_path_cancel (gp);
}
@@ -151,7 +152,7 @@ handle_get_path_end(void *cls,
* @param cls a `struct GNUNET_CADET_GetPath` operation
*/
static void
-reconnect(void *cls);
+reconnect (void *cls);
/**
@@ -161,18 +162,18 @@ reconnect(void *cls);
* @param error error code from MQ
*/
static void
-error_handler(void *cls,
- enum GNUNET_MQ_Error error)
+error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_GetPath *gp = cls;
- GNUNET_MQ_destroy(gp->mq);
+ GNUNET_MQ_destroy (gp->mq);
gp->mq = NULL;
- gp->backoff = GNUNET_TIME_randomized_backoff(gp->backoff,
- GNUNET_TIME_UNIT_MINUTES);
- gp->reconnect_task = GNUNET_SCHEDULER_add_delayed(gp->backoff,
- &reconnect,
- gp);
+ gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff,
+ GNUNET_TIME_UNIT_MINUTES);
+ gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff,
+ &reconnect,
+ gp);
}
@@ -182,36 +183,36 @@ error_handler(void *cls,
* @param cls a `struct GNUNET_CADET_GetPath` operation
*/
static void
-reconnect(void *cls)
+reconnect (void *cls)
{
struct GNUNET_CADET_GetPath *gp = cls;
struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size(get_path,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH,
- struct GNUNET_CADET_LocalInfoPath,
- gp),
- GNUNET_MQ_hd_fixed_size(get_path_end,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END,
- struct GNUNET_MessageHeader,
- gp),
- GNUNET_MQ_handler_end()
+ GNUNET_MQ_hd_var_size (get_path,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH,
+ struct GNUNET_CADET_LocalInfoPath,
+ gp),
+ GNUNET_MQ_hd_fixed_size (get_path_end,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END,
+ struct GNUNET_MessageHeader,
+ gp),
+ GNUNET_MQ_handler_end ()
};
struct GNUNET_CADET_RequestPathInfoMessage *msg;
struct GNUNET_MQ_Envelope *env;
gp->reconnect_task = NULL;
- gp->mq = GNUNET_CLIENT_connect(gp->cfg,
- "cadet",
- handlers,
- &error_handler,
- gp);
+ gp->mq = GNUNET_CLIENT_connect (gp->cfg,
+ "cadet",
+ handlers,
+ &error_handler,
+ gp);
if (NULL == gp->mq)
return;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH);
msg->peer = gp->id;
- GNUNET_MQ_send(gp->mq,
- env);
+ GNUNET_MQ_send (gp->mq,
+ env);
}
@@ -225,29 +226,29 @@ reconnect(void *cls)
* @return NULL on error
*/
struct GNUNET_CADET_GetPath *
-GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_PeerIdentity *id,
- GNUNET_CADET_PathCB callback,
- void *callback_cls)
+GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_CADET_PathCB callback,
+ void *callback_cls)
{
struct GNUNET_CADET_GetPath *gp;
if (NULL == callback)
- {
- GNUNET_break(0);
- return NULL;
- }
- gp = GNUNET_new(struct GNUNET_CADET_GetPath);
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ gp = GNUNET_new (struct GNUNET_CADET_GetPath);
gp->path_cb = callback;
gp->path_cb_cls = callback_cls;
gp->cfg = cfg;
gp->id = *id;
- reconnect(gp);
+ reconnect (gp);
if (NULL == gp->mq)
- {
- GNUNET_free(gp);
- return NULL;
- }
+ {
+ GNUNET_free (gp);
+ return NULL;
+ }
return gp;
}
@@ -259,15 +260,15 @@ GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return closure from #GNUNET_CADET_get_path().
*/
void *
-GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp)
+GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp)
{
void *ret = gp->path_cb_cls;
if (NULL != gp->mq)
- GNUNET_MQ_destroy(gp->mq);
+ GNUNET_MQ_destroy (gp->mq);
if (NULL != gp->reconnect_task)
- GNUNET_SCHEDULER_cancel(gp->reconnect_task);
- GNUNET_free(gp);
+ GNUNET_SCHEDULER_cancel (gp->reconnect_task);
+ GNUNET_free (gp);
return ret;
}
diff --git a/src/cadet/cadet_api_helper.c b/src/cadet/cadet_api_helper.c
index 78e5eb45c..52aec6cc9 100644
--- a/src/cadet/cadet_api_helper.c
+++ b/src/cadet/cadet_api_helper.c
@@ -41,15 +41,14 @@
* @return A GNUNET_HashCode usable for the new CADET API.
*/
const struct GNUNET_HashCode *
-GC_u2h(uint32_t port)
+GC_u2h (uint32_t port)
{
static struct GNUNET_HashCode hash;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "This is a transitional function, use proper crypto hashes as CADET ports\n");
- GNUNET_CRYPTO_hash(&port,
- sizeof(port),
- &hash);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "This is a transitional function, use proper crypto hashes as CADET ports\n");
+ GNUNET_CRYPTO_hash (&port,
+ sizeof(port),
+ &hash);
return &hash;
}
-
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index 65e9ad4da..8865b6f57 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.c
@@ -34,7 +34,8 @@
/**
* Operation handle.
*/
-struct GNUNET_CADET_PeersLister {
+struct GNUNET_CADET_PeersLister
+{
/**
* Monitor callback
*/
@@ -74,18 +75,18 @@ struct GNUNET_CADET_PeersLister {
* @param info Message itself.
*/
static void
-handle_get_peers(void *cls,
- const struct GNUNET_CADET_LocalInfoPeers *info)
+handle_get_peers (void *cls,
+ const struct GNUNET_CADET_LocalInfoPeers *info)
{
struct GNUNET_CADET_PeersLister *pl = cls;
struct GNUNET_CADET_PeerListEntry ple;
ple.peer = info->destination;
- ple.have_tunnel = (int)ntohs(info->tunnel);
- ple.n_paths = (unsigned int)ntohs(info->paths);
- ple.best_path_length = (unsigned int)ntohl(info->best_path_length);
- pl->peers_cb(pl->peers_cb_cls,
- &ple);
+ ple.have_tunnel = (int) ntohs (info->tunnel);
+ ple.n_paths = (unsigned int) ntohs (info->paths);
+ ple.best_path_length = (unsigned int) ntohl (info->best_path_length);
+ pl->peers_cb (pl->peers_cb_cls,
+ &ple);
}
@@ -96,16 +97,16 @@ handle_get_peers(void *cls,
* @param msg Message itself.
*/
static void
-handle_get_peers_end(void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_get_peers_end (void *cls,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CADET_PeersLister *pl = cls;
- (void)msg;
+ (void) msg;
- pl->peers_cb(pl->peers_cb_cls,
- NULL);
- GNUNET_CADET_list_peers_cancel(pl);
+ pl->peers_cb (pl->peers_cb_cls,
+ NULL);
+ GNUNET_CADET_list_peers_cancel (pl);
}
@@ -115,7 +116,7 @@ handle_get_peers_end(void *cls,
* @param cls a `struct GNUNET_CADET_PeersLister` operation
*/
static void
-reconnect(void *cls);
+reconnect (void *cls);
/**
@@ -125,18 +126,18 @@ reconnect(void *cls);
* @param error error code from MQ
*/
static void
-error_handler(void *cls,
- enum GNUNET_MQ_Error error)
+error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_PeersLister *pl = cls;
- GNUNET_MQ_destroy(pl->mq);
+ GNUNET_MQ_destroy (pl->mq);
pl->mq = NULL;
- pl->backoff = GNUNET_TIME_randomized_backoff(pl->backoff,
- GNUNET_TIME_UNIT_MINUTES);
- pl->reconnect_task = GNUNET_SCHEDULER_add_delayed(pl->backoff,
- &reconnect,
- pl);
+ pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff,
+ GNUNET_TIME_UNIT_MINUTES);
+ pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff,
+ &reconnect,
+ pl);
}
@@ -146,35 +147,35 @@ error_handler(void *cls,
* @param cls a `struct GNUNET_CADET_PeersLister` operation
*/
static void
-reconnect(void *cls)
+reconnect (void *cls)
{
struct GNUNET_CADET_PeersLister *pl = cls;
struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size(get_peers,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
- struct GNUNET_CADET_LocalInfoPeers,
- pl),
- GNUNET_MQ_hd_fixed_size(get_peers_end,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
- struct GNUNET_MessageHeader,
- pl),
- GNUNET_MQ_handler_end()
+ GNUNET_MQ_hd_fixed_size (get_peers,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
+ struct GNUNET_CADET_LocalInfoPeers,
+ pl),
+ GNUNET_MQ_hd_fixed_size (get_peers_end,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END,
+ struct GNUNET_MessageHeader,
+ pl),
+ GNUNET_MQ_handler_end ()
};
struct GNUNET_MessageHeader *msg;
struct GNUNET_MQ_Envelope *env;
pl->reconnect_task = NULL;
- pl->mq = GNUNET_CLIENT_connect(pl->cfg,
- "cadet",
- handlers,
- &error_handler,
- pl);
+ pl->mq = GNUNET_CLIENT_connect (pl->cfg,
+ "cadet",
+ handlers,
+ &error_handler,
+ pl);
if (NULL == pl->mq)
return;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
- GNUNET_MQ_send(pl->mq,
- env);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS);
+ GNUNET_MQ_send (pl->mq,
+ env);
}
@@ -189,27 +190,27 @@ reconnect(void *cls)
* @return NULL on error
*/
struct GNUNET_CADET_PeersLister *
-GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CADET_PeersCB callback,
- void *callback_cls)
+GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_CADET_PeersCB callback,
+ void *callback_cls)
{
struct GNUNET_CADET_PeersLister *pl;
if (NULL == callback)
- {
- GNUNET_break(0);
- return NULL;
- }
- pl = GNUNET_new(struct GNUNET_CADET_PeersLister);
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ pl = GNUNET_new (struct GNUNET_CADET_PeersLister);
pl->peers_cb = callback;
pl->peers_cb_cls = callback_cls;
pl->cfg = cfg;
- reconnect(pl);
+ reconnect (pl);
if (NULL == pl->mq)
- {
- GNUNET_free(pl);
- return NULL;
- }
+ {
+ GNUNET_free (pl);
+ return NULL;
+ }
return pl;
}
@@ -221,15 +222,15 @@ GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return Closure given to GNUNET_CADET_get_peers().
*/
void *
-GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
+GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
{
void *ret = pl->peers_cb_cls;
if (NULL != pl->mq)
- GNUNET_MQ_destroy(pl->mq);
+ GNUNET_MQ_destroy (pl->mq);
if (NULL != pl->reconnect_task)
- GNUNET_SCHEDULER_cancel(pl->reconnect_task);
- GNUNET_free(pl);
+ GNUNET_SCHEDULER_cancel (pl->reconnect_task);
+ GNUNET_free (pl);
return ret;
}
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index 2ea8cf26c..e9ae069bb 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -34,7 +34,8 @@
/**
* Operation handle.
*/
-struct GNUNET_CADET_ListTunnels {
+struct GNUNET_CADET_ListTunnels
+{
/**
* Monitor callback
*/
@@ -74,19 +75,19 @@ struct GNUNET_CADET_ListTunnels {
* @param info Message itself.
*/
static void
-handle_get_tunnels(void *cls,
- const struct GNUNET_CADET_LocalInfoTunnel *info)
+handle_get_tunnels (void *cls,
+ const struct GNUNET_CADET_LocalInfoTunnel *info)
{
struct GNUNET_CADET_ListTunnels *lt = cls;
struct GNUNET_CADET_TunnelDetails td;
td.peer = info->destination;
- td.channels = ntohl(info->channels);
- td.connections = ntohl(info->connections);
- td.estate = ntohs(info->estate);
- td.cstate = ntohs(info->cstate);
- lt->tunnels_cb(lt->tunnels_cb_cls,
- &td);
+ td.channels = ntohl (info->channels);
+ td.connections = ntohl (info->connections);
+ td.estate = ntohs (info->estate);
+ td.cstate = ntohs (info->cstate);
+ lt->tunnels_cb (lt->tunnels_cb_cls,
+ &td);
}
@@ -97,16 +98,16 @@ handle_get_tunnels(void *cls,
* @param message Message itself.
*/
static void
-handle_get_tunnels_end(void *cls,
- const struct GNUNET_MessageHeader *msg)
+handle_get_tunnels_end (void *cls,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_CADET_ListTunnels *lt = cls;
- (void)msg;
+ (void) msg;
- lt->tunnels_cb(lt->tunnels_cb_cls,
- NULL);
- GNUNET_CADET_list_tunnels_cancel(lt);
+ lt->tunnels_cb (lt->tunnels_cb_cls,
+ NULL);
+ GNUNET_CADET_list_tunnels_cancel (lt);
}
@@ -116,7 +117,7 @@ handle_get_tunnels_end(void *cls,
* @param cls a `struct GNUNET_CADET_ListTunnels` operation
*/
static void
-reconnect(void *cls);
+reconnect (void *cls);
/**
@@ -126,18 +127,18 @@ reconnect(void *cls);
* @param error error code from MQ
*/
static void
-error_handler(void *cls,
- enum GNUNET_MQ_Error error)
+error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
{
struct GNUNET_CADET_ListTunnels *lt = cls;
- GNUNET_MQ_destroy(lt->mq);
+ GNUNET_MQ_destroy (lt->mq);
lt->mq = NULL;
- lt->backoff = GNUNET_TIME_randomized_backoff(lt->backoff,
- GNUNET_TIME_UNIT_MINUTES);
- lt->reconnect_task = GNUNET_SCHEDULER_add_delayed(lt->backoff,
- &reconnect,
- lt);
+ lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff,
+ GNUNET_TIME_UNIT_MINUTES);
+ lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff,
+ &reconnect,
+ lt);
}
@@ -147,35 +148,35 @@ error_handler(void *cls,
* @param cls a `struct GNUNET_CADET_ListTunnels` operation
*/
static void
-reconnect(void *cls)
+reconnect (void *cls)
{
struct GNUNET_CADET_ListTunnels *lt = cls;
struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size(get_tunnels,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
- struct GNUNET_CADET_LocalInfoTunnel,
- lt),
- GNUNET_MQ_hd_fixed_size(get_tunnels_end,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
- struct GNUNET_MessageHeader,
- lt),
- GNUNET_MQ_handler_end()
+ GNUNET_MQ_hd_fixed_size (get_tunnels,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
+ struct GNUNET_CADET_LocalInfoTunnel,
+ lt),
+ GNUNET_MQ_hd_fixed_size (get_tunnels_end,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
+ struct GNUNET_MessageHeader,
+ lt),
+ GNUNET_MQ_handler_end ()
};
struct GNUNET_MessageHeader *msg;
struct GNUNET_MQ_Envelope *env;
lt->reconnect_task = NULL;
- lt->mq = GNUNET_CLIENT_connect(lt->cfg,
- "cadet",
- handlers,
- &error_handler,
- lt);
+ lt->mq = GNUNET_CLIENT_connect (lt->cfg,
+ "cadet",
+ handlers,
+ &error_handler,
+ lt);
if (NULL == lt->mq)
return;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
- GNUNET_MQ_send(lt->mq,
- env);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
+ GNUNET_MQ_send (lt->mq,
+ env);
}
@@ -190,27 +191,27 @@ reconnect(void *cls)
* @return NULL on error
*/
struct GNUNET_CADET_ListTunnels *
-GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_CADET_TunnelsCB callback,
- void *callback_cls)
+GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_CADET_TunnelsCB callback,
+ void *callback_cls)
{
struct GNUNET_CADET_ListTunnels *lt;
if (NULL == callback)
- {
- GNUNET_break(0);
- return NULL;
- }
- lt = GNUNET_new(struct GNUNET_CADET_ListTunnels);
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
lt->tunnels_cb = callback;
lt->tunnels_cb_cls = callback_cls;
lt->cfg = cfg;
- reconnect(lt);
+ reconnect (lt);
if (NULL == lt->mq)
- {
- GNUNET_free(lt);
- return NULL;
- }
+ {
+ GNUNET_free (lt);
+ return NULL;
+ }
return lt;
}
@@ -222,15 +223,15 @@ GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
* @return Closure given to GNUNET_CADET_list_tunnels().
*/
void *
-GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
+GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
{
void *ret = lt->tunnels_cb_cls;
if (NULL != lt->mq)
- GNUNET_MQ_destroy(lt->mq);
+ GNUNET_MQ_destroy (lt->mq);
if (NULL != lt->reconnect_task)
- GNUNET_SCHEDULER_cancel(lt->reconnect_task);
- GNUNET_free(lt);
+ GNUNET_SCHEDULER_cancel (lt->reconnect_task);
+ GNUNET_free (lt);
return ret;
}
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 6252a1da5..e3417f8c4 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -66,7 +66,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* Message for cadet connection creation.
*/
-struct GNUNET_CADET_ConnectionCreateMessage {
+struct GNUNET_CADET_ConnectionCreateMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
*
@@ -99,7 +100,8 @@ struct GNUNET_CADET_ConnectionCreateMessage {
/**
* Message for ack'ing a connection
*/
-struct GNUNET_CADET_ConnectionCreateAckMessage {
+struct GNUNET_CADET_ConnectionCreateAckMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
*/
@@ -120,7 +122,8 @@ struct GNUNET_CADET_ConnectionCreateAckMessage {
/**
* Message for notifying a disconnection in a path
*/
-struct GNUNET_CADET_ConnectionBrokenMessage {
+struct GNUNET_CADET_ConnectionBrokenMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
*/
@@ -151,7 +154,8 @@ struct GNUNET_CADET_ConnectionBrokenMessage {
/**
* Message to destroy a connection.
*/
-struct GNUNET_CADET_ConnectionDestroyMessage {
+struct GNUNET_CADET_ConnectionDestroyMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
*/
@@ -180,7 +184,8 @@ struct GNUNET_CADET_ConnectionDestroyMessage {
* against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
* messages.
*/
-struct CadetEncryptedMessageIdentifier {
+struct CadetEncryptedMessageIdentifier
+{
/**
* This number is incremented by one per message. It may wrap around.
* In network byte order.
@@ -192,7 +197,8 @@ struct CadetEncryptedMessageIdentifier {
/**
* Flags to be used in GNUNET_CADET_KX.
*/
-enum GNUNET_CADET_KX_Flags {
+enum GNUNET_CADET_KX_Flags
+{
/**
* Should the peer reply with its KX details?
*/
@@ -208,7 +214,8 @@ enum GNUNET_CADET_KX_Flags {
/**
* Message for a Key eXchange for a tunnel.
*/
-struct GNUNET_CADET_TunnelKeyExchangeMessage {
+struct GNUNET_CADET_TunnelKeyExchangeMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
* #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
@@ -263,7 +270,8 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage {
* Message for a Key eXchange for a tunnel, with authentication.
* Used as a response to the initial KX as well as for rekeying.
*/
-struct GNUNET_CADET_TunnelKeyExchangeAuthMessage {
+struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
+{
/**
* Message header with key material.
*/
@@ -290,7 +298,8 @@ struct GNUNET_CADET_TunnelKeyExchangeAuthMessage {
* Encrypted axolotl header with numbers that identify which
* keys in which ratchet are to be used to decrypt the body.
*/
-struct GNUNET_CADET_AxHeader {
+struct GNUNET_CADET_AxHeader
+{
/**
* Number of messages sent with the current ratchet key.
*/
@@ -311,7 +320,8 @@ struct GNUNET_CADET_AxHeader {
/**
* Axolotl-encrypted tunnel message with application payload.
*/
-struct GNUNET_CADET_TunnelEncryptedMessage {
+struct GNUNET_CADET_TunnelEncryptedMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
*/
@@ -354,7 +364,8 @@ struct GNUNET_CADET_TunnelEncryptedMessage {
/**
* Message to create a Channel.
*/
-struct GNUNET_CADET_ChannelOpenMessage {
+struct GNUNET_CADET_ChannelOpenMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
*/
@@ -381,7 +392,8 @@ struct GNUNET_CADET_ChannelOpenMessage {
* Message to acknowledge opening a channel of type
* #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
*/
-struct GNUNET_CADET_ChannelOpenAckMessage {
+struct GNUNET_CADET_ChannelOpenAckMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
*/
@@ -409,7 +421,8 @@ struct GNUNET_CADET_ChannelOpenAckMessage {
* Message to destroy a channel of type
* #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
*/
-struct GNUNET_CADET_ChannelDestroyMessage {
+struct GNUNET_CADET_ChannelDestroyMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
*/
@@ -430,7 +443,8 @@ struct GNUNET_CADET_ChannelDestroyMessage {
/**
* Number used to uniquely identify messages in a CADET Channel.
*/
-struct ChannelMessageIdentifier {
+struct ChannelMessageIdentifier
+{
/**
* Unique ID of the message, cycles around, in NBO.
*/
@@ -441,7 +455,8 @@ struct ChannelMessageIdentifier {
/**
* Message for cadet data traffic.
*/
-struct GNUNET_CADET_ChannelAppDataMessage {
+struct GNUNET_CADET_ChannelAppDataMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
*/
@@ -466,7 +481,8 @@ struct GNUNET_CADET_ChannelAppDataMessage {
/**
* Message to acknowledge end-to-end data.
*/
-struct GNUNET_CADET_ChannelDataAckMessage {
+struct GNUNET_CADET_ChannelDataAckMessage
+{
/**
* Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
*/
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c
index ae1eb6f00..490e6539b 100644
--- a/src/cadet/cadet_test_lib.c
+++ b/src/cadet/cadet_test_lib.c
@@ -31,7 +31,8 @@
/**
* Test context for a CADET Test.
*/
-struct GNUNET_CADET_TEST_Context {
+struct GNUNET_CADET_TEST_Context
+{
/**
* Array of running peers.
*/
@@ -97,7 +98,8 @@ struct GNUNET_CADET_TEST_Context {
/**
* Context for a cadet adapter callback.
*/
-struct GNUNET_CADET_TEST_AdapterContext {
+struct GNUNET_CADET_TEST_AdapterContext
+{
/**
* Peer number for the particular peer.
*/
@@ -126,33 +128,33 @@ struct GNUNET_CADET_TEST_AdapterContext {
* @return service handle to return in 'op_result', NULL on error
*/
static void *
-cadet_connect_adapter(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+cadet_connect_adapter (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
struct GNUNET_CADET_TEST_Context *ctx = actx->ctx;
struct GNUNET_CADET_Handle *h;
- h = GNUNET_CADET_connect(cfg);
+ h = GNUNET_CADET_connect (cfg);
if (NULL == h)
- {
- GNUNET_break(0);
- return NULL;
- }
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
if (NULL == ctx->ports)
return h;
- actx->ports = GNUNET_new_array(ctx->port_count,
- struct GNUNET_CADET_Port *);
+ actx->ports = GNUNET_new_array (ctx->port_count,
+ struct GNUNET_CADET_Port *);
for (unsigned int i = 0; i < ctx->port_count; i++)
- {
- actx->ports[i] = GNUNET_CADET_open_port(h,
- ctx->ports[i],
- ctx->connects,
- (void *)(long)actx->peer,
- ctx->window_changes,
- ctx->disconnects,
- ctx->handlers);
- }
+ {
+ actx->ports[i] = GNUNET_CADET_open_port (h,
+ ctx->ports[i],
+ ctx->connects,
+ (void *) (long) actx->peer,
+ ctx->window_changes,
+ ctx->disconnects,
+ ctx->handlers);
+ }
return h;
}
@@ -165,23 +167,23 @@ cadet_connect_adapter(void *cls,
* @param op_result service handle returned from the connect adapter
*/
static void
-cadet_disconnect_adapter(void *cls,
- void *op_result)
+cadet_disconnect_adapter (void *cls,
+ void *op_result)
{
struct GNUNET_CADET_Handle *cadet = op_result;
struct GNUNET_CADET_TEST_AdapterContext *actx = cls;
if (NULL != actx->ports)
+ {
+ for (unsigned int i = 0; i < actx->ctx->port_count; i++)
{
- for (unsigned int i = 0; i < actx->ctx->port_count; i++)
- {
- GNUNET_CADET_close_port(actx->ports[i]);
- actx->ports[i] = NULL;
- }
- GNUNET_free(actx->ports);
+ GNUNET_CADET_close_port (actx->ports[i]);
+ actx->ports[i] = NULL;
}
- GNUNET_free(actx);
- GNUNET_CADET_disconnect(cadet);
+ GNUNET_free (actx->ports);
+ }
+ GNUNET_free (actx);
+ GNUNET_CADET_disconnect (cadet);
}
@@ -196,56 +198,56 @@ cadet_disconnect_adapter(void *cls,
* NULL if operation has executed successfully.
*/
static void
-cadet_connect_cb(void *cls,
- struct GNUNET_TESTBED_Operation *op,
- void *ca_result,
- const char *emsg)
+cadet_connect_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
{
struct GNUNET_CADET_TEST_Context *ctx = cls;
if (NULL != emsg)
- {
- fprintf(stderr,
- "Failed to connect to CADET service: %s\n",
- emsg);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ fprintf (stderr,
+ "Failed to connect to CADET service: %s\n",
+ emsg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
for (unsigned int i = 0; i < ctx->num_peers; i++)
if (op == ctx->ops[i])
- {
- ctx->cadets[i] = ca_result;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "...cadet %u connected\n",
- i);
- }
+ {
+ ctx->cadets[i] = ca_result;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "...cadet %u connected\n",
+ i);
+ }
for (unsigned int i = 0; i < ctx->num_peers; i++)
if (NULL == ctx->cadets[i])
return;
/* still some CADET connections missing */
/* all CADET connections ready! */
- ctx->app_main(ctx->app_main_cls,
- ctx,
- ctx->num_peers,
- ctx->peers,
- ctx->cadets);
+ ctx->app_main (ctx->app_main_cls,
+ ctx,
+ ctx->num_peers,
+ ctx->peers,
+ ctx->cadets);
}
void
-GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx)
+GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx)
{
for (unsigned int i = 0; i < ctx->num_peers; i++)
- {
- GNUNET_assert(NULL != ctx->ops[i]);
- GNUNET_TESTBED_operation_done(ctx->ops[i]);
- ctx->ops[i] = NULL;
- }
- GNUNET_free(ctx->ops);
- GNUNET_free(ctx->cadets);
- GNUNET_free(ctx->handlers);
- GNUNET_free(ctx);
- GNUNET_SCHEDULER_shutdown();
+ {
+ GNUNET_assert (NULL != ctx->ops[i]);
+ GNUNET_TESTBED_operation_done (ctx->ops[i]);
+ ctx->ops[i] = NULL;
+ }
+ GNUNET_free (ctx->ops);
+ GNUNET_free (ctx->cadets);
+ GNUNET_free (ctx->handlers);
+ GNUNET_free (ctx);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -263,57 +265,57 @@ GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx)
* failed
*/
static void
-cadet_test_run(void *cls,
- struct GNUNET_TESTBED_RunHandle *h,
- unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **peers,
- unsigned int links_succeeded,
- unsigned int links_failed)
+cadet_test_run (void *cls,
+ struct GNUNET_TESTBED_RunHandle *h,
+ unsigned int num_peers,
+ struct GNUNET_TESTBED_Peer **peers,
+ unsigned int links_succeeded,
+ unsigned int links_failed)
{
struct GNUNET_CADET_TEST_Context *ctx = cls;
if (0 != links_failed)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Some links failed (%u), ending\n",
- links_failed);
- exit(77);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Some links failed (%u), ending\n",
+ links_failed);
+ exit (77);
+ }
if (num_peers != ctx->num_peers)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Peers started %u/%u, ending\n",
- num_peers,
- ctx->num_peers);
- exit(1);
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Testbed up, %u peers and %u links\n",
- num_peers,
- links_succeeded);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Peers started %u/%u, ending\n",
+ num_peers,
+ ctx->num_peers);
+ exit (1);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testbed up, %u peers and %u links\n",
+ num_peers,
+ links_succeeded);
ctx->peers = peers;
for (unsigned int i = 0; i < num_peers; i++)
- {
- struct GNUNET_CADET_TEST_AdapterContext *newctx;
-
- newctx = GNUNET_new(struct GNUNET_CADET_TEST_AdapterContext);
- newctx->peer = i;
- newctx->ctx = ctx;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Connecting to cadet %u\n",
- i);
- ctx->ops[i] = GNUNET_TESTBED_service_connect(ctx,
- peers[i],
- "cadet",
- &cadet_connect_cb,
- ctx,
- &cadet_connect_adapter,
- &cadet_disconnect_adapter,
- newctx);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "op handle %p\n",
- ctx->ops[i]);
- }
+ {
+ struct GNUNET_CADET_TEST_AdapterContext *newctx;
+
+ newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext);
+ newctx->peer = i;
+ newctx->ctx = ctx;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connecting to cadet %u\n",
+ i);
+ ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx,
+ peers[i],
+ "cadet",
+ &cadet_connect_cb,
+ ctx,
+ &cadet_connect_adapter,
+ &cadet_disconnect_adapter,
+ newctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "op handle %p\n",
+ ctx->ops[i]);
+ }
}
@@ -333,41 +335,41 @@ cadet_test_run(void *cls,
* @param ports Ports the peers offer, NULL-terminated.
*/
void
-GNUNET_CADET_TEST_ruN(const char *testname,
- const char *cfgfile,
- unsigned int num_peers,
- GNUNET_CADET_TEST_AppMain tmain,
- void *tmain_cls,
- GNUNET_CADET_ConnectEventHandler connects,
- GNUNET_CADET_WindowSizeEventHandler window_changes,
- GNUNET_CADET_DisconnectEventHandler disconnects,
- struct GNUNET_MQ_MessageHandler *handlers,
- const struct GNUNET_HashCode **ports)
+GNUNET_CADET_TEST_ruN (const char *testname,
+ const char *cfgfile,
+ unsigned int num_peers,
+ GNUNET_CADET_TEST_AppMain tmain,
+ void *tmain_cls,
+ GNUNET_CADET_ConnectEventHandler connects,
+ GNUNET_CADET_WindowSizeEventHandler window_changes,
+ GNUNET_CADET_DisconnectEventHandler disconnects,
+ struct GNUNET_MQ_MessageHandler *handlers,
+ const struct GNUNET_HashCode **ports)
{
struct GNUNET_CADET_TEST_Context *ctx;
- ctx = GNUNET_new(struct GNUNET_CADET_TEST_Context);
+ ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context);
ctx->num_peers = num_peers;
- ctx->ops = GNUNET_new_array(num_peers,
- struct GNUNET_TESTBED_Operation *);
- ctx->cadets = GNUNET_new_array(num_peers,
- struct GNUNET_CADET_Handle *);
+ ctx->ops = GNUNET_new_array (num_peers,
+ struct GNUNET_TESTBED_Operation *);
+ ctx->cadets = GNUNET_new_array (num_peers,
+ struct GNUNET_CADET_Handle *);
ctx->app_main = tmain;
ctx->app_main_cls = tmain_cls;
ctx->connects = connects;
ctx->window_changes = window_changes;
ctx->disconnects = disconnects;
- ctx->handlers = GNUNET_MQ_copy_handlers(handlers);
+ ctx->handlers = GNUNET_MQ_copy_handlers (handlers);
ctx->ports = ports;
ctx->port_count = 0;
while (NULL != ctx->ports[ctx->port_count])
ctx->port_count++;
- GNUNET_TESTBED_test_run(testname,
- cfgfile,
- num_peers,
- 0LL, NULL, NULL,
- &cadet_test_run,
- ctx);
+ GNUNET_TESTBED_test_run (testname,
+ cfgfile,
+ num_peers,
+ 0LL, NULL, NULL,
+ &cadet_test_run,
+ ctx);
}
/* end of cadet_test_lib.c */
diff --git a/src/cadet/cadet_test_lib.h b/src/cadet/cadet_test_lib.h
index f526831a6..7d446801a 100644
--- a/src/cadet/cadet_test_lib.h
+++ b/src/cadet/cadet_test_lib.h
@@ -74,16 +74,16 @@ typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls,
* @param ports Ports the peers offer, NULL-terminated.
*/
void
-GNUNET_CADET_TEST_ruN(const char *testname,
- const char *cfgfile,
- unsigned int num_peers,
- GNUNET_CADET_TEST_AppMain tmain,
- void *tmain_cls,
- GNUNET_CADET_ConnectEventHandler connects,
- GNUNET_CADET_WindowSizeEventHandler window_changes,
- GNUNET_CADET_DisconnectEventHandler disconnects,
- struct GNUNET_MQ_MessageHandler *handlers,
- const struct GNUNET_HashCode **ports);
+GNUNET_CADET_TEST_ruN (const char *testname,
+ const char *cfgfile,
+ unsigned int num_peers,
+ GNUNET_CADET_TEST_AppMain tmain,
+ void *tmain_cls,
+ GNUNET_CADET_ConnectEventHandler connects,
+ GNUNET_CADET_WindowSizeEventHandler window_changes,
+ GNUNET_CADET_DisconnectEventHandler disconnects,
+ struct GNUNET_MQ_MessageHandler *handlers,
+ const struct GNUNET_HashCode **ports);
/**
* Clean up the testbed.
@@ -91,7 +91,7 @@ GNUNET_CADET_TEST_ruN(const char *testname,
* @param ctx handle for the testbed
*/
void
-GNUNET_CADET_TEST_cleanup(struct GNUNET_CADET_TEST_Context *ctx);
+GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/desirability_table.c b/src/cadet/desirability_table.c
index 5c23de76b..829c618af 100644
--- a/src/cadet/desirability_table.c
+++ b/src/cadet/desirability_table.c
@@ -8,26 +8,26 @@
#include <stdio.h>
int
-main()
+main ()
{
for (unsigned int num_alts = 1; num_alts < 10; num_alts++)
for (unsigned int off = 0; off < 10; off++)
- for (double delta = -(int)off; delta <= 5; delta += 0.25)
- {
- double weight_alts;
+ for (double delta = -(int) off; delta <= 5; delta += 0.25)
+ {
+ double weight_alts;
- if (delta <= -1.0)
- weight_alts = -1.0 * num_alts / delta; /* discount alternative paths */
- else if (delta >= 1.0)
- weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */
- else
- weight_alts = 1.0 * num_alts; /* count alternative paths normally */
+ if (delta <= -1.0)
+ weight_alts = -1.0 * num_alts / delta; /* discount alternative paths */
+ else if (delta >= 1.0)
+ weight_alts = 1.0 * num_alts * delta; /* overcount alternative paths */
+ else
+ weight_alts = 1.0 * num_alts; /* count alternative paths normally */
- fprintf(stderr,
- "Paths: %u Offset: %u Delta: %5.2f SCORE: %f\n",
- num_alts,
- off,
- delta,
- ((off + 1.0) / (weight_alts * weight_alts)));
- }
+ fprintf (stderr,
+ "Paths: %u Offset: %u Delta: %5.2f SCORE: %f\n",
+ num_alts,
+ off,
+ delta,
+ ((off + 1.0) / (weight_alts * weight_alts)));
+ }
}
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index b3e7fa30d..e66761e1e 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -41,12 +41,12 @@
/**
* How long until we give up on connecting the peers?
*/
-#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
/**
* Time to wait for stuff that should be rather fast
*/
-#define SHORT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
+#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
/**
* Total number of rounds.
@@ -61,7 +61,8 @@ static float rounds[] = { 0.8, 0.6, 0.8, 0.5, 0.3, 0.8, 0.0 };
/**
* Message type for pings.
*/
-struct CadetPingMessage {
+struct CadetPingMessage
+{
/**
* Header. Type PING/PONG.
*/
@@ -86,7 +87,8 @@ struct CadetPingMessage {
/**
* Peer description.
*/
-struct CadetPeer {
+struct CadetPeer
+{
/**
* Testbed Operation (to get peer id, etc).
*/
@@ -253,7 +255,7 @@ static struct GNUNET_SCHEDULER_Task *round_task;
* @param cls Closure (unsued).
*/
static void
-start_test(void *cls);
+start_test (void *cls);
/**
@@ -264,12 +266,12 @@ start_test(void *cls);
* @return A time between 0 a max-1 ms.
*/
static struct GNUNET_TIME_Relative
-delay_ms_rnd(unsigned int max)
+delay_ms_rnd (unsigned int max)
{
unsigned int rnd;
- rnd = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max);
- return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, rnd);
+ rnd = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max);
+ return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, rnd);
}
@@ -281,7 +283,7 @@ delay_ms_rnd(unsigned int max)
* @return Index of peer in peers.
*/
static unsigned int
-get_index(struct CadetPeer *peer)
+get_index (struct CadetPeer *peer)
{
return peer - peers;
}
@@ -291,23 +293,23 @@ get_index(struct CadetPeer *peer)
* Show the results of the test (banwidth acheived) and log them to GAUGER
*/
static void
-show_end_data(void)
+show_end_data (void)
{
struct CadetPeer *peer;
unsigned int i;
unsigned int j;
for (i = 0; i < number_rounds; i++)
+ {
+ for (j = 0; j < peers_pinging; j++)
{
- for (j = 0; j < peers_pinging; j++)
- {
- peer = &peers[j];
- fprintf(stdout,
- "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
- i, j, peer->mean[i], sqrt(peer->var[i] / (peer->pongs[i] - 1)),
- peer->pings[i], peer->pongs[i]);
- }
+ peer = &peers[j];
+ fprintf (stdout,
+ "ROUND %3u PEER %3u: %10.2f / %10.2f, PINGS: %3u, PONGS: %3u\n",
+ i, j, peer->mean[i], sqrt (peer->var[i] / (peer->pongs[i] - 1)),
+ peer->pings[i], peer->pongs[i]);
}
+ }
}
@@ -317,46 +319,46 @@ show_end_data(void)
* @param cls Closure (unused).
*/
static void
-disconnect_cadet_peers(void *cls)
+disconnect_cadet_peers (void *cls)
{
- long line = (long)cls;
+ long line = (long) cls;
unsigned int i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet service, called from line %ld\n",
- line);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "disconnecting cadet service, called from line %ld\n",
+ line);
disconnect_task = NULL;
for (i = 0; i < peers_total; i++)
+ {
+ if (NULL != peers[i].op)
+ GNUNET_TESTBED_operation_done (peers[i].op);
+
+ if (peers[i].up != GNUNET_YES)
+ continue;
+
+ if (NULL != peers[i].ch)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: channel %p\n", i, peers[i].ch);
+ GNUNET_CADET_channel_destroy (peers[i].ch);
+ }
+ if (NULL != peers[i].warmup_ch)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: warmup channel %p\n",
+ i, peers[i].warmup_ch);
+ GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
+ }
+ if (NULL != peers[i].incoming_ch)
{
- if (NULL != peers[i].op)
- GNUNET_TESTBED_operation_done(peers[i].op);
-
- if (peers[i].up != GNUNET_YES)
- continue;
-
- if (NULL != peers[i].ch)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%u: channel %p\n", i, peers[i].ch);
- GNUNET_CADET_channel_destroy(peers[i].ch);
- }
- if (NULL != peers[i].warmup_ch)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%u: warmup channel %p\n",
- i, peers[i].warmup_ch);
- GNUNET_CADET_channel_destroy(peers[i].warmup_ch);
- }
- if (NULL != peers[i].incoming_ch)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%u: incoming channel %p\n",
- i, peers[i].incoming_ch);
- GNUNET_CADET_channel_destroy(peers[i].incoming_ch);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: incoming channel %p\n",
+ i, peers[i].incoming_ch);
+ GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
}
- GNUNET_CADET_TEST_cleanup(test_ctx);
- GNUNET_SCHEDULER_shutdown();
+ }
+ GNUNET_CADET_TEST_cleanup (test_ctx);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -366,26 +368,26 @@ disconnect_cadet_peers(void *cls)
* @param cls Closure (unused).
*/
static void
-shutdown_task(void *cls)
+shutdown_task (void *cls)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Ending test.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Ending test.\n");
if (NULL != disconnect_task)
- {
- GNUNET_SCHEDULER_cancel(disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers,
- (void *)__LINE__);
- }
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
+ }
if (NULL != round_task)
- {
- GNUNET_SCHEDULER_cancel(round_task);
- round_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
if (NULL != test_task)
- {
- GNUNET_SCHEDULER_cancel(test_task);
- test_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
+ }
}
@@ -395,14 +397,14 @@ shutdown_task(void *cls)
* @param line Line in the code the abort is requested from (__LINE__).
*/
static void
-abort_test(long line)
+abort_test (long line)
{
if (disconnect_task != NULL)
- {
- GNUNET_SCHEDULER_cancel(disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers,
- (void *)line);
- }
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) line);
+ }
}
/**
@@ -415,15 +417,15 @@ abort_test(long line)
* operation has executed successfully.
*/
static void
-stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
+stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
- GNUNET_TESTBED_operation_done(stats_op);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "... collecting statistics done.\n");
+ GNUNET_TESTBED_operation_done (stats_op);
if (NULL != disconnect_task)
- GNUNET_SCHEDULER_cancel(disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_cadet_peers,
- (void *)__LINE__);
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
}
@@ -439,20 +441,20 @@ stats_cont(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator(void *cls,
- const struct GNUNET_TESTBED_Peer *peer,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+stats_iterator (void *cls,
+ const struct GNUNET_TESTBED_Peer *peer,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
{
uint32_t i;
- i = GNUNET_TESTBED_get_index(peer);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- " STATS %u - %s [%s]: %llu\n",
- i, subsystem, name,
- (unsigned long long)value);
+ i = GNUNET_TESTBED_get_index (peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " STATS %u - %s [%s]: %llu\n",
+ i, subsystem, name,
+ (unsigned long long) value);
return GNUNET_OK;
}
@@ -464,15 +466,15 @@ stats_iterator(void *cls,
* @param cls Closure (NULL).
*/
static void
-collect_stats(void *cls)
+collect_stats (void *cls)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Start collecting statistics...\n");
- stats_op = GNUNET_TESTBED_get_statistics(peers_total,
- testbed_handles,
- NULL, NULL,
- &stats_iterator,
- &stats_cont, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Start collecting statistics...\n");
+ stats_op = GNUNET_TESTBED_get_statistics (peers_total,
+ testbed_handles,
+ NULL, NULL,
+ &stats_iterator,
+ &stats_cont, NULL);
}
@@ -482,11 +484,11 @@ collect_stats(void *cls)
* @param cls Closure (unused).
*/
static void
-finish_profiler(void *cls)
+finish_profiler (void *cls)
{
test_finished = GNUNET_YES;
- show_end_data();
- GNUNET_SCHEDULER_add_now(&collect_stats, NULL);
+ show_end_data ();
+ GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
}
@@ -496,7 +498,7 @@ finish_profiler(void *cls)
* @param target Desired number of running peers.
*/
static void
-adjust_running_peers(unsigned int target)
+adjust_running_peers (unsigned int target)
{
struct GNUNET_TESTBED_Operation *op;
unsigned int delta;
@@ -504,60 +506,60 @@ adjust_running_peers(unsigned int target)
unsigned int i;
unsigned int r;
- GNUNET_assert(target <= peers_total);
+ GNUNET_assert (target <= peers_total);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "adjust peers to %u\n", target);
if (target > peers_running)
+ {
+ delta = target - peers_running;
+ run = GNUNET_YES;
+ }
+ else
+ {
+ delta = peers_running - target;
+ run = GNUNET_NO;
+ }
+
+ for (i = 0; i < delta; i++)
+ {
+ do
{
- delta = target - peers_running;
- run = GNUNET_YES;
+ r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ peers_total - peers_pinging);
+ r += peers_pinging;
}
- else
+ while (peers[r].up == run || NULL != peers[r].incoming);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
+ run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
+
+ if (NULL != peers[r].ping_task)
+ {
+ GNUNET_SCHEDULER_cancel (peers[r].ping_task);
+ peers[r].ping_task = NULL;
+ }
+ if (NULL != peers[r].ping_ntr)
{
- delta = peers_running - target;
- run = GNUNET_NO;
+ GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
+ peers[r].ping_ntr = NULL;
}
+ peers[r].up = run;
- for (i = 0; i < delta; i++)
+ if (NULL != peers[r].ch)
+ GNUNET_CADET_channel_destroy (peers[r].ch);
+ peers[r].ch = NULL;
+ if (NULL != peers[r].dest)
{
- do
- {
- r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
- peers_total - peers_pinging);
- r += peers_pinging;
- }
- while (peers[r].up == run || NULL != peers[r].incoming);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "St%s peer %u: %s\n",
- run ? "arting" : "opping", r, GNUNET_i2s(&peers[r].id));
-
- if (NULL != peers[r].ping_task)
- {
- GNUNET_SCHEDULER_cancel(peers[r].ping_task);
- peers[r].ping_task = NULL;
- }
- if (NULL != peers[r].ping_ntr)
- {
- GNUNET_CADET_notify_transmit_ready_cancel(peers[r].ping_ntr);
- peers[r].ping_ntr = NULL;
- }
- peers[r].up = run;
-
- if (NULL != peers[r].ch)
- GNUNET_CADET_channel_destroy(peers[r].ch);
- peers[r].ch = NULL;
- if (NULL != peers[r].dest)
- {
- if (NULL != peers[r].dest->incoming_ch)
- GNUNET_CADET_channel_destroy(peers[r].dest->incoming_ch);
- peers[r].dest->incoming_ch = NULL;
- }
-
- op = GNUNET_TESTBED_peer_manage_service(&peers[r], testbed_handles[r],
- "cadet", NULL, NULL, run);
- GNUNET_break(NULL != op);
- peers_running += run ? 1 : -1;
- GNUNET_assert(peers_running > 0);
+ if (NULL != peers[r].dest->incoming_ch)
+ GNUNET_CADET_channel_destroy (peers[r].dest->incoming_ch);
+ peers[r].dest->incoming_ch = NULL;
}
+
+ op = GNUNET_TESTBED_peer_manage_service (&peers[r], testbed_handles[r],
+ "cadet", NULL, NULL, run);
+ GNUNET_break (NULL != op);
+ peers_running += run ? 1 : -1;
+ GNUNET_assert (peers_running > 0);
+ }
}
@@ -567,23 +569,23 @@ adjust_running_peers(unsigned int target)
* @param cls Closure (round #).
*/
static void
-next_rnd(void *cls)
+next_rnd (void *cls)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "ROUND %u\n",
- current_round);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "ROUND %u\n",
+ current_round);
if (0.0 == rounds[current_round])
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Finishing\n");
- GNUNET_SCHEDULER_add_now(&finish_profiler, NULL);
- return;
- }
- adjust_running_peers(rounds[current_round] * peers_total);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
+ GNUNET_SCHEDULER_add_now (&finish_profiler, NULL);
+ return;
+ }
+ adjust_running_peers (rounds[current_round] * peers_total);
current_round++;
- round_task = GNUNET_SCHEDULER_add_delayed(round_time,
- &next_rnd,
- NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
@@ -597,7 +599,7 @@ next_rnd(void *cls)
* @return Number of bytes written to buf.
*/
static size_t
-tmt_rdy_ping(void *cls, size_t size, void *buf);
+tmt_rdy_ping (void *cls, size_t size, void *buf);
/**
@@ -608,21 +610,21 @@ tmt_rdy_ping(void *cls, size_t size, void *buf);
* @param buf Buffer to copy data to.
*/
static size_t
-tmt_rdy_pong(void *cls, size_t size, void *buf)
+tmt_rdy_pong (void *cls, size_t size, void *buf)
{
struct CadetPingMessage *ping = cls;
struct CadetPingMessage *pong;
- if (0 == size || NULL == buf)
- {
- GNUNET_free(ping);
- return 0;
- }
- pong = (struct CadetPingMessage *)buf;
- GNUNET_memcpy(pong, ping, sizeof(*ping));
- pong->header.type = htons(PONG);
+ if ((0 == size)||(NULL == buf))
+ {
+ GNUNET_free (ping);
+ return 0;
+ }
+ pong = (struct CadetPingMessage *) buf;
+ GNUNET_memcpy (pong, ping, sizeof(*ping));
+ pong->header.type = htons (PONG);
- GNUNET_free(ping);
+ GNUNET_free (ping);
return sizeof(*ping);
}
@@ -633,22 +635,23 @@ tmt_rdy_pong(void *cls, size_t size, void *buf)
* @param cls Closure (peer).
*/
static void
-ping(void *cls)
+ping (void *cls)
{
struct CadetPeer *peer = cls;
peer->ping_task = NULL;
if (GNUNET_YES == test_finished)
return;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%u -> %u (%u)\n",
- get_index(peer),
- get_index(peer->dest),
- peer->data_sent);
- peer->ping_ntr = GNUNET_CADET_notify_transmit_ready(peer->ch, GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof(struct CadetPingMessage),
- &tmt_rdy_ping, peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u -> %u (%u)\n",
+ get_index (peer),
+ get_index (peer->dest),
+ peer->data_sent);
+ peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof(struct
+ CadetPingMessage),
+ &tmt_rdy_ping, peer);
}
/**
@@ -658,17 +661,17 @@ ping(void *cls)
* @param tc Task context.
*/
static void
-pong(struct GNUNET_CADET_Channel *channel,
- const struct CadetPingMessage *ping)
+pong (struct GNUNET_CADET_Channel *channel,
+ const struct CadetPingMessage *ping)
{
struct CadetPingMessage *copy;
- copy = GNUNET_new(struct CadetPingMessage);
+ copy = GNUNET_new (struct CadetPingMessage);
*copy = *ping;
- GNUNET_CADET_notify_transmit_ready(channel, GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof(struct CadetPingMessage),
- &tmt_rdy_pong, copy);
+ GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof(struct CadetPingMessage),
+ &tmt_rdy_pong, copy);
}
@@ -680,37 +683,37 @@ pong(struct GNUNET_CADET_Channel *channel,
* @param buf Buffer to copy data to.
*/
static size_t
-tmt_rdy_ping(void *cls, size_t size, void *buf)
+tmt_rdy_ping (void *cls, size_t size, void *buf)
{
struct CadetPeer *peer = cls;
struct CadetPingMessage *msg = buf;
peer->ping_ntr = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "tmt_rdy called, filling buffer\n");
- if (size < sizeof(struct CadetPingMessage) || NULL == buf)
- {
- GNUNET_break(GNUNET_YES == test_finished);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "size %u, buf %p, data_sent %u, data_received %u\n",
- (unsigned int)size,
- buf,
- peer->data_sent,
- peer->data_received);
-
- return 0;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending: msg %d\n",
- peer->data_sent);
- msg->header.size = htons(size);
- msg->header.type = htons(PING);
- msg->counter = htonl(peer->data_sent++);
- msg->round_number = htonl(current_round);
- msg->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get());
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tmt_rdy called, filling buffer\n");
+ if ((size < sizeof(struct CadetPingMessage))||(NULL == buf))
+ {
+ GNUNET_break (GNUNET_YES == test_finished);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "size %u, buf %p, data_sent %u, data_received %u\n",
+ (unsigned int) size,
+ buf,
+ peer->data_sent,
+ peer->data_received);
+
+ return 0;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending: msg %d\n",
+ peer->data_sent);
+ msg->header.size = htons (size);
+ msg->header.type = htons (PING);
+ msg->counter = htonl (peer->data_sent++);
+ msg->round_number = htonl (current_round);
+ msg->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
peer->pings[current_round]++;
- peer->ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(PING_PERIOD),
- &ping, peer);
+ peer->ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (PING_PERIOD),
+ &ping, peer);
return sizeof(struct CadetPingMessage);
}
@@ -727,18 +730,18 @@ tmt_rdy_ping(void *cls, size_t size, void *buf)
* GNUNET_SYSERR to close it (signal serious error)
*/
int
-ping_handler(void *cls, struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *message)
+ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *message)
{
- long n = (long)cls;
+ long n = (long) cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "%u got PING\n",
- (unsigned int)n);
- GNUNET_CADET_receive_done(channel);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u got PING\n",
+ (unsigned int) n);
+ GNUNET_CADET_receive_done (channel);
if (GNUNET_NO == test_finished)
- pong(channel, (struct CadetPingMessage *)message);
+ pong (channel, (struct CadetPingMessage *) message);
return GNUNET_OK;
}
@@ -755,11 +758,11 @@ ping_handler(void *cls, struct GNUNET_CADET_Channel *channel,
* GNUNET_SYSERR to close it (signal serious error)
*/
int
-pong_handler(void *cls, struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *message)
+pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *message)
{
- long n = (long)cls;
+ long n = (long) cls;
struct CadetPeer *peer;
struct CadetPingMessage *msg;
struct GNUNET_TIME_Absolute send_time;
@@ -767,19 +770,19 @@ pong_handler(void *cls, struct GNUNET_CADET_Channel *channel,
unsigned int r /* Ping round */;
float delta;
- GNUNET_CADET_receive_done(channel);
+ GNUNET_CADET_receive_done (channel);
peer = &peers[n];
- msg = (struct CadetPingMessage *)message;
+ msg = (struct CadetPingMessage *) message;
- send_time = GNUNET_TIME_absolute_ntoh(msg->timestamp);
- latency = GNUNET_TIME_absolute_get_duration(send_time);
- r = ntohl(msg->round_number);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
- get_index(peer),
- get_index(peer->dest),
- (uint32_t)ntohl(msg->counter),
- GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO));
+ send_time = GNUNET_TIME_absolute_ntoh (msg->timestamp);
+ latency = GNUNET_TIME_absolute_get_duration (send_time);
+ r = ntohl (msg->round_number);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
+ get_index (peer),
+ get_index (peer->dest),
+ (uint32_t) ntohl (msg->counter),
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
/* Online variance calculation */
peer->pongs[r]++;
@@ -814,41 +817,41 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
* (can be NULL -- that's not an error).
*/
static void *
-incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel,
- const struct GNUNET_PeerIdentity *initiator,
- const struct GNUNET_HashCode *port,
- enum GNUNET_CADET_ChannelOption options)
+incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
+ const struct GNUNET_PeerIdentity *initiator,
+ const struct GNUNET_HashCode *port,
+ enum GNUNET_CADET_ChannelOption options)
{
- long n = (long)cls;
+ long n = (long) cls;
struct CadetPeer *peer;
- peer = GNUNET_CONTAINER_multipeermap_get(ids, initiator);
- GNUNET_assert(NULL != peer);
+ peer = GNUNET_CONTAINER_multipeermap_get (ids, initiator);
+ GNUNET_assert (NULL != peer);
if (NULL == peers[n].incoming)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "WARMUP %3u: %u <= %u\n",
- peers_warmup,
- (unsigned int)n,
- get_index(peer));
- peers_warmup++;
- if (peers_warmup < peers_total)
- return NULL;
- if (NULL != test_task)
- {
- GNUNET_SCHEDULER_cancel(test_task);
- test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
- &start_test, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "WARMUP %3u: %u <= %u\n",
+ peers_warmup,
+ (unsigned int) n,
+ get_index (peer));
+ peers_warmup++;
+ if (peers_warmup < peers_total)
return NULL;
+ if (NULL != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &start_test, NULL);
}
- GNUNET_assert(peer == peers[n].incoming);
- GNUNET_assert(peer->dest == &peers[n]);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%u <= %u %p\n",
- (unsigned int)n,
- get_index(peer),
- channel);
+ return NULL;
+ }
+ GNUNET_assert (peer == peers[n].incoming);
+ GNUNET_assert (peer->dest == &peers[n]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u <= %u %p\n",
+ (unsigned int) n,
+ get_index (peer),
+ channel);
peers[n].incoming_ch = channel;
return NULL;
@@ -864,15 +867,15 @@ incoming_channel(void *cls, struct GNUNET_CADET_Channel *channel,
* with the channel is stored
*/
static void
-channel_cleaner(void *cls,
- const struct GNUNET_CADET_Channel *channel,
- void *channel_ctx)
+channel_cleaner (void *cls,
+ const struct GNUNET_CADET_Channel *channel,
+ void *channel_ctx)
{
- long n = (long)cls;
+ long n = (long) cls;
struct CadetPeer *peer = &peers[n];
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Channel %p disconnected at peer %ld\n", channel, n);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Channel %p disconnected at peer %ld\n", channel, n);
if (peer->ch == channel)
peer->ch = NULL;
}
@@ -886,14 +889,14 @@ channel_cleaner(void *cls,
* @return Random peer not yet connected to.
*/
static struct CadetPeer *
-select_random_peer(struct CadetPeer *peer)
+select_random_peer (struct CadetPeer *peer)
{
unsigned int r;
do
- {
- r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
- }
+ {
+ r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, peers_total);
+ }
while (NULL != peers[r].incoming);
peers[r].incoming = peer;
@@ -909,45 +912,46 @@ select_random_peer(struct CadetPeer *peer)
* @param cls Closure (unsued).
*/
static void
-start_test(void *cls)
+start_test (void *cls)
{
unsigned long i;
test_task = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
for (i = 0; i < peers_pinging; i++)
+ {
+ peers[i].dest = select_random_peer (&peers[i]);
+ peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
+ &peers[i].dest->id,
+ GC_u2h (1));
+ if (NULL == peers[i].ch)
{
- peers[i].dest = select_random_peer(&peers[i]);
- peers[i].ch = GNUNET_CADET_channel_create(peers[i].cadet, NULL,
- &peers[i].dest->id,
- GC_u2h(1));
- if (NULL == peers[i].ch)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
- GNUNET_CADET_TEST_cleanup(test_ctx);
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%lu => %u %p\n",
- i,
- get_index(peers[i].dest),
- peers[i].ch);
- peers[i].ping_task = GNUNET_SCHEDULER_add_delayed(delay_ms_rnd(2000),
- &ping, &peers[i]);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
+ GNUNET_CADET_TEST_cleanup (test_ctx);
+ return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%lu => %u %p\n",
+ i,
+ get_index (peers[i].dest),
+ peers[i].ch);
+ peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
+ &ping, &peers[i]);
+ }
peers_running = peers_total;
if (NULL != disconnect_task)
- GNUNET_SCHEDULER_cancel(disconnect_task);
+ GNUNET_SCHEDULER_cancel (disconnect_task);
disconnect_task =
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(round_time,
- number_rounds + 1),
- &disconnect_cadet_peers,
- (void *)__LINE__);
- round_task = GNUNET_SCHEDULER_add_delayed(round_time,
- &next_rnd,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (round_time,
+ number_rounds
+ + 1),
+ &disconnect_cadet_peers,
+ (void *) __LINE__);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
@@ -955,26 +959,26 @@ start_test(void *cls)
* Do warmup: create some channels to spread information about the topology.
*/
static void
-warmup(void)
+warmup (void)
{
struct CadetPeer *peer;
unsigned int i;
for (i = 0; i < peers_total; i++)
+ {
+ peer = select_random_peer (NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
+ i, get_index (peer));
+ peers[i].warmup_ch =
+ GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
+ GC_u2h (1));
+ if (NULL == peers[i].warmup_ch)
{
- peer = select_random_peer(NULL);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WARMUP %u => %u\n",
- i, get_index(peer));
- peers[i].warmup_ch =
- GNUNET_CADET_channel_create(peers[i].cadet, NULL, &peer->id,
- GC_u2h(1));
- if (NULL == peers[i].warmup_ch)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
- GNUNET_CADET_TEST_cleanup(test_ctx);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
+ GNUNET_CADET_TEST_cleanup (test_ctx);
+ return;
}
+ }
}
@@ -988,48 +992,48 @@ warmup(void)
* NULL if the operation is successfull
*/
static void
-peer_id_cb(void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
+peer_id_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ const struct GNUNET_TESTBED_PeerInformation *pinfo,
+ const char *emsg)
{
- long n = (long)cls;
+ long n = (long) cls;
- if (NULL == pinfo || NULL != emsg)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
- abort_test(__LINE__);
- return;
- }
+ if ((NULL == pinfo)||(NULL != emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
+ abort_test (__LINE__);
+ return;
+ }
peers[n].id = *(pinfo->result.id);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "%ld id: %s\n",
- n,
- GNUNET_i2s(&peers[n].id));
- GNUNET_break(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put(ids, &peers[n].id, &peers[n],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
-
- GNUNET_TESTBED_operation_done(peers[n].op);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%ld id: %s\n",
+ n,
+ GNUNET_i2s (&peers[n].id));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+
+ GNUNET_TESTBED_operation_done (peers[n].op);
peers[n].op = NULL;
p_ids++;
if (p_ids < peers_total)
return;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got all IDs, starting profiler\n");
if (do_warmup)
- {
- struct GNUNET_TIME_Relative delay;
-
- warmup();
- delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,
- 100 * peers_total);
- test_task = GNUNET_SCHEDULER_add_delayed(delay, &start_test, NULL);
- return; /* start_test from incoming_channel */
- }
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
- test_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
- &start_test, NULL);
+ {
+ struct GNUNET_TIME_Relative delay;
+
+ warmup ();
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ 100 * peers_total);
+ test_task = GNUNET_SCHEDULER_add_delayed (delay, &start_test, NULL);
+ return; /* start_test from incoming_channel */
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting in a second...\n");
+ test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &start_test, NULL);
}
@@ -1043,37 +1047,37 @@ peer_id_cb(void *cls,
* @param cadetes Handle to each of the CADETs of the peers.
*/
static void
-tmain(void *cls,
- struct GNUNET_CADET_TEST_Context *ctx,
- unsigned int num_peers,
- struct GNUNET_TESTBED_Peer **testbed_peers,
- struct GNUNET_CADET_Handle **cadetes)
+tmain (void *cls,
+ struct GNUNET_CADET_TEST_Context *ctx,
+ unsigned int num_peers,
+ struct GNUNET_TESTBED_Peer **testbed_peers,
+ struct GNUNET_CADET_Handle **cadetes)
{
unsigned long i;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "test main\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test main\n");
test_ctx = ctx;
- GNUNET_assert(peers_total == num_peers);
+ GNUNET_assert (peers_total == num_peers);
peers_running = num_peers;
testbed_handles = testbed_peers;
- disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
- &disconnect_cadet_peers,
- (void *)__LINE__);
- GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
+ disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
+ &disconnect_cadet_peers,
+ (void *) __LINE__);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
for (i = 0; i < peers_total; i++)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "requesting id %ld\n",
- i);
- peers[i].up = GNUNET_YES;
- peers[i].cadet = cadetes[i];
- peers[i].op =
- GNUNET_TESTBED_peer_get_information(testbed_handles[i],
- GNUNET_TESTBED_PIT_IDENTITY,
- &peer_id_cb, (void *)i);
- }
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "requesting id %ld\n",
+ i);
+ peers[i].up = GNUNET_YES;
+ peers[i].cadet = cadetes[i];
+ peers[i].op =
+ GNUNET_TESTBED_peer_get_information (testbed_handles[i],
+ GNUNET_TESTBED_PIT_IDENTITY,
+ &peer_id_cb, (void *) i);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "requested peer ids\n");
/* Continues from pi_cb -> do_test */
}
@@ -1082,7 +1086,7 @@ tmain(void *cls,
* Main: start profiler.
*/
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
static const struct GNUNET_HashCode *ports[2];
const char *config_file;
@@ -1090,59 +1094,59 @@ main(int argc, char *argv[])
config_file = ".profiler.conf";
if (4 > argc)
- {
- fprintf(stderr,
- "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
- argv[0]);
- fprintf(stderr,
- "example: %s 30s 16 1 Y\n",
- argv[0]);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
+ argv[0]);
+ fprintf (stderr,
+ "example: %s 30s 16 1 Y\n",
+ argv[0]);
+ return 1;
+ }
if (GNUNET_OK !=
- GNUNET_STRINGS_fancy_time_to_relative(argv[1],
- &round_time))
- {
- fprintf(stderr,
- "%s is not a valid time\n",
- argv[1]);
- return 1;
- }
-
- peers_total = atoll(argv[2]);
+ GNUNET_STRINGS_fancy_time_to_relative (argv[1],
+ &round_time))
+ {
+ fprintf (stderr,
+ "%s is not a valid time\n",
+ argv[1]);
+ return 1;
+ }
+
+ peers_total = atoll (argv[2]);
if (2 > peers_total)
- {
- fprintf(stderr,
- "%s peers is not valid (> 2)\n",
- argv[1]);
- return 1;
- }
- peers = GNUNET_new_array(peers_total,
- struct CadetPeer);
- peers_pinging = atoll(argv[3]);
+ {
+ fprintf (stderr,
+ "%s peers is not valid (> 2)\n",
+ argv[1]);
+ return 1;
+ }
+ peers = GNUNET_new_array (peers_total,
+ struct CadetPeer);
+ peers_pinging = atoll (argv[3]);
if (peers_total < 2 * peers_pinging)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "not enough peers, total should be > 2 * peers_pinging\n");
- return 1;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "not enough peers, total should be > 2 * peers_pinging\n");
+ return 1;
+ }
do_warmup = (5 > argc || argv[4][0] != 'N');
- ids = GNUNET_CONTAINER_multipeermap_create(2 * peers_total,
- GNUNET_YES);
- GNUNET_assert(NULL != ids);
+ ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
+ GNUNET_YES);
+ GNUNET_assert (NULL != ids);
p_ids = 0;
test_finished = GNUNET_NO;
- ports[0] = GC_u2h(1);
+ ports[0] = GC_u2h (1);
ports[1] = 0;
- GNUNET_CADET_TEST_run("cadet-profiler", config_file, peers_total,
- &tmain, NULL, /* tmain cls */
- &incoming_channel, &channel_cleaner,
- handlers, ports);
- GNUNET_free(peers);
+ GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
+ &tmain, NULL, /* tmain cls */
+ &incoming_channel, &channel_cleaner,
+ handlers, ports);
+ GNUNET_free (peers);
return 0;
}
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index f5cf86211..d85a3c6ba 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -143,7 +143,7 @@ static unsigned int sent_pkt;
* Wait for input on STDIO and send it out over the #ch.
*/
static void
-listen_stdio(void);
+listen_stdio (void);
/**
@@ -154,25 +154,25 @@ listen_stdio(void);
* @return Human readable string.
*/
static const char *
-enc_2s(uint16_t status)
+enc_2s (uint16_t status)
{
switch (status)
- {
- case 0:
- return "NULL ";
+ {
+ case 0:
+ return "NULL ";
- case 1:
- return "KSENT";
+ case 1:
+ return "KSENT";
- case 2:
- return "KRECV";
+ case 2:
+ return "KRECV";
- case 3:
- return "READY";
+ case 3:
+ return "READY";
- default:
- return "";
- }
+ default:
+ return "";
+ }
}
@@ -184,28 +184,28 @@ enc_2s(uint16_t status)
* @return Human readable string.
*/
static const char *
-conn_2s(uint16_t status)
+conn_2s (uint16_t status)
{
switch (status)
- {
- case 0:
- return "NEW ";
+ {
+ case 0:
+ return "NEW ";
- case 1:
- return "SRCH ";
+ case 1:
+ return "SRCH ";
- case 2:
- return "WAIT ";
+ case 2:
+ return "WAIT ";
- case 3:
- return "READY";
+ case 3:
+ return "READY";
- case 4:
- return "SHUTD";
+ case 4:
+ return "SHUTD";
- default:
- return "";
- }
+ default:
+ return "";
+ }
}
@@ -215,60 +215,60 @@ conn_2s(uint16_t status)
* @param cls Closure (unused).
*/
static void
-shutdown_task(void *cls)
+shutdown_task (void *cls)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
if (NULL != lp)
- {
- GNUNET_CADET_close_port(lp);
- lp = NULL;
- }
+ {
+ GNUNET_CADET_close_port (lp);
+ lp = NULL;
+ }
if (NULL != ch)
- {
- GNUNET_CADET_channel_destroy(ch);
- ch = NULL;
- }
+ {
+ GNUNET_CADET_channel_destroy (ch);
+ ch = NULL;
+ }
if (NULL != gpo)
- {
- GNUNET_CADET_get_path_cancel(gpo);
- gpo = NULL;
- }
+ {
+ GNUNET_CADET_get_path_cancel (gpo);
+ gpo = NULL;
+ }
if (NULL != plo)
- {
- GNUNET_CADET_list_peers_cancel(plo);
- plo = NULL;
- }
+ {
+ GNUNET_CADET_list_peers_cancel (plo);
+ plo = NULL;
+ }
if (NULL != tio)
- {
- GNUNET_CADET_list_tunnels_cancel(tio);
- tio = NULL;
- }
+ {
+ GNUNET_CADET_list_tunnels_cancel (tio);
+ tio = NULL;
+ }
if (NULL != mh)
- {
- GNUNET_CADET_disconnect(mh);
- mh = NULL;
- }
+ {
+ GNUNET_CADET_disconnect (mh);
+ mh = NULL;
+ }
if (NULL != rd_task)
- {
- GNUNET_SCHEDULER_cancel(rd_task);
- rd_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (rd_task);
+ rd_task = NULL;
+ }
if (NULL != echo_task)
- {
- GNUNET_SCHEDULER_cancel(echo_task);
- echo_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (echo_task);
+ echo_task = NULL;
+ }
if (NULL != job)
- {
- GNUNET_SCHEDULER_cancel(job);
- job = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (job);
+ job = NULL;
+ }
}
void
-mq_cb(void *cls)
+mq_cb (void *cls)
{
- listen_stdio();
+ listen_stdio ();
}
@@ -278,7 +278,7 @@ mq_cb(void *cls)
* @param cls Closure (unused).
*/
static void
-read_stdio(void *cls)
+read_stdio (void *cls)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
@@ -286,41 +286,41 @@ read_stdio(void *cls)
ssize_t data_size;
rd_task = NULL;
- data_size = read(0, buf, 60000);
+ data_size = read (0, buf, 60000);
if (data_size < 1)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "read() returned %s\n",
- strerror(errno));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Read %u bytes from stdio\n",
- (unsigned int)data_size);
- env = GNUNET_MQ_msg_extra(msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_memcpy(&msg[1], buf, data_size);
- GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "read() returned %s\n",
+ strerror (errno));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Read %u bytes from stdio\n",
+ (unsigned int) data_size);
+ env = GNUNET_MQ_msg_extra (msg, data_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_memcpy (&msg[1], buf, data_size);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
sent_pkt++;
if (GNUNET_NO == echo)
+ {
+ // Use MQ's notification if too much data of stdin is pooring in too fast.
+ if (STREAM_BUFFER_SIZE < sent_pkt)
{
- // Use MQ's notification if too much data of stdin is pooring in too fast.
- if (STREAM_BUFFER_SIZE < sent_pkt)
- {
- GNUNET_MQ_notify_sent(env, mq_cb, cls);
- sent_pkt = 0;
- }
- else
- {
- listen_stdio();
- }
+ GNUNET_MQ_notify_sent (env, mq_cb, cls);
+ sent_pkt = 0;
}
- else
+ else
{
- echo_time = GNUNET_TIME_absolute_get();
+ listen_stdio ();
}
+ }
+ else
+ {
+ echo_time = GNUNET_TIME_absolute_get ();
+ }
}
@@ -328,20 +328,20 @@ read_stdio(void *cls)
* Wait for input on STDIO and send it out over the #ch.
*/
static void
-listen_stdio()
+listen_stdio ()
{
struct GNUNET_NETWORK_FDSet *rs;
/* FIXME: why use 'rs' here, seems overly complicated... */
- rs = GNUNET_NETWORK_fdset_create();
- GNUNET_NETWORK_fdset_set_native(rs, 0); /* STDIN */
- rd_task = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_TIME_UNIT_FOREVER_REL,
- rs,
- NULL,
- &read_stdio,
- NULL);
- GNUNET_NETWORK_fdset_destroy(rs);
+ rs = GNUNET_NETWORK_fdset_create ();
+ GNUNET_NETWORK_fdset_set_native (rs, 0); /* STDIN */
+ rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rs,
+ NULL,
+ &read_stdio,
+ NULL);
+ GNUNET_NETWORK_fdset_destroy (rs);
}
@@ -355,12 +355,12 @@ listen_stdio()
* @param channel connection to the other end (henceforth invalid)
*/
static void
-channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel)
+channel_ended (void *cls, const struct GNUNET_CADET_Channel *channel)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
- GNUNET_assert(channel == ch);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel ended!\n");
+ GNUNET_assert (channel == ch);
ch = NULL;
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -379,20 +379,20 @@ channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel)
* @return initial channel context for the channel, we use @a channel
*/
static void *
-channel_incoming(void *cls,
- struct GNUNET_CADET_Channel *channel,
- const struct GNUNET_PeerIdentity *initiator)
+channel_incoming (void *cls,
+ struct GNUNET_CADET_Channel *channel,
+ const struct GNUNET_PeerIdentity *initiator)
{
- GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
- "Incoming connection from %s\n",
- GNUNET_i2s_full(initiator));
- GNUNET_assert(NULL == ch);
- GNUNET_assert(NULL != lp);
- GNUNET_CADET_close_port(lp);
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "Incoming connection from %s\n",
+ GNUNET_i2s_full (initiator));
+ GNUNET_assert (NULL == ch);
+ GNUNET_assert (NULL != lp);
+ GNUNET_CADET_close_port (lp);
lp = NULL;
ch = channel;
if (GNUNET_NO == echo)
- listen_stdio();
+ listen_stdio ();
return channel;
}
@@ -403,7 +403,7 @@ channel_incoming(void *cls,
* @param cls Closure (NULL).
*/
static void
-send_echo(void *cls)
+send_echo (void *cls)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
@@ -411,8 +411,8 @@ send_echo(void *cls)
echo_task = NULL;
if (NULL == ch)
return;
- env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
}
@@ -425,7 +425,7 @@ send_echo(void *cls)
* #GNUNET_SYSERR to close it (signal serious error).
*/
static int
-check_data(void *cls, const struct GNUNET_MessageHeader *message)
+check_data (void *cls, const struct GNUNET_MessageHeader *message)
{
return GNUNET_OK; /* all is well-formed */
}
@@ -442,59 +442,59 @@ check_data(void *cls, const struct GNUNET_MessageHeader *message)
* @param message The actual message.
*/
static void
-handle_data(void *cls, const struct GNUNET_MessageHeader *message)
+handle_data (void *cls, const struct GNUNET_MessageHeader *message)
{
- size_t payload_size = ntohs(message->size) - sizeof(*message);
+ size_t payload_size = ntohs (message->size) - sizeof(*message);
uint16_t len;
ssize_t done;
uint16_t off;
const char *buf;
- GNUNET_CADET_receive_done(ch);
+ GNUNET_CADET_receive_done (ch);
if (GNUNET_YES == echo)
+ {
+ if (NULL != listen_port)
{
- if (NULL != listen_port)
- {
- struct GNUNET_MQ_Envelope *env;
- struct GNUNET_MessageHeader *msg;
-
- env =
- GNUNET_MQ_msg_extra(msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
- GNUNET_memcpy(&msg[1], &message[1], payload_size);
- GNUNET_MQ_send(GNUNET_CADET_get_mq(ch), env);
- return;
- }
- else
- {
- struct GNUNET_TIME_Relative latency;
-
- latency = GNUNET_TIME_absolute_get_duration(echo_time);
- echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
- GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
- "time: %s\n",
- GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_NO));
- echo_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
- &send_echo,
- NULL);
- }
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_MessageHeader *msg;
+
+ env =
+ GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MESSAGE_TYPE_CADET_CLI);
+ GNUNET_memcpy (&msg[1], &message[1], payload_size);
+ GNUNET_MQ_send (GNUNET_CADET_get_mq (ch), env);
+ return;
}
+ else
+ {
+ struct GNUNET_TIME_Relative latency;
+
+ latency = GNUNET_TIME_absolute_get_duration (echo_time);
+ echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "time: %s\n",
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
+ echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &send_echo,
+ NULL);
+ }
+ }
- len = ntohs(message->size) - sizeof(*message);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
- buf = (const char *)&message[1];
+ len = ntohs (message->size) - sizeof(*message);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
+ buf = (const char *) &message[1];
off = 0;
while (off < len)
+ {
+ done = write (1, &buf[off], len - off);
+ if (done <= 0)
{
- done = write(1, &buf[off], len - off);
- if (done <= 0)
- {
- if (-1 == done)
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "write");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- off += done;
+ if (-1 == done)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
+ off += done;
+ }
}
@@ -508,19 +508,19 @@ handle_data(void *cls, const struct GNUNET_MessageHeader *message)
* @param ple information about peer, or NULL on "EOF".
*/
static void
-peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
+peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
{
if (NULL == ple)
- {
- plo = NULL;
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- fprintf(stdout,
- "%s tunnel: %c, paths: %u\n",
- GNUNET_i2s_full(&ple->peer),
- ple->have_tunnel ? 'Y' : 'N',
- ple->n_paths);
+ {
+ plo = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ fprintf (stdout,
+ "%s tunnel: %c, paths: %u\n",
+ GNUNET_i2s_full (&ple->peer),
+ ple->have_tunnel ? 'Y' : 'N',
+ ple->n_paths);
}
@@ -532,20 +532,20 @@ peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
* @param ppd path detail
*/
static void
-path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
+path_callback (void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
{
if (NULL == ppd)
- {
- gpo = NULL;
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- fprintf(stdout, "Path of length %u: ", ppd->path_length);
+ {
+ gpo = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ fprintf (stdout, "Path of length %u: ", ppd->path_length);
for (unsigned int i = 0; i < ppd->path_length; i++)
- fprintf(stdout,
- (i == ppd->target_offset) ? "*%s* " : "%s ",
- GNUNET_i2s(&ppd->path[i]));
- fprintf(stdout, "\n");
+ fprintf (stdout,
+ (i == ppd->target_offset) ? "*%s* " : "%s ",
+ GNUNET_i2s (&ppd->path[i]));
+ fprintf (stdout, "\n");
}
@@ -556,21 +556,21 @@ path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
* @param td tunnel details
*/
static void
-tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
+tunnels_callback (void *cls, const struct GNUNET_CADET_TunnelDetails *td)
{
if (NULL == td)
- {
- tio = NULL;
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- fprintf(stdout,
- "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
- GNUNET_i2s_full(&td->peer),
- enc_2s(td->estate),
- conn_2s(td->cstate),
- td->channels,
- td->connections);
+ {
+ tio = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ fprintf (stdout,
+ "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
+ GNUNET_i2s_full (&td->peer),
+ enc_2s (td->estate),
+ conn_2s (td->cstate),
+ td->channels,
+ td->connections);
}
@@ -580,10 +580,10 @@ tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
* @param cls Closure (unused).
*/
static void
-get_peers(void *cls)
+get_peers (void *cls)
{
job = NULL;
- plo = GNUNET_CADET_list_peers(my_cfg, &peers_callback, NULL);
+ plo = GNUNET_CADET_list_peers (my_cfg, &peers_callback, NULL);
}
@@ -593,20 +593,20 @@ get_peers(void *cls)
* @param cls Closure (unused).
*/
static void
-show_peer(void *cls)
+show_peer (void *cls)
{
struct GNUNET_PeerIdentity pid;
job = NULL;
- if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(peer_id,
- strlen(peer_id),
- &pid.public_key))
- {
- fprintf(stderr, _("Invalid peer ID `%s'\n"), peer_id);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- gpo = GNUNET_CADET_get_path(my_cfg, &pid, &path_callback, NULL);
+ if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+ strlen (peer_id),
+ &pid.public_key))
+ {
+ fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ gpo = GNUNET_CADET_get_path (my_cfg, &pid, &path_callback, NULL);
}
@@ -616,10 +616,10 @@ show_peer(void *cls)
* @param cls Closure (unused).
*/
static void
-get_tunnels(void *cls)
+get_tunnels (void *cls)
{
job = NULL;
- tio = GNUNET_CADET_list_tunnels(my_cfg, &tunnels_callback, NULL);
+ tio = GNUNET_CADET_list_tunnels (my_cfg, &tunnels_callback, NULL);
}
@@ -629,10 +629,10 @@ get_tunnels(void *cls)
* @param cls Closure (unused).
*/
static void
-show_channel(void *cls)
+show_channel (void *cls)
{
job = NULL;
- GNUNET_break(0);
+ GNUNET_break (0);
}
@@ -642,10 +642,10 @@ show_channel(void *cls)
* @param cls Closure (unused).
*/
static void
-show_connection(void *cls)
+show_connection (void *cls)
{
job = NULL;
- GNUNET_break(0);
+ GNUNET_break (0);
}
@@ -658,17 +658,17 @@ show_connection(void *cls)
* @param cfg configuration
*/
static void
-run(void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct GNUNET_MQ_MessageHandler handlers[] =
- { GNUNET_MQ_hd_var_size(data,
- GNUNET_MESSAGE_TYPE_CADET_CLI,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end() };
+ { GNUNET_MQ_hd_var_size (data,
+ GNUNET_MESSAGE_TYPE_CADET_CLI,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end () };
/* FIXME add option to monitor apps */
my_cfg = cfg;
@@ -676,105 +676,105 @@ run(void *cls,
if (target_id && args[1])
target_port = args[1];
- if ((0 != (request_peers | request_tunnels) || NULL != conn_id ||
- NULL != channel_id) &&
- target_id != NULL)
- {
- fprintf(stderr,
- _("Extra arguments are not applicable "
+ if (((0 != (request_peers | request_tunnels))||(NULL != conn_id)||
+ (NULL != channel_id) ) &&
+ (target_id != NULL) )
+ {
+ fprintf (stderr,
+ _ ("Extra arguments are not applicable "
"in combination with this option.\n"));
- return;
- }
+ return;
+ }
if (NULL != peer_id)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
- job = GNUNET_SCHEDULER_add_now(&show_peer, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
+ job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+ }
else if (NULL != channel_id)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
- job = GNUNET_SCHEDULER_add_now(&show_channel, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
+ job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+ }
else if (NULL != conn_id)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
- job = GNUNET_SCHEDULER_add_now(&show_connection, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
+ job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+ }
else if (GNUNET_YES == request_peers)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
- job = GNUNET_SCHEDULER_add_now(&get_peers, NULL);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
+ job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+ }
else if (GNUNET_YES == request_tunnels)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
- job = GNUNET_SCHEDULER_add_now(&get_tunnels, NULL);
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
- mh = GNUNET_CADET_connect(cfg);
- GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
+ job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CADET service\n");
+ mh = GNUNET_CADET_connect (cfg);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
if (NULL == mh)
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (NULL != listen_port)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
+ GNUNET_CRYPTO_hash (listen_port, strlen (listen_port), &porthash);
+ lp = GNUNET_CADET_open_port (mh,
+ &porthash,
+ &channel_incoming,
+ NULL,
+ NULL /* window changes */,
+ &channel_ended,
+ handlers);
+ }
+ if (NULL != target_id)
+ {
+ struct GNUNET_PeerIdentity pid;
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (target_id,
+ strlen (target_id),
+ &pid.public_key))
{
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ _ ("Invalid target `%s'\n"),
+ target_id);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- if (NULL != listen_port)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to `%s:%s'\n",
+ target_id,
+ target_port);
+ GNUNET_CRYPTO_hash (target_port, strlen (target_port), &porthash);
+ ch = GNUNET_CADET_channel_create (mh,
+ NULL,
+ &pid,
+ &porthash,
+ NULL /* window changes */,
+ &channel_ended,
+ handlers);
+ if (GNUNET_YES == echo)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening CADET listen port\n");
- GNUNET_CRYPTO_hash(listen_port, strlen(listen_port), &porthash);
- lp = GNUNET_CADET_open_port(mh,
- &porthash,
- &channel_incoming,
- NULL,
- NULL /* window changes */,
- &channel_ended,
- handlers);
+ echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
}
- if (NULL != target_id)
+ else
{
- struct GNUNET_PeerIdentity pid;
-
- if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string(target_id,
- strlen(target_id),
- &pid.public_key))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE,
- _("Invalid target `%s'\n"),
- target_id);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to `%s:%s'\n",
- target_id,
- target_port);
- GNUNET_CRYPTO_hash(target_port, strlen(target_port), &porthash);
- ch = GNUNET_CADET_channel_create(mh,
- NULL,
- &pid,
- &porthash,
- NULL /* window changes */,
- &channel_ended,
- handlers);
- if (GNUNET_YES == echo)
- {
- echo_task = GNUNET_SCHEDULER_add_now(&send_echo, NULL);
- }
- else
- {
- listen_stdio();
- }
+ listen_stdio ();
}
+ }
if ((NULL == lp) && (NULL == job) && (NULL == ch))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_MESSAGE, _("No action requested\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _ ("No action requested\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
}
@@ -786,61 +786,60 @@ run(void *cls,
* @return 0 ok, 1 on error
*/
int
-main(int argc, char *const *argv)
+main (int argc, char *const *argv)
{
int res;
const char helpstr[] =
"Create tunnels and retrieve info about CADET's status.";
- struct GNUNET_GETOPT_CommandLineOption options[] =
- { /* I would use the terminology 'circuit' here... --lynX */
- GNUNET_GETOPT_option_string(
+ struct GNUNET_GETOPT_CommandLineOption options[] = { /* I would use the terminology 'circuit' here... --lynX */
+ GNUNET_GETOPT_option_string (
'C',
"connection",
"CONNECTION_ID",
- gettext_noop("Provide information about a particular connection"),
+ gettext_noop ("Provide information about a particular connection"),
&conn_id),
- GNUNET_GETOPT_option_flag('e',
- "echo",
- gettext_noop("Activate echo mode"),
- &echo),
- GNUNET_GETOPT_option_string(
+ GNUNET_GETOPT_option_flag ('e',
+ "echo",
+ gettext_noop ("Activate echo mode"),
+ &echo),
+ GNUNET_GETOPT_option_string (
'o',
"open-port",
"SHARED_SECRET",
- gettext_noop(
+ gettext_noop (
"Listen for connections using a shared secret among sender and recipient"),
&listen_port),
- GNUNET_GETOPT_option_string('p',
- "peer",
- "PEER_ID",
- gettext_noop(
- "Provide information about a patricular peer"),
- &peer_id),
- GNUNET_GETOPT_option_flag('P',
- "peers",
- gettext_noop(
- "Provide information about all peers"),
- &request_peers),
- GNUNET_GETOPT_option_flag('T',
- "tunnels",
- gettext_noop(
- "Provide information about all tunnels"),
- &request_tunnels),
+ GNUNET_GETOPT_option_string ('p',
+ "peer",
+ "PEER_ID",
+ gettext_noop (
+ "Provide information about a patricular peer"),
+ &peer_id),
+ GNUNET_GETOPT_option_flag ('P',
+ "peers",
+ gettext_noop (
+ "Provide information about all peers"),
+ &request_peers),
+ GNUNET_GETOPT_option_flag ('T',
+ "tunnels",
+ gettext_noop (
+ "Provide information about all tunnels"),
+ &request_tunnels),
GNUNET_GETOPT_OPTION_END
};
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- res = GNUNET_PROGRAM_run(argc,
- argv,
- "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
- gettext_noop(helpstr),
- options,
- &run,
- NULL);
+ res = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
+ gettext_noop (helpstr),
+ options,
+ &run,
+ NULL);
- GNUNET_free((void *)argv);
+ GNUNET_free ((void *) argv);
if (GNUNET_OK == res)
return 0;
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c
index a06cd184f..c64da33e2 100644
--- a/src/cadet/gnunet-service-cadet.c
+++ b/src/cadet/gnunet-service-cadet.c
@@ -46,13 +46,14 @@
#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
*/
@@ -201,11 +202,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);
}
@@ -216,14 +217,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;
}
@@ -236,11 +237,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));
}
@@ -251,23 +252,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;
}
@@ -285,38 +286,39 @@ 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;
}
@@ -331,16 +333,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;
}
@@ -355,13 +357,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;
}
@@ -370,50 +372,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;
}
@@ -424,14 +426,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 ();
}
@@ -445,20 +447,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;
}
@@ -473,44 +475,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);
}
@@ -524,41 +526,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);
}
@@ -569,54 +571,56 @@ 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);
}
@@ -627,37 +631,40 @@ 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);
}
@@ -669,8 +676,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;
@@ -683,36 +690,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];
+ 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))
{
- /* 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;
- }
- if (0 != payload_size)
- {
- GNUNET_break_op(0);
+ 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;
+ }
+ if (0 != payload_size)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -725,47 +732,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);
}
@@ -776,30 +783,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);
}
@@ -812,24 +819,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;
}
@@ -841,20 +848,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);
}
@@ -869,9 +876,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;
@@ -880,36 +887,37 @@ path_info_iterator(void *cls,
size_t path_size;
unsigned int path_length;
- path_length = GCPP_get_length(path);
+ 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;
- }
+ {
+ /* 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];
+ {
+ 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;
}
@@ -921,25 +929,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);
}
@@ -952,9 +960,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;
@@ -962,19 +970,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;
}
@@ -986,20 +994,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);
}
@@ -1012,28 +1020,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;
}
@@ -1046,22 +1054,23 @@ 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));
}
@@ -1073,13 +1082,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));
}
@@ -1092,26 +1101,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;
}
@@ -1125,27 +1134,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;
}
@@ -1158,42 +1167,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);
+ {
+ 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();
+ shutdown_rest ();
}
@@ -1205,92 +1214,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));
}
@@ -1304,42 +1313,42 @@ GNUNET_SERVICE_MAIN
&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_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
- struct GNUNET_CADET_PortMessage,
- NULL),
- 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_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
- struct GNUNET_CADET_LocalChannelDestroyMessage,
- NULL),
- 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_MESSAGE_TYPE_CADET_LOCAL_ACK,
- struct GNUNET_CADET_LocalAck,
- NULL),
- 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_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
- struct GNUNET_CADET_RequestPathInfoMessage,
- NULL),
- 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_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_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
+ struct GNUNET_CADET_PortMessage,
+ NULL),
+ 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_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
+ struct GNUNET_CADET_LocalChannelDestroyMessage,
+ NULL),
+ 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_MESSAGE_TYPE_CADET_LOCAL_ACK,
+ struct GNUNET_CADET_LocalAck,
+ NULL),
+ 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_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH,
+ struct GNUNET_CADET_RequestPathInfoMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (info_tunnels,
+ GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-cadet-new.c */
diff --git a/src/cadet/gnunet-service-cadet.h b/src/cadet/gnunet-service-cadet.h
index 8decdba0d..6da0950f1 100644
--- a/src/cadet/gnunet-service-cadet.h
+++ b/src/cadet/gnunet-service-cadet.h
@@ -1,4 +1,3 @@
-
/*
This file is part of GNUnet.
Copyright (C) 2001-2017 GNUnet e.V.
@@ -64,7 +63,8 @@ struct CadetPeerPath;
/**
* Entry in a peer path.
*/
-struct CadetPeerPathEntry {
+struct CadetPeerPathEntry
+{
/**
* DLL of paths where the same @e peer is at the same offset.
*/
@@ -103,7 +103,8 @@ struct CadetPeerPathEntry {
/**
* Entry in list of connections used by tunnel, with metadata.
*/
-struct CadetTConnection {
+struct CadetTConnection
+{
/**
* Next in DLL.
*/
@@ -144,7 +145,8 @@ struct CadetTConnection {
/**
* Port opened by a client.
*/
-struct OpenPort {
+struct OpenPort
+{
/**
* Client that opened the port.
*/
@@ -266,8 +268,8 @@ extern 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);
/**
@@ -278,9 +280,9 @@ GSC_send_to_client(struct CadetClient *c,
* @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);
/**
* A client that created a loose channel that was not bound to a port
@@ -290,8 +292,8 @@ 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);
/**
@@ -306,11 +308,11 @@ GSC_drop_loose_channel(const struct GNUNET_HashCode *h_port,
* @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);
/**
@@ -320,7 +322,7 @@ GSC_bind(struct CadetClient *c,
* @return string for debugging
*/
const char *
-GSC_2s(struct CadetClient *c);
+GSC_2s (struct CadetClient *c);
#endif
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index dad5325fc..0a261039c 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -41,26 +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)
+ 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)
+ 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)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75)
/**
* Maximum message ID into the future we accept for out-of-order messages.
@@ -78,7 +78,8 @@
/**
* All the states a channel can be in.
*/
-enum CadetChannelState {
+enum CadetChannelState
+{
/**
* Uninitialized status, should never appear in operation.
*/
@@ -107,7 +108,8 @@ enum CadetChannelState {
* Note that we DO use this structure also for unreliable
* messages.
*/
-struct CadetReliableMessage {
+struct CadetReliableMessage
+{
/**
* Double linked list, FIFO style
*/
@@ -171,7 +173,8 @@ struct CadetReliableMessage {
/**
* List of received out-of-order data messages.
*/
-struct CadetOutOfOrderMessage {
+struct CadetOutOfOrderMessage
+{
/**
* Double linked list, FIFO style
*/
@@ -200,7 +203,8 @@ struct CadetOutOfOrderMessage {
* loopback channel, in which case it has two of these endpoints.
* Note that flow control also is required in both directions.
*/
-struct CadetChannelClient {
+struct CadetChannelClient
+{
/**
* Client handle. Not by itself sufficient to designate
* the client endpoint, as the same client handle may
@@ -241,7 +245,8 @@ struct CadetChannelClient {
/**
* Struct containing all information regarding a channel to a remote client.
*/
-struct CadetChannel {
+struct CadetChannel
+{
/**
* Tunnel this channel is in.
*/
@@ -386,24 +391,24 @@ struct CadetChannel {
* @return Static string with the channel IDs.
*/
const char *
-GCCH_2s(const struct CadetChannel *ch)
+GCCH_2s (const struct CadetChannel *ch)
{
static char buf[128];
- GNUNET_snprintf(buf,
- 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))),
- 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));
+ GNUNET_snprintf (buf,
+ 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))),
+ 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));
return buf;
}
@@ -418,19 +423,19 @@ GCCH_2s(const struct CadetChannel *ch)
* @param listener peer that is listining on @a port
*/
void
-GCCH_hash_port(struct GNUNET_HashCode *h_port,
- const struct GNUNET_HashCode *port,
- const struct GNUNET_PeerIdentity *listener)
+GCCH_hash_port (struct GNUNET_HashCode *h_port,
+ 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);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Calculated port hash %s\n",
- GNUNET_h2s(h_port));
+ 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);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Calculated port hash %s\n",
+ GNUNET_h2s (h_port));
}
@@ -442,7 +447,7 @@ GCCH_hash_port(struct GNUNET_HashCode *h_port,
* @return ID used to identify the channel with the remote peer.
*/
struct GNUNET_CADET_ChannelTunnelNumber
-GCCH_get_id(const struct CadetChannel *ch)
+GCCH_get_id (const struct CadetChannel *ch)
{
return ch->ctn;
}
@@ -454,18 +459,18 @@ GCCH_get_id(const struct CadetChannel *ch)
* @param ccc data structure to clean up
*/
static void
-free_channel_client(struct CadetChannelClient *ccc)
+free_channel_client (struct CadetChannelClient *ccc)
{
struct CadetOutOfOrderMessage *com;
while (NULL != (com = ccc->head_recv))
- {
- GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com);
- ccc->num_recv--;
- GNUNET_MQ_discard(com->env);
- GNUNET_free(com);
- }
- GNUNET_free(ccc);
+ {
+ GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
+ ccc->num_recv--;
+ GNUNET_MQ_discard (com->env);
+ GNUNET_free (com);
+ }
+ GNUNET_free (ccc);
}
@@ -475,57 +480,57 @@ free_channel_client(struct CadetChannelClient *ccc)
* @param ch channel to destroy
*/
static void
-channel_destroy(struct CadetChannel *ch)
+channel_destroy (struct CadetChannel *ch)
{
struct CadetReliableMessage *crm;
while (NULL != (crm = ch->head_sent))
+ {
+ GNUNET_assert (ch == crm->ch);
+ if (NULL != crm->qe)
{
- GNUNET_assert(ch == crm->ch);
- if (NULL != crm->qe)
- {
- GCT_send_cancel(crm->qe);
- crm->qe = NULL;
- }
- GNUNET_CONTAINER_DLL_remove(ch->head_sent, ch->tail_sent, crm);
- GNUNET_free(crm->data_message);
- GNUNET_free(crm);
+ GCT_send_cancel (crm->qe);
+ crm->qe = NULL;
}
+ 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)
- {
- free_channel_client(ch->owner);
- ch->owner = NULL;
- }
+ {
+ free_channel_client (ch->owner);
+ ch->owner = NULL;
+ }
if (NULL != ch->dest)
- {
- free_channel_client(ch->dest);
- ch->dest = NULL;
- }
+ {
+ free_channel_client (ch->dest);
+ ch->dest = NULL;
+ }
if (NULL != ch->last_control_qe)
- {
- GCT_send_cancel(ch->last_control_qe);
- ch->last_control_qe = NULL;
- }
+ {
+ GCT_send_cancel (ch->last_control_qe);
+ ch->last_control_qe = NULL;
+ }
if (NULL != ch->retry_data_task)
- {
- GNUNET_SCHEDULER_cancel(ch->retry_data_task);
- ch->retry_data_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ch->retry_data_task);
+ ch->retry_data_task = NULL;
+ }
if (NULL != ch->retry_control_task)
- {
- GNUNET_SCHEDULER_cancel(ch->retry_control_task);
- ch->retry_control_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (ch->retry_control_task);
+ ch->retry_control_task = NULL;
+ }
if (GNUNET_NO == ch->is_loopback)
- {
- GCT_remove_channel(ch->t, ch, ch->ctn);
- ch->t = NULL;
- }
- GNUNET_free(ch);
+ {
+ GCT_remove_channel (ch->t, ch, ch->ctn);
+ ch->t = NULL;
+ }
+ GNUNET_free (ch);
}
@@ -535,7 +540,7 @@ channel_destroy(struct CadetChannel *ch)
* @param cls Channel for which to send.
*/
static void
-send_channel_open(void *cls);
+send_channel_open (void *cls);
/**
@@ -547,20 +552,20 @@ send_channel_open(void *cls);
* if transmission failed
*/
static void
-channel_open_sent_cb(void *cls,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+channel_open_sent_cb (void *cls,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
struct CadetChannel *ch = cls;
- GNUNET_assert(NULL != ch->last_control_qe);
+ GNUNET_assert (NULL != ch->last_control_qe);
ch->last_control_qe = NULL;
- ch->retry_time = GNUNET_TIME_STD_BACKOFF(ch->retry_time);
- 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_time = GNUNET_TIME_STD_BACKOFF (ch->retry_time);
+ 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_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch);
}
@@ -570,27 +575,27 @@ channel_open_sent_cb(void *cls,
* @param cls Channel for which to send.
*/
static void
-send_channel_open(void *cls)
+send_channel_open (void *cls)
{
struct CadetChannel *ch = cls;
struct GNUNET_CADET_ChannelOpenMessage msgcc;
ch->retry_control_task = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending CHANNEL_OPEN message for %s\n",
- 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 set the deprecated "reliable" bit here that was removed.
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending CHANNEL_OPEN message for %s\n",
+ 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 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);
+ GCT_send_cancel (ch->last_control_qe);
ch->last_control_qe =
- GCT_send(ch->t, &msgcc.header, &channel_open_sent_cb, ch);
- GNUNET_assert(NULL == ch->retry_control_task);
+ GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch);
+ GNUNET_assert (NULL == ch->retry_control_task);
}
@@ -605,13 +610,13 @@ send_channel_open(void *cls)
* @param ch the channel for which the tunnel is now ready
*/
void
-GCCH_tunnel_up(struct CadetChannel *ch)
+GCCH_tunnel_up (struct CadetChannel *ch)
{
- GNUNET_assert(NULL == ch->retry_control_task);
- 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);
+ GNUNET_assert (NULL == ch->retry_control_task);
+ 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);
}
@@ -626,22 +631,22 @@ GCCH_tunnel_up(struct CadetChannel *ch)
* @return handle to the new channel
*/
struct CadetChannel *
-GCCH_channel_local_new(struct CadetClient *owner,
- struct GNUNET_CADET_ClientChannelNumber ccn,
- struct CadetPeer *destination,
- const struct GNUNET_HashCode *port,
- uint32_t options)
+GCCH_channel_local_new (struct CadetClient *owner,
+ struct GNUNET_CADET_ClientChannelNumber ccn,
+ struct CadetPeer *destination,
+ const struct GNUNET_HashCode *port,
+ uint32_t options)
{
struct CadetChannel *ch;
struct CadetChannelClient *ccco;
- ccco = GNUNET_new(struct CadetChannelClient);
+ ccco = GNUNET_new (struct CadetChannelClient);
ccco->c = owner;
ccco->ccn = ccn;
ccco->client_ready = GNUNET_YES;
- ch = GNUNET_new(struct CadetChannel);
- ch->mid_recv.mid = htonl(1); /* The OPEN_ACK counts as message 0! */
+ ch = GNUNET_new (struct CadetChannel);
+ ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */
ch->nobuffer = GNUNET_NO;
ch->reliable = GNUNET_YES;
ch->out_of_order = GNUNET_NO;
@@ -649,44 +654,44 @@ GCCH_channel_local_new(struct CadetClient *owner,
(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);
+ if (NULL == op)
{
- struct OpenPort *op;
-
- ch->is_loopback = GNUNET_YES;
- 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);
- 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);
- }
+ /* 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);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Created loose incoming loopback channel to port %s\n",
+ GNUNET_h2s (&ch->port));
}
- else
+ else
{
- ch->t = GCP_get_tunnel(destination, GNUNET_YES);
- ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
- ch->ctn = GCT_add_channel(ch->t, ch);
+ GCCH_bind (ch, op->c, &op->port);
}
- 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),
- GCP_2s(destination),
- GSC_2s(owner),
- (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s(ch->t));
+ }
+ else
+ {
+ ch->t = GCP_get_tunnel (destination, GNUNET_YES);
+ ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
+ ch->ctn = GCT_add_channel (ch->t, ch);
+ }
+ 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),
+ GCP_2s (destination),
+ GSC_2s (owner),
+ (GNUNET_YES == ch->is_loopback) ? "loopback" : GCT_2s (ch->t));
return ch;
}
@@ -698,16 +703,16 @@ GCCH_channel_local_new(struct CadetClient *owner,
* @param cls the channel to drop
*/
static void
-timeout_closed_cb(void *cls)
+timeout_closed_cb (void *cls)
{
struct CadetChannel *ch = cls;
ch->retry_control_task = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Closing incoming channel to port %s from peer %s due to timeout\n",
- GNUNET_h2s(&ch->port),
- GCP_2s(GCT_get_destination(ch->t)));
- channel_destroy(ch);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Closing incoming channel to port %s from peer %s due to timeout\n",
+ GNUNET_h2s (&ch->port),
+ GCP_2s (GCT_get_destination (ch->t)));
+ channel_destroy (ch);
}
@@ -721,15 +726,15 @@ timeout_closed_cb(void *cls)
* @return handle to the new channel
*/
struct CadetChannel *
-GCCH_channel_incoming_new(struct CadetTunnel *t,
- struct GNUNET_CADET_ChannelTunnelNumber ctn,
- const struct GNUNET_HashCode *h_port,
- uint32_t options)
+GCCH_channel_incoming_new (struct CadetTunnel *t,
+ struct GNUNET_CADET_ChannelTunnelNumber ctn,
+ const struct GNUNET_HashCode *h_port,
+ uint32_t options)
{
struct CadetChannel *ch;
struct OpenPort *op;
- ch = GNUNET_new(struct CadetChannel);
+ ch = GNUNET_new (struct CadetChannel);
ch->h_port = *h_port;
ch->t = t;
ch->ctn = ctn;
@@ -739,32 +744,32 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
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);
+ GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
- op = GNUNET_CONTAINER_multihashmap_get(open_ports, h_port);
+ 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);
- GNUNET_assert(NULL == ch->retry_control_task);
- 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),
- GCP_2s(GCT_get_destination(ch->t)));
- }
+ {
+ /* 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);
+ GNUNET_assert (NULL == ch->retry_control_task);
+ 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),
+ GCP_2s (GCT_get_destination (ch->t)));
+ }
else
- {
- GCCH_bind(ch, op->c, &op->port);
- }
- GNUNET_STATISTICS_update(stats, "# channels", 1, GNUNET_NO);
+ {
+ GCCH_bind (ch, op->c, &op->port);
+ }
+ GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
return ch;
}
@@ -779,12 +784,12 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
* if transmission failed
*/
static void
-send_ack_cb(void *cls,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+send_ack_cb (void *cls,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
struct CadetChannel *ch = cls;
- GNUNET_assert(NULL != ch->last_control_qe);
+ GNUNET_assert (NULL != ch->last_control_qe);
ch->last_control_qe = NULL;
}
@@ -795,25 +800,25 @@ send_ack_cb(void *cls,
* @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for
*/
static void
-send_channel_data_ack(struct CadetChannel *ch)
+send_channel_data_ack (struct CadetChannel *ch)
{
struct GNUNET_CADET_ChannelDataAckMessage msg;
if (GNUNET_NO == ch->reliable)
return; /* no ACKs */
- msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
- msg.header.size = htons(sizeof(msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
+ msg.header.size = htons (sizeof(msg));
msg.ctn = ch->ctn;
- msg.mid.mid = htonl(ntohl(ch->mid_recv.mid));
- msg.futures = GNUNET_htonll(ch->mid_futures);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending DATA_ACK %u:%llX via %s\n",
- (unsigned int)ntohl(msg.mid.mid),
- (unsigned long long)ch->mid_futures,
- GCCH_2s(ch));
+ msg.mid.mid = htonl (ntohl (ch->mid_recv.mid));
+ msg.futures = GNUNET_htonll (ch->mid_futures);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending DATA_ACK %u:%llX via %s\n",
+ (unsigned int) ntohl (msg.mid.mid),
+ (unsigned long long) ch->mid_futures,
+ 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);
+ GCT_send_cancel (ch->last_control_qe);
+ ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
}
@@ -824,23 +829,23 @@ send_channel_data_ack(struct CadetChannel *ch)
* @param cls the `struct CadetChannel`
*/
static void
-send_open_ack(void *cls)
+send_open_ack (void *cls)
{
struct CadetChannel *ch = cls;
struct GNUNET_CADET_ChannelOpenAckMessage msg;
ch->retry_control_task = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending CHANNEL_OPEN_ACK on %s\n",
- GCCH_2s(ch));
- msg.header.type = htons(GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK);
- msg.header.size = htons(sizeof(msg));
- msg.reserved = htonl(0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending CHANNEL_OPEN_ACK on %s\n",
+ GCCH_2s (ch));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK);
+ msg.header.size = htons (sizeof(msg));
+ msg.reserved = htonl (0);
msg.ctn = ch->ctn;
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);
+ GCT_send_cancel (ch->last_control_qe);
+ ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
}
@@ -853,28 +858,28 @@ send_open_ack(void *cls)
* @param cti identifier of the connection that delivered the message
*/
void
-GCCH_handle_duplicate_open(
+GCCH_handle_duplicate_open (
struct CadetChannel *ch,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
{
if (NULL == ch->dest)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n",
- GCCH_2s(ch));
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring duplicate CHANNEL_OPEN on %s: port is closed\n",
+ GCCH_2s (ch));
+ return;
+ }
if (NULL != ch->retry_control_task)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n",
- GCCH_2s(ch));
- return;
- }
- 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);
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ignoring duplicate CHANNEL_OPEN on %s: control message is pending\n",
+ GCCH_2s (ch));
+ return;
+ }
+ 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);
}
@@ -886,7 +891,7 @@ GCCH_handle_duplicate_open(
* #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;
@@ -894,22 +899,22 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner)
ccc = (GNUNET_YES == to_owner) ? ch->owner : ch->dest;
if (NULL == ccc)
- {
- /* This can happen if we are just getting ACKs after
- our local client already disconnected. */
- GNUNET_assert(GNUNET_YES == ch->destroy);
- return;
- }
- env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
+ {
+ /* This can happen if we are just getting ACKs after
+ our local client already disconnected. */
+ GNUNET_assert (GNUNET_YES == ch->destroy);
+ return;
+ }
+ 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",
- GSC_2s(ccc->c),
- (GNUNET_YES == to_owner) ? "owner" : "dest",
- ntohl(ack->ccn.channel_of_client),
- ch->pending_messages,
- ch->max_pending_messages);
- GSC_send_to_client(ccc->c, env);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n",
+ GSC_2s (ccc->c),
+ (GNUNET_YES == to_owner) ? "owner" : "dest",
+ ntohl (ack->ccn.channel_of_client),
+ ch->pending_messages,
+ ch->max_pending_messages);
+ GSC_send_to_client (ccc->c, env);
}
@@ -923,58 +928,58 @@ send_ack_to_client(struct CadetChannel *ch, int to_owner)
* @param port the port @a is listening on
*/
void
-GCCH_bind(struct CadetChannel *ch,
- struct CadetClient *c,
- const struct GNUNET_HashCode *port)
+GCCH_bind (struct CadetChannel *ch,
+ struct CadetClient *c,
+ const struct GNUNET_HashCode *port)
{
uint32_t options;
struct CadetChannelClient *cccd;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Binding %s from %s to port %s of %s\n",
- GCCH_2s(ch),
- GCT_2s(ch->t),
- GNUNET_h2s(&ch->port),
- GSC_2s(c));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Binding %s from %s to port %s of %s\n",
+ GCCH_2s (ch),
+ GCT_2s (ch->t),
+ GNUNET_h2s (&ch->port),
+ GSC_2s (c));
if (NULL != ch->retry_control_task)
- {
- /* there might be a timeout task here */
- GNUNET_SCHEDULER_cancel(ch->retry_control_task);
- ch->retry_control_task = NULL;
- }
+ {
+ /* there might be a timeout task here */
+ GNUNET_SCHEDULER_cancel (ch->retry_control_task);
+ ch->retry_control_task = NULL;
+ }
options = 0;
- cccd = GNUNET_new(struct CadetChannelClient);
- GNUNET_assert(NULL == ch->dest);
+ cccd = GNUNET_new (struct CadetChannelClient);
+ GNUNET_assert (NULL == ch->dest);
ch->dest = cccd;
ch->port = *port;
cccd->c = c;
cccd->client_ready = GNUNET_YES;
- cccd->ccn = GSC_bind(c,
- ch,
- (GNUNET_YES == ch->is_loopback)
- ? GCP_get(&my_full_id, GNUNET_YES)
- : GCT_get_destination(ch->t),
- port,
- options);
- GNUNET_assert(ntohl(cccd->ccn.channel_of_client) <
- GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
- ch->mid_recv.mid = htonl(1); /* The OPEN counts as message 0! */
+ cccd->ccn = GSC_bind (c,
+ ch,
+ (GNUNET_YES == ch->is_loopback)
+ ? GCP_get (&my_full_id, GNUNET_YES)
+ : GCT_get_destination (ch->t),
+ port,
+ options);
+ GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
+ GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
+ ch->mid_recv.mid = htonl (1); /* The OPEN counts as message 0! */
if (GNUNET_YES == ch->is_loopback)
- {
- ch->state = CADET_CHANNEL_OPEN_SENT;
- GCCH_handle_channel_open_ack(ch, NULL, port);
- }
+ {
+ ch->state = CADET_CHANNEL_OPEN_SENT;
+ 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);
- }
+ {
+ /* 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);
+ }
/* give client it's initial supply of ACKs */
- GNUNET_assert(ntohl(cccd->ccn.channel_of_client) <
- GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
+ GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
+ GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
for (unsigned int i = 0; i < ch->max_pending_messages; i++)
- send_ack_to_client(ch, GNUNET_NO);
+ send_ack_to_client (ch, GNUNET_NO);
}
@@ -986,7 +991,7 @@ GCCH_bind(struct CadetChannel *ch,
* @param cls the `struct CadetChannel` where one of the ends is now dead
*/
static void
-signal_remote_destroy_cb(void *cls)
+signal_remote_destroy_cb (void *cls)
{
struct CadetChannel *ch = cls;
struct CadetChannelClient *ccc;
@@ -994,8 +999,8 @@ 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);
- channel_destroy(ch);
+ GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
+ channel_destroy (ch);
}
@@ -1008,74 +1013,74 @@ signal_remote_destroy_cb(void *cls)
* @param ccn client number of the client @a c
*/
void
-GCCH_channel_local_destroy(struct CadetChannel *ch,
- struct CadetClient *c,
- struct GNUNET_CADET_ClientChannelNumber ccn)
+GCCH_channel_local_destroy (struct CadetChannel *ch,
+ struct CadetClient *c,
+ struct GNUNET_CADET_ClientChannelNumber ccn)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "%s asks for destruction of %s\n",
- GSC_2s(c),
- GCCH_2s(ch));
- GNUNET_assert(NULL != c);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "%s asks for destruction of %s\n",
+ 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))
- {
- free_channel_client(ch->owner);
- ch->owner = NULL;
- }
+ {
+ 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))
- {
- free_channel_client(ch->dest);
- ch->dest = NULL;
- }
+ {
+ free_channel_client (ch->dest);
+ ch->dest = NULL;
+ }
else
- {
- GNUNET_assert(0);
- }
+ {
+ GNUNET_assert (0);
+ }
if (GNUNET_YES == ch->destroy)
- {
- /* other end already destroyed, with the local client gone, no need
- to finish transmissions, just destroy immediately. */
- channel_destroy(ch);
- return;
- }
+ {
+ /* other end already destroyed, with the local client gone, no need
+ to finish transmissions, just destroy immediately. */
+ channel_destroy (ch);
+ return;
+ }
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;
- }
+ {
+ /* 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 (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);
- return;
- }
+ {
+ 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);
+ return;
+ }
if (GNUNET_NO == ch->is_loopback)
+ {
+ /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */
+ switch (ch->state)
{
- /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */
- switch (ch->state)
- {
- case CADET_CHANNEL_NEW:
- /* We gave up on a channel that we created as a client to a remote
- target, but that never went anywhere. Nothing to do here. */
- break;
-
- case CADET_CHANNEL_LOOSE:
- break;
-
- default:
- GCT_send_channel_destroy(ch->t, ch->ctn);
- }
+ case CADET_CHANNEL_NEW:
+ /* We gave up on a channel that we created as a client to a remote
+ target, but that never went anywhere. Nothing to do here. */
+ break;
+
+ case CADET_CHANNEL_LOOSE:
+ break;
+
+ default:
+ GCT_send_channel_destroy (ch->t, ch->ctn);
}
+ }
/* Nothing left to do, just finish destruction */
- channel_destroy(ch);
+ channel_destroy (ch);
}
@@ -1089,60 +1094,60 @@ GCCH_channel_local_destroy(struct CadetChannel *ch,
* @param port port number (needed to verify receiver knows the port)
*/
void
-GCCH_handle_channel_open_ack(
+GCCH_handle_channel_open_ack (
struct CadetChannel *ch,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
const struct GNUNET_HashCode *port)
{
switch (ch->state)
+ {
+ case CADET_CHANNEL_NEW:
+ /* this should be impossible */
+ GNUNET_break (0);
+ break;
+
+ case CADET_CHANNEL_LOOSE:
+ /* This makes no sense. */
+ GNUNET_break_op (0);
+ break;
+
+ case CADET_CHANNEL_OPEN_SENT:
+ if (NULL == ch->owner)
{
- case CADET_CHANNEL_NEW:
- /* this should be impossible */
- GNUNET_break(0);
- break;
-
- case CADET_CHANNEL_LOOSE:
- /* This makes no sense. */
- GNUNET_break_op(0);
- break;
-
- case CADET_CHANNEL_OPEN_SENT:
- if (NULL == ch->owner)
- {
- /* We're not the owner, wrong direction! */
- GNUNET_break_op(0);
- return;
- }
- if (0 != GNUNET_memcmp(&ch->port, port))
- {
- /* Other peer failed to provide the right port,
- refuse connection. */
- GNUNET_break_op(0);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n",
- GCCH_2s(ch));
- if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */
- {
- GNUNET_SCHEDULER_cancel(ch->retry_control_task);
- ch->retry_control_task = NULL;
- }
- 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; 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);
- break;
+ /* We're not the owner, wrong direction! */
+ GNUNET_break_op (0);
+ return;
+ }
+ if (0 != GNUNET_memcmp (&ch->port, port))
+ {
+ /* Other peer failed to provide the right port,
+ refuse connection. */
+ GNUNET_break_op (0);
+ return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CHANNEL_OPEN_ACK for waiting %s, entering READY state\n",
+ GCCH_2s (ch));
+ if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */
+ {
+ GNUNET_SCHEDULER_cancel (ch->retry_control_task);
+ ch->retry_control_task = NULL;
+ }
+ 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; 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);
+ break;
+ }
}
@@ -1155,28 +1160,28 @@ GCCH_handle_channel_open_ack(
* @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO
*/
static int
-is_before(void *cls,
- struct CadetOutOfOrderMessage *m1,
- struct CadetOutOfOrderMessage *m2)
+is_before (void *cls,
+ struct CadetOutOfOrderMessage *m1,
+ struct CadetOutOfOrderMessage *m2)
{
int *duplicate = cls;
- uint32_t v1 = ntohl(m1->mid.mid);
- uint32_t v2 = ntohl(m2->mid.mid);
+ uint32_t v1 = ntohl (m1->mid.mid);
+ uint32_t v2 = ntohl (m2->mid.mid);
uint32_t delta;
delta = v2 - v1;
if (0 == delta)
*duplicate = GNUNET_YES;
- if (delta > (uint32_t)INT_MAX)
- {
- /* in overflow range, we can safely assume we wrapped around */
- return GNUNET_NO;
- }
+ if (delta > (uint32_t) INT_MAX)
+ {
+ /* in overflow range, we can safely assume we wrapped around */
+ return GNUNET_NO;
+ }
else
- {
- /* result is small, thus v2 > v1, thus m1 < m2 */
- return GNUNET_YES;
- }
+ {
+ /* result is small, thus v2 > v1, thus m1 < m2 */
+ return GNUNET_YES;
+ }
}
@@ -1189,7 +1194,7 @@ is_before(void *cls,
* @param msg message that was received
*/
void
-GCCH_handle_channel_plaintext_data(
+GCCH_handle_channel_plaintext_data (
struct CadetChannel *ch,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
const struct GNUNET_CADET_ChannelAppDataMessage *msg)
@@ -1205,239 +1210,239 @@ GCCH_handle_channel_plaintext_data(
uint32_t mid_msg;
uint32_t delta;
- GNUNET_assert(GNUNET_NO == ch->is_loopback);
+ GNUNET_assert (GNUNET_NO == ch->is_loopback);
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,
- we cannot pass messages to our client anymore. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping incoming payload on %s as this end is already closed\n",
- GCCH_2s(ch));
- /* send back DESTROY notification to stop further retransmissions! */
- if (GNUNET_YES == ch->destroy)
- GCT_send_channel_destroy(ch->t, ch->ctn);
- return;
- }
- payload_size = ntohs(msg->header.size) - sizeof(*msg);
- env = GNUNET_MQ_msg_extra(ld,
- payload_size,
- GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
+ {
+ /* 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,
+ we cannot pass messages to our client anymore. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping incoming payload on %s as this end is already closed\n",
+ GCCH_2s (ch));
+ /* send back DESTROY notification to stop further retransmissions! */
+ if (GNUNET_YES == ch->destroy)
+ GCT_send_channel_destroy (ch->t, ch->ctn);
+ return;
+ }
+ payload_size = ntohs (msg->header.size) - sizeof(*msg);
+ env = GNUNET_MQ_msg_extra (ld,
+ 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)
+ {
+ /*
+ * We ad-hoc send the message if
+ * - The channel is out-of-order
+ * - 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)))))
{
- /*
- * We ad-hoc send the message if
- * - The channel is out-of-order
- * - 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)))))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Giving %u bytes of payload with MID %u from %s to client %s\n",
- (unsigned int)payload_size,
- ntohl(msg->mid.mid),
- GCCH_2s(ch),
- GSC_2s(ccc->c));
- ccc->client_ready = GNUNET_NO;
- 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))
- {
- /* 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;
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Giving %u bytes of payload with MID %u from %s to client %s\n",
+ (unsigned int) payload_size,
+ ntohl (msg->mid.mid),
+ GCCH_2s (ch),
+ GSC_2s (ccc->c));
+ ccc->client_ready = GNUNET_NO;
+ 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))
+ {
+ /* 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;
}
+ }
if (GNUNET_YES == ch->reliable)
+ {
+ /* check if message ought to be dropped because it is ancient/too distant/duplicate */
+ 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))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "%s at %u drops ancient or far-future message %u\n",
+ GCCH_2s (ch),
+ (unsigned int) mid_min,
+ ntohl (msg->mid.mid));
+
+ GNUNET_STATISTICS_update (stats,
+ "# duplicate DATA (ancient or future)",
+ 1,
+ GNUNET_NO);
+ GNUNET_MQ_discard (env);
+ send_channel_data_ack (ch);
+ return;
+ }
+ /* mark bit for future ACKs */
+ delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */
+ if (delta < 64)
{
- /* check if message ought to be dropped because it is ancient/too distant/duplicate */
- 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))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "%s at %u drops ancient or far-future message %u\n",
- GCCH_2s(ch),
- (unsigned int)mid_min,
- ntohl(msg->mid.mid));
-
- GNUNET_STATISTICS_update(stats,
- "# duplicate DATA (ancient or future)",
- 1,
- GNUNET_NO);
- GNUNET_MQ_discard(env);
- send_channel_data_ack(ch);
- return;
- }
- /* mark bit for future ACKs */
- delta = mid_msg - mid_min - 1; /* overflow/underflow are OK here */
- if (delta < 64)
- {
- if (0 != (ch->mid_futures & (1LLU << delta)))
- {
- /* Duplicate within the queue, drop also */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
- (unsigned int)payload_size,
- GCCH_2s(ch),
- ntohl(msg->mid.mid));
- GNUNET_STATISTICS_update(stats, "# duplicate DATA", 1, GNUNET_NO);
- GNUNET_MQ_discard(env);
- send_channel_data_ack(ch);
- return;
- }
- ch->mid_futures |= (1LLU << delta);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Marked bit %llX for mid %u (base: %u); now: %llX\n",
- (1LLU << delta),
- mid_msg,
- mid_min,
- ch->mid_futures);
- }
+ if (0 != (ch->mid_futures & (1LLU << delta)))
+ {
+ /* Duplicate within the queue, drop also */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
+ (unsigned int) payload_size,
+ GCCH_2s (ch),
+ ntohl (msg->mid.mid));
+ GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
+ GNUNET_MQ_discard (env);
+ send_channel_data_ack (ch);
+ return;
+ }
+ ch->mid_futures |= (1LLU << delta);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Marked bit %llX for mid %u (base: %u); now: %llX\n",
+ (1LLU << delta),
+ mid_msg,
+ mid_min,
+ ch->mid_futures);
}
+ }
else /* ! ch->reliable */
+ {
+ struct CadetOutOfOrderMessage *next_msg;
+
+ /**
+ * 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))
+ {
+ next_msg = ccc->head_recv;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Giving queued MID %u from %s to client %s\n",
+ ntohl (next_msg->mid.mid),
+ GCCH_2s (ch),
+ GSC_2s (ccc->c));
+ ccc->client_ready = GNUNET_NO;
+ 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);
+ ccc->num_recv--;
+ /* Do not process duplicate MID */
+ if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
+ {
+ /* Duplicate within the queue, drop */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Message on %s (mid %u) dropped, duplicate\n",
+ GCCH_2s (ch),
+ ntohl (msg->mid.mid));
+ GNUNET_free (next_msg);
+ GNUNET_MQ_discard (env);
+ return;
+ }
+ GNUNET_free (next_msg);
+ }
+
+ if (ntohl (msg->mid.mid) < ntohl (ch->mid_recv.mid)) /* Old */
+ {
+ /* Duplicate within the queue, drop */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Message on %s (mid %u) dropped, old.\n",
+ GCCH_2s (ch),
+ ntohl (msg->mid.mid));
+ GNUNET_MQ_discard (env);
+ return;
+ }
+
+ /* Channel is unreliable, so we do not ACK. But we also cannot
+ allow buffering everything, so check if we have space... */
+ if (ccc->num_recv >= ch->max_pending_messages)
{
- struct CadetOutOfOrderMessage *next_msg;
-
- /**
- * 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))
- {
- next_msg = ccc->head_recv;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Giving queued MID %u from %s to client %s\n",
- ntohl(next_msg->mid.mid),
- GCCH_2s(ch),
- GSC_2s(ccc->c));
- ccc->client_ready = GNUNET_NO;
- 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);
- ccc->num_recv--;
- /* Do not process duplicate MID */
- if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
- {
- /* Duplicate within the queue, drop */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Message on %s (mid %u) dropped, duplicate\n",
- GCCH_2s(ch),
- ntohl(msg->mid.mid));
- GNUNET_free(next_msg);
- GNUNET_MQ_discard(env);
- return;
- }
- GNUNET_free(next_msg);
- }
-
- if (ntohl(msg->mid.mid) < ntohl(ch->mid_recv.mid)) /* Old */
- {
- /* Duplicate within the queue, drop */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Message on %s (mid %u) dropped, old.\n",
- GCCH_2s(ch),
- ntohl(msg->mid.mid));
- GNUNET_MQ_discard(env);
- return;
- }
-
- /* Channel is unreliable, so we do not ACK. But we also cannot
- allow buffering everything, so check if we have space... */
- if (ccc->num_recv >= ch->max_pending_messages)
- {
- struct CadetOutOfOrderMessage *drop;
-
- /* Yep, need to drop. Drop the oldest message in
- the buffer. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Queue full due slow client on %s, dropping oldest message\n",
- GCCH_2s(ch));
- GNUNET_STATISTICS_update(stats,
- "# messages dropped due to slow client",
- 1,
- GNUNET_NO);
- drop = ccc->head_recv;
- GNUNET_assert(NULL != drop);
- GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, drop);
- ccc->num_recv--;
- GNUNET_MQ_discard(drop->env);
- GNUNET_free(drop);
- }
+ struct CadetOutOfOrderMessage *drop;
+
+ /* Yep, need to drop. Drop the oldest message in
+ the buffer. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue full due slow client on %s, dropping oldest message\n",
+ GCCH_2s (ch));
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped due to slow client",
+ 1,
+ GNUNET_NO);
+ drop = ccc->head_recv;
+ GNUNET_assert (NULL != drop);
+ GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop);
+ ccc->num_recv--;
+ GNUNET_MQ_discard (drop->env);
+ GNUNET_free (drop);
}
+ }
/* Insert message into sorted out-of-order queue */
- com = GNUNET_new(struct CadetOutOfOrderMessage);
+ com = GNUNET_new (struct CadetOutOfOrderMessage);
com->mid = msg->mid;
com->env = env;
duplicate = GNUNET_NO;
- GNUNET_CONTAINER_DLL_insert_sorted(struct CadetOutOfOrderMessage,
- is_before,
- &duplicate,
- ccc->head_recv,
- ccc->tail_recv,
- com);
+ GNUNET_CONTAINER_DLL_insert_sorted (struct CadetOutOfOrderMessage,
+ is_before,
+ &duplicate,
+ ccc->head_recv,
+ ccc->tail_recv,
+ com);
ccc->num_recv++;
if (GNUNET_YES == duplicate)
- {
- /* Duplicate within the queue, drop also (this is not covered by
- the case above if "delta" >= 64, which could be the case if
- max_pending_messages is also >= 64 or if our client is unready
- and we are seeing retransmissions of the message our client is
- blocked on. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
- (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);
- ccc->num_recv--;
- GNUNET_MQ_discard(com->env);
- GNUNET_free(com);
- send_channel_data_ack(ch);
- return;
- }
- 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",
- (unsigned int)payload_size,
- GCCH_2s(ch),
- ntohl(ccc->ccn.channel_of_client),
- ccc,
- ntohl(msg->mid.mid),
- ntohl(ch->mid_recv.mid));
+ {
+ /* Duplicate within the queue, drop also (this is not covered by
+ the case above if "delta" >= 64, which could be the case if
+ max_pending_messages is also >= 64 or if our client is unready
+ and we are seeing retransmissions of the message our client is
+ blocked on. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Duplicate payload of %u bytes on %s (mid %u) dropped\n",
+ (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);
+ ccc->num_recv--;
+ GNUNET_MQ_discard (com->env);
+ GNUNET_free (com);
+ send_channel_data_ack (ch);
+ return;
+ }
+ 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",
+ (unsigned int) payload_size,
+ GCCH_2s (ch),
+ ntohl (ccc->ccn.channel_of_client),
+ ccc,
+ ntohl (msg->mid.mid),
+ ntohl (ch->mid_recv.mid));
/* NOTE: this ACK we _could_ skip, as the packet is out-of-order and
the sender may already be transmitting the previous one. Needs
experimental evaluation to see if/when this ACK helps or
hurts. (We might even want another option.) */
- send_channel_data_ack(ch);
+ send_channel_data_ack (ch);
}
@@ -1452,8 +1457,8 @@ GCCH_handle_channel_plaintext_data(
* if transmission failed
*/
static void
-data_sent_cb(void *cls,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+data_sent_cb (void *cls,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
/**
@@ -1463,19 +1468,19 @@ data_sent_cb(void *cls,
* @param cls the `struct CadetChannel` where we need to retransmit
*/
static void
-retry_transmission(void *cls)
+retry_transmission (void *cls)
{
struct CadetChannel *ch = cls;
struct CadetReliableMessage *crm = ch->head_sent;
ch->retry_data_task = NULL;
- GNUNET_assert(NULL == crm->qe);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "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);
- GNUNET_assert(NULL == ch->retry_data_task);
+ GNUNET_assert (NULL == crm->qe);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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);
+ GNUNET_assert (NULL == ch->retry_data_task);
}
@@ -1488,36 +1493,36 @@ retry_transmission(void *cls)
* @param crm the message that got acknowledged
*/
static void
-handle_matching_ack(struct CadetChannel *ch,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
- struct CadetReliableMessage *crm)
+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,
- "Received DATA_ACK on %s for message %u (%u ACKs pending)\n",
- GCCH_2s(ch),
- (unsigned int)ntohl(crm->data_message->mid.mid),
- ch->pending_messages);
+ GNUNET_assert (ch->pending_messages < ch->max_pending_messages);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received DATA_ACK on %s for message %u (%u ACKs pending)\n",
+ GCCH_2s (ch),
+ (unsigned int) ntohl (crm->data_message->mid.mid),
+ ch->pending_messages);
if (NULL != crm->qe)
- {
- GCT_send_cancel(crm->qe);
- crm->qe = NULL;
- }
+ {
+ GCT_send_cancel (crm->qe);
+ crm->qe = NULL;
+ }
if ((1 == crm->num_transmissions) && (NULL != cti))
+ {
+ GCC_ack_observed (cti);
+ if (0 == GNUNET_memcmp (cti, &crm->connection_taken))
{
- GCC_ack_observed(cti);
- if (0 == GNUNET_memcmp(cti, &crm->connection_taken))
- {
- GCC_latency_observed(cti,
- GNUNET_TIME_absolute_get_duration(
- crm->first_transmission_time));
- }
+ GCC_latency_observed (cti,
+ 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);
+ }
+ GNUNET_free (crm->data_message);
+ GNUNET_free (crm);
+ send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
}
@@ -1530,7 +1535,7 @@ handle_matching_ack(struct CadetChannel *ch,
* @param ack details about what was received
*/
void
-GCCH_handle_channel_plaintext_data_ack(
+GCCH_handle_channel_plaintext_data_ack (
struct CadetChannel *ch,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
const struct GNUNET_CADET_ChannelDataAckMessage *ack)
@@ -1542,72 +1547,72 @@ GCCH_handle_channel_plaintext_data_ack(
uint64_t mid_mask;
unsigned int delta;
- GNUNET_break(GNUNET_NO == ch->is_loopback);
+ GNUNET_break (GNUNET_NO == ch->is_loopback);
if (GNUNET_NO == ch->reliable)
- {
- /* not expecting ACKs on unreliable channel, odd */
- GNUNET_break_op(0);
- return;
- }
+ {
+ /* not expecting ACKs on unreliable channel, odd */
+ GNUNET_break_op (0);
+ return;
+ }
/* mid_base is the MID of the next message that the
other peer expects (i.e. that is missing!), everything
LOWER (but excluding mid_base itself) was received. */
- mid_base = ntohl(ack->mid.mid);
- mid_mask = GNUNET_htonll(ack->futures);
+ mid_base = ntohl (ack->mid.mid);
+ mid_mask = GNUNET_htonll (ack->futures);
found = GNUNET_NO;
for (crm = ch->head_sent; NULL != crm; crm = crmn)
+ {
+ crmn = crm->next;
+ delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base);
+ if (delta >= UINT_MAX - ch->max_pending_messages)
{
- crmn = crm->next;
- delta = (unsigned int)(ntohl(crm->data_message->mid.mid) - mid_base);
- if (delta >= UINT_MAX - ch->max_pending_messages)
- {
- /* overflow, means crm was a bit in the past, so this ACK counts for it. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got DATA_ACK with base %u satisfying past message %u on %s\n",
- (unsigned int)mid_base,
- ntohl(crm->data_message->mid.mid),
- GCCH_2s(ch));
- handle_matching_ack(ch, cti, crm);
- found = GNUNET_YES;
- continue;
- }
- delta--;
- if (delta >= 64)
- continue;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Testing bit %llX for mid %u (base: %u)\n",
- (1LLU << delta),
- ntohl(crm->data_message->mid.mid),
- mid_base);
- if (0 != (mid_mask & (1LLU << delta)))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "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);
- found = GNUNET_YES;
- }
+ /* overflow, means crm was a bit in the past, so this ACK counts for it. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got DATA_ACK with base %u satisfying past message %u on %s\n",
+ (unsigned int) mid_base,
+ ntohl (crm->data_message->mid.mid),
+ GCCH_2s (ch));
+ handle_matching_ack (ch, cti, crm);
+ found = GNUNET_YES;
+ continue;
}
- if (GNUNET_NO == found)
+ delta--;
+ if (delta >= 64)
+ continue;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing bit %llX for mid %u (base: %u)\n",
+ (1LLU << delta),
+ ntohl (crm->data_message->mid.mid),
+ mid_base);
+ if (0 != (mid_mask & (1LLU << delta)))
{
- /* ACK for message we already dropped, might have been a
- duplicate ACK? Ignore. */
- 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);
- return;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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);
+ found = GNUNET_YES;
}
+ }
+ if (GNUNET_NO == found)
+ {
+ /* ACK for message we already dropped, might have been a
+ duplicate ACK? Ignore. */
+ 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);
+ return;
+ }
if (NULL != ch->retry_data_task)
- {
- GNUNET_SCHEDULER_cancel(ch->retry_data_task);
- ch->retry_data_task = NULL;
- }
+ {
+ 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);
+ ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
+ &retry_transmission,
+ ch);
}
@@ -1621,34 +1626,34 @@ GCCH_handle_channel_plaintext_data_ack(
* NULL if we are simulating receiving a destroy due to shutdown
*/
void
-GCCH_handle_remote_destroy(
+GCCH_handle_remote_destroy (
struct CadetChannel *ch,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
{
struct CadetChannelClient *ccc;
- GNUNET_assert(GNUNET_NO == ch->is_loopback);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received remote channel DESTROY for %s\n",
- GCCH_2s(ch));
+ GNUNET_assert (GNUNET_NO == ch->is_loopback);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received remote channel DESTROY for %s\n",
+ GCCH_2s (ch));
if (GNUNET_YES == ch->destroy)
- {
- /* Local client already gone, this is instant-death. */
- channel_destroy(ch);
- return;
- }
+ {
+ /* Local client already gone, this is instant-death. */
+ channel_destroy (ch);
+ return;
+ }
ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
if ((NULL != ccc) && (NULL != ccc->head_recv))
- {
- LOG(GNUNET_ERROR_TYPE_WARNING,
- "Lost end of transmission due to remote shutdown on %s\n",
- GCCH_2s(ch));
- /* FIXME: change API to notify client about truncated transmission! */
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Lost end of transmission due to remote shutdown on %s\n",
+ GCCH_2s (ch));
+ /* FIXME: change API to notify client about truncated transmission! */
+ }
ch->destroy = GNUNET_YES;
if (NULL != ccc)
- GSC_handle_remote_channel_destroy(ccc->c, ccc->ccn, ch);
- channel_destroy(ch);
+ GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
+ channel_destroy (ch);
}
@@ -1661,9 +1666,9 @@ GCCH_handle_remote_destroy(
* @return #GNUNET_YES if @e1 < @e2, otherwise #GNUNET_NO
*/
static int
-cmp_crm_by_next_retry(void *cls,
- struct CadetReliableMessage *crm1,
- struct CadetReliableMessage *crm2)
+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)
return GNUNET_YES;
@@ -1682,75 +1687,76 @@ cmp_crm_by_next_retry(void *cls,
* if transmission failed
*/
static void
-data_sent_cb(void *cls,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+data_sent_cb (void *cls,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
struct CadetReliableMessage *crm = cls;
struct CadetChannel *ch = crm->ch;
- GNUNET_assert(GNUNET_NO == ch->is_loopback);
- GNUNET_assert(NULL != crm->qe);
+ 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);
- return;
- }
+ {
+ GNUNET_free (crm->data_message);
+ GNUNET_free (crm);
+ ch->pending_messages--;
+ send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
+ return;
+ }
if (NULL == cid)
- {
- /* There was an error sending. */
- crm->num_transmissions = GNUNET_SYSERR;
- }
+ {
+ /* There was an error sending. */
+ crm->num_transmissions = GNUNET_SYSERR;
+ }
else if (GNUNET_SYSERR != crm->num_transmissions)
+ {
+ /* Increment transmission counter, and possibly store @a cid
+ if this was the first transmission. */
+ crm->num_transmissions++;
+ if (1 == crm->num_transmissions)
{
- /* Increment transmission counter, and possibly store @a cid
- if this was the first transmission. */
- crm->num_transmissions++;
- if (1 == crm->num_transmissions)
- {
- crm->first_transmission_time = GNUNET_TIME_absolute_get();
- crm->connection_taken = *cid;
- GCC_ack_expected(cid);
- }
+ crm->first_transmission_time = GNUNET_TIME_absolute_get ();
+ crm->connection_taken = *cid;
+ GCC_ack_expected (cid);
}
+ }
if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid))
- {
- struct CadetConnection *cc = GCC_lookup(cid);
-
- if (NULL != cc)
- crm->retry_delay = GCC_get_metrics(cc)->aged_latency;
- else
- 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->next_retry = GNUNET_TIME_relative_to_absolute(crm->retry_delay);
-
- GNUNET_CONTAINER_DLL_insert_sorted(struct CadetReliableMessage,
- cmp_crm_by_next_retry,
- NULL,
- ch->head_sent,
- ch->tail_sent,
- crm);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "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_YES));
+ {
+ struct CadetConnection *cc = GCC_lookup (cid);
+
+ if (NULL != cc)
+ crm->retry_delay = GCC_get_metrics (cc)->aged_latency;
+ else
+ 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->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay);
+
+ GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage,
+ cmp_crm_by_next_retry,
+ NULL,
+ ch->head_sent,
+ ch->tail_sent,
+ crm);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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_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);
- }
+ {
+ 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);
+ }
}
@@ -1769,100 +1775,100 @@ data_sent_cb(void *cls,
* #GNUNET_SYSERR in case of an error.
*/
int
-GCCH_handle_local_data(struct CadetChannel *ch,
- struct GNUNET_CADET_ClientChannelNumber sender_ccn,
- const char *buf,
- size_t buf_len)
+GCCH_handle_local_data (struct CadetChannel *ch,
+ struct GNUNET_CADET_ClientChannelNumber sender_ccn,
+ const char *buf,
+ size_t buf_len)
{
struct CadetReliableMessage *crm;
if (ch->pending_messages >= ch->max_pending_messages)
+ {
+ GNUNET_break (0); /* Fails: #5370 */
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_YES == ch->destroy)
+ {
+ /* we are going down, drop messages */
+ return GNUNET_OK;
+ }
+ ch->pending_messages++;
+
+ if (GNUNET_YES == ch->is_loopback)
+ {
+ struct CadetChannelClient *receiver;
+ struct GNUNET_MQ_Envelope *env;
+ 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))
+ {
+ receiver = ch->dest;
+ ack_to_owner = GNUNET_YES;
+ }
+ else if ((NULL != ch->dest) &&
+ (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
+ {
+ receiver = ch->owner;
+ ack_to_owner = GNUNET_NO;
+ }
+ else
{
- GNUNET_break(0); /* Fails: #5370 */
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (GNUNET_YES == ch->destroy)
+ GNUNET_assert (NULL != receiver);
+ ld->ccn = receiver->ccn;
+ GNUNET_memcpy (&ld[1], buf, buf_len);
+ if (GNUNET_YES == receiver->client_ready)
{
- /* we are going down, drop messages */
- return GNUNET_OK;
+ ch->pending_messages--;
+ GSC_send_to_client (receiver->c, env);
+ send_ack_to_client (ch, ack_to_owner);
}
- ch->pending_messages++;
-
- if (GNUNET_YES == ch->is_loopback)
+ else
{
- struct CadetChannelClient *receiver;
- struct GNUNET_MQ_Envelope *env;
- 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))
- {
- receiver = ch->dest;
- ack_to_owner = GNUNET_YES;
- }
- else if ((NULL != ch->dest) &&
- (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
- {
- receiver = ch->owner;
- ack_to_owner = GNUNET_NO;
- }
- else
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert(NULL != receiver);
- ld->ccn = receiver->ccn;
- 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);
- }
- else
- {
- struct CadetOutOfOrderMessage *oom;
-
- oom = GNUNET_new(struct CadetOutOfOrderMessage);
- oom->env = env;
- GNUNET_CONTAINER_DLL_insert_tail(receiver->head_recv,
- receiver->tail_recv,
- oom);
- receiver->num_recv++;
- }
- return GNUNET_OK;
+ struct CadetOutOfOrderMessage *oom;
+
+ oom = GNUNET_new (struct CadetOutOfOrderMessage);
+ oom->env = env;
+ GNUNET_CONTAINER_DLL_insert_tail (receiver->head_recv,
+ receiver->tail_recv,
+ oom);
+ receiver->num_recv++;
}
+ return GNUNET_OK;
+ }
/* Everything is correct, send the message. */
- crm = GNUNET_malloc(sizeof(*crm));
+ crm = GNUNET_malloc (sizeof(*crm));
crm->ch = ch;
- crm->data_message = GNUNET_malloc(
+ 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);
+ 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);
+ 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);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u from local client to %s with %u bytes\n",
- ntohl(crm->data_message->mid.mid),
- GCCH_2s(ch),
- buf_len);
+ 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),
+ GCCH_2s (ch),
+ buf_len);
if (NULL != ch->retry_data_task)
- {
- 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);
- GNUNET_assert(NULL == ch->retry_data_task);
+ {
+ 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);
+ GNUNET_assert (NULL == ch->retry_data_task);
return GNUNET_OK;
}
@@ -1875,8 +1881,8 @@ GCCH_handle_local_data(struct CadetChannel *ch,
* @param client_ccn ccn of the client sending the ack
*/
void
-GCCH_handle_local_ack(struct CadetChannel *ch,
- struct GNUNET_CADET_ClientChannelNumber client_ccn)
+GCCH_handle_local_ack (struct CadetChannel *ch,
+ struct GNUNET_CADET_ClientChannelNumber client_ccn)
{
struct CadetChannelClient *ccc;
struct CadetOutOfOrderMessage *com;
@@ -1888,87 +1894,87 @@ GCCH_handle_local_ack(struct CadetChannel *ch,
(ch->dest->ccn.channel_of_client == client_ccn.channel_of_client))
ccc = ch->dest;
else
- GNUNET_assert(0);
+ GNUNET_assert (0);
ccc->client_ready = GNUNET_YES;
com = ccc->head_recv;
if (NULL == com)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n",
+ GSC_2s (ccc->c),
+ ntohl (client_ccn.channel_of_client),
+ GCCH_2s (ch),
+ ntohl (ccc->ccn.channel_of_client),
+ ccc);
+ return; /* none pending */
+ }
+ if (GNUNET_YES == ch->is_loopback)
+ {
+ int to_owner;
+
+ /* Messages are always in-order, just send */
+ GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
+ ccc->num_recv--;
+ 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))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got LOCAL_ACK, %s-%X ready to receive more data, but none pending on %s-%X(%p)!\n",
- GSC_2s(ccc->c),
- ntohl(client_ccn.channel_of_client),
- GCCH_2s(ch),
- ntohl(ccc->ccn.channel_of_client),
- ccc);
- return; /* none pending */
+ to_owner = GNUNET_NO;
}
- if (GNUNET_YES == ch->is_loopback)
+ else
{
- int to_owner;
-
- /* Messages are always in-order, just send */
- GNUNET_CONTAINER_DLL_remove(ccc->head_recv, ccc->tail_recv, com);
- ccc->num_recv--;
- 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))
- {
- to_owner = GNUNET_NO;
- }
- else
- {
- 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);
- GNUNET_free(com);
- return;
+ 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);
+ GNUNET_free (com);
+ return;
+ }
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",
- GSC_2s(ccc->c),
- ntohl(ccc->ccn.channel_of_client),
- ntohl(com->mid.mid),
- ntohl(ch->mid_recv.mid));
- return; /* missing next one in-order */
- }
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n",
- ntohl(com->mid.mid),
- GSC_2s(ccc->c),
- ntohl(ccc->ccn.channel_of_client),
- GCCH_2s(ch));
+ {
+ 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",
+ GSC_2s (ccc->c),
+ ntohl (ccc->ccn.channel_of_client),
+ ntohl (com->mid.mid),
+ ntohl (ch->mid_recv.mid));
+ return; /* missing next one in-order */
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got LOCAL_ACK, giving payload message %u to %s-%X on %s\n",
+ ntohl (com->mid.mid),
+ GSC_2s (ccc->c),
+ ntohl (ccc->ccn.channel_of_client),
+ 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! */
- ch->mid_recv.mid = htonl(1 + ntohl(com->mid.mid));
+ 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);
- GNUNET_free(com);
- send_channel_data_ack(ch);
+ 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);
- channel_destroy(ch);
+ GCT_send_channel_destroy (ch->t, ch->ctn);
+ channel_destroy (ch);
}
#define LOG2(level, ...) \
- GNUNET_log_from_nocheck(level, "cadet-chn", __VA_ARGS__)
+ GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__)
/**
@@ -1978,46 +1984,46 @@ 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__);
+ do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
+ "cadet-chn",
+ __FILE__,
+ __FUNCTION__,
+ __LINE__);
if (0 == do_log)
return;
if (NULL == 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 *** DEBUG NULL CHANNEL ***\n");
+ return;
+ }
+ LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch);
if (NULL != ch->owner)
- {
- LOG2(level,
- "CHN origin %s ready %s local-id: %u\n",
- GSC_2s(ch->owner->c),
- ch->owner->client_ready ? "YES" : "NO",
- ntohl(ch->owner->ccn.channel_of_client));
- }
+ {
+ LOG2 (level,
+ "CHN origin %s ready %s local-id: %u\n",
+ GSC_2s (ch->owner->c),
+ ch->owner->client_ready ? "YES" : "NO",
+ ntohl (ch->owner->ccn.channel_of_client));
+ }
if (NULL != ch->dest)
- {
- LOG2(level,
- "CHN destination %s ready %s local-id: %u\n",
- GSC_2s(ch->dest->c),
- ch->dest->client_ready ? "YES" : "NO",
- ntohl(ch->dest->ccn.channel_of_client));
- }
- LOG2(level,
- "CHN Message IDs recv: %d (%LLX), send: %d\n",
- ntohl(ch->mid_recv.mid),
- (unsigned long long)ch->mid_futures,
- ntohl(ch->mid_send.mid));
+ {
+ LOG2 (level,
+ "CHN destination %s ready %s local-id: %u\n",
+ GSC_2s (ch->dest->c),
+ ch->dest->client_ready ? "YES" : "NO",
+ ntohl (ch->dest->ccn.channel_of_client));
+ }
+ LOG2 (level,
+ "CHN Message IDs recv: %d (%LLX), send: %d\n",
+ ntohl (ch->mid_recv.mid),
+ (unsigned long long) ch->mid_futures,
+ ntohl (ch->mid_send.mid));
#endif
}
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index a64d4058e..181c6e88b 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -53,9 +53,9 @@ struct CadetChannel;
* @param listener peer that is listining on @a port
*/
void
-GCCH_hash_port(struct GNUNET_HashCode *h_port,
- const struct GNUNET_HashCode *port,
- const struct GNUNET_PeerIdentity *listener);
+GCCH_hash_port (struct GNUNET_HashCode *h_port,
+ const struct GNUNET_HashCode *port,
+ const struct GNUNET_PeerIdentity *listener);
/**
@@ -66,7 +66,7 @@ GCCH_hash_port(struct GNUNET_HashCode *h_port,
* @return Static string with the channel IDs.
*/
const char *
-GCCH_2s(const struct CadetChannel *ch);
+GCCH_2s (const struct CadetChannel *ch);
/**
@@ -76,8 +76,8 @@ GCCH_2s(const 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);
/**
@@ -88,7 +88,7 @@ GCCH_debug(struct CadetChannel *ch,
* @return ID used to identify the channel with the remote peer.
*/
struct GNUNET_CADET_ChannelTunnelNumber
-GCCH_get_id(const struct CadetChannel *ch);
+GCCH_get_id (const struct CadetChannel *ch);
/**
@@ -102,11 +102,11 @@ GCCH_get_id(const struct CadetChannel *ch);
* @return handle to the new channel
*/
struct CadetChannel *
-GCCH_channel_local_new(struct CadetClient *owner,
- struct GNUNET_CADET_ClientChannelNumber owner_id,
- struct CadetPeer *destination,
- const struct GNUNET_HashCode *port,
- uint32_t options);
+GCCH_channel_local_new (struct CadetClient *owner,
+ struct GNUNET_CADET_ClientChannelNumber owner_id,
+ struct CadetPeer *destination,
+ const struct GNUNET_HashCode *port,
+ uint32_t options);
/**
@@ -119,9 +119,9 @@ GCCH_channel_local_new(struct CadetClient *owner,
* @param port port number @a c is listening on
*/
void
-GCCH_bind(struct CadetChannel *ch,
- struct CadetClient *c,
- const struct GNUNET_HashCode *port);
+GCCH_bind (struct CadetChannel *ch,
+ struct CadetClient *c,
+ const struct GNUNET_HashCode *port);
/**
@@ -133,9 +133,9 @@ GCCH_bind(struct CadetChannel *ch,
* @param ccn client number of the client @a c
*/
void
-GCCH_channel_local_destroy(struct CadetChannel *ch,
- struct CadetClient *c,
- struct GNUNET_CADET_ClientChannelNumber ccn);
+GCCH_channel_local_destroy (struct CadetChannel *ch,
+ struct CadetClient *c,
+ struct GNUNET_CADET_ClientChannelNumber ccn);
/**
@@ -149,7 +149,7 @@ GCCH_channel_local_destroy(struct CadetChannel *ch,
* @param ch the channel for which the tunnel is now ready
*/
void
-GCCH_tunnel_up(struct CadetChannel *ch);
+GCCH_tunnel_up (struct CadetChannel *ch);
/**
@@ -163,10 +163,10 @@ GCCH_tunnel_up(struct CadetChannel *ch);
* @return handle to the new channel
*/
struct CadetChannel *
-GCCH_channel_incoming_new(struct CadetTunnel *t,
- struct GNUNET_CADET_ChannelTunnelNumber chid,
- const struct GNUNET_HashCode *h_port,
- uint32_t options);
+GCCH_channel_incoming_new (struct CadetTunnel *t,
+ struct GNUNET_CADET_ChannelTunnelNumber chid,
+ const struct GNUNET_HashCode *h_port,
+ uint32_t options);
/**
@@ -178,8 +178,9 @@ GCCH_channel_incoming_new(struct CadetTunnel *t,
* @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);
@@ -191,9 +192,11 @@ GCCH_handle_duplicate_open(struct CadetChannel *ch,
* @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);
/**
@@ -205,9 +208,12 @@ GCCH_handle_channel_plaintext_data(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);
/**
@@ -220,9 +226,10 @@ GCCH_handle_channel_plaintext_data_ack(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);
/**
@@ -242,8 +249,9 @@ GCCH_handle_channel_open_ack(struct CadetChannel *ch,
* NULL during 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);
/**
@@ -261,10 +269,10 @@ GCCH_handle_remote_destroy(struct CadetChannel *ch,
* #GNUNET_SYSERR in case of an error.
*/
int
-GCCH_handle_local_data(struct CadetChannel *ch,
- struct GNUNET_CADET_ClientChannelNumber sender_ccn,
- const char *buf,
- size_t buf_len);
+GCCH_handle_local_data (struct CadetChannel *ch,
+ struct GNUNET_CADET_ClientChannelNumber sender_ccn,
+ const char *buf,
+ size_t buf_len);
/**
@@ -274,7 +282,7 @@ GCCH_handle_local_data(struct CadetChannel *ch,
* @param client_ccn ccn of the client sending the ack
*/
void
-GCCH_handle_local_ack(struct CadetChannel *ch,
- struct GNUNET_CADET_ClientChannelNumber client_ccn);
+GCCH_handle_local_ack (struct CadetChannel *ch,
+ struct GNUNET_CADET_ClientChannelNumber client_ccn);
#endif
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index e3c1a4124..66dc20481 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -35,7 +35,7 @@
#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__)
/**
@@ -43,13 +43,14 @@
* 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)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
/**
* All the states a connection can be in.
*/
-enum CadetConnectionState {
+enum CadetConnectionState
+{
/**
* Uninitialized status, we have not yet even gotten the message queue.
*/
@@ -81,7 +82,8 @@ enum CadetConnectionState {
/**
* Low-level connection to a destination.
*/
-struct CadetConnection {
+struct CadetConnection
+{
/**
* ID of the connection.
*/
@@ -181,10 +183,10 @@ struct CadetConnection {
* @return NULL if connection was not found
*/
struct CadetConnection *
-GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
- return GNUNET_CONTAINER_multishortmap_get(connections,
- &cid->connection_of_tunnel);
+ return GNUNET_CONTAINER_multishortmap_get (connections,
+ &cid->connection_of_tunnel);
}
@@ -197,9 +199,9 @@ GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
* @param new_mqm_ready new `mqm_ready` state for @a cc
*/
static void
-update_state(struct CadetConnection *cc,
- enum CadetConnectionState new_state,
- int new_mqm_ready)
+update_state (struct CadetConnection *cc,
+ enum CadetConnectionState new_state,
+ int new_mqm_ready)
{
int old_ready;
int new_ready;
@@ -213,7 +215,7 @@ update_state(struct CadetConnection *cc,
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);
}
@@ -224,34 +226,34 @@ update_state(struct CadetConnection *cc,
* @param cc connection to destroy
*/
static void
-GCC_destroy(struct CadetConnection *cc)
+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);
- cc->mq_man = NULL;
- }
+ {
+ GCP_request_mq_cancel (cc->mq_man, NULL);
+ cc->mq_man = NULL;
+ }
if (NULL != cc->task)
- {
- GNUNET_SCHEDULER_cancel(cc->task);
- cc->task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cc->task);
+ cc->task = NULL;
+ }
if (NULL != cc->keepalive_qe)
- {
- GCT_send_cancel(cc->keepalive_qe);
- cc->keepalive_qe = NULL;
- }
- GCPP_del_connection(cc->path, cc->off, cc);
+ {
+ GCT_send_cancel (cc->keepalive_qe);
+ cc->keepalive_qe = NULL;
+ }
+ 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(
+ 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);
+ GNUNET_CONTAINER_multishortmap_remove (connections,
+ &GCC_get_id (cc)
+ ->connection_of_tunnel,
+ cc));
+ GNUNET_free (cc);
}
@@ -264,14 +266,14 @@ GCC_destroy(struct CadetConnection *cc)
* @param cc connection to destroy
*/
void
-GCC_destroy_without_core(struct CadetConnection *cc)
+GCC_destroy_without_core (struct CadetConnection *cc)
{
if (NULL != cc->ct)
- {
- GCT_connection_lost(cc->ct);
- cc->ct = NULL;
- }
- GCC_destroy(cc);
+ {
+ GCT_connection_lost (cc->ct);
+ cc->ct = NULL;
+ }
+ GCC_destroy (cc);
}
@@ -283,22 +285,22 @@ GCC_destroy_without_core(struct CadetConnection *cc)
* @param cc connection to destroy
*/
void
-GCC_destroy_without_tunnel(struct CadetConnection *cc)
+GCC_destroy_without_tunnel (struct CadetConnection *cc)
{
cc->ct = NULL;
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);
- destroy_msg->cid = cc->cid;
- GCP_request_mq_cancel(cc->mq_man, env);
- cc->mq_man = NULL;
- }
- GCC_destroy(cc);
+ {
+ 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);
+ destroy_msg->cid = cc->cid;
+ GCP_request_mq_cancel (cc->mq_man, env);
+ cc->mq_man = NULL;
+ }
+ GCC_destroy (cc);
}
@@ -309,7 +311,7 @@ GCC_destroy_without_tunnel(struct CadetConnection *cc)
* @return corresponding entry in the tunnel's connection list
*/
struct CadetTConnection *
-GCC_get_ct(struct CadetConnection *cc)
+GCC_get_ct (struct CadetConnection *cc)
{
return cc->ct;
}
@@ -322,7 +324,7 @@ GCC_get_ct(struct CadetConnection *cc)
* @return the metrics
*/
const struct CadetConnectionMetrics *
-GCC_get_metrics(struct CadetConnection *cc)
+GCC_get_metrics (struct CadetConnection *cc)
{
return &cc->metrics;
}
@@ -335,7 +337,7 @@ GCC_get_metrics(struct CadetConnection *cc)
* @param cls the `struct CadetConnection` to keep alive.
*/
static void
-send_keepalive(void *cls);
+send_keepalive (void *cls);
/**
@@ -347,15 +349,15 @@ send_keepalive(void *cls);
* if transmission failed
*/
static void
-keepalive_done(void *cls,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+keepalive_done (void *cls,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
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);
+ GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
}
@@ -366,31 +368,31 @@ keepalive_done(void *cls,
* @param cls the `struct CadetConnection` to keep alive.
*/
static void
-send_keepalive(void *cls)
+send_keepalive (void *cls)
{
struct CadetConnection *cc = cls;
struct GNUNET_MessageHeader msg;
cc->task = NULL;
- 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);
- return;
- }
- GNUNET_assert(NULL != cc->ct);
- GNUNET_assert(GNUNET_YES == cc->mqm_ready);
- GNUNET_assert(NULL == cc->keepalive_qe);
- LOG(GNUNET_ERROR_TYPE_INFO,
- "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);
- 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);
+ 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);
+ return;
+ }
+ GNUNET_assert (NULL != cc->ct);
+ GNUNET_assert (GNUNET_YES == cc->mqm_ready);
+ GNUNET_assert (NULL == cc->keepalive_qe);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "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);
+ 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);
}
@@ -401,11 +403,11 @@ send_keepalive(void *cls)
* @param cid connection identifier where we expect an ACK
*/
void
-GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
struct CadetConnection *cc;
- cc = GCC_lookup(cid);
+ cc = GCC_lookup (cid);
if (NULL == cc)
return; /* whopise, connection alredy down? */
cc->metrics.num_acked_transmissions++;
@@ -421,11 +423,11 @@ GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
* may have gotten back to us via a different connection).
*/
void
-GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
struct CadetConnection *cc;
- cc = GCC_lookup(cid);
+ cc = GCC_lookup (cid);
if (NULL == cc)
return; /* whopise, connection alredy down? */
cc->metrics.num_successes++;
@@ -441,17 +443,17 @@ GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
* @param latency the observed latency
*/
void
-GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- struct GNUNET_TIME_Relative latency)
+GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ struct GNUNET_TIME_Relative latency)
{
struct CadetConnection *cc;
double weight;
double result;
- cc = GCC_lookup(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;
@@ -460,10 +462,10 @@ 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;
+ cc->metrics.aged_latency.rel_value_us = (uint64_t) result;
}
@@ -475,26 +477,26 @@ GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
* @param cc the connection that got the ACK.
*/
void
-GCC_handle_connection_create_ack(struct CadetConnection *cc)
+GCC_handle_connection_create_ack (struct CadetConnection *cc)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
- GCC_2s(cc),
- cc->state,
- (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CADET_CONNECTION_CREATE_ACK for %s in state %d (%s)\n",
+ GCC_2s (cc),
+ cc->state,
+ (GNUNET_YES == cc->mqm_ready) ? "MQM ready" : "MQM busy");
if (CADET_CONNECTION_READY == cc->state)
return; /* Duplicate ACK, ignore */
if (NULL != cc->task)
- {
- GNUNET_SCHEDULER_cancel(cc->task);
- cc->task = NULL;
- }
- cc->metrics.age = GNUNET_TIME_absolute_get();
- update_state(cc, CADET_CONNECTION_READY, cc->mqm_ready);
+ {
+ GNUNET_SCHEDULER_cancel (cc->task);
+ 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);
+ GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
}
@@ -505,24 +507,24 @@ GCC_handle_connection_create_ack(struct CadetConnection *cc)
* @param msg the key exchange message
*/
void
-GCC_handle_kx(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
+GCC_handle_kx (struct CadetConnection *cc,
+ const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received KX message with ephermal %s on CC %s in state %d\n",
- GNUNET_e2s(&msg->ephemeral_key),
- GNUNET_sh2s(&cc->cid.connection_of_tunnel),
- cc->state);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received KX message with ephermal %s on CC %s in state %d\n",
+ GNUNET_e2s (&msg->ephemeral_key),
+ GNUNET_sh2s (&cc->cid.connection_of_tunnel),
+ cc->state);
if (CADET_CONNECTION_SENT == cc->state)
- {
- /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
- clearly something is working, so pretend we got an ACK. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
- GCC_2s(cc));
- GCC_handle_connection_create_ack(cc);
- }
- GCT_handle_kx(cc->ct, msg);
+ {
+ /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
+ clearly something is working, so pretend we got an ACK. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
+ GCC_2s (cc));
+ GCC_handle_connection_create_ack (cc);
+ }
+ GCT_handle_kx (cc->ct, msg);
}
@@ -533,24 +535,24 @@ GCC_handle_kx(struct CadetConnection *cc,
* @param msg the key exchange message
*/
void
-GCC_handle_kx_auth(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
+GCC_handle_kx_auth (struct CadetConnection *cc,
+ const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
- GNUNET_e2s(&msg->kx.ephemeral_key),
- GNUNET_sh2s(&cc->cid.connection_of_tunnel),
- cc->state);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received KX AUTH message with ephermal %s on CC %s in state %d\n",
+ GNUNET_e2s (&msg->kx.ephemeral_key),
+ GNUNET_sh2s (&cc->cid.connection_of_tunnel),
+ cc->state);
if (CADET_CONNECTION_SENT == cc->state)
- {
- /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
- clearly something is working, so pretend we got an ACK. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
- GCC_2s(cc));
- GCC_handle_connection_create_ack(cc);
- }
- GCT_handle_kx_auth(cc->ct, msg);
+ {
+ /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine,
+ clearly something is working, so pretend we got an ACK. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Faking connection CADET_CONNECTION_CREATE_ACK for %s due to KX\n",
+ GCC_2s (cc));
+ GCC_handle_connection_create_ack (cc);
+ }
+ GCT_handle_kx_auth (cc->ct, msg);
}
@@ -561,20 +563,20 @@ GCC_handle_kx_auth(struct CadetConnection *cc,
* @param msg the encrypted message to decrypt
*/
void
-GCC_handle_encrypted(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
+GCC_handle_encrypted (struct CadetConnection *cc,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
{
if (CADET_CONNECTION_SENT == cc->state)
- {
- /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
- clearly something is working, so pretend we got an ACK. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Faking connection ACK for %s due to ENCRYPTED payload\n",
- GCC_2s(cc));
- GCC_handle_connection_create_ack(cc);
- }
- cc->metrics.last_use = GNUNET_TIME_absolute_get();
- GCT_handle_encrypted(cc->ct, msg);
+ {
+ /* We didn't get the CREATE_ACK, but instead got payload. That's fine,
+ clearly something is working, so pretend we got an ACK. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Faking connection ACK for %s due to ENCRYPTED payload\n",
+ GCC_2s (cc));
+ GCC_handle_connection_create_ack (cc);
+ }
+ cc->metrics.last_use = GNUNET_TIME_absolute_get ();
+ GCT_handle_encrypted (cc->ct, msg);
}
@@ -585,7 +587,7 @@ GCC_handle_encrypted(struct CadetConnection *cc,
* @param cls the `struct CadetConnection` to initiate
*/
static void
-send_create(void *cls)
+send_create (void *cls)
{
struct CadetConnection *cc = cls;
struct GNUNET_CADET_ConnectionCreateMessage *create_msg;
@@ -593,27 +595,27 @@ send_create(void *cls)
struct GNUNET_MQ_Envelope *env;
cc->task = NULL;
- GNUNET_assert(GNUNET_YES == cc->mqm_ready);
+ 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 set the deprecated 'reliable' bit here that was removed.
+ 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 = (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));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n",
- GCC_2s(cc),
- cc->off + 2);
+ 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),
+ cc->off + 2);
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);
+ 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);
}
@@ -623,29 +625,29 @@ send_create(void *cls)
* @param cls the `struct CadetConnection` to initiate
*/
static void
-send_create_ack(void *cls)
+send_create_ack (void *cls)
{
struct CadetConnection *cc = cls;
struct GNUNET_CADET_ConnectionCreateAckMessage *ack_msg;
struct GNUNET_MQ_Envelope *env;
cc->task = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending CONNECTION_CREATE_ACK message for %s\n",
- GCC_2s(cc));
- GNUNET_assert(GNUNET_YES == cc->mqm_ready);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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);
+ 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);
+ 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);
+ GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
+ GCP_send (cc->mq_man, env);
}
@@ -657,31 +659,31 @@ send_create_ack(void *cls)
* @param cc connection that got the duplicate CREATE
*/
void
-GCC_handle_duplicate_create(struct CadetConnection *cc)
+GCC_handle_duplicate_create (struct CadetConnection *cc)
{
if (GNUNET_YES == cc->mqm_ready)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
- GCC_2s(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);
- if (NULL != cc->task)
- GNUNET_SCHEDULER_cancel(cc->task);
- cc->task =
- GNUNET_SCHEDULER_add_at(cc->create_ack_at, &send_create_ack, cc);
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got duplicate CREATE for %s, scheduling another ACK (%s)\n",
+ GCC_2s (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);
+ if (NULL != cc->task)
+ GNUNET_SCHEDULER_cancel (cc->task);
+ cc->task =
+ GNUNET_SCHEDULER_add_at (cc->create_ack_at, &send_create_ack, cc);
+ }
else
- {
- /* We are currently sending something else back, which
- can only be an ACK or payload, either of which would
- do. So actually no need to do anything. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
- GCC_2s(cc));
- }
+ {
+ /* We are currently sending something else back, which
+ can only be an ACK or payload, either of which would
+ do. So actually no need to do anything. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got duplicate CREATE for %s. MQ is busy, not queueing another ACK\n",
+ GCC_2s (cc));
+ }
}
@@ -696,67 +698,67 @@ 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);
+ cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
+ if (NULL != cc->task)
{
- /* 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);
- cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY;
- if (NULL != cc->task)
- {
- GNUNET_SCHEDULER_cancel(cc->task);
- cc->task = NULL;
- }
- return;
+ GNUNET_SCHEDULER_cancel (cc->task);
+ cc->task = NULL;
}
+ return;
+ }
- 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),
- cc->state);
+ 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),
+ cc->state);
switch (cc->state)
+ {
+ case CADET_CONNECTION_NEW:
+ /* Transmit immediately */
+ 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. */
+ GNUNET_assert (0);
+ break;
+
+ case CADET_CONNECTION_SENT:
+ /* Retry a bit later... */
+ 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);
+ break;
+
+ case CADET_CONNECTION_READY:
+ if ((NULL == cc->keepalive_qe) && (GNUNET_YES == cc->mqm_ready) &&
+ (NULL == cc->task))
{
- case CADET_CONNECTION_NEW:
- /* Transmit immediately */
- 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. */
- GNUNET_assert(0);
- break;
-
- case CADET_CONNECTION_SENT:
- /* Retry a bit later... */
- 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();
+ 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_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))
- {
- 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);
- }
- break;
+ GNUNET_SCHEDULER_add_delayed (keepalive_period, &send_keepalive, cc);
}
+ break;
+ }
}
@@ -775,44 +777,44 @@ manage_first_hop_mq(void *cls, int available)
* @return handle to the connection
*/
static struct CadetConnection *
-connection_create(struct CadetPeer *destination,
- struct CadetPeerPath *path,
- unsigned int off,
- struct CadetTConnection *ct,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- enum CadetConnectionState init_state,
- GCC_ReadyCallback ready_cb,
- void *ready_cb_cls)
+connection_create (struct CadetPeer *destination,
+ struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetTConnection *ct,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ enum CadetConnectionState init_state,
+ GCC_ReadyCallback ready_cb,
+ void *ready_cb_cls)
{
struct CadetConnection *cc;
struct CadetPeer *first_hop;
- cc = GNUNET_new(struct CadetConnection);
+ cc = GNUNET_new (struct CadetConnection);
cc->state = init_state;
cc->ct = ct;
cc->cid = *cid;
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_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));
cc->ready_cb = ready_cb;
cc->ready_cb_cls = ready_cb_cls;
cc->path = path;
cc->off = off;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating %s using path %s (offset: %u)\n",
- GCC_2s(cc),
- GCPP_2s(path),
- off);
- GCPP_add_connection(path, off, cc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating %s using path %s (offset: %u)\n",
+ GCC_2s (cc),
+ GCPP_2s (path),
+ off);
+ 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);
+ 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;
}
@@ -831,64 +833,64 @@ connection_create(struct CadetPeer *destination,
* a connection that takes precedence on @a path
*/
struct CadetConnection *
-GCC_create_inbound(struct CadetPeer *destination,
- struct CadetPeerPath *path,
- struct CadetTConnection *ct,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- GCC_ReadyCallback ready_cb,
- void *ready_cb_cls)
+GCC_create_inbound (struct CadetPeer *destination,
+ struct CadetPeerPath *path,
+ struct CadetTConnection *ct,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ GCC_ReadyCallback ready_cb,
+ void *ready_cb_cls)
{
struct CadetConnection *cc;
unsigned int off;
- off = GCPP_find_peer(path, destination);
- GNUNET_assert(UINT_MAX != off);
- cc = GCPP_get_connection(path, destination, off);
+ off = GCPP_find_peer (path, destination);
+ GNUNET_assert (UINT_MAX != off);
+ cc = GCPP_get_connection (path, destination, off);
if (NULL != cc)
+ {
+ int cmp;
+
+ cmp = GNUNET_memcmp (cid, &cc->cid);
+ if (0 == cmp)
{
- int cmp;
-
- cmp = GNUNET_memcmp(cid, &cc->cid);
- if (0 == cmp)
- {
- /* Two peers picked the SAME random connection identifier at the
- same time for the same path? Must be malicious. Drop
- connection (existing and inbound), even if it is the only
- one. */
- GNUNET_break_op(0);
- GCT_connection_lost(cc->ct);
- GCC_destroy_without_tunnel(cc);
- return NULL;
- }
- if (0 < cmp)
- {
- /* drop existing */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got two connections on %s, dropping my existing %s\n",
- GCPP_2s(path),
- GCC_2s(cc));
- GCT_connection_lost(cc->ct);
- GCC_destroy_without_tunnel(cc);
- }
- else
- {
- /* keep existing */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got two connections on %s, keeping my existing %s\n",
- GCPP_2s(path),
- GCC_2s(cc));
- return NULL;
- }
+ /* Two peers picked the SAME random connection identifier at the
+ same time for the same path? Must be malicious. Drop
+ connection (existing and inbound), even if it is the only
+ one. */
+ GNUNET_break_op (0);
+ GCT_connection_lost (cc->ct);
+ GCC_destroy_without_tunnel (cc);
+ return NULL;
}
-
- return connection_create(destination,
- path,
- off,
- ct,
- cid,
- CADET_CONNECTION_CREATE_RECEIVED,
- ready_cb,
- ready_cb_cls);
+ if (0 < cmp)
+ {
+ /* drop existing */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got two connections on %s, dropping my existing %s\n",
+ GCPP_2s (path),
+ GCC_2s (cc));
+ GCT_connection_lost (cc->ct);
+ GCC_destroy_without_tunnel (cc);
+ }
+ else
+ {
+ /* keep existing */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got two connections on %s, keeping my existing %s\n",
+ GCPP_2s (path),
+ GCC_2s (cc));
+ return NULL;
+ }
+ }
+
+ return connection_create (destination,
+ path,
+ off,
+ ct,
+ cid,
+ CADET_CONNECTION_CREATE_RECEIVED,
+ ready_cb,
+ ready_cb_cls);
}
@@ -905,24 +907,24 @@ GCC_create_inbound(struct CadetPeer *destination,
* @return handle to the connection
*/
struct CadetConnection *
-GCC_create(struct CadetPeer *destination,
- struct CadetPeerPath *path,
- unsigned int off,
- struct CadetTConnection *ct,
- GCC_ReadyCallback ready_cb,
- void *ready_cb_cls)
+GCC_create (struct CadetPeer *destination,
+ struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetTConnection *ct,
+ GCC_ReadyCallback ready_cb,
+ void *ready_cb_cls)
{
struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof(cid));
- return connection_create(destination,
- path,
- off,
- ct,
- &cid,
- CADET_CONNECTION_NEW,
- ready_cb,
- ready_cb_cls);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &cid, sizeof(cid));
+ return connection_create (destination,
+ path,
+ off,
+ ct,
+ &cid,
+ CADET_CONNECTION_NEW,
+ ready_cb,
+ ready_cb_cls);
}
@@ -937,21 +939,21 @@ 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",
- GCC_2s(cc));
- GNUNET_assert(GNUNET_YES == cc->mqm_ready);
- GNUNET_assert(CADET_CONNECTION_READY == cc->state);
- cc->metrics.last_use = GNUNET_TIME_absolute_get();
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling message for transmission on %s\n",
+ GCC_2s (cc));
+ GNUNET_assert (GNUNET_YES == cc->mqm_ready);
+ GNUNET_assert (CADET_CONNECTION_READY == cc->state);
+ cc->metrics.last_use = GNUNET_TIME_absolute_get ();
cc->mqm_ready = GNUNET_NO;
if (NULL != cc->task)
- {
- GNUNET_SCHEDULER_cancel(cc->task);
- cc->task = NULL;
- }
- GCP_send(cc->mq_man, env);
+ {
+ GNUNET_SCHEDULER_cancel (cc->task);
+ cc->task = NULL;
+ }
+ GCP_send (cc->mq_man, env);
}
@@ -963,7 +965,7 @@ GCC_transmit(struct CadetConnection *cc, struct GNUNET_MQ_Envelope *env)
* @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;
@@ -977,7 +979,7 @@ GCC_get_path(struct CadetConnection *cc, unsigned int *off)
* @return unique number of the connection
*/
const struct GNUNET_CADET_ConnectionTunnelIdentifier *
-GCC_get_id(struct CadetConnection *cc)
+GCC_get_id (struct CadetConnection *cc)
{
return &cc->cid;
}
@@ -989,7 +991,7 @@ GCC_get_id(struct CadetConnection *cc)
* @param cc Connection.
*/
const char *
-GCC_2s(const struct CadetConnection *cc)
+GCC_2s (const struct CadetConnection *cc)
{
static char buf[128];
@@ -997,24 +999,24 @@ GCC_2s(const struct CadetConnection *cc)
return "Connection(NULL)";
if (NULL != cc->ct)
- {
- GNUNET_snprintf(buf,
- sizeof(buf),
- "Connection %s (%s)",
- GNUNET_sh2s(&cc->cid.connection_of_tunnel),
- GCT_2s(cc->ct->t));
- return buf;
- }
- GNUNET_snprintf(buf,
- sizeof(buf),
- "Connection %s",
- GNUNET_sh2s(&cc->cid.connection_of_tunnel));
+ {
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "Connection %s (%s)",
+ GNUNET_sh2s (&cc->cid.connection_of_tunnel),
+ GCT_2s (cc->ct->t));
+ return buf;
+ }
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "Connection %s",
+ GNUNET_sh2s (&cc->cid.connection_of_tunnel));
return buf;
}
#define LOG2(level, ...) \
- GNUNET_log_from_nocheck(level, "cadet-con", __VA_ARGS__)
+ GNUNET_log_from_nocheck (level, "cadet-con", __VA_ARGS__)
/**
@@ -1024,30 +1026,30 @@ 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__);
+ do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
+ "cadet-con",
+ __FILE__,
+ __FUNCTION__,
+ __LINE__);
if (0 == do_log)
return;
if (NULL == cc)
- {
- LOG2(level, "Connection (NULL)\n");
- return;
- }
- LOG2(level,
- "%s to %s via path %s in state %d is %s\n",
- GCC_2s(cc),
- GCP_2s(cc->destination),
- GCPP_2s(cc->path),
- cc->state,
- (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
+ {
+ LOG2 (level, "Connection (NULL)\n");
+ return;
+ }
+ LOG2 (level,
+ "%s to %s via path %s in state %d is %s\n",
+ GCC_2s (cc),
+ GCP_2s (cc->destination),
+ GCPP_2s (cc->path),
+ cc->state,
+ (GNUNET_YES == cc->mqm_ready) ? "ready" : "busy");
#endif
}
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index 47b654cbb..b05c3b72c 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -57,7 +57,7 @@ typedef void
* @param cc connection to destroy
*/
void
-GCC_destroy_without_core(struct CadetConnection *cc);
+GCC_destroy_without_core (struct CadetConnection *cc);
/**
@@ -68,7 +68,7 @@ GCC_destroy_without_core(struct CadetConnection *cc);
* @param cc connection to destroy
*/
void
-GCC_destroy_without_tunnel(struct CadetConnection *cc);
+GCC_destroy_without_tunnel (struct CadetConnection *cc);
/**
@@ -78,7 +78,7 @@ GCC_destroy_without_tunnel(struct CadetConnection *cc);
* @return NULL if connection was not found
*/
struct CadetConnection *
-GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_lookup (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
/**
@@ -94,12 +94,12 @@ GCC_lookup(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
* @return handle to the connection
*/
struct CadetConnection *
-GCC_create(struct CadetPeer *destination,
- struct CadetPeerPath *path,
- unsigned int off,
- struct CadetTConnection *ct,
- GCC_ReadyCallback ready_cb,
- void *ready_cb_cls);
+GCC_create (struct CadetPeer *destination,
+ struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetTConnection *ct,
+ GCC_ReadyCallback ready_cb,
+ void *ready_cb_cls);
/**
@@ -116,12 +116,12 @@ GCC_create(struct CadetPeer *destination,
* a connection that takes precedence on @a path
*/
struct CadetConnection *
-GCC_create_inbound(struct CadetPeer *destination,
- struct CadetPeerPath *path,
- struct CadetTConnection *ct,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- GCC_ReadyCallback ready_cb,
- void *ready_cb_cls);
+GCC_create_inbound (struct CadetPeer *destination,
+ struct CadetPeerPath *path,
+ struct CadetTConnection *ct,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ GCC_ReadyCallback ready_cb,
+ void *ready_cb_cls);
/**
@@ -137,8 +137,8 @@ GCC_create_inbound(struct CadetPeer *destination,
* connection identifier of this connection...
*/
void
-GCC_transmit(struct CadetConnection *cc,
- struct GNUNET_MQ_Envelope *env);
+GCC_transmit (struct CadetConnection *cc,
+ struct GNUNET_MQ_Envelope *env);
/**
@@ -147,7 +147,7 @@ GCC_transmit(struct CadetConnection *cc,
* @param cc the connection that got the ACK.
*/
void
-GCC_handle_connection_create_ack(struct CadetConnection *cc);
+GCC_handle_connection_create_ack (struct CadetConnection *cc);
/**
@@ -158,7 +158,7 @@ GCC_handle_connection_create_ack(struct CadetConnection *cc);
* @param cc connection that got the duplicate CREATE
*/
void
-GCC_handle_duplicate_create(struct CadetConnection *cc);
+GCC_handle_duplicate_create (struct CadetConnection *cc);
/**
@@ -168,8 +168,8 @@ GCC_handle_duplicate_create(struct CadetConnection *cc);
* @param msg the key exchange message
*/
void
-GCC_handle_kx(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
+GCC_handle_kx (struct CadetConnection *cc,
+ const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
/**
@@ -179,14 +179,16 @@ GCC_handle_kx(struct CadetConnection *cc,
* @param msg the key exchange message
*/
void
-GCC_handle_kx_auth(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
+GCC_handle_kx_auth (struct CadetConnection *cc,
+ const struct
+ GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg);
/**
* Performance metrics for a connection.
*/
-struct CadetConnectionMetrics {
+struct CadetConnectionMetrics
+{
/**
* Our current best estimate of the latency, based on a weighted
* average of at least @a latency_datapoints values.
@@ -229,7 +231,7 @@ struct CadetConnectionMetrics {
* @return the metrics
*/
const struct CadetConnectionMetrics *
-GCC_get_metrics(struct CadetConnection *cc);
+GCC_get_metrics (struct CadetConnection *cc);
/**
@@ -239,8 +241,8 @@ GCC_get_metrics(struct CadetConnection *cc);
* @param msg the encrypted message to decrypt
*/
void
-GCC_handle_encrypted(struct CadetConnection *cc,
- const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
+GCC_handle_encrypted (struct CadetConnection *cc,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
/**
@@ -250,7 +252,7 @@ GCC_handle_encrypted(struct CadetConnection *cc,
* @param cid connection identifier where we expect an ACK
*/
void
-GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_ack_expected (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
/**
@@ -262,7 +264,7 @@ GCC_ack_expected(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
* may have gotten back to us via a different connection).
*/
void
-GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
+GCC_ack_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
/**
@@ -274,8 +276,8 @@ GCC_ack_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid);
* @param latency the observed latency
*/
void
-GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
- struct GNUNET_TIME_Relative latency);
+GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
+ struct GNUNET_TIME_Relative latency);
/**
@@ -285,7 +287,7 @@ GCC_latency_observed(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
* @return corresponding entry in the tunnel's connection list
*/
struct CadetTConnection *
-GCC_get_ct(struct CadetConnection *cc);
+GCC_get_ct (struct CadetConnection *cc);
/**
@@ -296,8 +298,8 @@ GCC_get_ct(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);
/**
@@ -307,7 +309,7 @@ GCC_get_path(struct CadetConnection *cc,
* @return unique number of the connection
*/
const struct GNUNET_CADET_ConnectionTunnelIdentifier *
-GCC_get_id(struct CadetConnection *cc);
+GCC_get_id (struct CadetConnection *cc);
/**
@@ -316,7 +318,7 @@ GCC_get_id(struct CadetConnection *cc);
* @param cc Connection.
*/
const char *
-GCC_2s(const struct CadetConnection *cc);
+GCC_2s (const struct CadetConnection *cc);
/**
@@ -326,8 +328,8 @@ 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);
#endif
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c
index a08c80aae..7d1791f3c 100644
--- a/src/cadet/gnunet-service-cadet_core.c
+++ b/src/cadet/gnunet-service-cadet_core.c
@@ -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.
@@ -52,7 +52,8 @@ struct RouteDirection;
* routes that have the current maximum of messages in the buffer (in
* case we have to purge).
*/
-struct Rung {
+struct Rung
+{
/**
* Rung of RouteDirections with one more buffer entry each.
*/
@@ -89,7 +90,8 @@ struct Rung {
/**
* Information we keep per direction for a route.
*/
-struct RouteDirection {
+struct RouteDirection
+{
/**
* DLL of other route directions within the same `struct Rung`.
*/
@@ -145,7 +147,8 @@ struct RouteDirection {
* the complete `struct CadetPath` that is formed by the individual
* routes.
*/
-struct CadetRoute {
+struct CadetRoute
+{
/**
* Information about the next hop on this route.
*/
@@ -231,10 +234,10 @@ static struct GNUNET_SCHEDULER_Task *timeout_task;
* @param cid hash generated from the connection identifier
*/
static struct CadetRoute *
-get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
+get_route (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
{
- return GNUNET_CONTAINER_multishortmap_get(routes,
- &cid->connection_of_tunnel);
+ return GNUNET_CONTAINER_multishortmap_get (routes,
+ &cid->connection_of_tunnel);
}
@@ -244,22 +247,22 @@ get_route(const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid)
* @param dir direction to lower in rung.
*/
static void
-lower_rung(struct RouteDirection *dir)
+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);
+ 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_assert(NULL != prev);
- GNUNET_CONTAINER_DLL_insert(prev->rd_head, prev->rd_tail, dir);
+ {
+ 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_assert (NULL != prev);
+ GNUNET_CONTAINER_DLL_insert (prev->rd_head, prev->rd_tail, dir);
dir->rung = prev;
}
@@ -272,13 +275,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_MQ_discard (env);
+ lower_rung (dir);
+ GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
}
@@ -286,24 +289,24 @@ discard_buffer(struct RouteDirection *dir, struct GNUNET_MQ_Envelope *env)
* Discard all messages from the highest rung, to make space.
*/
static void
-discard_all_from_rung_tail()
+discard_all_from_rung_tail ()
{
struct Rung *tail = rung_tail;
struct RouteDirection *dir;
while (NULL != (dir = tail->rd_head))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Queue full due new message %s on connection %s, dropping old message\n",
- GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel));
- GNUNET_STATISTICS_update(stats,
- "# messages dropped due to full buffer",
- 1,
- GNUNET_NO);
- discard_buffer(dir, dir->env_head);
- }
- GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, tail);
- GNUNET_free(tail);
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue full due new message %s on connection %s, dropping old message\n",
+ GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel));
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped due to full buffer",
+ 1,
+ GNUNET_NO);
+ discard_buffer (dir, dir->env_head);
+ }
+ GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, tail);
+ GNUNET_free (tail);
}
@@ -317,10 +320,10 @@ discard_all_from_rung_tail()
* @param msg the message to forward
*/
static void
-route_message(struct CadetPeer *prev,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- const struct GNUNET_MessageHeader *msg,
- const enum GNUNET_MQ_PriorityPreferences priority)
+route_message (struct CadetPeer *prev,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ const struct GNUNET_MessageHeader *msg,
+ const enum GNUNET_MQ_PriorityPreferences priority)
{
struct CadetRoute *route;
struct RouteDirection *dir;
@@ -328,133 +331,133 @@ route_message(struct CadetPeer *prev,
struct Rung *nxt;
struct GNUNET_MQ_Envelope *env;
- route = get_route(cid);
+ route = get_route (cid);
if (NULL == route)
+ {
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_CADET_ConnectionBrokenMessage *bm;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to route message of type %u from %s on connection %s: no route\n",
+ ntohs (msg->type),
+ GCP_2s (prev),
+ GNUNET_sh2s (&cid->connection_of_tunnel));
+ switch (ntohs (msg->type))
{
- struct GNUNET_MQ_Envelope *env;
- struct GNUNET_CADET_ConnectionBrokenMessage *bm;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Failed to route message of type %u from %s on connection %s: no route\n",
- ntohs(msg->type),
- GCP_2s(prev),
- GNUNET_sh2s(&cid->connection_of_tunnel));
- switch (ntohs(msg->type))
- {
- case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
- case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
- /* No need to respond to these! */
- return;
- }
- env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
- bm->cid = *cid;
- bm->peer1 = my_full_id;
- GCP_send_ooo(prev, env);
+ case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY:
+ case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN:
+ /* No need to respond to these! */
return;
}
- route->last_use = GNUNET_TIME_absolute_get();
- GNUNET_CONTAINER_heap_update_cost(route->hn, route->last_use.abs_value_us);
+ env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
+ bm->cid = *cid;
+ bm->peer1 = my_full_id;
+ 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);
dir = (prev == route->prev.hop) ? &route->next : &route->prev;
if (GNUNET_YES == dir->is_ready)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Routing message of type %u from %s to %s on connection %s\n",
- ntohs(msg->type),
- GCP_2s(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));
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing message of type %u from %s to %s on connection %s\n",
+ ntohs (msg->type),
+ GCP_2s (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));
+ return;
+ }
/* 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);
+ (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;
- env = GNUNET_MQ_env_next(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))))
{
- const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg(env);
-
- 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");
- GNUNET_STATISTICS_update(stats,
- "# messages dropped due to duplicate in buffer",
- 1,
- GNUNET_NO);
- return;
- }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received duplicate of message already in buffer, dropping\n");
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped due to duplicate in buffer",
+ 1,
+ GNUNET_NO);
+ return;
}
+ }
rung = dir->rung;
if (cur_buffers == max_buffers)
+ {
+ /* Need to make room. */
+ if (NULL != rung->next)
{
- /* Need to make room. */
- if (NULL != rung->next)
- {
- /* Easy case, drop messages from route directions in highest rung */
- discard_all_from_rung_tail();
- }
- else
- {
- /* We are in the highest rung, drop our own! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Queue full due new message %s on connection %s, dropping old message\n",
- GNUNET_sh2s(&dir->my_route->cid.connection_of_tunnel));
- GNUNET_STATISTICS_update(stats,
- "# messages dropped due to full buffer",
- 1,
- GNUNET_NO);
- discard_buffer(dir, dir->env_head);
- rung = dir->rung;
- }
+ /* Easy case, drop messages from route directions in highest rung */
+ discard_all_from_rung_tail ();
}
+ else
+ {
+ /* We are in the highest rung, drop our own! */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Queue full due new message %s on connection %s, dropping old message\n",
+ GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel));
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped due to full buffer",
+ 1,
+ GNUNET_NO);
+ 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))
- {
- nxt = GNUNET_new(struct Rung);
- nxt->rung_off = rung->rung_off + 1;
- GNUNET_CONTAINER_DLL_insert_after(rung_head, rung_tail, rung, nxt);
- }
+ {
+ nxt = GNUNET_new (struct Rung);
+ nxt->rung_off = rung->rung_off + 1;
+ 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 */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Queueing new message of type %u from %s to %s on connection %s\n",
- ntohs(msg->type),
- GCP_2s(prev),
- GNUNET_i2s(GCP_get_id(dir->hop)),
- GNUNET_sh2s(&cid->connection_of_tunnel));
- env = GNUNET_MQ_msg_copy(msg);
- GNUNET_MQ_env_set_options(env, priority);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Queueing new message of type %u from %s to %s on connection %s\n",
+ ntohs (msg->type),
+ GCP_2s (prev),
+ GNUNET_i2s (GCP_get_id (dir->hop)),
+ GNUNET_sh2s (&cid->connection_of_tunnel));
+ env = GNUNET_MQ_msg_copy (msg);
+ 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);
+ (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);
+ 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))
- {
- GNUNET_CONTAINER_DLL_remove(rung_head, rung_tail, rung);
- GNUNET_free(rung);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (rung_head, rung_tail, rung);
+ GNUNET_free (rung);
+ }
}
@@ -467,16 +470,16 @@ route_message(struct CadetPeer *prev,
* @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
*/
static int
-check_connection_create(void *cls,
- const struct GNUNET_CADET_ConnectionCreateMessage *msg)
+check_connection_create (void *cls,
+ const struct GNUNET_CADET_ConnectionCreateMessage *msg)
{
- uint16_t size = ntohs(msg->header.size) - sizeof(*msg);
+ uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
if (0 != (size % sizeof(struct GNUNET_PeerIdentity)))
- {
- GNUNET_break_op(0);
- return GNUNET_NO;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -487,24 +490,24 @@ check_connection_create(void *cls,
* @param dir direction to destroy (do NOT free memory of 'dir' itself)
*/
static void
-destroy_direction(struct RouteDirection *dir)
+destroy_direction (struct RouteDirection *dir)
{
struct GNUNET_MQ_Envelope *env;
while (NULL != (env = dir->env_head))
- {
- GNUNET_STATISTICS_update(stats,
- "# messages dropped due to route destruction",
- 1,
- GNUNET_NO);
- discard_buffer(dir, env);
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped due to route destruction",
+ 1,
+ GNUNET_NO);
+ discard_buffer (dir, env);
+ }
if (NULL != dir->mqm)
- {
- GCP_request_mq_cancel(dir->mqm, NULL);
- dir->mqm = NULL;
- }
- GNUNET_CONTAINER_DLL_remove(rung_head->rd_head, rung_head->rd_tail, dir);
+ {
+ GCP_request_mq_cancel (dir->mqm, NULL);
+ dir->mqm = NULL;
+ }
+ GNUNET_CONTAINER_DLL_remove (rung_head->rd_head, rung_head->rd_tail, dir);
}
@@ -514,26 +517,26 @@ destroy_direction(struct RouteDirection *dir)
* @param route route to destroy
*/
static void
-destroy_route(struct CadetRoute *route)
+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_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(
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying route from %s to %s of connection %s\n",
+ 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_STATISTICS_set(stats,
- "# routes",
- GNUNET_CONTAINER_multishortmap_size(routes),
- GNUNET_NO);
- destroy_direction(&route->prev);
- destroy_direction(&route->next);
- GNUNET_free(route);
+ GNUNET_CONTAINER_multishortmap_remove (routes,
+ &route->cid.connection_of_tunnel,
+ route));
+ GNUNET_STATISTICS_set (stats,
+ "# routes",
+ GNUNET_CONTAINER_multishortmap_size (routes),
+ GNUNET_NO);
+ destroy_direction (&route->prev);
+ destroy_direction (&route->next);
+ GNUNET_free (route);
}
@@ -546,30 +549,30 @@ destroy_route(struct CadetRoute *route)
* @param peer2 another one of the peers where a link is broken
*/
static void
-send_broken(struct RouteDirection *target,
- const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
- const struct GNUNET_PeerIdentity *peer1,
- const struct GNUNET_PeerIdentity *peer2)
+send_broken (struct RouteDirection *target,
+ const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ const struct GNUNET_PeerIdentity *peer1,
+ const struct GNUNET_PeerIdentity *peer2)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_ConnectionBrokenMessage *bm;
if (NULL == target->mqm)
return; /* Can't send notification, connection is down! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Notifying %s about BROKEN route at %s-%s of connection %s\n",
- GCP_2s(target->hop),
- GNUNET_i2s(peer1),
- GNUNET_i2s2(peer2),
- GNUNET_sh2s(&cid->connection_of_tunnel));
-
- env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying %s about BROKEN route at %s-%s of connection %s\n",
+ GCP_2s (target->hop),
+ GNUNET_i2s (peer1),
+ GNUNET_i2s2 (peer2),
+ GNUNET_sh2s (&cid->connection_of_tunnel));
+
+ 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;
}
@@ -582,31 +585,31 @@ send_broken(struct RouteDirection *target,
* @param cls NULL
*/
static void
-timeout_cb(void *cls)
+timeout_cb (void *cls)
{
struct CadetRoute *r;
struct GNUNET_TIME_Relative linger;
struct GNUNET_TIME_Absolute exp;
timeout_task = NULL;
- linger = GNUNET_TIME_relative_multiply(keepalive_period, 3);
- while (NULL != (r = GNUNET_CONTAINER_heap_peek(route_heap)))
+ 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);
+ if (0 != GNUNET_TIME_absolute_get_remaining (exp).rel_value_us)
{
- 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);
- 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);
- destroy_route(r);
+ /* Route not yet timed out, wait until it does. */
+ 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);
+ destroy_route (r);
+ }
/* No more routes left, so no need for a #timeout_task */
}
@@ -624,32 +627,32 @@ 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;
struct RouteDirection *odir;
if (GNUNET_YES == ready)
+ {
+ struct GNUNET_MQ_Envelope *env;
+
+ dir->is_ready = GNUNET_YES;
+ if (NULL != (env = dir->env_head))
{
- struct GNUNET_MQ_Envelope *env;
-
- dir->is_ready = GNUNET_YES;
- if (NULL != (env = dir->env_head))
- {
- GNUNET_MQ_dll_remove(&dir->env_head, &dir->env_tail, env);
- cur_buffers--;
- GNUNET_STATISTICS_set(stats, "# buffer use", cur_buffers, GNUNET_NO);
- lower_rung(dir);
- dir->is_ready = GNUNET_NO;
- GCP_send(dir->mqm, env);
- }
- return;
+ GNUNET_MQ_dll_remove (&dir->env_head, &dir->env_tail, env);
+ cur_buffers--;
+ GNUNET_STATISTICS_set (stats, "# buffer use", cur_buffers, GNUNET_NO);
+ lower_rung (dir);
+ dir->is_ready = GNUNET_NO;
+ 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);
- destroy_route(route);
+ 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);
}
@@ -661,16 +664,16 @@ dir_ready_cb(void *cls, int ready)
* @param hop next hop on in the @a dir
*/
static void
-dir_init(struct RouteDirection *dir,
- struct CadetRoute *route,
- struct CadetPeer *hop)
+dir_init (struct RouteDirection *dir,
+ struct CadetRoute *route,
+ struct CadetPeer *hop)
{
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);
+ GNUNET_assert (GNUNET_YES == dir->is_ready);
}
@@ -685,7 +688,7 @@ dir_init(struct RouteDirection *dir,
* or NULL.
*/
static void
-send_broken_without_mqm(
+send_broken_without_mqm (
struct CadetPeer *target,
const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
const struct GNUNET_PeerIdentity *failure_at)
@@ -693,12 +696,12 @@ send_broken_without_mqm(
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);
}
@@ -709,193 +712,194 @@ send_broken_without_mqm(
* @param msg Message itself.
*/
static void
-handle_connection_create(
+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 *) &msg[1];
struct CadetRoute *route;
- uint16_t size = ntohs(msg->header.size) - sizeof(*msg);
+ uint16_t size = ntohs (msg->header.size) - sizeof(*msg);
unsigned int path_length;
unsigned int off;
path_length = size / sizeof(struct GNUNET_PeerIdentity);
if (0 == path_length)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping CADET_CONNECTION_CREATE with empty path\n");
- GNUNET_break_op(0);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n",
- GCP_2s(sender),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel),
- path_length);
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping CADET_CONNECTION_CREATE with empty path\n");
+ GNUNET_break_op (0);
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n",
+ GCP_2s (sender),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel),
+ path_length);
/* Check for loops */
{
struct GNUNET_CONTAINER_MultiPeerMap *map;
- map = GNUNET_CONTAINER_multipeermap_create(path_length * 2, GNUNET_YES);
- GNUNET_assert(NULL != map);
+ map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, GNUNET_YES);
+ GNUNET_assert (NULL != map);
for (unsigned int i = 0; i < path_length; i++)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
+ GNUNET_i2s (&pids[i]),
+ i);
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (
+ map,
+ &pids[i],
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "CADET_CONNECTION_CREATE has peer %s at offset %u\n",
- GNUNET_i2s(&pids[i]),
- i);
- if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put(
- map,
- &pids[i],
- NULL,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- /* bogus request */
- GNUNET_CONTAINER_multipeermap_destroy(map);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
- GNUNET_break_op(0);
- return;
- }
+ /* bogus request */
+ GNUNET_CONTAINER_multipeermap_destroy (map);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping CADET_CONNECTION_CREATE with cyclic path\n");
+ GNUNET_break_op (0);
+ return;
}
- GNUNET_CONTAINER_multipeermap_destroy(map);
+ }
+ GNUNET_CONTAINER_multipeermap_destroy (map);
}
/* Initiator is at offset 0, find us */
for (off = 1; off < path_length; off++)
- if (0 == GNUNET_memcmp(&my_full_id, &pids[off]))
+ if (0 == GNUNET_memcmp (&my_full_id, &pids[off]))
break;
if (off == path_length)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping CADET_CONNECTION_CREATE without us in the path\n");
- GNUNET_break_op(0);
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping CADET_CONNECTION_CREATE without us in the path\n");
+ GNUNET_break_op (0);
+ return;
+ }
/* Check previous hop */
- if (sender != GCP_get(&pids[off - 1], GNUNET_NO))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
- GNUNET_break_op(0);
- return;
- }
- if (NULL != (route = get_route(&msg->cid)))
- {
- /* Duplicate CREATE, pass it on, previous one might have been lost! */
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- route_message(sender,
- &msg->cid,
- &msg->header,
- GNUNET_MQ_PRIO_CRITICAL_CONTROL |
- GNUNET_MQ_PREF_LOW_LATENCY);
- return;
- }
+ if (sender != GCP_get (&pids[off - 1], GNUNET_NO))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n");
+ GNUNET_break_op (0);
+ return;
+ }
+ if (NULL != (route = get_route (&msg->cid)))
+ {
+ /* Duplicate CREATE, pass it on, previous one might have been lost! */
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ route_message (sender,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL
+ | GNUNET_MQ_PREF_LOW_LATENCY);
+ return;
+ }
if (off == path_length - 1)
+ {
+ /* We are the destination, create connection */
+ struct CadetConnection *cc;
+ struct CadetPeerPath *path;
+ struct CadetPeer *origin;
+
+ cc = GCC_lookup (&msg->cid);
+ if (NULL != cc)
{
- /* We are the destination, create connection */
- struct CadetConnection *cc;
- struct CadetPeerPath *path;
- struct CadetPeer *origin;
-
- cc = GCC_lookup(&msg->cid);
- if (NULL != cc)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- GCC_handle_duplicate_create(cc);
- return;
- }
-
- 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);
- if (GNUNET_OK !=
- GCT_add_inbound_connection(GCP_get_tunnel(origin, GNUNET_YES),
- &msg->cid,
- path))
- {
- /* Send back BROKEN: duplicate connection on the same path,
- we will use the other one. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n",
- GCP_2s(sender),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel),
- GCPP_2s(path));
- 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)))
- {
- /* unworkable, send back BROKEN notification */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n",
- GCP_2s(sender),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel),
- GNUNET_i2s(&pids[off + 1]),
- off + 1);
- send_broken_without_mqm(sender, &msg->cid, &pids[off + 1]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received duplicate CADET_CONNECTION_CREATE message on connection %s\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ GCC_handle_duplicate_create (cc);
return;
}
- if (max_routes <= GNUNET_CONTAINER_multishortmap_size(routes))
+
+ 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);
+ if (GNUNET_OK !=
+ GCT_add_inbound_connection (GCP_get_tunnel (origin, GNUNET_YES),
+ &msg->cid,
+ path))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "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 back BROKEN: duplicate connection on the same path,
+ we will use the other one. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CADET_CONNECTION_CREATE from %s for %s, but %s already has a connection. Sending BROKEN\n",
+ GCP_2s (sender),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel),
+ GCPP_2s (path));
+ 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)))
+ {
+ /* unworkable, send back BROKEN notification */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is down. Sending BROKEN\n",
+ GCP_2s (sender),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel),
+ GNUNET_i2s (&pids[off + 1]),
+ off + 1);
+ send_broken_without_mqm (sender, &msg->cid, &pids[off + 1]);
+ return;
+ }
+ if (max_routes <= GNUNET_CONTAINER_multishortmap_size (routes))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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]);
+ return;
+ }
/* Workable route, create routing entry */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n",
- GCP_2s(sender),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel),
- GNUNET_i2s(&pids[off + 1]),
- off + 1);
- route = GNUNET_new(struct CadetRoute);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CADET_CONNECTION_CREATE from %s for %s. Next hop %s:%u is up. Creating route\n",
+ GCP_2s (sender),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel),
+ GNUNET_i2s (&pids[off + 1]),
+ off + 1);
+ 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);
- GNUNET_assert(GNUNET_OK ==
- 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),
- GNUNET_NO);
- route->hn = GNUNET_CONTAINER_heap_insert(route_heap,
- route,
- route->last_use.abs_value_us);
+ route->last_use = GNUNET_TIME_absolute_get ();
+ 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_STATISTICS_set (stats,
+ "# routes",
+ GNUNET_CONTAINER_multishortmap_size (routes),
+ GNUNET_NO);
+ route->hn = GNUNET_CONTAINER_heap_insert (route_heap,
+ 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);
+ 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_PREF_LOW_LATENCY);
+ route_message (sender,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
}
@@ -906,7 +910,7 @@ handle_connection_create(
* @param msg Message itself.
*/
static void
-handle_connection_create_ack(
+handle_connection_create_ack (
void *cls,
const struct GNUNET_CADET_ConnectionCreateAckMessage *msg)
{
@@ -914,31 +918,31 @@ handle_connection_create_ack(
struct CadetConnection *cc;
/* First, check if ACK belongs to a connection that ends here. */
- cc = GCC_lookup(&msg->cid);
+ cc = GCC_lookup (&msg->cid);
if (NULL != cc)
+ {
+ /* verify ACK came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify ACK came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- if (peer != GCPP_get_peer_at_offset(path, 0))
- {
- /* received ACK from unexpected direction, ignore! */
- GNUNET_break_op(0);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECTION_CREATE_ACK for connection %s.\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- GCC_handle_connection_create_ack(cc);
+ /* received ACK from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CONNECTION_CREATE_ACK for connection %s.\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ GCC_handle_connection_create_ack (cc);
+ 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 | GNUNET_MQ_PREF_LOW_LATENCY);
+ route_message (peer,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
}
@@ -950,7 +954,7 @@ handle_connection_create_ack(
* @deprecated duplicate logic with #handle_destroy(); dedup!
*/
static void
-handle_connection_broken(
+handle_connection_broken (
void *cls,
const struct GNUNET_CADET_ConnectionBrokenMessage *msg)
{
@@ -959,36 +963,36 @@ handle_connection_broken(
struct CadetRoute *route;
/* First, check if message belongs to a connection that ends here. */
- cc = GCC_lookup(&msg->cid);
+ cc = GCC_lookup (&msg->cid);
if (NULL != cc)
+ {
+ /* verify message came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify message came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- if (peer != GCPP_get_peer_at_offset(path, 0))
- {
- /* received message from unexpected direction, ignore! */
- GNUNET_break_op(0);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- GCC_destroy_without_core(cc);
-
- /* FIXME: also destroy the path up to the specified link! */
+ /* received message from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CONNECTION_BROKEN for connection %s. Destroying it.\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ GCC_destroy_without_core (cc);
+
+ /* FIXME: also destroy the path up to the specified link! */
+ return;
+ }
/* We're just an intermediary peer, route the message along its path */
- route_message(peer,
- &msg->cid,
- &msg->header,
- GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
- route = get_route(&msg->cid);
+ route_message (peer,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
+ route = get_route (&msg->cid);
if (NULL != route)
- destroy_route(route);
+ destroy_route (route);
/* FIXME: also destroy paths we MAY have up to the specified link! */
}
@@ -1000,7 +1004,7 @@ handle_connection_broken(
* @param msg Message itself.
*/
static void
-handle_connection_destroy(
+handle_connection_destroy (
void *cls,
const struct GNUNET_CADET_ConnectionDestroyMessage *msg)
{
@@ -1009,38 +1013,38 @@ handle_connection_destroy(
struct CadetRoute *route;
/* First, check if message belongs to a connection that ends here. */
- cc = GCC_lookup(&msg->cid);
+ cc = GCC_lookup (&msg->cid);
if (NULL != cc)
+ {
+ /* verify message came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify message came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- if (peer != GCPP_get_peer_at_offset(path, 0))
- {
- /* received message from unexpected direction, ignore! */
- GNUNET_break_op(0);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
-
- GCC_destroy_without_core(cc);
+ /* received message from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CONNECTION_DESTROY for connection %s. Destroying connection.\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+
+ GCC_destroy_without_core (cc);
+ return;
+ }
/* We're just an intermediary peer, route the message along its path */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECTION_DESTROY for connection %s. Destroying route.\n",
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- route_message(peer,
- &msg->cid,
- &msg->header,
- GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
- route = get_route(&msg->cid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received CONNECTION_DESTROY for connection %s. Destroying route.\n",
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ route_message (peer,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PREF_LOW_LATENCY | GNUNET_MQ_PRIO_CRITICAL_CONTROL);
+ route = get_route (&msg->cid);
if (NULL != route)
- destroy_route(route);
+ destroy_route (route);
}
@@ -1051,41 +1055,41 @@ handle_connection_destroy(
* @param msg Message itself.
*/
static void
-handle_tunnel_kx(void *cls,
- const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
+handle_tunnel_kx (void *cls,
+ const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg)
{
struct CadetPeer *peer = cls;
struct CadetConnection *cc;
/* First, check if message belongs to a connection that ends here. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Routing KX with ephemeral %s on CID %s\n",
- GNUNET_e2s(&msg->ephemeral_key),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing KX with ephemeral %s on CID %s\n",
+ GNUNET_e2s (&msg->ephemeral_key),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
- cc = GCC_lookup(&msg->cid);
+ cc = GCC_lookup (&msg->cid);
if (NULL != cc)
+ {
+ /* verify message came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify message came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- 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);
+ /* received message from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ GCC_handle_kx (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 | GNUNET_MQ_PREF_LOW_LATENCY);
+ route_message (peer,
+ &msg->cid,
+ &msg->header,
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
}
@@ -1096,7 +1100,7 @@ handle_tunnel_kx(void *cls,
* @param msg Message itself.
*/
static void
-handle_tunnel_kx_auth(
+handle_tunnel_kx_auth (
void *cls,
const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg)
{
@@ -1104,28 +1108,28 @@ handle_tunnel_kx_auth(
struct CadetConnection *cc;
/* First, check if message belongs to a connection that ends here. */
- cc = GCC_lookup(&msg->kx.cid);
+ cc = GCC_lookup (&msg->kx.cid);
if (NULL != cc)
+ {
+ /* verify message came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify message came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- 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);
+ /* received message from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ GCC_handle_kx_auth (cc, msg);
+ return;
+ }
/* We're just an intermediary peer, route the message along its path */
- route_message(peer,
- &msg->kx.cid,
- &msg->kx.header,
- GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
+ route_message (peer,
+ &msg->kx.cid,
+ &msg->kx.header,
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL | GNUNET_MQ_PREF_LOW_LATENCY);
}
@@ -1138,8 +1142,8 @@ handle_tunnel_kx_auth(
* @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
*/
static int
-check_tunnel_encrypted(void *cls,
- const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
+check_tunnel_encrypted (void *cls,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
{
return GNUNET_YES;
}
@@ -1152,31 +1156,31 @@ check_tunnel_encrypted(void *cls,
* @param msg Message itself.
*/
static void
-handle_tunnel_encrypted(void *cls,
- const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
+handle_tunnel_encrypted (void *cls,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *msg)
{
struct CadetPeer *peer = cls;
struct CadetConnection *cc;
/* First, check if message belongs to a connection that ends here. */
- cc = GCC_lookup(&msg->cid);
+ cc = GCC_lookup (&msg->cid);
if (NULL != cc)
+ {
+ /* verify message came from the right direction */
+ unsigned int len;
+ struct CadetPeerPath *path = GCC_get_path (cc, &len);
+
+ if (peer != GCPP_get_peer_at_offset (path, 0))
{
- /* verify message came from the right direction */
- unsigned int len;
- struct CadetPeerPath *path = GCC_get_path(cc, &len);
-
- 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);
+ /* received message from unexpected direction, ignore! */
+ GNUNET_break_op (0);
return;
}
+ 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_BEST_EFFORT);
+ route_message (peer, &msg->cid, &msg->header, GNUNET_MQ_PRIO_BEST_EFFORT);
}
@@ -1193,14 +1197,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);
+ return;
+ }
+ GNUNET_break (0 == GNUNET_memcmp (my_identity, &my_full_id));
}
@@ -1211,17 +1215,17 @@ core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
* @param peer peer identity this notification is about
*/
static void *
-core_connect_cb(void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+core_connect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
struct CadetPeer *cp;
- 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);
+ 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);
return cp;
}
@@ -1233,16 +1237,16 @@ core_connect_cb(void *cls,
* @param peer peer identity this notification is about
*/
static void
-core_disconnect_cb(void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *peer_cls)
+core_disconnect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *peer_cls)
{
struct CadetPeer *cp = peer_cls;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "CORE connection to peer %s went down.\n",
- GNUNET_i2s(peer));
- GCP_set_mq(cp, NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "CORE connection to peer %s went down.\n",
+ GNUNET_i2s (peer));
+ GCP_set_mq (cp, NULL);
}
@@ -1252,57 +1256,57 @@ core_disconnect_cb(void *cls,
* @param c Configuration.
*/
void
-GCO_init(const struct GNUNET_CONFIGURATION_Handle *c)
+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))
+ { 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))
+ 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,
- &core_init_cb,
- &core_connect_cb,
- &core_disconnect_cb,
- handlers);
+ 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,
+ &core_init_cb,
+ &core_connect_cb,
+ &core_disconnect_cb,
+ handlers);
}
@@ -1310,23 +1314,23 @@ GCO_init(const struct GNUNET_CONFIGURATION_Handle *c)
* Shut down the CORE subsystem.
*/
void
-GCO_shutdown()
+GCO_shutdown ()
{
if (NULL != core)
- {
- GNUNET_CORE_disconnect(core);
- core = NULL;
- }
- GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(routes));
- GNUNET_CONTAINER_multishortmap_destroy(routes);
+ {
+ GNUNET_CORE_disconnect (core);
+ core = NULL;
+ }
+ GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (routes));
+ GNUNET_CONTAINER_multishortmap_destroy (routes);
routes = NULL;
- GNUNET_CONTAINER_heap_destroy(route_heap);
+ GNUNET_CONTAINER_heap_destroy (route_heap);
route_heap = NULL;
if (NULL != timeout_task)
- {
- GNUNET_SCHEDULER_cancel(timeout_task);
- timeout_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = NULL;
+ }
}
/* end of gnunet-cadet-service_core.c */
diff --git a/src/cadet/gnunet-service-cadet_core.h b/src/cadet/gnunet-service-cadet_core.h
index b049dc2af..3438dcb31 100644
--- a/src/cadet/gnunet-service-cadet_core.h
+++ b/src/cadet/gnunet-service-cadet_core.h
@@ -47,14 +47,14 @@ extern "C"
* @param c Configuration.
*/
void
-GCO_init(const struct GNUNET_CONFIGURATION_Handle *c);
+GCO_init (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Shut down the CORE subsystem.
*/
void
-GCO_shutdown(void);
+GCO_shutdown (void);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c
index c208c7f29..3bb86cae4 100644
--- a/src/cadet/gnunet-service-cadet_dht.c
+++ b/src/cadet/gnunet-service-cadet_dht.c
@@ -40,23 +40,26 @@
* notifications when our HELLO is ready, so this is just the maximum
* we wait for the first notification.
*/
-#define STARTUP_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define STARTUP_DELAY GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MILLISECONDS, 500)
/**
* How long do we wait after we get an updated HELLO before publishing?
* Allows for the HELLO to be updated again quickly, for example in
* case multiple addresses changed and we got a partial update.
*/
-#define CHANGE_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100)
+#define CHANGE_DELAY GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MILLISECONDS, 100)
-#define LOG(level, ...) GNUNET_log_from(level, "cadet-dht", __VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-dht", __VA_ARGS__)
/**
* Handle for DHT searches.
*/
-struct GCD_search_handle {
+struct GCD_search_handle
+{
/**
* DHT_GET handle.
*/
@@ -107,35 +110,35 @@ static struct GNUNET_TIME_Relative announce_delay;
* @param data pointer to the result data
*/
static void
-dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode *key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type,
- size_t size,
- const void *data)
+dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode *key,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
+ enum GNUNET_BLOCK_Type type,
+ size_t size,
+ const void *data)
{
const struct GNUNET_HELLO_Message *hello = data;
struct CadetPeer *peer;
- GCPP_try_path_from_dht(get_path,
- get_path_length,
- put_path,
- put_path_length);
+ GCPP_try_path_from_dht (get_path,
+ get_path_length,
+ put_path,
+ put_path_length);
if ((size >= sizeof(struct GNUNET_HELLO_Message)) &&
- (ntohs(hello->header.size) == size) &&
- (size == GNUNET_HELLO_size(hello)))
- {
- peer = GCP_get(&put_path[0],
- GNUNET_YES);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got HELLO for %s\n",
- GCP_2s(peer));
- GCP_set_hello(peer,
- hello);
- }
+ (ntohs (hello->header.size) == size) &&
+ (size == GNUNET_HELLO_size (hello)))
+ {
+ peer = GCP_get (&put_path[0],
+ GNUNET_YES);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got HELLO for %s\n",
+ GCP_2s (peer));
+ GCP_set_hello (peer,
+ hello);
+ }
}
@@ -145,7 +148,7 @@ dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp,
* @param cls closure
*/
static void
-announce_id(void *cls)
+announce_id (void *cls)
{
struct GNUNET_HashCode phash;
const struct GNUNET_HELLO_Message *hello;
@@ -153,58 +156,58 @@ announce_id(void *cls)
struct GNUNET_TIME_Absolute expiration;
struct GNUNET_TIME_Relative next_put;
- hello = GCH_get_mine();
- size = (NULL != hello) ? GNUNET_HELLO_size(hello) : 0;
+ hello = GCH_get_mine ();
+ size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0;
if (0 == size)
- {
- expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- announce_delay);
- announce_delay = GNUNET_TIME_STD_BACKOFF(announce_delay);
- }
+ {
+ expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ announce_delay);
+ announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay);
+ }
else
- {
- expiration = GNUNET_HELLO_get_last_expiration(hello);
- announce_delay = GNUNET_TIME_UNIT_SECONDS;
- }
+ {
+ expiration = GNUNET_HELLO_get_last_expiration (hello);
+ announce_delay = GNUNET_TIME_UNIT_SECONDS;
+ }
/* Call again in id_announce_time, unless HELLO expires first,
* but wait at least 1s. */
next_put
- = GNUNET_TIME_absolute_get_remaining(expiration);
+ = GNUNET_TIME_absolute_get_remaining (expiration);
next_put
- = GNUNET_TIME_relative_min(next_put,
- id_announce_time);
+ = GNUNET_TIME_relative_min (next_put,
+ id_announce_time);
next_put
- = GNUNET_TIME_relative_max(next_put,
- GNUNET_TIME_UNIT_SECONDS);
+ = GNUNET_TIME_relative_max (next_put,
+ GNUNET_TIME_UNIT_SECONDS);
announce_id_task
- = GNUNET_SCHEDULER_add_delayed(next_put,
- &announce_id,
- cls);
- GNUNET_STATISTICS_update(stats,
- "# DHT announce",
- 1,
- GNUNET_NO);
- memset(&phash,
- 0,
- sizeof(phash));
- GNUNET_memcpy(&phash,
- &my_full_id,
- sizeof(my_full_id));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Announcing my HELLO (%u bytes) in the DHT\n",
- size);
- GNUNET_DHT_put(dht_handle, /* DHT handle */
- &phash, /* Key to use */
- dht_replication_level, /* Replication level */
- GNUNET_DHT_RO_RECORD_ROUTE
- | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
- GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
- size, /* Size of the data */
- (const char *)hello, /* Data itself */
- expiration, /* Data expiration */
- NULL, /* Continuation */
- NULL); /* Continuation closure */
+ = GNUNET_SCHEDULER_add_delayed (next_put,
+ &announce_id,
+ cls);
+ GNUNET_STATISTICS_update (stats,
+ "# DHT announce",
+ 1,
+ GNUNET_NO);
+ memset (&phash,
+ 0,
+ sizeof(phash));
+ GNUNET_memcpy (&phash,
+ &my_full_id,
+ sizeof(my_full_id));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Announcing my HELLO (%u bytes) in the DHT\n",
+ size);
+ GNUNET_DHT_put (dht_handle, /* DHT handle */
+ &phash, /* Key to use */
+ dht_replication_level, /* Replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE
+ | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
+ size, /* Size of the data */
+ (const char *) hello, /* Data itself */
+ expiration, /* Data expiration */
+ NULL, /* Continuation */
+ NULL); /* Continuation closure */
}
@@ -213,15 +216,15 @@ announce_id(void *cls)
* changes. Re-triggers the DHT PUT immediately.
*/
void
-GCD_hello_update()
+GCD_hello_update ()
{
if (NULL == announce_id_task)
return; /* too early */
- GNUNET_SCHEDULER_cancel(announce_id_task);
+ GNUNET_SCHEDULER_cancel (announce_id_task);
announce_id_task
- = GNUNET_SCHEDULER_add_delayed(CHANGE_DELAY,
- &announce_id,
- NULL);
+ = GNUNET_SCHEDULER_add_delayed (CHANGE_DELAY,
+ &announce_id,
+ NULL);
}
@@ -231,42 +234,42 @@ GCD_hello_update()
* @param c Configuration.
*/
void
-GCD_init(const struct GNUNET_CONFIGURATION_Handle *c)
+GCD_init (const struct GNUNET_CONFIGURATION_Handle *c)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number(c,
- "CADET",
- "DHT_REPLICATION_LEVEL",
- &dht_replication_level))
- {
- GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING,
- "CADET",
- "DHT_REPLICATION_LEVEL",
- "USING DEFAULT");
- dht_replication_level = 3;
- }
+ GNUNET_CONFIGURATION_get_value_number (c,
+ "CADET",
+ "DHT_REPLICATION_LEVEL",
+ &dht_replication_level))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+ "CADET",
+ "DHT_REPLICATION_LEVEL",
+ "USING DEFAULT");
+ dht_replication_level = 3;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time(c,
- "CADET",
- "ID_ANNOUNCE_TIME",
- &id_announce_time))
- {
- GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
- "CADET",
- "ID_ANNOUNCE_TIME",
- "MISSING");
- GNUNET_SCHEDULER_shutdown();
- return;
- }
-
- dht_handle = GNUNET_DHT_connect(c,
- 64);
- GNUNET_break(NULL != dht_handle);
+ GNUNET_CONFIGURATION_get_value_time (c,
+ "CADET",
+ "ID_ANNOUNCE_TIME",
+ &id_announce_time))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "CADET",
+ "ID_ANNOUNCE_TIME",
+ "MISSING");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ dht_handle = GNUNET_DHT_connect (c,
+ 64);
+ GNUNET_break (NULL != dht_handle);
announce_delay = GNUNET_TIME_UNIT_SECONDS;
- announce_id_task = GNUNET_SCHEDULER_add_delayed(STARTUP_DELAY,
- &announce_id,
- NULL);
+ announce_id_task = GNUNET_SCHEDULER_add_delayed (STARTUP_DELAY,
+ &announce_id,
+ NULL);
}
@@ -274,18 +277,18 @@ GCD_init(const struct GNUNET_CONFIGURATION_Handle *c)
* Shut down the DHT subsystem.
*/
void
-GCD_shutdown(void)
+GCD_shutdown (void)
{
if (NULL != dht_handle)
- {
- GNUNET_DHT_disconnect(dht_handle);
- dht_handle = NULL;
- }
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
if (NULL != announce_id_task)
- {
- GNUNET_SCHEDULER_cancel(announce_id_task);
- announce_id_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (announce_id_task);
+ announce_id_task = NULL;
+ }
}
@@ -296,37 +299,37 @@ GCD_shutdown(void)
* @return handle to abort search
*/
struct GCD_search_handle *
-GCD_search(const struct GNUNET_PeerIdentity *peer_id)
+GCD_search (const struct GNUNET_PeerIdentity *peer_id)
{
struct GNUNET_HashCode phash;
struct GCD_search_handle *h;
- GNUNET_STATISTICS_update(stats,
- "# DHT search",
- 1,
- GNUNET_NO);
- memset(&phash,
- 0,
- sizeof(phash));
- GNUNET_memcpy(&phash,
- peer_id,
- sizeof(*peer_id));
-
- h = GNUNET_new(struct GCD_search_handle);
- h->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
- &phash, /* key to search */
- dht_replication_level, /* replication level */
- GNUNET_DHT_RO_RECORD_ROUTE |
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, /* xquery */
- 0, /* xquery bits */
- &dht_get_id_handler,
- h);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Starting DHT GET for peer %s (%p)\n",
- GNUNET_i2s(peer_id),
- h);
+ GNUNET_STATISTICS_update (stats,
+ "# DHT search",
+ 1,
+ GNUNET_NO);
+ memset (&phash,
+ 0,
+ sizeof(phash));
+ GNUNET_memcpy (&phash,
+ peer_id,
+ sizeof(*peer_id));
+
+ h = GNUNET_new (struct GCD_search_handle);
+ h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
+ &phash, /* key to search */
+ dht_replication_level, /* replication level */
+ GNUNET_DHT_RO_RECORD_ROUTE
+ | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ NULL, /* xquery */
+ 0, /* xquery bits */
+ &dht_get_id_handler,
+ h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DHT GET for peer %s (%p)\n",
+ GNUNET_i2s (peer_id),
+ h);
return h;
}
@@ -337,13 +340,13 @@ GCD_search(const struct GNUNET_PeerIdentity *peer_id)
* @param h handle to search to stop
*/
void
-GCD_search_stop(struct GCD_search_handle *h)
+GCD_search_stop (struct GCD_search_handle *h)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Stopping DHT GET %p\n",
- h);
- GNUNET_DHT_get_stop(h->dhtget);
- GNUNET_free(h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Stopping DHT GET %p\n",
+ h);
+ GNUNET_DHT_get_stop (h->dhtget);
+ GNUNET_free (h);
}
/* end of gnunet-service-cadet_dht.c */
diff --git a/src/cadet/gnunet-service-cadet_dht.h b/src/cadet/gnunet-service-cadet_dht.h
index 4cb6e9fff..bcc27f5d2 100644
--- a/src/cadet/gnunet-service-cadet_dht.h
+++ b/src/cadet/gnunet-service-cadet_dht.h
@@ -52,14 +52,14 @@ struct GCD_search_handle;
* @param c Configuration.
*/
void
-GCD_init(const struct GNUNET_CONFIGURATION_Handle *c);
+GCD_init (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Shut down the DHT subsystem.
*/
void
-GCD_shutdown(void);
+GCD_shutdown (void);
/**
@@ -67,7 +67,7 @@ GCD_shutdown(void);
* changes. Re-triggers the DHT PUT immediately.
*/
void
-GCD_hello_update(void);
+GCD_hello_update (void);
/**
* Search DHT for paths to @a peeR_id
@@ -76,7 +76,7 @@ GCD_hello_update(void);
* @return handle to abort search
*/
struct GCD_search_handle *
-GCD_search(const struct GNUNET_PeerIdentity *peer_id);
+GCD_search (const struct GNUNET_PeerIdentity *peer_id);
/**
@@ -85,7 +85,7 @@ GCD_search(const struct GNUNET_PeerIdentity *peer_id);
* @param h handle to search to stop
*/
void
-GCD_search_stop(struct GCD_search_handle *h);
+GCD_search_stop (struct GCD_search_handle *h);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_hello.c b/src/cadet/gnunet-service-cadet_hello.c
index 7d6d2b0ce..bbe947ad1 100644
--- a/src/cadet/gnunet-service-cadet_hello.c
+++ b/src/cadet/gnunet-service-cadet_hello.c
@@ -35,7 +35,7 @@
#include "gnunet-service-cadet_hello.h"
#include "gnunet-service-cadet_peer.h"
-#define LOG(level, ...) GNUNET_log_from(level, "cadet-hll", __VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__)
/**
* Hello message of local peer.
@@ -62,34 +62,35 @@ static struct GNUNET_PEERINFO_NotifyContext *nc;
* @param err_msg Error message.
*/
static void
-got_hello(void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_HELLO_Message *hello,
- const char *err_msg)
+got_hello (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const struct GNUNET_HELLO_Message *hello,
+ const char *err_msg)
{
struct CadetPeer *peer;
if ((NULL == id) ||
(NULL == hello))
return;
- if (0 == GNUNET_memcmp(id,
- &my_full_id))
- {
- GNUNET_free_non_null(mine);
- mine = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(&hello->header);
- GCD_hello_update();
- return;
- }
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Hello for %s (%d bytes), expires on %s\n",
- GNUNET_i2s(id),
- GNUNET_HELLO_size(hello),
- GNUNET_STRINGS_absolute_time_to_string(GNUNET_HELLO_get_last_expiration(hello)));
- peer = GCP_get(id,
- GNUNET_YES);
- GCP_set_hello(peer,
- hello);
+ if (0 == GNUNET_memcmp (id,
+ &my_full_id))
+ {
+ GNUNET_free_non_null (mine);
+ mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
+ GCD_hello_update ();
+ return;
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Hello for %s (%d bytes), expires on %s\n",
+ GNUNET_i2s (id),
+ GNUNET_HELLO_size (hello),
+ GNUNET_STRINGS_absolute_time_to_string (
+ GNUNET_HELLO_get_last_expiration (hello)));
+ peer = GCP_get (id,
+ GNUNET_YES);
+ GCP_set_hello (peer,
+ hello);
}
@@ -99,14 +100,14 @@ got_hello(void *cls,
* @param c Configuration.
*/
void
-GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
+GCH_init (const struct GNUNET_CONFIGURATION_Handle *c)
{
- GNUNET_assert(NULL == nc);
- peerinfo = GNUNET_PEERINFO_connect(c);
- nc = GNUNET_PEERINFO_notify(c,
- GNUNET_NO,
- &got_hello,
- NULL);
+ GNUNET_assert (NULL == nc);
+ peerinfo = GNUNET_PEERINFO_connect (c);
+ nc = GNUNET_PEERINFO_notify (c,
+ GNUNET_NO,
+ &got_hello,
+ NULL);
}
@@ -114,23 +115,23 @@ GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
* Shut down the hello subsystem.
*/
void
-GCH_shutdown()
+GCH_shutdown ()
{
if (NULL != nc)
- {
- GNUNET_PEERINFO_notify_cancel(nc);
- nc = NULL;
- }
+ {
+ GNUNET_PEERINFO_notify_cancel (nc);
+ nc = NULL;
+ }
if (NULL != peerinfo)
- {
- GNUNET_PEERINFO_disconnect(peerinfo);
- peerinfo = NULL;
- }
+ {
+ GNUNET_PEERINFO_disconnect (peerinfo);
+ peerinfo = NULL;
+ }
if (NULL != mine)
- {
- GNUNET_free(mine);
- mine = NULL;
- }
+ {
+ GNUNET_free (mine);
+ mine = NULL;
+ }
}
@@ -140,7 +141,7 @@ GCH_shutdown()
* @return Own hello message.
*/
const struct GNUNET_HELLO_Message *
-GCH_get_mine(void)
+GCH_get_mine (void)
{
return mine;
}
diff --git a/src/cadet/gnunet-service-cadet_hello.h b/src/cadet/gnunet-service-cadet_hello.h
index 99b6c807d..2cb444b4a 100644
--- a/src/cadet/gnunet-service-cadet_hello.h
+++ b/src/cadet/gnunet-service-cadet_hello.h
@@ -49,14 +49,14 @@ extern "C"
* @param c Configuration.
*/
void
-GCH_init(const struct GNUNET_CONFIGURATION_Handle *c);
+GCH_init (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Shut down the hello subsystem.
*/
void
-GCH_shutdown(void);
+GCH_shutdown (void);
/**
@@ -65,7 +65,7 @@ GCH_shutdown(void);
* @return Own hello message.
*/
const struct GNUNET_HELLO_Message *
-GCH_get_mine(void);
+GCH_get_mine (void);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c
index 149ac659a..e4a8dc789 100644
--- a/src/cadet/gnunet-service-cadet_paths.c
+++ b/src/cadet/gnunet-service-cadet_paths.c
@@ -30,13 +30,14 @@
#include "gnunet-service-cadet_paths.h"
-#define LOG(level, ...) GNUNET_log_from(level, "cadet-pat", __VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-pat", __VA_ARGS__)
/**
* Information regarding a possible path to reach a peer.
*/
-struct CadetPeerPath {
+struct CadetPeerPath
+{
/**
* Array of all the peers on the path. If @e hn is non-NULL, the
* last one is our owner.
@@ -68,18 +69,18 @@ struct CadetPeerPath {
* @param path path to calculate the score for
*/
static void
-recalculate_path_desirability(struct CadetPeerPath *path)
+recalculate_path_desirability (struct CadetPeerPath *path)
{
double result = 0.0;
for (unsigned int i = 0; i < path->entries_length; i++)
- {
- struct CadetPeer *cp = path->entries[i]->peer;
+ {
+ struct CadetPeer *cp = path->entries[i]->peer;
- result += GCP_get_desirability_of_path(cp,
- i);
- }
- path->desirability = (GNUNET_CONTAINER_HeapCostType)result;
+ result += GCP_get_desirability_of_path (cp,
+ i);
+ }
+ path->desirability = (GNUNET_CONTAINER_HeapCostType) result;
}
@@ -97,7 +98,7 @@ recalculate_path_desirability(struct CadetPeerPath *path)
* @return desirability of the path, larger is more desirable
*/
GNUNET_CONTAINER_HeapCostType
-GCPP_get_desirability(const struct CadetPeerPath *path)
+GCPP_get_desirability (const struct CadetPeerPath *path)
{
return path->desirability;
}
@@ -114,15 +115,15 @@ GCPP_get_desirability(const struct CadetPeerPath *path)
* otherwise connection from us to @a destination via @a path
*/
struct CadetConnection *
-GCPP_get_connection(struct CadetPeerPath *path,
- struct CadetPeer *destination,
- unsigned int off)
+GCPP_get_connection (struct CadetPeerPath *path,
+ struct CadetPeer *destination,
+ unsigned int off)
{
struct CadetPeerPathEntry *entry;
- GNUNET_assert(off < path->entries_length);
+ GNUNET_assert (off < path->entries_length);
entry = path->entries[off];
- GNUNET_assert(entry->peer == destination);
+ GNUNET_assert (entry->peer == destination);
return entry->cc;
}
@@ -136,21 +137,21 @@ GCPP_get_connection(struct CadetPeerPath *path,
* @param cc the connection to remember
*/
void
-GCPP_add_connection(struct CadetPeerPath *path,
- unsigned int off,
- struct CadetConnection *cc)
+GCPP_add_connection (struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetConnection *cc)
{
struct CadetPeerPathEntry *entry;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Adding %s to path %s at offset %u\n",
- GCC_2s(cc),
- GCPP_2s(path),
- off);
- GNUNET_assert(off < path->entries_length);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding %s to path %s at offset %u\n",
+ GCC_2s (cc),
+ GCPP_2s (path),
+ off);
+ GNUNET_assert (off < path->entries_length);
entry = path->entries[off];
- GNUNET_assert(NULL == entry->cc);
- GNUNET_assert(NULL != cc);
+ GNUNET_assert (NULL == entry->cc);
+ GNUNET_assert (NULL != cc);
entry->cc = cc;
}
@@ -165,20 +166,20 @@ GCPP_add_connection(struct CadetPeerPath *path,
* @param cc the connection to forget
*/
void
-GCPP_del_connection(struct CadetPeerPath *path,
- unsigned int off,
- struct CadetConnection *cc)
+GCPP_del_connection (struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetConnection *cc)
{
struct CadetPeerPathEntry *entry;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Removing connection %s to path %s at offset %u\n",
- GCC_2s(cc),
- GCPP_2s(path),
- off);
- GNUNET_assert(off < path->entries_length);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing connection %s to path %s at offset %u\n",
+ GCC_2s (cc),
+ GCPP_2s (path),
+ off);
+ GNUNET_assert (off < path->entries_length);
entry = path->entries[off];
- GNUNET_assert(cc == entry->cc);
+ GNUNET_assert (cc == entry->cc);
entry->cc = NULL;
}
@@ -193,42 +194,42 @@ GCPP_del_connection(struct CadetPeerPath *path,
* @param stop_at the path length at which to stop trying
*/
static void
-attach_path(struct CadetPeerPath *path, unsigned int stop_at)
+attach_path (struct CadetPeerPath *path, unsigned int stop_at)
{
- GNUNET_assert(NULL == path->hn);
+ GNUNET_assert (NULL == path->hn);
/* Try to attach this path to a peer, working backwards from the end. */
while (path->entries_length > stop_at)
- {
- unsigned int end = path->entries_length - 1;
- struct CadetPeerPathEntry *entry = path->entries[end];
- int force = GNUNET_NO;
-
- recalculate_path_desirability(path);
- /* If the entry already has a connection using it, force attach. */
- if (NULL != entry->cc)
- force = GNUNET_YES;
- path->hn = GCP_attach_path(entry->peer,
- path,
- end,
- force);
- if (NULL != path->hn)
- break;
-
- /* Attach failed, trim this entry from the path. */
- GNUNET_assert(NULL == entry->cc);
- GCP_path_entry_remove(entry->peer,
- entry,
- end);
- GNUNET_free(entry);
- path->entries[end] = NULL;
- path->entries_length--;
- }
+ {
+ unsigned int end = path->entries_length - 1;
+ struct CadetPeerPathEntry *entry = path->entries[end];
+ int force = GNUNET_NO;
+
+ recalculate_path_desirability (path);
+ /* If the entry already has a connection using it, force attach. */
+ if (NULL != entry->cc)
+ force = GNUNET_YES;
+ path->hn = GCP_attach_path (entry->peer,
+ path,
+ end,
+ force);
+ if (NULL != path->hn)
+ break;
+
+ /* Attach failed, trim this entry from the path. */
+ GNUNET_assert (NULL == entry->cc);
+ GCP_path_entry_remove (entry->peer,
+ entry,
+ end);
+ GNUNET_free (entry);
+ path->entries[end] = NULL;
+ path->entries_length--;
+ }
/* Shrink array to actual path length. */
- GNUNET_array_grow(path->entries,
- path->entries_length,
- path->entries_length);
+ GNUNET_array_grow (path->entries,
+ path->entries_length,
+ path->entries_length);
}
@@ -240,33 +241,33 @@ attach_path(struct CadetPeerPath *path, unsigned int stop_at)
* @param path the path that is being released
*/
void
-GCPP_release(struct CadetPeerPath *path)
+GCPP_release (struct CadetPeerPath *path)
{
struct CadetPeerPathEntry *entry;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Owner releases path %s\n",
- GCPP_2s(path));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Owner releases path %s\n",
+ GCPP_2s (path));
path->hn = NULL;
entry = path->entries[path->entries_length - 1];
- GNUNET_assert(path == entry->path);
- GNUNET_assert(NULL == entry->cc);
+ GNUNET_assert (path == entry->path);
+ GNUNET_assert (NULL == entry->cc);
/* cut 'off' end of path */
- GCP_path_entry_remove(entry->peer,
- entry,
- path->entries_length - 1);
- GNUNET_free(entry);
+ GCP_path_entry_remove (entry->peer,
+ entry,
+ path->entries_length - 1);
+ GNUNET_free (entry);
path->entries[path->entries_length - 1] = NULL;
path->entries_length--;
/* see if new peer at the end likes this path any better */
- attach_path(path, 0);
+ attach_path (path, 0);
if (NULL == path->hn)
- {
- /* nobody wants us, discard the path */
- GNUNET_assert(0 == path->entries_length);
- GNUNET_assert(NULL == path->entries);
- GNUNET_free(path);
- }
+ {
+ /* nobody wants us, discard the path */
+ GNUNET_assert (0 == path->entries_length);
+ GNUNET_assert (NULL == path->entries);
+ GNUNET_free (path);
+ }
}
@@ -279,38 +280,39 @@ GCPP_release(struct CadetPeerPath *path)
* @param delta change in the score to apply
*/
void
-GCPP_update_score(struct CadetPeerPath *path,
- unsigned int off,
- int delta)
+GCPP_update_score (struct CadetPeerPath *path,
+ unsigned int off,
+ int delta)
{
struct CadetPeerPathEntry *entry;
- GNUNET_assert(off < path->entries_length);
+ GNUNET_assert (off < path->entries_length);
entry = path->entries[off];
/* Add delta, with checks for overflows */
if (delta >= 0)
- {
- if (delta + entry->score < entry->score)
- entry->score = INT_MAX;
- else
- entry->score += delta;
- }
+ {
+ if (delta + entry->score < entry->score)
+ entry->score = INT_MAX;
+ else
+ entry->score += delta;
+ }
else
- {
- if (delta + entry->score > entry->score)
- entry->score = INT_MIN;
- else
- entry->score += delta;
- }
- recalculate_path_desirability(path);
+ {
+ if (delta + entry->score > entry->score)
+ entry->score = INT_MIN;
+ else
+ entry->score += delta;
+ }
+ recalculate_path_desirability (path);
}
/**
* Closure for #find_peer_at() and #check_match().
*/
-struct CheckMatchContext {
+struct CheckMatchContext
+{
/**
* Set to a matching path, if any.
*/
@@ -339,38 +341,38 @@ struct CheckMatchContext {
* @return #GNUNET_YES (continue to iterate), or if found #GNUNET_NO
*/
static int
-check_match(void *cls,
- struct CadetPeerPath *path,
- unsigned int off)
+check_match (void *cls,
+ struct CadetPeerPath *path,
+ unsigned int off)
{
struct CheckMatchContext *cm_ctx = cls;
- GNUNET_assert(path->entries_length > off);
+ GNUNET_assert (path->entries_length > off);
if ((path->entries_length != off + 1) &&
(off + 1 != cm_ctx->cpath_length))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
- GCPP_2s(path),
- path->entries_length,
- off + 1,
- cm_ctx->cpath_length);
- return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
+ GCPP_2s (path),
+ path->entries_length,
+ off + 1,
+ cm_ctx->cpath_length);
+ return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
+ }
for (unsigned int i = 0; i < off; i++)
if (cm_ctx->cpath[i] !=
- GCPP_get_peer_at_offset(path,
- i))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "check_match path %s mismatches at offset %u\n",
- GCPP_2s(path),
- i);
- return GNUNET_YES; /* mismatch, ignore */
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "check_match found match with path %s\n",
- GCPP_2s(path));
+ GCPP_get_peer_at_offset (path,
+ i))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "check_match path %s mismatches at offset %u\n",
+ GCPP_2s (path),
+ i);
+ return GNUNET_YES; /* mismatch, ignore */
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "check_match found match with path %s\n",
+ GCPP_2s (path));
cm_ctx->match = path;
return GNUNET_NO; /* match, we are done! */
}
@@ -387,70 +389,70 @@ check_match(void *cls,
* paths already
*/
static void
-extend_path(struct CadetPeerPath *path,
- struct CadetPeer **peers,
- unsigned int num_peers,
- int force)
+extend_path (struct CadetPeerPath *path,
+ struct CadetPeer **peers,
+ unsigned int num_peers,
+ int force)
{
unsigned int old_len = path->entries_length;
int i;
/* Expand path */
- GNUNET_array_grow(path->entries,
- path->entries_length,
- old_len + num_peers);
+ GNUNET_array_grow (path->entries,
+ path->entries_length,
+ old_len + num_peers);
for (i = num_peers - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+ {
+ struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
- path->entries[old_len + i] = entry;
- entry->peer = peers[i];
- entry->path = path;
- }
+ path->entries[old_len + i] = entry;
+ entry->peer = peers[i];
+ entry->path = path;
+ }
for (i = num_peers - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = path->entries[old_len + i];
+ {
+ struct CadetPeerPathEntry *entry = path->entries[old_len + i];
- GCP_path_entry_add(entry->peer,
- entry,
- old_len + i);
- }
+ GCP_path_entry_add (entry->peer,
+ entry,
+ old_len + i);
+ }
/* If we extend an existing path, detach it from the
old owner and re-attach to the new one */
- GCP_detach_path(path->entries[old_len - 1]->peer,
- path,
- path->hn);
+ GCP_detach_path (path->entries[old_len - 1]->peer,
+ path,
+ path->hn);
path->hn = NULL;
path->entries_length = old_len + num_peers;
if (GNUNET_YES == force)
- {
- int end = path->entries_length - 1;
-
- path->hn = GCP_attach_path(path->entries[end]->peer,
- path,
- end,
- GNUNET_YES);
- }
+ {
+ int end = path->entries_length - 1;
+
+ path->hn = GCP_attach_path (path->entries[end]->peer,
+ path,
+ end,
+ GNUNET_YES);
+ }
else
- {
- attach_path(path, old_len);
- }
+ {
+ attach_path (path, old_len);
+ }
if (NULL == path->hn)
- {
- /* none of the peers is interested in this path;
- re-attach. */
- GNUNET_assert(old_len == path->entries_length);
- path->hn = GCP_attach_path(path->entries[old_len - 1]->peer,
- path,
- old_len - 1,
- GNUNET_YES);
- GNUNET_assert(NULL != path->hn);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Extended path %s\n",
- GCPP_2s(path));
+ {
+ /* none of the peers is interested in this path;
+ re-attach. */
+ GNUNET_assert (old_len == path->entries_length);
+ path->hn = GCP_attach_path (path->entries[old_len - 1]->peer,
+ path,
+ old_len - 1,
+ GNUNET_YES);
+ GNUNET_assert (NULL != path->hn);
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Extended path %s\n",
+ GCPP_2s (path));
}
@@ -467,10 +469,10 @@ extend_path(struct CadetPeerPath *path,
* @return a path through the network
*/
void
-GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length)
+GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length)
{
struct CadetPeer *cpath[get_path_length + put_path_length];
struct CheckMatchContext cm_ctx;
@@ -480,42 +482,42 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
/* precompute 'cpath' so we can avoid doing the lookups lots of times */
skip = 0;
- memset(cpath,
- 0,
- sizeof(cpath)); /* Just to trigger harder errors later. */
+ memset (cpath,
+ 0,
+ sizeof(cpath)); /* Just to trigger harder errors later. */
total_len = get_path_length + put_path_length;
for (unsigned int off = 0; off < total_len; off++)
+ {
+ const struct GNUNET_PeerIdentity *pid;
+
+ pid = (off < get_path_length)
+ ? &get_path[get_path_length - off - 1]
+ : &put_path[get_path_length + put_path_length - off - 1];
+ /* Check that I am not in the path */
+ if (0 == GNUNET_memcmp (&my_full_id,
+ pid))
{
- const struct GNUNET_PeerIdentity *pid;
-
- pid = (off < get_path_length)
- ? &get_path[get_path_length - off - 1]
- : &put_path[get_path_length + put_path_length - off - 1];
- /* Check that I am not in the path */
- if (0 == GNUNET_memcmp(&my_full_id,
- pid))
- {
- skip = off + 1;
- continue;
- }
- cpath[off - skip] = GCP_get(pid,
- GNUNET_YES);
- /* Check that no peer is twice on the path */
- for (unsigned int i = 0; i < off - skip; i++)
- {
- if (cpath[i] == cpath[off - skip])
- {
- skip = off - i;
- break;
- }
- }
+ skip = off + 1;
+ continue;
}
- if (skip >= total_len)
+ cpath[off - skip] = GCP_get (pid,
+ GNUNET_YES);
+ /* Check that no peer is twice on the path */
+ for (unsigned int i = 0; i < off - skip; i++)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Path discovered from DHT is one big cycle?\n");
- return;
+ if (cpath[i] == cpath[off - skip])
+ {
+ skip = off - i;
+ break;
+ }
}
+ }
+ if (skip >= total_len)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Path discovered from DHT is one big cycle?\n");
+ return;
+ }
total_len -= skip;
/* First figure out if this path is a subset of an existing path, an
@@ -524,72 +526,72 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
cm_ctx.cpath = cpath;
cm_ctx.match = NULL;
for (int i = total_len - 1; i >= 0; i--)
+ {
+ GCP_iterate_paths_at (cpath[i],
+ (unsigned int) i,
+ &check_match,
+ &cm_ctx);
+ if (NULL != cm_ctx.match)
{
- GCP_iterate_paths_at(cpath[i],
- (unsigned int)i,
- &check_match,
- &cm_ctx);
- if (NULL != cm_ctx.match)
- {
- if (i == total_len - 1)
- {
- /* Existing path includes this one, nothing to do! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Path discovered from DHT is already known\n");
- return;
- }
- if (cm_ctx.match->entries_length == i + 1)
- {
- /* Existing path ends in the middle of new path, extend it! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Trying to extend existing path %s by additional links discovered from DHT\n",
- GCPP_2s(cm_ctx.match));
- extend_path(cm_ctx.match,
- &cpath[i + 1],
- total_len - i - 1,
- GNUNET_NO);
- return;
- }
- }
+ if (i == total_len - 1)
+ {
+ /* Existing path includes this one, nothing to do! */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Path discovered from DHT is already known\n");
+ return;
+ }
+ if (cm_ctx.match->entries_length == i + 1)
+ {
+ /* Existing path ends in the middle of new path, extend it! */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to extend existing path %s by additional links discovered from DHT\n",
+ GCPP_2s (cm_ctx.match));
+ extend_path (cm_ctx.match,
+ &cpath[i + 1],
+ total_len - i - 1,
+ GNUNET_NO);
+ return;
+ }
}
+ }
/* No match at all, create completely new path */
- path = GNUNET_new(struct CadetPeerPath);
+ path = GNUNET_new (struct CadetPeerPath);
path->entries_length = total_len;
- path->entries = GNUNET_new_array(path->entries_length,
- struct CadetPeerPathEntry *);
+ path->entries = GNUNET_new_array (path->entries_length,
+ struct CadetPeerPathEntry *);
for (int i = path->entries_length - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+ {
+ struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
- path->entries[i] = entry;
- entry->peer = cpath[i];
- entry->path = path;
- }
+ path->entries[i] = entry;
+ entry->peer = cpath[i];
+ entry->path = path;
+ }
for (int i = path->entries_length - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = path->entries[i];
+ {
+ struct CadetPeerPathEntry *entry = path->entries[i];
- GCP_path_entry_add(entry->peer,
- entry,
- i);
- }
+ GCP_path_entry_add (entry->peer,
+ entry,
+ i);
+ }
/* Finally, try to attach it */
- attach_path(path, 0);
+ attach_path (path, 0);
if (NULL == path->hn)
- {
- /* None of the peers on the path care about it. */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Path discovered from DHT is not interesting to us\n");
- GNUNET_assert(0 == path->entries_length);
- GNUNET_assert(NULL == path->entries);
- GNUNET_free(path);
- return;
- }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Created new path %s based on information from DHT\n",
- GCPP_2s(path));
+ {
+ /* None of the peers on the path care about it. */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Path discovered from DHT is not interesting to us\n");
+ GNUNET_assert (0 == path->entries_length);
+ GNUNET_assert (NULL == path->entries);
+ GNUNET_free (path);
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Created new path %s based on information from DHT\n",
+ GCPP_2s (path));
}
@@ -601,8 +603,8 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
* @return corresponding path object
*/
struct CadetPeerPath *
-GCPP_get_path_from_route(unsigned int path_length,
- const struct GNUNET_PeerIdentity *pids)
+GCPP_get_path_from_route (unsigned int path_length,
+ const struct GNUNET_PeerIdentity *pids)
{
struct CheckMatchContext cm_ctx;
struct CadetPeer *cpath[path_length];
@@ -611,8 +613,8 @@ GCPP_get_path_from_route(unsigned int path_length,
/* precompute inverted 'cpath' so we can avoid doing the lookups and
have the correct order */
for (unsigned int off = 0; off < path_length; off++)
- cpath[off] = GCP_get(&pids[path_length - 1 - off],
- GNUNET_YES);
+ cpath[off] = GCP_get (&pids[path_length - 1 - off],
+ GNUNET_YES);
/* First figure out if this path is a subset of an existing path, an
extension of an existing path, or a new path. */
@@ -620,69 +622,69 @@ GCPP_get_path_from_route(unsigned int path_length,
cm_ctx.cpath_length = path_length;
cm_ctx.match = NULL;
for (int i = path_length - 1; i >= 0; i--)
+ {
+ GCP_iterate_paths_at (cpath[i],
+ (unsigned int) i,
+ &check_match,
+ &cm_ctx);
+ if (NULL != cm_ctx.match)
{
- GCP_iterate_paths_at(cpath[i],
- (unsigned int)i,
- &check_match,
- &cm_ctx);
- if (NULL != cm_ctx.match)
- {
- if (i == path_length - 1)
- {
- /* Existing path includes this one, return the match! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Returning existing path %s as inverse for incoming connection\n",
- GCPP_2s(cm_ctx.match));
- return cm_ctx.match;
- }
- if (cm_ctx.match->entries_length == i + 1)
- {
- /* Existing path ends in the middle of new path, extend it! */
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Extending existing path %s to create inverse for incoming connection\n",
- GCPP_2s(cm_ctx.match));
- extend_path(cm_ctx.match,
- &cpath[i + 1],
- path_length - i - 1,
- GNUNET_YES);
- /* Check that extension was successful */
- GNUNET_assert(cm_ctx.match->entries_length == path_length);
- return cm_ctx.match;
- }
- /* Eh, we found a match but couldn't use it? Something is wrong. */
- GNUNET_break(0);
- }
+ if (i == path_length - 1)
+ {
+ /* Existing path includes this one, return the match! */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Returning existing path %s as inverse for incoming connection\n",
+ GCPP_2s (cm_ctx.match));
+ return cm_ctx.match;
+ }
+ if (cm_ctx.match->entries_length == i + 1)
+ {
+ /* Existing path ends in the middle of new path, extend it! */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Extending existing path %s to create inverse for incoming connection\n",
+ GCPP_2s (cm_ctx.match));
+ extend_path (cm_ctx.match,
+ &cpath[i + 1],
+ path_length - i - 1,
+ GNUNET_YES);
+ /* Check that extension was successful */
+ GNUNET_assert (cm_ctx.match->entries_length == path_length);
+ return cm_ctx.match;
+ }
+ /* Eh, we found a match but couldn't use it? Something is wrong. */
+ GNUNET_break (0);
}
+ }
/* No match at all, create completely new path */
- path = GNUNET_new(struct CadetPeerPath);
+ path = GNUNET_new (struct CadetPeerPath);
path->entries_length = path_length;
- path->entries = GNUNET_new_array(path->entries_length,
- struct CadetPeerPathEntry *);
+ path->entries = GNUNET_new_array (path->entries_length,
+ struct CadetPeerPathEntry *);
for (int i = path_length - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = GNUNET_new(struct CadetPeerPathEntry);
+ {
+ struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
- path->entries[i] = entry;
- entry->peer = cpath[i];
- entry->path = path;
- }
+ path->entries[i] = entry;
+ entry->peer = cpath[i];
+ entry->path = path;
+ }
for (int i = path_length - 1; i >= 0; i--)
- {
- struct CadetPeerPathEntry *entry = path->entries[i];
+ {
+ struct CadetPeerPathEntry *entry = path->entries[i];
- GCP_path_entry_add(entry->peer,
- entry,
- i);
- }
- recalculate_path_desirability(path);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Created new path %s to create inverse for incoming connection\n",
- GCPP_2s(path));
- path->hn = GCP_attach_path(cpath[path_length - 1],
- path,
- path_length - 1,
- GNUNET_YES);
+ GCP_path_entry_add (entry->peer,
+ entry,
+ i);
+ }
+ recalculate_path_desirability (path);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Created new path %s to create inverse for incoming connection\n",
+ GCPP_2s (path));
+ path->hn = GCP_attach_path (cpath[path_length - 1],
+ path,
+ path_length - 1,
+ GNUNET_YES);
return path;
}
@@ -695,7 +697,7 @@ GCPP_get_path_from_route(unsigned int path_length,
* @return number of peers on the path
*/
unsigned int
-GCPP_get_length(struct CadetPeerPath *path)
+GCPP_get_length (struct CadetPeerPath *path)
{
return path->entries_length;
}
@@ -709,14 +711,14 @@ GCPP_get_length(struct CadetPeerPath *path)
* @return offset of @a cp on @a path, or UINT_MAX if not found
*/
unsigned int
-GCPP_find_peer(struct CadetPeerPath *path,
- struct CadetPeer *cp)
+GCPP_find_peer (struct CadetPeerPath *path,
+ struct CadetPeer *cp)
{
for (unsigned int off = 0;
off < path->entries_length;
off++)
- if (cp == GCPP_get_peer_at_offset(path,
- off))
+ if (cp == GCPP_get_peer_at_offset (path,
+ off))
return off;
return UINT_MAX;
}
@@ -730,10 +732,10 @@ GCPP_find_peer(struct CadetPeerPath *path,
* @return the peer at offset @a off
*/
struct CadetPeer *
-GCPP_get_peer_at_offset(struct CadetPeerPath *path,
- unsigned int off)
+GCPP_get_peer_at_offset (struct CadetPeerPath *path,
+ unsigned int off)
{
- GNUNET_assert(off < path->entries_length);
+ GNUNET_assert (off < path->entries_length);
return path->entries[off]->peer;
}
@@ -745,7 +747,7 @@ GCPP_get_peer_at_offset(struct CadetPeerPath *path,
* @return string, to be freed by caller (unlike other *_2s APIs!)
*/
const char *
-GCPP_2s(struct CadetPeerPath *path)
+GCPP_2s (struct CadetPeerPath *path)
{
static char buf[2048];
size_t off;
@@ -755,27 +757,28 @@ GCPP_2s(struct CadetPeerPath *path)
for (unsigned int i = 0;
i < path->entries_length;
i++)
- {
- if ((path->entries_length > max_plen) &&
- (i == max_plen / 2))
- off += GNUNET_snprintf(&buf[off],
- sizeof(buf) - off,
- "...-");
- if ((path->entries_length > max_plen) &&
- (i > max_plen / 2) &&
- (i < path->entries_length - max_plen / 2))
- continue;
- off += GNUNET_snprintf(&buf[off],
- sizeof(buf) - off,
- "%s%s",
- GNUNET_i2s(GCP_get_id(GCPP_get_peer_at_offset(path,
- i))),
- (i == path->entries_length - 1) ? "" : "-");
- }
- GNUNET_snprintf(&buf[off],
- sizeof(buf) - off,
- "(%p)",
- path);
+ {
+ if ((path->entries_length > max_plen) &&
+ (i == max_plen / 2))
+ off += GNUNET_snprintf (&buf[off],
+ sizeof(buf) - off,
+ "...-");
+ if ((path->entries_length > max_plen) &&
+ (i > max_plen / 2) &&
+ (i < path->entries_length - max_plen / 2))
+ continue;
+ off += GNUNET_snprintf (&buf[off],
+ sizeof(buf) - off,
+ "%s%s",
+ GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (
+ path,
+ i))),
+ (i == path->entries_length - 1) ? "" : "-");
+ }
+ GNUNET_snprintf (&buf[off],
+ sizeof(buf) - off,
+ "(%p)",
+ path);
return buf;
}
diff --git a/src/cadet/gnunet-service-cadet_paths.h b/src/cadet/gnunet-service-cadet_paths.h
index 399f91516..125ea669a 100644
--- a/src/cadet/gnunet-service-cadet_paths.h
+++ b/src/cadet/gnunet-service-cadet_paths.h
@@ -1,4 +1,3 @@
-
/*
This file is part of GNUnet.
Copyright (C) 2001-2017 GNUnet e.V.
@@ -43,10 +42,10 @@
* @param put_path_length length of the @a put_path
*/
void
-GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length);
+GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length);
/**
@@ -57,8 +56,8 @@ GCPP_try_path_from_dht(const struct GNUNET_PeerIdentity *get_path,
* @return corresponding path object
*/
struct CadetPeerPath *
-GCPP_get_path_from_route(unsigned int path_length,
- const struct GNUNET_PeerIdentity *pids);
+GCPP_get_path_from_route (unsigned int path_length,
+ const struct GNUNET_PeerIdentity *pids);
/**
@@ -69,7 +68,7 @@ GCPP_get_path_from_route(unsigned int path_length,
* @return number of peers on the path
*/
unsigned int
-GCPP_get_length(struct CadetPeerPath *path);
+GCPP_get_length (struct CadetPeerPath *path);
/**
@@ -83,9 +82,9 @@ GCPP_get_length(struct CadetPeerPath *path);
* otherwise connection from us to @a destination via @a path
*/
struct CadetConnection *
-GCPP_get_connection(struct CadetPeerPath *path,
- struct CadetPeer *destination,
- unsigned int off);
+GCPP_get_connection (struct CadetPeerPath *path,
+ struct CadetPeer *destination,
+ unsigned int off);
/**
@@ -97,9 +96,9 @@ GCPP_get_connection(struct CadetPeerPath *path,
* @param cc the connection to remember
*/
void
-GCPP_add_connection(struct CadetPeerPath *path,
- unsigned int off,
- struct CadetConnection *cc);
+GCPP_add_connection (struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetConnection *cc);
/**
@@ -111,9 +110,9 @@ GCPP_add_connection(struct CadetPeerPath *path,
* @param cc the connection to forget
*/
void
-GCPP_del_connection(struct CadetPeerPath *path,
- unsigned int off,
- struct CadetConnection *cc);
+GCPP_del_connection (struct CadetPeerPath *path,
+ unsigned int off,
+ struct CadetConnection *cc);
/**
@@ -124,8 +123,8 @@ GCPP_del_connection(struct CadetPeerPath *path,
* @return offset of @a cp on @a path, or UINT_MAX if not found
*/
unsigned int
-GCPP_find_peer(struct CadetPeerPath *path,
- struct CadetPeer *cp);
+GCPP_find_peer (struct CadetPeerPath *path,
+ struct CadetPeer *cp);
/**
@@ -142,7 +141,7 @@ GCPP_find_peer(struct CadetPeerPath *path,
* @return desirability of the path, larger is more desirable
*/
GNUNET_CONTAINER_HeapCostType
-GCPP_get_desirability(const struct CadetPeerPath *path);
+GCPP_get_desirability (const struct CadetPeerPath *path);
/**
@@ -154,7 +153,7 @@ GCPP_get_desirability(const struct CadetPeerPath *path);
* @param path the path that is being released
*/
void
-GCPP_release(struct CadetPeerPath *path);
+GCPP_release (struct CadetPeerPath *path);
/**
@@ -165,8 +164,8 @@ GCPP_release(struct CadetPeerPath *path);
* @return peer at offset @a off
*/
struct CadetPeer *
-GCPP_get_peer_at_offset(struct CadetPeerPath *path,
- unsigned int off);
+GCPP_get_peer_at_offset (struct CadetPeerPath *path,
+ unsigned int off);
/**
@@ -176,7 +175,7 @@ GCPP_get_peer_at_offset(struct CadetPeerPath *path,
* @return string, statically allocated
*/
const char *
-GCPP_2s(struct CadetPeerPath *p);
+GCPP_2s (struct CadetPeerPath *p);
#endif
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 23eb6b225..52a0c2bd3 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -46,18 +46,20 @@
#include "gnunet-service-cadet_tunnels.h"
-#define LOG(level, ...) GNUNET_log_from(level, "cadet-per", __VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-per", __VA_ARGS__)
/**
* How long do we wait until tearing down an idle peer?
*/
-#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
+#define IDLE_PEER_TIMEOUT GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MINUTES, 5)
/**
* How long do we keep paths around if we no longer care about the peer?
*/
-#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
+#define IDLE_PATH_TIMEOUT GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MINUTES, 2)
/**
* Queue size when we start dropping OOO messages.
@@ -69,7 +71,8 @@
* Data structure used to track whom we have to notify about changes
* to our message queue.
*/
-struct GCP_MessageQueueManager {
+struct GCP_MessageQueueManager
+{
/**
* Kept in a DLL.
*/
@@ -105,7 +108,8 @@ struct GCP_MessageQueueManager {
/**
* Struct containing all information regarding a given peer
*/
-struct CadetPeer {
+struct CadetPeer
+{
/**
* ID of the peer
*/
@@ -235,23 +239,23 @@ struct CadetPeer {
* @return Static string for it's ID.
*/
const char *
-GCP_2s(const struct CadetPeer *cp)
+GCP_2s (const struct CadetPeer *cp)
{
static char buf[5];
char *ret;
if ((NULL == cp) ||
- (0 == GNUNET_is_zero(&cp->pid.public_key)))
+ (0 == GNUNET_is_zero (&cp->pid.public_key)))
return "NULL";
- ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&cp->pid.public_key);
+ ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key);
if (NULL == ret)
return "NULL";
- GNUNET_strlcpy(buf,
- ret,
- sizeof(buf));
- GNUNET_free(ret);
+ GNUNET_strlcpy (buf,
+ ret,
+ sizeof(buf));
+ GNUNET_free (ret);
return buf;
}
@@ -272,8 +276,8 @@ GCP_2s(const struct CadetPeer *cp)
* positive scores mean path is more desirable
*/
double
-GCP_get_desirability_of_path(struct CadetPeer *cp,
- unsigned int off)
+GCP_get_desirability_of_path (struct CadetPeer *cp,
+ unsigned int off)
{
unsigned int num_alts = cp->num_paths;
unsigned int off_sum;
@@ -281,8 +285,8 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
double path_delta;
double weight_alts;
- GNUNET_assert(num_alts >= 1); /* 'path' should be in there! */
- GNUNET_assert(0 != cp->path_dll_length);
+ GNUNET_assert (num_alts >= 1); /* 'path' should be in there! */
+ GNUNET_assert (0 != cp->path_dll_length);
/* We maintain 'off_sum' in 'peer' and thereby
avoid the SLOW recalculation each time. Kept here
@@ -294,7 +298,7 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
NULL != pe;
pe = pe->next)
off_sum += j;
- GNUNET_assert(off_sum == cp->off_sum);
+ GNUNET_assert (off_sum == cp->off_sum);
#else
off_sum = cp->off_sum;
#endif
@@ -323,63 +327,63 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
* @param cls peer to clean up
*/
static void
-destroy_peer(void *cls)
+destroy_peer (void *cls)
{
struct CadetPeer *cp = cls;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Destroying state about peer %s\n",
- GCP_2s(cp));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying state about peer %s\n",
+ GCP_2s (cp));
cp->destroy_task = NULL;
- GNUNET_assert(NULL == cp->t);
- GNUNET_assert(NULL == cp->core_mq);
- GNUNET_assert(0 == cp->num_paths);
+ GNUNET_assert (NULL == cp->t);
+ GNUNET_assert (NULL == cp->core_mq);
+ GNUNET_assert (0 == cp->num_paths);
for (unsigned int i = 0; i < cp->path_dll_length; i++)
- GNUNET_assert(NULL == cp->path_heads[i]);
- GNUNET_assert(0 == GNUNET_CONTAINER_multishortmap_size(cp->connections));
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(peers,
- &cp->pid,
- cp));
- GNUNET_free_non_null(cp->path_heads);
- GNUNET_free_non_null(cp->path_tails);
+ GNUNET_assert (NULL == cp->path_heads[i]);
+ GNUNET_assert (0 == GNUNET_CONTAINER_multishortmap_size (cp->connections));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (peers,
+ &cp->pid,
+ cp));
+ GNUNET_free_non_null (cp->path_heads);
+ GNUNET_free_non_null (cp->path_tails);
cp->path_dll_length = 0;
if (NULL != cp->search_h)
- {
- GCD_search_stop(cp->search_h);
- cp->search_h = NULL;
- }
+ {
+ GCD_search_stop (cp->search_h);
+ cp->search_h = NULL;
+ }
/* FIXME: clean up search_delayedXXX! */
if (NULL != cp->hello_offer)
- {
- GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer);
- cp->hello_offer = NULL;
- }
+ {
+ GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
+ cp->hello_offer = NULL;
+ }
if (NULL != cp->connectivity_suggestion)
- {
- GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion);
- cp->connectivity_suggestion = NULL;
- }
- GNUNET_CONTAINER_multishortmap_destroy(cp->connections);
+ {
+ GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
+ cp->connectivity_suggestion = NULL;
+ }
+ GNUNET_CONTAINER_multishortmap_destroy (cp->connections);
if (NULL != cp->path_heap)
- {
- GNUNET_CONTAINER_heap_destroy(cp->path_heap);
- cp->path_heap = NULL;
- }
+ {
+ GNUNET_CONTAINER_heap_destroy (cp->path_heap);
+ cp->path_heap = NULL;
+ }
if (NULL != cp->heap_cleanup_task)
- {
- GNUNET_SCHEDULER_cancel(cp->heap_cleanup_task);
- cp->heap_cleanup_task = NULL;
- }
- GNUNET_free_non_null(cp->hello);
+ {
+ GNUNET_SCHEDULER_cancel (cp->heap_cleanup_task);
+ cp->heap_cleanup_task = NULL;
+ }
+ GNUNET_free_non_null (cp->hello);
/* Peer should not be freed if paths exist; if there are no paths,
there ought to be no connections, and without connections, no
notifications. Thus we can assert that mqm_head is empty at this
point. */
- GNUNET_assert(NULL == cp->mqm_head);
- GNUNET_assert(NULL == cp->mqm_ready_ptr);
- GNUNET_free(cp);
+ GNUNET_assert (NULL == cp->mqm_head);
+ GNUNET_assert (NULL == cp->mqm_ready_ptr);
+ GNUNET_free (cp);
}
@@ -389,64 +393,64 @@ destroy_peer(void *cls)
* @param cp the more-active peer
*/
static void
-consider_peer_activate(struct CadetPeer *cp)
+consider_peer_activate (struct CadetPeer *cp)
{
uint32_t strength;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Updating peer %s activation state (%u connections)%s%s\n",
- GCP_2s(cp),
- GNUNET_CONTAINER_multishortmap_size(cp->connections),
- (NULL == cp->t) ? "" : " with tunnel",
- (NULL == cp->core_mq) ? "" : " with CORE link");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Updating peer %s activation state (%u connections)%s%s\n",
+ GCP_2s (cp),
+ GNUNET_CONTAINER_multishortmap_size (cp->connections),
+ (NULL == cp->t) ? "" : " with tunnel",
+ (NULL == cp->core_mq) ? "" : " with CORE link");
if (NULL != cp->destroy_task)
- {
- /* It's active, do not destory! */
- GNUNET_SCHEDULER_cancel(cp->destroy_task);
- cp->destroy_task = NULL;
- }
- if ((0 == GNUNET_CONTAINER_multishortmap_size(cp->connections)) &&
+ {
+ /* It's active, do not destory! */
+ GNUNET_SCHEDULER_cancel (cp->destroy_task);
+ cp->destroy_task = NULL;
+ }
+ if ((0 == GNUNET_CONTAINER_multishortmap_size (cp->connections)) &&
(NULL == cp->t))
+ {
+ /* We're just on a path or directly connected; don't bother too much */
+ if (NULL != cp->connectivity_suggestion)
{
- /* We're just on a path or directly connected; don't bother too much */
- if (NULL != cp->connectivity_suggestion)
- {
- GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion);
- cp->connectivity_suggestion = NULL;
- }
- if (NULL != cp->search_h)
- {
- GCD_search_stop(cp->search_h);
- cp->search_h = NULL;
- }
- return;
+ GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
+ cp->connectivity_suggestion = NULL;
}
- if (NULL == cp->core_mq)
+ if (NULL != cp->search_h)
{
- /* Lacks direct connection, try to create one by querying the DHT */
- if ((NULL == cp->search_h) &&
- (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
- cp->search_h
- = GCD_search(&cp->pid);
+ GCD_search_stop (cp->search_h);
+ cp->search_h = NULL;
}
+ return;
+ }
+ if (NULL == cp->core_mq)
+ {
+ /* Lacks direct connection, try to create one by querying the DHT */
+ if ((NULL == cp->search_h) &&
+ (DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
+ cp->search_h
+ = GCD_search (&cp->pid);
+ }
else
+ {
+ /* Have direct connection, stop DHT search if active */
+ if (NULL != cp->search_h)
{
- /* Have direct connection, stop DHT search if active */
- if (NULL != cp->search_h)
- {
- GCD_search_stop(cp->search_h);
- cp->search_h = NULL;
- }
+ GCD_search_stop (cp->search_h);
+ cp->search_h = NULL;
}
+ }
/* If we have a tunnel, our urge for connections is much bigger */
strength = (NULL != cp->t) ? 32 : 1;
if (NULL != cp->connectivity_suggestion)
- GNUNET_ATS_connectivity_suggest_cancel(cp->connectivity_suggestion);
+ GNUNET_ATS_connectivity_suggest_cancel (cp->connectivity_suggestion);
cp->connectivity_suggestion
- = GNUNET_ATS_connectivity_suggest(ats_ch,
- &cp->pid,
- strength);
+ = GNUNET_ATS_connectivity_suggest (ats_ch,
+ &cp->pid,
+ strength);
}
@@ -456,7 +460,7 @@ consider_peer_activate(struct CadetPeer *cp)
* @param cp peer to clean up
*/
static void
-consider_peer_destroy(struct CadetPeer *cp);
+consider_peer_destroy (struct CadetPeer *cp);
/**
@@ -466,15 +470,15 @@ consider_peer_destroy(struct CadetPeer *cp);
* @param cls a `struct CadetPeer`.
*/
static void
-drop_paths(void *cls)
+drop_paths (void *cls)
{
struct CadetPeer *cp = cls;
struct CadetPeerPath *path;
cp->destroy_task = NULL;
- while (NULL != (path = GNUNET_CONTAINER_heap_remove_root(cp->path_heap)))
- GCPP_release(path);
- consider_peer_destroy(cp);
+ while (NULL != (path = GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
+ GCPP_release (path);
+ consider_peer_destroy (cp);
}
@@ -484,43 +488,44 @@ drop_paths(void *cls)
* @param cp peer to clean up
*/
static void
-consider_peer_destroy(struct CadetPeer *cp)
+consider_peer_destroy (struct CadetPeer *cp)
{
struct GNUNET_TIME_Relative exp;
if (NULL != cp->destroy_task)
- {
- GNUNET_SCHEDULER_cancel(cp->destroy_task);
- cp->destroy_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cp->destroy_task);
+ cp->destroy_task = NULL;
+ }
if (NULL != cp->t)
return; /* still relevant! */
if (NULL != cp->core_mq)
return; /* still relevant! */
- if (0 != GNUNET_CONTAINER_multishortmap_size(cp->connections))
+ if (0 != GNUNET_CONTAINER_multishortmap_size (cp->connections))
return; /* still relevant! */
if ((NULL != cp->path_heap) &&
- (0 < GNUNET_CONTAINER_heap_get_size(cp->path_heap)))
- {
- cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PATH_TIMEOUT,
- &drop_paths,
- cp);
- return;
- }
+ (0 < GNUNET_CONTAINER_heap_get_size (cp->path_heap)))
+ {
+ cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PATH_TIMEOUT,
+ &drop_paths,
+ cp);
+ return;
+ }
if (0 != cp->num_paths)
return; /* still relevant! */
if (NULL != cp->hello)
- {
- /* relevant only until HELLO expires */
- exp = GNUNET_TIME_absolute_get_remaining(GNUNET_HELLO_get_last_expiration(cp->hello));
- cp->destroy_task = GNUNET_SCHEDULER_add_delayed(exp,
- &destroy_peer,
- cp);
- return;
- }
- cp->destroy_task = GNUNET_SCHEDULER_add_delayed(IDLE_PEER_TIMEOUT,
- &destroy_peer,
- cp);
+ {
+ /* relevant only until HELLO expires */
+ exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration (
+ cp->hello));
+ cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp,
+ &destroy_peer,
+ cp);
+ return;
+ }
+ cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT,
+ &destroy_peer,
+ cp);
}
@@ -531,60 +536,60 @@ consider_peer_destroy(struct CadetPeer *cp)
* @param mq message queue to set (can be NULL)
*/
void
-GCP_set_mq(struct CadetPeer *cp,
- struct GNUNET_MQ_Handle *mq)
+GCP_set_mq (struct CadetPeer *cp,
+ struct GNUNET_MQ_Handle *mq)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Message queue for peer %s is now %p\n",
- GCP_2s(cp),
- mq);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Message queue for peer %s is now %p\n",
+ GCP_2s (cp),
+ mq);
cp->core_mq = mq;
for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next;
NULL != mqm;
mqm = next)
+ {
+ /* Save next pointer in case mqm gets freed by the callback */
+ next = mqm->next;
+ if (NULL == mq)
{
- /* Save next pointer in case mqm gets freed by the callback */
- next = mqm->next;
- if (NULL == mq)
- {
- if (NULL != mqm->env)
- {
- GNUNET_MQ_discard(mqm->env);
- mqm->env = NULL;
- mqm->cb(mqm->cb_cls,
- GNUNET_SYSERR);
- }
- else
- {
- mqm->cb(mqm->cb_cls,
- GNUNET_NO);
- }
- }
+ if (NULL != mqm->env)
+ {
+ GNUNET_MQ_discard (mqm->env);
+ mqm->env = NULL;
+ mqm->cb (mqm->cb_cls,
+ GNUNET_SYSERR);
+ }
else
- {
- GNUNET_assert(NULL == mqm->env);
- mqm->cb(mqm->cb_cls,
- GNUNET_YES);
- }
+ {
+ mqm->cb (mqm->cb_cls,
+ GNUNET_NO);
+ }
+ }
+ else
+ {
+ GNUNET_assert (NULL == mqm->env);
+ mqm->cb (mqm->cb_cls,
+ GNUNET_YES);
}
+ }
if ((NULL != mq) ||
(NULL != cp->t))
- consider_peer_activate(cp);
+ consider_peer_activate (cp);
else
- consider_peer_destroy(cp);
+ consider_peer_destroy (cp);
if ((NULL != mq) &&
(NULL != cp->t))
- {
- /* have a new, direct path to the target, notify tunnel */
- struct CadetPeerPath *path;
-
- path = GCPP_get_path_from_route(1,
- &cp->pid);
- GCT_consider_path(cp->t,
- path,
- 0);
- }
+ {
+ /* have a new, direct path to the target, notify tunnel */
+ struct CadetPeerPath *path;
+
+ path = GCPP_get_path_from_route (1,
+ &cp->pid);
+ GCT_consider_path (cp->t,
+ path,
+ 0);
+ }
}
@@ -595,12 +600,12 @@ GCP_set_mq(struct CadetPeer *cp,
* @return #GNUNET_YES or #GNUNET_NO with the decision to drop.
*/
static int
-should_I_drop(void)
+should_I_drop (void)
{
if (0 == drop_percent)
return GNUNET_NO;
- if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
- 101) < drop_percent)
+ if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ 101) < drop_percent)
return GNUNET_YES;
return GNUNET_NO;
}
@@ -613,7 +618,7 @@ should_I_drop(void)
* @param cls the `struct CadetPeeer` where we made progress
*/
static void
-mqm_send_done(void *cls);
+mqm_send_done (void *cls);
/**
@@ -622,7 +627,7 @@ mqm_send_done(void *cls);
* @param mqm mqm to transmit message for now
*/
static void
-mqm_execute(struct GCP_MessageQueueManager *mqm)
+mqm_execute (struct GCP_MessageQueueManager *mqm)
{
struct CadetPeer *cp = mqm->cp;
@@ -632,59 +637,59 @@ mqm_execute(struct GCP_MessageQueueManager *mqm)
cp->mqm_ready_ptr = mqm->next;
/* Move entry to the end of the DLL, to be fair. */
if (mqm != cp->mqm_tail)
- {
- GNUNET_CONTAINER_DLL_remove(cp->mqm_head,
- cp->mqm_tail,
- mqm);
- GNUNET_CONTAINER_DLL_insert_tail(cp->mqm_head,
- cp->mqm_tail,
- mqm);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (cp->mqm_head,
+ cp->mqm_tail,
+ mqm);
+ GNUNET_CONTAINER_DLL_insert_tail (cp->mqm_head,
+ cp->mqm_tail,
+ mqm);
+ }
cp->mqm_ready_counter--;
- if (GNUNET_YES == should_I_drop())
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "DROPPING message to peer %s from MQM %p\n",
- GCP_2s(cp),
- mqm);
- GNUNET_MQ_discard(mqm->env);
- mqm->env = NULL;
- mqm_send_done(cp);
- }
+ if (GNUNET_YES == should_I_drop ())
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "DROPPING message to peer %s from MQM %p\n",
+ GCP_2s (cp),
+ mqm);
+ GNUNET_MQ_discard (mqm->env);
+ mqm->env = NULL;
+ mqm_send_done (cp);
+ }
else
+ {
{
+ const struct GNUNET_MessageHeader *mh;
+
+ mh = GNUNET_MQ_env_get_msg (mqm->env);
+ switch (ntohs (mh->type))
{
- const struct GNUNET_MessageHeader *mh;
-
- mh = GNUNET_MQ_env_get_msg(mqm->env);
- switch (ntohs(mh->type))
- {
- case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX:
- {
- const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg
- = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *)mh;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "P2P forwarding KX with ephemeral %s to %s on CID %s\n",
- GNUNET_e2s(&msg->ephemeral_key),
- GCP_2s(cp),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- }
- break;
-
- default:
- break;
- }
+ case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX:
+ {
+ const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg
+ = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "P2P forwarding KX with ephemeral %s to %s on CID %s\n",
+ GNUNET_e2s (&msg->ephemeral_key),
+ GCP_2s (cp),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ }
+ break;
+
+ default:
+ break;
}
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending to peer %s from MQM %p\n",
- GCP_2s(cp),
- mqm);
- GNUNET_MQ_send(cp->core_mq,
- mqm->env);
- mqm->env = NULL;
}
- mqm->cb(mqm->cb_cls,
- GNUNET_YES);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending to peer %s from MQM %p\n",
+ GCP_2s (cp),
+ mqm);
+ GNUNET_MQ_send (cp->core_mq,
+ mqm->env);
+ mqm->env = NULL;
+ }
+ mqm->cb (mqm->cb_cls,
+ GNUNET_YES);
}
@@ -696,7 +701,7 @@ mqm_execute(struct GCP_MessageQueueManager *mqm)
* @param cp peer to try to send the next ready message to
*/
static void
-send_next_ready(struct CadetPeer *cp)
+send_next_ready (struct CadetPeer *cp)
{
struct GCP_MessageQueueManager *mqm;
@@ -707,7 +712,7 @@ send_next_ready(struct CadetPeer *cp)
cp->mqm_ready_ptr = mqm->next;
if (NULL == mqm)
return; /* nothing to do */
- mqm_execute(mqm);
+ mqm_execute (mqm);
}
@@ -718,14 +723,14 @@ send_next_ready(struct CadetPeer *cp)
* @param cls the `struct CadetPeeer` where we made progress
*/
static void
-mqm_send_done(void *cls)
+mqm_send_done (void *cls)
{
struct CadetPeer *cp = cls;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending to peer %s completed\n",
- GCP_2s(cp));
- send_next_ready(cp);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending to peer %s completed\n",
+ GCP_2s (cp));
+ send_next_ready (cp);
}
@@ -737,30 +742,30 @@ mqm_send_done(void *cls)
* yet have a #GNUNET_MQ_notify_sent() callback attached to it
*/
void
-GCP_send(struct GCP_MessageQueueManager *mqm,
- struct GNUNET_MQ_Envelope *env)
+GCP_send (struct GCP_MessageQueueManager *mqm,
+ struct GNUNET_MQ_Envelope *env)
{
struct CadetPeer *cp = mqm->cp;
- GNUNET_assert(NULL != env);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Queueing message to peer %s in MQM %p\n",
- GCP_2s(cp),
- mqm);
- GNUNET_assert(NULL != cp->core_mq);
- GNUNET_assert(NULL == mqm->env);
- GNUNET_MQ_notify_sent(env,
- &mqm_send_done,
- cp);
+ GNUNET_assert (NULL != env);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Queueing message to peer %s in MQM %p\n",
+ GCP_2s (cp),
+ mqm);
+ GNUNET_assert (NULL != cp->core_mq);
+ GNUNET_assert (NULL == mqm->env);
+ GNUNET_MQ_notify_sent (env,
+ &mqm_send_done,
+ cp);
mqm->env = env;
cp->mqm_ready_counter++;
if (mqm != cp->mqm_ready_ptr)
cp->mqm_ready_ptr = cp->mqm_head;
if (1 == cp->mqm_ready_counter)
cp->mqm_ready_ptr = mqm;
- if (0 != GNUNET_MQ_get_length(cp->core_mq))
+ if (0 != GNUNET_MQ_get_length (cp->core_mq))
return;
- send_next_ready(cp);
+ send_next_ready (cp);
}
@@ -773,18 +778,18 @@ GCP_send(struct GCP_MessageQueueManager *mqm,
* @return #GNUNET_OK (continue to iterate)
*/
static int
-destroy_iterator_cb(void *cls,
- const struct GNUNET_PeerIdentity *pid,
- void *value)
+destroy_iterator_cb (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
{
struct CadetPeer *cp = value;
if (NULL != cp->destroy_task)
- {
- GNUNET_SCHEDULER_cancel(cp->destroy_task);
- cp->destroy_task = NULL;
- }
- destroy_peer(cp);
+ {
+ GNUNET_SCHEDULER_cancel (cp->destroy_task);
+ cp->destroy_task = NULL;
+ }
+ destroy_peer (cp);
return GNUNET_OK;
}
@@ -795,13 +800,13 @@ destroy_iterator_cb(void *cls,
* connections are down.
*/
void
-GCP_destroy_all_peers()
+GCP_destroy_all_peers ()
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Destroying all peers now\n");
- GNUNET_CONTAINER_multipeermap_iterate(peers,
- &destroy_iterator_cb,
- NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying all peers now\n");
+ GNUNET_CONTAINER_multipeermap_iterate (peers,
+ &destroy_iterator_cb,
+ NULL);
}
@@ -812,17 +817,17 @@ GCP_destroy_all_peers()
* @param cp peer to drop paths to
*/
void
-GCP_drop_owned_paths(struct CadetPeer *cp)
+GCP_drop_owned_paths (struct CadetPeer *cp)
{
struct CadetPeerPath *path;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Destroying all paths to %s\n",
- GCP_2s(cp));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying all paths to %s\n",
+ GCP_2s (cp));
while (NULL != (path =
- GNUNET_CONTAINER_heap_remove_root(cp->path_heap)))
- GCPP_release(path);
- GNUNET_CONTAINER_heap_destroy(cp->path_heap);
+ GNUNET_CONTAINER_heap_remove_root (cp->path_heap)))
+ GCPP_release (path);
+ GNUNET_CONTAINER_heap_destroy (cp->path_heap);
cp->path_heap = NULL;
}
@@ -835,55 +840,55 @@ GCP_drop_owned_paths(struct CadetPeer *cp)
* @param off offset of this peer on the path
*/
void
-GCP_path_entry_add(struct CadetPeer *cp,
- struct CadetPeerPathEntry *entry,
- unsigned int off)
+GCP_path_entry_add (struct CadetPeer *cp,
+ struct CadetPeerPathEntry *entry,
+ unsigned int off)
{
- GNUNET_assert(cp == GCPP_get_peer_at_offset(entry->path,
- off));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Discovered that peer %s is on path %s at offset %u\n",
- GCP_2s(cp),
- GCPP_2s(entry->path),
- off);
+ GNUNET_assert (cp == GCPP_get_peer_at_offset (entry->path,
+ off));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Discovered that peer %s is on path %s at offset %u\n",
+ GCP_2s (cp),
+ GCPP_2s (entry->path),
+ off);
if (off >= cp->path_dll_length)
- {
- unsigned int len = cp->path_dll_length;
-
- GNUNET_array_grow(cp->path_heads,
- len,
- off + 4);
- GNUNET_array_grow(cp->path_tails,
- cp->path_dll_length,
- off + 4);
- }
- GNUNET_CONTAINER_DLL_insert(cp->path_heads[off],
- cp->path_tails[off],
- entry);
+ {
+ unsigned int len = cp->path_dll_length;
+
+ GNUNET_array_grow (cp->path_heads,
+ len,
+ off + 4);
+ GNUNET_array_grow (cp->path_tails,
+ cp->path_dll_length,
+ off + 4);
+ }
+ GNUNET_CONTAINER_DLL_insert (cp->path_heads[off],
+ cp->path_tails[off],
+ entry);
cp->off_sum += off;
cp->num_paths++;
/* If we have a tunnel to this peer, tell the tunnel that there is a
new path available. */
if (NULL != cp->t)
- GCT_consider_path(cp->t,
- entry->path,
- off);
+ GCT_consider_path (cp->t,
+ entry->path,
+ off);
if ((NULL != cp->search_h) &&
(DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths))
- {
- /* Now I have enough paths, stop search */
- GCD_search_stop(cp->search_h);
- cp->search_h = NULL;
- }
+ {
+ /* Now I have enough paths, stop search */
+ GCD_search_stop (cp->search_h);
+ cp->search_h = NULL;
+ }
if (NULL != cp->destroy_task)
- {
- /* paths changed, this resets the destroy timeout counter
- and aborts a destroy task that may no longer be valid
- to have (as we now have more paths via this peer). */
- consider_peer_destroy(cp);
- }
+ {
+ /* paths changed, this resets the destroy timeout counter
+ and aborts a destroy task that may no longer be valid
+ to have (as we now have more paths via this peer). */
+ consider_peer_destroy (cp);
+ }
}
@@ -895,19 +900,19 @@ GCP_path_entry_add(struct CadetPeer *cp,
* @param off offset of this peer on the path
*/
void
-GCP_path_entry_remove(struct CadetPeer *cp,
- struct CadetPeerPathEntry *entry,
- unsigned int off)
+GCP_path_entry_remove (struct CadetPeer *cp,
+ struct CadetPeerPathEntry *entry,
+ unsigned int off)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Removing knowledge about peer %s beging on path %s at offset %u\n",
- GCP_2s(cp),
- GCPP_2s(entry->path),
- off);
- GNUNET_CONTAINER_DLL_remove(cp->path_heads[off],
- cp->path_tails[off],
- entry);
- GNUNET_assert(0 < cp->num_paths);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing knowledge about peer %s beging on path %s at offset %u\n",
+ GCP_2s (cp),
+ GCPP_2s (entry->path),
+ off);
+ GNUNET_CONTAINER_DLL_remove (cp->path_heads[off],
+ cp->path_tails[off],
+ entry);
+ GNUNET_assert (0 < cp->num_paths);
cp->off_sum -= off;
cp->num_paths--;
if ((NULL == cp->core_mq) &&
@@ -915,12 +920,12 @@ GCP_path_entry_remove(struct CadetPeer *cp,
(NULL == cp->search_h) &&
(DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths))
cp->search_h
- = GCD_search(&cp->pid);
+ = GCD_search (&cp->pid);
if (NULL == cp->destroy_task)
- {
- /* paths changed, we might now be ready for destruction, check again */
- consider_peer_destroy(cp);
- }
+ {
+ /* paths changed, we might now be ready for destruction, check again */
+ consider_peer_destroy (cp);
+ }
}
@@ -931,32 +936,32 @@ GCP_path_entry_remove(struct CadetPeer *cp,
* @param cls the `struct CadetPeer` to maintain the path heap for
*/
static void
-path_heap_cleanup(void *cls)
+path_heap_cleanup (void *cls)
{
struct CadetPeer *cp = cls;
struct CadetPeerPath *root;
cp->heap_cleanup_task = NULL;
- while (GNUNET_CONTAINER_heap_get_size(cp->path_heap) >=
+ while (GNUNET_CONTAINER_heap_get_size (cp->path_heap) >=
2 * DESIRED_CONNECTIONS_PER_TUNNEL)
- {
- /* Now we have way too many, drop least desirable UNLESS it is in use!
- (Note that this intentionally keeps highly desireable, but currently
- unused paths around in the hope that we might be able to switch, even
- if the number of paths exceeds the threshold.) */
- root = GNUNET_CONTAINER_heap_peek(cp->path_heap);
- GNUNET_assert(NULL != root);
- if (NULL !=
- GCPP_get_connection(root,
- cp,
- GCPP_get_length(root) - 1))
- break; /* can't fix */
- /* Got plenty of paths to this destination, and this is a low-quality
- one that we don't care about. Allow it to die. */
- GNUNET_assert(root ==
- GNUNET_CONTAINER_heap_remove_root(cp->path_heap));
- GCPP_release(root);
- }
+ {
+ /* Now we have way too many, drop least desirable UNLESS it is in use!
+ (Note that this intentionally keeps highly desireable, but currently
+ unused paths around in the hope that we might be able to switch, even
+ if the number of paths exceeds the threshold.) */
+ root = GNUNET_CONTAINER_heap_peek (cp->path_heap);
+ GNUNET_assert (NULL != root);
+ if (NULL !=
+ GCPP_get_connection (root,
+ cp,
+ GCPP_get_length (root) - 1))
+ break; /* can't fix */
+ /* Got plenty of paths to this destination, and this is a low-quality
+ one that we don't care about. Allow it to die. */
+ GNUNET_assert (root ==
+ GNUNET_CONTAINER_heap_remove_root (cp->path_heap));
+ GCPP_release (root);
+ }
}
@@ -972,66 +977,66 @@ path_heap_cleanup(void *cls)
* otherwise the node in the peer's path heap for the @a path.
*/
struct GNUNET_CONTAINER_HeapNode *
-GCP_attach_path(struct CadetPeer *cp,
- struct CadetPeerPath *path,
- unsigned int off,
- int force)
+GCP_attach_path (struct CadetPeer *cp,
+ struct CadetPeerPath *path,
+ unsigned int off,
+ int force)
{
GNUNET_CONTAINER_HeapCostType desirability;
struct CadetPeerPath *root;
GNUNET_CONTAINER_HeapCostType root_desirability;
struct GNUNET_CONTAINER_HeapNode *hn;
- GNUNET_assert(off == GCPP_get_length(path) - 1);
- GNUNET_assert(cp == GCPP_get_peer_at_offset(path,
- off));
+ GNUNET_assert (off == GCPP_get_length (path) - 1);
+ GNUNET_assert (cp == GCPP_get_peer_at_offset (path,
+ off));
if (NULL == cp->path_heap)
- {
- /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */
- GNUNET_assert(GNUNET_NO == force);
- return NULL;
- }
- desirability = GCPP_get_desirability(path);
+ {
+ /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */
+ GNUNET_assert (GNUNET_NO == force);
+ return NULL;
+ }
+ desirability = GCPP_get_desirability (path);
if (GNUNET_NO == force)
+ {
+ /* FIXME: desirability is not yet initialized; tricky! */
+ if (GNUNET_NO ==
+ GNUNET_CONTAINER_heap_peek2 (cp->path_heap,
+ (void **) &root,
+ &root_desirability))
{
- /* FIXME: desirability is not yet initialized; tricky! */
- if (GNUNET_NO ==
- GNUNET_CONTAINER_heap_peek2(cp->path_heap,
- (void **)&root,
- &root_desirability))
- {
- root = NULL;
- root_desirability = 0;
- }
+ root = NULL;
+ root_desirability = 0;
+ }
- if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) &&
- (desirability < root_desirability))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Decided to not attach path %s to peer %s due to undesirability\n",
- GCPP_2s(path),
- GCP_2s(cp));
- return NULL;
- }
+ if ((DESIRED_CONNECTIONS_PER_TUNNEL > cp->num_paths) &&
+ (desirability < root_desirability))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Decided to not attach path %s to peer %s due to undesirability\n",
+ GCPP_2s (path),
+ GCP_2s (cp));
+ return NULL;
}
+ }
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Attaching path %s to peer %s (%s)\n",
- GCPP_2s(path),
- GCP_2s(cp),
- (GNUNET_NO == force) ? "desirable" : "forced");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Attaching path %s to peer %s (%s)\n",
+ GCPP_2s (path),
+ GCP_2s (cp),
+ (GNUNET_NO == force) ? "desirable" : "forced");
/* Yes, we'd like to add this path, add to our heap */
- hn = GNUNET_CONTAINER_heap_insert(cp->path_heap,
- path,
- desirability);
+ hn = GNUNET_CONTAINER_heap_insert (cp->path_heap,
+ path,
+ desirability);
/* Consider maybe dropping other paths because of the new one */
- if ((GNUNET_CONTAINER_heap_get_size(cp->path_heap) >=
+ if ((GNUNET_CONTAINER_heap_get_size (cp->path_heap) >=
2 * DESIRED_CONNECTIONS_PER_TUNNEL) &&
(NULL != cp->heap_cleanup_task))
- cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now(&path_heap_cleanup,
- cp);
+ cp->heap_cleanup_task = GNUNET_SCHEDULER_add_now (&path_heap_cleanup,
+ cp);
return hn;
}
@@ -1046,16 +1051,16 @@ GCP_attach_path(struct CadetPeer *cp,
* @param hn note in @a cp's path heap that must be deleted
*/
void
-GCP_detach_path(struct CadetPeer *cp,
- struct CadetPeerPath *path,
- struct GNUNET_CONTAINER_HeapNode *hn)
+GCP_detach_path (struct CadetPeer *cp,
+ struct CadetPeerPath *path,
+ struct GNUNET_CONTAINER_HeapNode *hn)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Detatching path %s from peer %s\n",
- GCPP_2s(path),
- GCP_2s(cp));
- GNUNET_assert(path ==
- GNUNET_CONTAINER_heap_remove_node(hn));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Detatching path %s from peer %s\n",
+ GCPP_2s (path),
+ GCP_2s (cp));
+ GNUNET_assert (path ==
+ GNUNET_CONTAINER_heap_remove_node (hn));
}
@@ -1066,23 +1071,24 @@ GCP_detach_path(struct CadetPeer *cp,
* @param cc the connection to add
*/
void
-GCP_add_connection(struct CadetPeer *cp,
- struct CadetConnection *cc)
+GCP_add_connection (struct CadetPeer *cp,
+ struct CadetConnection *cc)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Adding %s to peer %s\n",
- GCC_2s(cc),
- GCP_2s(cp));
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONTAINER_multishortmap_put(cp->connections,
- &GCC_get_id(cc)->connection_of_tunnel,
- cc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding %s to peer %s\n",
+ GCC_2s (cc),
+ GCP_2s (cp));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multishortmap_put (cp->connections,
+ &GCC_get_id (
+ cc)->connection_of_tunnel,
+ cc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
if (NULL != cp->destroy_task)
- {
- GNUNET_SCHEDULER_cancel(cp->destroy_task);
- cp->destroy_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (cp->destroy_task);
+ cp->destroy_task = NULL;
+ }
}
@@ -1093,18 +1099,20 @@ GCP_add_connection(struct CadetPeer *cp,
* @param cc the connection to remove
*/
void
-GCP_remove_connection(struct CadetPeer *cp,
- struct CadetConnection *cc)
+GCP_remove_connection (struct CadetPeer *cp,
+ struct CadetConnection *cc)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Removing connection %s from peer %s\n",
- GCC_2s(cc),
- GCP_2s(cp));
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multishortmap_remove(cp->connections,
- &GCC_get_id(cc)->connection_of_tunnel,
- cc));
- consider_peer_destroy(cp);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Removing connection %s from peer %s\n",
+ GCC_2s (cc),
+ GCP_2s (cp));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multishortmap_remove (cp->connections,
+ &GCC_get_id (
+ cc)->
+ connection_of_tunnel,
+ cc));
+ consider_peer_destroy (cp);
}
@@ -1120,30 +1128,31 @@ GCP_remove_connection(struct CadetPeer *cp,
* NULL if unknown and not requested @a create
*/
struct CadetPeer *
-GCP_get(const struct GNUNET_PeerIdentity *peer_id,
- int create)
+GCP_get (const struct GNUNET_PeerIdentity *peer_id,
+ int create)
{
struct CadetPeer *cp;
- cp = GNUNET_CONTAINER_multipeermap_get(peers,
- peer_id);
+ cp = GNUNET_CONTAINER_multipeermap_get (peers,
+ peer_id);
if (NULL != cp)
return cp;
if (GNUNET_NO == create)
return NULL;
- cp = GNUNET_new(struct CadetPeer);
+ cp = GNUNET_new (struct CadetPeer);
cp->pid = *peer_id;
- cp->connections = GNUNET_CONTAINER_multishortmap_create(32,
- GNUNET_YES);
- cp->path_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_put(peers,
- &cp->pid,
- cp,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating peer %s\n",
- GCP_2s(cp));
+ cp->connections = GNUNET_CONTAINER_multishortmap_create (32,
+ GNUNET_YES);
+ cp->path_heap = GNUNET_CONTAINER_heap_create (
+ GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_put (peers,
+ &cp->pid,
+ cp,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating peer %s\n",
+ GCP_2s (cp));
return cp;
}
@@ -1155,7 +1164,7 @@ GCP_get(const struct GNUNET_PeerIdentity *peer_id,
* @return the peer identity
*/
const struct GNUNET_PeerIdentity *
-GCP_get_id(struct CadetPeer *cp)
+GCP_get_id (struct CadetPeer *cp)
{
return &cp->pid;
}
@@ -1168,12 +1177,12 @@ GCP_get_id(struct CadetPeer *cp)
* @param cls Closure for @c iter.
*/
void
-GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
- void *cls)
+GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
+ void *cls)
{
- GNUNET_CONTAINER_multipeermap_iterate(peers,
- iter,
- cls);
+ GNUNET_CONTAINER_multipeermap_iterate (peers,
+ iter,
+ cls);
}
@@ -1184,7 +1193,7 @@ GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
* @return Number of known paths.
*/
unsigned int
-GCP_count_paths(const struct CadetPeer *cp)
+GCP_count_paths (const struct CadetPeer *cp)
{
return cp->num_paths;
}
@@ -1199,45 +1208,45 @@ GCP_count_paths(const struct CadetPeer *cp)
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_paths(struct CadetPeer *cp,
- GCP_PathIterator callback,
- void *callback_cls)
+GCP_iterate_paths (struct CadetPeer *cp,
+ GCP_PathIterator callback,
+ void *callback_cls)
{
unsigned int ret = 0;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Iterating over paths to peer %s%s\n",
- GCP_2s(cp),
- (NULL == cp->core_mq) ? "" : " including direct link");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Iterating over paths to peer %s%s\n",
+ GCP_2s (cp),
+ (NULL == cp->core_mq) ? "" : " including direct link");
if (NULL != cp->core_mq)
+ {
+ /* FIXME: this branch seems to duplicate the
+ i=0 case below (direct link). Leave out!??? -CG */
+ struct CadetPeerPath *path;
+
+ path = GCPP_get_path_from_route (1,
+ &cp->pid);
+ ret++;
+ if (GNUNET_NO ==
+ callback (callback_cls,
+ path,
+ 0))
+ return ret;
+ }
+ for (unsigned int i = 0; i < cp->path_dll_length; i++)
+ {
+ for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
+ NULL != pe;
+ pe = pe->next)
{
- /* FIXME: this branch seems to duplicate the
- i=0 case below (direct link). Leave out!??? -CG */
- struct CadetPeerPath *path;
-
- path = GCPP_get_path_from_route(1,
- &cp->pid);
ret++;
if (GNUNET_NO ==
- callback(callback_cls,
- path,
- 0))
+ callback (callback_cls,
+ pe->path,
+ i))
return ret;
}
- for (unsigned int i = 0; i < cp->path_dll_length; i++)
- {
- for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
- NULL != pe;
- pe = pe->next)
- {
- ret++;
- if (GNUNET_NO ==
- callback(callback_cls,
- pe->path,
- i))
- return ret;
- }
- }
+ }
return ret;
}
@@ -1250,29 +1259,29 @@ GCP_iterate_paths(struct CadetPeer *cp,
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_indirect_paths(struct CadetPeer *cp,
- GCP_PathIterator callback,
- void *callback_cls)
+GCP_iterate_indirect_paths (struct CadetPeer *cp,
+ GCP_PathIterator callback,
+ void *callback_cls)
{
unsigned int ret = 0;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Iterating over paths to peer %s without direct link\n",
- GCP_2s(cp));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Iterating over paths to peer %s without direct link\n",
+ GCP_2s (cp));
for (unsigned int i = 1; i < cp->path_dll_length; i++)
+ {
+ for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
+ NULL != pe;
+ pe = pe->next)
{
- for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
- NULL != pe;
- pe = pe->next)
- {
- ret++;
- if (GNUNET_NO ==
- callback(callback_cls,
- pe->path,
- i))
- return ret;
- }
+ ret++;
+ if (GNUNET_NO ==
+ callback (callback_cls,
+ pe->path,
+ i))
+ return ret;
}
+ }
return ret;
}
@@ -1288,32 +1297,32 @@ GCP_iterate_indirect_paths(struct CadetPeer *cp,
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_paths_at(struct CadetPeer *cp,
- unsigned int dist,
- GCP_PathIterator callback,
- void *callback_cls)
+GCP_iterate_paths_at (struct CadetPeer *cp,
+ unsigned int dist,
+ GCP_PathIterator callback,
+ void *callback_cls)
{
unsigned int ret = 0;
if (dist >= cp->path_dll_length)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Asked to look for paths at distance %u, but maximum for me is < %u\n",
- dist,
- cp->path_dll_length);
- return 0;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Asked to look for paths at distance %u, but maximum for me is < %u\n",
+ dist,
+ cp->path_dll_length);
+ return 0;
+ }
for (struct CadetPeerPathEntry *pe = cp->path_heads[dist];
NULL != pe;
pe = pe->next)
- {
- if (GNUNET_NO ==
- callback(callback_cls,
- pe->path,
- dist))
- return ret;
- ret++;
- }
+ {
+ if (GNUNET_NO ==
+ callback (callback_cls,
+ pe->path,
+ dist))
+ return ret;
+ ret++;
+ }
return ret;
}
@@ -1326,16 +1335,16 @@ GCP_iterate_paths_at(struct CadetPeer *cp,
* @return Tunnel towards peer.
*/
struct CadetTunnel *
-GCP_get_tunnel(struct CadetPeer *cp,
- int create)
+GCP_get_tunnel (struct CadetPeer *cp,
+ int create)
{
if (NULL == cp)
return NULL;
if ((NULL != cp->t) ||
(GNUNET_NO == create))
return cp->t;
- cp->t = GCT_create_tunnel(cp);
- consider_peer_activate(cp);
+ cp->t = GCT_create_tunnel (cp);
+ consider_peer_activate (cp);
return cp->t;
}
@@ -1347,7 +1356,7 @@ GCP_get_tunnel(struct CadetPeer *cp,
* @param cls the `struct CadetPeer` where the offer completed
*/
static void
-hello_offer_done(void *cls)
+hello_offer_done (void *cls)
{
struct CadetPeer *cp = cls;
@@ -1363,39 +1372,39 @@ hello_offer_done(void *cls)
* @param hello the HELLO to remember
*/
void
-GCP_set_hello(struct CadetPeer *cp,
- const struct GNUNET_HELLO_Message *hello)
+GCP_set_hello (struct CadetPeer *cp,
+ const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_HELLO_Message *mrg;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Got %u byte HELLO for peer %s\n",
- (unsigned int)GNUNET_HELLO_size(hello),
- GCP_2s(cp));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Got %u byte HELLO for peer %s\n",
+ (unsigned int) GNUNET_HELLO_size (hello),
+ GCP_2s (cp));
if (NULL != cp->hello_offer)
- {
- GNUNET_TRANSPORT_offer_hello_cancel(cp->hello_offer);
- cp->hello_offer = NULL;
- }
+ {
+ GNUNET_TRANSPORT_offer_hello_cancel (cp->hello_offer);
+ cp->hello_offer = NULL;
+ }
if (NULL != cp->hello)
- {
- mrg = GNUNET_HELLO_merge(hello,
- cp->hello);
- GNUNET_free(cp->hello);
- cp->hello = mrg;
- }
+ {
+ mrg = GNUNET_HELLO_merge (hello,
+ cp->hello);
+ GNUNET_free (cp->hello);
+ cp->hello = mrg;
+ }
else
- {
- cp->hello = GNUNET_memdup(hello,
- GNUNET_HELLO_size(hello));
- }
+ {
+ cp->hello = GNUNET_memdup (hello,
+ GNUNET_HELLO_size (hello));
+ }
cp->hello_offer
- = GNUNET_TRANSPORT_offer_hello(cfg,
- GNUNET_HELLO_get_header(cp->hello),
- &hello_offer_done,
- cp);
+ = GNUNET_TRANSPORT_offer_hello (cfg,
+ GNUNET_HELLO_get_header (cp->hello),
+ &hello_offer_done,
+ cp);
/* New HELLO means cp's destruction time may change... */
- consider_peer_destroy(cp);
+ consider_peer_destroy (cp);
}
@@ -1407,16 +1416,16 @@ GCP_set_hello(struct CadetPeer *cp,
* @param t the dead tunnel
*/
void
-GCP_drop_tunnel(struct CadetPeer *cp,
- struct CadetTunnel *t)
+GCP_drop_tunnel (struct CadetPeer *cp,
+ struct CadetTunnel *t)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Dropping tunnel %s to peer %s\n",
- GCT_2s(t),
- GCP_2s(cp));
- GNUNET_assert(cp->t == t);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Dropping tunnel %s to peer %s\n",
+ GCT_2s (t),
+ GCP_2s (cp));
+ GNUNET_assert (cp->t == t);
cp->t = NULL;
- consider_peer_destroy(cp);
+ consider_peer_destroy (cp);
}
@@ -1427,7 +1436,7 @@ GCP_drop_tunnel(struct CadetPeer *cp,
* @return #GNUNET_YES if @a cp has a core-level connection
*/
int
-GCP_has_core_connection(struct CadetPeer *cp)
+GCP_has_core_connection (struct CadetPeer *cp)
{
return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO;
}
@@ -1442,26 +1451,26 @@ GCP_has_core_connection(struct CadetPeer *cp)
* @return handle to cancel request
*/
struct GCP_MessageQueueManager *
-GCP_request_mq(struct CadetPeer *cp,
- GCP_MessageQueueNotificationCallback cb,
- void *cb_cls)
+GCP_request_mq (struct CadetPeer *cp,
+ GCP_MessageQueueNotificationCallback cb,
+ void *cb_cls)
{
struct GCP_MessageQueueManager *mqm;
- mqm = GNUNET_new(struct GCP_MessageQueueManager);
+ mqm = GNUNET_new (struct GCP_MessageQueueManager);
mqm->cb = cb;
mqm->cb_cls = cb_cls;
mqm->cp = cp;
- GNUNET_CONTAINER_DLL_insert(cp->mqm_head,
- cp->mqm_tail,
- mqm);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating MQM %p for peer %s\n",
- mqm,
- GCP_2s(cp));
+ GNUNET_CONTAINER_DLL_insert (cp->mqm_head,
+ cp->mqm_tail,
+ mqm);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating MQM %p for peer %s\n",
+ mqm,
+ GCP_2s (cp));
if (NULL != cp->core_mq)
- cb(cb_cls,
- GNUNET_YES);
+ cb (cb_cls,
+ GNUNET_YES);
return mqm;
}
@@ -1473,39 +1482,39 @@ GCP_request_mq(struct CadetPeer *cp,
* @param last_env final message to transmit, or NULL
*/
void
-GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
- struct GNUNET_MQ_Envelope *last_env)
+GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
+ struct GNUNET_MQ_Envelope *last_env)
{
struct CadetPeer *cp = mqm->cp;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Destroying MQM %p for peer %s%s\n",
- mqm,
- GCP_2s(cp),
- (NULL == last_env) ? "" : " with last ditch transmission");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Destroying MQM %p for peer %s%s\n",
+ mqm,
+ GCP_2s (cp),
+ (NULL == last_env) ? "" : " with last ditch transmission");
if (NULL != mqm->env)
- GNUNET_MQ_discard(mqm->env);
+ GNUNET_MQ_discard (mqm->env);
if (NULL != last_env)
+ {
+ if (NULL != cp->core_mq)
{
- if (NULL != cp->core_mq)
- {
- GNUNET_MQ_notify_sent(last_env,
- &mqm_send_done,
- cp);
- GNUNET_MQ_send(cp->core_mq,
- last_env);
- }
- else
- {
- GNUNET_MQ_discard(last_env);
- }
+ GNUNET_MQ_notify_sent (last_env,
+ &mqm_send_done,
+ cp);
+ GNUNET_MQ_send (cp->core_mq,
+ last_env);
}
+ else
+ {
+ GNUNET_MQ_discard (last_env);
+ }
+ }
if (cp->mqm_ready_ptr == mqm)
cp->mqm_ready_ptr = mqm->next;
- GNUNET_CONTAINER_DLL_remove(cp->mqm_head,
- cp->mqm_tail,
- mqm);
- GNUNET_free(mqm);
+ GNUNET_CONTAINER_DLL_remove (cp->mqm_head,
+ cp->mqm_tail,
+ mqm);
+ GNUNET_free (mqm);
}
@@ -1519,27 +1528,27 @@ GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
* @param env envelope with the message to send
*/
void
-GCP_send_ooo(struct CadetPeer *cp,
- struct GNUNET_MQ_Envelope *env)
+GCP_send_ooo (struct CadetPeer *cp,
+ struct GNUNET_MQ_Envelope *env)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending message to %s out of management\n",
- GCP_2s(cp));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending message to %s out of management\n",
+ GCP_2s (cp));
if (NULL == cp->core_mq)
- {
- GNUNET_MQ_discard(env);
- return;
- }
- if (GNUNET_MQ_get_length(cp->core_mq) > MAX_OOO_QUEUE_SIZE)
- {
- GNUNET_MQ_discard(env);
- return;
- }
- GNUNET_MQ_notify_sent(env,
- &mqm_send_done,
- cp);
- GNUNET_MQ_send(cp->core_mq,
- env);
+ {
+ GNUNET_MQ_discard (env);
+ return;
+ }
+ if (GNUNET_MQ_get_length (cp->core_mq) > MAX_OOO_QUEUE_SIZE)
+ {
+ GNUNET_MQ_discard (env);
+ return;
+ }
+ GNUNET_MQ_notify_sent (env,
+ &mqm_send_done,
+ cp);
+ GNUNET_MQ_send (cp->core_mq,
+ env);
}
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index 09c6f64c9..bec0606a0 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -39,7 +39,7 @@
* @return Static string for it's ID.
*/
const char *
-GCP_2s(const struct CadetPeer *peer);
+GCP_2s (const struct CadetPeer *peer);
/**
@@ -54,8 +54,8 @@ GCP_2s(const struct CadetPeer *peer);
* NULL if unknown and not requested @a create
*/
struct CadetPeer *
-GCP_get(const struct GNUNET_PeerIdentity *peer_id,
- int create);
+GCP_get (const struct GNUNET_PeerIdentity *peer_id,
+ int create);
/**
@@ -68,8 +68,8 @@ GCP_get(const struct GNUNET_PeerIdentity *peer_id,
* positive scores mean path is more desirable
*/
double
-GCP_get_desirability_of_path(struct CadetPeer *cp,
- unsigned int off);
+GCP_get_desirability_of_path (struct CadetPeer *cp,
+ unsigned int off);
/**
@@ -79,7 +79,7 @@ GCP_get_desirability_of_path(struct CadetPeer *cp,
* @return the peer identity
*/
const struct GNUNET_PeerIdentity *
-GCP_get_id(struct CadetPeer *cp);
+GCP_get_id (struct CadetPeer *cp);
/**
@@ -89,8 +89,8 @@ GCP_get_id(struct CadetPeer *cp);
* @param cls Closure for @c iter.
*/
void
-GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
- void *cls);
+GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
+ void *cls);
/**
@@ -100,7 +100,7 @@ GCP_iterate_all(GNUNET_CONTAINER_PeerMapIterator iter,
* @return Number of known paths.
*/
unsigned int
-GCP_count_paths(const struct CadetPeer *cp);
+GCP_count_paths (const struct CadetPeer *cp);
/**
@@ -110,7 +110,7 @@ GCP_count_paths(const struct CadetPeer *cp);
* @param cp peer to drop paths to
*/
void
-GCP_drop_owned_paths(struct CadetPeer *cp);
+GCP_drop_owned_paths (struct CadetPeer *cp);
/**
@@ -137,9 +137,9 @@ typedef int
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_paths(struct CadetPeer *cp,
- GCP_PathIterator callback,
- void *callback_cls);
+GCP_iterate_paths (struct CadetPeer *cp,
+ GCP_PathIterator callback,
+ void *callback_cls);
/**
* Iterate over the paths to a peer without direct link.
@@ -150,9 +150,9 @@ GCP_iterate_paths(struct CadetPeer *cp,
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_indirect_paths(struct CadetPeer *cp,
- GCP_PathIterator callback,
- void *callback_cls);
+GCP_iterate_indirect_paths (struct CadetPeer *cp,
+ GCP_PathIterator callback,
+ void *callback_cls);
/**
@@ -166,10 +166,10 @@ GCP_iterate_indirect_paths(struct CadetPeer *cp,
* @return Number of iterated paths.
*/
unsigned int
-GCP_iterate_paths_at(struct CadetPeer *cp,
- unsigned int dist,
- GCP_PathIterator callback,
- void *callback_cls);
+GCP_iterate_paths_at (struct CadetPeer *cp,
+ unsigned int dist,
+ GCP_PathIterator callback,
+ void *callback_cls);
/**
@@ -180,9 +180,9 @@ GCP_iterate_paths_at(struct CadetPeer *cp,
* @param off offset of this peer on the path
*/
void
-GCP_path_entry_remove(struct CadetPeer *cp,
- struct CadetPeerPathEntry *entry,
- unsigned int off);
+GCP_path_entry_remove (struct CadetPeer *cp,
+ struct CadetPeerPathEntry *entry,
+ unsigned int off);
/**
@@ -193,9 +193,9 @@ GCP_path_entry_remove(struct CadetPeer *cp,
* @param off offset of this peer on the path
*/
void
-GCP_path_entry_add(struct CadetPeer *cp,
- struct CadetPeerPathEntry *entry,
- unsigned int off);
+GCP_path_entry_add (struct CadetPeer *cp,
+ struct CadetPeerPathEntry *entry,
+ unsigned int off);
/**
@@ -206,8 +206,8 @@ GCP_path_entry_add(struct CadetPeer *cp,
* @return Tunnel towards peer.
*/
struct CadetTunnel *
-GCP_get_tunnel(struct CadetPeer *cp,
- int create);
+GCP_get_tunnel (struct CadetPeer *cp,
+ int create);
/**
@@ -218,8 +218,8 @@ GCP_get_tunnel(struct CadetPeer *cp,
* @param t the dead tunnel
*/
void
-GCP_drop_tunnel(struct CadetPeer *cp,
- struct CadetTunnel *t);
+GCP_drop_tunnel (struct CadetPeer *cp,
+ struct CadetTunnel *t);
/**
@@ -234,10 +234,10 @@ GCP_drop_tunnel(struct CadetPeer *cp,
* otherwise the node in the peer's path heap for the @a path.
*/
struct GNUNET_CONTAINER_HeapNode *
-GCP_attach_path(struct CadetPeer *cp,
- struct CadetPeerPath *path,
- unsigned int off,
- int force);
+GCP_attach_path (struct CadetPeer *cp,
+ struct CadetPeerPath *path,
+ unsigned int off,
+ int force);
/**
@@ -250,9 +250,9 @@ GCP_attach_path(struct CadetPeer *cp,
* @param hn note in @a cp's path heap that must be deleted
*/
void
-GCP_detach_path(struct CadetPeer *cp,
- struct CadetPeerPath *path,
- struct GNUNET_CONTAINER_HeapNode *hn);
+GCP_detach_path (struct CadetPeer *cp,
+ struct CadetPeerPath *path,
+ struct GNUNET_CONTAINER_HeapNode *hn);
/**
@@ -262,8 +262,8 @@ GCP_detach_path(struct CadetPeer *cp,
* @param cc the connection to add
*/
void
-GCP_add_connection(struct CadetPeer *cp,
- struct CadetConnection *cc);
+GCP_add_connection (struct CadetPeer *cp,
+ struct CadetConnection *cc);
/**
@@ -273,8 +273,8 @@ GCP_add_connection(struct CadetPeer *cp,
* @param cc the connection to remove
*/
void
-GCP_remove_connection(struct CadetPeer *cp,
- struct CadetConnection *cc);
+GCP_remove_connection (struct CadetPeer *cp,
+ struct CadetConnection *cc);
/**
@@ -285,8 +285,8 @@ GCP_remove_connection(struct CadetPeer *cp,
* @param hello the HELLO to remember
*/
void
-GCP_set_hello(struct CadetPeer *cp,
- const struct GNUNET_HELLO_Message *hello);
+GCP_set_hello (struct CadetPeer *cp,
+ const struct GNUNET_HELLO_Message *hello);
/**
@@ -295,7 +295,7 @@ GCP_set_hello(struct CadetPeer *cp,
* connections are down.
*/
void
-GCP_destroy_all_peers(void);
+GCP_destroy_all_peers (void);
/**
@@ -334,9 +334,9 @@ typedef void
* @return handle to cancel request
*/
struct GCP_MessageQueueManager *
-GCP_request_mq(struct CadetPeer *cp,
- GCP_MessageQueueNotificationCallback cb,
- void *cb_cls);
+GCP_request_mq (struct CadetPeer *cp,
+ GCP_MessageQueueNotificationCallback cb,
+ void *cb_cls);
/**
@@ -346,7 +346,7 @@ GCP_request_mq(struct CadetPeer *cp,
* @return #GNUNET_YES if @a cp has a core-level connection
*/
int
-GCP_has_core_connection(struct CadetPeer *cp);
+GCP_has_core_connection (struct CadetPeer *cp);
/**
@@ -361,8 +361,8 @@ GCP_has_core_connection(struct CadetPeer *cp);
* yet have a #GNUNET_MQ_notify_sent() callback attached to it
*/
void
-GCP_send(struct GCP_MessageQueueManager *mqm,
- struct GNUNET_MQ_Envelope *env);
+GCP_send (struct GCP_MessageQueueManager *mqm,
+ struct GNUNET_MQ_Envelope *env);
/**
@@ -375,8 +375,8 @@ GCP_send(struct GCP_MessageQueueManager *mqm,
* @param env envelope with the message to send
*/
void
-GCP_send_ooo(struct CadetPeer *cp,
- struct GNUNET_MQ_Envelope *env);
+GCP_send_ooo (struct CadetPeer *cp,
+ struct GNUNET_MQ_Envelope *env);
/**
@@ -388,8 +388,8 @@ GCP_send_ooo(struct CadetPeer *cp,
* @param last_env final message to transmit, or NULL
*/
void
-GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
- struct GNUNET_MQ_Envelope *last_env);
+GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm,
+ struct GNUNET_MQ_Envelope *last_env);
/**
@@ -399,8 +399,8 @@ GCP_request_mq_cancel(struct GCP_MessageQueueManager *mqm,
* @param mq message queue to set (can be NULL)
*/
void
-GCP_set_mq(struct CadetPeer *cp,
- struct GNUNET_MQ_Handle *mq);
+GCP_set_mq (struct CadetPeer *cp,
+ struct GNUNET_MQ_Handle *mq);
#endif
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c
index c73f8cdbe..6f2dd1d8d 100644
--- a/src/cadet/gnunet-service-cadet_tunnels.c
+++ b/src/cadet/gnunet-service-cadet_tunnels.c
@@ -42,7 +42,7 @@
#include "gnunet-service-cadet_paths.h"
-#define LOG(level, ...) GNUNET_log_from(level, "cadet-tun", __VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-tun", __VA_ARGS__)
/**
* How often do we try to decrypt payload with unverified key
@@ -54,13 +54,15 @@
/**
* How long do we wait until tearing down an idle tunnel?
*/
-#define IDLE_DESTROY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
+#define IDLE_DESTROY_DELAY GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_SECONDS, 90)
/**
* 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_KX_RETRY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250)
+#define INITIAL_KX_RETRY_DELAY GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MILLISECONDS, 250)
/**
* Maximum number of skipped keys we keep in memory per tunnel.
@@ -77,7 +79,8 @@
/**
* Struct to old keys for skipped messages while advancing the Axolotl ratchet.
*/
-struct CadetTunnelSkippedKey {
+struct CadetTunnelSkippedKey
+{
/**
* DLL next.
*/
@@ -113,7 +116,8 @@ struct CadetTunnelSkippedKey {
/**
* Axolotl data, according to https://github.com/trevp/axolotl/wiki .
*/
-struct CadetTunnelAxolotl {
+struct CadetTunnelAxolotl
+{
/**
* A (double linked) list of stored message keys and associated header keys
* for "skipped" messages, i.e. messages that have not been
@@ -252,7 +256,8 @@ struct CadetTunnelAxolotl {
/**
* Struct used to save messages in a non-ready tunnel to send once connected.
*/
-struct CadetTunnelQueueEntry {
+struct CadetTunnelQueueEntry
+{
/**
* We are entries in a DLL
*/
@@ -294,7 +299,8 @@ struct CadetTunnelQueueEntry {
/**
* Struct containing all information regarding a tunnel to a peer.
*/
-struct CadetTunnel {
+struct CadetTunnel
+{
/**
* Destination of the tunnel.
*/
@@ -459,19 +465,19 @@ struct CadetTunnel {
* @return #GNUNET_YES for Alice, #GNUNET_NO for Betty, #GNUNET_SYSERR if talking to myself
*/
static int
-alice_or_betty(const struct GNUNET_PeerIdentity *other)
+alice_or_betty (const struct GNUNET_PeerIdentity *other)
{
- if (0 > GNUNET_memcmp(&my_full_id,
- other))
+ if (0 > GNUNET_memcmp (&my_full_id,
+ other))
return GNUNET_YES;
- else if (0 < GNUNET_memcmp(&my_full_id,
- other))
+ else if (0 < GNUNET_memcmp (&my_full_id,
+ other))
return GNUNET_NO;
else
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
}
@@ -482,20 +488,20 @@ alice_or_betty(const struct GNUNET_PeerIdentity *other)
* @param ct connection to move to unready status
*/
static void
-mark_connection_unready(struct CadetTConnection *ct)
+mark_connection_unready (struct CadetTConnection *ct)
{
struct CadetTunnel *t = ct->t;
- GNUNET_assert(GNUNET_YES == ct->is_ready);
- GNUNET_CONTAINER_DLL_remove(t->connection_ready_head,
- t->connection_ready_tail,
- ct);
- GNUNET_assert(0 < t->num_ready_connections);
+ GNUNET_assert (GNUNET_YES == ct->is_ready);
+ GNUNET_CONTAINER_DLL_remove (t->connection_ready_head,
+ t->connection_ready_tail,
+ ct);
+ GNUNET_assert (0 < t->num_ready_connections);
t->num_ready_connections--;
ct->is_ready = GNUNET_NO;
- GNUNET_CONTAINER_DLL_insert(t->connection_busy_head,
- t->connection_busy_tail,
- ct);
+ GNUNET_CONTAINER_DLL_insert (t->connection_busy_head,
+ t->connection_busy_tail,
+ ct);
t->num_busy_connections++;
}
@@ -508,16 +514,16 @@ mark_connection_unready(struct CadetTConnection *ct)
* @return Static string the destination peer's ID.
*/
const char *
-GCT_2s(const struct CadetTunnel *t)
+GCT_2s (const struct CadetTunnel *t)
{
static char buf[64];
if (NULL == t)
return "Tunnel(NULL)";
- GNUNET_snprintf(buf,
- sizeof(buf),
- "Tunnel %s",
- GNUNET_i2s(GCP_get_id(t->destination)));
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "Tunnel %s",
+ GNUNET_i2s (GCP_get_id (t->destination)));
return buf;
}
@@ -530,37 +536,37 @@ GCT_2s(const struct CadetTunnel *t)
* @return String representation.
*/
static const char *
-estate2s(enum CadetTunnelEState es)
+estate2s (enum CadetTunnelEState es)
{
static char buf[32];
switch (es)
- {
- case CADET_TUNNEL_KEY_UNINITIALIZED:
- return "CADET_TUNNEL_KEY_UNINITIALIZED";
+ {
+ case CADET_TUNNEL_KEY_UNINITIALIZED:
+ return "CADET_TUNNEL_KEY_UNINITIALIZED";
- case CADET_TUNNEL_KEY_AX_RECV:
- return "CADET_TUNNEL_KEY_AX_RECV";
+ case CADET_TUNNEL_KEY_AX_RECV:
+ return "CADET_TUNNEL_KEY_AX_RECV";
- case CADET_TUNNEL_KEY_AX_SENT:
- return "CADET_TUNNEL_KEY_AX_SENT";
+ case CADET_TUNNEL_KEY_AX_SENT:
+ return "CADET_TUNNEL_KEY_AX_SENT";
- case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
- return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV";
+ case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
+ return "CADET_TUNNEL_KEY_AX_SENT_AND_RECV";
- case CADET_TUNNEL_KEY_AX_AUTH_SENT:
- return "CADET_TUNNEL_KEY_AX_AUTH_SENT";
+ case CADET_TUNNEL_KEY_AX_AUTH_SENT:
+ return "CADET_TUNNEL_KEY_AX_AUTH_SENT";
- case CADET_TUNNEL_KEY_OK:
- return "CADET_TUNNEL_KEY_OK";
+ case CADET_TUNNEL_KEY_OK:
+ return "CADET_TUNNEL_KEY_OK";
- default:
- GNUNET_snprintf(buf,
- sizeof(buf),
- "%u (UNKNOWN STATE)",
- es);
- return buf;
- }
+ default:
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "%u (UNKNOWN STATE)",
+ es);
+ return buf;
+ }
}
@@ -571,7 +577,7 @@ estate2s(enum CadetTunnelEState es)
* @return the destination of the tunnel
*/
struct CadetPeer *
-GCT_get_destination(struct CadetTunnel *t)
+GCT_get_destination (struct CadetTunnel *t)
{
return t->destination;
}
@@ -585,9 +591,9 @@ GCT_get_destination(struct CadetTunnel *t)
* @return Number of channels.
*/
unsigned int
-GCT_count_channels(struct CadetTunnel *t)
+GCT_count_channels (struct CadetTunnel *t)
{
- return GNUNET_CONTAINER_multihashmap32_size(t->channels);
+ return GNUNET_CONTAINER_multihashmap32_size (t->channels);
}
@@ -599,11 +605,11 @@ GCT_count_channels(struct CadetTunnel *t)
* @return NULL if channel does not exist
*/
struct CadetChannel *
-lookup_channel(struct CadetTunnel *t,
- struct GNUNET_CADET_ChannelTunnelNumber ctn)
+lookup_channel (struct CadetTunnel *t,
+ struct GNUNET_CADET_ChannelTunnelNumber ctn)
{
- return GNUNET_CONTAINER_multihashmap32_get(t->channels,
- ntohl(ctn.cn));
+ return GNUNET_CONTAINER_multihashmap32_get (t->channels,
+ ntohl (ctn.cn));
}
@@ -615,7 +621,7 @@ lookup_channel(struct CadetTunnel *t,
* @return Number of connections created, either being established or ready.
*/
unsigned int
-GCT_count_any_connections(const struct CadetTunnel *t)
+GCT_count_any_connections (const struct CadetTunnel *t)
{
return t->num_ready_connections + t->num_busy_connections;
}
@@ -629,12 +635,12 @@ GCT_count_any_connections(const struct CadetTunnel *t)
* @return NULL if we have no connection that is ready
*/
static struct CadetTConnection *
-get_ready_connection(struct CadetTunnel *t)
+get_ready_connection (struct CadetTunnel *t)
{
struct CadetTConnection *hd = t->connection_ready_head;
- GNUNET_assert((NULL == hd) ||
- (GNUNET_YES == hd->is_ready));
+ GNUNET_assert ((NULL == hd) ||
+ (GNUNET_YES == hd->is_ready));
return hd;
}
@@ -647,7 +653,7 @@ get_ready_connection(struct CadetTunnel *t)
* @return Tunnel's encryption state.
*/
enum CadetTunnelEState
-GCT_get_estate(struct CadetTunnel *t)
+GCT_get_estate (struct CadetTunnel *t)
{
return t->estate;
}
@@ -662,7 +668,7 @@ GCT_get_estate(struct CadetTunnel *t)
* @param cls the `struct CadetTunnel` to process messages on
*/
static void
-trigger_transmissions(void *cls);
+trigger_transmissions (void *cls);
/* ************************************** start core crypto ***************************** */
@@ -674,12 +680,12 @@ trigger_transmissions(void *cls);
* @param ax key material to update
*/
static void
-new_ephemeral(struct CadetTunnelAxolotl *ax)
+new_ephemeral (struct CadetTunnelAxolotl *ax)
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Creating new ephemeral ratchet key (DHRs)\n");
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2(&ax->DHRs));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating new ephemeral ratchet key (DHRs)\n");
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecdhe_key_create2 (&ax->DHRs));
}
@@ -693,31 +699,31 @@ new_ephemeral(struct CadetTunnelAxolotl *ax)
* @param hmac[out] Destination to store the HMAC.
*/
static void
-t_hmac(const void *plaintext,
- size_t size,
- uint32_t iv,
- const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_ShortHashCode *hmac)
+t_hmac (const void *plaintext,
+ size_t size,
+ uint32_t iv,
+ const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
+ struct GNUNET_ShortHashCode *hmac)
{
static const char ctx[] = "cadet authentication key";
struct GNUNET_CRYPTO_AuthKey auth_key;
struct GNUNET_HashCode hash;
- GNUNET_CRYPTO_hmac_derive_key(&auth_key,
- key,
- &iv, sizeof(iv),
- key, sizeof(*key),
- ctx, sizeof(ctx),
- NULL);
+ GNUNET_CRYPTO_hmac_derive_key (&auth_key,
+ key,
+ &iv, sizeof(iv),
+ key, sizeof(*key),
+ ctx, sizeof(ctx),
+ NULL);
/* Two step: GNUNET_ShortHash is only 256 bits,
GNUNET_HashCode is 512, so we truncate. */
- GNUNET_CRYPTO_hmac(&auth_key,
- plaintext,
- size,
- &hash);
- GNUNET_memcpy(hmac,
- &hash,
- sizeof(*hmac));
+ GNUNET_CRYPTO_hmac (&auth_key,
+ plaintext,
+ size,
+ &hash);
+ GNUNET_memcpy (hmac,
+ &hash,
+ sizeof(*hmac));
}
@@ -730,22 +736,22 @@ t_hmac(const void *plaintext,
* @param len Length of @a source.
*/
static void
-t_ax_hmac_hash(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_HashCode *hash,
- const void *source,
- unsigned int len)
+t_ax_hmac_hash (const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
+ struct GNUNET_HashCode *hash,
+ const void *source,
+ unsigned int len)
{
static const char ctx[] = "axolotl HMAC-HASH";
struct GNUNET_CRYPTO_AuthKey auth_key;
- GNUNET_CRYPTO_hmac_derive_key(&auth_key,
- key,
- ctx, sizeof(ctx),
- NULL);
- GNUNET_CRYPTO_hmac(&auth_key,
- source,
- len,
- hash);
+ GNUNET_CRYPTO_hmac_derive_key (&auth_key,
+ key,
+ ctx, sizeof(ctx),
+ NULL);
+ GNUNET_CRYPTO_hmac (&auth_key,
+ source,
+ len,
+ hash);
}
@@ -758,22 +764,22 @@ t_ax_hmac_hash(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
* @param len Length of @a source.
*/
static void
-t_hmac_derive_key(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_CRYPTO_SymmetricSessionKey *out,
- const void *source,
- unsigned int len)
+t_hmac_derive_key (const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
+ struct GNUNET_CRYPTO_SymmetricSessionKey *out,
+ const void *source,
+ unsigned int len)
{
static const char ctx[] = "axolotl derive key";
struct GNUNET_HashCode h;
- t_ax_hmac_hash(key,
- &h,
- source,
- len);
- GNUNET_CRYPTO_kdf(out, sizeof(*out),
- ctx, sizeof(ctx),
- &h, sizeof(h),
- NULL);
+ t_ax_hmac_hash (key,
+ &h,
+ source,
+ len);
+ GNUNET_CRYPTO_kdf (out, sizeof(*out),
+ ctx, sizeof(ctx),
+ &h, sizeof(h),
+ NULL);
}
@@ -786,10 +792,10 @@ t_hmac_derive_key(const struct GNUNET_CRYPTO_SymmetricSessionKey *key,
* @param size Size of the buffers at @a src and @a dst
*/
static void
-t_ax_encrypt(struct CadetTunnelAxolotl *ax,
- void *dst,
- const void *src,
- size_t size)
+t_ax_encrypt (struct CadetTunnelAxolotl *ax,
+ void *dst,
+ const void *src,
+ size_t size)
{
struct GNUNET_CRYPTO_SymmetricSessionKey MK;
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
@@ -798,66 +804,67 @@ t_ax_encrypt(struct CadetTunnelAxolotl *ax,
ax->ratchet_counter++;
if ((GNUNET_YES == ax->ratchet_allowed) &&
((ratchet_messages <= ax->ratchet_counter) ||
- (0 == GNUNET_TIME_absolute_get_remaining(ax->ratchet_expiration).rel_value_us)))
- {
- ax->ratchet_flag = GNUNET_YES;
- }
+ (0 == GNUNET_TIME_absolute_get_remaining (
+ ax->ratchet_expiration).rel_value_us)))
+ {
+ ax->ratchet_flag = GNUNET_YES;
+ }
if (GNUNET_YES == ax->ratchet_flag)
- {
- /* Advance ratchet */
- struct GNUNET_CRYPTO_SymmetricSessionKey keys[3];
- struct GNUNET_HashCode dh;
- struct GNUNET_HashCode hmac;
- static const char ctx[] = "axolotl ratchet";
-
- new_ephemeral(ax);
- ax->HKs = ax->NHKs;
-
- /* RK, NHKs, CKs = KDF( HMAC-HASH(RK, DH(DHRs, DHRr)) ) */
- GNUNET_CRYPTO_ecc_ecdh(&ax->DHRs,
- &ax->DHRr,
- &dh);
- t_ax_hmac_hash(&ax->RK,
- &hmac,
- &dh,
- sizeof(dh));
- GNUNET_CRYPTO_kdf(keys, sizeof(keys),
- ctx, sizeof(ctx),
- &hmac, sizeof(hmac),
- NULL);
- ax->RK = keys[0];
- ax->NHKs = keys[1];
- ax->CKs = keys[2];
-
- ax->PNs = ax->Ns;
- ax->Ns = 0;
- ax->ratchet_flag = GNUNET_NO;
- ax->ratchet_allowed = GNUNET_NO;
- ax->ratchet_counter = 0;
- ax->ratchet_expiration
- = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- ratchet_time);
- }
-
- t_hmac_derive_key(&ax->CKs,
- &MK,
- "0",
- 1);
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &MK,
- NULL, 0,
- NULL);
-
- out_size = GNUNET_CRYPTO_symmetric_encrypt(src,
- size,
- &MK,
- &iv,
- dst);
- GNUNET_assert(size == out_size);
- t_hmac_derive_key(&ax->CKs,
- &ax->CKs,
- "1",
- 1);
+ {
+ /* Advance ratchet */
+ struct GNUNET_CRYPTO_SymmetricSessionKey keys[3];
+ struct GNUNET_HashCode dh;
+ struct GNUNET_HashCode hmac;
+ static const char ctx[] = "axolotl ratchet";
+
+ new_ephemeral (ax);
+ ax->HKs = ax->NHKs;
+
+ /* RK, NHKs, CKs = KDF( HMAC-HASH(RK, DH(DHRs, DHRr)) ) */
+ GNUNET_CRYPTO_ecc_ecdh (&ax->DHRs,
+ &ax->DHRr,
+ &dh);
+ t_ax_hmac_hash (&ax->RK,
+ &hmac,
+ &dh,
+ sizeof(dh));
+ GNUNET_CRYPTO_kdf (keys, sizeof(keys),
+ ctx, sizeof(ctx),
+ &hmac, sizeof(hmac),
+ NULL);
+ ax->RK = keys[0];
+ ax->NHKs = keys[1];
+ ax->CKs = keys[2];
+
+ ax->PNs = ax->Ns;
+ ax->Ns = 0;
+ ax->ratchet_flag = GNUNET_NO;
+ ax->ratchet_allowed = GNUNET_NO;
+ ax->ratchet_counter = 0;
+ ax->ratchet_expiration
+ = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ ratchet_time);
+ }
+
+ t_hmac_derive_key (&ax->CKs,
+ &MK,
+ "0",
+ 1);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &MK,
+ NULL, 0,
+ NULL);
+
+ out_size = GNUNET_CRYPTO_symmetric_encrypt (src,
+ size,
+ &MK,
+ &iv,
+ dst);
+ GNUNET_assert (size == out_size);
+ t_hmac_derive_key (&ax->CKs,
+ &ax->CKs,
+ "1",
+ 1);
}
@@ -870,34 +877,34 @@ t_ax_encrypt(struct CadetTunnelAxolotl *ax,
* @param size Size of the @a src and @a dst buffers
*/
static void
-t_ax_decrypt(struct CadetTunnelAxolotl *ax,
- void *dst,
- const void *src,
- size_t size)
+t_ax_decrypt (struct CadetTunnelAxolotl *ax,
+ void *dst,
+ const void *src,
+ size_t size)
{
struct GNUNET_CRYPTO_SymmetricSessionKey MK;
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
size_t out_size;
- t_hmac_derive_key(&ax->CKr,
- &MK,
- "0",
- 1);
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &MK,
- NULL, 0,
- NULL);
- GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader));
- out_size = GNUNET_CRYPTO_symmetric_decrypt(src,
- size,
- &MK,
- &iv,
- dst);
- GNUNET_assert(out_size == size);
- t_hmac_derive_key(&ax->CKr,
- &ax->CKr,
- "1",
- 1);
+ t_hmac_derive_key (&ax->CKr,
+ &MK,
+ "0",
+ 1);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &MK,
+ NULL, 0,
+ NULL);
+ GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader));
+ out_size = GNUNET_CRYPTO_symmetric_decrypt (src,
+ size,
+ &MK,
+ &iv,
+ dst);
+ GNUNET_assert (out_size == size);
+ t_hmac_derive_key (&ax->CKr,
+ &ax->CKr,
+ "1",
+ 1);
}
@@ -908,22 +915,23 @@ t_ax_decrypt(struct CadetTunnelAxolotl *ax,
* @param[in|out] msg Message whose header to encrypt.
*/
static void
-t_h_encrypt(struct CadetTunnelAxolotl *ax,
- struct GNUNET_CADET_TunnelEncryptedMessage *msg)
+t_h_encrypt (struct CadetTunnelAxolotl *ax,
+ struct GNUNET_CADET_TunnelEncryptedMessage *msg)
{
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
size_t out_size;
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &ax->HKs,
- NULL, 0,
- NULL);
- out_size = GNUNET_CRYPTO_symmetric_encrypt(&msg->ax_header,
- sizeof(struct GNUNET_CADET_AxHeader),
- &ax->HKs,
- &iv,
- &msg->ax_header);
- GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == out_size);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &ax->HKs,
+ NULL, 0,
+ NULL);
+ out_size = GNUNET_CRYPTO_symmetric_encrypt (&msg->ax_header,
+ sizeof(struct
+ GNUNET_CADET_AxHeader),
+ &ax->HKs,
+ &iv,
+ &msg->ax_header);
+ GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
}
@@ -935,23 +943,24 @@ t_h_encrypt(struct CadetTunnelAxolotl *ax,
* @param dst Where to decrypt header to.
*/
static void
-t_h_decrypt(struct CadetTunnelAxolotl *ax,
- const struct GNUNET_CADET_TunnelEncryptedMessage *src,
- struct GNUNET_CADET_TunnelEncryptedMessage *dst)
+t_h_decrypt (struct CadetTunnelAxolotl *ax,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *src,
+ struct GNUNET_CADET_TunnelEncryptedMessage *dst)
{
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
size_t out_size;
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &ax->HKr,
- NULL, 0,
- NULL);
- out_size = GNUNET_CRYPTO_symmetric_decrypt(&src->ax_header.Ns,
- sizeof(struct GNUNET_CADET_AxHeader),
- &ax->HKr,
- &iv,
- &dst->ax_header.Ns);
- GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == out_size);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &ax->HKr,
+ NULL, 0,
+ NULL);
+ out_size = GNUNET_CRYPTO_symmetric_decrypt (&src->ax_header.Ns,
+ sizeof(struct
+ GNUNET_CADET_AxHeader),
+ &ax->HKr,
+ &iv,
+ &dst->ax_header.Ns);
+ GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == out_size);
}
@@ -962,13 +971,13 @@ t_h_decrypt(struct CadetTunnelAxolotl *ax,
* @param key Key to delete.
*/
static void
-delete_skipped_key(struct CadetTunnelAxolotl *ax,
- struct CadetTunnelSkippedKey *key)
+delete_skipped_key (struct CadetTunnelAxolotl *ax,
+ struct CadetTunnelSkippedKey *key)
{
- GNUNET_CONTAINER_DLL_remove(ax->skipped_head,
- ax->skipped_tail,
- key);
- GNUNET_free(key);
+ GNUNET_CONTAINER_DLL_remove (ax->skipped_head,
+ ax->skipped_tail,
+ key);
+ GNUNET_free (key);
ax->skipped--;
}
@@ -984,10 +993,10 @@ delete_skipped_key(struct CadetTunnelAxolotl *ax,
* @return Size of the decrypted data, -1 if an error was encountered.
*/
static ssize_t
-try_old_ax_keys(struct CadetTunnelAxolotl *ax,
- void *dst,
- const struct GNUNET_CADET_TunnelEncryptedMessage *src,
- size_t size)
+try_old_ax_keys (struct CadetTunnelAxolotl *ax,
+ void *dst,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *src,
+ size_t size)
{
struct CadetTunnelSkippedKey *key;
struct GNUNET_ShortHashCode *hmac;
@@ -999,70 +1008,70 @@ try_old_ax_keys(struct CadetTunnelAxolotl *ax,
size_t len;
unsigned int N;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Trying skipped keys\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying skipped keys\n");
hmac = &plaintext_header.hmac;
esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
/* Find a correct Header Key */
valid_HK = NULL;
for (key = ax->skipped_head; NULL != key; key = key->next)
- {
- t_hmac(&src->ax_header,
- sizeof(struct GNUNET_CADET_AxHeader) + esize,
- 0,
- &key->HK,
- hmac);
- if (0 == GNUNET_memcmp(hmac,
- &src->hmac))
- {
- valid_HK = &key->HK;
- break;
- }
+ {
+ t_hmac (&src->ax_header,
+ sizeof(struct GNUNET_CADET_AxHeader) + esize,
+ 0,
+ &key->HK,
+ hmac);
+ if (0 == GNUNET_memcmp (hmac,
+ &src->hmac))
+ {
+ valid_HK = &key->HK;
+ break;
}
+ }
if (NULL == key)
return -1;
/* Should've been checked in -cadet_connection.c handle_cadet_encrypted. */
- GNUNET_assert(size > sizeof(struct GNUNET_CADET_TunnelEncryptedMessage));
+ GNUNET_assert (size > sizeof(struct GNUNET_CADET_TunnelEncryptedMessage));
len = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
- GNUNET_assert(len >= sizeof(struct GNUNET_MessageHeader));
+ GNUNET_assert (len >= sizeof(struct GNUNET_MessageHeader));
/* Decrypt header */
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &key->HK,
- NULL, 0,
- NULL);
- res = GNUNET_CRYPTO_symmetric_decrypt(&src->ax_header.Ns,
- sizeof(struct GNUNET_CADET_AxHeader),
- &key->HK,
- &iv,
- &plaintext_header.ax_header.Ns);
- GNUNET_assert(sizeof(struct GNUNET_CADET_AxHeader) == res);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &key->HK,
+ NULL, 0,
+ NULL);
+ res = GNUNET_CRYPTO_symmetric_decrypt (&src->ax_header.Ns,
+ sizeof(struct GNUNET_CADET_AxHeader),
+ &key->HK,
+ &iv,
+ &plaintext_header.ax_header.Ns);
+ GNUNET_assert (sizeof(struct GNUNET_CADET_AxHeader) == res);
/* Find the correct message key */
- N = ntohl(plaintext_header.ax_header.Ns);
+ N = ntohl (plaintext_header.ax_header.Ns);
while ((NULL != key) &&
(N != key->Kn))
key = key->next;
if ((NULL == key) ||
- (0 != GNUNET_memcmp(&key->HK,
- valid_HK)))
+ (0 != GNUNET_memcmp (&key->HK,
+ valid_HK)))
return -1;
/* Decrypt payload */
- GNUNET_CRYPTO_symmetric_derive_iv(&iv,
- &key->MK,
- NULL,
- 0,
- NULL);
- res = GNUNET_CRYPTO_symmetric_decrypt(&src[1],
- len,
- &key->MK,
- &iv,
- dst);
- delete_skipped_key(ax,
- key);
+ GNUNET_CRYPTO_symmetric_derive_iv (&iv,
+ &key->MK,
+ NULL,
+ 0,
+ NULL);
+ res = GNUNET_CRYPTO_symmetric_decrypt (&src[1],
+ len,
+ &key->MK,
+ &iv,
+ dst);
+ delete_skipped_key (ax,
+ key);
return res;
}
@@ -1074,26 +1083,26 @@ try_old_ax_keys(struct CadetTunnelAxolotl *ax,
* @param HKr Header Key to use.
*/
static void
-store_skipped_key(struct CadetTunnelAxolotl *ax,
- const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr)
+store_skipped_key (struct CadetTunnelAxolotl *ax,
+ const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr)
{
struct CadetTunnelSkippedKey *key;
- key = GNUNET_new(struct CadetTunnelSkippedKey);
- key->timestamp = GNUNET_TIME_absolute_get();
+ key = GNUNET_new (struct CadetTunnelSkippedKey);
+ key->timestamp = GNUNET_TIME_absolute_get ();
key->Kn = ax->Nr;
key->HK = ax->HKr;
- t_hmac_derive_key(&ax->CKr,
- &key->MK,
- "0",
- 1);
- t_hmac_derive_key(&ax->CKr,
- &ax->CKr,
- "1",
- 1);
- GNUNET_CONTAINER_DLL_insert(ax->skipped_head,
- ax->skipped_tail,
- key);
+ t_hmac_derive_key (&ax->CKr,
+ &key->MK,
+ "0",
+ 1);
+ t_hmac_derive_key (&ax->CKr,
+ &ax->CKr,
+ "1",
+ 1);
+ GNUNET_CONTAINER_DLL_insert (ax->skipped_head,
+ ax->skipped_tail,
+ key);
ax->skipped++;
ax->Nr++;
}
@@ -1110,41 +1119,41 @@ store_skipped_key(struct CadetTunnelAxolotl *ax,
* #GNUNET_SYSERR if an error ocurred (@a Np not expected).
*/
static int
-store_ax_keys(struct CadetTunnelAxolotl *ax,
- const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr,
- uint32_t Np)
+store_ax_keys (struct CadetTunnelAxolotl *ax,
+ const struct GNUNET_CRYPTO_SymmetricSessionKey *HKr,
+ uint32_t Np)
{
int gap;
gap = Np - ax->Nr;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Storing skipped keys [%u, %u)\n",
- ax->Nr,
- Np);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing skipped keys [%u, %u)\n",
+ ax->Nr,
+ Np);
if (MAX_KEY_GAP < gap)
- {
- /* Avoid DoS (forcing peer to do more than #MAX_KEY_GAP HMAC operations) */
- /* TODO: start new key exchange on return */
- GNUNET_break_op(0);
- LOG(GNUNET_ERROR_TYPE_WARNING,
- "Got message %u, expected %u+\n",
- Np,
- ax->Nr);
- return GNUNET_SYSERR;
- }
+ {
+ /* Avoid DoS (forcing peer to do more than #MAX_KEY_GAP HMAC operations) */
+ /* TODO: start new key exchange on return */
+ GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Got message %u, expected %u+\n",
+ Np,
+ ax->Nr);
+ return GNUNET_SYSERR;
+ }
if (0 > gap)
- {
- /* Delayed message: don't store keys, flag to try old keys. */
- return GNUNET_SYSERR;
- }
+ {
+ /* Delayed message: don't store keys, flag to try old keys. */
+ return GNUNET_SYSERR;
+ }
while (ax->Nr < Np)
- store_skipped_key(ax,
- HKr);
+ store_skipped_key (ax,
+ HKr);
while (ax->skipped > MAX_SKIPPED_KEYS)
- delete_skipped_key(ax,
- ax->skipped_tail);
+ delete_skipped_key (ax,
+ ax->skipped_tail);
return GNUNET_OK;
}
@@ -1160,10 +1169,11 @@ store_ax_keys(struct CadetTunnelAxolotl *ax,
* @return Size of the decrypted data, -1 if an error was encountered.
*/
static ssize_t
-t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax,
- void *dst,
- const struct GNUNET_CADET_TunnelEncryptedMessage *src,
- size_t size)
+t_ax_decrypt_and_validate (struct CadetTunnelAxolotl *ax,
+ void *dst,
+ const struct
+ GNUNET_CADET_TunnelEncryptedMessage *src,
+ size_t size)
{
struct GNUNET_ShortHashCode msg_hmac;
struct GNUNET_HashCode hmac;
@@ -1175,90 +1185,90 @@ t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax,
esize = size - sizeof(struct GNUNET_CADET_TunnelEncryptedMessage);
/* Try current HK */
- t_hmac(&src->ax_header,
- sizeof(struct GNUNET_CADET_AxHeader) + esize,
- 0, &ax->HKr,
- &msg_hmac);
- if (0 != GNUNET_memcmp(&msg_hmac,
- &src->hmac))
+ t_hmac (&src->ax_header,
+ sizeof(struct GNUNET_CADET_AxHeader) + esize,
+ 0, &ax->HKr,
+ &msg_hmac);
+ if (0 != GNUNET_memcmp (&msg_hmac,
+ &src->hmac))
+ {
+ static const char ctx[] = "axolotl ratchet";
+ struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; /* RKp, NHKp, CKp */
+ struct GNUNET_CRYPTO_SymmetricSessionKey HK;
+ struct GNUNET_HashCode dh;
+ struct GNUNET_CRYPTO_EcdhePublicKey *DHRp;
+
+ /* Try Next HK */
+ t_hmac (&src->ax_header,
+ sizeof(struct GNUNET_CADET_AxHeader) + esize,
+ 0,
+ &ax->NHKr,
+ &msg_hmac);
+ if (0 != GNUNET_memcmp (&msg_hmac,
+ &src->hmac))
{
- static const char ctx[] = "axolotl ratchet";
- struct GNUNET_CRYPTO_SymmetricSessionKey keys[3]; /* RKp, NHKp, CKp */
- struct GNUNET_CRYPTO_SymmetricSessionKey HK;
- struct GNUNET_HashCode dh;
- struct GNUNET_CRYPTO_EcdhePublicKey *DHRp;
-
- /* Try Next HK */
- t_hmac(&src->ax_header,
- sizeof(struct GNUNET_CADET_AxHeader) + esize,
- 0,
- &ax->NHKr,
- &msg_hmac);
- if (0 != GNUNET_memcmp(&msg_hmac,
- &src->hmac))
- {
- /* Try the skipped keys, if that fails, we're out of luck. */
- return try_old_ax_keys(ax,
- dst,
- src,
- size);
- }
- HK = ax->HKr;
- ax->HKr = ax->NHKr;
- t_h_decrypt(ax,
- src,
- &plaintext_header);
- Np = ntohl(plaintext_header.ax_header.Ns);
- PNp = ntohl(plaintext_header.ax_header.PNs);
- DHRp = &plaintext_header.ax_header.DHRs;
- store_ax_keys(ax,
- &HK,
- PNp);
-
- /* RKp, NHKp, CKp = KDF (HMAC-HASH (RK, DH (DHRp, DHRs))) */
- GNUNET_CRYPTO_ecc_ecdh(&ax->DHRs,
- DHRp,
- &dh);
- t_ax_hmac_hash(&ax->RK,
- &hmac,
- &dh, sizeof(dh));
- GNUNET_CRYPTO_kdf(keys, sizeof(keys),
- ctx, sizeof(ctx),
- &hmac, sizeof(hmac),
- NULL);
-
- /* Commit "purported" keys */
- ax->RK = keys[0];
- ax->NHKr = keys[1];
- ax->CKr = keys[2];
- ax->DHRr = *DHRp;
- ax->Nr = 0;
- ax->ratchet_allowed = GNUNET_YES;
- }
+ /* Try the skipped keys, if that fails, we're out of luck. */
+ return try_old_ax_keys (ax,
+ dst,
+ src,
+ size);
+ }
+ HK = ax->HKr;
+ ax->HKr = ax->NHKr;
+ t_h_decrypt (ax,
+ src,
+ &plaintext_header);
+ Np = ntohl (plaintext_header.ax_header.Ns);
+ PNp = ntohl (plaintext_header.ax_header.PNs);
+ DHRp = &plaintext_header.ax_header.DHRs;
+ store_ax_keys (ax,
+ &HK,
+ PNp);
+
+ /* RKp, NHKp, CKp = KDF (HMAC-HASH (RK, DH (DHRp, DHRs))) */
+ GNUNET_CRYPTO_ecc_ecdh (&ax->DHRs,
+ DHRp,
+ &dh);
+ t_ax_hmac_hash (&ax->RK,
+ &hmac,
+ &dh, sizeof(dh));
+ GNUNET_CRYPTO_kdf (keys, sizeof(keys),
+ ctx, sizeof(ctx),
+ &hmac, sizeof(hmac),
+ NULL);
+
+ /* Commit "purported" keys */
+ ax->RK = keys[0];
+ ax->NHKr = keys[1];
+ ax->CKr = keys[2];
+ ax->DHRr = *DHRp;
+ ax->Nr = 0;
+ ax->ratchet_allowed = GNUNET_YES;
+ }
else
- {
- t_h_decrypt(ax,
- src,
- &plaintext_header);
- Np = ntohl(plaintext_header.ax_header.Ns);
- PNp = ntohl(plaintext_header.ax_header.PNs);
- }
+ {
+ t_h_decrypt (ax,
+ src,
+ &plaintext_header);
+ Np = ntohl (plaintext_header.ax_header.Ns);
+ PNp = ntohl (plaintext_header.ax_header.PNs);
+ }
if ((Np != ax->Nr) &&
- (GNUNET_OK != store_ax_keys(ax,
- &ax->HKr,
- Np)))
- {
- /* Try the skipped keys, if that fails, we're out of luck. */
- return try_old_ax_keys(ax,
- dst,
- src,
- size);
- }
-
- t_ax_decrypt(ax,
- dst,
- &src[1],
- esize);
+ (GNUNET_OK != store_ax_keys (ax,
+ &ax->HKr,
+ Np)))
+ {
+ /* Try the skipped keys, if that fails, we're out of luck. */
+ return try_old_ax_keys (ax,
+ dst,
+ src,
+ size);
+ }
+
+ t_ax_decrypt (ax,
+ dst,
+ &src[1],
+ esize);
ax->Nr = Np + 1;
return esize;
}
@@ -1274,13 +1284,13 @@ t_ax_decrypt_and_validate(struct CadetTunnelAxolotl *ax,
* @return #GNUNET_OK (continue to iterate)
*/
static int
-notify_tunnel_up_cb(void *cls,
- uint32_t key,
- void *value)
+notify_tunnel_up_cb (void *cls,
+ uint32_t key,
+ void *value)
{
struct CadetChannel *ch = value;
- GCCH_tunnel_up(ch);
+ GCCH_tunnel_up (ch);
return GNUNET_OK;
}
@@ -1293,35 +1303,35 @@ notify_tunnel_up_cb(void *cls,
* @param state New encryption state.
*/
void
-GCT_change_estate(struct CadetTunnel *t,
- enum CadetTunnelEState state)
+GCT_change_estate (struct CadetTunnel *t,
+ enum CadetTunnelEState state)
{
enum CadetTunnelEState old = t->estate;
t->estate = state;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "%s estate changed from %s to %s\n",
- GCT_2s(t),
- estate2s(old),
- estate2s(state));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "%s estate changed from %s to %s\n",
+ GCT_2s (t),
+ estate2s (old),
+ estate2s (state));
if ((CADET_TUNNEL_KEY_OK != old) &&
(CADET_TUNNEL_KEY_OK == t->estate))
+ {
+ if (NULL != t->kx_task)
{
- if (NULL != t->kx_task)
- {
- GNUNET_SCHEDULER_cancel(t->kx_task);
- t->kx_task = NULL;
- }
- /* notify all channels that have been waiting */
- GNUNET_CONTAINER_multihashmap32_iterate(t->channels,
- &notify_tunnel_up_cb,
- t);
- if (NULL != t->send_task)
- GNUNET_SCHEDULER_cancel(t->send_task);
- t->send_task = GNUNET_SCHEDULER_add_now(&trigger_transmissions,
- t);
+ GNUNET_SCHEDULER_cancel (t->kx_task);
+ t->kx_task = NULL;
}
+ /* notify all channels that have been waiting */
+ GNUNET_CONTAINER_multihashmap32_iterate (t->channels,
+ &notify_tunnel_up_cb,
+ t);
+ if (NULL != t->send_task)
+ GNUNET_SCHEDULER_cancel (t->send_task);
+ t->send_task = GNUNET_SCHEDULER_add_now (&trigger_transmissions,
+ t);
+ }
}
@@ -1334,63 +1344,63 @@ GCT_change_estate(struct CadetTunnel *t,
* @param ax axolotl key context to use
*/
static void
-send_kx(struct CadetTunnel *t,
- struct CadetTConnection *ct,
- struct CadetTunnelAxolotl *ax)
+send_kx (struct CadetTunnel *t,
+ struct CadetTConnection *ct,
+ struct CadetTunnelAxolotl *ax)
{
struct CadetConnection *cc;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_CADET_TunnelKeyExchangeMessage *msg;
enum GNUNET_CADET_KX_Flags flags;
- if (GNUNET_YES != alice_or_betty(GCP_get_id(t->destination)))
+ if (GNUNET_YES != alice_or_betty (GCP_get_id (t->destination)))
return; /* only Alice may send KX */
if ((NULL == ct) ||
(GNUNET_NO == ct->is_ready))
- ct = get_ready_connection(t);
+ ct = get_ready_connection (t);
if (NULL == ct)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Wanted to send %s in state %s, but no connection is ready, deferring\n",
- GCT_2s(t),
- estate2s(t->estate));
- t->next_kx_attempt = GNUNET_TIME_absolute_get();
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wanted to send %s in state %s, but no connection is ready, deferring\n",
+ GCT_2s (t),
+ estate2s (t->estate));
+ t->next_kx_attempt = GNUNET_TIME_absolute_get ();
+ return;
+ }
cc = ct->cc;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX);
flags = GNUNET_CADET_KX_FLAG_FORCE_REPLY; /* always for KX */
- msg->flags = htonl(flags);
- msg->cid = *GCC_get_id(cc);
- GNUNET_CRYPTO_ecdhe_key_get_public(&ax->kx_0,
- &msg->ephemeral_key);
+ msg->flags = htonl (flags);
+ msg->cid = *GCC_get_id (cc);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0,
+ &msg->ephemeral_key);
#if DEBUG_KX
msg->ephemeral_key_XXX = ax->kx_0;
msg->private_key_XXX = *my_private_key;
#endif
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending KX message to %s with ephemeral %s on CID %s\n",
- GCT_2s(t),
- GNUNET_e2s(&msg->ephemeral_key),
- GNUNET_sh2s(&msg->cid.connection_of_tunnel));
- GNUNET_CRYPTO_ecdhe_key_get_public(&ax->DHRs,
- &msg->ratchet_key);
- mark_connection_unready(ct);
- t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF(t->kx_retry_delay);
- t->next_kx_attempt = GNUNET_TIME_relative_to_absolute(t->kx_retry_delay);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending KX message to %s with ephemeral %s on CID %s\n",
+ GCT_2s (t),
+ GNUNET_e2s (&msg->ephemeral_key),
+ GNUNET_sh2s (&msg->cid.connection_of_tunnel));
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs,
+ &msg->ratchet_key);
+ mark_connection_unready (ct);
+ t->kx_retry_delay = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
+ t->next_kx_attempt = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate)
- GCT_change_estate(t,
- CADET_TUNNEL_KEY_AX_SENT);
+ GCT_change_estate (t,
+ CADET_TUNNEL_KEY_AX_SENT);
else if (CADET_TUNNEL_KEY_AX_RECV == t->estate)
- GCT_change_estate(t,
- CADET_TUNNEL_KEY_AX_SENT_AND_RECV);
- GCC_transmit(cc,
- env);
- GNUNET_STATISTICS_update(stats,
- "# KX transmitted",
- 1,
- GNUNET_NO);
+ GCT_change_estate (t,
+ CADET_TUNNEL_KEY_AX_SENT_AND_RECV);
+ GCC_transmit (cc,
+ env);
+ GNUNET_STATISTICS_update (stats,
+ "# KX transmitted",
+ 1,
+ GNUNET_NO);
}
@@ -1405,10 +1415,10 @@ send_kx(struct CadetTunnel *t,
* (set if we would like to transmit right now, but cannot)
*/
static void
-send_kx_auth(struct CadetTunnel *t,
- struct CadetTConnection *ct,
- struct CadetTunnelAxolotl *ax,
- int force_reply)
+send_kx_auth (struct CadetTunnel *t,
+ struct CadetTConnection *ct,
+ struct CadetTunnelAxolotl *ax,
+ int force_reply)
{
struct CadetConnection *cc;
struct GNUNET_MQ_Envelope *env;
@@ -1417,64 +1427,64 @@ send_kx_auth(struct CadetTunnel *t,
if ((NULL == ct) ||
(GNUNET_NO == ct->is_ready))
- ct = get_ready_connection(t);
+ ct = get_ready_connection (t);
if (NULL == ct)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Wanted to send KX_AUTH on %s, but no connection is ready, deferring\n",
- GCT_2s(t));
- t->next_kx_attempt = GNUNET_TIME_absolute_get();
- t->kx_auth_requested = GNUNET_YES; /* queue KX_AUTH independent of estate */
- return;
- }
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Wanted to send KX_AUTH on %s, but no connection is ready, deferring\n",
+ GCT_2s (t));
+ t->next_kx_attempt = GNUNET_TIME_absolute_get ();
+ t->kx_auth_requested = GNUNET_YES; /* queue KX_AUTH independent of estate */
+ return;
+ }
t->kx_auth_requested = GNUNET_NO; /* clear flag */
cc = ct->cc;
- env = GNUNET_MQ_msg(msg,
- GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH);
flags = GNUNET_CADET_KX_FLAG_NONE;
if (GNUNET_YES == force_reply)
flags |= GNUNET_CADET_KX_FLAG_FORCE_REPLY;
- msg->kx.flags = htonl(flags);
- msg->kx.cid = *GCC_get_id(cc);
- GNUNET_CRYPTO_ecdhe_key_get_public(&ax->kx_0,
- &msg->kx.ephemeral_key);
- GNUNET_CRYPTO_ecdhe_key_get_public(&ax->DHRs,
- &msg->kx.ratchet_key);
+ msg->kx.flags = htonl (flags);
+ msg->kx.cid = *GCC_get_id (cc);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0,
+ &msg->kx.ephemeral_key);
+ GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs,
+ &msg->kx.ratchet_key);
#if DEBUG_KX
msg->kx.ephemeral_key_XXX = ax->kx_0;
msg->kx.private_key_XXX = *my_private_key;
msg->r_ephemeral_key_XXX = ax->last_ephemeral;
#endif
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n",
- GCT_2s(t),
- GNUNET_e2s(&msg->kx.ephemeral_key),
- GNUNET_sh2s(&msg->kx.cid.connection_of_tunnel));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n",
+ GCT_2s (t),
+ GNUNET_e2s (&msg->kx.ephemeral_key),
+ GNUNET_sh2s (&msg->kx.cid.connection_of_tunnel));
/* Compute authenticator (this is the main difference to #send_kx()) */
- GNUNET_CRYPTO_hash(&ax->RK,
- sizeof(ax->RK),
- &msg->auth);
+ GNUNET_CRYPTO_hash (&ax->RK,
+ sizeof(ax->RK),
+ &msg->auth);
/* Compute when to be triggered again; actual job will
be scheduled via #connection_ready_cb() */
t->kx_retry_delay
- = GNUNET_TIME_STD_BACKOFF(t->kx_retry_delay);
+ = GNUNET_TIME_STD_BACKOFF (t->kx_retry_delay);
t->next_kx_attempt
- = GNUNET_TIME_relative_to_absolute(t->kx_retry_delay);
+ = GNUNET_TIME_relative_to_absolute (t->kx_retry_delay);
/* Send via cc, mark it as unready */
- mark_connection_unready(ct);
+ mark_connection_unready (ct);
/* Update state machine, unless we are already OK */
if (CADET_TUNNEL_KEY_OK != t->estate)
- GCT_change_estate(t,
- CADET_TUNNEL_KEY_AX_AUTH_SENT);
- GCC_transmit(cc,
- env);
- GNUNET_STATISTICS_update(stats,
- "# KX_AUTH transmitted",
- 1,
- GNUNET_NO);
+ GCT_change_estate (t,
+ CADET_TUNNEL_KEY_AX_AUTH_SENT);
+ GCC_transmit (cc,
+ env);
+ GNUNET_STATISTICS_update (stats,
+ "# KX_AUTH transmitted",
+ 1,
+ GNUNET_NO);
}
@@ -1484,14 +1494,14 @@ send_kx_auth(struct CadetTunnel *t,
* @param ax state to free, but not memory of @a ax itself
*/
static void
-cleanup_ax(struct CadetTunnelAxolotl *ax)
+cleanup_ax (struct CadetTunnelAxolotl *ax)
{
while (NULL != ax->skipped_head)
- delete_skipped_key(ax,
- ax->skipped_head);
- GNUNET_assert(0 == ax->skipped);
- GNUNET_CRYPTO_ecdhe_key_clear(&ax->kx_0);
- GNUNET_CRYPTO_ecdhe_key_clear(&ax->DHRs);
+ delete_skipped_key (ax,
+ ax->skipped_head);
+ GNUNET_assert (0 == ax->skipped);
+ GNUNET_CRYPTO_ecdhe_key_clear (&ax->kx_0);
+ GNUNET_CRYPTO_ecdhe_key_clear (&ax->DHRs);
}
@@ -1509,105 +1519,105 @@ cleanup_ax(struct CadetTunnelAxolotl *ax)
* #GNUNET_SYSERR on hard errors (i.e. @a pid is #my_full_id)
*/
static int
-update_ax_by_kx(struct CadetTunnelAxolotl *ax,
- const struct GNUNET_PeerIdentity *pid,
- const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral_key,
- const struct GNUNET_CRYPTO_EcdhePublicKey *ratchet_key)
+update_ax_by_kx (struct CadetTunnelAxolotl *ax,
+ const struct GNUNET_PeerIdentity *pid,
+ const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral_key,
+ const struct GNUNET_CRYPTO_EcdhePublicKey *ratchet_key)
{
struct GNUNET_HashCode key_material[3];
struct GNUNET_CRYPTO_SymmetricSessionKey keys[5];
const char salt[] = "CADET Axolotl salt";
int am_I_alice;
- if (GNUNET_SYSERR == (am_I_alice = alice_or_betty(pid)))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- if (0 == GNUNET_memcmp(&ax->DHRr,
- ratchet_key))
- {
- GNUNET_STATISTICS_update(stats,
- "# Ratchet key already known",
- 1,
- GNUNET_NO);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Ratchet key already known. Ignoring KX.\n");
- return GNUNET_NO;
- }
+ if (GNUNET_SYSERR == (am_I_alice = alice_or_betty (pid)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 == GNUNET_memcmp (&ax->DHRr,
+ ratchet_key))
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# Ratchet key already known",
+ 1,
+ GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Ratchet key already known. Ignoring KX.\n");
+ return GNUNET_NO;
+ }
ax->DHRr = *ratchet_key;
ax->last_ephemeral = *ephemeral_key;
/* ECDH A B0 */
if (GNUNET_YES == am_I_alice)
- {
- GNUNET_CRYPTO_eddsa_ecdh(my_private_key, /* a */
- ephemeral_key, /* B0 */
- &key_material[0]);
- }
+ {
+ GNUNET_CRYPTO_eddsa_ecdh (my_private_key, /* a */
+ ephemeral_key, /* B0 */
+ &key_material[0]);
+ }
else
- {
- GNUNET_CRYPTO_ecdh_eddsa(&ax->kx_0, /* b0 */
- &pid->public_key, /* A */
- &key_material[0]);
- }
+ {
+ GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* b0 */
+ &pid->public_key, /* A */
+ &key_material[0]);
+ }
/* ECDH A0 B */
if (GNUNET_YES == am_I_alice)
- {
- GNUNET_CRYPTO_ecdh_eddsa(&ax->kx_0, /* a0 */
- &pid->public_key, /* B */
- &key_material[1]);
- }
+ {
+ GNUNET_CRYPTO_ecdh_eddsa (&ax->kx_0, /* a0 */
+ &pid->public_key, /* B */
+ &key_material[1]);
+ }
else
- {
- GNUNET_CRYPTO_eddsa_ecdh(my_private_key, /* b */
- ephemeral_key, /* A0 */
- &key_material[1]);
- }
+ {
+ GNUNET_CRYPTO_eddsa_ecdh (my_private_key, /* b */
+ ephemeral_key, /* A0 */
+ &key_material[1]);
+ }
/* ECDH A0 B0 */
- GNUNET_CRYPTO_ecc_ecdh(&ax->kx_0, /* a0 or b0 */
- ephemeral_key, /* B0 or A0 */
- &key_material[2]);
+ GNUNET_CRYPTO_ecc_ecdh (&ax->kx_0, /* a0 or b0 */
+ ephemeral_key, /* B0 or A0 */
+ &key_material[2]);
/* KDF */
- GNUNET_CRYPTO_kdf(keys, sizeof(keys),
- salt, sizeof(salt),
- &key_material, sizeof(key_material),
- NULL);
-
- if (0 == memcmp(&ax->RK,
- &keys[0],
- sizeof(ax->RK)))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Root key already known. Ignoring KX.\n");
- GNUNET_STATISTICS_update(stats,
- "# Root key already known",
- 1,
- GNUNET_NO);
- return GNUNET_NO;
- }
+ GNUNET_CRYPTO_kdf (keys, sizeof(keys),
+ salt, sizeof(salt),
+ &key_material, sizeof(key_material),
+ NULL);
+
+ if (0 == memcmp (&ax->RK,
+ &keys[0],
+ sizeof(ax->RK)))
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Root key already known. Ignoring KX.\n");
+ GNUNET_STATISTICS_update (stats,
+ "# Root key already known",
+ 1,
+ GNUNET_NO);
+ return GNUNET_NO;
+ }
ax->RK = keys[0];
if (GNUNET_YES == am_I_alice)
- {
- ax->HKr = keys[1];
- ax->NHKs = keys[2];
- ax->NHKr = keys[3];
- ax->CKr = keys[4];
- ax->ratchet_flag = GNUNET_YES;
- }
+ {
+ ax->HKr = keys[1];
+ ax->NHKs = keys[2];
+ ax->NHKr = keys[3];
+ ax->CKr = keys[4];
+ ax->ratchet_flag = GNUNET_YES;
+ }
else
- {
- ax->HKs = keys[1];
- ax->NHKr = keys[2];
- ax->NHKs = keys[3];
- ax->CKs = keys[4];
- ax->ratchet_flag = GNUNET_NO;
- ax->ratchet_expiration
- = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
- ratchet_time);
- }
+ {
+ ax->HKs = keys[1];
+ ax->NHKr = keys[2];
+ ax->NHKs = keys[3];
+ ax->CKs = keys[4];
+ ax->ratchet_flag = GNUNET_NO;
+ ax->ratchet_expiration
+ = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ ratchet_time);
+ }
return GNUNET_OK;
}
@@ -1618,89 +1628,89 @@ update_ax_by_kx(struct CadetTunnelAxolotl *ax,
* @param cls the `struct CadetTunnel` to do KX for.
*/
static void
-retry_kx(void *cls)
+retry_kx (void *cls)
{
struct CadetTunnel *t = cls;
struct CadetTunnelAxolotl *ax;
t->kx_task = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Trying to make KX progress on %s in state %s\n",
- GCT_2s(t),
- estate2s(t->estate));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to make KX progress on %s in state %s\n",
+ GCT_2s (t),
+ estate2s (t->estate));
switch (t->estate)
- {
- case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */
- case CADET_TUNNEL_KEY_AX_SENT: /* trying again */
- send_kx(t,
- NULL,
- &t->ax);
- break;
+ {
+ case CADET_TUNNEL_KEY_UNINITIALIZED: /* first attempt */
+ case CADET_TUNNEL_KEY_AX_SENT: /* trying again */
+ send_kx (t,
+ NULL,
+ &t->ax);
+ break;
- case CADET_TUNNEL_KEY_AX_RECV:
- case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
- /* We are responding, so only require reply
- if WE have a channel waiting. */
- if (NULL != t->unverified_ax)
- {
- /* Send AX_AUTH so we might get this one verified */
- ax = t->unverified_ax;
- }
- else
- {
- /* How can this be? */
- GNUNET_break(0);
- ax = &t->ax;
- }
- send_kx_auth(t,
- NULL,
- ax,
- (0 == GCT_count_channels(t))
- ? GNUNET_NO
- : GNUNET_YES);
- break;
+ case CADET_TUNNEL_KEY_AX_RECV:
+ case CADET_TUNNEL_KEY_AX_SENT_AND_RECV:
+ /* We are responding, so only require reply
+ if WE have a channel waiting. */
+ if (NULL != t->unverified_ax)
+ {
+ /* Send AX_AUTH so we might get this one verified */
+ ax = t->unverified_ax;
+ }
+ else
+ {
+ /* How can this be? */
+ GNUNET_break (0);
+ ax = &t->ax;
+ }
+ send_kx_auth (t,
+ NULL,
+ ax,
+ (0 == GCT_count_channels (t))
+ ? GNUNET_NO
+ : GNUNET_YES);
+ break;
- case CADET_TUNNEL_KEY_AX_AUTH_SENT:
- /* We are responding, so only require reply
- if WE have a channel waiting. */
- if (NULL != t->unverified_ax)
- {
- /* Send AX_AUTH so we might get this one verified */
- ax = t->unverified_ax;
- }
- else
- {
- /* How can this be? */
- GNUNET_break(0);
- ax = &t->ax;
- }
- send_kx_auth(t,
- NULL,
- ax,
- (0 == GCT_count_channels(t))
- ? GNUNET_NO
- : GNUNET_YES);
- break;
+ case CADET_TUNNEL_KEY_AX_AUTH_SENT:
+ /* We are responding, so only require reply
+ if WE have a channel waiting. */
+ if (NULL != t->unverified_ax)
+ {
+ /* Send AX_AUTH so we might get this one verified */
+ ax = t->unverified_ax;