Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
342df0f800f357ac54aa5142b6a2ddd253c2e53c
[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 XBT_INLINE msg_task_t task_message_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id);
43 /**
44  * Builds a new "have/piece" message
45  */
46 XBT_INLINE msg_task_t task_message_index_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id, int index);
47 /**
48  * Builds a new bitfield message
49  */
50 msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id, char *bitfield);
51 /**
52  * Builds a new "request" message
53  */
54 msg_task_t task_message_request_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index, int block_index, int block_length);
55
56 /**
57  * Build a new "piece" message
58  */
59 msg_task_t task_message_piece_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index, int stalled, int block_index, int block_length);
60 /**
61  * Free a message task
62  */
63 void task_message_free(void*);
64 #endif /* BITTORRENT_MESSAGES_H_ */