From 77990e170e992a745b7edde92fbb705247ab83e8 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 16 Oct 2012 11:20:27 +0000 Subject: [PATCH] overhead reporting --- .../gnunet-service-transport_clients.c | 5 +++- .../gnunet-service-transport_neighbours.c | 17 +++++------ .../gnunet-service-transport_neighbours.h | 4 ++- src/transport/plugin_transport_http_client.c | 15 ++++++++-- src/transport/plugin_transport_http_server.c | 11 ++++++-- src/transport/plugin_transport_tcp.c | 8 +++--- src/transport/plugin_transport_udp.c | 28 ++++++++++++++----- src/transport/plugin_transport_unix.c | 14 ++++++---- src/transport/plugin_transport_wlan.c | 20 +++++++++++-- 9 files changed, 88 insertions(+), 34 deletions(-) diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 1beb39ff6..065e8c4e6 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -562,11 +562,14 @@ struct SendTransmitContinuationContext * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected */ static void -handle_send_transmit_continuation (void *cls, int success) +handle_send_transmit_continuation (void *cls, int success, + size_t bytes_payload, size_t bytes_on_wire) { struct SendTransmitContinuationContext *stcc = cls; struct SendOkMessage send_ok_msg; + //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Payload: %u, On wire %u \n", bytes_payload, bytes_on_wire); + send_ok_msg.header.size = htons (sizeof (send_ok_msg)); send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); send_ok_msg.success = htonl (success); diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index da42b8c56..00ce6e5a0 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -862,7 +862,7 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) { GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); if (NULL != mq->cont) - mq->cont (mq->cont_cls, GNUNET_SYSERR); + mq->cont (mq->cont_cls, GNUNET_SYSERR, mq->message_buf_size, 0); GNUNET_free (mq); } /* It is too late to send other peer disconnect notifications, but at @@ -955,7 +955,7 @@ send_with_session (struct NeighbourMapEntry *n, timeout, cont, cont_cls)))) && (NULL != cont)) - cont (cont_cls, &n->id, GNUNET_SYSERR); + cont (cont_cls, &n->id, GNUNET_SYSERR, msgbuf_size, 0); GNUNET_break (NULL != papi); } @@ -983,7 +983,7 @@ master_task (void *cls, */ static void send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, - int result) + int result, size_t payload, size_t physical) { struct NeighbourMapEntry *n; @@ -1130,7 +1130,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) static void transmit_send_continuation (void *cls, const struct GNUNET_PeerIdentity *receiver, - int success) + int success, size_t size_payload, size_t physical) { struct MessageQueue *mq = cls; struct NeighbourMapEntry *n; @@ -1150,6 +1150,7 @@ transmit_send_continuation (void *cls, n->task = GNUNET_SCHEDULER_add_now (&master_task, n); } GNUNET_assert (bytes_in_send_queue >= mq->message_buf_size); + GNUNET_break (size_payload == mq->message_buf_size); bytes_in_send_queue -= mq->message_buf_size; GNUNET_STATISTICS_set (GST_stats, gettext_noop @@ -1171,7 +1172,7 @@ transmit_send_continuation (void *cls, ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), (success == GNUNET_OK) ? "success" : "FAILURE"); if (NULL != mq->cont) - mq->cont (mq->cont_cls, success); + mq->cont (mq->cont_cls, success, size_payload, physical); GNUNET_free (mq); } @@ -1224,7 +1225,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) 1, GNUNET_NO); GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); n->is_active = mq; - transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */ + transmit_send_continuation (mq, &n->id, GNUNET_SYSERR, mq->message_buf_size, 0); /* timeout */ } if (NULL == mq) return; /* no more messages */ @@ -1477,14 +1478,14 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, { GNUNET_break (0); if (NULL != cont) - cont (cont_cls, GNUNET_SYSERR); + cont (cont_cls, GNUNET_SYSERR, msg_size, 0); return; } if (GNUNET_YES != test_connected (n)) { GNUNET_break (0); if (NULL != cont) - cont (cont_cls, GNUNET_SYSERR); + cont (cont_cls, GNUNET_SYSERR, msg_size, 0); return; } bytes_in_send_queue += msg_size; diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index d137c311d..6a743359f 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -84,7 +84,9 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target); * @param cls closure * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected */ -typedef void (*GST_NeighbourSendContinuation) (void *cls, int success); +typedef void (*GST_NeighbourSendContinuation) (void *cls, int success, + size_t bytes_payload, + size_t bytes_on_wire); /** diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 536e7382b..e6f52850f 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -84,6 +84,12 @@ struct HTTP_Message */ size_t size; + /** + * HTTP overhead required to send this message + * FIXME: to implement + */ + size_t overhead; + /** * Continuation function to call once the transmission buffer * has again space available. NULL if there is no @@ -546,7 +552,8 @@ client_delete_session (struct Session *s) next = pos->next; GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, pos); if (pos->transmit_cont != NULL) - pos->transmit_cont (pos->transmit_cont_cls, &s->target, GNUNET_SYSERR); + pos->transmit_cont (pos->transmit_cont_cls, &s->target, GNUNET_SYSERR, + pos->size, pos->pos + pos->overhead); GNUNET_free (pos); } @@ -631,7 +638,8 @@ client_disconnect (struct Session *s) { t = msg->next; if (NULL != msg->transmit_cont) - msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR); + msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, + msg->size, msg->pos + msg->overhead); GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); GNUNET_free (msg); msg = t; @@ -784,7 +792,8 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) /* Calling transmit continuation */ GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); if (NULL != msg->transmit_cont) - msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); + msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK, + msg->size, msg->size + msg->overhead); GNUNET_free (msg); } diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index ea4a09175..a8731907e 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -397,6 +397,11 @@ struct HTTP_Message */ size_t size; + /** + * HTTP/S specific overhead + */ + size_t overhead; + /** * Continuation function to call once the transmission buffer * has again space available. NULL if there is no @@ -680,7 +685,8 @@ server_delete_session (struct Session *s) GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); if (msg->transmit_cont != NULL) { - msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR); + msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, + msg->size, msg->pos + msg->overhead); } GNUNET_free (msg); msg = tmp; @@ -1203,7 +1209,8 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) { GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); if (NULL != msg->transmit_cont) - msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); + msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK, + msg->size, msg->size + msg->overhead); GNUNET_free (msg); } } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 877356c16..99da8bb17 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -849,7 +849,7 @@ do_transmit (void *cls, size_t size, void *buf) { GNUNET_CONTAINER_DLL_remove (hd, tl, pos); if (pos->transmit_cont != NULL) - pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR); + pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR, pos->message_size, 0); GNUNET_free (pos); } GNUNET_STATISTICS_update (plugin->env->stats, @@ -895,7 +895,7 @@ do_transmit (void *cls, size_t size, void *buf) { GNUNET_CONTAINER_DLL_remove (hd, tl, pos); if (pos->transmit_cont != NULL) - pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK); + pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK, pos->message_size, pos->message_size); /* FIXME: include TCP overhead */ GNUNET_free (pos); } GNUNET_assert (hd == NULL); @@ -999,7 +999,7 @@ disconnect_session (struct Session *session) session->pending_messages_tail, pm); if (NULL != pm->transmit_cont) pm->transmit_cont (pm->transmit_cont_cls, &session->target, - GNUNET_SYSERR); + GNUNET_SYSERR, pm->message_size, 0); GNUNET_free (pm); } if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) @@ -1159,7 +1159,7 @@ tcp_plugin_send (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); if (NULL != cont) - cont (cont_cls, &session->target, GNUNET_SYSERR); + cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); GNUNET_break (0); GNUNET_free (pm); return GNUNET_SYSERR; /* session does not exist here */ diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 1630c48b1..c7bfe6237 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -273,6 +273,11 @@ struct UDP_FragmentationContext * Payload size of original unfragmented message */ size_t payload_size; + + /** + * Bytes used to send all fragments on wire including UDP overhead + */ + size_t on_wire_size; }; @@ -688,7 +693,12 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) if (NULL != udpw->cont) { /* FIXME: add bytes used on wire here */ - udpw->cont (udpw->cont_cls, &udpw->session->target, result); + /* Calls transport continuation if message was not fragmented, + * GNUNET_FRAGMENT if just an fragment was sent + */ + + /* Call continuation for fragmented message */ + udpw->cont (udpw->cont_cls, &udpw->session->target, result, udpw->payload_size, udpw->msg_size); } } @@ -837,7 +847,8 @@ disconnect_session (struct Session *s) { if (NULL != s->frag_ctx->cont) { - s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR); + s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, + s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling continuation for fragemented message to `%s' with result SYSERR\n", GNUNET_i2s (&s->target)); @@ -1186,10 +1197,9 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) static void send_next_fragment (void *cls, const struct GNUNET_PeerIdentity *target, - int result) + int result, size_t payload, size_t physical) { struct UDP_MessageWrapper *udpw = cls; - GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); } @@ -1223,6 +1233,7 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) udpw->timeout = frag_ctx->timeout; udpw->frag_ctx = frag_ctx; memcpy (udpw->msg_buf, msg, msg_len); + frag_ctx->on_wire_size += msg_len; enqueue (plugin, udpw); schedule_select (plugin); } @@ -1337,6 +1348,7 @@ udp_plugin_send (void *cls, frag_ctx->cont_cls = cont_cls; frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ + frag_ctx->on_wire_size = 0; frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, &plugin->tracker, @@ -1344,7 +1356,6 @@ udp_plugin_send (void *cls, &udp->header, &enqueue_fragment, frag_ctx); - s->frag_ctx = frag_ctx; } schedule_select (plugin); @@ -1714,11 +1725,12 @@ read_process_ack (struct Plugin *plugin, "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); + /* Expect more ACKs to arrive */ return; } LOG (GNUNET_ERROR_TYPE_DEBUG, - "FULL MESSAGE ACKed\n", + "Message full ACK'ed\n", (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); s->last_expected_delay = GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag); @@ -1759,7 +1771,9 @@ read_process_ack (struct Plugin *plugin, LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling continuation for fragmented message to `%s' with result %s\n", GNUNET_i2s (&s->target), "OK"); - s->frag_ctx->cont (s->frag_ctx->cont_cls, &udp_ack->sender, GNUNET_OK); + /* FIXME add overhead bytes here */ + s->frag_ctx->cont (s->frag_ctx->cont_cls, &udp_ack->sender, GNUNET_OK, + s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); } GNUNET_free (s->frag_ctx); diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index fc1556591..5fda1191a 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -377,7 +377,8 @@ disconnect_session (struct Session *s) continue; GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); if (NULL != msgw->cont) - msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR); + msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR, + msgw->msgsize, 0); GNUNET_free (msgw->msg); GNUNET_free (msgw); removed = GNUNET_YES; @@ -442,7 +443,8 @@ unix_transport_server_stop (void *cls) { GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); if (msgw->cont != NULL) - msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR); + msgw->cont (msgw->cont_cls, &msgw->session->target, GNUNET_SYSERR, + msgw->msgsize, 0); GNUNET_free (msgw->msg); GNUNET_free (msgw); } @@ -508,7 +510,7 @@ unix_real_send (void *cls, /* We do not have a send handle */ GNUNET_break (0); if (cont != NULL) - cont (cont_cls, target, GNUNET_SYSERR); + cont (cont_cls, target, GNUNET_SYSERR, msgbuf_size, 0); return -1; } if ((addr == NULL) || (addrlen == 0)) @@ -516,7 +518,7 @@ unix_real_send (void *cls, /* Can never send if we don't have an address */ GNUNET_break (0); if (cont != NULL) - cont (cont_cls, target, GNUNET_SYSERR); + cont (cont_cls, target, GNUNET_SYSERR, msgbuf_size, 0); return -1; } @@ -598,9 +600,9 @@ unix_real_send (void *cls, if (cont != NULL) { if (sent == GNUNET_SYSERR) - cont (cont_cls, target, GNUNET_SYSERR); + cont (cont_cls, target, GNUNET_SYSERR, msgbuf_size, 0); if (sent > 0) - cont (cont_cls, target, GNUNET_OK); + cont (cont_cls, target, GNUNET_OK, msgbuf_size, msgbuf_size); } /* return number of bytes successfully sent */ diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 49fe101b7..d23608db9 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -260,6 +260,16 @@ struct FragmentMessage */ void *cont_cls; + /** + * Size of original message + */ + size_t size_payload; + + /** + * Number of bytes used to transmit message + */ + size_t size_on_wire; + }; @@ -745,6 +755,7 @@ transmit_fragment (void *cls, &radio_header->header, GNUNET_NO, &fragment_transmission_done, fm); + fm->size_on_wire += size; if (NULL != fm->sh) GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN message fragments sent"), 1, GNUNET_NO); @@ -804,7 +815,7 @@ fragmentmessage_timeout (void *cls, fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; if (NULL != fm->cont) { - fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR); + fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR, fm->size_payload, fm->size_on_wire); fm->cont = NULL; } free_fragment_message (fm); @@ -818,6 +829,7 @@ fragmentmessage_timeout (void *cls, * @param timeout how long can the message wait? * @param target peer that should receive the message * @param msg message to transmit + * @param bytes of payload * @param cont continuation to call once the message has * been transmitted (or if the transport is ready * for the next transmission call; or if the @@ -829,6 +841,7 @@ send_with_fragmentation (struct MacEndpoint *endpoint, struct GNUNET_TIME_Relative timeout, const struct GNUNET_PeerIdentity *target, const struct GNUNET_MessageHeader *msg, + size_t payload_size, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { @@ -839,6 +852,8 @@ send_with_fragmentation (struct MacEndpoint *endpoint, fm = GNUNET_malloc (sizeof (struct FragmentMessage)); fm->macendpoint = endpoint; fm->target = *target; + fm->size_payload = payload_size; + fm->size_on_wire = 0; fm->timeout = GNUNET_TIME_relative_to_absolute (timeout); fm->cont = cont; fm->cont_cls = cont_cls; @@ -1079,6 +1094,7 @@ wlan_plugin_send (void *cls, to, &session->target, &wlanheader->header, + msgbuf_size, cont, cont_cls); return size; } @@ -1177,7 +1193,7 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); if (NULL != fm->cont) { - fm->cont (fm->cont_cls, &fm->target, GNUNET_OK); + fm->cont (fm->cont_cls, &fm->target, GNUNET_OK, fm->size_payload, fm->size_on_wire); fm->cont = NULL; } free_fragment_message (fm); -- 2.25.1