aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-30 22:27:18 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-30 22:27:18 +0000
commitc4f4203aaff577fdbe60a7a0976e913dbb77f03e (patch)
tree2fca5cb9cdc7b8c8d046c81453313c275d7dd5cd /src/core
parente9dbabbabb9edd41bb7d7cb907826abdd8edb257 (diff)
downloadgnunet-c4f4203aaff577fdbe60a7a0976e913dbb77f03e.tar.gz
gnunet-c4f4203aaff577fdbe60a7a0976e913dbb77f03e.zip
enable setting per-envelope or per-queue transmission options with MQ API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_api_2.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/core/core_api_2.c b/src/core/core_api_2.c
index d45c98e93..70dd1e0f0 100644
--- a/src/core/core_api_2.c
+++ b/src/core/core_api_2.c
@@ -257,6 +257,26 @@ handle_mq_error (void *cls,
257 257
258 258
259/** 259/**
260 * Inquire with CORE what options should be set for a message
261 * so that it is transmitted with the given @a priority and
262 * the given @a cork value.
263 *
264 * @param cork desired corking
265 * @param priority desired message priority
266 * @param[out] flags set to `flags` value for #GNUNET_MQ_set_options()
267 * @return `extra` argument to give to #GNUNET_MQ_set_options()
268 */
269const void *
270GNUNET_CORE_get_mq_options (int cork,
271 enum GNUNET_CORE_Priority priority,
272 uint64_t *flags)
273{
274 *flags = ((uint64_t) priority) + (((uint64_t) cork) << 32);
275 return NULL;
276}
277
278
279/**
260 * Implement sending functionality of a message queue for 280 * Implement sending functionality of a message queue for
261 * us sending messages to a peer. 281 * us sending messages to a peer.
262 * 282 *
@@ -275,12 +295,20 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
275 struct SendMessage *sm; 295 struct SendMessage *sm;
276 struct GNUNET_MQ_Envelope *env; 296 struct GNUNET_MQ_Envelope *env;
277 uint16_t msize; 297 uint16_t msize;
278 int cork 298 uint64_t flags;
279 = GNUNET_NO; // FIXME 299 int cork;
280 enum GNUNET_CORE_Priority priority 300 enum GNUNET_CORE_Priority priority;
281 = GNUNET_CORE_PRIO_BEST_EFFORT; // FIXME
282 301
283 GNUNET_assert (NULL == pr->env); 302 GNUNET_assert (NULL == pr->env);
303 /* extract options from envelope */
304 env = GNUNET_MQ_get_current_envelope (mq);
305 GNUNET_break (NULL ==
306 GNUNET_MQ_env_get_options (env,
307 &flags));
308 cork = (int) (flags >> 32);
309 priority = (uint32_t) flags;
310
311 /* check message size for sanity */
284 msize = ntohs (msg->size); 312 msize = ntohs (msg->size);
285 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct SendMessage)) 313 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct SendMessage))
286 { 314 {
@@ -288,6 +316,8 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
288 GNUNET_MQ_impl_send_continue (mq); 316 GNUNET_MQ_impl_send_continue (mq);
289 return; 317 return;
290 } 318 }
319
320 /* ask core for transmission */
291 LOG (GNUNET_ERROR_TYPE_DEBUG, 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
292 "Asking core for transmission of %u bytes to `%s'\n", 322 "Asking core for transmission of %u bytes to `%s'\n",
293 (unsigned int) msize, 323 (unsigned int) msize,
@@ -302,6 +332,8 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
302 smr->smr_id = htons (++pr->smr_id_gen); 332 smr->smr_id = htons (++pr->smr_id_gen);
303 GNUNET_MQ_send (h->mq, 333 GNUNET_MQ_send (h->mq,
304 env); 334 env);
335
336 /* prepare message with actual transmission data */
305 pr->env = GNUNET_MQ_msg_nested_mh (sm, 337 pr->env = GNUNET_MQ_msg_nested_mh (sm,
306 GNUNET_MESSAGE_TYPE_CORE_SEND, 338 GNUNET_MESSAGE_TYPE_CORE_SEND,
307 msg); 339 msg);
@@ -385,6 +417,8 @@ connect_peer (struct GNUNET_CORE_Handle *h,
385 const struct GNUNET_PeerIdentity *peer) 417 const struct GNUNET_PeerIdentity *peer)
386{ 418{
387 struct PeerRecord *pr; 419 struct PeerRecord *pr;
420 uint64_t flags;
421 const void *extra;
388 422
389 pr = GNUNET_new (struct PeerRecord); 423 pr = GNUNET_new (struct PeerRecord);
390 pr->peer = *peer; 424 pr->peer = *peer;
@@ -401,6 +435,13 @@ connect_peer (struct GNUNET_CORE_Handle *h,
401 h->handlers, 435 h->handlers,
402 &core_mq_error_handler, 436 &core_mq_error_handler,
403 pr); 437 pr);
438 /* get our default options */
439 extra = GNUNET_CORE_get_mq_options (GNUNET_NO,
440 GNUNET_CORE_PRIO_BEST_EFFORT,
441 &flags);
442 GNUNET_MQ_set_options (pr->mq,
443 flags,
444 extra);
404 if (NULL != h->connects) 445 if (NULL != h->connects)
405 { 446 {
406 pr->client_cls = h->connects (h->cls, 447 pr->client_cls = h->connects (h->cls,