3 import java.util.Arrays;
4 import org.simgrid.msg.Msg;
5 public class Connection {
11 * Remote peer bitfield.
13 public char bitfield[];
17 public String mailbox;
19 * Indicates if we are interested in something this peer has
21 public boolean amInterested = false;
23 * Indicates if the peer is interested in one of our pieces
25 public boolean interested = false;
27 * Indicates if the peer is choked for the current peer
29 public boolean chokedUpload = true;
31 * Indicates if the peer has choked the current peer
33 public boolean chokedDownload = true;
35 * Number of messages we have received from the peer
37 public int messagesCount = 0;
41 public double peerSpeed = 0;
43 * Last time the peer was unchoked
45 public double lastUnchoke = 0;
49 public Connection(int id) {
51 this.mailbox = Integer.toString(id);
54 * Add a new value to the peer speed average
56 public void addSpeedValue(double speed) {
57 peerSpeed = peerSpeed * 0.55 + speed * 0.45;
58 // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount);
62 public String toString() {
63 return "Connection [id=" + id + ", bitfield="
64 + Arrays.toString(bitfield) + ", mailbox=" + mailbox
65 + ", amInterested=" + amInterested + ", interested="
66 + interested + ", chokedUpload=" + chokedUpload
67 + ", chokedDownload=" + chokedDownload + "]";