1 /* Copyright (c) 2012-2014, 2016. 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_CONNECTION_H_
8 #define BITTORRENT_CONNECTION_H_
10 /** Contains the connection data of a peer. */
11 typedef struct s_connection {
13 unsigned int bitfield; // Fields
19 unsigned int am_interested : 1; // Indicates if we are interested in something the peer has
20 unsigned int interested : 1; // Indicates if the peer is interested in one of our pieces
21 unsigned int choked_upload : 1; // Indicates if the peer is choked for the current peer
22 unsigned int choked_download : 1; // Indicates if the peer has choked the current peer
25 typedef s_connection_t* connection_t;
27 /** @brief Build a new connection object from the peer id.
28 * @param id id of the peer
30 connection_t connection_new(int id);
31 /** @brief Add a new value to the peer speed average
32 * @param connection connection data
33 * @param speed speed to add to the speed average
35 void connection_add_speed_value(connection_t connection, double speed);
36 /** Frees a connection object */
37 void connection_free(void* data);
38 int connection_has_piece(connection_t connection, unsigned int piece);
39 #endif /* BITTORRENT_CONNECTION_H_ */