Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update bittorrent 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 int blockIndex;
26         public int blockLength;
27         public boolean stalled;
28         /**
29          * Constructor, builds a value-less message
30          * @param type
31          * @param issuerHostname
32          * @param mailbox
33          * @param peerId
34          */
35         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId) {
36                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
37         }
38         /**
39          * Constructor, builds a new "have/request/piece" message
40          * @param type
41          * @param issuerHostname
42          * @param mailbox
43          * @param peerId
44          * @param index
45          */
46         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index) {
47                 this(type,issuerHostname,mailbox,peerId,index,false,-1,-1);
48         }
49         /**
50          * Constructor, builds a new bitfield message
51          */
52         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, char bitfield[]) {
53                 this(type,issuerHostname,mailbox,peerId,-1,false,-1,-1);
54                 this.bitfield = bitfield;
55         }
56         /**
57          * Constructor, build a new "request"  message
58          */
59         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, int blockIndex, int blockLength) {
60                 this(type,issuerHostname,mailbox,peerId,index,false,blockIndex,blockLength);
61         }
62         /**
63          * Constructor, build a new "piece" message
64          */
65         public MessageTask(Type type, String issuerHostname, String mailbox, int peerId, int index, boolean stalled, int blockIndex, int blockLength) {
66                 this.type = type;
67                 this.issuerHostname = issuerHostname;
68                 this.mailbox = mailbox;
69                 this.peerId = peerId;
70                 this.index = index;
71                 this.stalled = stalled;
72                 this.blockIndex = blockIndex;
73                 this.blockLength = blockLength;
74         }       
75 }