-/* Copyright (c) 2012-2020. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2021. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "bittorrent-peer.h"
#include "tracker.h"
#include <simgrid/forward.h>
+#include <xbt/ex.h>
#include <limits.h>
#include <stdio.h> /* snprintf */
xbt_assert(argc == 3 || argc == 4, "Wrong number of arguments");
// Build peer object
- peer_t peer = peer_init((int)xbt_str_parse_int(argv[1], "Invalid ID: %s"), argc == 4 ? 1 : 0);
+ peer_t peer = peer_init((int)xbt_str_parse_int(argv[1], "Invalid ID"), argc == 4 ? 1 : 0);
// Retrieve deadline
- peer->deadline = xbt_str_parse_double(argv[2], "Invalid deadline: %s");
+ peer->deadline = xbt_str_parse_double(argv[2], "Invalid deadline");
xbt_assert(peer->deadline > 0, "Wrong deadline supplied");
char* status = xbt_malloc0(FILE_PIECES + 1);
- get_status(&status, peer->bitfield);
+ get_status(status, peer->bitfield);
XBT_INFO("Hi, I'm joining the network with id %d", peer->id);
XBT_INFO("Couldn't contact the tracker.");
}
- get_status(&status, peer->bitfield);
+ get_status(status, peer->bitfield);
XBT_INFO("Here is my current status: %s", status);
if (peer->comm_received) {
sg_comm_unref(peer->comm_received);
}
}
-void get_status(char** status, unsigned int bitfield)
+void get_status(char* status, unsigned int bitfield)
{
for (int i = FILE_PIECES - 1; i >= 0; i--)
- (*status)[i] = (bitfield & (1U << i)) ? '1' : '0';
- (*status)[FILE_PIECES] = '\0';
+ status[i] = (bitfield & (1U << i)) ? '1' : '0';
+ status[FILE_PIECES] = '\0';
}
int has_finished(unsigned int bitfield)
// Setting the fact that we have the piece
peer->bitfield = peer->bitfield | (1U << message->piece);
char* status = xbt_malloc0(FILE_PIECES + 1);
- get_status(&status, peer->bitfield);
+ get_status(status, peer->bitfield);
XBT_DEBUG("My status is now %s", status);
xbt_free(status);
// Sending the information to all the peers we are connected to