Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright notices
[simgrid.git] / examples / msg / bittorrent / peer.c
index 6f5481c..4382710 100644 (file)
@@ -1,13 +1,14 @@
-/* Copyright (c) 2012. The SimGrid Team.
+/* Copyright (c) 2012-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
+
 #include "peer.h"
 #include "tracker.h"
 #include "connection.h"
 #include "messages.h"
-#include <msg/msg.h>
+#include <simgrid/msg.h>
 #include <xbt/RngStream.h>
 #include <limits.h>
 
@@ -95,8 +96,6 @@ void leech_loop(peer_t peer, double deadline)
    * (since it couldn't have gotten more than 50 peers)
    */
   send_handshake_all(peer);
-  //Wait for at least one "bitfield" message.
-//  wait_for_pieces(peer, deadline);
   XBT_DEBUG("Starting main leech loop");
 
   while (MSG_get_clock() < deadline && peer->pieces < FILE_PIECES) {
@@ -243,7 +242,8 @@ void peer_init(peer_t peer, int id, int seed)
 
   peer->current_pieces = xbt_dynar_new(sizeof(int), NULL);
 
-  peer->stream = RngStream_CreateStream("");
+  peer->stream =
+    (RngStream)MSG_host_get_property_value(MSG_host_self(), "stream");
   peer->comm_received = NULL;
 
   peer->round = 0;
@@ -267,8 +267,6 @@ void peer_free(peer_t peer)
   xbt_free(peer->pieces_count);
   xbt_free(peer->bitfield);
   xbt_free(peer->bitfield_blocks);
-
-  RngStream_DeleteStream(&peer->stream);
 }
 
 /**
@@ -660,7 +658,7 @@ void update_choked_peers(peer_t peer)
             xbt_dict_size(peer->active_peers));
   //update the current round
   peer->round = (peer->round + 1) % 3;
-  char *key, *key_choked;
+  char *key, *key_choked=NULL;
   connection_t peer_choosed = NULL;
   connection_t peer_choked = NULL;
   //remove a peer from the list