Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix rm
[simgrid.git] / examples / msg / bittorrent / messages.h
1 /* Copyright (c) 2012-2016. 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 <simgrid/msg.h>
10
11 /** Message sizes
12  * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective
13  * http://hal.inria.fr/inria-00000156/en
14  */
15 #define MESSAGE_HANDSHAKE_SIZE 68
16 #define MESSAGE_CHOKE_SIZE 5
17 #define MESSAGE_UNCHOKE_SIZE 5
18 #define MESSAGE_INTERESTED_SIZE 5
19 #define MESSAGE_NOTINTERESTED_SIZE 5
20 #define MESSAGE_HAVE_SIZE 9
21 #define MESSAGE_BITFIELD_SIZE 5
22 #define MESSAGE_REQUEST_SIZE 17
23 #define MESSAGE_PIECE_SIZE 13
24 #define MESSAGE_CANCEL_SIZE 17
25
26 /** Types of messages exchanged between two peers. */
27 typedef enum {
28   MESSAGE_HANDSHAKE,
29   MESSAGE_CHOKE,
30   MESSAGE_UNCHOKE,
31   MESSAGE_INTERESTED,
32   MESSAGE_NOTINTERESTED,
33   MESSAGE_HAVE,
34   MESSAGE_BITFIELD,
35   MESSAGE_REQUEST,
36   MESSAGE_PIECE,
37   MESSAGE_CANCEL
38 } e_message_type;
39
40 /** Message data */
41 typedef struct s_message {
42   e_message_type type;
43   const char *mailbox;
44   const char *issuer_host_name;
45   int peer_id;
46   char *bitfield;
47   int index;
48   int block_index;
49   int block_length;
50 } s_message_t, *message_t;
51
52 /** Builds a new value-less message */
53 msg_task_t task_message_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id,
54                             int size);
55 /** Builds a new "have/piece" message */
56 msg_task_t task_message_index_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id,
57                                   int index, int varsize);
58 /** Builds a new bitfield message */
59 msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id, char *bitfield,
60                                      int bitfield_size);
61 /** Builds a new "request" message */
62 msg_task_t task_message_request_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index,
63                                     int block_index, int block_length);
64 /** Build a new "piece" message */
65 msg_task_t task_message_piece_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index,
66                                   int block_index, int block_length, int block_size);
67 /** Free a message task */
68 void task_message_free(void *);
69 int task_message_size(e_message_type type);
70
71 #endif                          /* BITTORRENT_MESSAGES_H_ */