From 42b758ecd70b4057d2b9a11d16284c9b5fc15d36 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 9 Jul 2011 16:48:59 +0000 Subject: [PATCH] data structures --- src/fragmentation/defragmentation_new.c | 126 +++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/src/fragmentation/defragmentation_new.c b/src/fragmentation/defragmentation_new.c index 8fdc334d9..523a2cede 100644 --- a/src/fragmentation/defragmentation_new.c +++ b/src/fragmentation/defragmentation_new.c @@ -26,8 +26,97 @@ #include "gnunet_fragmentation_lib.h" #include "fragmentation.h" + /** - * Defragmentation context. + * Timestamps for fragments. + */ +struct FragTimes +{ + /** + * The time the fragment was received. + */ + GNUNET_TIME_Absolute time; + + /** + * Number of the bit for the fragment (in [0,..,63]). + */ + unsigned int bit; +}; + + +/** + * Information we keep for one message that is being assembled. + */ +struct MessageContext +{ + /** + * This is a DLL. + */ + struct MessageContext *next; + + /** + * This is a DLL. + */ + struct MessageContext *prev; + + /** + * Pointer to the assembled message, allocated at the + * end of this struct. + */ + const struct GNUNET_MessageHeader *msg; + + /** + * Last time we received any update for this message + * (least-recently updated message will be discarded + * if we hit the queue size). + */ + struct GNUNET_TIME_Absolute last_update; + + /** + * Task scheduled for transmitting the next ACK to the + * other peer. + */ + struct GNUNET_SCHEDULER_TaskIdentifier ack_task; + + /** + * When did we receive which fragment? Used to calculate + * the time we should send the ACK. + */ + struct FragTimes frag_times[64]; + + /** + * Which fragments have we gotten yet? bits that are 1 + * indicate missing fragments. + */ + uint64_t bits; + + /** + * Unique ID for this message. + */ + uint32_t fragment_id; + + /** + * For the current ACK round, which is the first relevant + * offset in 'frag_times'? + */ + unsigned int frag_times_start_offset; + + /** + * Which offset whould we write the next frag value into + * in the 'frag_times' array? All smaller entries are valid. + */ + unsigned int frag_times_write_offset; + + /** + * Total size of the message that we are assembling. + */ + uint16_t total_size; + +}; + + +/** + * Defragmentation context (one per connection). */ struct GNUNET_DEFRAGMENT_Context { @@ -42,6 +131,16 @@ struct GNUNET_DEFRAGMENT_Context */ void *cls; + /** + * Head of list of messages we're defragmenting. + */ + struct MessageContext *head; + + /** + * Tail of list of messages we're defragmenting. + */ + struct MessageContext *tail; + /** * Function to call with defragmented messages. */ @@ -51,6 +150,26 @@ struct GNUNET_DEFRAGMENT_Context * Function to call with acknowledgements. */ GNUNET_FRAGMENT_MessageProcessor ackp; + + /** + * Running average of the latency (delay between messages) for this + * connection. + */ + struct GNUNET_TIME_Relative latency; + + /** + * num_msgs how many fragmented messages + * to we defragment at most at the same time? + */ + unsigned int num_msgs; + + /** + * Current number of messages in the 'struct MessageContext' + * DLL (smaller or equal to 'num_msgs'). + */ + unsigned int list_size; + + }; @@ -58,6 +177,8 @@ struct GNUNET_DEFRAGMENT_Context * Create a defragmentation context. * * @param stats statistics context + * @param num_msgs how many fragmented messages + * to we defragment at most at the same time? * @param cls closure for proc and ackp * @param proc function to call with defragmented messages * @param ackp function to call with acknowledgements (to send @@ -66,6 +187,7 @@ struct GNUNET_DEFRAGMENT_Context */ struct GNUNET_DEFRAGMENT_Context * GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, + unsigned int num_msgs, void *cls, GNUNET_FRAGMENT_MessageProcessor proc, GNUNET_FRAGMENT_MessageProcessor ackp) @@ -77,6 +199,8 @@ GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, dc->cls = cls; dc->proc = proc; dc->ackp = ackp; + dc->num_msgs = num_msgs; + dc->latency = GNUNET_TIME_UNIT_SECONDS; /* start with likely overestimate */ return dc; } -- 2.25.1