gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit d6845922193d63e28d743ab77d843af9023d8a14
parent b544508d067006323c6f51d84adfaf8adbcd4ee8
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue,  4 Jun 2019 14:10:57 +0200

use macro

Diffstat:
Msrc/transport/transport_api2_communication.c | 395++++++++++++++++++++++++++++++++-----------------------------------------------
Msrc/transport/transport_api2_monitor.c | 72++++++++++++++++++++++++------------------------------------------------
2 files changed, 184 insertions(+), 283 deletions(-)

diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c @@ -222,7 +222,6 @@ struct GNUNET_TRANSPORT_CommunicatorHandle * Characteristics of the communicator. */ enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; - }; @@ -282,7 +281,6 @@ struct GNUNET_TRANSPORT_QueueHandle * Maximum transmission unit for the queue. */ uint32_t mtu; - }; @@ -329,7 +327,6 @@ struct GNUNET_TRANSPORT_AddressIdentifier * Network type for the address. */ enum GNUNET_NetworkType nt; - }; @@ -357,15 +354,12 @@ send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) if (NULL == ai->ch->mq) return; env = GNUNET_MQ_msg_extra (aam, - strlen (ai->address) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); + strlen (ai->address) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); aam->expiration = GNUNET_TIME_relative_hton (ai->expiration); aam->nt = htonl ((uint32_t) ai->nt); - memcpy (&aam[1], - ai->address, - strlen (ai->address) + 1); - GNUNET_MQ_send (ai->ch->mq, - env); + memcpy (&aam[1], ai->address, strlen (ai->address) + 1); + GNUNET_MQ_send (ai->ch->mq, env); } @@ -383,11 +377,9 @@ send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) if (NULL == ai->ch->mq) return; - env = GNUNET_MQ_msg (dam, - GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); + env = GNUNET_MQ_msg (dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); dam->aid = htonl (ai->aid); - GNUNET_MQ_send (ai->ch->mq, - env); + GNUNET_MQ_send (ai->ch->mq, env); } @@ -406,18 +398,15 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) if (NULL == qh->ch->mq) return; env = GNUNET_MQ_msg_extra (aqm, - strlen (qh->address) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); + strlen (qh->address) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); aqm->qid = htonl (qh->queue_id); aqm->receiver = qh->peer; aqm->nt = htonl ((uint32_t) qh->nt); aqm->mtu = htonl (qh->mtu); aqm->cs = htonl ((uint32_t) qh->cs); - memcpy (&aqm[1], - qh->address, - strlen (qh->address) + 1); - GNUNET_MQ_send (qh->ch->mq, - env); + memcpy (&aqm[1], qh->address, strlen (qh->address) + 1); + GNUNET_MQ_send (qh->ch->mq, env); } @@ -435,12 +424,10 @@ send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) if (NULL == qh->ch->mq) return; - env = GNUNET_MQ_msg (dqm, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); + env = GNUNET_MQ_msg (dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); dqm->qid = htonl (qh->queue_id); dqm->receiver = qh->peer; - GNUNET_MQ_send (qh->ch->mq, - env); + GNUNET_MQ_send (qh->ch->mq, env); } @@ -458,26 +445,17 @@ disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) struct FlowControl *fcn; struct AckPending *apn; - for (struct FlowControl *fc = ch->fc_head; - NULL != fc; - fc = fcn) + for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn) { fcn = fc->next; - GNUNET_CONTAINER_DLL_remove (ch->fc_head, - ch->fc_tail, - fc); - fc->cb (fc->cb_cls, - GNUNET_SYSERR); + GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); + fc->cb (fc->cb_cls, GNUNET_SYSERR); GNUNET_free (fc); } - for (struct AckPending *ap = ch->ap_head; - NULL != ap; - ap = apn) + for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn) { apn = ap->next; - GNUNET_CONTAINER_DLL_remove (ch->ap_head, - ch->ap_tail, - ap); + GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); GNUNET_free (ap); } if (NULL == ch->mq) @@ -491,14 +469,13 @@ disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) * Function called on MQ errors. */ static void -error_handler (void *cls, - enum GNUNET_MQ_Error error) +error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "MQ failure %d, reconnecting to transport service.\n", - error); + "MQ failure %d, reconnecting to transport service.\n", + error); disconnect (ch); /* TODO: maybe do this with exponential backoff/delay */ reconnect (ch); @@ -513,25 +490,21 @@ error_handler (void *cls, * @param incoming_ack the ack */ static void -handle_incoming_ack (void *cls, - const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) +handle_incoming_ack ( + void *cls, + const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; - for (struct FlowControl *fc = ch->fc_head; - NULL != fc; - fc = fc->next) + for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next) { - if ( (fc->id == incoming_ack->fc_id) && - (0 == memcmp (&fc->sender, - &incoming_ack->sender, - sizeof (struct GNUNET_PeerIdentity))) ) + if ((fc->id == incoming_ack->fc_id) && + (0 == memcmp (&fc->sender, + &incoming_ack->sender, + sizeof (struct GNUNET_PeerIdentity)))) { - GNUNET_CONTAINER_DLL_remove (ch->fc_head, - ch->fc_tail, - fc); - fc->cb (fc->cb_cls, - GNUNET_OK); + GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); + fc->cb (fc->cb_cls, GNUNET_OK); GNUNET_free (fc); return; } @@ -552,19 +525,10 @@ handle_incoming_ack (void *cls, * @return #GNUNET_OK if @a smt is well-formed */ static int -check_create_queue (void *cls, - const struct GNUNET_TRANSPORT_CreateQueue *cq) +check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) { - uint16_t len = ntohs (cq->header.size) - sizeof (*cq); - const char *addr = (const char *) &cq[1]; - (void) cls; - if ( (0 == len) || - ('\0' != addr[len-1]) ) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + GNUNET_MQ_check_zero_termination (cq); return GNUNET_OK; } @@ -576,33 +540,26 @@ check_create_queue (void *cls, * @param cq the queue creation request */ static void -handle_create_queue (void *cls, - const struct GNUNET_TRANSPORT_CreateQueue *cq) +handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; const char *addr = (const char *) &cq[1]; struct GNUNET_TRANSPORT_CreateQueueResponse *cqr; struct GNUNET_MQ_Envelope *env; - if (GNUNET_OK != - ch->mq_init (ch->mq_init_cls, - &cq->receiver, - addr)) + if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Address `%s' invalid for this communicator\n", - addr); - env = GNUNET_MQ_msg (cqr, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); + "Address `%s' invalid for this communicator\n", + addr); + env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); } else { - env = GNUNET_MQ_msg (cqr, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); + env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); } cqr->request_id = cq->request_id; - GNUNET_MQ_send (ch->mq, - env); + GNUNET_MQ_send (ch->mq, env); } @@ -615,8 +572,7 @@ handle_create_queue (void *cls, * @return #GNUNET_OK if @a smt is well-formed */ static int -check_send_msg (void *cls, - const struct GNUNET_TRANSPORT_SendMessageTo *smt) +check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) { (void) cls; GNUNET_MQ_check_boxed_message (smt); @@ -635,20 +591,18 @@ check_send_msg (void *cls, */ static void send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - int status, - const struct GNUNET_PeerIdentity *receiver, - uint64_t mid) + int status, + const struct GNUNET_PeerIdentity *receiver, + uint64_t mid) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_SendMessageToAck *ack; - env = GNUNET_MQ_msg (ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); + env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); ack->status = htonl (status); ack->mid = mid; ack->receiver = *receiver; - GNUNET_MQ_send (ch->mq, - env); + GNUNET_MQ_send (ch->mq, env); } @@ -664,13 +618,8 @@ send_ack_cb (void *cls) struct AckPending *ap = cls; struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch; - GNUNET_CONTAINER_DLL_remove (ch->ap_head, - ch->ap_tail, - ap); - send_ack (ch, - GNUNET_OK, - &ap->receiver, - ap->mid); + GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); + send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid); GNUNET_free (ap); } @@ -682,8 +631,7 @@ send_ack_cb (void *cls) * @param smt the transmission request */ static void -handle_send_msg (void *cls, - const struct GNUNET_TRANSPORT_SendMessageTo *smt) +handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; const struct GNUNET_MessageHeader *mh; @@ -691,37 +639,29 @@ handle_send_msg (void *cls, struct AckPending *ap; struct GNUNET_TRANSPORT_QueueHandle *qh; - for (qh = ch->queue_head;NULL != qh; qh = qh->next) - if ( (qh->queue_id == smt->qid) && - (0 == memcmp (&qh->peer, - &smt->receiver, - sizeof (struct GNUNET_PeerIdentity))) ) + for (qh = ch->queue_head; NULL != qh; qh = qh->next) + if ((qh->queue_id == smt->qid) && + (0 == memcmp (&qh->peer, + &smt->receiver, + sizeof (struct GNUNET_PeerIdentity)))) break; if (NULL == qh) { /* queue is already gone, tell transport this one failed */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Transmission failed, queue no longer exists.\n"); - send_ack (ch, - GNUNET_NO, - &smt->receiver, - smt->mid); + "Transmission failed, queue no longer exists.\n"); + send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid); return; } ap = GNUNET_new (struct AckPending); ap->ch = ch; ap->receiver = smt->receiver; ap->mid = smt->mid; - GNUNET_CONTAINER_DLL_insert (ch->ap_head, - ch->ap_tail, - ap); + GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap); mh = (const struct GNUNET_MessageHeader *) &smt[1]; env = GNUNET_MQ_msg_copy (mh); - GNUNET_MQ_notify_sent (env, - &send_ack_cb, - ap); - GNUNET_MQ_send (qh->mq, - env); + GNUNET_MQ_notify_sent (env, &send_ack_cb, ap); + GNUNET_MQ_send (qh->mq, env); } @@ -734,8 +674,9 @@ handle_send_msg (void *cls, * @return #GNUNET_OK if @a smt is well-formed */ static int -check_backchannel_incoming (void *cls, - const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) +check_backchannel_incoming ( + void *cls, + const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) { (void) cls; GNUNET_MQ_check_boxed_message (bi); @@ -750,18 +691,20 @@ check_backchannel_incoming (void *cls, * @param bi the backchannel message */ static void -handle_backchannel_incoming (void *cls, - const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) +handle_backchannel_incoming ( + void *cls, + const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; if (NULL != ch->notify_cb) ch->notify_cb (ch->notify_cb_cls, - &bi->pid, - (const struct GNUNET_MessageHeader *) &bi[1]); + &bi->pid, + (const struct GNUNET_MessageHeader *) &bi[1]); else - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Dropped backchanel message: handler not provided by communicator\n")); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Dropped backchanel message: handler not provided by communicator\n")); } @@ -773,50 +716,42 @@ handle_backchannel_incoming (void *cls, static void reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size (incoming_ack, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, - struct GNUNET_TRANSPORT_IncomingMessageAck, - ch), - GNUNET_MQ_hd_var_size (create_queue, - GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, - struct GNUNET_TRANSPORT_CreateQueue, - ch), - GNUNET_MQ_hd_var_size (send_msg, - GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, - struct GNUNET_TRANSPORT_SendMessageTo, - ch), - GNUNET_MQ_hd_var_size (backchannel_incoming, - GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, - struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming, - ch), - GNUNET_MQ_handler_end() - }; + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_fixed_size (incoming_ack, + GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, + struct GNUNET_TRANSPORT_IncomingMessageAck, + ch), + GNUNET_MQ_hd_var_size (create_queue, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, + struct GNUNET_TRANSPORT_CreateQueue, + ch), + GNUNET_MQ_hd_var_size (send_msg, + GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, + struct GNUNET_TRANSPORT_SendMessageTo, + ch), + GNUNET_MQ_hd_var_size ( + backchannel_incoming, + GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, + struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming, + ch), + GNUNET_MQ_handler_end ()}; struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; struct GNUNET_MQ_Envelope *env; - ch->mq = GNUNET_CLIENT_connect (ch->cfg, - "transport", - handlers, - &error_handler, - ch); + ch->mq = + GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); if (NULL == ch->mq) return; env = GNUNET_MQ_msg_extra (cam, - strlen (ch->addr_prefix) + 1, - GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); + strlen (ch->addr_prefix) + 1, + GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); cam->cc = htonl ((uint32_t) ch->cc); - memcpy (&cam[1], - ch->addr_prefix, - strlen (ch->addr_prefix) + 1); - GNUNET_MQ_send (ch->mq, - env); - for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; - NULL != ai; + memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1); + GNUNET_MQ_send (ch->mq, env); + for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; ai = ai->next) send_add_address (ai); - for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; - NULL != qh; + for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh; qh = qh->next) send_add_queue (qh); } @@ -841,14 +776,15 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) * @return NULL on error */ struct GNUNET_TRANSPORT_CommunicatorHandle * -GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *config_section, - const char *addr_prefix, - enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, - GNUNET_TRANSPORT_CommunicatorMqInit mq_init, - void *mq_init_cls, - GNUNET_TRANSPORT_CommunicatorNotify notify_cb, - void *notify_cb_cls) +GNUNET_TRANSPORT_communicator_connect ( + const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *config_section, + const char *addr_prefix, + enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, + GNUNET_TRANSPORT_CommunicatorMqInit mq_init, + void *mq_init_cls, + GNUNET_TRANSPORT_CommunicatorNotify notify_cb, + void *notify_cb_cls) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch; @@ -864,9 +800,9 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle reconnect (ch); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, - config_section, - "MAX_QUEUE_LENGTH", - &ch->max_queue_length)) + config_section, + "MAX_QUEUE_LENGTH", + &ch->max_queue_length)) ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; if (NULL == ch->mq) { @@ -883,7 +819,8 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle * @param ch handle returned from connect */ void -GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) +GNUNET_TRANSPORT_communicator_disconnect ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch) { disconnect (ch); while (NULL != ch->ai_head) @@ -919,12 +856,13 @@ GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHa * the tranport service is not yet up */ int -GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - const struct GNUNET_PeerIdentity *sender, - const struct GNUNET_MessageHeader *msg, - struct GNUNET_TIME_Relative expected_addr_validity, - GNUNET_TRANSPORT_MessageCompletedCallback cb, - void *cb_cls) +GNUNET_TRANSPORT_communicator_receive ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch, + const struct GNUNET_PeerIdentity *sender, + const struct GNUNET_MessageHeader *msg, + struct GNUNET_TIME_Relative expected_addr_validity, + GNUNET_TRANSPORT_MessageCompletedCallback cb, + void *cb_cls) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_IncomingMessage *im; @@ -932,29 +870,27 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl if (NULL == ch->mq) return GNUNET_SYSERR; - if ( (NULL == cb) && - (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length) ) + if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length)) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Dropping message: transprot is too slow, queue length %llu exceeded\n", - ch->max_queue_length); + GNUNET_log ( + GNUNET_ERROR_TYPE_WARNING, + "Dropping message: transprot is too slow, queue length %llu exceeded\n", + ch->max_queue_length); return GNUNET_NO; } msize = ntohs (msg->size); - env = GNUNET_MQ_msg_extra (im, - msize, - GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); + env = + GNUNET_MQ_msg_extra (im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); if (NULL == env) { GNUNET_break (0); return GNUNET_SYSERR; } - im->expected_address_validity = GNUNET_TIME_relative_hton (expected_addr_validity); + im->expected_address_validity = + GNUNET_TIME_relative_hton (expected_addr_validity); im->sender = *sender; - memcpy (&im[1], - msg, - msize); + memcpy (&im[1], msg, msize); if (NULL != cb) { struct FlowControl *fc; @@ -966,12 +902,9 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl fc->id = im->fc_id; fc->cb = cb; fc->cb_cls = cb_cls; - GNUNET_CONTAINER_DLL_insert (ch->fc_head, - ch->fc_tail, - fc); + GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc); } - GNUNET_MQ_send (ch->mq, - env); + GNUNET_MQ_send (ch->mq, env); return GNUNET_OK; } @@ -996,13 +929,14 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl * @return API handle identifying the new MQ */ struct GNUNET_TRANSPORT_QueueHandle * -GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - const struct GNUNET_PeerIdentity *peer, - const char *address, - uint32_t mtu, - enum GNUNET_NetworkType nt, - enum GNUNET_TRANSPORT_ConnectionStatus cs, - struct GNUNET_MQ_Handle *mq) +GNUNET_TRANSPORT_communicator_mq_add ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch, + const struct GNUNET_PeerIdentity *peer, + const char *address, + uint32_t mtu, + enum GNUNET_NetworkType nt, + enum GNUNET_TRANSPORT_ConnectionStatus cs, + struct GNUNET_MQ_Handle *mq) { struct GNUNET_TRANSPORT_QueueHandle *qh; @@ -1015,9 +949,7 @@ GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle qh->cs = cs; qh->mq = mq; qh->queue_id = ch->queue_gen++; - GNUNET_CONTAINER_DLL_insert (ch->queue_head, - ch->queue_tail, - qh); + GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh); send_add_queue (qh); return qh; } @@ -1035,9 +967,7 @@ GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh) struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch; send_del_queue (qh); - GNUNET_CONTAINER_DLL_remove (ch->queue_head, - ch->queue_tail, - qh); + GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh); GNUNET_MQ_destroy (qh->mq); GNUNET_free (qh->address); GNUNET_free (qh); @@ -1054,10 +984,11 @@ GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh) * @param expiration when does the communicator forsee this address expiring? */ struct GNUNET_TRANSPORT_AddressIdentifier * -GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - const char *address, - enum GNUNET_NetworkType nt, - struct GNUNET_TIME_Relative expiration) +GNUNET_TRANSPORT_communicator_address_add ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch, + const char *address, + enum GNUNET_NetworkType nt, + struct GNUNET_TIME_Relative expiration) { struct GNUNET_TRANSPORT_AddressIdentifier *ai; @@ -1067,9 +998,7 @@ GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorH ai->nt = nt; ai->expiration = expiration; ai->aid = ch->aid_gen++; - GNUNET_CONTAINER_DLL_insert (ch->ai_head, - ch->ai_tail, - ai); + GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai); send_add_address (ai); return ai; } @@ -1082,14 +1011,13 @@ GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorH * @param ai address that is no longer provided */ void -GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIdentifier *ai) +GNUNET_TRANSPORT_communicator_address_remove ( + struct GNUNET_TRANSPORT_AddressIdentifier *ai) { struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch; send_del_address (ai); - GNUNET_CONTAINER_DLL_remove (ch->ai_head, - ch->ai_tail, - ai); + GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai); GNUNET_free (ai->address); GNUNET_free (ai); } @@ -1113,10 +1041,11 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde * notify-API to @a pid's communicator @a comm */ void -GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, - const struct GNUNET_PeerIdentity *pid, - const char *comm, - const struct GNUNET_MessageHeader *header) +GNUNET_TRANSPORT_communicator_notify ( + struct GNUNET_TRANSPORT_CommunicatorHandle *ch, + const struct GNUNET_PeerIdentity *pid, + const char *comm, + const struct GNUNET_MessageHeader *header) { struct GNUNET_MQ_Envelope *env; struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb; @@ -1124,18 +1053,14 @@ GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle uint16_t mlen = ntohs (header->size); GNUNET_assert (mlen + slen + sizeof (*cb) < UINT16_MAX); - env = GNUNET_MQ_msg_extra (cb, - slen + mlen, - GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); + env = + GNUNET_MQ_msg_extra (cb, + slen + mlen, + GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); cb->pid = *pid; - memcpy (&cb[1], - header, - mlen); - memcpy (((char *)&cb[1]) + mlen, - comm, - slen); - GNUNET_MQ_send (ch->mq, - env); + memcpy (&cb[1], header, mlen); + memcpy (((char *) &cb[1]) + mlen, comm, slen); + GNUNET_MQ_send (ch->mq, env); } diff --git a/src/transport/transport_api2_monitor.c b/src/transport/transport_api2_monitor.c @@ -64,7 +64,6 @@ struct GNUNET_TRANSPORT_MonitorContext * Closure for @e cb. */ void *cb_cls; - }; @@ -91,12 +90,10 @@ send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc) if (NULL == mc->mq) return; - env = GNUNET_MQ_msg (smm, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); + env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); smm->one_shot = htonl ((uint32_t) mc->one_shot); smm->peer = mc->peer; - GNUNET_MQ_send (mc->mq, - env); + GNUNET_MQ_send (mc->mq, env); } @@ -122,14 +119,13 @@ disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) * @param error what error happened? */ static void -error_handler (void *cls, - enum GNUNET_MQ_Error error) +error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "MQ failure %d, reconnecting to transport service.\n", - error); + "MQ failure %d, reconnecting to transport service.\n", + error); disconnect (mc); /* TODO: maybe do this with exponential backoff/delay */ reconnect (mc); @@ -145,19 +141,10 @@ error_handler (void *cls, * @return #GNUNET_OK if @a smt is well-formed */ static int -check_monitor_data (void *cls, - const struct GNUNET_TRANSPORT_MonitorData *md) +check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) { - uint16_t len = ntohs (md->header.size) - sizeof (*md); - const char *addr = (const char *) &md[1]; - (void) cls; - if ( (0 == len) || - ('\0' != addr[len-1]) ) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + GNUNET_MQ_check_zero_termination (md); return GNUNET_OK; } @@ -169,8 +156,7 @@ check_monitor_data (void *cls, * @param md monitor data */ static void -handle_monitor_data (void *cls, - const struct GNUNET_TRANSPORT_MonitorData *md) +handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; struct GNUNET_TRANSPORT_MonitorInformation mi; @@ -184,9 +170,7 @@ handle_monitor_data (void *cls, mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until); mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation); mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt); - mc->cb (mc->cb_cls, - &md->peer, - &mi); + mc->cb (mc->cb_cls, &md->peer, &mi); } @@ -197,8 +181,7 @@ handle_monitor_data (void *cls, * @param me end message */ static void -handle_monitor_end (void *cls, - const struct GNUNET_MessageHeader *me) +handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me) { struct GNUNET_TRANSPORT_MonitorContext *mc = cls; @@ -209,9 +192,7 @@ handle_monitor_end (void *cls, reconnect (mc); return; } - mc->cb (mc->cb_cls, - NULL, - NULL); + mc->cb (mc->cb_cls, NULL, NULL); GNUNET_TRANSPORT_monitor_cancel (mc); } @@ -224,23 +205,19 @@ handle_monitor_end (void *cls, static void reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (monitor_data, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, - struct GNUNET_TRANSPORT_MonitorData, - mc), - GNUNET_MQ_hd_fixed_size (monitor_end, - GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, - struct GNUNET_MessageHeader, - mc), - GNUNET_MQ_handler_end() - }; - - mc->mq = GNUNET_CLIENT_connect (mc->cfg, - "transport", - handlers, - &error_handler, - mc); + struct GNUNET_MQ_MessageHandler handlers[] = + {GNUNET_MQ_hd_var_size (monitor_data, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, + struct GNUNET_TRANSPORT_MonitorData, + mc), + GNUNET_MQ_hd_fixed_size (monitor_end, + GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, + struct GNUNET_MessageHeader, + mc), + GNUNET_MQ_handler_end ()}; + + mc->mq = + GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc); if (NULL == mc->mq) return; send_start_monitor (mc); @@ -299,7 +276,6 @@ GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, } - /** * Cancel request to monitor peers *