Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename two more files in msg/app-bittorrent/.
[simgrid.git] / teshsuite / msg / app-bittorrent / 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   unsigned int bitfield;
47   int index;
48   int block_index;
49   int block_length;
50 } s_message_t;
51 typedef s_message_t* message_t;
52
53 /** Builds a new value-less message */
54 msg_task_t task_message_new(e_message_type type, const char* issuer_host_name, const char* mailbox, int peer_id,
55                             int size);
56 /** Builds a new "have/piece" message */
57 msg_task_t task_message_index_new(e_message_type type, const char* issuer_host_name, const char* mailbox, int peer_id,
58                                   int index, int varsize);
59 /** Builds a new bitfield message */
60 msg_task_t task_message_bitfield_new(const char* issuer_host_name, const char* mailbox, int peer_id,
61                                      unsigned int bitfield, int bitfield_size);
62 /** Builds a new "request" message */
63 msg_task_t task_message_request_new(const char* issuer_host_name, const char* mailbox, int peer_id, int index,
64                                     int block_index, int block_length);
65 /** Build a new "piece" message */
66 msg_task_t task_message_piece_new(const char* issuer_host_name, const char* mailbox, int peer_id, int index,
67                                   int block_index, int block_length, int block_size);
68 /** Free a message task */
69 void task_message_free(void*);
70 int task_message_size(e_message_type type);
71
72 #endif /* BITTORRENT_MESSAGES_H_ */