Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Dig through git history, and update copyright lines.
[simgrid.git] / examples / msg / bittorrent / bittorrent.c
index ba52ea4..741cd2c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012. The SimGrid Team.
+/* Copyright (c) 2012-2013. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -7,15 +7,22 @@
 #include "peer.h"
 #include "tracker.h"
 #include <msg/msg.h>
+#include <xbt/RngStream.h>
+
 /**
  * Bittorrent example launcher
  */
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
+  xbt_dynar_t host_list;
+  msg_host_t host;
+  unsigned i;
+
   MSG_init(&argc, argv);
 
   /* Check the arguments */
   if (argc < 3) {
-    printf("Usage: %s platform_file deployment_file \n",argv[0]);
+    printf("Usage: %s platform_file deployment_file \n", argv[0]);
     return -1;
   }
 
@@ -24,14 +31,27 @@ int main(int argc, char *argv[]) {
 
   MSG_create_environment(platform_file);
 
-  MSG_function_register("tracker",tracker);
-  MSG_function_register("peer",peer);
+  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_launch_application(deployment_file);
 
-  msg_error_t res = MSG_main();
+  MSG_main();
 
-  MSG_clean();
+  xbt_dynar_foreach(host_list, i, host) {
+    RngStream stream = MSG_host_get_data(host);
+    RngStream_DeleteStream(&stream);
+  }
+  xbt_dynar_free(&host_list);
 
   return 0;
 }