1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 import java.util.Arrays;
10 public class Connection {
16 * Remote peer bitfield.
18 public char bitfield[];
22 public String mailbox;
24 * Indicates if we are interested in something this peer has
26 public boolean amInterested = false;
28 * Indicates if the peer is interested in one of our pieces
30 public boolean interested = false;
32 * Indicates if the peer is choked for the current peer
34 public boolean chokedUpload = true;
36 * Indicates if the peer has choked the current peer
38 public boolean chokedDownload = true;
40 * Number of messages we have received from the peer
42 public int messagesCount = 0;
46 public double peerSpeed = 0;
48 * Last time the peer was unchoked
50 public double lastUnchoke = 0;
54 public Connection(int id) {
56 this.mailbox = Integer.toString(id);
59 * Add a new value to the peer speed average
61 public void addSpeedValue(double speed) {
62 peerSpeed = peerSpeed * 0.55 + speed * 0.45;
63 // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount);
67 public String toString() {
68 return "Connection [id=" + id + ", bitfield="
69 + Arrays.toString(bitfield) + ", mailbox=" + mailbox
70 + ", amInterested=" + amInterested + ", interested="
71 + interested + ", chokedUpload=" + chokedUpload
72 + ", chokedDownload=" + chokedDownload + "]";