Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c2cb1264d60e76a7ba50c84412db18bbb5565e89
[simgrid.git] / examples / msg / bittorrent / connection.h
1 /* Copyright (c) 2012. 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 #ifndef BITTORRENT_CONNECTION_H_
7 #define BITTORRENT_CONNECTION_H_
8 /**
9  * Contains the connection data of a peer.
10  */
11 typedef struct s_connection {
12   int id;                       //Peer id
13   char *bitfield;               //Fields
14   char *mailbox;
15   int messages_count;
16   double peer_speed;
17   double last_unchoke;
18   int current_piece;
19   int am_interested:1;          //Indicates if we are interested in something the peer has
20   int interested:1;             //Indicates if the peer is interested in one of our pieces
21   int choked_upload:1;          //Indicates if the peer is choked for the current peer
22   int choked_download:1;        //Indicates if the peer has choked the current peer
23 } s_connection_t, *connection_t;
24 /**
25  * Build a new connection object from the peer id.
26  * @param id id of the peer
27  */
28 connection_t connection_new(int id);
29 /**
30  * Add a new value to the peer speed average
31  * @param connection connection data
32  * @param speed speed to add to the speed average
33  */
34 void connection_add_speed_value(connection_t connection, double speed);
35 /**
36  * Frees a connection object
37  */
38 void connection_free(void *data);
39 #endif /* BITTORRENT_CONNECTION_H_ */