import org.simgrid.msg.Host;
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
+import org.simgrid.msg.RngStream;
import org.simgrid.msg.Process;
import org.simgrid.msg.Task;
protected double deadline;
+ protected static RngStream stream = new RngStream();
+
protected int id;
protected String mailbox;
protected String mailboxTracker;
if (bitfield[message.index] == '0') {
piecesRequested--;
//Removing the piece from our piece list.
- //TODO: It can not work, I should test it
if (!currentPieces.remove((Object)Integer.valueOf(message.index))) {
}
//Setting the fact that we have the piece
Msg.debug("My status is now " + getStatus());
//Sending the information to all the peers we are connected to
sendHave(message.index);
- //sending UNINTERSTED to peers that doesn't have what we want.
+ //sending UNINTERESTED to peers that doesn't have what we want.
updateInterestedAfterReceive();
}
else {
if (true || pieces < 3) {
int i = 0, peerPiece;
do {
- currentPiece = ((int)Msg.getClock() + id + i) % Common.FILE_PIECES;
+ currentPiece = stream.randInt(0,Common.FILE_PIECES - 1);
i++;
} while (!(bitfield[currentPiece] == '0' && !currentPieces.contains(currentPiece)));
}
Connection peerChoosed = null;
do {
i = 0;
- int idChosen = ((int)Msg.getClock() + j) % peers.size();
+ int idChosen = stream.randInt(0,peers.size() - 1);
for (Connection connection : peers.values()) {
if (i == idChosen) {
peerChoosed = connection;
peerChoosed = null;
}
j++;
- } while (peerChoosed == null && j < Common.MAXIMUM_PAIRS);
+ } while (peerChoosed == null && j <
+Common.MAXIMUM_PEERS);
if (peerChoosed != null) {
activePeers.put(peerChoosed.id,peerChoosed);
peerChoosed.chokedUpload = false;
sendUnchoked(peerChoosed.mailbox);
}
}
+ //TODO: Use the leecher choke algorithm.
}
/**
* Updates our "interested" state about peers: send "not interested" to peers