Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reindent.
[simgrid.git] / examples / msg / bittorrent / connection.c
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 #include "connection.h"
7 #include "bittorrent.h"
8 #include <xbt/sysdep.h>
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg_peers);
10
11 connection_t connection_new(int id)
12 {
13   connection_t connection = xbt_new(s_connection_t, 1);
14
15   connection->id = id;
16   connection->mailbox = bprintf("%d", id);
17   connection->bitfield = NULL;
18   connection->interested = 0;
19   connection->am_interested = 0;
20   connection->choked_upload = 1;
21   connection->choked_download = 1;
22   connection->peer_speed = 0;
23   connection->last_unchoke = 0;
24
25   return connection;
26 }
27
28 void connection_add_speed_value(connection_t connection, double speed)
29 {
30   connection->peer_speed = connection->peer_speed * 0.6 + speed * 0.4;
31 }
32
33 void connection_free(void *data)
34 {
35   connection_t co = (connection_t) data;
36   xbt_free(co->bitfield);
37   xbt_free(co->mailbox);
38   xbt_free(co);
39
40 }