Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't override CMAKE_C_FLAGS!
[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         connection_t connection = xbt_new(s_connection_t,1);
13
14         connection->id = id;
15         connection->mailbox = bprintf("%d",id);
16         connection->bitfield = NULL;
17         connection->interested = 0;
18         connection->am_interested = 0;
19         connection->choked_upload = 1;
20         connection->choked_download = 1;
21         connection->peer_speed = 0;
22         connection->last_unchoke = 0;
23
24         return connection;
25 }
26 void connection_add_speed_value(connection_t connection, double speed) {
27   connection->peer_speed = connection->peer_speed * 0.6 + speed * 0.4;
28 }
29 void connection_free(void *data) {
30         connection_t co = (connection_t)data;
31         xbt_free(co->bitfield);
32         xbt_free(co->mailbox);
33         xbt_free(co);
34
35 }