Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't store raw objects as host properties, which must be strings
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 4 Dec 2016 17:49:40 +0000 (18:49 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 4 Dec 2016 18:26:33 +0000 (19:26 +0100)
examples/msg/app-bittorrent/bittorrent.c
examples/msg/app-bittorrent/peer.c
examples/msg/app-bittorrent/tracker.c
examples/msg/dht-chord/dht-chord.c

index b469d4e..c88b708 100644 (file)
@@ -29,10 +29,9 @@ int main(int argc, char *argv[])
   xbt_dynar_t 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_property_value(host, "stream", (char*)stream, NULL);
+    RngStream stream = RngStream_CreateStream(descr);
+    MSG_host_set_data(host, stream);
   }
 
   MSG_function_register("tracker", tracker);
@@ -43,8 +42,9 @@ int main(int argc, char *argv[])
   MSG_main();
 
   xbt_dynar_foreach(host_list, i, host) {
-    RngStream stream = (RngStream) MSG_host_get_property_value(host, "stream");
+    RngStream stream = (RngStream)MSG_host_get_data(host);
     RngStream_DeleteStream(&stream);
+    MSG_host_set_data(host, NULL);
   }
   xbt_dynar_free(&host_list);
 
index 5acba5d..e27520e 100644 (file)
@@ -227,7 +227,7 @@ void peer_init(peer_t peer, int id, int seed)
 
   peer->current_pieces = xbt_dynar_new(sizeof(int), NULL);
 
-  peer->stream = (RngStream)MSG_host_get_property_value(MSG_host_self(), "stream");
+  peer->stream        = (RngStream)MSG_host_get_data(MSG_host_self());
   peer->comm_received = NULL;
 
   peer->round = 0;
index 55b329a..c6e9255 100644 (file)
@@ -20,7 +20,7 @@ int tracker(int argc, char *argv[])
 {
   int i;
 
-  RngStream stream = (RngStream) MSG_host_get_property_value(MSG_host_self(), "stream");
+  RngStream stream = (RngStream)MSG_host_get_data(MSG_host_self());
   //Checking arguments
   xbt_assert(argc == 2, "Wrong number of arguments for the tracker.");
   //Retrieving end time
index 57ae2ff..f4264e4 100644 (file)
@@ -43,7 +43,7 @@ static void chord_initialize(void)
     RngStream stream;
     snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
     stream = RngStream_CreateStream(descr);
-    MSG_host_set_property_value(host, "stream", (char*)stream, NULL);
+    MSG_host_set_data(host, stream);
   }
 }
 
@@ -52,8 +52,9 @@ static void chord_exit(void)
   msg_host_t host;
   unsigned i;
   xbt_dynar_foreach(host_list, i, host) {
-    RngStream stream = (RngStream)MSG_host_get_property_value(host, "stream");
+    RngStream stream = (RngStream)MSG_host_get_data(host);
     RngStream_DeleteStream(&stream);
+    MSG_host_set_data(host, NULL);
   }
   xbt_dynar_free(&host_list);
 
@@ -712,7 +713,7 @@ static int node(int argc, char *argv[])
   // initialize my node
   s_node_t node = {0};
   node.id = xbt_str_parse_int(argv[1],"Invalid ID: %s");
-  node.stream = (RngStream)MSG_host_get_property_value(MSG_host_self(), "stream");
+  node.stream   = (RngStream)MSG_host_get_data(MSG_host_self());
   get_mailbox(node.id, node.mailbox);
   node.next_finger_to_fix = 0;
   node.fingers = xbt_new0(s_finger_t, nb_bits);