Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disable mmalloc_test when !HAVE_MMAP, since mmalloc is not compiled in.
[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 /**
12  * Message sizes
13  */
14 #define MESSAGE_HANDSHAKE_SIZE 68
15 #define MESSAGE_CHOKE_SIZE 5
16 #define MESSAGE_UNCHOKE_SIZE 5
17 #define MESSAGE_INTERESTED_SIZE 5
18 #define MESSAGE_NOTINTERESTED_SIZE 5
19 #define MESSAGE_HAVE_SIZE 9
20 #define MESSAGE_BITFIELD_SIZE 5
21 #define MESSAGE_REQUEST_SIZE 17
22 #define MESSAGE_PIECE_SIZE 13
23 #define MESSAGE_CANCEL_SIZE 17
24
25 /**
26  * Types of messages exchanged between two peers.
27  */
28 typedef enum {
29   MESSAGE_HANDSHAKE,
30   MESSAGE_CHOKE,
31   MESSAGE_UNCHOKE,
32   MESSAGE_INTERESTED,
33   MESSAGE_NOTINTERESTED,
34   MESSAGE_HAVE,
35   MESSAGE_BITFIELD,
36   MESSAGE_REQUEST,
37   MESSAGE_PIECE
38 } e_message_type;
39
40 /**
41  * Message data
42  */
43 typedef struct s_message {
44   e_message_type type;
45   const char *mailbox;
46   const char *issuer_host_name;
47   int peer_id;
48   char *bitfield;
49   int index;
50   int block_index;
51   int block_length;
52   int stalled:1;
53 } s_message_t, *message_t;
54 /**
55  * Builds a new value-less message
56  */
57 msg_task_t task_message_new(e_message_type type,
58                                        const char *issuer_host_name,
59                                        const char *mailbox, int peer_id, 
60                                        int size);
61 /**
62  * Builds a new "have/piece" message
63  */
64 msg_task_t task_message_index_new(e_message_type type,
65                                              const char *issuer_host_name,
66                                              const char *mailbox, int peer_id,
67                                              int index, int varsize);
68 /**
69  * Builds a new bitfield message
70  */
71 msg_task_t task_message_bitfield_new(const char *issuer_host_name,
72                                      const char *mailbox, int peer_id,
73                                      char *bitfield, int bitfield_size);
74 /**
75  * Builds a new "request" message
76  */
77 msg_task_t task_message_request_new(const char *issuer_host_name,
78                                     const char *mailbox, int peer_id, int index,
79                                     int block_index, int block_length);
80
81 /**
82  * Build a new "piece" message
83  */
84 msg_task_t task_message_piece_new(const char *issuer_host_name,
85                                   const char *mailbox, int peer_id, int index,
86                                   int stalled, int block_index,
87                                   int block_length, int block_size);
88 /**
89  * Free a message task
90  */
91 void task_message_free(void *);
92
93 int task_message_size(e_message_type type);
94 #endif                          /* BITTORRENT_MESSAGES_H_ */