1 /* Copyright (c) 2012. 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;
56 } s_message_t, *message_t;
58 * Builds a new value-less message
60 msg_task_t task_message_new(e_message_type type,
61 const char *issuer_host_name,
62 const char *mailbox, int peer_id,
65 * Builds a new "have/piece" message
67 msg_task_t task_message_index_new(e_message_type type,
68 const char *issuer_host_name,
69 const char *mailbox, int peer_id,
70 int index, int varsize);
72 * Builds a new bitfield message
74 msg_task_t task_message_bitfield_new(const char *issuer_host_name,
75 const char *mailbox, int peer_id,
76 char *bitfield, int bitfield_size);
78 * Builds a new "request" message
80 msg_task_t task_message_request_new(const char *issuer_host_name,
81 const char *mailbox, int peer_id, int index,
82 int block_index, int block_length);
85 * Build a new "piece" message
87 msg_task_t task_message_piece_new(const char *issuer_host_name,
88 const char *mailbox, int peer_id, int index,
89 int stalled, int block_index,
90 int block_length, int block_size);
94 void task_message_free(void *);
96 int task_message_size(e_message_type type);
97 #endif /* BITTORRENT_MESSAGES_H_ */