X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fsync%2Fdata_structures.c;h=c4d4d966f31025db80058b69bfadb4762411f8ef;hb=d4721e1a5216f34570d7e10257f85601cb3991bc;hp=6206969875cb900b99568900cd172e8a3d5f766f;hpb=10341d26543c63ff318a4cf5cb163bccdc58b19d;p=lttv.git diff --git a/lttv/lttv/sync/data_structures.c b/lttv/lttv/sync/data_structures.c index 62069698..c4d4d966 100644 --- a/lttv/lttv/sync/data_structures.c +++ b/lttv/lttv/sync/data_structures.c @@ -99,15 +99,12 @@ bool isAcking(const Message* const ackSegment, const Message* const * Convert an IP address from 32 bit form to dotted quad * * Args: - * str: A preallocated string of length >= 17 + * str: A preallocated string of length >= 16 * addr: Address */ void convertIP(char* const str, const uint32_t addr) { - struct in_addr iaddr; - - iaddr.s_addr= htonl(addr); - strcpy(str, inet_ntoa(iaddr)); + strcpy(str, inet_ntoa((struct in_addr) {.s_addr= addr})); } @@ -116,7 +113,7 @@ void convertIP(char* const str, const uint32_t addr) */ void printTCPSegment(const Message* const segment) { - char saddr[17], daddr[17]; + char saddr[16], daddr[16]; SegmentKey* segmentKey; g_assert(segment->inE->type == TCP); @@ -329,6 +326,7 @@ void destroyTCPEvent(Event* const event) destroyEvent(event); } + /* * Free the memory used by a base Event */ @@ -453,3 +451,192 @@ void gdnConnectionKeyDestroy(gpointer data) { free((ConnectionKey*) data); } + + +/* + * A GHashFunc for g_hash_table_new() + * + * Args: + * key DatagramKey* + */ +guint ghfDatagramKeyHash(gconstpointer key) +{ + DatagramKey* datagramKey; + uint32_t a, b, c; + + datagramKey= (DatagramKey*) key; + + a= datagramKey->saddr; + b= datagramKey->daddr; + c= datagramKey->source + (datagramKey->dest << 16); + mix(a, b, c); + + a+= datagramKey->ulen; // 16 bits left here + b+= *((uint32_t*) datagramKey->dataKey); + c+= *((uint32_t*) ((void*) datagramKey->dataKey + 4)); + final(a, b, c); + + return c; +} + + +/* + * A GEqualFunc for g_hash_table_new() + * + * Args: + * a, b DatagramKey* + * + * Returns: + * TRUE if both values are equal + */ +gboolean gefDatagramKeyEqual(gconstpointer a, gconstpointer b) +{ + const DatagramKey* dA, * dB; + + dA= (DatagramKey*) a; + dB= (DatagramKey*) b; + + if (dA->saddr == dB->saddr && dA->daddr == dB->daddr && + dA->source == dB->source && dA->dest == dB->dest && + dA->ulen == dB->ulen && + memcmp(dA->dataKey, dB->dataKey, sizeof(dA->dataKey)) == 0) + { + return TRUE; + } + else + { + return FALSE; + } +} + + +/* + * A GDestroyNotify function for g_hash_table_new_full() + * + * Args: + * data: DatagramKey* + */ +void gdnDestroyDatagramKey(gpointer data) +{ + free((DatagramKey*) data); +} + + +/* + * A GDestroyNotify function for g_hash_table_new_full() + * + * Args: + * data: Broadcast* + */ +void gdnDestroyBroadcast(gpointer data) +{ + destroyBroadcast((Broadcast*) data); +} + + +/* + * Free a Broadcast struct and its associated ressources + * + * Args: + * broadcast: Broadcast* + */ +void destroyBroadcast(Broadcast* const broadcast) +{ + g_queue_foreach(broadcast->events, &gfDestroyEvent, NULL); + g_queue_free(broadcast->events); + free(broadcast); +} + + +/* + * A GFunc for g_queue_foreach() + * + * Args: + * data Event* + * user_data NULL + */ +void gfDestroyEvent(gpointer data, gpointer user_data) +{ + Event* event= data; + + event->destroy(event); +} + + +/* Subtract two WallTime structs + * + * Args: + * tA, tB: WallTime + * + * Returns: + * The result of tA - tB, as a double. This may incur a loss of + * precision. + */ +double wallTimeSub(const WallTime const* tA, const WallTime const* tB) +{ + return (double) tA->seconds - tB->seconds + ((double) tA->nanosec - tB->nanosec) / 1e9; +} + + +/* + * Allocate and copy a base event + * + * Args: + * newEvent: new event, pointer will be updated + * event: event to copy + */ +void copyEvent(const Event* const event, Event** const newEvent) +{ + g_assert(event->event.tcpEvent == NULL); + + *newEvent= malloc(sizeof(Event)); + memcpy(*newEvent, event, sizeof(Event)); +} + + +/* + * Allocate and copy a TCP event + * + * Args: + * newEvent: new event, pointer will be updated + * event: event to copy + */ +void copyTCPEvent(const Event* const event, Event** const newEvent) +{ + g_assert(event->type == TCP); + + *newEvent= malloc(sizeof(Event)); + memcpy(*newEvent, event, sizeof(Event)); + + (*newEvent)->event.tcpEvent= malloc(sizeof(TCPEvent)); + memcpy((*newEvent)->event.tcpEvent, event->event.tcpEvent, + sizeof(TCPEvent)); + + (*newEvent)->event.tcpEvent->segmentKey= malloc(sizeof(SegmentKey)); + memcpy((*newEvent)->event.tcpEvent->segmentKey, + event->event.tcpEvent->segmentKey, sizeof(SegmentKey)); +} + + +/* + * Allocate and copy a UDP event + * + * Args: + * newEvent: new event, pointer will be updated + * event: event to copy + */ +void copyUDPEvent(const Event* const event, Event** const newEvent) +{ + g_assert(event->type == UDP); + + *newEvent= malloc(sizeof(Event)); + memcpy(*newEvent, event, sizeof(Event)); + + (*newEvent)->event.udpEvent= malloc(sizeof(UDPEvent)); + memcpy((*newEvent)->event.udpEvent, event->event.udpEvent, + sizeof(UDPEvent)); + + (*newEvent)->event.udpEvent->datagramKey= malloc(sizeof(DatagramKey)); + memcpy((*newEvent)->event.udpEvent->datagramKey, + event->event.udpEvent->datagramKey, sizeof(DatagramKey)); +}