1 /* Copyright (c) 2012-2013. 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. */
6 #include "connection.h"
7 #include "bittorrent.h"
8 #include <xbt/sysdep.h>
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg_peers);
11 connection_t connection_new(int id)
13 connection_t connection = xbt_new(s_connection_t, 1);
16 connection->mailbox = bprintf("%d", id);
17 connection->bitfield = NULL;
18 connection->current_piece = -1;
19 connection->interested = 0;
20 connection->am_interested = 0;
21 connection->choked_upload = 1;
22 connection->choked_download = 1;
23 connection->peer_speed = 0;
24 connection->last_unchoke = 0;
29 void connection_add_speed_value(connection_t connection, double speed)
31 connection->peer_speed = connection->peer_speed * 0.6 + speed * 0.4;
34 void connection_free(void *data)
36 connection_t co = (connection_t) data;
37 xbt_free(co->bitfield);
38 xbt_free(co->mailbox);