X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/871107618b8c0e08361b84990c5c4a35ae4188e6..c2f951e38bdf2b8639bf42b78b69c1530510b6f0:/examples/java/app/bittorrent/Peer.java diff --git a/examples/java/app/bittorrent/Peer.java b/examples/java/app/bittorrent/Peer.java index 0bdc770232..43be4d4bda 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-2014, 2016-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -216,7 +216,7 @@ public class Peer extends Process { return success; } - void handleMessage(Task task) { + private void handleMessage(Task task) { MessageTask message = (MessageTask)task; Connection remotePeer = peers.get(message.peerId); switch (message.type) { @@ -332,7 +332,7 @@ public class Peer extends Process { beginReceiveTime = Msg.getClock(); } - void waitForPieces() { + private void waitForPieces() { boolean finished = false; while (Msg.getClock() < deadline && !finished) { if (commReceived == null) { @@ -380,18 +380,16 @@ public class Peer extends Process { * If the peer has more than pieces, he downloads the pieces that are the less * replicated */ - void updateCurrentPiece() { + private void updateCurrentPiece() { 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; @@ -624,10 +622,9 @@ public class Peer extends Process { } private String getStatus() { - String s = ""; - for (int i = 0; i < Common.FILE_PIECES; i++) { - s = s + bitfield[i]; - } - return s; + StringBuilder s = new StringBuilder(""); + for (int i = 0; i < Common.FILE_PIECES; i++) + s.append(bitfield[i]); + return s.toString(); } }