Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent ... this time with the appropriate options
[simgrid.git] / examples / msg / bittorrent / messages.h
index 82515f7..46e166b 100644 (file)
@@ -7,6 +7,23 @@
 #ifndef BITTORRENT_MESSAGES_H_
 #define BITTORRENT_MESSAGES_H_
 #include <msg/msg.h>
+
+/**
+ * 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.
  */
@@ -19,7 +36,8 @@ typedef enum {
   MESSAGE_HAVE,
   MESSAGE_BITFIELD,
   MESSAGE_REQUEST,
-  MESSAGE_PIECE
+  MESSAGE_PIECE,
+  MESSAGE_CANCEL
 } e_message_type;
 
 /**
@@ -39,28 +57,29 @@ typedef struct s_message {
 /**
  * Builds a new value-less message
  */
-XBT_INLINE msg_task_t task_message_new(e_message_type type,
-                                       const char *issuer_host_name,
-                                       const char *mailbox, int peer_id);
+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
  */
-XBT_INLINE msg_task_t task_message_index_new(e_message_type type,
-                                             const char *issuer_host_name,
-                                             const char *mailbox, int peer_id,
-                                             int index);
+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);
+                                     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);
+                                    const char *mailbox, int peer_id,
+                                    int index, int block_index,
+                                    int block_length);
 
 /**
  * Build a new "piece" message
@@ -68,9 +87,11 @@ msg_task_t task_message_request_new(const char *issuer_host_name,
 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);
+                                  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_ */