[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 01/02: simplify MQ logic to always carry the same
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 01/02: simplify MQ logic to always carry the same kinds of flags, and extend transport API to pass them to (TNG) service |
Date: |
Sat, 04 May 2019 22:19:01 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
commit 80f480c752fd8dfa1be51d78fce314d9f0650b50
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat May 4 22:16:24 2019 +0200
simplify MQ logic to always carry the same kinds of flags, and extend
transport API to pass them to (TNG) service
---
src/core/core.h | 33 +-
src/core/core_api.c | 266 ++++--------
src/core/gnunet-service-core.c | 527 ++++++++++------------
src/core/gnunet-service-core.h | 21 +-
src/core/gnunet-service-core_sessions.c | 285 +++++-------
src/core/gnunet-service-core_sessions.h | 7 +-
src/core/test_core_api.c | 207 ++++-----
src/hostlist/gnunet-daemon-hostlist_server.c | 268 ++++++------
src/include/gnunet_core_service.h | 90 +---
src/include/gnunet_mq_lib.h | 288 +++++++-----
src/nse/gnunet-service-nse.c | 627 +++++++++++----------------
src/topology/gnunet-daemon-topology.c | 377 ++++++----------
src/transport/gnunet-service-tng.c | 3 +
src/transport/transport.h | 4 +-
src/transport/transport_api2_core.c | 7 +-
src/transport/transport_api_core.c | 7 +-
src/util/mq.c | 277 +++++-------
17 files changed, 1413 insertions(+), 1881 deletions(-)
diff --git a/src/core/core.h b/src/core/core.h
index bc9638706..95d506fbd 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -42,23 +42,23 @@
* for handlers that were specifically registered are always
* transmitted to the client.
*/
-#define GNUNET_CORE_OPTION_NOTHING 0
+#define GNUNET_CORE_OPTION_NOTHING 0
/**
* Client cares about connectivity changes.
*/
-#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4
+#define GNUNET_CORE_OPTION_SEND_STATUS_CHANGE 4
/**
* Client wants all inbound messages in full.
*/
-#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8
+#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND 8
/**
* Client just wants the 4-byte message headers of
* all inbound messages.
*/
-#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16
+#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND 16
/**
* Client wants all outbound messages in full.
@@ -69,7 +69,7 @@
* Client just wants the 4-byte message headers of
* all outbound messages.
*/
-#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
+#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND 64
GNUNET_NETWORK_STRUCT_BEGIN
@@ -92,7 +92,6 @@ struct InitMessage
* Options, see GNUNET_CORE_OPTION_ values.
*/
uint32_t options GNUNET_PACKED;
-
};
@@ -117,7 +116,6 @@ struct InitReplyMessage
* Public key of the local peer.
*/
struct GNUNET_PeerIdentity my_identity;
-
};
@@ -141,7 +139,6 @@ struct ConnectNotifyMessage
* Identity of the connecting peer.
*/
struct GNUNET_PeerIdentity peer;
-
};
@@ -165,7 +162,6 @@ struct DisconnectNotifyMessage
* Identity of the connecting peer.
*/
struct GNUNET_PeerIdentity peer;
-
};
@@ -236,7 +232,6 @@ struct SendMessageRequest
* Counter for this peer to match SMRs to replies.
*/
uint16_t smr_id GNUNET_PACKED;
-
};
@@ -269,7 +264,6 @@ struct SendMessageReady
* Identity of the intended target.
*/
struct GNUNET_PeerIdentity peer;
-
};
@@ -285,7 +279,8 @@ struct SendMessage
struct GNUNET_MessageHeader header;
/**
- * How important is this message?
+ * How important is this message? Contains a
+ * `enum GNUNET_MQ_PriorityPreferences` in NBO.
*/
uint32_t priority GNUNET_PACKED;
@@ -299,17 +294,6 @@ struct SendMessage
* Identity of the intended receiver.
*/
struct GNUNET_PeerIdentity peer;
-
- /**
- * #GNUNET_YES if corking is allowed, #GNUNET_NO if not.
- */
- uint32_t cork GNUNET_PACKED;
-
- /**
- * Always 0.
- */
- uint32_t reserved GNUNET_PACKED;
-
};
@@ -338,7 +322,6 @@ struct MonitorNotifyMessage
* How long will we stay in this state (if nothing else happens)?
*/
struct GNUNET_TIME_AbsoluteNBO timeout;
-
};
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 6adaadabf..6381d9097 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -29,7 +29,7 @@
#include "gnunet_core_service.h"
#include "core.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "core-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__)
/**
@@ -69,7 +69,6 @@ struct PeerRecord
* SendMessageRequest ID generator for this peer.
*/
uint16_t smr_id_gen;
-
};
@@ -144,7 +143,6 @@ struct GNUNET_CORE_Handle
* Did we ever get INIT?
*/
int have_init;
-
};
@@ -170,8 +168,7 @@ reconnect_task (void *cls)
struct GNUNET_CORE_Handle *h = cls;
h->reconnect_task = NULL;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service after delay\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n");
reconnect (h);
}
@@ -187,7 +184,7 @@ reconnect_task (void *cls)
*/
static int
disconnect_and_free_peer_entry (void *cls,
- const struct GNUNET_PeerIdentity *key,
+ const struct GNUNET_PeerIdentity *key,
void *value)
{
struct GNUNET_CORE_Handle *h = cls;
@@ -195,13 +192,9 @@ disconnect_and_free_peer_entry (void *cls,
GNUNET_assert (pr->h == h);
if (NULL != h->disconnects)
- h->disconnects (h->cls,
- &pr->peer,
- pr->client_cls);
+ h->disconnects (h->cls, &pr->peer, pr->client_cls);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (h->peers,
- key,
- pr));
+ GNUNET_CONTAINER_multipeermap_remove (h->peers, key, pr));
GNUNET_MQ_destroy (pr->mq);
GNUNET_assert (NULL == pr->mq);
if (NULL != pr->env)
@@ -231,9 +224,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
}
GNUNET_assert (NULL == h->reconnect_task);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
- &reconnect_task,
- h);
+ GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h);
GNUNET_CONTAINER_multipeermap_iterate (h->peers,
&disconnect_and_free_peer_entry,
h);
@@ -249,38 +240,15 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
* @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_CORE_Handle *h = cls;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "MQ ERROR: %d\n",
- error);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error);
reconnect_later (h);
}
-/**
- * Inquire with CORE what options should be set for a message
- * so that it is transmitted with the given @a priority and
- * the given @a cork value.
- *
- * @param cork desired corking
- * @param priority desired message priority
- * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
- * @return `extra` argument to give to #GNUNET_MQ_set_options()
- */
-const void *
-GNUNET_CORE_get_mq_options (int cork,
- enum GNUNET_CORE_Priority priority,
- uint64_t *flags)
-{
- *flags = ((uint64_t) priority) + (((uint64_t) cork) << 32);
- return NULL;
-}
-
-
/**
* Implement sending functionality of a message queue for
* us sending messages to a peer.
@@ -291,8 +259,8 @@ GNUNET_CORE_get_mq_options (int cork,
*/
static void
core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct PeerRecord *pr = impl_state;
struct GNUNET_CORE_Handle *h = pr->h;
@@ -300,9 +268,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
struct SendMessage *sm;
struct GNUNET_MQ_Envelope *env;
uint16_t msize;
- uint64_t flags;
- int cork;
- enum GNUNET_CORE_Priority priority;
+ enum GNUNET_MQ_PriorityPreferences flags;
if (NULL == h->mq)
{
@@ -313,11 +279,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
GNUNET_assert (NULL == pr->env);
/* extract options from envelope */
env = GNUNET_MQ_get_current_envelope (mq);
- GNUNET_break (NULL ==
- GNUNET_MQ_env_get_options (env,
- &flags));
- cork = (int) (flags >> 32);
- priority = (uint32_t) flags;
+ flags = GNUNET_MQ_env_get_options (env);
/* check message size for sanity */
msize = ntohs (msg->size);
@@ -333,28 +295,20 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
"Asking core for transmission of %u bytes to `%s'\n",
(unsigned int) msize,
GNUNET_i2s (&pr->peer));
- env = GNUNET_MQ_msg (smr,
- GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
- smr->priority = htonl ((uint32_t) priority);
+ env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
+ smr->priority = htonl ((uint32_t) flags);
smr->peer = pr->peer;
- smr->reserved = htonl (0);
smr->size = htons (msize);
smr->smr_id = htons (++pr->smr_id_gen);
- GNUNET_MQ_send (h->mq,
- env);
+ GNUNET_MQ_send (h->mq, env);
/* prepare message with actual transmission data */
- pr->env = GNUNET_MQ_msg_nested_mh (sm,
- GNUNET_MESSAGE_TYPE_CORE_SEND,
- msg);
- sm->priority = htonl ((uint32_t) priority);
+ pr->env = GNUNET_MQ_msg_nested_mh (sm, GNUNET_MESSAGE_TYPE_CORE_SEND, msg);
+ sm->priority = htonl ((uint32_t) flags);
sm->peer = pr->peer;
- sm->cork = htonl ((uint32_t) cork);
- sm->reserved = htonl (0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Calling get_message with buffer of %u bytes (%s)\n",
- (unsigned int) msize,
- cork ? "corked" : "uncorked");
+ "Calling get_message with buffer of %u bytes\n",
+ (unsigned int) msize);
}
@@ -366,8 +320,7 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
* @param impl_state state of the implementation
*/
static void
-core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct PeerRecord *pr = impl_state;
@@ -384,8 +337,7 @@ core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq,
* @param impl_state state specific to the implementation
*/
static void
-core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct PeerRecord *pr = impl_state;
@@ -404,8 +356,7 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq,
* @param error error code
*/
static void
-core_mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
/* struct PeerRecord *pr = cls; */
@@ -423,41 +374,30 @@ core_mq_error_handler (void *cls,
*/
static void
connect_peer (struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *peer)
+ const struct GNUNET_PeerIdentity *peer)
{
struct PeerRecord *pr;
- uint64_t flags;
- const void *extra;
pr = GNUNET_new (struct PeerRecord);
pr->peer = *peer;
pr->h = h;
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_put (h->peers,
- &pr->peer,
- pr,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ h->peers,
+ &pr->peer,
+ pr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl,
- &core_mq_destroy_impl,
- &core_mq_cancel_impl,
- pr,
- h->handlers,
- &core_mq_error_handler,
- pr);
- /* get our default options */
- extra = GNUNET_CORE_get_mq_options (GNUNET_NO,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- &flags);
- GNUNET_MQ_set_options (pr->mq,
- flags,
- extra);
+ &core_mq_destroy_impl,
+ &core_mq_cancel_impl,
+ pr,
+ h->handlers,
+ &core_mq_error_handler,
+ pr);
if (NULL != h->connects)
{
- pr->client_cls = h->connects (h->cls,
- &pr->peer,
- pr->mq);
- GNUNET_MQ_set_handlers_closure (pr->mq,
- pr->client_cls);
+ pr->client_cls = h->connects (h->cls, &pr->peer, pr->mq);
+ GNUNET_MQ_set_handlers_closure (pr->mq, pr->client_cls);
}
}
@@ -471,8 +411,7 @@ connect_peer (struct GNUNET_CORE_Handle *h,
* @param m the init reply
*/
static void
-handle_init_reply (void *cls,
- const struct InitReplyMessage *m)
+handle_init_reply (void *cls, const struct InitReplyMessage *m)
{
struct GNUNET_CORE_Handle *h = cls;
GNUNET_CORE_StartupCallback init;
@@ -488,8 +427,7 @@ handle_init_reply (void *cls,
"Connected to core service of peer `%s'.\n",
GNUNET_i2s (&h->me));
h->have_init = GNUNET_YES;
- init (h->cls,
- &h->me);
+ init (h->cls, &h->me);
}
else
{
@@ -508,8 +446,7 @@ handle_init_reply (void *cls,
}
}
/* fake 'connect to self' */
- connect_peer (h,
- &h->me);
+ connect_peer (h, &h->me);
}
@@ -521,8 +458,7 @@ handle_init_reply (void *cls,
* @param cnm the connect message
*/
static void
-handle_connect_notify (void *cls,
- const struct ConnectNotifyMessage *cnm)
+handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm)
{
struct GNUNET_CORE_Handle *h = cls;
struct PeerRecord *pr;
@@ -530,24 +466,20 @@ handle_connect_notify (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received notification about connection from `%s'.\n",
GNUNET_i2s (&cnm->peer));
- if (0 == memcmp (&h->me,
- &cnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity)))
{
/* connect to self!? */
GNUNET_break (0);
return;
}
- pr = GNUNET_CONTAINER_multipeermap_get (h->peers,
- &cnm->peer);
+ pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &cnm->peer);
if (NULL != pr)
{
GNUNET_break (0);
reconnect_later (h);
return;
}
- connect_peer (h,
- &cnm->peer);
+ connect_peer (h, &cnm->peer);
}
@@ -559,15 +491,12 @@ handle_connect_notify (void *cls,
* @param dnm message about the disconnect event
*/
static void
-handle_disconnect_notify (void *cls,
- const struct DisconnectNotifyMessage *dnm)
+handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm)
{
struct GNUNET_CORE_Handle *h = cls;
struct PeerRecord *pr;
- if (0 == memcmp (&h->me,
- &dnm->peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity)))
{
/* disconnect from self!? */
GNUNET_break (0);
@@ -577,17 +506,14 @@ handle_disconnect_notify (void *cls,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received notification about disconnect from `%s'.\n",
GNUNET_i2s (&dnm->peer));
- pr = GNUNET_CONTAINER_multipeermap_get (h->peers,
- &dnm->peer);
+ pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &dnm->peer);
if (NULL == pr)
{
GNUNET_break (0);
reconnect_later (h);
return;
}
- disconnect_and_free_peer_entry (h,
- &pr->peer,
- pr);
+ disconnect_and_free_peer_entry (h, &pr->peer, pr);
}
@@ -599,8 +525,7 @@ handle_disconnect_notify (void *cls,
* @return #GNUNET_OK if the message is well-formed
*/
static int
-check_notify_inbound (void *cls,
- const struct NotifyTrafficMessage *ntm)
+check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
{
uint16_t msize;
const struct GNUNET_MessageHeader *em;
@@ -629,8 +554,7 @@ check_notify_inbound (void *cls,
* @param ntm the message we got from CORE.
*/
static void
-handle_notify_inbound (void *cls,
- const struct NotifyTrafficMessage *ntm)
+handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
{
struct GNUNET_CORE_Handle *h = cls;
const struct GNUNET_MessageHeader *em;
@@ -640,16 +564,14 @@ handle_notify_inbound (void *cls,
"Received inbound message from `%s'.\n",
GNUNET_i2s (&ntm->peer));
em = (const struct GNUNET_MessageHeader *) &ntm[1];
- pr = GNUNET_CONTAINER_multipeermap_get (h->peers,
- &ntm->peer);
+ pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &ntm->peer);
if (NULL == pr)
{
GNUNET_break (0);
reconnect_later (h);
return;
}
- GNUNET_MQ_inject_message (pr->mq,
- em);
+ GNUNET_MQ_inject_message (pr->mq, em);
}
@@ -662,14 +584,12 @@ handle_notify_inbound (void *cls,
* @param smr the message we got
*/
static void
-handle_send_ready (void *cls,
- const struct SendMessageReady *smr)
+handle_send_ready (void *cls, const struct SendMessageReady *smr)
{
struct GNUNET_CORE_Handle *h = cls;
struct PeerRecord *pr;
- pr = GNUNET_CONTAINER_multipeermap_get (h->peers,
- &smr->peer);
+ pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &smr->peer);
if (NULL == pr)
{
GNUNET_break (0);
@@ -693,8 +613,7 @@ handle_send_ready (void *cls,
}
/* ok, all good, send message out! */
- GNUNET_MQ_send (h->mq,
- pr->env);
+ GNUNET_MQ_send (h->mq, pr->env);
pr->env = NULL;
GNUNET_MQ_impl_send_continue (pr->mq);
}
@@ -709,39 +628,34 @@ handle_send_ready (void *cls,
static void
reconnect (struct GNUNET_CORE_Handle *h)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (init_reply,
- GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY,
- struct InitReplyMessage,
- h),
- GNUNET_MQ_hd_fixed_size (connect_notify,
- GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
- struct ConnectNotifyMessage,
- h),
- GNUNET_MQ_hd_fixed_size (disconnect_notify,
- GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
- struct DisconnectNotifyMessage,
- h),
- GNUNET_MQ_hd_var_size (notify_inbound,
- GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
- struct NotifyTrafficMessage,
- h),
- GNUNET_MQ_hd_fixed_size (send_ready,
- GNUNET_MESSAGE_TYPE_CORE_SEND_READY,
- struct SendMessageReady,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (init_reply,
+ GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY,
+ struct InitReplyMessage,
+ h),
+ GNUNET_MQ_hd_fixed_size (connect_notify,
+ GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
+ struct ConnectNotifyMessage,
+ h),
+ GNUNET_MQ_hd_fixed_size (disconnect_notify,
+ GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
+ struct DisconnectNotifyMessage,
+ h),
+ GNUNET_MQ_hd_var_size (notify_inbound,
+ GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
+ struct NotifyTrafficMessage,
+ h),
+ GNUNET_MQ_hd_fixed_size (send_ready,
+ GNUNET_MESSAGE_TYPE_CORE_SEND_READY,
+ struct SendMessageReady,
+ h),
+ GNUNET_MQ_handler_end ()};
struct InitMessage *init;
struct GNUNET_MQ_Envelope *env;
uint16_t *ts;
GNUNET_assert (NULL == h->mq);
- h->mq = GNUNET_CLIENT_connect (h->cfg,
- "core",
- handlers,
- &handle_mq_error,
- h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg, "core", handlers, &handle_mq_error,
h);
if (NULL == h->mq)
{
reconnect_later (h);
@@ -750,14 +664,12 @@ reconnect (struct GNUNET_CORE_Handle *h)
env = GNUNET_MQ_msg_extra (init,
sizeof (uint16_t) * h->hcnt,
GNUNET_MESSAGE_TYPE_CORE_INIT);
- LOG (GNUNET_ERROR_TYPE_INFO,
- "(Re)connecting to CORE service\n");
+ LOG (GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n");
init->options = htonl (0);
ts = (uint16_t *) &init[1];
for (unsigned int hpos = 0; hpos < h->hcnt; hpos++)
ts[hpos] = htons (h->handlers[hpos].type);
- GNUNET_MQ_send (h->mq,
- env);
+ GNUNET_MQ_send (h->mq, env);
}
@@ -791,15 +703,13 @@ GNUNET_CORE_connect (const struct
GNUNET_CONFIGURATION_Handle *cfg,
h->init = init;
h->connects = connects;
h->disconnects = disconnects;
- h->peers = GNUNET_CONTAINER_multipeermap_create (128,
- GNUNET_NO);
+ h->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
h->handlers = GNUNET_MQ_copy_handlers (handlers);
h->hcnt = GNUNET_MQ_count_handlers (handlers);
GNUNET_assert (h->hcnt <
- (GNUNET_MAX_MESSAGE_SIZE -
- sizeof (struct InitMessage)) / sizeof (uint16_t));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to CORE service\n");
+ (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InitMessage)) /
+ sizeof (uint16_t));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
reconnect (h);
if (NULL == h->mq)
{
@@ -818,8 +728,7 @@ GNUNET_CORE_connect (const struct
GNUNET_CONFIGURATION_Handle *cfg,
void
GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from CORE service\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
GNUNET_CONTAINER_multipeermap_iterate (handle->peers,
&disconnect_and_free_peer_entry,
handle);
@@ -849,12 +758,11 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
*/
struct GNUNET_MQ_Handle *
GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *pid)
+ const struct GNUNET_PeerIdentity *pid)
{
struct PeerRecord *pr;
- pr = GNUNET_CONTAINER_multipeermap_get (h->peers,
- pid);
+ pr = GNUNET_CONTAINER_multipeermap_get (h->peers, pid);
if (NULL == pr)
return NULL;
return pr->mq;
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index e26bb4d5c..740707ce1 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -107,7 +107,6 @@ struct GSC_Client
* specifically cares about. Size of the @e types array.
*/
unsigned int tcnt;
-
};
@@ -150,12 +149,10 @@ static struct GSC_Client *client_tail;
* @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not.
*/
static int
-type_match (uint16_t type,
- struct GSC_Client *c)
+type_match (uint16_t type, struct GSC_Client *c)
{
- if ( (0 == c->tcnt) &&
- (0 != c->options) )
- return GNUNET_YES; /* peer without handlers and inbound/outbond
+ if ((0 == c->tcnt) && (0 != c->options))
+ return GNUNET_YES; /* peer without handlers and inbound/outbond
callbacks matches ALL */
if (NULL == c->types)
return GNUNET_NO;
@@ -174,8 +171,7 @@ type_match (uint16_t type,
* @return #GNUNET_OK if @a im is well-formed
*/
static int
-check_client_init (void *cls,
- const struct InitMessage *im)
+check_client_init (void *cls, const struct InitMessage *im)
{
return GNUNET_OK;
}
@@ -188,8 +184,7 @@ check_client_init (void *cls,
* @param im the `struct InitMessage`
*/
static void
-handle_client_init (void *cls,
- const struct InitMessage *im)
+handle_client_init (void *cls, const struct InitMessage *im)
{
struct GSC_Client *c = cls;
struct GNUNET_MQ_Envelope *env;
@@ -206,24 +201,23 @@ handle_client_init (void *cls,
all_client_options |= c->options;
c->types = GNUNET_malloc (msize);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_put (c->connectmap,
- &GSC_my_identity,
- NULL,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ c->connectmap,
+ &GSC_my_identity,
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
for (unsigned int i = 0; i < c->tcnt; i++)
c->types[i] = ntohs (types[i]);
- GSC_TYPEMAP_add (c->types,
- c->tcnt);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client connecting to core service is interested in %u message
types\n",
- (unsigned int) c->tcnt);
+ GSC_TYPEMAP_add (c->types, c->tcnt);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Client connecting to core service is interested in %u message types\n",
+ (unsigned int) c->tcnt);
/* send init reply message */
- env = GNUNET_MQ_msg (irm,
- GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
+ env = GNUNET_MQ_msg (irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
irm->reserved = htonl (0);
irm->my_identity = GSC_my_identity;
- GNUNET_MQ_send (c->mq,
- env);
+ GNUNET_MQ_send (c->mq, env);
GSC_SESSIONS_notify_client_about_sessions (c);
GNUNET_SERVICE_client_continue (c->client);
}
@@ -245,11 +239,11 @@ void
GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
int drop_client)
{
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (car->
- client_handle->requests,
- &car->target,
- car));
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests,
+ &car->target,
+ car));
if (GNUNET_YES == drop_client)
GNUNET_SERVICE_client_drop (car->client_handle->client);
GNUNET_free (car);
@@ -274,38 +268,31 @@ GSC_CLIENTS_solicit_request (struct
GSC_ClientActiveRequest *car)
c = car->client_handle;
if (GNUNET_YES !=
- GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
- &car->target))
+ GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &car->target))
{
/* connection has gone down since, drop request */
- GNUNET_assert (0 !=
- memcmp (&car->target,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)));
+ GNUNET_assert (0 != memcmp (&car->target,
+ &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)));
GSC_SESSIONS_dequeue_request (car);
- GSC_CLIENTS_reject_request (car,
- GNUNET_NO);
+ GSC_CLIENTS_reject_request (car, GNUNET_NO);
return;
}
delay = GNUNET_TIME_absolute_get_duration (car->received_time);
left = GNUNET_TIME_absolute_get_duration (car->deadline);
if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Client waited %s for permission to transmit to `%s'%s
(priority %u)\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
- GNUNET_i2s (&car->target),
- (0 == left.rel_value_us)
- ? " (past deadline)"
- : "",
- car->priority);
- env = GNUNET_MQ_msg (smr,
- GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ "Client waited %s for permission to transmit to `%s'%s (priority %u)\n",
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
+ GNUNET_i2s (&car->target),
+ (0 == left.rel_value_us) ? " (past deadline)" : "",
+ car->priority);
+ env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
smr->size = htons (car->msize);
smr->smr_id = car->smr_id;
smr->peer = car->target;
- GNUNET_MQ_send (c->mq,
- env);
+ GNUNET_MQ_send (c->mq, env);
}
@@ -316,51 +303,47 @@ GSC_CLIENTS_solicit_request (struct
GSC_ClientActiveRequest *car)
* @param req the `struct SendMessageRequest`
*/
static void
-handle_client_send_request (void *cls,
- const struct SendMessageRequest *req)
+handle_client_send_request (void *cls, const struct SendMessageRequest *req)
{
struct GSC_Client *c = cls;
struct GSC_ClientActiveRequest *car;
int is_loopback;
if (NULL == c->requests)
- c->requests = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_NO);
+ c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Client asked for transmission to `%s'\n",
GNUNET_i2s (&req->peer));
- is_loopback =
- (0 ==
- memcmp (&req->peer,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)));
+ is_loopback = (0 == memcmp (&req->peer,
+ &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)));
if ((! is_loopback) &&
(GNUNET_YES !=
- GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
- &req->peer)))
+ GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &req->peer)))
{
/* neighbour must have disconnected since request was issued,
* ignore (client will realize it once it processes the
* disconnect notification) */
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# send requests dropped (disconnected)"), 1,
+ gettext_noop (
+ "# send requests dropped (disconnected)"),
+ 1,
GNUNET_NO);
GNUNET_SERVICE_client_continue (c->client);
return;
}
- car = GNUNET_CONTAINER_multipeermap_get (c->requests,
- &req->peer);
+ car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer);
if (NULL == car)
{
/* create new entry */
car = GNUNET_new (struct GSC_ClientActiveRequest);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (c->requests,
- &req->peer,
- car,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+ GNUNET_CONTAINER_multipeermap_put (
+ c->requests,
+ &req->peer,
+ car,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
car->client_handle = c;
}
else
@@ -368,8 +351,9 @@ handle_client_send_request (void *cls,
/* dequeue and recycle memory from pending request, there can only
be at most one per client and peer */
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# dequeuing CAR (duplicate
request)"),
- 1,
+ gettext_noop (
+ "# dequeuing CAR (duplicate request)"),
+ 1,
GNUNET_NO);
GSC_SESSIONS_dequeue_request (car);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -379,7 +363,7 @@ handle_client_send_request (void *cls,
car->target = req->peer;
car->received_time = GNUNET_TIME_absolute_get ();
car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
- car->priority = (enum GNUNET_CORE_Priority) ntohl (req->priority);
+ car->priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (req->priority);
car->msize = ntohs (req->size);
car->smr_id = req->smr_id;
car->was_solicited = GNUNET_NO;
@@ -408,13 +392,7 @@ struct TokenizerContext
/**
* How important is this message.
*/
- enum GNUNET_CORE_Priority priority;
-
- /**
- * Is corking allowed (set only once we have the real message).
- */
- int cork;
-
+ enum GNUNET_MQ_PriorityPreferences priority;
};
@@ -431,65 +409,57 @@ struct TokenizerContext
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-tokenized_cb (void *cls,
- const struct GNUNET_MessageHeader *message)
+tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message)
{
struct TokenizerContext *tc = cls;
struct GSC_ClientActiveRequest *car = tc->car;
char buf[92];
GNUNET_snprintf (buf,
- sizeof (buf),
- gettext_noop ("# bytes of messages of type %u received"),
- (unsigned int) ntohs (message->type));
- GNUNET_STATISTICS_update (GSC_stats,
- buf,
- ntohs (message->size),
- GNUNET_NO);
- if (0 ==
- memcmp (&car->target,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ sizeof (buf),
+ gettext_noop ("# bytes of messages of type %u received"),
+ (unsigned int) ntohs (message->type));
+ GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO);
+ if (0 == memcmp (&car->target,
+ &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delivering message of type %u to myself\n",
ntohs (message->type));
GSC_CLIENTS_deliver_message (&GSC_my_identity,
- message,
- ntohs (message->size),
- GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
+ message,
+ ntohs (message->size),
+ GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
GSC_CLIENTS_deliver_message (&GSC_my_identity,
- message,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
+ message,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
GSC_CLIENTS_deliver_message (&GSC_my_identity,
- message,
- ntohs (message->size),
- GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
+ message,
+ ntohs (message->size),
+ GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
GSC_CLIENTS_deliver_message (&GSC_my_identity,
- message,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
+ message,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delivering message of type %u and size %u to %s\n",
ntohs (message->type),
- ntohs (message->size),
+ ntohs (message->size),
GNUNET_i2s (&car->target));
GSC_CLIENTS_deliver_message (&car->target,
- message,
- ntohs (message->size),
- GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
+ message,
+ ntohs (message->size),
+ GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
GSC_CLIENTS_deliver_message (&car->target,
- message,
- sizeof (struct GNUNET_MessageHeader),
- GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
- GSC_SESSIONS_transmit (car,
- message,
- tc->cork,
- tc->priority);
+ message,
+ sizeof (struct GNUNET_MessageHeader),
+ GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
+ GSC_SESSIONS_transmit (car, message, tc->priority);
}
return GNUNET_OK;
}
@@ -503,8 +473,7 @@ tokenized_cb (void *cls,
* @return #GNUNET_OK if @a sm is well-formed
*/
static int
-check_client_send (void *cls,
- const struct SendMessage *sm)
+check_client_send (void *cls, const struct SendMessage *sm)
{
return GNUNET_OK;
}
@@ -517,8 +486,7 @@ check_client_send (void *cls,
* @param sm the `struct SendMessage`
*/
static void
-handle_client_send (void *cls,
- const struct SendMessage *sm)
+handle_client_send (void *cls, const struct SendMessage *sm)
{
struct GSC_Client *c = cls;
struct TokenizerContext tc;
@@ -527,9 +495,7 @@ handle_client_send (void *cls,
struct GNUNET_MessageStreamTokenizer *mst;
msize = ntohs (sm->header.size) - sizeof (struct SendMessage);
- GNUNET_break (0 == ntohl (sm->reserved));
- tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests,
- &sm->peer);
+ tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer);
if (NULL == tc.car)
{
/* Must have been that we first approved the request, then got disconnected
@@ -538,43 +504,37 @@ handle_client_send (void *cls,
* might also now be *again* connected. So this can happen (but should be
* rare). If it does happen, the message is discarded. */
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# messages discarded (session
disconnected)"),
+ gettext_noop (
+ "# messages discarded (session disconnected)"),
1,
- GNUNET_NO);
+ GNUNET_NO);
GNUNET_SERVICE_client_continue (c->client);
return;
}
delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time);
- tc.cork = ntohl (sm->cork);
- tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority);
+ tc.priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (sm->priority);
if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Client waited %s for transmission of %u bytes to `%s'%s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
+ "Client waited %s for transmission of %u bytes to `%s'\n",
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
msize,
- GNUNET_i2s (&sm->peer),
- tc.cork ? " (cork)" : " (uncorked)");
+ GNUNET_i2s (&sm->peer));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client waited %s for transmission of %u bytes to `%s'%s\n",
- GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES),
+ "Client waited %s for transmission of %u bytes to `%s'\n",
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
msize,
- GNUNET_i2s (&sm->peer),
- tc.cork ? " (cork)" : " (uncorked)");
+ GNUNET_i2s (&sm->peer));
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (c->requests,
- &sm->peer,
- tc.car));
- mst = GNUNET_MST_create (&tokenized_cb,
- &tc);
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (c->requests, &sm->peer, tc.car));
+ mst = GNUNET_MST_create (&tokenized_cb, &tc);
GNUNET_MST_from_buffer (mst,
- (const char *) &sm[1],
- msize,
- GNUNET_YES,
- GNUNET_NO);
+ (const char *) &sm[1],
+ msize,
+ GNUNET_YES,
+ GNUNET_NO);
GNUNET_MST_destroy (mst);
GSC_SESSIONS_dequeue_request (tc.car);
GNUNET_free (tc.car);
@@ -592,16 +552,16 @@ handle_client_send (void *cls,
*/
static int
destroy_active_client_request (void *cls,
- const struct GNUNET_PeerIdentity *key,
+ const struct GNUNET_PeerIdentity *key,
void *value)
{
struct GSC_ClientActiveRequest *car = value;
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (car->
- client_handle->requests,
- &car->target,
- car));
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests,
+ &car->target,
+ car));
GSC_SESSIONS_dequeue_request (car);
GNUNET_free (car);
return GNUNET_YES;
@@ -618,19 +578,16 @@ destroy_active_client_request (void *cls,
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
{
struct GSC_Client *c;
c = GNUNET_new (struct GSC_Client);
c->client = client;
c->mq = mq;
- c->connectmap = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert (client_head,
- client_tail,
- c);
+ c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
+ GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
return c;
}
@@ -644,17 +601,15 @@ client_connect_cb (void *cls,
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
{
struct GSC_Client *c = app_ctx;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Client %p has disconnected from core service.\n",
client);
- GNUNET_CONTAINER_DLL_remove (client_head,
- client_tail,
- c);
+ GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
if (NULL != c->requests)
{
GNUNET_CONTAINER_multipeermap_iterate (c->requests,
@@ -666,15 +621,14 @@ client_disconnect_cb (void *cls,
c->connectmap = NULL;
if (NULL != c->types)
{
- GSC_TYPEMAP_remove (c->types,
- c->tcnt);
+ GSC_TYPEMAP_remove (c->types, c->tcnt);
GNUNET_free (c->types);
}
GNUNET_free (c);
/* recalculate 'all_client_options' */
all_client_options = 0;
- for (c = client_head; NULL != c ; c = c->next)
+ for (c = client_head; NULL != c; c = c->next)
all_client_options |= c->options;
}
@@ -690,10 +644,11 @@ client_disconnect_cb (void *cls,
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
- const struct GNUNET_PeerIdentity
*neighbour,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new)
+GSC_CLIENTS_notify_client_about_neighbour (
+ struct GSC_Client *client,
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new)
{
struct GNUNET_MQ_Envelope *env;
int old_match;
@@ -701,12 +656,8 @@ GSC_CLIENTS_notify_client_about_neighbour (struct
GSC_Client *client,
if (GNUNET_YES != client->got_init)
return;
- old_match = GSC_TYPEMAP_test_match (tmap_old,
- client->types,
- client->tcnt);
- new_match = GSC_TYPEMAP_test_match (tmap_new,
- client->types,
- client->tcnt);
+ old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt);
+ new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Notifying client about neighbour %s (%d/%d)\n",
GNUNET_i2s (neighbour),
@@ -714,55 +665,52 @@ GSC_CLIENTS_notify_client_about_neighbour (struct
GSC_Client *client,
new_match);
if (old_match == new_match)
{
- GNUNET_assert (old_match ==
- GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
- neighbour));
- return; /* no change */
+ GNUNET_assert (
+ old_match ==
+ GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
+ return; /* no change */
}
if (GNUNET_NO == old_match)
{
struct ConnectNotifyMessage *cnm;
/* send connect */
- GNUNET_assert (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
- neighbour));
+ GNUNET_assert (
+ GNUNET_NO ==
+ GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_put (client->connectmap,
- neighbour,
- NULL,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- env = GNUNET_MQ_msg (cnm,
- GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
+ GNUNET_CONTAINER_multipeermap_put (
+ client->connectmap,
+ neighbour,
+ NULL,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ env = GNUNET_MQ_msg (cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
cnm->reserved = htonl (0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending NOTIFY_CONNECT message about peer %s to client.\n",
GNUNET_i2s (neighbour));
cnm->peer = *neighbour;
- GNUNET_MQ_send (client->mq,
- env);
+ GNUNET_MQ_send (client->mq, env);
}
else
{
struct DisconnectNotifyMessage *dcm;
/* send disconnect */
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
- neighbour));
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour));
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (client->connectmap,
neighbour,
NULL));
- env = GNUNET_MQ_msg (dcm,
- GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
+ env = GNUNET_MQ_msg (dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
dcm->reserved = htonl (0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending NOTIFY_DISCONNECT message about peer %s to client.\n",
GNUNET_i2s (neighbour));
dcm->peer = *neighbour;
- GNUNET_MQ_send (client->mq,
- env);
+ GNUNET_MQ_send (client->mq, env);
}
}
@@ -777,17 +725,18 @@ GSC_CLIENTS_notify_client_about_neighbour (struct
GSC_Client *client,
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
*neighbour,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new)
+GSC_CLIENTS_notify_clients_about_neighbour (
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new)
{
struct GSC_Client *c;
for (c = client_head; NULL != c; c = c->next)
GSC_CLIENTS_notify_client_about_neighbour (c,
- neighbour,
+ neighbour,
tmap_old,
- tmap_new);
+ tmap_new);
}
@@ -815,15 +764,14 @@ GSC_CLIENTS_deliver_message (const struct
GNUNET_PeerIdentity *sender,
GNUNET_break (0);
return;
}
- if (! ( (0 != (all_client_options & options)) ||
- (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ))
+ if (! ((0 != (all_client_options & options)) ||
+ (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))))
return; /* no client cares about this message notification */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core service passes message from `%s' of type %u to client.\n",
GNUNET_i2s (sender),
(unsigned int) ntohs (msg->type));
- GSC_SESSIONS_add_to_typemap (sender,
- ntohs (msg->type));
+ GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
for (struct GSC_Client *c = client_head; NULL != c; c = c->next)
{
@@ -833,18 +781,17 @@ GSC_CLIENTS_deliver_message (const struct
GNUNET_PeerIdentity *sender,
unsigned int qlen;
int tm;
- tm = type_match (ntohs (msg->type),
- c);
- if (! ( (0 != (c->options & options)) ||
- ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
- (GNUNET_YES == tm) ) ) )
- continue; /* neither options nor type match permit the message */
- if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
- ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
- (GNUNET_YES == tm) ) )
+ tm = type_match (ntohs (msg->type), c);
+ if (! ((0 != (c->options & options)) ||
+ ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
+ (GNUNET_YES == tm))))
+ continue; /* neither options nor type match permit the message */
+ if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
+ ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
+ (GNUNET_YES == tm)))
continue;
- if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
- (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) )
+ if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
+ (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)))
continue;
/* Drop messages if:
@@ -862,54 +809,50 @@ GSC_CLIENTS_deliver_message (const struct
GNUNET_PeerIdentity *sender,
(ACK, queries) which may be cummulative or highly redundant,
and cheap to drop than data traffic. */
qlen = GNUNET_MQ_get_length (c->mq);
- if ( (qlen >= HARD_MAX_QUEUE) ||
- ( (qlen > SOFT_MAX_QUEUE) &&
- ( (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- ntohs (msg->size)) ) <
- (qlen - SOFT_MAX_QUEUE) * 0x8000 /
- (HARD_MAX_QUEUE - SOFT_MAX_QUEUE) ) ) )
+ if ((qlen >= HARD_MAX_QUEUE) ||
+ ((qlen > SOFT_MAX_QUEUE) &&
+ ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ ntohs (msg->size))) <
+ (qlen - SOFT_MAX_QUEUE) * 0x8000 /
+ (HARD_MAX_QUEUE - SOFT_MAX_QUEUE))))
{
char buf[1024];
- GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
- "Dropping decrypted message of type %u as client is too busy
(queue full)\n",
- (unsigned int) ntohs (msg->type));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
+ "Dropping decrypted message of type %u as client is too busy (queue
full)\n",
+ (unsigned int) ntohs (msg->type));
GNUNET_snprintf (buf,
sizeof (buf),
- gettext_noop ("# messages of type %u discarded (client
busy)"),
+ gettext_noop (
+ "# messages of type %u discarded (client busy)"),
(unsigned int) ntohs (msg->type));
- GNUNET_STATISTICS_update (GSC_stats,
- buf,
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (GSC_stats, buf, 1, GNUNET_NO);
continue;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u message with %u bytes to client interested in
messages of type %u.\n",
- options,
- ntohs (msg->size),
- (unsigned int) ntohs (msg->type));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %u message with %u bytes to client interested in messages of
type %u.\n",
+ options,
+ ntohs (msg->size),
+ (unsigned int) ntohs (msg->type));
- if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
+ if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
+ GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND;
else
mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND;
- env = GNUNET_MQ_msg_extra (ntm,
- msize,
- mtype);
+ env = GNUNET_MQ_msg_extra (ntm, msize, mtype);
ntm->peer = *sender;
- GNUNET_memcpy (&ntm[1],
- msg,
- msize);
-
- GNUNET_assert ( (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))
||
- (GNUNET_YES != tm) ||
- (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
- sender)) );
- GNUNET_MQ_send (c->mq,
- env);
+ GNUNET_memcpy (&ntm[1], msg, msize);
+
+ GNUNET_assert (
+ (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
+ (GNUNET_YES != tm) ||
+ (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_contains (c->connectmap, sender)));
+ GNUNET_MQ_send (c->mq, env);
}
}
@@ -925,8 +868,7 @@ shutdown_task (void *cls)
{
struct GSC_Client *c;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core service shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
while (NULL != (c = client_head))
GNUNET_SERVICE_client_drop (c->client);
GSC_SESSIONS_done ();
@@ -934,8 +876,7 @@ shutdown_task (void *cls)
GSC_TYPEMAP_done ();
if (NULL != GSC_stats)
{
- GNUNET_STATISTICS_destroy (GSC_stats,
- GNUNET_NO);
+ GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO);
GSC_stats = NULL;
}
GSC_cfg = NULL;
@@ -953,7 +894,7 @@ shutdown_task (void *cls)
*/
static void
handle_client_monitor_peers (void *cls,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_MessageHeader *message)
{
struct GSC_Client *c = cls;
@@ -978,21 +919,19 @@ run (void *cls,
char *keyfile;
GSC_cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (GSC_cfg,
- "PEER",
- "PRIVATE_KEY",
- &keyfile))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &keyfile))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Core service is lacking HOSTKEY configuration setting.
Exiting.\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Core service is lacking HOSTKEY configuration setting.
Exiting.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
- GSC_stats = GNUNET_STATISTICS_create ("core",
- GSC_cfg);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVICE_suspend (service);
GSC_TYPEMAP_init ();
pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
@@ -1006,7 +945,7 @@ run (void *cls,
GSC_SESSIONS_init ();
GNUNET_SERVICE_resume (service);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Core service of `%s' ready.\n"),
+ _ ("Core service of `%s' ready.\n"),
GNUNET_i2s (&GSC_my_identity));
}
@@ -1014,30 +953,30 @@ run (void *cls,
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("core",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (client_init,
- GNUNET_MESSAGE_TYPE_CORE_INIT,
- struct InitMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (client_monitor_peers,
- GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (client_send_request,
- GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
- struct SendMessageRequest,
- NULL),
- GNUNET_MQ_hd_var_size (client_send,
- GNUNET_MESSAGE_TYPE_CORE_SEND,
- struct SendMessage,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "core",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (client_init,
+ GNUNET_MESSAGE_TYPE_CORE_INIT,
+ struct InitMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_monitor_peers,
+ GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (client_send_request,
+ GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
+ struct SendMessageRequest,
+ NULL),
+ GNUNET_MQ_hd_var_size (client_send,
+ GNUNET_MESSAGE_TYPE_CORE_SEND,
+ struct SendMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-core.c */
diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h
index 00461c5ab..154596933 100644
--- a/src/core/gnunet-service-core.h
+++ b/src/core/gnunet-service-core.h
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -81,7 +81,7 @@ struct GSC_ClientActiveRequest
/**
* How important is this request.
*/
- enum GNUNET_CORE_Priority priority;
+ enum GNUNET_MQ_PriorityPreferences priority;
/**
* Has this request been solicited yet?
@@ -97,7 +97,6 @@ struct GSC_ClientActiveRequest
* Unique request ID (in big endian).
*/
uint16_t smr_id;
-
};
@@ -140,10 +139,11 @@ GSC_CLIENTS_reject_request (struct
GSC_ClientActiveRequest *car,
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
- const struct GNUNET_PeerIdentity
*neighbour,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap *tmap_new);
+GSC_CLIENTS_notify_client_about_neighbour (
+ struct GSC_Client *client,
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new);
/**
@@ -174,9 +174,10 @@ GSC_CLIENTS_deliver_message (const struct
GNUNET_PeerIdentity *sender,
* @param tmap_new updated type map for the neighbour, NULL for disconnect
*/
void
-GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
*neighbour,
- const struct GSC_TypeMap *tmap_old,
- const struct GSC_TypeMap
*tmap_new);
+GSC_CLIENTS_notify_clients_about_neighbour (
+ const struct GNUNET_PeerIdentity *neighbour,
+ const struct GSC_TypeMap *tmap_old,
+ const struct GSC_TypeMap *tmap_new);
/**
diff --git a/src/core/gnunet-service-core_sessions.c
b/src/core/gnunet-service-core_sessions.c
index 4f678c784..8ff61ec20 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -59,7 +59,7 @@ struct SessionMessageEntry
/**
* How important is this message.
*/
- enum GNUNET_CORE_Priority priority;
+ enum GNUNET_MQ_PriorityPreferences priority;
/**
* Flag set to #GNUNET_YES if this is a typemap message.
@@ -84,7 +84,6 @@ struct SessionMessageEntry
* MessageEntry` itself!)
*/
size_t size;
-
};
@@ -177,7 +176,6 @@ struct TypeMapConfirmationMessage
* Hash of the (decompressed) type map that was received.
*/
struct GNUNET_HashCode tm_hash;
-
};
GNUNET_NETWORK_STRUCT_END
@@ -201,8 +199,7 @@ find_session (const struct GNUNET_PeerIdentity *peer)
{
if (NULL == sessions)
return NULL;
- return GNUNET_CONTAINER_multipeermap_get (sessions,
- peer);
+ return GNUNET_CONTAINER_multipeermap_get (sessions, peer);
}
@@ -233,15 +230,13 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
while (NULL != (car = session->active_client_request_head))
{
GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
- session->active_client_request_tail, car);
- GSC_CLIENTS_reject_request (car,
- GNUNET_NO);
+ session->active_client_request_tail,
+ car);
+ GSC_CLIENTS_reject_request (car, GNUNET_NO);
}
while (NULL != (sme = session->sme_head))
{
- GNUNET_CONTAINER_DLL_remove (session->sme_head,
- session->sme_tail,
- sme);
+ GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
GNUNET_free (sme);
}
if (NULL != session->typemap_task)
@@ -251,13 +246,12 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
}
GSC_CLIENTS_notify_clients_about_neighbour (session->peer,
session->tmap,
- NULL);
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (sessions,
- session->peer,
- session));
+ NULL);
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (sessions, session->peer, session));
GNUNET_STATISTICS_set (GSC_stats,
- gettext_noop ("# peers connected"),
+ gettext_noop ("# peers connected"),
GNUNET_CONTAINER_multipeermap_size (sessions),
GNUNET_NO);
GSC_TYPEMAP_destroy (session->tmap);
@@ -286,20 +280,15 @@ transmit_typemap_task (void *cls)
delay = session->typemap_delay;
/* randomize a bit to avoid spont. sync */
delay.rel_value_us +=
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 1000 * 1000);
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000);
session->typemap_task =
- GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_typemap_task,
- session);
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# type map refreshes sent"),
1,
GNUNET_NO);
hdr = GSC_TYPEMAP_compute_type_map_message ();
- GSC_KX_encrypt_and_transmit (session->kx,
- hdr,
- ntohs (hdr->size));
+ GSC_KX_encrypt_and_transmit (session->kx, hdr, ntohs (hdr->size));
GNUNET_free (hdr);
}
@@ -315,10 +304,9 @@ start_typemap_task (struct Session *session)
if (NULL != session->typemap_task)
GNUNET_SCHEDULER_cancel (session->typemap_task);
session->typemap_delay = GNUNET_TIME_UNIT_SECONDS;
- session->typemap_task =
- GNUNET_SCHEDULER_add_delayed (session->typemap_delay,
- &transmit_typemap_task,
- session);
+ session->typemap_task = GNUNET_SCHEDULER_add_delayed (session->typemap_delay,
+ &transmit_typemap_task,
+ session);
}
@@ -342,17 +330,16 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity
*peer,
session->peer = peer;
session->kx = kx;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (sessions,
- session->peer,
- session,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ sessions,
+ session->peer,
+ session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
GNUNET_STATISTICS_set (GSC_stats,
- gettext_noop ("# peers connected"),
+ gettext_noop ("# peers connected"),
GNUNET_CONTAINER_multipeermap_size (sessions),
GNUNET_NO);
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- NULL,
- session->tmap);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, session->tmap);
start_typemap_task (session);
}
@@ -406,15 +393,15 @@ GSC_SESSIONS_confirm_typemap (const struct
GNUNET_PeerIdentity *peer,
return;
}
cmsg = (const struct TypeMapConfirmationMessage *) msg;
- if (GNUNET_YES !=
- GSC_TYPEMAP_check_hash (&cmsg->tm_hash))
+ if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash))
{
/* our typemap has changed in the meantime, do not
accept confirmation */
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# outdated typemap confirmations received"),
- 1, GNUNET_NO);
+ gettext_noop (
+ "# outdated typemap confirmations received"),
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Got outdated typemap confirmated from peer `%s'\n",
GNUNET_i2s (session->peer));
@@ -429,9 +416,10 @@ GSC_SESSIONS_confirm_typemap (const struct
GNUNET_PeerIdentity *peer,
session->typemap_task = NULL;
}
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop
- ("# valid typemap confirmations received"),
- 1, GNUNET_NO);
+ gettext_noop (
+ "# valid typemap confirmations received"),
+ 1,
+ GNUNET_NO);
}
@@ -453,7 +441,7 @@ notify_client_about_session (void *cls,
GSC_CLIENTS_notify_client_about_neighbour (client,
session->peer,
- NULL, /* old TMAP: none */
+ NULL, /* old TMAP: none */
session->tmap);
return GNUNET_OK;
}
@@ -503,16 +491,14 @@ GSC_SESSIONS_queue_request (struct
GSC_ClientActiveRequest *car)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Dropped client request for transmission (am disconnected)\n");
- GNUNET_break (0); /* should have been rejected earlier */
- GSC_CLIENTS_reject_request (car,
- GNUNET_NO);
+ GNUNET_break (0); /* should have been rejected earlier */
+ GSC_CLIENTS_reject_request (car, GNUNET_NO);
return;
}
if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
{
GNUNET_break (0);
- GSC_CLIENTS_reject_request (car,
- GNUNET_YES);
+ GSC_CLIENTS_reject_request (car, GNUNET_YES);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -535,10 +521,9 @@ GSC_SESSIONS_dequeue_request (struct
GSC_ClientActiveRequest *car)
{
struct Session *session;
- if (0 ==
- memcmp (&car->target,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&car->target,
+ &GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity)))
return;
session = find_session (&car->target);
GNUNET_assert (NULL != session);
@@ -560,21 +545,20 @@ GSC_SESSIONS_dequeue_request (struct
GSC_ClientActiveRequest *car)
* @param msize how many bytes do we have already
*/
static void
-solicit_messages (struct Session *session,
- size_t msize)
+solicit_messages (struct Session *session, size_t msize)
{
struct GSC_ClientActiveRequest *car;
struct GSC_ClientActiveRequest *nxt;
size_t so_size;
- enum GNUNET_CORE_Priority pmax;
+ enum GNUNET_MQ_PriorityPreferences pmax;
so_size = msize;
- pmax = GNUNET_CORE_PRIO_BACKGROUND;
+ pmax = GNUNET_MQ_PRIO_BACKGROUND;
for (car = session->active_client_request_head; NULL != car; car = car->next)
{
if (GNUNET_YES == car->was_solicited)
continue;
- pmax = GNUNET_MAX (pmax, car->priority);
+ pmax = GNUNET_MAX (pmax, car->priority & GNUNET_MQ_PRIORITY_MASK);
}
nxt = session->active_client_request_head;
while (NULL != (car = nxt))
@@ -631,11 +615,11 @@ try_transmission (struct Session *session)
size_t msize;
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute min_deadline;
- enum GNUNET_CORE_Priority maxp;
- enum GNUNET_CORE_Priority maxpc;
+ enum GNUNET_MQ_PriorityPreferences maxp;
+ enum GNUNET_MQ_PriorityPreferences maxpc;
struct GSC_ClientActiveRequest *car;
int excess;
-
+
msize = 0;
min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
/* if the peer has excess bandwidth, background traffic is allowed,
@@ -649,9 +633,9 @@ try_transmission (struct Session *session)
}
excess = GSC_NEIGHBOURS_check_excess_bandwidth (session->kx);
if (GNUNET_YES == excess)
- maxp = GNUNET_CORE_PRIO_BACKGROUND;
+ maxp = GNUNET_MQ_PRIO_BACKGROUND;
else
- maxp = GNUNET_CORE_PRIO_BEST_EFFORT;
+ maxp = GNUNET_MQ_PRIO_BEST_EFFORT;
/* determine highest priority of 'ready' messages we already solicited from
clients */
pos = session->sme_head;
while ((NULL != pos) &&
@@ -659,32 +643,33 @@ try_transmission (struct Session *session)
{
GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
msize += pos->size;
- maxp = GNUNET_MAX (maxp, pos->priority);
- min_deadline = GNUNET_TIME_absolute_min (min_deadline,
- pos->deadline);
+ maxp = GNUNET_MAX (maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK);
+ min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline);
pos = pos->next;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Calculating transmission set with %u priority (%s) and %s
earliest deadline\n",
- maxp,
- (GNUNET_YES == excess) ? "excess bandwidth" : "limited
bandwidth",
- GNUNET_STRINGS_relative_time_to_string
(GNUNET_TIME_absolute_get_remaining (min_deadline),
- GNUNET_YES));
-
- if (maxp < GNUNET_CORE_PRIO_CRITICAL_CONTROL)
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Calculating transmission set with %u priority (%s) and %s earliest
deadline\n",
+ maxp,
+ (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth",
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining
(
+ min_deadline),
+ GNUNET_YES));
+
+ if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL)
{
/* if highest already solicited priority from clients is not critical,
check if there are higher-priority messages to be solicited from
clients */
if (GNUNET_YES == excess)
- maxpc = GNUNET_CORE_PRIO_BACKGROUND;
+ maxpc = GNUNET_MQ_PRIO_BACKGROUND;
else
- maxpc = GNUNET_CORE_PRIO_BEST_EFFORT;
- for (car = session->active_client_request_head; NULL != car; car =
car->next)
+ maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
+ for (car = session->active_client_request_head; NULL != car;
+ car = car->next)
{
if (GNUNET_YES == car->was_solicited)
continue;
- maxpc = GNUNET_MAX (maxpc,
- car->priority);
+ maxpc = GNUNET_MAX (maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK);
}
if (maxpc > maxp)
{
@@ -703,41 +688,40 @@ try_transmission (struct Session *session)
{
/* never solicit more, we have critical messages to process */
excess = GNUNET_NO;
- maxpc = GNUNET_CORE_PRIO_BACKGROUND;
+ maxpc = GNUNET_MQ_PRIO_BACKGROUND;
}
now = GNUNET_TIME_absolute_get ();
- if ( ( (GNUNET_YES == excess) ||
- (maxpc >= GNUNET_CORE_PRIO_BEST_EFFORT) ) &&
- ( (0 == msize) ||
- ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
- (min_deadline.abs_value_us > now.abs_value_us))) )
+ if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) &&
+ ((0 == msize) ||
+ ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
+ (min_deadline.abs_value_us > now.abs_value_us))))
{
/* not enough ready yet (tiny message & cork possible), or no messages at
all,
and either excess bandwidth or best-effort or higher message waiting at
client; in this case, we try to solicit more */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Soliciting messages (excess %d, maxpc %d, message size %u,
deadline %s)\n",
- excess,
- maxpc,
- (unsigned int) msize,
- GNUNET_STRINGS_relative_time_to_string
(GNUNET_TIME_absolute_get_remaining (min_deadline),
- GNUNET_YES));
- solicit_messages (session,
- msize);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Soliciting messages (excess %d, maxpc %d, message size %u, deadline
%s)\n",
+ excess,
+ maxpc,
+ (unsigned int) msize,
+ GNUNET_STRINGS_relative_time_to_string
(GNUNET_TIME_absolute_get_remaining (
+ min_deadline),
+ GNUNET_YES));
+ solicit_messages (session, msize);
if (msize > 0)
{
/* if there is data to send, just not yet, make sure we do transmit
* it once the deadline is reached */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Corking until %s\n",
- GNUNET_STRINGS_relative_time_to_string
(GNUNET_TIME_absolute_get_remaining (min_deadline),
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_remaining (min_deadline),
+ GNUNET_YES));
if (NULL != session->cork_task)
GNUNET_SCHEDULER_cancel (session->cork_task);
- session->cork_task
- = GNUNET_SCHEDULER_add_at (min_deadline,
- &pop_cork_task,
- session);
+ session->cork_task =
+ GNUNET_SCHEDULER_add_at (min_deadline, &pop_cork_task, session);
}
else
{
@@ -753,26 +737,21 @@ try_transmission (struct Session *session)
{
static unsigned long long total_bytes;
static unsigned int total_msgs;
- char pbuf[msize]; /* plaintext */
+ char pbuf[msize]; /* plaintext */
size_t used;
used = 0;
- while ( (NULL != (pos = session->sme_head)) &&
- (used + pos->size <= msize) )
+ while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding message of type %d (%d/%d) to payload for %s\n",
- ntohs (((const struct GNUNET_MessageHeader *)&pos[1])->type),
+ ntohs (((const struct GNUNET_MessageHeader *)
&pos[1])->type),
pos->is_typemap,
pos->is_typemap_confirm,
GNUNET_i2s (session->peer));
- GNUNET_memcpy (&pbuf[used],
- &pos[1],
- pos->size);
+ GNUNET_memcpy (&pbuf[used], &pos[1], pos->size);
used += pos->size;
- GNUNET_CONTAINER_DLL_remove (session->sme_head,
- session->sme_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos);
GNUNET_free (pos);
}
/* compute average payload size */
@@ -789,9 +768,7 @@ try_transmission (struct Session *session)
total_bytes / total_msgs,
GNUNET_NO);
/* now actually transmit... */
- GSC_KX_encrypt_and_transmit (session->kx,
- pbuf,
- used);
+ GSC_KX_encrypt_and_transmit (session->kx, pbuf, used);
}
}
@@ -823,23 +800,17 @@ do_restart_typemap_message (void *cls,
{
if (GNUNET_YES == sme->is_typemap)
{
- GNUNET_CONTAINER_DLL_remove (session->sme_head,
- session->sme_tail,
- sme);
+ GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
GNUNET_free (sme);
break;
}
}
sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
sme->is_typemap = GNUNET_YES;
- GNUNET_memcpy (&sme[1],
- hdr,
- size);
+ GNUNET_memcpy (&sme[1], hdr, size);
sme->size = size;
- sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL;
- GNUNET_CONTAINER_DLL_insert (session->sme_head,
- session->sme_tail,
- sme);
+ sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
+ GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme);
try_transmission (session);
start_typemap_task (session);
return GNUNET_OK;
@@ -876,8 +847,8 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
struct Session *session;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transport solicits for %s\n",
- GNUNET_i2s (pid));
+ "Transport solicits for %s\n",
+ GNUNET_i2s (pid));
session = find_session (pid);
if (NULL == session)
return;
@@ -891,14 +862,12 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity
*pid)
* @param car original request that was queued and then solicited;
* this handle will now be 'owned' by the SESSIONS subsystem
* @param msg message to transmit
- * @param cork is corking allowed?
* @param priority how important is this message
*/
void
GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
const struct GNUNET_MessageHeader *msg,
- int cork,
- enum GNUNET_CORE_Priority priority)
+ enum GNUNET_MQ_PriorityPreferences priority)
{
struct Session *session;
struct SessionMessageEntry *sme;
@@ -910,21 +879,18 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest
*car,
return;
msize = ntohs (msg->size);
sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize);
- GNUNET_memcpy (&sme[1],
- msg,
- msize);
+ GNUNET_memcpy (&sme[1], msg, msize);
sme->size = msize;
sme->priority = priority;
- if (GNUNET_YES == cork)
+ if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority))
{
sme->deadline =
- GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Mesage corked, delaying transmission\n");
+ "Mesage corked, delaying transmission\n");
}
pos = session->sme_head;
- while ( (NULL != pos) &&
- (pos->priority >= sme->priority) )
+ while ((NULL != pos) && (pos->priority >= sme->priority))
pos = pos->next;
if (NULL == pos)
GNUNET_CONTAINER_DLL_insert_tail (session->sme_head,
@@ -959,7 +925,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity
*peer,
if (NULL == nmap)
{
GNUNET_break_op (0);
- return; /* malformed */
+ return; /* malformed */
}
session = find_session (peer);
if (NULL == session)
@@ -975,9 +941,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity
*peer,
{
if (GNUNET_YES == sme->is_typemap_confirm)
{
- GNUNET_CONTAINER_DLL_remove (session->sme_head,
- session->sme_tail,
- sme);
+ GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
GNUNET_free (sme);
break;
}
@@ -986,21 +950,16 @@ GSC_SESSIONS_set_typemap (const struct
GNUNET_PeerIdentity *peer,
sizeof (struct TypeMapConfirmationMessage));
sme->deadline = GNUNET_TIME_absolute_get ();
sme->size = sizeof (struct TypeMapConfirmationMessage);
- sme->priority = GNUNET_CORE_PRIO_CRITICAL_CONTROL;
+ sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
sme->is_typemap_confirm = GNUNET_YES;
tmc = (struct TypeMapConfirmationMessage *) &sme[1];
tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage));
tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP);
tmc->reserved = htonl (0);
- GSC_TYPEMAP_hash (nmap,
- &tmc->tm_hash);
- GNUNET_CONTAINER_DLL_insert (session->sme_head,
- session->sme_tail,
- sme);
+ GSC_TYPEMAP_hash (nmap, &tmc->tm_hash);
+ GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme);
try_transmission (session);
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- session->tmap,
- nmap);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
GSC_TYPEMAP_destroy (session->tmap);
session->tmap = nmap;
}
@@ -1021,21 +980,14 @@ GSC_SESSIONS_add_to_typemap (const struct
GNUNET_PeerIdentity *peer,
struct Session *session;
struct GSC_TypeMap *nmap;
- if (0 == memcmp (peer,
- &GSC_my_identity,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct
GNUNET_PeerIdentity)))
return;
session = find_session (peer);
GNUNET_assert (NULL != session);
- if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap,
- &type, 1))
- return; /* already in it */
- nmap = GSC_TYPEMAP_extend (session->tmap,
- &type,
- 1);
- GSC_CLIENTS_notify_clients_about_neighbour (peer,
- session->tmap,
- nmap);
+ if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
+ return; /* already in it */
+ nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
+ GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
GSC_TYPEMAP_destroy (session->tmap);
session->tmap = nmap;
}
@@ -1047,8 +999,7 @@ GSC_SESSIONS_add_to_typemap (const struct
GNUNET_PeerIdentity *peer,
void
GSC_SESSIONS_init ()
{
- sessions = GNUNET_CONTAINER_multipeermap_create (128,
- GNUNET_YES);
+ sessions = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
}
@@ -1083,7 +1034,7 @@ GSC_SESSIONS_done ()
{
GNUNET_CONTAINER_multipeermap_iterate (sessions,
&free_session_helper,
- NULL);
+ NULL);
GNUNET_CONTAINER_multipeermap_destroy (sessions);
sessions = NULL;
}
diff --git a/src/core/gnunet-service-core_sessions.h
b/src/core/gnunet-service-core_sessions.h
index 9f5070d57..e92ce0962 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -114,14 +114,12 @@ GSC_SESSIONS_dequeue_request (struct
GSC_ClientActiveRequest *car);
* @param car original request that was queued and then solicited,
* ownership does not change (dequeue will be called soon).
* @param msg message to transmit
- * @param cork is corking allowed?
* @param priority how important is this message
*/
void
GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
const struct GNUNET_MessageHeader *msg,
- int cork,
- enum GNUNET_CORE_Priority priority);
+ enum GNUNET_MQ_PriorityPreferences priority);
/**
@@ -182,5 +180,4 @@ void
GSC_SESSIONS_done (void);
-
#endif
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 0cf88a324..1e268c3a6 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -54,7 +54,16 @@ static struct GNUNET_SCHEDULER_Task *err_task;
static int ok;
-#define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u
at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
+#define OKPP \
+ do \
+ { \
+ ok++; \
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \
+ "Now at stage %u at %s:%u\n", \
+ ok, \
+ __FILE__, \
+ __LINE__); \
+ } while (0)
static void
@@ -67,8 +76,7 @@ offer_hello_done (void *cls)
static void
-process_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
+process_hello (void *cls, const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
@@ -76,14 +84,11 @@ process_hello (void *cls,
"Received (my) HELLO from transport service\n");
GNUNET_assert (message != NULL);
if ((p == &p1) && (NULL == p2.oh))
- p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message,
- &offer_hello_done,
- &p2);
+ p2.oh =
+ GNUNET_TRANSPORT_offer_hello (p2.cfg, message, &offer_hello_done, &p2);
if ((p == &p2) && (NULL == p1.oh))
- p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg,
- message,
- &offer_hello_done,
- &p1);
+ p1.oh =
+ GNUNET_TRANSPORT_offer_hello (p1.cfg, message, &offer_hello_done, &p1);
}
@@ -131,9 +136,7 @@ terminate_task (void *cls)
static void
terminate_task_error (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ENDING ANGRILY %u\n",
- ok);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ENDING ANGRILY %u\n", ok);
GNUNET_break (0);
terminate_peer (&p1);
terminate_peer (&p2);
@@ -144,15 +147,13 @@ terminate_task_error (void *cls)
static void *
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_MQ_Handle *mq)
{
struct PeerContext *pc = cls;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return (void *) peer;
GNUNET_assert (pc->connect_status == 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -161,26 +162,18 @@ connect_notify (void *cls,
pc->connect_status = 1;
if (pc == &p1)
{
- uint64_t flags;
- const void *extra;
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking core (1) for transmission to peer `%s'\n",
GNUNET_i2s (&p2.id));
- env = GNUNET_MQ_msg (msg,
- MTYPE);
+ env = GNUNET_MQ_msg (msg, MTYPE);
/* enable corking for this test */
- extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- &flags);
GNUNET_MQ_env_set_options (env,
- flags,
- extra);
+ GNUNET_MQ_PRIO_BEST_EFFORT |
+ GNUNET_MQ_PREF_CORK_ALLOWED);
/* now actually transmit message */
GNUNET_assert (ok == 4);
OKPP;
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_send (mq, env);
}
return (void *) peer;
}
@@ -188,25 +181,22 @@ connect_notify (void *cls,
static void
disconnect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *internal_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls)
{
struct PeerContext *pc = cls;
- if (0 == memcmp (&pc->id,
- peer,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
pc->connect_status = 0;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection to `%s' cut\n",
+ "Encrypted connection to `%s' cut\n",
GNUNET_i2s (peer));
}
static void
-handle_test (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_test (void *cls, const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_PeerIdentity *peer = cls;
@@ -216,23 +206,17 @@ handle_test (void *cls,
GNUNET_assert (ok == 5);
OKPP;
GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_now (&terminate_task,
- NULL);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
}
static void
-init_notify (void *cls,
- const struct GNUNET_PeerIdentity *my_identity)
+init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity)
{
struct PeerContext *p = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (test,
- MTYPE,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL),
+ GNUNET_MQ_handler_end ()};
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core connection to `%s' established\n",
@@ -244,50 +228,46 @@ init_notify (void *cls,
OKPP;
/* connect p2 */
p2.ch = GNUNET_CORE_connect (p2.cfg,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- handlers);
+ &p2,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ handlers);
}
else
{
GNUNET_assert (ok == 3);
OKPP;
GNUNET_assert (cls == &p2);
- p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats,
- &p2.id,
- 1);
+ p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1);
}
}
static void
-setup_peer (struct PeerContext *p,
- const char *cfgname)
+setup_peer (struct PeerContext *p, const char *cfgname)
{
char *binary;
binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
p->cfg = GNUNET_CONFIGURATION_create ();
- p->arm_proc =
- GNUNET_OS_start_process (GNUNET_YES,
- GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- NULL, NULL, NULL,
- binary,
- "gnunet-service-arm",
- "-c",
- cfgname,
- NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_load (p->cfg,
- cfgname));
+ p->arm_proc = GNUNET_OS_start_process (GNUNET_YES,
+ GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+ NULL,
+ NULL,
+ NULL,
+ binary,
+ "gnunet-service-arm",
+ "-c",
+ cfgname,
+ NULL);
+ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->ats = GNUNET_ATS_connectivity_init (p->cfg);
GNUNET_assert (NULL != p->ats);
p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg,
- GNUNET_TRANSPORT_AC_ANY,
- &process_hello,
- p);
+ GNUNET_TRANSPORT_AC_ANY,
+ &process_hello,
+ p);
GNUNET_free (binary);
}
@@ -298,47 +278,36 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (test,
- MTYPE,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL),
+ GNUNET_MQ_handler_end ()};
GNUNET_assert (ok == 1);
OKPP;
- setup_peer (&p1,
- "test_core_api_peer1.conf");
- setup_peer (&p2,
- "test_core_api_peer2.conf");
- err_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 300),
- &terminate_task_error, NULL);
- p1.ch =
- GNUNET_CORE_connect (p1.cfg,
- &p1,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- handlers);
+ setup_peer (&p1, "test_core_api_peer1.conf");
+ setup_peer (&p2, "test_core_api_peer2.conf");
+ err_task = GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300),
+ &terminate_task_error,
+ NULL);
+ p1.ch = GNUNET_CORE_connect (p1.cfg,
+ &p1,
+ &init_notify,
+ &connect_notify,
+ &disconnect_notify,
+ handlers);
}
static void
stop_arm (struct PeerContext *p)
{
- if (0 != GNUNET_OS_process_kill (p->arm_proc,
- GNUNET_TERM_SIG))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "kill");
- if (GNUNET_OK !=
- GNUNET_OS_process_wait (p->arm_proc))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "waitpid");
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n",
+ "ARM process %u stopped\n",
GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_destroy (p->arm_proc);
p->arm_proc = NULL;
@@ -347,29 +316,19 @@ stop_arm (struct PeerContext *p)
int
-main (int argc,
- char *argv1[])
+main (int argc, char *argv1[])
{
- char *const argv[] = {
- "test-core-api",
- "-c",
- "test_core_api_data.conf",
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ char *const argv[] = {"test-core-api", "-c", "test_core_api_data.conf",
NULL};
+ struct GNUNET_GETOPT_CommandLineOption options[] =
{GNUNET_GETOPT_OPTION_END};
ok = 1;
- GNUNET_log_setup ("test-core-api",
- "WARNING",
- NULL);
+ GNUNET_log_setup ("test-core-api", "WARNING", NULL);
GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv,
+ argv,
"test-core-api",
- "nohelp",
- options,
- &run,
- &ok);
+ "nohelp",
+ options,
+ &run,
+ &ok);
stop_arm (&p1);
stop_arm (&p2);
GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c
b/src/hostlist/gnunet-daemon-hostlist_server.c
index 529fe4e62..8764586d6 100644
--- a/src/hostlist/gnunet-daemon-hostlist_server.c
+++ b/src/hostlist/gnunet-daemon-hostlist_server.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -38,7 +38,8 @@
* How long until our hostlist advertisment transmission via CORE should
* time out?
*/
-#define GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MINUTES, 5)
+#define GNUNET_ADV_TIMEOUT \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
@@ -121,7 +122,6 @@ struct HostSet
* Number of bytes in @e data.
*/
unsigned int size;
-
};
@@ -140,15 +140,11 @@ static struct HostSet *builder;
static void
add_cors_headers (struct MHD_Response *response)
{
- MHD_add_response_header (response,
- "Access-Control-Allow-Origin",
- "*");
+ MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");
MHD_add_response_header (response,
"Access-Control-Allow-Methods",
"GET, OPTIONS");
- MHD_add_response_header (response,
- "Access-Control-Max-Age",
- "86400");
+ MHD_add_response_header (response, "Access-Control-Max-Age", "86400");
}
@@ -163,18 +159,19 @@ finish_response ()
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating hostlist response with %u bytes\n",
(unsigned int) builder->size);
- response =
- MHD_create_response_from_buffer (builder->size,
- builder->data,
- MHD_RESPMEM_MUST_FREE);
+ response = MHD_create_response_from_buffer (builder->size,
+ builder->data,
+ MHD_RESPMEM_MUST_FREE);
add_cors_headers (response);
if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6))
{
MHD_destroy_response (response);
response = NULL;
}
- GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"),
- builder->size, GNUNET_YES);
+ GNUNET_STATISTICS_set (stats,
+ gettext_noop ("bytes in hostlist"),
+ builder->size,
+ GNUNET_YES);
GNUNET_free (builder);
builder = NULL;
}
@@ -198,9 +195,10 @@ check_has_addr (void *cls,
if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
{
GNUNET_STATISTICS_update (stats,
- gettext_noop ("expired addresses encountered"),
1,
+ gettext_noop ("expired addresses encountered"),
+ 1,
GNUNET_YES);
- return GNUNET_YES; /* ignore this address */
+ return GNUNET_YES; /* ignore this address */
}
*arg = GNUNET_YES;
return GNUNET_SYSERR;
@@ -234,7 +232,7 @@ host_processor (void *cls,
GNUNET_free (builder);
builder = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Error in communication with PEERINFO service: %s\n"),
+ _ ("Error in communication with PEERINFO service: %s\n"),
err_msg);
return;
}
@@ -247,19 +245,17 @@ host_processor (void *cls,
if (NULL == hello)
return;
has_addr = GNUNET_NO;
- GNUNET_HELLO_iterate_addresses (hello,
- GNUNET_NO,
- &check_has_addr,
- &has_addr);
+ GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr,
&has_addr);
if (GNUNET_NO == has_addr)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"HELLO for peer `%4s' has no address, not suitable for
hostlist!\n",
GNUNET_i2s (peer));
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("HELLOs without addresses encountered
(ignored)"),
- 1, GNUNET_NO);
+ gettext_noop (
+ "HELLOs without addresses encountered
(ignored)"),
+ 1,
+ GNUNET_NO);
return;
}
old = builder->size;
@@ -269,26 +265,23 @@ host_processor (void *cls,
(unsigned int) s,
"HELLO",
GNUNET_i2s (peer));
- if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
- (old + s >= MAX_BYTES_PER_HOSTLISTS) )
+ if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) ||
+ (old + s >= MAX_BYTES_PER_HOSTLISTS))
{
/* too large, skip! */
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("bytes not included in hostlist (size limit)"),
- s, GNUNET_NO);
+ gettext_noop (
+ "bytes not included in hostlist (size limit)"),
+ s,
+ GNUNET_NO);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Adding peer `%s' to hostlist (%u bytes)\n",
GNUNET_i2s (peer),
(unsigned int) s);
- GNUNET_array_grow (builder->data,
- builder->size,
- old + s);
- GNUNET_memcpy (&builder->data[old],
- hello,
- s);
+ GNUNET_array_grow (builder->data, builder->size, old + s);
+ GNUNET_memcpy (&builder->data[old], hello, s);
}
@@ -308,11 +301,12 @@ accept_policy_callback (void *cls,
{
if (NULL == response)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received request for hostlist, but I am not yet ready;
rejecting!\n");
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Received request for hostlist, but I am not yet ready; rejecting!\n");
return MHD_NO;
}
- return MHD_YES; /* accept all */
+ return MHD_YES; /* accept all */
}
@@ -369,9 +363,9 @@ access_handler_callback (void *cls,
struct MHD_Response *options_response;
int rc;
- options_response = MHD_create_response_from_buffer (0, NULL,
-
MHD_RESPMEM_PERSISTENT);
- add_cors_headers(options_response);
+ options_response =
+ MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT);
+ add_cors_headers (options_response);
rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response);
MHD_destroy_response (options_response);
return rc;
@@ -379,10 +373,12 @@ access_handler_callback (void *cls,
if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Refusing `%s' request to hostlist server\n"), method);
+ _ ("Refusing `%s' request to hostlist server\n"),
+ method);
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("hostlist requests refused (not HTTP GET)"), 1,
+ gettext_noop (
+ "hostlist requests refused (not HTTP GET)"),
+ 1,
GNUNET_YES);
return MHD_NO;
}
@@ -394,29 +390,35 @@ access_handler_callback (void *cls,
if (0 != *upload_data_size)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Refusing `%s' request with %llu bytes of upload data\n"),
- method, (unsigned long long) *upload_data_size);
+ _ ("Refusing `%s' request with %llu bytes of upload data\n"),
+ method,
+ (unsigned long long) *upload_data_size);
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("hostlist requests refused (upload data)"), 1,
+ gettext_noop (
+ "hostlist requests refused (upload data)"),
+ 1,
GNUNET_YES);
- return MHD_NO; /* do not support upload data */
+ return MHD_NO; /* do not support upload data */
}
if (NULL == response)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not handle hostlist request since I do not have a
response yet\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Could not handle hostlist request since I do not have a response
yet\n"));
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("hostlist requests refused (not ready)"), 1,
+ gettext_noop (
+ "hostlist requests refused (not ready)"),
+ 1,
GNUNET_YES);
- return MHD_NO; /* internal error, no response yet */
+ return MHD_NO; /* internal error, no response yet */
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Received request for our hostlist\n"));
+ _ ("Received request for our hostlist\n"));
GNUNET_STATISTICS_update (stats,
gettext_noop ("hostlist requests processed"),
- 1, GNUNET_YES);
+ 1,
+ GNUNET_YES);
return MHD_queue_response (connection, MHD_HTTP_OK, response);
}
@@ -434,27 +436,19 @@ static void
adv_transmit (struct GNUNET_MQ_Handle *mq)
{
static uint64_t hostlist_adv_count;
- const void *extra;
- uint64_t flags;
- size_t uri_size; /* Including \0 termination! */
+ size_t uri_size; /* Including \0 termination! */
struct GNUNET_MessageHeader *header;
struct GNUNET_MQ_Envelope *env;
- extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- &flags);
uri_size = strlen (hostlist_uri) + 1;
env = GNUNET_MQ_msg_extra (header,
- uri_size,
- GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
- GNUNET_memcpy (&header[1],
- hostlist_uri,
- uri_size);
+ uri_size,
+ GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
+ GNUNET_memcpy (&header[1], hostlist_uri, uri_size);
GNUNET_MQ_env_set_options (env,
- flags,
- extra);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_PREF_CORK_ALLOWED |
+ GNUNET_MQ_PREF_UNRELIABLE);
+ GNUNET_MQ_send (mq, env);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sent advertisement message: Copied %u bytes into buffer!\n",
(unsigned int) uri_size);
@@ -463,7 +457,8 @@ adv_transmit (struct GNUNET_MQ_Handle *mq)
" # Sent advertisement message: %llu\n",
(unsigned long long) hostlist_adv_count);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# hostlist advertisements send"), 1,
+ gettext_noop ("# hostlist advertisements send"),
+ 1,
GNUNET_NO);
}
@@ -479,7 +474,7 @@ adv_transmit (struct GNUNET_MQ_Handle *mq)
static void *
connect_handler (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_MQ_Handle *mq)
{
size_t size;
@@ -488,8 +483,7 @@ connect_handler (void *cls,
if (NULL == hostlist_uri)
return NULL;
size = strlen (hostlist_uri) + 1;
- if (size + sizeof (struct GNUNET_MessageHeader) >=
- GNUNET_MAX_MESSAGE_SIZE)
+ if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
return NULL;
@@ -500,10 +494,11 @@ connect_handler (void *cls,
GNUNET_break (0);
return NULL;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asked CORE to transmit advertisement message with a size of %u
bytes to peer `%s'\n",
- (unsigned int) size,
- GNUNET_i2s (peer));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Asked CORE to transmit advertisement message with a size of %u bytes to
peer `%s'\n",
+ (unsigned int) size,
+ GNUNET_i2s (peer));
adv_transmit (mq);
return NULL;
}
@@ -528,8 +523,8 @@ process_notify (void *cls,
"Peerinfo is notifying us to rebuild our hostlist\n");
if (NULL != err_msg)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Error in communication with PEERINFO service: %s\n"),
- err_msg);
+ _ ("Error in communication with PEERINFO service: %s\n"),
+ err_msg);
if (NULL != builder)
{
/* restart re-build already in progress ... */
@@ -547,10 +542,8 @@ process_notify (void *cls,
builder = GNUNET_new (struct HostSet);
}
GNUNET_assert (NULL != peerinfo);
- builder->pitr
- = GNUNET_PEERINFO_iterate (peerinfo,
- GNUNET_NO, NULL,
- &host_processor, NULL);
+ builder->pitr =
+ GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL);
}
@@ -594,7 +587,7 @@ run_daemon (void *cls)
static struct GNUNET_SCHEDULER_Task *
prepare_daemon (struct MHD_Daemon *daemon_handle)
{
- struct GNUNET_SCHEDULER_Task * ret;
+ struct GNUNET_SCHEDULER_Task *ret;
fd_set rs;
fd_set ws;
fd_set es;
@@ -611,9 +604,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
wrs = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
- GNUNET_assert (MHD_YES ==
- MHD_get_fdset (daemon_handle,
- &rs, &ws, &es, &max));
+ GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es,
&max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
tv.rel_value_us = (uint64_t) timeout * 1000LL;
@@ -622,8 +613,11 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- tv, wrs, wws,
- &run_daemon, daemon_handle);
+ tv,
+ wrs,
+ wws,
+ &run_daemon,
+ daemon_handle);
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
return ret;
@@ -676,19 +670,18 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
if (NULL == peerinfo)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access PEERINFO service. Exiting.\n"));
+ _ ("Could not access PEERINFO service. Exiting.\n"));
return GNUNET_SYSERR;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "HOSTLIST",
- "HTTPPORT",
- &port))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "HOSTLIST",
+ "HTTPPORT",
+ &port))
return GNUNET_SYSERR;
if ((0 == port) || (port > UINT16_MAX))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Invalid port number %llu. Exiting.\n"),
+ _ ("Invalid port number %llu. Exiting.\n"),
port);
return GNUNET_SYSERR;
}
@@ -700,8 +693,9 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
&hostname))
hostname = GNUNET_RESOLVER_local_fqdn_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Hostlist service starts on %s:%llu\n"),
- hostname, port);
+ _ ("Hostlist service starts on %s:%llu\n"),
+ hostname,
+ port);
if (NULL != hostname)
{
size = strlen (hostname);
@@ -712,10 +706,11 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
else
{
GNUNET_asprintf (&hostlist_uri,
- "http://%s:%u/", hostname,
+ "http://%s:%u/",
+ hostname,
(unsigned int) port);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Address to obtain hostlist: `%s'\n"),
+ _ ("Address to obtain hostlist: `%s'\n"),
hostlist_uri);
}
GNUNET_free (hostname);
@@ -723,29 +718,28 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
- "BINDTOIP", &ipv4))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "BINDTOIP",
+ &ipv4))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("BINDTOIP does not a valid IPv4 address! Ignoring
BINDTOIPV4.\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n"));
}
-
}
else
ipv4 = NULL;
- if (GNUNET_CONFIGURATION_have_value (cfg,
- "HOSTLIST",
- "BINDTOIPV6"))
- {
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "HOSTLIST",
- "BINDTOIP",
- &ipv6))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
+ if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
+ {
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "HOSTLIST",
+ "BINDTOIP",
+ &ipv6))
+ {
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n"));
}
}
else
@@ -766,7 +760,8 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
}
else
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' is not a valid IPv4 address! Ignoring
BINDTOIPV4.\n"),
+ _ (
+ "`%s' is not a valid IPv4 address! Ignoring
BINDTOIPV4.\n"),
ipv4);
GNUNET_free (ipv4);
}
@@ -786,15 +781,18 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
}
else
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' is not a valid IPv6 address! Ignoring
BINDTOIPV6.\n"),
+ _ (
+ "`%s' is not a valid IPv6 address! Ignoring
BINDTOIPV6.\n"),
ipv6);
GNUNET_free (ipv6);
}
daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
(uint16_t) port,
- &accept_policy_callback, NULL,
- &access_handler_callback, NULL,
+ &accept_policy_callback,
+ NULL,
+ &access_handler_callback,
+ NULL,
MHD_OPTION_CONNECTION_LIMIT,
(unsigned int) 128,
MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -807,9 +805,11 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
sa6,
MHD_OPTION_END);
daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
- (uint16_t) port,
- &accept_policy_callback, NULL,
- &access_handler_callback, NULL,
+ (uint16_t) port,
+ &accept_policy_callback,
+ NULL,
+ &access_handler_callback,
+ NULL,
MHD_OPTION_CONNECTION_LIMIT,
(unsigned int) 128,
MHD_OPTION_PER_IP_CONNECTION_LIMIT,
@@ -822,11 +822,10 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
sa4,
MHD_OPTION_END);
- if ( (NULL == daemon_handle_v6) &&
- (NULL == daemon_handle_v4) )
+ if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not start hostlist HTTP server on port %u\n"),
+ _ ("Could not start hostlist HTTP server on port %u\n"),
(unsigned short) port);
return GNUNET_SYSERR;
}
@@ -837,9 +836,7 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
if (NULL != daemon_handle_v6)
hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
- notify = GNUNET_PEERINFO_notify (cfg,
- GNUNET_NO,
- &process_notify, NULL);
+ notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL);
return GNUNET_OK;
}
@@ -850,8 +847,7 @@ GNUNET_HOSTLIST_server_start (const struct
GNUNET_CONFIGURATION_Handle *c,
void
GNUNET_HOSTLIST_server_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Hostlist server shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n");
if (NULL != hostlist_task_v6)
{
GNUNET_SCHEDULER_cancel (hostlist_task_v6);
diff --git a/src/include/gnunet_core_service.h
b/src/include/gnunet_core_service.h
index f10ddee75..111eb529d 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -34,9 +34,8 @@
#define GNUNET_CORE_SERVICE_H
#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
@@ -49,35 +48,6 @@ extern "C"
*/
#define GNUNET_CORE_VERSION 0x00000001
-/**
- * Traffic priorities.
- */
-enum GNUNET_CORE_Priority
-{
-
- /**
- * Lowest priority, i.e. background traffic (i.e. fs)
- */
- GNUNET_CORE_PRIO_BACKGROUND = 0,
-
- /**
- * Normal traffic (i.e. cadet/dv relay, DHT)
- */
- GNUNET_CORE_PRIO_BEST_EFFORT = 1,
-
- /**
- * Urgent traffic (local peer, i.e. conversation).
- */
- GNUNET_CORE_PRIO_URGENT = 2,
-
- /**
- * Highest priority, control traffic (i.e. NSE, Core/Cadet KX).
- */
- GNUNET_CORE_PRIO_CRITICAL_CONTROL = 3
-
-
-};
-
/**
* Opaque handle to the service.
@@ -93,10 +63,10 @@ struct GNUNET_CORE_Handle;
* @return closure associated with @a peer. given to mq callbacks and
* #GNUNET_CORE_DisconnectEventHandler
*/
-typedef void *
-(*GNUNET_CORE_ConnectEventHandler) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq);
+typedef void *(*GNUNET_CORE_ConnectEventHandler) (
+ void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq);
/**
@@ -107,10 +77,10 @@ typedef void *
* @param peer_cls closure associated with peer. given in
* #GNUNET_CORE_ConnectEventHandler
*/
-typedef void
-(*GNUNET_CORE_DisconnectEventHandler) (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *peer_cls);
+typedef void (*GNUNET_CORE_DisconnectEventHandler) (
+ void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *peer_cls);
/**
@@ -125,9 +95,9 @@ typedef void
* @param cls closure
* @param my_identity ID of this peer, NULL if we failed
*/
-typedef void
-(*GNUNET_CORE_StartupCallback) (void *cls,
- const struct GNUNET_PeerIdentity *my_identity);
+typedef void (*GNUNET_CORE_StartupCallback) (
+ void *cls,
+ const struct GNUNET_PeerIdentity *my_identity);
/**
@@ -172,22 +142,6 @@ void
GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle);
-/**
- * Inquire with CORE what options should be set for a message
- * so that it is transmitted with the given @a priority and
- * the given @a cork value.
- *
- * @param cork desired corking
- * @param priority desired message priority
- * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
- * @return `extra` argument to give to #GNUNET_MQ_set_options()
- */
-const void *
-GNUNET_CORE_get_mq_options (int cork,
- enum GNUNET_CORE_Priority priority,
- uint64_t *flags);
-
-
/**
* Obtain the message queue for a connected peer.
*
@@ -197,7 +151,7 @@ GNUNET_CORE_get_mq_options (int cork,
*/
struct GNUNET_MQ_Handle *
GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
- const struct GNUNET_PeerIdentity *pid);
+ const struct GNUNET_PeerIdentity *pid);
/**
@@ -287,11 +241,11 @@ enum GNUNET_CORE_KxState
* @param state current key exchange state of the peer
* @param timeout when does the current state expire
*/
-typedef void
-(*GNUNET_CORE_MonitorCallback)(void *cls,
- const struct GNUNET_PeerIdentity *pid,
- enum GNUNET_CORE_KxState state,
- struct GNUNET_TIME_Absolute timeout);
+typedef void (*GNUNET_CORE_MonitorCallback) (
+ void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ enum GNUNET_CORE_KxState state,
+ struct GNUNET_TIME_Absolute timeout);
/**
@@ -360,7 +314,7 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
const struct GNUNET_PeerIdentity *target);
-#if 0 /* keep Emacsens' auto-indent happy */
+#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
@@ -370,6 +324,6 @@ GNUNET_CORE_mq_create (struct GNUNET_CORE_Handle *h,
/* ifndef GNUNET_CORE_SERVICE_H */
#endif
-/** @} */ /* end of group core */
+/** @} */ /* end of group core */
/* end of gnunet_core_service.h */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 2a459636a..498567ec2 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -49,7 +49,10 @@
* @param type type of the message
* @return the MQ message
*/
-#define GNUNET_MQ_msg_extra(mvar, esize, type) GNUNET_MQ_msg_(((struct
GNUNET_MessageHeader**) &(mvar)), (esize) + sizeof *(mvar), (type))
+#define GNUNET_MQ_msg_extra(mvar, esize, type) \
+ GNUNET_MQ_msg_ (((struct GNUNET_MessageHeader **) &(mvar)), \
+ (esize) + sizeof *(mvar), \
+ (type))
/**
* Allocate a GNUNET_MQ_Envelope.
@@ -61,7 +64,7 @@
* @param type type of the message
* @return the allocated envelope
*/
-#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
+#define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra (mvar, 0, type)
/**
@@ -70,7 +73,8 @@
*
* @param type type of the message
*/
-#define GNUNET_MQ_msg_header(type) GNUNET_MQ_msg_ (NULL, sizeof (struct
GNUNET_MessageHeader), type)
+#define GNUNET_MQ_msg_header(type) \
+ GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
/**
@@ -81,7 +85,8 @@
* @param esize extra space to allocate after the message header
* @param type type of the message
*/
-#define GNUNET_MQ_msg_header_extra(mh, esize, type) GNUNET_MQ_msg_ (&mh,
(esize) + sizeof (struct GNUNET_MessageHeader), type)
+#define GNUNET_MQ_msg_header_extra(mh, esize, type) \
+ GNUNET_MQ_msg_ (&mh, (esize) + sizeof (struct GNUNET_MessageHeader), type)
/**
@@ -94,14 +99,16 @@
* @param mh message to nest
* @return a newly allocated 'struct GNUNET_MQ_Envelope *'
*/
-#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
- ({struct GNUNET_MQ_Envelope *_ev;\
- _ev = GNUNET_MQ_msg_nested_mh_((struct GNUNET_MessageHeader**) &(mvar),\
- sizeof (*(mvar)),\
- (type),\
- (mh));\
- (void)(mvar)->header; /* type check */\
- _ev;})
+#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
+ ({ \
+ struct GNUNET_MQ_Envelope *_ev; \
+ _ev = GNUNET_MQ_msg_nested_mh_ ((struct GNUNET_MessageHeader **) &(mvar), \
+ sizeof (*(mvar)), \
+ (type), \
+ (mh)); \
+ (void) (mvar)->header; /* type check */ \
+ _ev; \
+ })
/**
@@ -112,7 +119,9 @@
* @return a 'struct GNUNET_MessageHeader *' that points at the nested message
of the given message,
* or NULL if the given message in @a var does not have any space
after the message struct
*/
-#define GNUNET_MQ_extract_nested_mh(var) GNUNET_MQ_extract_nested_mh_ ((struct
GNUNET_MessageHeader *) (var), sizeof (*(var)))
+#define GNUNET_MQ_extract_nested_mh(var) \
+ GNUNET_MQ_extract_nested_mh_ ((struct GNUNET_MessageHeader *) (var), \
+ sizeof (*(var)))
/**
@@ -212,15 +221,90 @@ enum GNUNET_MQ_Error
};
+/**
+ * Per envelope preferences and priorities.
+ */
+enum GNUNET_MQ_PriorityPreferences
+{
+
+ /**
+ * Lowest priority, i.e. background traffic (i.e. NSE, FS).
+ * This is the default!
+ */
+ GNUNET_MQ_PRIO_BACKGROUND = 0,
+
+ /**
+ * Best-effort traffic (i.e. CADET relay, DHT)
+ */
+ GNUNET_MQ_PRIO_BEST_EFFORT = 1,
+
+ /**
+ * Urgent traffic (local peer, i.e. Conversation).
+ */
+ GNUNET_MQ_PRIO_URGENT = 2,
+
+ /**
+ * Highest priority, control traffic (i.e. CORE/CADET KX).
+ */
+ GNUNET_MQ_PRIO_CRITICAL_CONTROL = 3,
+
+ /**
+ * Bit mask to apply to extract the priority bits.
+ */
+ GNUNET_MQ_PRIORITY_MASK = 3,
+
+ /**
+ * Flag to indicate that unreliable delivery is acceptable. This
+ * means TRANSPORT will not attempt to receive an
+ * acknowledgment. CORE will just pass this flag through. CADET
+ * will use unreliable delivery if this flag is set.
+ *
+ * Note that even without this flag, messages may be lost by
+ * TRANSPORT and CORE.
+ *
+ * Thus, how "strong" the semantics of reliable delivery are depends
+ * on the layer!
+ */
+ GNUNET_MQ_PREF_UNRELIABLE = 16,
+
+ /**
+ * Flag to indicate that low latency is important. This flag must
+ * generally not be used in combination with
+ * #GNUNET_MQ_PREF_CORKING_ALLOWED as it would be a contradiction.
+ * When this flags is set, the envelope may skip forward in the
+ * queue (depending on priority) and also TRANSPORT should attempt
+ * to pick a communicator with particularly low latency.
+ */
+ GNUNET_MQ_PREF_LOW_LATENCY = 32,
+
+ /**
+ * Flag to indicate that CORKing is acceptable. This allows the
+ * receiver to delay transmission in hope of combining this message
+ * with other messages into a larger transmission with less
+ * per-message overhead.
+ */
+ GNUNET_MQ_PREF_CORK_ALLOWED = 64,
+
+ /**
+ * Flag to indicate that high bandwidth is desired. This flag
+ * indicates that the method chosen for transmission should focus on
+ * overall goodput. It rarely makes sense to combine this flag with
+ * #GNUNET_MQ_PREF_LOW_LATENCY.
+ */
+ GNUNET_MQ_PREF_GOODPUT = 128
+
+};
+
+
/**
* Called when a message has been received.
*
* @param cls closure
* @param msg the received message
*/
-typedef void
-(*GNUNET_MQ_MessageCallback) (void *cls,
- const struct GNUNET_MessageHeader *msg);
+typedef void (*GNUNET_MQ_MessageCallback) (
+ void *cls,
+ const struct GNUNET_MessageHeader *msg);
/**
@@ -231,9 +315,9 @@ typedef void
* @return #GNUNET_OK if the message is well-formed,
* #GNUNET_SYSERR if not
*/
-typedef int
-(*GNUNET_MQ_MessageValidationCallback) (void *cls,
- const struct GNUNET_MessageHeader *msg);
+typedef int (*GNUNET_MQ_MessageValidationCallback) (
+ void *cls,
+ const struct GNUNET_MessageHeader *msg);
/**
@@ -244,10 +328,9 @@ typedef int
* @param msg the message to send
* @param impl_state state of the implementation
*/
-typedef void
-(*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state);
+typedef void (*GNUNET_MQ_SendImpl) (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state);
/**
@@ -259,9 +342,8 @@ typedef void
* @param mq the message queue to destroy
* @param impl_state state of the implementation
*/
-typedef void
-(*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq,
- void *impl_state);
+typedef void (*GNUNET_MQ_DestroyImpl) (struct GNUNET_MQ_Handle *mq,
+ void *impl_state);
/**
@@ -270,9 +352,8 @@ typedef void
* @param mq message queue
* @param impl_state state specific to the implementation
*/
-typedef void
-(*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq,
- void *impl_state);
+typedef void (*GNUNET_MQ_CancelImpl) (struct GNUNET_MQ_Handle *mq,
+ void *impl_state);
/**
@@ -284,9 +365,7 @@ typedef void
* @param cls closure
* @param error error code
*/
-typedef void
-(*GNUNET_MQ_ErrorHandler) (void *cls,
- enum GNUNET_MQ_Error error);
+typedef void (*GNUNET_MQ_ErrorHandler) (void *cls, enum GNUNET_MQ_Error error);
/**
@@ -411,7 +490,10 @@ struct GNUNET_MQ_MessageHandler
/**
* End-marker for the handlers array
*/
-#define GNUNET_MQ_handler_end() { NULL, NULL, NULL, 0, 0 }
+#define GNUNET_MQ_handler_end() \
+ { \
+ NULL, NULL, NULL, 0, 0 \
+ }
/**
@@ -442,12 +524,14 @@ struct GNUNET_MQ_MessageHandler
* @param str type of the message (a struct)
* @param ctx context for the callbacks
*/
-#define GNUNET_MQ_hd_fixed_size(name,code,str,ctx) \
- ({ \
- void (*_cb)(void *cls, const str *msg) = &handle_##name; \
- ((struct GNUNET_MQ_MessageHandler) { \
- NULL, (GNUNET_MQ_MessageCallback) _cb, \
- (ctx), (code), sizeof (str) }); \
+#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx) \
+ ({ \
+ void (*_cb) (void *cls, const str *msg) = &handle_##name; \
+ ((struct GNUNET_MQ_MessageHandler){NULL, \
+ (GNUNET_MQ_MessageCallback) _cb, \
+ (ctx), \
+ (code), \
+ sizeof (str)}); \
})
@@ -491,14 +575,16 @@ struct GNUNET_MQ_MessageHandler
* @param str type of the message (a struct)
* @param ctx context for the callbacks
*/
-#define GNUNET_MQ_hd_var_size(name,code,str,ctx) \
- __extension__ ({ \
- int (*_mv)(void *cls, const str *msg) = &check_##name; \
- void (*_cb)(void *cls, const str *msg) = &handle_##name; \
- ((struct GNUNET_MQ_MessageHandler) \
- { (GNUNET_MQ_MessageValidationCallback) _mv, \
- (GNUNET_MQ_MessageCallback) _cb, \
- (ctx), (code), sizeof (str) }); \
+#define GNUNET_MQ_hd_var_size(name, code, str, ctx) \
+ __extension__({ \
+ int (*_mv) (void *cls, const str *msg) = &check_##name; \
+ void (*_cb) (void *cls, const str *msg) = &handle_##name; \
+ ((struct GNUNET_MQ_MessageHandler){(GNUNET_MQ_MessageValidationCallback) \
+ _mv, \
+ (GNUNET_MQ_MessageCallback) _cb, \
+ (ctx), \
+ (code), \
+ sizeof (str)}); \
})
@@ -512,18 +598,17 @@ struct GNUNET_MQ_MessageHandler
* @param an IPC message with proper type to determine
* the size, starting with a `struct GNUNET_MessageHeader`
*/
-#define GNUNET_MQ_check_zero_termination(m) \
- { \
- const char *str = (const char *) &m[1]; \
- const struct GNUNET_MessageHeader *hdr = \
- (const struct GNUNET_MessageHeader *) m; \
- uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
- if ( (0 == slen) || \
- (memchr (str, 0, slen) != &str[slen - 1]) ) \
- { \
- GNUNET_break (0); \
- return GNUNET_NO; \
- } \
+#define GNUNET_MQ_check_zero_termination(m) \
+ { \
+ const char *str = (const char *) &m[1]; \
+ const struct GNUNET_MessageHeader *hdr = \
+ (const struct GNUNET_MessageHeader *) m; \
+ uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
+ if ((0 == slen) || (memchr (str, 0, slen) != &str[slen - 1])) \
+ { \
+ GNUNET_break (0); \
+ return GNUNET_NO; \
+ } \
}
@@ -539,19 +624,19 @@ struct GNUNET_MQ_MessageHandler
* @param an IPC message with proper type to determine
* the size, starting with a `struct GNUNET_MessageHeader`
*/
-#define GNUNET_MQ_check_boxed_message(m) \
- { \
- const struct GNUNET_MessageHeader *inbox = \
- (const struct GNUNET_MessageHeader *) &m[1]; \
- const struct GNUNET_MessageHeader *hdr = \
- (const struct GNUNET_MessageHeader *) m; \
- uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
- if ( (slen < sizeof (struct GNUNET_MessageHeader))||\
- (slen != ntohs (inbox->size)) ) \
- { \
- GNUNET_break (0); \
- return GNUNET_NO; \
- } \
+#define GNUNET_MQ_check_boxed_message(m) \
+ { \
+ const struct GNUNET_MessageHeader *inbox = \
+ (const struct GNUNET_MessageHeader *) &m[1]; \
+ const struct GNUNET_MessageHeader *hdr = \
+ (const struct GNUNET_MessageHeader *) m; \
+ uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
+ if ((slen < sizeof (struct GNUNET_MessageHeader)) || \
+ (slen != ntohs (inbox->size))) \
+ { \
+ GNUNET_break (0); \
+ return GNUNET_NO; \
+ } \
}
@@ -645,25 +730,34 @@ GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq);
* #GNUNET_MQ_set_options() for this message only.
*
* @param env message to set options for
- * @param flags flags to use (meaning is queue-specific)
- * @param extra additional buffer for further data (also queue-specific)
+ * @param pp priority and preferences to set for @a env
*/
void
GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
- uint64_t flags,
- const void *extra);
+ enum GNUNET_MQ_PriorityPreferences pp);
/**
- * Get application-specific options for this envelope.
+ * Get performance preferences set for this envelope.
*
* @param env message to set options for
- * @param[out] flags set to flags to use (meaning is queue-specific)
- * @return extra additional buffer for further data (also queue-specific)
+ * @return priority and preferences to use
+ */
+enum GNUNET_MQ_PriorityPreferences
+GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env);
+
+
+/**
+ * Combine performance preferences set for different
+ * envelopes that are being combined into one larger envelope.
+ *
+ * @param p1 one set of preferences
+ * @param p2 second set of preferences
+ * @return combined priority and preferences to use
*/
-const void *
-GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env,
- uint64_t *flags);
+enum GNUNET_MQ_PriorityPreferences
+GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
+ enum GNUNET_MQ_PriorityPreferences p2);
/**
@@ -681,13 +775,11 @@ GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq);
* Set application-specific options for this queue.
*
* @param mq message queue to set options for
- * @param flags flags to use (meaning is queue-specific)
- * @param extra additional buffer for further data (also queue-specific)
+ * @param pp priority and preferences to use by default
*/
void
GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
- uint64_t flags,
- const void *extra);
+ enum GNUNET_MQ_PriorityPreferences pp);
/**
@@ -708,8 +800,7 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq);
* @param ev the envelope with the message to send.
*/
void
-GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
- struct GNUNET_MQ_Envelope *ev);
+GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev);
/**
@@ -742,8 +833,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev);
* @param assoc_data to associate
*/
uint32_t
-GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
- void *assoc_data);
+GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data);
/**
@@ -754,8 +844,7 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
- uint32_t request_id);
+GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
/**
@@ -766,8 +855,7 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
- uint32_t request_id);
+GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id);
/**
@@ -846,8 +934,8 @@ struct GNUNET_MQ_DestroyNotificationHandle;
*/
struct GNUNET_MQ_DestroyNotificationHandle *
GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
- GNUNET_SCHEDULER_TaskCallback cb,
- void *cb_cls);
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls);
/**
* Cancel registration from #GNUNET_MQ_destroy_notify().
@@ -855,7 +943,8 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
* @param dnh handle for registration to cancel
*/
void
-GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle
*dnh);
+GNUNET_MQ_destroy_notify_cancel (
+ struct GNUNET_MQ_DestroyNotificationHandle *dnh);
/**
@@ -947,7 +1036,6 @@ const struct GNUNET_MessageHeader *
GNUNET_MQ_impl_current (struct GNUNET_MQ_Handle *mq);
-
/**
* Enum defining all known preference categories.
*/
@@ -977,7 +1065,7 @@ enum GNUNET_MQ_PreferenceKind
*/
GNUNET_MQ_PREFERENCE_RELIABILITY = 3
- /**
+/**
* Number of preference values allowed.
*/
#define GNUNET_MQ_PREFERENCE_COUNT 4
@@ -995,8 +1083,6 @@ const char *
GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type);
-
-
#endif
/** @} */ /* end of group mq */
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 5b12c4b98..09316dbcf 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -51,7 +51,6 @@
#include <gcrypt.h>
-
/**
* Should messages be delayed randomly? This option should be set to
* #GNUNET_NO only for experiments, not in production.
@@ -69,12 +68,15 @@
#define HISTORY_SIZE 64
/**
- * Message priority to use.
+ * Message priority to use. No real rush, reliability not
+ * required. Corking OK.
*/
-#define NSE_PRIORITY GNUNET_CORE_PRIO_CRITICAL_CONTROL
+#define NSE_PRIORITY \
+ (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE | \
+ GNUNET_MQ_PREF_CORK_ALLOWED)
#if FREEBSD
-#define log2(a) (log(a)/log(2))
+#define log2(a) (log (a) / log (2))
#endif
/**
@@ -158,7 +160,6 @@ struct NSEPeerEntry
unsigned int last_transmitted_size;
#endif
-
};
@@ -380,13 +381,14 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage
*em)
if (0 != estimate_count)
{
mean = sum / estimate_count;
- variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible
for numerical stability...
+ variance = (vsq - mean * sum) /
+ (estimate_count - 1.0); // terrible for numerical stability...
}
#endif
if (variance >= 0)
std_dev = sqrt (variance);
else
- std_dev = variance; /* must be infinity due to estimate_count == 0
*/
+ std_dev = variance; /* must be infinity due to estimate_count == 0 */
current_std_dev = std_dev;
current_size_estimate = mean;
@@ -401,14 +403,12 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage
*em)
j = 1; /* Avoid log2(0); can only happen if CORE didn't report
connection to self yet */
nsize = log2 (j);
- em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se,
- nsize));
+ em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize));
em->std_deviation = GNUNET_hton_double (std_dev);
GNUNET_STATISTICS_set (stats,
- "# nodes in the network (estimate)",
- (uint64_t) pow (2, GNUNET_MAX (se,
- nsize)),
- GNUNET_NO);
+ "# nodes in the network (estimate)",
+ (uint64_t) pow (2, GNUNET_MAX (se, nsize)),
+ GNUNET_NO);
}
}
@@ -423,23 +423,19 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage
*em)
* @param message the message received
*/
static void
-handle_start (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_start (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Handle *mq;
struct GNUNET_NSE_ClientMessage em;
struct GNUNET_MQ_Envelope *env;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received START message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
mq = GNUNET_SERVICE_client_get_mq (client);
- GNUNET_notification_context_add (nc,
- mq);
+ GNUNET_notification_context_add (nc, mq);
setup_estimate_message (&em);
env = GNUNET_MQ_msg_copy (&em.header);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_send (mq, env);
GNUNET_SERVICE_client_continue (client);
}
@@ -459,8 +455,8 @@ get_matching_bits_delay (uint32_t matching_bits)
// x is matching_bits
// p' is current_size_estimate
return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0) -
- ((gnunet_nse_interval.rel_value_us / M_PI) *
- atan (matching_bits - current_size_estimate));
+ ((gnunet_nse_interval.rel_value_us / M_PI) *
+ atan (matching_bits - current_size_estimate));
}
@@ -482,10 +478,10 @@ get_delay_randomization (uint32_t matching_bits)
i = (uint32_t) (d / (double) (hop_count_max + 1));
ret.rel_value_us = i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Randomizing flood using latencies up to %s\n",
- GNUNET_STRINGS_relative_time_to_string (ret,
- GNUNET_YES));
- ret.rel_value_us = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i +
1);
+ "Randomizing flood using latencies up to %s\n",
+ GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
+ ret.rel_value_us =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, i + 1);
return ret;
#else
return GNUNET_TIME_UNIT_ZERO;
@@ -501,19 +497,18 @@ get_delay_randomization (uint32_t matching_bits)
* @param result where to write the resulting hash
*/
static void
-pow_hash (const void *buf,
- size_t buf_len,
- struct GNUNET_HashCode *result)
+pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
{
- GNUNET_break (0 ==
- gcry_kdf_derive (buf, buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- "gnunet-proof-of-work",
- strlen ("gnunet-proof-of-work"),
- 2 /* iterations; keep cost of individual op
small */,
- sizeof (struct GNUNET_HashCode),
- result));
+ GNUNET_break (
+ 0 == gcry_kdf_derive (buf,
+ buf_len,
+ GCRY_KDF_SCRYPT,
+ 1 /* subalgo */,
+ "gnunet-proof-of-work",
+ strlen ("gnunet-proof-of-work"),
+ 2 /* iterations; keep cost of individual op small */,
+ sizeof (struct GNUNET_HashCode),
+ result));
}
@@ -534,11 +529,8 @@ get_matching_bits (struct GNUNET_TIME_Absolute timestamp,
GNUNET_CRYPTO_hash (×tamp.abs_value_us,
sizeof (timestamp.abs_value_us),
×tamp_hash);
- GNUNET_CRYPTO_hash (id,
- sizeof (struct GNUNET_PeerIdentity),
- &pid_hash);
- return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash,
- &pid_hash);
+ GNUNET_CRYPTO_hash (id, sizeof (struct GNUNET_PeerIdentity), &pid_hash);
+ return GNUNET_CRYPTO_hash_matching_bits (×tamp_hash, &pid_hash);
}
@@ -563,20 +555,19 @@ get_transmit_delay (int round_offset)
case -1:
/* previous round is randomized between 0 and 50 ms */
#if USE_RANDOM_DELAYS
- ret.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- 50);
+ ret.rel_value_us =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 50);
#else
ret = GNUNET_TIME_UNIT_ZERO;
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting previous round behind schedule in %s\n",
- GNUNET_STRINGS_relative_time_to_string (ret,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
return ret;
case 0:
/* current round is based on best-known matching_bits */
matching_bits =
- ntohl (size_estimate_messages[estimate_index].matching_bits);
+ ntohl (size_estimate_messages[estimate_index].matching_bits);
dist_delay = get_matching_bits_delay (matching_bits);
dist_delay += get_delay_randomization (matching_bits).rel_value_us;
ret.rel_value_us = (uint64_t) dist_delay;
@@ -584,11 +575,9 @@ get_transmit_delay (int round_offset)
"For round %s, delay for %u matching bits is %s\n",
GNUNET_STRINGS_absolute_time_to_string (current_timestamp),
(unsigned int) matching_bits,
- GNUNET_STRINGS_relative_time_to_string (ret,
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
/* now consider round start time and add delay to it */
- tgt = GNUNET_TIME_absolute_add (current_timestamp,
- ret);
+ tgt = GNUNET_TIME_absolute_add (current_timestamp, ret);
return GNUNET_TIME_absolute_get_remaining (tgt);
}
GNUNET_break (0);
@@ -614,10 +603,10 @@ transmit_task_cb (void *cls)
{
idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
peer_entry->previous_round = GNUNET_YES;
- peer_entry->transmit_task
- = GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0),
- &transmit_task_cb,
- peer_entry);
+ peer_entry->transmit_task =
+ GNUNET_SCHEDULER_add_delayed (get_transmit_delay (0),
+ &transmit_task_cb,
+ peer_entry);
}
if ((0 == ntohl (size_estimate_messages[idx].hop_count)) &&
(NULL != proof_task))
@@ -625,7 +614,7 @@ transmit_task_cb (void *cls)
GNUNET_STATISTICS_update (stats,
"# flood messages not generated (no proof yet)",
1,
- GNUNET_NO);
+ GNUNET_NO);
return;
}
if (0 == ntohs (size_estimate_messages[idx].header.size))
@@ -633,31 +622,29 @@ transmit_task_cb (void *cls)
GNUNET_STATISTICS_update (stats,
"# flood messages not generated (lack of
history)",
1,
- GNUNET_NO);
+ GNUNET_NO);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In round %s, sending to `%s' estimate with %u bits\n",
- GNUNET_STRINGS_absolute_time_to_string
(GNUNET_TIME_absolute_ntoh (size_estimate_messages[idx].timestamp)),
+ GNUNET_STRINGS_absolute_time_to_string (
+ GNUNET_TIME_absolute_ntoh (
+ size_estimate_messages[idx].timestamp)),
GNUNET_i2s (peer_entry->id),
(unsigned int) ntohl
(size_estimate_messages[idx].matching_bits));
if (0 == ntohl (size_estimate_messages[idx].hop_count))
- GNUNET_STATISTICS_update (stats,
- "# flood messages started",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- "# flood messages transmitted",
- 1,
+ "# flood messages transmitted",
+ 1,
GNUNET_NO);
#if ENABLE_NSE_HISTOGRAM
peer_entry->transmitted_messages++;
- peer_entry->last_transmitted_size
- = ntohl(size_estimate_messages[idx].matching_bits);
+ peer_entry->last_transmitted_size =
+ ntohl (size_estimate_messages[idx].matching_bits);
#endif
env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header);
- GNUNET_MQ_send (peer_entry->mq,
- env);
+ GNUNET_MQ_send (peer_entry->mq, env);
}
@@ -673,9 +660,7 @@ update_network_size_estimate ()
struct GNUNET_NSE_ClientMessage em;
setup_estimate_message (&em);
- GNUNET_notification_context_broadcast (nc,
- &em.header,
- GNUNET_YES);
+ GNUNET_notification_context_broadcast (nc, &em.header, GNUNET_YES);
}
@@ -687,36 +672,31 @@ update_network_size_estimate ()
* @param ts timestamp to use
*/
static void
-setup_flood_message (unsigned int slot,
- struct GNUNET_TIME_Absolute ts)
+setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
{
struct GNUNET_NSE_FloodMessage *fm;
uint32_t matching_bits;
- matching_bits = get_matching_bits (ts,
- &my_identity);
+ matching_bits = get_matching_bits (ts, &my_identity);
fm = &size_estimate_messages[slot];
fm->header.size = htons (sizeof (struct GNUNET_NSE_FloodMessage));
fm->header.type = htons (GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD);
fm->hop_count = htonl (0);
fm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_NSE_SEND);
fm->purpose.size =
- htonl (sizeof (struct GNUNET_NSE_FloodMessage) -
- sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) -
- sizeof (struct GNUNET_CRYPTO_EddsaSignature));
+ htonl (sizeof (struct GNUNET_NSE_FloodMessage) -
+ sizeof (struct GNUNET_MessageHeader) - sizeof (uint32_t) -
+ sizeof (struct GNUNET_CRYPTO_EddsaSignature));
fm->matching_bits = htonl (matching_bits);
fm->timestamp = GNUNET_TIME_absolute_hton (ts);
fm->origin = my_identity;
fm->proof_of_work = my_proof;
if (nse_work_required > 0)
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &fm->purpose,
- &fm->signature));
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &fm->purpose,
+ &fm->signature));
else
- memset (&fm->signature,
- 0,
- sizeof (fm->signature));
+ memset (&fm->signature, 0, sizeof (fm->signature));
}
@@ -731,8 +711,8 @@ setup_flood_message (unsigned int slot,
*/
static int
schedule_current_round (void *cls,
- const struct GNUNET_PeerIdentity * key,
- void *value)
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
@@ -744,20 +724,18 @@ schedule_current_round (void *cls,
}
#if ENABLE_NSE_HISTOGRAM
if (peer_entry->received_messages > 1)
- GNUNET_STATISTICS_update(stats,
- "# extra messages",
- peer_entry->received_messages - 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# extra messages",
+ peer_entry->received_messages - 1,
+ GNUNET_NO);
peer_entry->transmitted_messages = 0;
peer_entry->last_transmitted_size = 0;
peer_entry->received_messages = 0;
#endif
delay =
- get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0);
+ get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_task_cb,
- peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
return GNUNET_OK;
}
@@ -779,9 +757,7 @@ update_flood_message (void *cls)
{
/* somehow run early, delay more */
flood_task =
- GNUNET_SCHEDULER_add_delayed (offset,
- &update_flood_message,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
return;
}
estimate_index = (estimate_index + 1) % HISTORY_SIZE;
@@ -789,32 +765,27 @@ update_flood_message (void *cls)
estimate_count++;
current_timestamp = next_timestamp;
next_timestamp =
- GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
- if ( (current_timestamp.abs_value_us ==
- GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) &&
- (get_matching_bits (current_timestamp, &my_identity) <
- ntohl(next_message.matching_bits)) )
+ GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
+ if ((current_timestamp.abs_value_us ==
+ GNUNET_TIME_absolute_ntoh (next_message.timestamp).abs_value_us) &&
+ (get_matching_bits (current_timestamp, &my_identity) <
+ ntohl (next_message.matching_bits)))
{
/* we received a message for this round way early, use it! */
size_estimate_messages[estimate_index] = next_message;
size_estimate_messages[estimate_index].hop_count =
- htonl (1 + ntohl (next_message.hop_count));
+ htonl (1 + ntohl (next_message.hop_count));
}
else
- setup_flood_message (estimate_index,
- current_timestamp);
- next_message.matching_bits = htonl (0); /* reset for 'next' round */
+ setup_flood_message (estimate_index, current_timestamp);
+ next_message.matching_bits = htonl (0); /* reset for 'next' round */
hop_count_max = 0;
for (i = 0; i < HISTORY_SIZE; i++)
- hop_count_max = GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count),
- hop_count_max);
- GNUNET_CONTAINER_multipeermap_iterate (peers,
- &schedule_current_round,
- NULL);
- flood_task
- = GNUNET_SCHEDULER_add_at (next_timestamp,
- &update_flood_message,
- NULL);
+ hop_count_max =
+ GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &schedule_current_round, NULL);
+ flood_task =
+ GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL);
}
@@ -830,8 +801,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
unsigned int hash_count;
hash_count = 0;
- while (0 == GNUNET_CRYPTO_hash_get_bit (hash,
- hash_count))
+ while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
hash_count++;
return hash_count;
}
@@ -853,17 +823,13 @@ check_proof_of_work (const struct
GNUNET_CRYPTO_EddsaPublicKey *pkey,
sizeof (val)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
- GNUNET_memcpy (buf,
- &val,
- sizeof (val));
+ GNUNET_memcpy (buf, &val, sizeof (val));
GNUNET_memcpy (&buf[sizeof (val)],
- pkey,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
- pow_hash (buf,
- sizeof (buf),
- &result);
- return (count_leading_zeroes (&result) >=
- nse_work_required) ? GNUNET_YES : GNUNET_NO;
+ pkey,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ pow_hash (buf, sizeof (buf), &result);
+ return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
+ : GNUNET_NO;
}
@@ -876,20 +842,14 @@ write_proof ()
char *proof;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE",
- "PROOFFILE",
- &proof))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE",
&proof))
return;
- if (sizeof (my_proof) !=
- GNUNET_DISK_fn_write (proof,
- &my_proof,
- sizeof (my_proof),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- proof);
+ if (sizeof (my_proof) != GNUNET_DISK_fn_write (proof,
+ &my_proof,
+ sizeof (my_proof),
+ GNUNET_DISK_PERM_USER_READ |
+
GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
GNUNET_free (proof);
}
@@ -910,8 +870,9 @@ find_proof (void *cls)
unsigned int i;
proof_task = NULL;
- GNUNET_memcpy (&buf[sizeof (uint64_t)], &my_identity,
- sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_memcpy (&buf[sizeof (uint64_t)],
+ &my_identity,
+ sizeof (struct GNUNET_PeerIdentity));
i = 0;
counter = my_proof;
while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
@@ -921,7 +882,8 @@ find_proof (void *cls)
if (nse_work_required <= count_leading_zeroes (&result))
{
my_proof = counter;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Proof of work found: %llu!\n",
(unsigned long long) GNUNET_ntohll (counter));
write_proof ();
setup_flood_message (estimate_index, current_timestamp);
@@ -944,9 +906,10 @@ find_proof (void *cls)
my_proof = counter;
}
proof_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
-
GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
}
@@ -962,23 +925,22 @@ find_proof (void *cls)
static int
verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
{
- if (GNUNET_YES !=
- check_proof_of_work (&incoming_flood->origin.public_key,
- incoming_flood->proof_of_work))
+ if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key,
+ incoming_flood->proof_of_work))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Proof of work invalid: %llu!\n",
- (unsigned long long)
- GNUNET_ntohll (incoming_flood->proof_of_work));
+ (unsigned long long) GNUNET_ntohll (
+ incoming_flood->proof_of_work));
GNUNET_break_op (0);
return GNUNET_NO;
}
if ((nse_work_required > 0) &&
(GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_NSE_SEND,
- &incoming_flood->purpose,
- &incoming_flood->signature,
- &incoming_flood->origin.public_key)))
+ &incoming_flood->purpose,
+ &incoming_flood->signature,
+ &incoming_flood->origin.public_key)))
{
GNUNET_break_op (0);
return GNUNET_NO;
@@ -998,15 +960,15 @@ verify_message_crypto (const struct
GNUNET_NSE_FloodMessage *incoming_flood)
*/
static int
update_flood_times (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct NSEPeerEntry *exclude = cls;
struct NSEPeerEntry *peer_entry = value;
struct GNUNET_TIME_Relative delay;
if (peer_entry == exclude)
- return GNUNET_OK; /* trigger of the update */
+ return GNUNET_OK; /* trigger of the update */
if (GNUNET_NO == peer_entry->previous_round)
{
/* still stuck in previous round, no point to update, check that
@@ -1024,8 +986,7 @@ update_flood_times (void *cls,
}
delay = get_transmit_delay (0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay,
- &transmit_task_cb, peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
return GNUNET_OK;
}
@@ -1038,7 +999,7 @@ update_flood_times (void *cls,
*/
static void
handle_p2p_estimate (void *cls,
- const struct GNUNET_NSE_FloodMessage *incoming_flood)
+ const struct GNUNET_NSE_FloodMessage *incoming_flood)
{
struct NSEPeerEntry *peer_entry = cls;
struct GNUNET_TIME_Absolute ts;
@@ -1049,17 +1010,14 @@ handle_p2p_estimate (void *cls,
{
uint64_t t;
- t = GNUNET_TIME_absolute_get().abs_value_us;
+ t = GNUNET_TIME_absolute_get ().abs_value_us;
if (NULL != lh)
GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof (uint64_t));
if (NULL != histogram)
GNUNET_BIO_write_int64 (histogram, t);
}
#endif
- GNUNET_STATISTICS_update (stats,
- "# flood messages received",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
matching_bits = ntohl (incoming_flood->matching_bits);
#if DEBUG_NSE
{
@@ -1068,19 +1026,17 @@ handle_p2p_estimate (void *cls,
struct GNUNET_PeerIdentity os;
GNUNET_snprintf (origin,
- sizeof (origin),
- "%s",
- GNUNET_i2s (&incoming_flood->origin));
- GNUNET_snprintf (pred,
- sizeof (pred),
- "%s",
- GNUNET_i2s (peer_entry->id));
+ sizeof (origin),
+ "%s",
+ GNUNET_i2s (&incoming_flood->origin));
+ GNUNET_snprintf (pred, sizeof (pred), "%s", GNUNET_i2s (peer_entry->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Flood at %s from `%s' via `%s' at `%s' with bits %u\n",
- GNUNET_STRINGS_absolute_time_to_string
(GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)),
+ GNUNET_STRINGS_absolute_time_to_string (
+ GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)),
origin,
- pred,
- GNUNET_i2s (&my_identity),
+ pred,
+ GNUNET_i2s (&my_identity),
(unsigned int) matching_bits);
}
#endif
@@ -1089,10 +1045,7 @@ handle_p2p_estimate (void *cls,
peer_entry->received_messages++;
if (peer_entry->transmitted_messages > 0 &&
peer_entry->last_transmitted_size >= matching_bits)
- GNUNET_STATISTICS_update(stats,
- "# cross messages",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO);
#endif
ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
@@ -1104,9 +1057,8 @@ handle_p2p_estimate (void *cls,
else if (ts.abs_value_us == next_timestamp.abs_value_us)
{
if (matching_bits <= ntohl (next_message.matching_bits))
- return; /* ignore, simply too early/late */
- if (GNUNET_YES !=
- verify_message_crypto (incoming_flood))
+ return; /* ignore, simply too early/late */
+ if (GNUNET_YES != verify_message_crypto (incoming_flood))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Peer %s is likely ill-configured!\n",
@@ -1121,21 +1073,18 @@ handle_p2p_estimate (void *cls,
{
GNUNET_STATISTICS_update (stats,
"# flood messages discarded (clock skew too
large)",
- 1, GNUNET_NO);
+ 1,
+ GNUNET_NO);
return;
}
- if (0 == (GNUNET_memcmp (peer_entry->id,
- &my_identity)))
+ if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity)))
{
/* send to self, update our own estimate IF this also comes from us! */
- if (0 ==
- GNUNET_memcmp (&incoming_flood->origin,
- &my_identity))
+ if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity))
update_network_size_estimate ();
return;
}
- if (matching_bits ==
- ntohl (size_estimate_messages[idx].matching_bits))
+ if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits))
{
/* Cancel transmission in the other direction, as this peer clearly has
up-to-date information already. Even if we didn't talk to this peer in
@@ -1159,26 +1108,23 @@ handle_p2p_estimate (void *cls,
}
if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits))
{
- if ( (idx < estimate_index) &&
- (peer_entry->previous_round == GNUNET_YES))
+ if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
{
peer_entry->previous_round = GNUNET_NO;
}
/* push back our result now, that peer is spreading bad information... */
if (NULL != peer_entry->transmit_task)
GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
- peer_entry->transmit_task
- = GNUNET_SCHEDULER_add_now (&transmit_task_cb,
- peer_entry);
+ peer_entry->transmit_task =
+ GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry);
/* Not closer than our most recent message, no need to do work here */
GNUNET_STATISTICS_update (stats,
"# flood messages ignored (had closer already)",
1,
- GNUNET_NO);
+ GNUNET_NO);
return;
}
- if (GNUNET_YES !=
- verify_message_crypto (incoming_flood))
+ if (GNUNET_YES != verify_message_crypto (incoming_flood))
{
GNUNET_break_op (0);
return;
@@ -1200,20 +1146,20 @@ handle_p2p_estimate (void *cls,
}
size_estimate_messages[idx] = *incoming_flood;
size_estimate_messages[idx].hop_count =
- htonl (ntohl (incoming_flood->hop_count) + 1);
+ htonl (ntohl (incoming_flood->hop_count) + 1);
hop_count_max =
- GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1,
- hop_count_max);
+ GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
GNUNET_STATISTICS_set (stats,
- "# estimated network diameter",
- hop_count_max, GNUNET_NO);
+ "# estimated network diameter",
+ hop_count_max,
+ GNUNET_NO);
/* have a new, better size estimate, inform clients */
update_network_size_estimate ();
/* flood to rest */
GNUNET_CONTAINER_multipeermap_iterate (peers,
- &update_flood_times,
+ &update_flood_times,
peer_entry);
}
@@ -1227,40 +1173,31 @@ handle_p2p_estimate (void *cls,
*/
static void *
handle_core_connect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
struct NSEPeerEntry *peer_entry;
- uint64_t flags;
- const void *extra;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer `%s' connected to us\n",
GNUNET_i2s (peer));
/* set our default transmission options */
- extra = GNUNET_CORE_get_mq_options (GNUNET_NO,
- NSE_PRIORITY,
- &flags);
- GNUNET_MQ_set_options (mq,
- flags,
- extra);
+ GNUNET_MQ_set_options (mq, NSE_PRIORITY);
/* create our peer entry for this peer */
peer_entry = GNUNET_new (struct NSEPeerEntry);
peer_entry->id = peer;
peer_entry->mq = mq;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (peers,
- peer_entry->id,
- peer_entry,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ peers,
+ peer_entry->id,
+ peer_entry,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1),
- &transmit_task_cb,
- peer_entry);
- GNUNET_STATISTICS_update (stats,
- "# peers connected",
- 1,
- GNUNET_NO);
+ GNUNET_SCHEDULER_add_delayed (get_transmit_delay (-1),
+ &transmit_task_cb,
+ peer_entry);
+ GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO);
return peer_entry;
}
@@ -1275,28 +1212,23 @@ handle_core_connect (void *cls,
*/
static void
handle_core_disconnect (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- void *internal_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls)
{
struct NSEPeerEntry *pos = internal_cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%s' disconnected from us\n",
+ "Peer `%s' disconnected from us\n",
GNUNET_i2s (peer));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (peers,
- peer,
- pos));
+ GNUNET_CONTAINER_multipeermap_remove (peers, peer, pos));
if (NULL != pos->transmit_task)
{
GNUNET_SCHEDULER_cancel (pos->transmit_task);
pos->transmit_task = NULL;
}
GNUNET_free (pos);
- GNUNET_STATISTICS_update (stats,
- "# peers connected",
- -1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO);
}
@@ -1309,8 +1241,7 @@ handle_core_disconnect (void *cls,
* @param size the amount of data sent (ignored)
*/
static void
-flush_comp_cb (void *cls,
- size_t size)
+flush_comp_cb (void *cls, size_t size)
{
GNUNET_TESTBED_LOGGER_disconnect (lh);
lh = NULL;
@@ -1335,7 +1266,7 @@ shutdown_task (void *cls)
{
GNUNET_SCHEDULER_cancel (proof_task);
proof_task = NULL;
- write_proof (); /* remember progress */
+ write_proof (); /* remember progress */
}
if (NULL != nc)
{
@@ -1370,9 +1301,7 @@ shutdown_task (void *cls)
}
if (NULL != lh)
{
- GNUNET_TESTBED_LOGGER_flush (lh,
- &flush_comp_cb,
- NULL);
+ GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL);
}
if (NULL != histogram)
{
@@ -1390,48 +1319,37 @@ shutdown_task (void *cls)
* @param identity the public identity of this peer
*/
static void
-core_init (void *cls,
- const struct GNUNET_PeerIdentity *identity)
+core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
{
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute prev_time;
if (NULL == identity)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Connection to core FAILED!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_assert (0 ==
- GNUNET_memcmp (&my_identity,
- identity));
+ GNUNET_assert (0 == GNUNET_memcmp (&my_identity, identity));
now = GNUNET_TIME_absolute_get ();
current_timestamp.abs_value_us =
- (now.abs_value_us / gnunet_nse_interval.rel_value_us) *
- gnunet_nse_interval.rel_value_us;
+ (now.abs_value_us / gnunet_nse_interval.rel_value_us) *
+ gnunet_nse_interval.rel_value_us;
next_timestamp =
- GNUNET_TIME_absolute_add (current_timestamp,
- gnunet_nse_interval);
+ GNUNET_TIME_absolute_add (current_timestamp, gnunet_nse_interval);
estimate_index = HISTORY_SIZE - 1;
estimate_count = 0;
- if (GNUNET_YES ==
- check_proof_of_work (&my_identity.public_key,
- my_proof))
+ if (GNUNET_YES == check_proof_of_work (&my_identity.public_key, my_proof))
{
int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
prev_time.abs_value_us =
- current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us;
- setup_flood_message (idx,
- prev_time);
- setup_flood_message (estimate_index,
- current_timestamp);
+ current_timestamp.abs_value_us - gnunet_nse_interval.rel_value_us;
+ setup_flood_message (idx, prev_time);
+ setup_flood_message (estimate_index, current_timestamp);
estimate_count++;
}
- flood_task
- = GNUNET_SCHEDULER_add_at (next_timestamp,
- &update_flood_message,
- NULL);
+ flood_task =
+ GNUNET_SCHEDULER_add_at (next_timestamp, &update_flood_message, NULL);
}
@@ -1445,14 +1363,12 @@ core_init (void *cls,
* #GNUNET_SYSERR if the configuration is invalid
*/
static void
-status_cb (void *cls,
- int status)
+status_cb (void *cls, int status)
{
logger_test = NULL;
if (GNUNET_YES != status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Testbed logger not running\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed logger not running\n");
return;
}
if (NULL == (lh = GNUNET_TESTBED_LOGGER_connect (cfg)))
@@ -1477,59 +1393,49 @@ run (void *cls,
const struct GNUNET_CONFIGURATION_Handle *c,
struct GNUNET_SERVICE_Handle *service)
{
- struct GNUNET_MQ_MessageHandler core_handlers[] = {
- GNUNET_MQ_hd_fixed_size (p2p_estimate,
- GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD,
- struct GNUNET_NSE_FloodMessage,
- NULL),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler core_handlers[] =
+ {GNUNET_MQ_hd_fixed_size (p2p_estimate,
+ GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD,
+ struct GNUNET_NSE_FloodMessage,
+ NULL),
+ GNUNET_MQ_handler_end ()};
char *proof;
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "NSE",
- "INTERVAL",
- &gnunet_nse_interval))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
+ "NSE",
+ "INTERVAL",
+ &gnunet_nse_interval))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "INTERVAL");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL");
GNUNET_SCHEDULER_shutdown ();
return;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "NSE",
- "WORKDELAY",
- &proof_find_delay))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg,
+ "NSE",
+ "WORKDELAY",
+ &proof_find_delay))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKDELAY");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY");
GNUNET_SCHEDULER_shutdown ();
return;
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "NSE",
- "WORKBITS",
- &nse_work_required))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE",
+ "WORKBITS",
+ &nse_work_required))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS",
- _("Value is too large.\n"));
+ "NSE",
+ "WORKBITS",
+ _ ("Value is too large.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -1539,49 +1445,38 @@ run (void *cls,
char *histogram_dir;
char *histogram_fn;
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE",
- "HISTOGRAM_DIR",
- &histogram_dir))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "NSE",
+ "HISTOGRAM_DIR",
+ &histogram_dir))
{
- GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn,
- "%s/timestamps",
- histogram_dir));
+ GNUNET_assert (
+ 0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir));
GNUNET_free (histogram_dir);
histogram = GNUNET_BIO_write_open (histogram_fn);
if (NULL == histogram)
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unable to open histogram file `%s'\n",
- histogram_fn);
+ "Unable to open histogram file `%s'\n",
+ histogram_fn);
GNUNET_free (histogram_fn);
}
- logger_test =
- GNUNET_CLIENT_service_test ("testbed-logger",
- cfg,
- GNUNET_TIME_UNIT_SECONDS,
- &status_cb,
- NULL);
-
+ logger_test = GNUNET_CLIENT_service_test ("testbed-logger",
+ cfg,
+ GNUNET_TIME_UNIT_SECONDS,
+ &status_cb,
+ NULL);
}
#endif
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
GNUNET_assert (NULL != pk);
my_private_key = pk;
- GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
- &my_identity.public_key);
+ GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE",
- "PROOFFILE",
- &proof))
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE",
&proof))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "PROOFFILE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE");
GNUNET_free (my_private_key);
my_private_key = NULL;
GNUNET_SCHEDULER_shutdown ();
@@ -1589,33 +1484,30 @@ run (void *cls,
}
if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
(sizeof (my_proof) !=
- GNUNET_DISK_fn_read (proof,
- &my_proof,
- sizeof (my_proof))))
+ GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof))))
my_proof = 0;
GNUNET_free (proof);
proof_task =
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof,
- NULL);
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
- peers = GNUNET_CONTAINER_multipeermap_create (128,
- GNUNET_YES);
+ peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
nc = GNUNET_notification_context_create (1);
/* Connect to core service and register core handlers */
- core_api = GNUNET_CORE_connect (cfg, /* Main configuration */
- NULL, /* Closure passed to functions */
- &core_init, /* Call core_init once
connected */
- &handle_core_connect, /* Handle connects */
- &handle_core_disconnect, /* Handle
disconnects */
- core_handlers); /* Register these
handlers */
+ core_api =
+ GNUNET_CORE_connect (cfg, /* Main configuration */
+ NULL, /* Closure passed to functions */
+ &core_init, /* Call core_init once connected */
+ &handle_core_connect, /* Handle connects */
+ &handle_core_disconnect, /* Handle disconnects */
+ core_handlers); /* Register these handlers */
if (NULL == core_api)
{
GNUNET_SCHEDULER_shutdown ();
return;
}
- stats = GNUNET_STATISTICS_create ("nse",
- cfg);
+ stats = GNUNET_STATISTICS_create ("nse", cfg);
}
@@ -1629,8 +1521,8 @@ run (void *cls,
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *c,
+ struct GNUNET_MQ_Handle *mq)
{
return c;
}
@@ -1645,8 +1537,8 @@ client_connect_cb (void *cls,
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- void *internal_cls)
+ struct GNUNET_SERVICE_Client *c,
+ void *internal_cls)
{
GNUNET_assert (c == internal_cls);
}
@@ -1655,18 +1547,17 @@ client_disconnect_cb (void *cls,
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("nse",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (start,
- GNUNET_MESSAGE_TYPE_NSE_START,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN ("nse",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (start,
+ GNUNET_MESSAGE_TYPE_NSE_START,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
#if defined(LINUX) && defined(__GLIBC__)
@@ -1675,8 +1566,7 @@ GNUNET_SERVICE_MAIN
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((constructor))
-GNUNET_ARM_memory_init ()
+void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
{
mallopt (M_TRIM_THRESHOLD, 4 * 1024);
mallopt (M_TOP_PAD, 1 * 1024);
@@ -1685,5 +1575,4 @@ GNUNET_ARM_memory_init ()
#endif
-
/* end of gnunet-service-nse.c */
diff --git a/src/topology/gnunet-daemon-topology.c
b/src/topology/gnunet-daemon-topology.c
index e5734abb4..5a22ee0d2 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -51,12 +51,14 @@
/**
* At what frequency do we sent HELLOs to a peer?
*/
-#define HELLO_ADVERTISEMENT_MIN_FREQUENCY GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_MINUTES, 5)
+#define HELLO_ADVERTISEMENT_MIN_FREQUENCY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
* After what time period do we expire the HELLO Bloom filter?
*/
-#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_HOURS, 4)
+#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
/**
@@ -116,7 +118,6 @@ struct Peer
* Is this peer listed here because it is a friend?
*/
int is_friend;
-
};
@@ -216,15 +217,12 @@ static unsigned int friend_count;
* @return #GNUNET_OK if the connection is allowed
*/
static int
-blacklist_check (void *cls,
- const struct GNUNET_PeerIdentity *pid)
+blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
{
struct Peer *pos;
- pos = GNUNET_CONTAINER_multipeermap_get (peers,
- pid);
- if ( (NULL != pos) &&
- (GNUNET_YES == pos->is_friend))
+ pos = GNUNET_CONTAINER_multipeermap_get (peers, pid);
+ if ((NULL != pos) && (GNUNET_YES == pos->is_friend))
return GNUNET_OK;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# peers blacklisted"),
@@ -258,17 +256,13 @@ whitelist_peers ()
* @return #GNUNET_YES (always: continue to iterate)
*/
static int
-free_peer (void *cls,
- const struct GNUNET_PeerIdentity * pid,
- void *value)
+free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
{
struct Peer *pos = value;
GNUNET_break (NULL == pos->mq);
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove (peers,
- pid,
- pos));
+ GNUNET_CONTAINER_multipeermap_remove (peers, pid, pos));
if (NULL != pos->hello_delay_task)
{
GNUNET_SCHEDULER_cancel (pos->hello_delay_task);
@@ -305,16 +299,13 @@ attempt_connect (struct Peer *pos)
{
uint32_t strength;
- if (0 ==
- GNUNET_memcmp (&my_identity,
- &pos->pid))
+ if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
return; /* This is myself, nothing to do. */
if (connection_count < target_connection_count)
strength = 1;
else
strength = 0;
- if ( (friend_count < minimum_friend_count) ||
- (GNUNET_YES == friends_only) )
+ if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only))
{
if (pos->is_friend)
strength += 10; /* urgently needed */
@@ -343,9 +334,7 @@ attempt_connect (struct Peer *pos)
gettext_noop ("# connect requests issued to
ATS"),
1,
GNUNET_NO);
- pos->sh = GNUNET_ATS_connectivity_suggest (ats,
- &pos->pid,
- strength);
+ pos->sh = GNUNET_ATS_connectivity_suggest (ats, &pos->pid, strength);
}
}
@@ -371,15 +360,14 @@ make_peer (const struct GNUNET_PeerIdentity *peer,
if (NULL != hello)
{
ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
- GNUNET_memcpy (ret->hello,
- hello,
- GNUNET_HELLO_size (hello));
+ GNUNET_memcpy (ret->hello, hello, GNUNET_HELLO_size (hello));
}
GNUNET_break (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (peers,
- peer,
- ret,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multipeermap_put (
+ peers,
+ peer,
+ ret,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return ret;
}
@@ -403,12 +391,9 @@ setup_filter (struct Peer *peer)
* any case; hence 64, 5 as bloomfilter parameters. */
peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
peer->filter_expiration =
- GNUNET_TIME_relative_to_absolute
- (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
+ GNUNET_TIME_relative_to_absolute
(HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
/* never send a peer its own HELLO */
- GNUNET_CRYPTO_hash (&peer->pid,
- sizeof (struct GNUNET_PeerIdentity),
- &hc);
+ GNUNET_CRYPTO_hash (&peer->pid, sizeof (struct GNUNET_PeerIdentity), &hc);
GNUNET_CONTAINER_bloomfilter_add (peer->filter, &hc);
}
@@ -473,10 +458,9 @@ find_advertisable_hello (void *cls,
if (hs > fah->max_size)
return GNUNET_YES;
GNUNET_CRYPTO_hash (&fah->peer->pid,
- sizeof (struct GNUNET_PeerIdentity), &hc);
- if (GNUNET_NO ==
- GNUNET_CONTAINER_bloomfilter_test (pos->filter,
- &hc))
+ sizeof (struct GNUNET_PeerIdentity),
+ &hc);
+ if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (pos->filter, &hc))
fah->result = pos;
return GNUNET_YES;
}
@@ -505,13 +489,9 @@ schedule_next_hello (void *cls)
fah.result = NULL;
fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_CONTAINER_multipeermap_iterate (peers,
- &find_advertisable_hello,
- &fah);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &find_advertisable_hello,
&fah);
pl->hello_delay_task =
- GNUNET_SCHEDULER_add_delayed (fah.next_adv,
- &schedule_next_hello,
- pl);
+ GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
if (NULL == fah.result)
return;
delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
@@ -520,31 +500,25 @@ schedule_next_hello (void *cls)
want = GNUNET_HELLO_size (fah.result->hello);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending HELLO with %u bytes",
- (unsigned int) want);
+ "Sending HELLO with %u bytes",
+ (unsigned int) want);
env = GNUNET_MQ_msg_copy (&fah.result->hello->header);
- GNUNET_MQ_send (pl->mq,
- env);
+ GNUNET_MQ_send (pl->mq, env);
/* avoid sending this one again soon */
- GNUNET_CRYPTO_hash (&pl->pid,
- sizeof (struct GNUNET_PeerIdentity),
- &hc);
- GNUNET_CONTAINER_bloomfilter_add (fah.result->filter,
- &hc);
+ GNUNET_CRYPTO_hash (&pl->pid, sizeof (struct GNUNET_PeerIdentity), &hc);
+ GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# HELLO messages gossipped"),
- 1,
- GNUNET_NO);
+ gettext_noop ("# HELLO messages gossipped"),
+ 1,
+ GNUNET_NO);
/* prepare to send the next one */
- pl->next_hello_allowed
- = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
+ pl->next_hello_allowed =
+ GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
if (NULL != pl->hello_delay_task)
GNUNET_SCHEDULER_cancel (pl->hello_delay_task);
- pl->hello_delay_task
- = GNUNET_SCHEDULER_add_now (&schedule_next_hello,
- pl);
+ pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl);
}
@@ -576,7 +550,7 @@ reschedule_hellos (void *cls,
peer->hello_delay_task = NULL;
}
peer->hello_delay_task =
- GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
+ GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer);
return GNUNET_YES;
}
@@ -592,36 +566,25 @@ reschedule_hellos (void *cls,
static void *
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_MQ_Handle *mq)
{
struct Peer *pos;
- uint64_t flags;
- const void *extra;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Core told us that we are connecting to `%s'\n",
GNUNET_i2s (peer));
- if (0 == GNUNET_memcmp (&my_identity,
- peer))
+ if (0 == GNUNET_memcmp (&my_identity, peer))
return NULL;
- extra = GNUNET_CORE_get_mq_options (GNUNET_YES,
- GNUNET_CORE_PRIO_BEST_EFFORT,
- &flags);
- GNUNET_MQ_set_options (mq,
- flags,
- extra);
+ GNUNET_MQ_set_options (mq, GNUNET_MQ_PRIO_BEST_EFFORT);
connection_count++;
GNUNET_STATISTICS_set (stats,
gettext_noop ("# peers connected"),
connection_count,
GNUNET_NO);
- pos = GNUNET_CONTAINER_multipeermap_get (peers,
- peer);
+ pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
if (NULL == pos)
{
- pos = make_peer (peer,
- NULL,
- GNUNET_NO);
+ pos = make_peer (peer, NULL, GNUNET_NO);
}
else
{
@@ -631,17 +594,14 @@ connect_notify (void *cls,
if (pos->is_friend)
{
friend_count++;
- if ( (friend_count == minimum_friend_count) &&
- (GNUNET_YES != friends_only) )
+ if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only))
whitelist_peers ();
GNUNET_STATISTICS_set (stats,
gettext_noop ("# friends connected"),
friend_count,
GNUNET_NO);
}
- reschedule_hellos (NULL,
- peer,
- pos);
+ reschedule_hellos (NULL, peer, pos);
return pos;
}
@@ -655,9 +615,7 @@ connect_notify (void *cls,
* @return #GNUNET_YES (continue to iterate)
*/
static int
-try_add_peers (void *cls,
- const struct GNUNET_PeerIdentity *pid,
- void *value)
+try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
{
struct Peer *pos = value;
@@ -676,9 +634,7 @@ add_peer_task (void *cls)
{
add_task = NULL;
- GNUNET_CONTAINER_multipeermap_iterate (peers,
- &try_add_peers,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &try_add_peers, NULL);
}
@@ -692,7 +648,7 @@ add_peer_task (void *cls)
static void
disconnect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
- void *internal_cls)
+ void *internal_cls)
{
struct Peer *pos = internal_cls;
@@ -725,16 +681,12 @@ disconnect_notify (void *cls,
friend_count,
GNUNET_NO);
}
- if ( ( (connection_count < target_connection_count) ||
- (friend_count < minimum_friend_count)) &&
- (NULL == add_task) )
- add_task = GNUNET_SCHEDULER_add_now (&add_peer_task,
- NULL);
- if ( (friend_count < minimum_friend_count) &&
- (NULL == blacklist))
- blacklist = GNUNET_TRANSPORT_blacklist (cfg,
- &blacklist_check,
- NULL);
+ if (((connection_count < target_connection_count) ||
+ (friend_count < minimum_friend_count)) &&
+ (NULL == add_task))
+ add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
+ if ((friend_count < minimum_friend_count) && (NULL == blacklist))
+ blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
}
@@ -779,38 +731,32 @@ consider_for_advertising (const struct
GNUNET_HELLO_Message *hello)
GNUNET_break (0);
return;
}
- if (0 == GNUNET_memcmp (&pid,
- &my_identity))
- return; /* that's me! */
+ if (0 == GNUNET_memcmp (&pid, &my_identity))
+ return; /* that's me! */
have_address = GNUNET_NO;
GNUNET_HELLO_iterate_addresses (hello,
GNUNET_NO,
&address_iterator,
&have_address);
if (GNUNET_NO == have_address)
- return; /* no point in advertising this one... */
+ return; /* no point in advertising this one... */
peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
if (NULL == peer)
{
- peer = make_peer (&pid,
- hello,
- GNUNET_NO);
+ peer = make_peer (&pid, hello, GNUNET_NO);
}
else if (NULL != peer->hello)
{
- dt = GNUNET_HELLO_equals (peer->hello,
- hello,
- GNUNET_TIME_absolute_get ());
+ dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ());
if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
- return; /* nothing new here */
+ return; /* nothing new here */
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Found HELLO from peer `%s' for advertising\n",
GNUNET_i2s (&pid));
if (NULL != peer->hello)
{
- nh = GNUNET_HELLO_merge (peer->hello,
- hello);
+ nh = GNUNET_HELLO_merge (peer->hello, hello);
GNUNET_free (peer->hello);
peer->hello = nh;
}
@@ -818,9 +764,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message
*hello)
{
size = GNUNET_HELLO_size (hello);
peer->hello = GNUNET_malloc (size);
- GNUNET_memcpy (peer->hello,
- hello,
- size);
+ GNUNET_memcpy (peer->hello, hello, size);
}
if (NULL != peer->filter)
{
@@ -830,9 +774,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message
*hello)
setup_filter (peer);
/* since we have a new HELLO to pick from, re-schedule all
* HELLO requests that are not bound by the HELLO send rate! */
- GNUNET_CONTAINER_multipeermap_iterate (peers,
- &reschedule_hellos,
- peer);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer);
}
@@ -856,24 +798,20 @@ process_peer (void *cls,
if (NULL != err_msg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Error in communication with PEERINFO service: %s\n"),
+ _ ("Error in communication with PEERINFO service: %s\n"),
err_msg);
GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg,
- GNUNET_NO,
- &process_peer,
- NULL);
+ peerinfo_notify =
+ GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
return;
}
GNUNET_assert (NULL != peer);
- if (0 == GNUNET_memcmp (&my_identity,
- peer))
- return; /* that's me! */
+ if (0 == GNUNET_memcmp (&my_identity, peer))
+ return; /* that's me! */
if (NULL == hello)
{
/* free existing HELLO, if any */
- pos = GNUNET_CONTAINER_multipeermap_get (peers,
- peer);
+ pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
if (NULL != pos)
{
GNUNET_free_non_null (pos->hello);
@@ -883,21 +821,15 @@ process_peer (void *cls,
GNUNET_CONTAINER_bloomfilter_free (pos->filter);
pos->filter = NULL;
}
- if ( (NULL == pos->mq) &&
- (GNUNET_NO == pos->is_friend) )
- free_peer (NULL,
- &pos->pid,
- pos);
+ if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend))
+ free_peer (NULL, &pos->pid, pos);
}
return;
}
consider_for_advertising (hello);
- pos = GNUNET_CONTAINER_multipeermap_get (peers,
- peer);
+ pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
if (NULL == pos)
- pos = make_peer (peer,
- hello,
- GNUNET_NO);
+ pos = make_peer (peer, hello, GNUNET_NO);
attempt_connect (pos);
}
@@ -910,24 +842,20 @@ process_peer (void *cls,
* @param my_id ID of this peer, NULL if we failed
*/
static void
-core_init (void *cls,
- const struct GNUNET_PeerIdentity *my_id)
+core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
{
if (NULL == my_id)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to core service, can not manage
topology!\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to connect to core service, can not manage topology!\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
my_identity = *my_id;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "I am peer `%s'\n",
- GNUNET_i2s (my_id));
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg,
- GNUNET_NO,
- &process_peer,
- NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
+ peerinfo_notify =
+ GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
}
@@ -938,24 +866,22 @@ core_init (void *cls,
* @param pid identity of the friend
*/
static void
-handle_friend (void *cls,
- const struct GNUNET_PeerIdentity *pid)
+handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid)
{
unsigned int *entries_found = cls;
struct Peer *fl;
- if (0 == GNUNET_memcmp (pid,
- &my_identity))
+ if (0 == GNUNET_memcmp (pid, &my_identity))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Found myself `%s' in friend list (useless, ignored)\n"),
+ _ ("Found myself `%s' in friend list (useless, ignored)\n"),
GNUNET_i2s (pid));
return;
}
(*entries_found)++;
fl = make_peer (pid, NULL, GNUNET_YES);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Found friend `%s' in configuration\n"),
+ _ ("Found friend `%s' in configuration\n"),
GNUNET_i2s (&fl->pid));
}
@@ -969,31 +895,30 @@ read_friends_file (const struct
GNUNET_CONFIGURATION_Handle *cfg)
unsigned int entries_found;
entries_found = 0;
- if (GNUNET_OK !=
- GNUNET_FRIENDS_parse (cfg,
- &handle_friend,
- &entries_found))
+ if (GNUNET_OK != GNUNET_FRIENDS_parse (cfg, &handle_friend, &entries_found))
{
- if ( (GNUNET_YES == friends_only) ||
- (minimum_friend_count > 0))
+ if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Encountered errors parsing friends list!\n"));
+ _ ("Encountered errors parsing friends list!\n"));
}
GNUNET_STATISTICS_update (stats,
gettext_noop ("# friends in configuration"),
entries_found,
GNUNET_NO);
- if ( (minimum_friend_count > entries_found) &&
- (GNUNET_NO == friends_only) )
+ if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Fewer friends specified than required by minimum friend
count. Will only connect to friends.\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Fewer friends specified than required by minimum friend count. Will
only connect to friends.\n"));
}
- if ( (minimum_friend_count > target_connection_count) &&
- (GNUNET_NO == friends_only))
+ if ((minimum_friend_count > target_connection_count) &&
+ (GNUNET_NO == friends_only))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("More friendly connections required than target total number
of connections.\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "More friendly connections required than target total number of
connections.\n"));
}
}
@@ -1008,14 +933,11 @@ read_friends_file (const struct
GNUNET_CONFIGURATION_Handle *cfg)
* #GNUNET_SYSERR if @a message is invalid
*/
static int
-check_hello (void *cls,
- const struct GNUNET_HELLO_Message *message)
+check_hello (void *cls, const struct GNUNET_HELLO_Message *message)
{
struct GNUNET_PeerIdentity pid;
- if (GNUNET_OK !=
- GNUNET_HELLO_get_id (message,
- &pid))
+ if (GNUNET_OK != GNUNET_HELLO_get_id (message, &pid))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1032,8 +954,7 @@ check_hello (void *cls,
* @param message the actual HELLO message
*/
static void
-handle_hello (void *cls,
- const struct GNUNET_HELLO_Message *message)
+handle_hello (void *cls, const struct GNUNET_HELLO_Message *message)
{
const struct GNUNET_PeerIdentity *other = cls;
struct Peer *peer;
@@ -1042,34 +963,26 @@ handle_hello (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received encrypted HELLO from peer `%s'",
GNUNET_i2s (other));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id (message,
- &pid));
+ GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (message, &pid));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# HELLO messages received"),
1,
GNUNET_NO);
- peer = GNUNET_CONTAINER_multipeermap_get (peers,
- &pid);
+ peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid);
if (NULL == peer)
{
- if ( (GNUNET_YES == friends_only) ||
- (friend_count < minimum_friend_count) )
+ if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
return;
}
else
{
- if ( (GNUNET_YES != peer->is_friend) &&
- (GNUNET_YES == friends_only) )
+ if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
return;
if ((GNUNET_YES != peer->is_friend) &&
(friend_count < minimum_friend_count))
return;
}
- (void) GNUNET_PEERINFO_add_peer (pi,
- message,
- NULL,
- NULL);
+ (void) GNUNET_PEERINFO_add_peer (pi, message, NULL, NULL);
}
@@ -1103,9 +1016,7 @@ cleaning_task (void *cls)
GNUNET_TRANSPORT_offer_hello_cancel (oh);
oh = NULL;
}
- GNUNET_CONTAINER_multipeermap_iterate (peers,
- &free_peer,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (peers, &free_peer, NULL);
GNUNET_CONTAINER_multipeermap_destroy (peers);
peers = NULL;
if (NULL != ats)
@@ -1140,26 +1051,22 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_var_size (hello,
- GNUNET_MESSAGE_TYPE_HELLO,
- struct GNUNET_HELLO_Message,
- NULL),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_var_size (hello,
+ GNUNET_MESSAGE_TYPE_HELLO,
+ struct GNUNET_HELLO_Message,
+ NULL),
+ GNUNET_MQ_handler_end ()};
unsigned long long opt;
cfg = c;
stats = GNUNET_STATISTICS_create ("topology", cfg);
friends_only =
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- "TOPOLOGY",
- "FRIENDS-ONLY");
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "TOPOLOGY",
- "MINIMUM-FRIENDS",
- &opt))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY");
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "TOPOLOGY",
+ "MINIMUM-FRIENDS",
+ &opt))
opt = 0;
minimum_friend_count = (unsigned int) opt;
if (GNUNET_OK !=
@@ -1176,25 +1083,21 @@ run (void *cls,
"Topology would like %u connections with at least %u friends\n",
target_connection_count,
minimum_friend_count);
- if ( (GNUNET_YES == friends_only) ||
- (minimum_friend_count > 0))
- blacklist = GNUNET_TRANSPORT_blacklist (cfg,
- &blacklist_check,
- NULL);
+ if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
+ blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL);
ats = GNUNET_ATS_connectivity_init (cfg);
pi = GNUNET_PEERINFO_connect (cfg);
handle = GNUNET_CORE_connect (cfg,
- NULL,
- &core_init,
- &connect_notify,
- &disconnect_notify,
- handlers);
- GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
- NULL);
+ NULL,
+ &core_init,
+ &connect_notify,
+ &disconnect_notify,
+ handlers);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
if (NULL == handle)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to connect to `%s' service.\n"),
+ _ ("Failed to connect to `%s' service.\n"),
"core");
GNUNET_SCHEDULER_shutdown ();
return;
@@ -1210,24 +1113,25 @@ run (void *cls,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
int ret;
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret =
- (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-daemon-topology",
- _("GNUnet topology control"),
- options, &run, NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-daemon-topology",
+ _ ("GNUnet topology control"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}
@@ -1238,8 +1142,7 @@ main (int argc,
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((constructor))
-GNUNET_ARM_memory_init ()
+void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
{
mallopt (M_TRIM_THRESHOLD, 4 * 1024);
mallopt (M_TOP_PAD, 1 * 1024);
diff --git a/src/transport/gnunet-service-tng.c
b/src/transport/gnunet-service-tng.c
index 95ea102df..b217c8aa9 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -3743,10 +3743,13 @@ handle_client_send (void *cls, const struct
OutboundMessage *obm)
size_t payload_size;
struct TransportDVBoxMessage *dvb;
struct VirtualLink *vl;
+ enum GNUNET_MQ_PriorityPreferences pp;
GNUNET_assert (CT_CORE == tc->type);
obmm = (const struct GNUNET_MessageHeader *) &obm[1];
bytes_msg = ntohs (obmm->size);
+ pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority);
+ /* FIXME: actually make use of pp */ (void) pp;
vl = GNUNET_CONTAINER_multipeermap_get (links, &obm->peer);
if (NULL == vl)
{
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 4ba628112..7fe869fa8 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -302,9 +302,9 @@ struct OutboundMessage
struct GNUNET_MessageHeader header;
/**
- * Always zero.
+ * An `enum GNUNET_MQ_PriorityPreferences` in NBO.
*/
- uint32_t reserved GNUNET_PACKED;
+ uint32_t priority GNUNET_PACKED;
#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
defined(GNUNET_TRANSPORT_CORE_VERSION))
diff --git a/src/transport/transport_api2_core.c
b/src/transport/transport_api2_core.c
index a3c49e94f..20bbf2994 100644
--- a/src/transport/transport_api2_core.c
+++ b/src/transport/transport_api2_core.c
@@ -329,7 +329,12 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
n->env =
GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
n->env_size = ntohs (msg->size);
- obm->reserved = htonl (0);
+ {
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_get_current_envelope (mq);
+ obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
+ }
obm->peer = n->id;
if (0 == n->ready_window)
{
diff --git a/src/transport/transport_api_core.c
b/src/transport/transport_api_core.c
index a163d7ccf..54dc7f4c3 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -418,7 +418,12 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
GNUNET_assert (NULL == n->env);
n->env =
GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
- obm->reserved = htonl (0);
+ {
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_get_current_envelope (mq);
+ obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
+ }
obm->timeout = GNUNET_TIME_relative_hton (
GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
obm->peer = n->id;
diff --git a/src/util/mq.c b/src/util/mq.c
index 513c008ee..2f9e650b6 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -26,7 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "util-mq",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-mq", __VA_ARGS__)
struct GNUNET_MQ_Envelope
@@ -70,14 +70,7 @@ struct GNUNET_MQ_Envelope
* #GNUNET_MQ_env_set_options(). Only valid if
* @e have_custom_options is set.
*/
- uint64_t flags;
-
- /**
- * Additional options buffer set for this envelope by
- * #GNUNET_MQ_env_set_options(). Only valid if
- * @e have_custom_options is set.
- */
- const void *extra;
+ enum GNUNET_MQ_PriorityPreferences priority;
/**
* Did the application call #GNUNET_MQ_env_set_options()?
@@ -164,17 +157,11 @@ struct GNUNET_MQ_Handle
*/
struct GNUNET_MQ_DestroyNotificationHandle *dnh_tail;
- /**
- * Additional options buffer set for this queue by
- * #GNUNET_MQ_set_options(). Default is 0.
- */
- const void *default_extra;
-
/**
* Flags that were set for this queue by
* #GNUNET_MQ_set_options(). Default is 0.
*/
- uint64_t default_flags;
+ enum GNUNET_MQ_PriorityPreferences priority;
/**
* Next id that should be used for the @e assoc_map,
@@ -217,12 +204,10 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
{
int ret;
- ret = GNUNET_MQ_handle_message (mq->handlers,
- mh);
+ ret = GNUNET_MQ_handle_message (mq->handlers, mh);
if (GNUNET_SYSERR == ret)
{
- GNUNET_MQ_inject_error (mq,
- GNUNET_MQ_ERROR_MALFORMED);
+ GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_MALFORMED);
return;
}
}
@@ -251,7 +236,8 @@ GNUNET_MQ_handle_message (const struct
GNUNET_MQ_MessageHandler *handlers,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received message of type %u and size %u\n",
- mtype, msize);
+ mtype,
+ msize);
if (NULL == handlers)
goto done;
@@ -260,41 +246,40 @@ GNUNET_MQ_handle_message (const struct
GNUNET_MQ_MessageHandler *handlers,
if (handler->type == mtype)
{
handled = GNUNET_YES;
- if ( (handler->expected_size > msize) ||
- ( (handler->expected_size != msize) &&
- (NULL == handler->mv) ) )
+ if ((handler->expected_size > msize) ||
+ ((handler->expected_size != msize) && (NULL == handler->mv)))
{
- /* Too small, or not an exact size and
+ /* Too small, or not an exact size and
no 'mv' handler to check rest */
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received malformed message of type %u\n",
(unsigned int) handler->type);
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
- if ( (NULL == handler->mv) ||
- (GNUNET_OK ==
- handler->mv (handler->cls, mh)) )
+ if ((NULL == handler->mv) ||
+ (GNUNET_OK == handler->mv (handler->cls, mh)))
{
- /* message well-formed, pass to handler */
- handler->cb (handler->cls, mh);
+ /* message well-formed, pass to handler */
+ handler->cb (handler->cls, mh);
}
else
{
- /* Message rejected by check routine */
+ /* Message rejected by check routine */
LOG (GNUNET_ERROR_TYPE_ERROR,
"Received malformed message of type %u\n",
(unsigned int) handler->type);
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
}
break;
}
}
- done:
+done:
if (GNUNET_NO == handled)
{
LOG (GNUNET_ERROR_TYPE_INFO,
"No handler for message of type %u and size %u\n",
- mtype, msize);
+ mtype,
+ msize);
return GNUNET_NO;
}
return GNUNET_OK;
@@ -312,8 +297,7 @@ GNUNET_MQ_handle_message (const struct
GNUNET_MQ_MessageHandler *handlers,
* @param error the error type
*/
void
-GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
- enum GNUNET_MQ_Error error)
+GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error
error)
{
if (NULL == mq->error_handler)
{
@@ -322,8 +306,7 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
(int) error);
return;
}
- mq->error_handler (mq->error_handler_cls,
- error);
+ mq->error_handler (mq->error_handler_cls, error);
}
@@ -367,8 +350,7 @@ GNUNET_MQ_get_length (struct GNUNET_MQ_Handle *mq)
* @param ev the envelope with the message to send.
*/
void
-GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
- struct GNUNET_MQ_Envelope *ev)
+GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
{
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL == ev->parent_queue);
@@ -378,18 +360,15 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
{
/* This would seem like a bug... */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "MQ with %u entries extended by message of type %u (FC
broken?)\n",
- (unsigned int) mq->queue_length,
- (unsigned int) ntohs (ev->mh->type));
+ "MQ with %u entries extended by message of type %u (FC
broken?)\n",
+ (unsigned int) mq->queue_length,
+ (unsigned int) ntohs (ev->mh->type));
}
ev->parent_queue = mq;
/* is the implementation busy? queue it! */
- if ( (NULL != mq->current_envelope) ||
- (NULL != mq->send_task) )
+ if ((NULL != mq->current_envelope) || (NULL != mq->send_task))
{
- GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head,
- mq->envelope_tail,
- ev);
+ GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, mq->envelope_tail,
ev);
return;
}
GNUNET_assert (NULL == mq->envelope_head);
@@ -397,12 +376,10 @@ GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"sending message of type %u, queue empty (MQ: %p)\n",
- ntohs(ev->mh->type),
+ ntohs (ev->mh->type),
mq);
- mq->send_impl (mq,
- ev->mh,
- mq->impl_state);
+ mq->send_impl (mq, ev->mh, mq->impl_state);
}
@@ -419,9 +396,7 @@ GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq)
struct GNUNET_MQ_Envelope *env;
env = mq->envelope_head;
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
- mq->envelope_tail,
- env);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, env);
mq->queue_length--;
env->parent_queue = NULL;
return env;
@@ -461,16 +436,12 @@ GNUNET_MQ_send_copy (struct GNUNET_MQ_Handle *mq,
uint16_t msize;
msize = ntohs (ev->mh->size);
- env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) +
- msize);
+ env = GNUNET_malloc (sizeof (struct GNUNET_MQ_Envelope) + msize);
env->mh = (struct GNUNET_MessageHeader *) &env[1];
env->sent_cb = ev->sent_cb;
env->sent_cls = ev->sent_cls;
- GNUNET_memcpy (&env[1],
- ev->mh,
- msize);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_memcpy (&env[1], ev->mh, msize);
+ GNUNET_MQ_send (mq, env);
}
@@ -493,16 +464,14 @@ impl_send_continue (void *cls)
return;
mq->current_envelope = mq->envelope_head;
GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
- mq->envelope_tail,
- mq->current_envelope);
+ mq->envelope_tail,
+ mq->current_envelope);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"sending message of type %u from queue\n",
- ntohs(mq->current_envelope->mh->type));
+ ntohs (mq->current_envelope->mh->type));
- mq->send_impl (mq,
- mq->current_envelope->mh,
- mq->impl_state);
+ mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
}
@@ -526,8 +495,7 @@ GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
current_envelope->parent_queue = NULL;
mq->current_envelope = NULL;
GNUNET_assert (NULL == mq->send_task);
- mq->send_task = GNUNET_SCHEDULER_add_now (&impl_send_continue,
- mq);
+ mq->send_task = GNUNET_SCHEDULER_add_now (&impl_send_continue, mq);
if (NULL != (cb = current_envelope->sent_cb))
{
current_envelope->sent_cb = NULL;
@@ -612,12 +580,11 @@ GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
* @param handlers_cls new closure to use
*/
void
-GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq,
- void *handlers_cls)
+GNUNET_MQ_set_handlers_closure (struct GNUNET_MQ_Handle *mq, void
*handlers_cls)
{
if (NULL == mq->handlers)
return;
- for (unsigned int i=0;NULL != mq->handlers[i].cb; i++)
+ for (unsigned int i = 0; NULL != mq->handlers[i].cb; i++)
mq->handlers[i].cls = handlers_cls;
}
@@ -662,9 +629,7 @@ GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq)
struct GNUNET_MQ_Envelope *
-GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
- uint16_t size,
- uint16_t type)
+GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t
type)
{
struct GNUNET_MQ_Envelope *ev;
@@ -692,9 +657,7 @@ GNUNET_MQ_msg_copy (const struct GNUNET_MessageHeader *hdr)
mqm = GNUNET_malloc (sizeof (*mqm) + size);
mqm->mh = (struct GNUNET_MessageHeader *) &mqm[1];
- GNUNET_memcpy (mqm->mh,
- hdr,
- size);
+ GNUNET_memcpy (mqm->mh, hdr, size);
return mqm;
}
@@ -728,8 +691,8 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
mqm = GNUNET_MQ_msg_ (mhp, size, type);
GNUNET_memcpy ((char *) mqm->mh + base_size,
- nested_mh,
- ntohs (nested_mh->size));
+ nested_mh,
+ ntohs (nested_mh->size));
return mqm;
}
@@ -742,8 +705,7 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
* @param assoc_data to associate
*/
uint32_t
-GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
- void *assoc_data)
+GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq, void *assoc_data)
{
uint32_t id;
@@ -754,10 +716,11 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
}
id = mq->assoc_id++;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap32_put (mq->assoc_map,
- id,
- assoc_data,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multihashmap32_put (
+ mq->assoc_map,
+ id,
+ assoc_data,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return id;
}
@@ -770,13 +733,11 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
- uint32_t request_id)
+GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
{
if (NULL == mq->assoc_map)
return NULL;
- return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
- request_id);
+ return GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
}
@@ -788,17 +749,14 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
* @return the associated data
*/
void *
-GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
- uint32_t request_id)
+GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
{
void *val;
if (NULL == mq->assoc_map)
return NULL;
- val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
- request_id);
- GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map,
- request_id);
+ val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
+ GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id);
return val;
}
@@ -818,8 +776,7 @@ GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
void *cb_cls)
{
/* allow setting *OR* clearing callback */
- GNUNET_assert ( (NULL == ev->sent_cb) ||
- (NULL == cb) );
+ GNUNET_assert ((NULL == ev->sent_cb) || (NULL == cb));
ev->sent_cb = cb;
ev->sent_cls = cb_cls;
}
@@ -883,9 +840,7 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
ev = mq->envelope_head;
ev->parent_queue = NULL;
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
- mq->envelope_tail,
- ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
GNUNET_assert (0 < mq->queue_length);
mq->queue_length--;
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -974,8 +929,7 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
GNUNET_assert (GNUNET_NO == mq->in_flight);
GNUNET_assert (0 < mq->queue_length);
mq->queue_length--;
- mq->cancel_impl (mq,
- mq->impl_state);
+ mq->cancel_impl (mq, mq->impl_state);
/* continue sending the next message, if any */
mq->current_envelope = mq->envelope_head;
if (NULL != mq->current_envelope)
@@ -986,19 +940,15 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"sending canceled message of type %u queue\n",
- ntohs(ev->mh->type));
+ ntohs (ev->mh->type));
- mq->send_impl (mq,
- mq->current_envelope->mh,
- mq->impl_state);
+ mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
}
}
else
{
/* simple case, message is still waiting in the queue */
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
- mq->envelope_tail,
- ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
GNUNET_assert (0 < mq->queue_length);
mq->queue_length--;
}
@@ -1044,21 +994,18 @@ GNUNET_MQ_get_last_envelope (struct GNUNET_MQ_Handle *mq)
/**
- * Set application-specific options for this envelope.
+ * Set application-specific preferences for this envelope.
* Overrides the options set for the queue with
* #GNUNET_MQ_set_options() for this message only.
*
* @param env message to set options for
- * @param flags flags to use (meaning is queue-specific)
- * @param extra additional buffer for further data (also queue-specific)
+ * @param pp priorities and preferences to apply
*/
void
GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope *env,
- uint64_t flags,
- const void *extra)
+ enum GNUNET_MQ_PriorityPreferences pp)
{
- env->flags = flags;
- env->extra = extra;
+ env->priority = pp;
env->have_custom_options = GNUNET_YES;
}
@@ -1067,44 +1014,57 @@ GNUNET_MQ_env_set_options (struct GNUNET_MQ_Envelope
*env,
* Get application-specific options for this envelope.
*
* @param env message to set options for
- * @param[out] flags set to flags to use (meaning is queue-specific)
- * @return extra additional buffer for further data (also queue-specific)
+ * @return priorities and preferences to apply for @a env
*/
-const void *
-GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env,
- uint64_t *flags)
+enum GNUNET_MQ_PriorityPreferences
+GNUNET_MQ_env_get_options (struct GNUNET_MQ_Envelope *env)
{
struct GNUNET_MQ_Handle *mq = env->parent_queue;
if (GNUNET_YES == env->have_custom_options)
- {
- *flags = env->flags;
- return env->extra;
- }
+ return env->priority;
if (NULL == mq)
- {
- *flags = 0;
- return NULL;
- }
- *flags = mq->default_flags;
- return mq->default_extra;
+ return 0;
+ return mq->priority;
+}
+
+
+/**
+ * Combine performance preferences set for different
+ * envelopes that are being combined into one larger envelope.
+ *
+ * @param p1 one set of preferences
+ * @param p2 second set of preferences
+ * @return combined priority and preferences to use
+ */
+enum GNUNET_MQ_PriorityPreferences
+GNUNET_MQ_env_combine_options (enum GNUNET_MQ_PriorityPreferences p1,
+ enum GNUNET_MQ_PriorityPreferences p2)
+{
+ enum GNUNET_MQ_PriorityPreferences ret;
+
+ ret = GNUNET_MAX (p1 & GNUNET_MQ_PRIORITY_MASK, p2 &
GNUNET_MQ_PRIORITY_MASK);
+ ret |= ((p1 & GNUNET_MQ_PREF_UNRELIABLE) & (p2 & GNUNET_MQ_PREF_UNRELIABLE));
+ ret |=
+ ((p1 & GNUNET_MQ_PREF_LOW_LATENCY) | (p2 & GNUNET_MQ_PREF_LOW_LATENCY));
+ ret |=
+ ((p1 & GNUNET_MQ_PREF_CORK_ALLOWED) & (p2 & GNUNET_MQ_PREF_CORK_ALLOWED));
+ ret |= ((p1 & GNUNET_MQ_PREF_GOODPUT) & (p2 & GNUNET_MQ_PREF_GOODPUT));
+ return ret;
}
/**
- * Set application-specific options for this queue.
+ * Set application-specific default options for this queue.
*
* @param mq message queue to set options for
- * @param flags flags to use (meaning is queue-specific)
- * @param extra additional buffer for further data (also queue-specific)
+ * @param pp priorities and preferences to apply
*/
void
GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq,
- uint64_t flags,
- const void *extra)
+ enum GNUNET_MQ_PriorityPreferences pp)
{
- mq->default_flags = flags;
- mq->default_extra = extra;
+ mq->priority = pp;
}
@@ -1145,8 +1105,8 @@ GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env)
*/
struct GNUNET_MQ_DestroyNotificationHandle *
GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
- GNUNET_SCHEDULER_TaskCallback cb,
- void *cb_cls)
+ GNUNET_SCHEDULER_TaskCallback cb,
+ void *cb_cls)
{
struct GNUNET_MQ_DestroyNotificationHandle *dnh;
@@ -1154,9 +1114,7 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
dnh->mq = mq;
dnh->cb = cb;
dnh->cb_cls = cb_cls;
- GNUNET_CONTAINER_DLL_insert (mq->dnh_head,
- mq->dnh_tail,
- dnh);
+ GNUNET_CONTAINER_DLL_insert (mq->dnh_head, mq->dnh_tail, dnh);
return dnh;
}
@@ -1167,13 +1125,12 @@ GNUNET_MQ_destroy_notify (struct GNUNET_MQ_Handle *mq,
* @param dnh handle for registration to cancel
*/
void
-GNUNET_MQ_destroy_notify_cancel (struct GNUNET_MQ_DestroyNotificationHandle
*dnh)
+GNUNET_MQ_destroy_notify_cancel (
+ struct GNUNET_MQ_DestroyNotificationHandle *dnh)
{
struct GNUNET_MQ_Handle *mq = dnh->mq;
- GNUNET_CONTAINER_DLL_remove (mq->dnh_head,
- mq->dnh_tail,
- dnh);
+ GNUNET_CONTAINER_DLL_remove (mq->dnh_head, mq->dnh_tail, dnh);
GNUNET_free (dnh);
}
@@ -1195,9 +1152,7 @@ GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope
**env_head,
struct GNUNET_MQ_Envelope **env_tail,
struct GNUNET_MQ_Envelope *env)
{
- GNUNET_CONTAINER_DLL_insert_tail (*env_head,
- *env_tail,
- env);
+ GNUNET_CONTAINER_DLL_insert_tail (*env_head, *env_tail, env);
}
@@ -1218,9 +1173,7 @@ GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope
**env_head,
struct GNUNET_MQ_Envelope **env_tail,
struct GNUNET_MQ_Envelope *env)
{
- GNUNET_CONTAINER_DLL_remove (*env_head,
- *env_tail,
- env);
+ GNUNET_CONTAINER_DLL_remove (*env_head, *env_tail, env);
}
@@ -1244,8 +1197,7 @@ GNUNET_MQ_copy_handlers (const struct
GNUNET_MQ_MessageHandler *handlers)
return NULL;
count = GNUNET_MQ_count_handlers (handlers);
- copy = GNUNET_new_array (count + 1,
- struct GNUNET_MQ_MessageHandler);
+ copy = GNUNET_new_array (count + 1, struct GNUNET_MQ_MessageHandler);
GNUNET_memcpy (copy,
handlers,
count * sizeof (struct GNUNET_MQ_MessageHandler));
@@ -1276,8 +1228,7 @@ GNUNET_MQ_copy_handlers2 (const struct
GNUNET_MQ_MessageHandler *handlers,
if (NULL == handlers)
return NULL;
count = GNUNET_MQ_count_handlers (handlers);
- copy = GNUNET_new_array (count + 2,
- struct GNUNET_MQ_MessageHandler);
+ copy = GNUNET_new_array (count + 2, struct GNUNET_MQ_MessageHandler);
GNUNET_memcpy (copy,
handlers,
count * sizeof (struct GNUNET_MQ_MessageHandler));
@@ -1304,7 +1255,8 @@ GNUNET_MQ_count_handlers (const struct
GNUNET_MQ_MessageHandler *handlers)
if (NULL == handlers)
return 0;
- for (i=0; NULL != handlers[i].cb; i++) ;
+ for (i = 0; NULL != handlers[i].cb; i++)
+ ;
return i;
}
@@ -1319,7 +1271,8 @@ GNUNET_MQ_count_handlers (const struct
GNUNET_MQ_MessageHandler *handlers)
const char *
GNUNET_MQ_preference_to_string (enum GNUNET_MQ_PreferenceKind type)
{
- switch (type) {
+ switch (type)
+ {
case GNUNET_MQ_PREFERENCE_NONE:
return "NONE";
case GNUNET_MQ_PREFERENCE_BANDWIDTH:
--
To stop receiving notification emails like this one, please contact
address@hidden