1 /* Copyright (c) 2012-2013. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef BITTORRENT_MESSAGES_H_
8 #define BITTORRENT_MESSAGES_H_
13 * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective
14 * http://hal.inria.fr/inria-00000156/en
16 #define MESSAGE_HANDSHAKE_SIZE 68
17 #define MESSAGE_CHOKE_SIZE 5
18 #define MESSAGE_UNCHOKE_SIZE 5
19 #define MESSAGE_INTERESTED_SIZE 5
20 #define MESSAGE_NOTINTERESTED_SIZE 5
21 #define MESSAGE_HAVE_SIZE 9
22 #define MESSAGE_BITFIELD_SIZE 5
23 #define MESSAGE_REQUEST_SIZE 17
24 #define MESSAGE_PIECE_SIZE 13
25 #define MESSAGE_CANCEL_SIZE 17
28 * Types of messages exchanged between two peers.
35 MESSAGE_NOTINTERESTED,
46 typedef struct s_message {
49 const char *issuer_host_name;
55 } s_message_t, *message_t;
57 * Builds a new value-less message
59 msg_task_t task_message_new(e_message_type type,
60 const char *issuer_host_name,
61 const char *mailbox, int peer_id, int size);
63 * Builds a new "have/piece" message
65 msg_task_t task_message_index_new(e_message_type type,
66 const char *issuer_host_name,
67 const char *mailbox, int peer_id,
68 int index, int varsize);
70 * Builds a new bitfield message
72 msg_task_t task_message_bitfield_new(const char *issuer_host_name,
73 const char *mailbox, int peer_id,
74 char *bitfield, int bitfield_size);
76 * Builds a new "request" message
78 msg_task_t task_message_request_new(const char *issuer_host_name,
79 const char *mailbox, int peer_id,
80 int index, int block_index,
84 * Build a new "piece" message
86 msg_task_t task_message_piece_new(const char *issuer_host_name,
87 const char *mailbox, int peer_id, int index,
89 int block_length, int block_size);
93 void task_message_free(void *);
95 int task_message_size(e_message_type type);
96 #endif /* BITTORRENT_MESSAGES_H_ */