X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a92d7b716f51a53dea7f59db8524d4add713b910..1b4dc02411d79e4c367d331b85c1b295ec41edff:/examples/java/app/bittorrent/Peer.java diff --git a/examples/java/app/bittorrent/Peer.java b/examples/java/app/bittorrent/Peer.java index 94d0a68cf8..6491bd6568 100644 --- a/examples/java/app/bittorrent/Peer.java +++ b/examples/java/app/bittorrent/Peer.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2014, 2016. The SimGrid Team. +/* Copyright (c) 2006-2019. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -178,16 +178,15 @@ public class Peer extends Process { private boolean getPeersData() { boolean success = false; - boolean sendSuccess = false; double timeout = Msg.getClock() + Common.GET_PEERS_TIMEOUT; //Build the task to send to the tracker TrackerTask taskSend = new TrackerTask(hostname, mailboxTracker, id); - while (!sendSuccess && Msg.getClock() < timeout) { + while (Msg.getClock() < timeout) { try { Msg.debug("Sending a peer request to the tracker."); taskSend.send(Common.TRACKER_MAILBOX,Common.GET_PEERS_TIMEOUT); - sendSuccess = true; + break; } catch (MsgException e) { e.printStackTrace(); @@ -212,7 +211,6 @@ public class Peer extends Process { } commReceived = null; } - commReceived = null; return success; } @@ -325,6 +323,9 @@ public class Peer extends Process { } } break; + default: + Msg.error("Unexpected message type: " + message.type); + break; } if (remotePeer != null) { remotePeer.addSpeedValue(1 / (Msg.getClock() - beginReceiveTime)); @@ -384,14 +385,12 @@ public class Peer extends Process { if (currentPieces.size() >= (Common.FILE_PIECES - pieces)) { return; } -// if (pieces < 3) { - do { - currentPiece = stream.randInt(0,Common.FILE_PIECES - 1); - } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece))); -// } -// else { - //TODO trivial min algorithm. -// } + + //TODO: trivial min algorithm when pieces >= 3 + do { + currentPiece = stream.randInt(0,Common.FILE_PIECES - 1); + } while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece))); + currentPieces.add(currentPiece); Msg.debug("New interested piece: " + currentPiece); assert currentPiece >= 0 && currentPiece < Common.FILE_PIECES;