#include "peer.h"
#include "tracker.h"
#include <msg/msg.h>
+#include <xbt/RngStream.h>
+
/**
* Bittorrent example launcher
*/
int main(int argc, char *argv[])
{
+ xbt_dynar_t host_list;
+ msg_host_t host;
+ unsigned i;
+
MSG_init(&argc, argv);
/* Check the arguments */
MSG_create_environment(platform_file);
+ host_list = MSG_hosts_as_dynar();
+ xbt_dynar_foreach(host_list, i, host) {
+ char descr[512];
+ RngStream stream;
+ snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
+ stream = RngStream_CreateStream(descr);
+ MSG_host_set_data(host, stream);
+ }
+
MSG_function_register("tracker", tracker);
MSG_function_register("peer", peer);
MSG_main();
+ xbt_dynar_foreach(host_list, i, host) {
+ RngStream stream = MSG_host_get_data(host);
+ RngStream_DeleteStream(&stream);
+ }
+ xbt_dynar_free(&host_list);
+
return 0;
}
* Number of pieces the peer asks for simultaneously
*/
#define MAX_PIECES 1
+
#endif /* BITTORRENT_BITTORRENT_H_ */
> [ 0.000000] (8:peer@McGee) Hi, I'm joining the network with id 8
> [ 3000.000000] (1:tracker@Jacquelin) Tracker is leaving
> [ 5000.005340] (5:peer@Geoff) Here is my current status: 1111111111
-> [ 5000.012657] (7:peer@iRMX) Here is my current status: 1111111111
+> [ 5000.012635] (7:peer@iRMX) Here is my current status: 1111111111
> [ 5000.048881] (2:peer@Boivin) Here is my current status: 1111111111
> [ 5000.827441] (8:peer@McGee) Here is my current status: 1111111111
> [ 5000.832977] (3:peer@Jean_Yves) Here is my current status: 1111111111
peer->current_pieces = xbt_dynar_new(sizeof(int), NULL);
peer->current_piece = -1;
- peer->stream = RngStream_CreateStream("");
+ peer->stream = MSG_host_get_data(MSG_host_self());
peer->comm_received = NULL;
peer->round = 0;
xbt_free(peer->pieces_count);
xbt_free(peer->bitfield);
xbt_free(peer->bitfield_blocks);
-
- RngStream_DeleteStream(&peer->stream);
}
/**
{
int i;
- RngStream stream = RngStream_CreateStream("tracker");
+ RngStream stream = MSG_host_get_data(MSG_host_self());
//Checking arguments
xbt_assert(argc == 2, "Wrong number of arguments for the tracker.");
}
//Free the peers list
xbt_dynar_free(&peers_list);
- //Free the RngStream object.
- RngStream_DeleteStream(&stream);
XBT_INFO("Tracker is leaving");