Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright notices
[simgrid.git] / examples / msg / bittorrent / bittorrent.c
1 /* Copyright (c) 2012-2015. 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 /**
14  * Bittorrent example launcher
15  */
16 int main(int argc, char *argv[])
17 {
18   xbt_dynar_t host_list;
19   msg_host_t host;
20   unsigned i;
21
22   MSG_init(&argc, argv);
23
24   /* Check the arguments */
25   if (argc < 3) {
26     printf("Usage: %s platform_file deployment_file \n", argv[0]);
27     return -1;
28   }
29
30   const char *platform_file = argv[1];
31   const char *deployment_file = argv[2];
32
33   MSG_create_environment(platform_file);
34
35   host_list = MSG_hosts_as_dynar();
36   xbt_dynar_foreach(host_list, i, host) {
37     char descr[512];
38     RngStream stream;
39     snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
40     stream = RngStream_CreateStream(descr);
41     MSG_host_set_property_value(host, "stream", (char*)stream, NULL);
42   }
43
44   MSG_function_register("tracker", tracker);
45   MSG_function_register("peer", peer);
46
47   MSG_launch_application(deployment_file);
48
49   MSG_main();
50
51   xbt_dynar_foreach(host_list, i, host) {
52     RngStream stream = (RngStream) MSG_host_get_property_value(host, "stream");
53     RngStream_DeleteStream(&stream);
54   }
55   xbt_dynar_free(&host_list);
56
57   return 0;
58 }