Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add kademlia example
[simgrid.git] / examples / bittorrent / MessageTask.java
1 package bittorrent;
2
3 import org.simgrid.msg.Task;
4 /**
5  * Tasks sent between peers
6  */
7 public class MessageTask extends Task {
8         public enum Type {
9                 HANDSHAKE,
10                 CHOKE,
11                 UNCHOKE,
12                 INTERESTED,
13                 NOTINTERESTED,
14                 HAVE,
15                 BITFIELD,
16                 REQUEST,
17                 PIECE
18         };
19         public Type type;
20         public String issuerHostname;
21         public String mailbox;
22         public int peerId;
23         public char bitfield[];
24         public int index;
25         public boolean stalled;
26         /**
27          * Constructor, builds a value-less message
28          * @param type
29          * @param issuerHostname
30          * @param mailbox
31          * @param peerId
32          */
33         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
34                 this.type = type;
35                 this.issuerHostname = issuerHostname;
36                 this.mailbox = mailbox;
37                 this.peerId = peerId;
38         }
39         /**
40          * Constructor, builds a new "have/request/piece" message
41          * @param type
42          * @param issuerHostname
43          * @param mailbox
44          * @param peerId
45          * @param index
46          */
47         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) {
48                 this.type = type;
49                 this.issuerHostname = issuerHostname;
50                 this.mailbox = mailbox;
51                 this.peerId = peerId;
52                 this.index = index;
53         }
54         /**
55          * Constructor, builds a new bitfield message
56          * @param type
57          * @param issuerHostname
58          * @param mailbox
59          * @param peerId
60          * @param bitfield
61          */
62         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) {
63                 this.type = type;
64                 this.issuerHostname = issuerHostname;
65                 this.mailbox = mailbox;
66                 this.peerId = peerId;
67                 this.bitfield = bitfield;
68         }
69         /**
70          * Constructor, build a new "piece" message
71          * @param type
72          * @param issuerHostname
73          * @param mailbox
74          * @param peerId
75          * @param index
76          * @param stalled
77          */
78         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled) {
79                 this.type = type;
80                 this.issuerHostname = issuerHostname;
81                 this.mailbox = mailbox;
82                 this.peerId = peerId;
83                 this.index = index;
84                 this.stalled = stalled;
85         }       
86 }