2 * Copyright 2006-2012. The SimGrid Team. 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 import org.simgrid.msg.Msg;
11 public class Connection {
17 * Remote peer bitfield.
19 public char bitfield[];
23 public String mailbox;
25 * Indicates if we are interested in something this peer has
27 public boolean amInterested = false;
29 * Indicates if the peer is interested in one of our pieces
31 public boolean interested = false;
33 * Indicates if the peer is choked for the current peer
35 public boolean chokedUpload = true;
37 * Indicates if the peer has choked the current peer
39 public boolean chokedDownload = true;
41 * Number of messages we have received from the peer
43 public int messagesCount = 0;
47 public double peerSpeed = 0;
49 * Last time the peer was unchoked
51 public double lastUnchoke = 0;
55 public Connection(int id) {
57 this.mailbox = Integer.toString(id);
60 * Add a new value to the peer speed average
62 public void addSpeedValue(double speed) {
63 peerSpeed = peerSpeed * 0.55 + speed * 0.45;
64 // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount);
68 public String toString() {
69 return "Connection [id=" + id + ", bitfield="
70 + Arrays.toString(bitfield) + ", mailbox=" + mailbox
71 + ", amInterested=" + amInterested + ", interested="
72 + interested + ", chokedUpload=" + chokedUpload
73 + ", chokedDownload=" + chokedDownload + "]";