Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / examples / msg / bittorrent / tracker.h
1 /* Copyright (c) 2012-2013. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef BITTORRENT_TRACKER_H_
8 #define BITTORRENT_TRACKER_H_
9 #include <xbt/dynar.h>
10 #include "bittorrent.h"
11 /**
12  * Tracker main function
13  */
14 int tracker(int argc, char *argv[]);
15 /**
16  * Task types exchanged between a node and the tracker
17  */
18 typedef enum {
19   TRACKER_TASK_QUERY,
20   TRACKER_TASK_ANSWER
21 } e_tracker_task_type_t;
22 /**
23  * Tasks exchanged between a tracker and peers.
24  */
25 typedef struct s_tracker_task_data {
26   e_tracker_task_type_t type;   //type of the task
27   const char *mailbox;          //mailbox where the tracker should answer
28   const char *issuer_host_name; //hostname, for debug purposes
29   //Query data
30   int peer_id;                  //peer id
31   int uploaded;                 //how much the peer has already uploaded
32   int downloaded;               //how much the peer has downloaded
33   int left;                     //how much the peer has left
34   //Answer data
35   int interval;                 //how often the peer should contact the tracker (unused for now)
36   xbt_dynar_t peers;            //the peer list the peer has asked for.
37 } s_tracker_task_data_t, *tracker_task_data_t;
38
39 tracker_task_data_t tracker_task_data_new(const char *issuer_host_name,
40                                           const char *mailbox, int peer_id,
41                                           int uploaded, int downloaded,
42                                           int left);
43 void tracker_task_data_free(tracker_task_data_t task);
44
45 int is_in_list(xbt_dynar_t peers, int id);
46 #endif                          /* BITTORRENT_TRACKER_H */