X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0e45e2bf6e0e59b7e594df0cefa6954d9a94fe7f..ab8d6bf77b9aa74785b486fd5704e7fc63f25d66:/examples/msg/bittorrent/messages.h diff --git a/examples/msg/bittorrent/messages.h b/examples/msg/bittorrent/messages.h index 507364057a..98f140a163 100644 --- a/examples/msg/bittorrent/messages.h +++ b/examples/msg/bittorrent/messages.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012. The SimGrid Team. +/* Copyright (c) 2012-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -6,10 +6,24 @@ #ifndef BITTORRENT_MESSAGES_H_ #define BITTORRENT_MESSAGES_H_ -#include -/** - * Types of messages exchanged between two peers. +#include + +/** Message sizes + * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective + * http://hal.inria.fr/inria-00000156/en */ +#define MESSAGE_HANDSHAKE_SIZE 68 +#define MESSAGE_CHOKE_SIZE 5 +#define MESSAGE_UNCHOKE_SIZE 5 +#define MESSAGE_INTERESTED_SIZE 5 +#define MESSAGE_NOTINTERESTED_SIZE 5 +#define MESSAGE_HAVE_SIZE 9 +#define MESSAGE_BITFIELD_SIZE 5 +#define MESSAGE_REQUEST_SIZE 17 +#define MESSAGE_PIECE_SIZE 13 +#define MESSAGE_CANCEL_SIZE 17 + +/** Types of messages exchanged between two peers. */ typedef enum { MESSAGE_HANDSHAKE, MESSAGE_CHOKE, @@ -19,12 +33,11 @@ typedef enum { MESSAGE_HAVE, MESSAGE_BITFIELD, MESSAGE_REQUEST, - MESSAGE_PIECE + MESSAGE_PIECE, + MESSAGE_CANCEL } e_message_type; -/** - * Message data - */ +/** Message data */ typedef struct s_message { e_message_type type; const char *mailbox; @@ -34,43 +47,25 @@ typedef struct s_message { int index; int block_index; int block_length; - int stalled:1; } s_message_t, *message_t; -/** - * Builds a new value-less message - */ -msg_task_t task_message_new(e_message_type type, - const char *issuer_host_name, - const char *mailbox, int peer_id); -/** - * Builds a new "have/piece" message - */ -msg_task_t task_message_index_new(e_message_type type, - const char *issuer_host_name, - const char *mailbox, int peer_id, - int index); -/** - * Builds a new bitfield message - */ -msg_task_t task_message_bitfield_new(const char *issuer_host_name, - const char *mailbox, int peer_id, - char *bitfield); -/** - * Builds a new "request" message - */ -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); -/** - * Build a new "piece" message - */ -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); -/** - * Free a message task - */ +/** Builds a new value-less message */ +msg_task_t task_message_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id, + int size); +/** Builds a new "have/piece" message */ +msg_task_t task_message_index_new(e_message_type type, const char *issuer_host_name, const char *mailbox, int peer_id, + int index, int varsize); +/** Builds a new bitfield message */ +msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id, char *bitfield, + int bitfield_size); +/** Builds a new "request" message */ +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); +/** Build a new "piece" message */ +msg_task_t task_message_piece_new(const char *issuer_host_name, const char *mailbox, int peer_id, int index, + int block_index, int block_length, int block_size); +/** Free a message task */ void task_message_free(void *); +int task_message_size(e_message_type type); + #endif /* BITTORRENT_MESSAGES_H_ */