~ubuntu-branches/ubuntu/wily/libtorrent/wily-proposed

« back to all changes in this revision

Viewing changes to src/torrent/tracker_list.h

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2011-03-20 01:06:18 UTC
  • mfrom: (1.1.13 upstream) (4.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110320010618-g3wyylccqzqko73c
Tags: 0.12.7-5
* Use Steinar's "real" patch for IPv6. Addresses #490277, #618275,
  and Closes: #617791.
* Adapt libtorrent-0.12.6-ipv6-07.patch. It FTBFS otherwise.
* Add proper attibution to the IPv6 patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// libTorrent - BitTorrent library
 
2
// Copyright (C) 2005-2007, Jari Sundell
 
3
//
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 2 of the License, or
 
7
// (at your option) any later version.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
//
 
18
// In addition, as a special exception, the copyright holders give
 
19
// permission to link the code of portions of this program with the
 
20
// OpenSSL library under certain conditions as described in each
 
21
// individual source file, and distribute linked combinations
 
22
// including the two.
 
23
//
 
24
// You must obey the GNU General Public License in all respects for
 
25
// all of the code used other than OpenSSL.  If you modify file(s)
 
26
// with this exception, you may extend this exception to your version
 
27
// of the file(s), but you are not obligated to do so.  If you do not
 
28
// wish to do so, delete this exception statement from your version.
 
29
// If you delete this exception statement from all source files in the
 
30
// program, then also delete it here.
 
31
//
 
32
// Contact:  Jari Sundell <jaris@ifi.uio.no>
 
33
//
 
34
//           Skomakerveien 33
 
35
//           3185 Skoppum, NORWAY
 
36
 
 
37
#ifndef LIBTORRENT_TRACKER_LIST_H
 
38
#define LIBTORRENT_TRACKER_LIST_H
 
39
 
 
40
#include <algorithm>
 
41
#include <string>
 
42
#include <vector>
 
43
#include <torrent/common.h>
 
44
 
 
45
namespace torrent {
 
46
 
 
47
class AddressList;
 
48
class DownloadInfo;
 
49
class Tracker;
 
50
class TrackerManager;
 
51
 
 
52
// The tracker list will contain a list of tracker, divided into
 
53
// subgroups. Each group must be randomized before we start. When
 
54
// starting the tracker request, always start from the beginning and
 
55
// iterate if the request failed. Upon request success move the
 
56
// tracker to the beginning of the subgroup and start from the
 
57
// beginning of the whole list.
 
58
 
 
59
class LIBTORRENT_EXPORT TrackerList : private std::vector<Tracker*> {
 
60
public:
 
61
  friend class TrackerManager;
 
62
 
 
63
  typedef std::vector<Tracker*> base_type;
 
64
 
 
65
  using base_type::value_type;
 
66
 
 
67
  using base_type::iterator;
 
68
  using base_type::const_iterator;
 
69
  using base_type::reverse_iterator;
 
70
  using base_type::const_reverse_iterator;
 
71
  using base_type::size;
 
72
  using base_type::empty;
 
73
 
 
74
  using base_type::begin;
 
75
  using base_type::end;
 
76
  using base_type::rbegin;
 
77
  using base_type::rend;
 
78
 
 
79
  using base_type::at;
 
80
  using base_type::operator[];
 
81
 
 
82
  TrackerList(TrackerManager* manager);
 
83
 
 
84
  bool                has_active() const;
 
85
  bool                has_usable() const;
 
86
 
 
87
  void                close_all();
 
88
  void                clear();
 
89
 
 
90
  iterator            insert(unsigned int group, Tracker* t);
 
91
 
 
92
  void                send_state(int s);
 
93
 
 
94
  DownloadInfo*       info()                                  { return m_info; }
 
95
  int                 state()                                 { return m_state; }
 
96
 
 
97
  uint32_t            key() const                             { return m_key; }
 
98
  void                set_key(uint32_t key)                   { m_key = key; }
 
99
 
 
100
  int32_t             numwant() const                         { return m_numwant; }
 
101
  void                set_numwant(int32_t n)                  { m_numwant = n; }
 
102
 
 
103
  iterator            find(Tracker* tb)                       { return std::find(begin(), end(), tb); }
 
104
  iterator            find_usable(iterator itr);
 
105
  const_iterator      find_usable(const_iterator itr) const;
 
106
 
 
107
  iterator            begin_group(unsigned int group);
 
108
  iterator            end_group(unsigned int group)           { return begin_group(group + 1); }
 
109
  void                cycle_group(unsigned int group);
 
110
 
 
111
  iterator            promote(iterator itr);
 
112
  void                randomize_group_entries();
 
113
 
 
114
  uint32_t            time_next_connection() const;
 
115
  uint32_t            time_last_connection() const            { return m_timeLastConnection; }
 
116
 
 
117
  // Some temporary functions that are routed to
 
118
  // TrackerManager... Clean this up.
 
119
  void                send_completed();
 
120
 
 
121
  void                manual_request(bool force);
 
122
  void                manual_cancel();
 
123
 
 
124
  // Functions for controlling the current focus. They only support
 
125
  // one active tracker atm.
 
126
  iterator            focus()                                 { return m_itr; }
 
127
  const_iterator      focus() const                           { return m_itr; }
 
128
  uint32_t            focus_index() const                     { return m_itr - begin(); }
 
129
 
 
130
  bool                focus_next_group();
 
131
 
 
132
  uint32_t            focus_normal_interval() const;
 
133
  uint32_t            focus_min_interval() const;
 
134
 
 
135
  void                receive_success(Tracker* tb, AddressList* l);
 
136
  void                receive_failed(Tracker* tb, const std::string& msg);
 
137
 
 
138
protected:
 
139
  void                set_info(DownloadInfo* info)            { m_info = info; }
 
140
  void                set_state(int s)                        { m_state = s; }
 
141
 
 
142
  void                set_focus(iterator itr)                 { m_itr = itr; }
 
143
  void                set_time_last_connection(uint32_t v)    { m_timeLastConnection = v; }
 
144
 
 
145
private:
 
146
  TrackerList(const TrackerList&) LIBTORRENT_NO_EXPORT;
 
147
  void operator = (const TrackerList&) LIBTORRENT_NO_EXPORT;
 
148
 
 
149
  TrackerManager*     m_manager;
 
150
  DownloadInfo*       m_info;
 
151
  int                 m_state;
 
152
 
 
153
  uint32_t            m_key;
 
154
  int32_t             m_numwant;
 
155
 
 
156
  uint32_t            m_timeLastConnection;
 
157
 
 
158
  iterator            m_itr;
 
159
};
 
160
 
 
161
}
 
162
 
 
163
#endif