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_DOWNLOAD_H
38
#define LIBTORRENT_DOWNLOAD_H
43
#include <sigc++/connection.h>
44
#include <sigc++/functors/slot.h>
46
#include <torrent/common.h>
47
#include <torrent/peer/peer.h>
54
// Download is safe to copy and destory as it is just a pointer to an
57
class LIBTORRENT_EXPORT Download {
59
static const uint32_t numwanted_diabled = ~uint32_t();
61
// Start and open flags can be stored in the same integer, same for
62
// stop and close flags.
63
static const int open_enable_fallocate = (1 << 0);
65
static const int start_no_create = (1 << 1);
66
static const int start_keep_baseline = (1 << 2);
67
static const int start_skip_tracker = (1 << 3);
69
static const int stop_skip_tracker = (1 << 0);
71
Download(DownloadWrapper* d = NULL) : m_ptr(d) {}
73
const DownloadInfo* info() const;
75
// Not active atm. Opens and prepares/closes the files.
76
void open(int flags = 0);
77
void close(int flags = 0);
79
// When 'tryQuick' is true, it will only check if the chunks can be
80
// mmaped and stops if one is encountered. If it doesn't find any
81
// mappable chunks it will return true to indicate that it is
82
// finished and a hash done signal has been queued.
84
// Chunk ranges that have valid resume data won't be checked.
85
bool hash_check(bool tryQuick);
88
// Start/stop the download. The torrent must be open.
89
void start(int flags = 0);
90
void stop(int flags = 0);
92
// Does not check if the download has been removed.
93
bool is_valid() const { return m_ptr; }
95
bool is_hash_checked() const;
96
bool is_hash_checking() const;
98
void set_pex_enabled(bool enabled);
101
const Object* bencode() const;
103
TrackerList* tracker_list() const;
105
FileList* file_list() const;
106
PeerList* peer_list();
107
const PeerList* peer_list() const;
108
const TransferList* transfer_list() const;
110
ConnectionList* connection_list();
111
const ConnectionList* connection_list() const;
114
uint64_t bytes_done() const;
116
uint32_t chunks_hashed() const;
118
const uint8_t* chunks_seen() const;
120
// Set the number of finished chunks for closed torrents.
121
void set_chunks_done(uint32_t chunks);
123
// Use the below to set the resume data and what chunk ranges need
124
// to be hash checked. If they arn't called then by default it will
125
// use an cleared bitfield and check the whole range.
127
// These must be called when is_open, !is_checked and !is_checking.
128
void set_bitfield(bool allSet);
129
void set_bitfield(uint8_t* first, uint8_t* last);
131
static const int update_range_recheck = (1 << 0);
132
static const int update_range_clear = (1 << 1);
134
void update_range(int flags, uint32_t first, uint32_t last);
136
// Temporary hack for syncing chunks to disk before hash resume is
140
uint32_t peers_complete() const;
141
uint32_t peers_accounted() const;
143
uint32_t peers_currently_unchoked() const;
144
uint32_t peers_currently_interested() const;
146
uint32_t size_pex() const;
147
uint32_t max_size_pex() const;
149
bool accepting_new_peers() const;
150
uint32_t uploads_max() const;
152
void set_uploads_max(uint32_t v);
154
void set_upload_throttle(Throttle* t);
155
void set_download_throttle(Throttle* t);
160
CONNECTION_INITIAL_SEED,
164
ConnectionType connection_type() const;
165
void set_connection_type(ConnectionType t);
167
// Call this when you want the modifications of the download priorities
168
// in the entries to take effect. It is slightly expensive as it rechecks
169
// all the peer bitfields to see if we are still interested.
170
void update_priorities();
172
void add_peer(const sockaddr* addr, int port);
174
DownloadWrapper* ptr() { return m_ptr; }
177
DownloadWrapper* m_ptr;