1 /* Copyright (c) 2012-2016. 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_
9 #include <simgrid/msg.h>
12 * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective
13 * http://hal.inria.fr/inria-00000156/en
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
26 /** Types of messages exchanged between two peers. */
32 MESSAGE_NOTINTERESTED,
41 typedef struct s_message {
44 const char *issuer_host_name;
50 } s_message_t, *message_t;
52 /** Builds a new value-less message */
53 msg_task_t task_message_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id,
55 /** Builds a new "have/piece" message */
56 msg_task_t task_message_index_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id,
57 int index, int varsize);
58 /** Builds a new bitfield message */
59 msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id, char *bitfield,
61 /** Builds a new "request" message */
62 msg_task_t task_message_request_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index,
63 int block_index, int block_length);
64 /** Build a new "piece" message */
65 msg_task_t task_message_piece_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index,
66 int block_index, int block_length, int block_size);
67 /** Free a message task */
68 void task_message_free(void *);
69 int task_message_size(e_message_type type);
71 #endif /* BITTORRENT_MESSAGES_H_ */