~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to examples/msg/bittorrent/peer.h

  • Committer: Package Import Robot
  • Author(s): Martin Quinson
  • Date: 2013-01-31 00:24:51 UTC
  • mfrom: (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130131002451-krejhf7w7h24lpsc
Tags: 3.9~rc1-1
* New upstream release: the "Grasgory" release. Major changes:
  - Gras was completely removed from this version.
  - Documentation reorganization to ease browsing it.
  - New default value for the TCP_gamma parameter: 4MiB

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_PEER_H
 
7
#define BITTORRENT_PEER_H
 
8
#include <msg/msg.h>
 
9
#include <xbt/dict.h>
 
10
#include <xbt/dynar.h>
 
11
#include <xbt/RngStream.h>
 
12
#include "connection.h"
 
13
#include "bittorrent.h"
 
14
 
 
15
/**
 
16
 * Peer data
 
17
 */
 
18
typedef struct s_peer {
 
19
  int id;                       //peer id
 
20
 
 
21
  int pieces;                   //number of pieces the peer has.
 
22
  char *bitfield;               //list of pieces the peer has.
 
23
  char *bitfield_blocks;        //list of blocks the peer has.
 
24
  short *pieces_count;          //number of peers that have each piece.
 
25
 
 
26
  xbt_dynar_t current_pieces;   //current pieces the peer is downloading
 
27
  int current_piece;            //current pieces
 
28
  int pieces_requested;         //number of pieces the peer has requested
 
29
 
 
30
  xbt_dict_t peers;             //peers list
 
31
  xbt_dict_t active_peers;      //active peers list
 
32
 
 
33
  char mailbox[MAILBOX_SIZE];   //peer mailbox.
 
34
  char mailbox_tracker[MAILBOX_SIZE];   //pair mailbox while communicating with the tracker.
 
35
  const char *hostname;         //peer hostname
 
36
 
 
37
  msg_task_t task_received;     //current task being received
 
38
  msg_comm_t comm_received;     //current comm
 
39
 
 
40
  int round;                    //current round for the chocking algortihm.
 
41
 
 
42
  RngStream stream;             //RngStream for
 
43
 
 
44
  double begin_receive_time;    //time when the receiving communication has begun, useful for calculating host speed.
 
45
 
 
46
  xbt_dynar_t pending_sends;    // list of sends being delivered
 
47
} s_peer_t, *peer_t;
 
48
 
 
49
/**
 
50
 * Peer main function
 
51
 */
 
52
int peer(int argc, char *argv[]);
 
53
 
 
54
int get_peers_data(peer_t peer);
 
55
void leech_loop(peer_t peer, double deadline);
 
56
void seed_loop(peer_t peer, double deadline);
 
57
 
 
58
void peer_init(peer_t, int id, int seed);
 
59
void peer_free(peer_t peer);
 
60
 
 
61
int has_finished(char *bitfield);
 
62
 
 
63
void handle_pending_sends(peer_t peer);
 
64
void handle_message(peer_t peer, msg_task_t task);
 
65
 
 
66
void wait_for_pieces(peer_t peer, double deadline);
 
67
 
 
68
void update_pieces_count_from_bitfield(peer_t peer, char *bitfield);
 
69
void update_current_piece(peer_t peer);
 
70
void update_choked_peers(peer_t peer);
 
71
 
 
72
void update_interested_after_receive(peer_t peer);
 
73
 
 
74
void update_bitfield_blocks(peer_t peer, int index, int block_index,
 
75
                            int block_length);
 
76
int piece_complete(peer_t peer, int index);
 
77
int get_first_block(peer_t peer, int piece);
 
78
 
 
79
 
 
80
void send_requests_to_peer(peer_t peer, connection_t remote_peer);
 
81
 
 
82
void send_interested_to_peers(peer_t peer);
 
83
void send_handshake_all(peer_t peer);
 
84
 
 
85
void send_interested(peer_t peer, const char *mailbox);
 
86
 
 
87
void send_notinterested(peer_t peer, const char *mailbox);
 
88
void send_handshake(peer_t peer, const char *mailbox);
 
89
void send_bitfield(peer_t peer, const char *mailbox);
 
90
void send_choked(peer_t peer, const char *mailbox);
 
91
void send_unchoked(peer_t peer, const char *mailbox);
 
92
void send_have(peer_t peer, int piece);
 
93
 
 
94
void send_request(peer_t peer, const char *mailbox, int piece, int block_index,
 
95
                  int block_length);
 
96
void send_piece(peer_t peer, const char *mailbox, int piece, int stalled,
 
97
                int block_index, int block_length);
 
98
 
 
99
int in_current_pieces(peer_t peer, int piece);
 
100
#endif                          /* BITTORRENT_PEER_H */