1 /* Copyright (c) 2006-2014, 2016. 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. */
7 package app.bittorrent;
8 import java.util.Arrays;
10 public class Connection {
12 protected char bitfield[];
13 protected String mailbox;
14 // Indicates if we are interested in something this peer has
15 protected boolean amInterested = false;
16 // Indicates if the peer is interested in one of our pieces
17 protected boolean interested = false;
18 // Indicates if the peer is choked for the current peer
19 protected boolean chokedUpload = true;
20 // Indicates if the peer has choked the current peer
21 protected boolean chokedDownload = true;
22 // Number of messages we have received from the peer
23 protected int messagesCount = 0;
24 protected double peerSpeed = 0;
25 protected double lastUnchoke = 0;
27 public Connection(int id) {
29 this.mailbox = Integer.toString(id);
32 // Add a new value to the peer speed average
33 public void addSpeedValue(double speed) {
34 peerSpeed = peerSpeed * 0.55 + speed * 0.45;
35 // peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount);
39 public String toString() {
40 return "Connection [id=" + id + ", bitfield=" + Arrays.toString(bitfield) + ", mailbox=" + mailbox
41 + ", amInterested=" + amInterested + ", interested=" + interested + ", chokedUpload=" + chokedUpload
42 + ", chokedDownload=" + chokedDownload + "]";