~ubuntu-branches/ubuntu/oneiric/libtorrent/oneiric

« back to all changes in this revision

Viewing changes to src/torrent/download.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_DOWNLOAD_H
 
38
#define LIBTORRENT_DOWNLOAD_H
 
39
 
 
40
#include <list>
 
41
#include <vector>
 
42
#include <string>
 
43
#include <sigc++/connection.h>
 
44
#include <sigc++/functors/slot.h>
 
45
 
 
46
#include <torrent/common.h>
 
47
#include <torrent/peer/peer.h>
 
48
 
 
49
namespace torrent {
 
50
 
 
51
class ConnectionList;
 
52
class DownloadInfo;
 
53
 
 
54
// Download is safe to copy and destory as it is just a pointer to an
 
55
// internal class.
 
56
 
 
57
class LIBTORRENT_EXPORT Download {
 
58
public:
 
59
  static const uint32_t numwanted_diabled = ~uint32_t();
 
60
 
 
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);
 
64
 
 
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);
 
68
 
 
69
  static const int stop_skip_tracker     = (1 << 0);
 
70
 
 
71
  Download(DownloadWrapper* d = NULL) : m_ptr(d) {}
 
72
 
 
73
  const DownloadInfo* info() const;
 
74
 
 
75
  // Not active atm. Opens and prepares/closes the files.
 
76
  void                open(int flags = 0);
 
77
  void                close(int flags = 0);
 
78
 
 
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.
 
83
  //
 
84
  // Chunk ranges that have valid resume data won't be checked.
 
85
  bool                hash_check(bool tryQuick);
 
86
  void                hash_stop();
 
87
 
 
88
  // Start/stop the download. The torrent must be open.
 
89
  void                start(int flags = 0);
 
90
  void                stop(int flags = 0);
 
91
 
 
92
  // Does not check if the download has been removed.
 
93
  bool                is_valid() const { return m_ptr; }
 
94
 
 
95
  bool                is_hash_checked() const;
 
96
  bool                is_hash_checking() const;
 
97
 
 
98
  void                set_pex_enabled(bool enabled);
 
99
 
 
100
  Object*             bencode();
 
101
  const Object*       bencode() const;
 
102
 
 
103
  TrackerList*        tracker_list() const;
 
104
 
 
105
  FileList*           file_list() const;
 
106
  PeerList*           peer_list();
 
107
  const PeerList*     peer_list() const;
 
108
  const TransferList* transfer_list() const;
 
109
 
 
110
  ConnectionList*       connection_list();
 
111
  const ConnectionList* connection_list() const;
 
112
 
 
113
  // Bytes completed.
 
114
  uint64_t            bytes_done() const;
 
115
 
 
116
  uint32_t            chunks_hashed() const;
 
117
 
 
118
  const uint8_t*      chunks_seen() const;
 
119
 
 
120
  // Set the number of finished chunks for closed torrents.
 
121
  void                set_chunks_done(uint32_t chunks);
 
122
 
 
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.
 
126
  //
 
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);
 
130
 
 
131
  static const int update_range_recheck = (1 << 0);
 
132
  static const int update_range_clear   = (1 << 1);
 
133
 
 
134
  void                update_range(int flags, uint32_t first, uint32_t last);
 
135
 
 
136
  // Temporary hack for syncing chunks to disk before hash resume is
 
137
  // saved.
 
138
  void                sync_chunks();
 
139
 
 
140
  uint32_t            peers_complete() const;
 
141
  uint32_t            peers_accounted() const;
 
142
 
 
143
  uint32_t            peers_currently_unchoked() const;
 
144
  uint32_t            peers_currently_interested() const;
 
145
 
 
146
  uint32_t            size_pex() const;
 
147
  uint32_t            max_size_pex() const;
 
148
 
 
149
  bool                accepting_new_peers() const;
 
150
  uint32_t            uploads_max() const;
 
151
  
 
152
  void                set_uploads_max(uint32_t v);
 
153
 
 
154
  void                set_upload_throttle(Throttle* t);
 
155
  void                set_download_throttle(Throttle* t);
 
156
 
 
157
  typedef enum {
 
158
    CONNECTION_LEECH,
 
159
    CONNECTION_SEED,
 
160
    CONNECTION_INITIAL_SEED,
 
161
    CONNECTION_METADATA,
 
162
  } ConnectionType;
 
163
 
 
164
  ConnectionType      connection_type() const;
 
165
  void                set_connection_type(ConnectionType t);
 
166
 
 
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();
 
171
 
 
172
  void                add_peer(const sockaddr* addr, int port);
 
173
 
 
174
  DownloadWrapper*    ptr() { return m_ptr; }
 
175
 
 
176
private:
 
177
  DownloadWrapper*    m_ptr;
 
178
};
 
179
 
 
180
}
 
181
 
 
182
#endif