1
// libTorrent - BitTorrent library
2
// Copyright (C) 2005-2007, Jari Sundell
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.
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.
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
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
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.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
37
#ifndef LIBTORRENT_TRACKER_LIST_H
38
#define LIBTORRENT_TRACKER_LIST_H
43
#include <torrent/common.h>
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.
59
class LIBTORRENT_EXPORT TrackerList : private std::vector<Tracker*> {
61
friend class TrackerManager;
63
typedef std::vector<Tracker*> base_type;
65
using base_type::value_type;
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;
74
using base_type::begin;
76
using base_type::rbegin;
77
using base_type::rend;
80
using base_type::operator[];
82
TrackerList(TrackerManager* manager);
84
bool has_active() const;
85
bool has_usable() const;
90
iterator insert(unsigned int group, Tracker* t);
92
void send_state(int s);
94
DownloadInfo* info() { return m_info; }
95
int state() { return m_state; }
97
uint32_t key() const { return m_key; }
98
void set_key(uint32_t key) { m_key = key; }
100
int32_t numwant() const { return m_numwant; }
101
void set_numwant(int32_t n) { m_numwant = n; }
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;
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);
111
iterator promote(iterator itr);
112
void randomize_group_entries();
114
uint32_t time_next_connection() const;
115
uint32_t time_last_connection() const { return m_timeLastConnection; }
117
// Some temporary functions that are routed to
118
// TrackerManager... Clean this up.
119
void send_completed();
121
void manual_request(bool force);
122
void manual_cancel();
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(); }
130
bool focus_next_group();
132
uint32_t focus_normal_interval() const;
133
uint32_t focus_min_interval() const;
135
void receive_success(Tracker* tb, AddressList* l);
136
void receive_failed(Tracker* tb, const std::string& msg);
139
void set_info(DownloadInfo* info) { m_info = info; }
140
void set_state(int s) { m_state = s; }
142
void set_focus(iterator itr) { m_itr = itr; }
143
void set_time_last_connection(uint32_t v) { m_timeLastConnection = v; }
146
TrackerList(const TrackerList&) LIBTORRENT_NO_EXPORT;
147
void operator = (const TrackerList&) LIBTORRENT_NO_EXPORT;
149
TrackerManager* m_manager;
150
DownloadInfo* m_info;
156
uint32_t m_timeLastConnection;