Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
clean user guide
[simgrid.git] / examples / msg / bittorrent / messages.h
1 /* Copyright (c) 2012. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef BITTORRENT_MESSAGES_H_
8 #define BITTORRENT_MESSAGES_H_
9 #include <msg/msg.h>
10 /**
11  * Types of messages exchanged between two peers.
12  */
13 typedef enum {
14   MESSAGE_HANDSHAKE,
15   MESSAGE_CHOKE,
16   MESSAGE_UNCHOKE,
17   MESSAGE_INTERESTED,
18   MESSAGE_NOTINTERESTED,
19   MESSAGE_HAVE,
20   MESSAGE_BITFIELD,
21   MESSAGE_REQUEST,
22   MESSAGE_PIECE
23 } e_message_type;
24
25 /**
26  * Message data
27  */
28 typedef struct s_message {
29   e_message_type type;
30   const char *mailbox;
31   const char *issuer_host_name;
32   int peer_id;
33   char *bitfield;
34   int index;
35   int block_index;
36   int block_length;
37   int stalled:1;
38 } s_message_t, *message_t;
39 /**
40  * Builds a new value-less message
41  */
42 msg_task_t task_message_new(e_message_type type,
43                                        const char *issuer_host_name,
44                                        const char *mailbox, int peer_id);
45 /**
46  * Builds a new "have/piece" message
47  */
48 msg_task_t task_message_index_new(e_message_type type,
49                                              const char *issuer_host_name,
50                                              const char *mailbox, int peer_id,
51                                              int index);
52 /**
53  * Builds a new bitfield message
54  */
55 msg_task_t task_message_bitfield_new(const char *issuer_host_name,
56                                      const char *mailbox, int peer_id,
57                                      char *bitfield);
58 /**
59  * Builds a new "request" message
60  */
61 msg_task_t task_message_request_new(const char *issuer_host_name,
62                                     const char *mailbox, int peer_id, int index,
63                                     int block_index, int block_length);
64
65 /**
66  * Build a new "piece" message
67  */
68 msg_task_t task_message_piece_new(const char *issuer_host_name,
69                                   const char *mailbox, int peer_id, int index,
70                                   int stalled, int block_index,
71                                   int block_length);
72 /**
73  * Free a message task
74  */
75 void task_message_free(void *);
76 #endif                          /* BITTORRENT_MESSAGES_H_ */