1 /* Copyright (c) 2012-2018. 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;
46 unsigned int bitfield;
51 typedef s_message_t* message_t;
53 /** Builds a new value-less message */
54 msg_task_t task_message_new(e_message_type type, const char* issuer_host_name, const char* mailbox, int peer_id,
56 /** Builds a new "have/piece" message */
57 msg_task_t task_message_index_new(e_message_type type, const char* issuer_host_name, const char* mailbox, int peer_id,
58 int index, int varsize);
59 /** Builds a new bitfield message */
60 msg_task_t task_message_bitfield_new(const char* issuer_host_name, const char* mailbox, int peer_id,
61 unsigned int bitfield, int bitfield_size);
62 /** Builds a new "request" message */
63 msg_task_t task_message_request_new(const char* issuer_host_name, const char* mailbox, int peer_id, int index,
64 int block_index, int block_length);
65 /** Build a new "piece" message */
66 msg_task_t task_message_piece_new(const char* issuer_host_name, const char* mailbox, int peer_id, int index,
67 int block_index, int block_length, int block_size);
68 /** Free a message task */
69 void task_message_free(void*);
70 int task_message_size(e_message_type type);
72 #endif /* BITTORRENT_MESSAGES_H_ */