Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bugfix in Bittorrent example
[simgrid.git] / examples / bittorrent / Connection.java
1 package bittorrent;
2
3 import java.util.Arrays;
4 import org.simgrid.msg.Msg;
5 public class Connection {
6         /**
7          * Remote peer id
8          */
9         public int id;
10         /**
11          * Remote peer bitfield.
12          */
13         public char bitfield[];
14         /**
15          * Remote peer mailbox
16          */
17         public String mailbox;
18         /**
19          * Indicates if we are interested in something this peer has
20          */
21         public boolean amInterested = false;
22         /**
23          * Indicates if the peer is interested in one of our pieces
24          */
25         public boolean interested = false;
26         /**
27          * Indicates if the peer is choked for the current peer
28          */
29         public boolean chokedUpload = true;
30         /**
31          * Indicates if the peer has choked the current peer
32          */
33         public boolean chokedDownload = true;
34         /**
35          * Number of messages we have received from the peer
36          */
37         public int messagesCount = 0;
38         /**
39          * Peer speed.
40          */
41         public double peerSpeed = 0;
42         /**
43          * Last time the peer was unchoked
44          */
45         public double lastUnchoke = 0;
46         /**
47          * Constructor
48          */
49         public Connection(int id) {
50                 this.id = id;
51                 this.mailbox = Integer.toString(id);
52         }
53         /**
54          * Add a new value to the peer speed average
55          */
56         public void addSpeedValue(double speed) {
57                 peerSpeed = peerSpeed * 0.55 + speed * 0.45;
58                 //              peerSpeed = (peerSpeed * messagesCount + speed) / (++messagesCount);            
59         }
60                 
61         @Override
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 + "]";
68         }
69         
70         
71 }
72