diff --git a/node.c b/node.c index 346291e..bba30b4 100644 --- a/node.c +++ b/node.c @@ -585,7 +585,6 @@ void message_free(message_t *message) /** * Handles recieved node to node messages by either forwarding the message closer * to its destination node, or if it is the destination by handling the contents - * @todo implement finger table correction */ void message_recieve(const char *buf, port_t source_port) { @@ -773,6 +772,9 @@ int main(int argc, char *argv[]) dbg_init(); + message_queue = queue_init(); + recycle_queue = queue_init(); + init_socket(); dbg("Initalized, port: %d, id %d\n", my_port, my_id); diff --git a/queue.c b/queue.c index 2f2e840..c56ffab 100644 --- a/queue.c +++ b/queue.c @@ -5,7 +5,7 @@ queue_t *queue_init(void) { - return calloc(sizeof(queue_t), 0); + return calloc(sizeof(queue_t), 1); } void queue_free(queue_t *queue) @@ -23,13 +23,15 @@ void queue_free(queue_t *queue) int queue_empty(queue_t *queue) { - return !!queue->head; + return !queue->head; } void enqueue(queue_t *queue, message_t *message) { message_t *current = queue->head; + assert(!message->next); + ++queue->size; if (!current) { @@ -52,5 +54,6 @@ message_t *dequeue(queue_t *queue) --queue->size; } + current->next = NULL; return current; }