Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4fc3fb19e180b74cadd26970b534e9cf34e2f064
[simgrid.git] / examples / msg / app-bittorrent / bittorrent.c
1 /* Copyright (c) 2012-2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "bittorrent.h"
8 #include "peer.h"
9 #include "tracker.h"
10 #include <simgrid/msg.h>
11 #include <xbt/RngStream.h>
12
13 /** Bittorrent example launcher */
14 int main(int argc, char *argv[])
15 {
16   xbt_dynar_t host_list;
17   msg_host_t host;
18   unsigned i;
19
20   MSG_init(&argc, argv);
21
22   /* Check the arguments */
23   xbt_assert (argc > 2, "Usage: %s platform_file deployment_file", argv[0]);
24
25   const char *platform_file = argv[1];
26   const char *deployment_file = argv[2];
27
28   MSG_create_environment(platform_file);
29
30   host_list = MSG_hosts_as_dynar();
31   xbt_dynar_foreach(host_list, i, host) {
32     char descr[512];
33     RngStream stream;
34     snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
35     stream = RngStream_CreateStream(descr);
36     MSG_host_set_property_value(host, "stream", (char*)stream, NULL);
37   }
38
39   MSG_function_register("tracker", tracker);
40   MSG_function_register("peer", peer);
41
42   MSG_launch_application(deployment_file);
43
44   MSG_main();
45
46   xbt_dynar_foreach(host_list, i, host) {
47     RngStream stream = (RngStream) MSG_host_get_property_value(host, "stream");
48     RngStream_DeleteStream(&stream);
49   }
50   xbt_dynar_free(&host_list);
51
52   return 0;
53 }