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

« back to all changes in this revision

Viewing changes to src/download/download_main.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_MAIN_H
 
38
#define LIBTORRENT_DOWNLOAD_MAIN_H
 
39
 
 
40
#include <deque>
 
41
#include <rak/functional.h>
 
42
#include <sigc++/signal.h>
 
43
 
 
44
#include "globals.h"
 
45
 
 
46
#include "delegator.h"
 
47
 
 
48
#include "data/chunk_handle.h"
 
49
#include "download/available_list.h"
 
50
#include "net/data_buffer.h"
 
51
#include "torrent/download_info.h"
 
52
#include "torrent/data/file_list.h"
 
53
#include "torrent/peer/peer_list.h"
 
54
 
 
55
namespace torrent {
 
56
 
 
57
class ChunkList;
 
58
class ChunkSelector;
 
59
class ChunkStatistics;
 
60
 
 
61
class ChokeManager;
 
62
class ConnectionList;
 
63
class DownloadWrapper;
 
64
class HandshakeManager;
 
65
class TrackerManager;
 
66
class DownloadInfo;
 
67
class ThrottleList;
 
68
class InitialSeeding;
 
69
 
 
70
class DownloadMain {
 
71
public:
 
72
  typedef std::deque<std::pair<rak::timer, uint32_t> > have_queue_type;
 
73
  typedef std::vector<SocketAddressCompact>            pex_list;
 
74
 
 
75
  DownloadMain();
 
76
  ~DownloadMain();
 
77
 
 
78
  void                open(int flags);
 
79
  void                close();
 
80
 
 
81
  void                start();
 
82
  void                stop();
 
83
 
 
84
  ChokeManager*       upload_choke_manager()                     { return m_uploadChokeManager; }
 
85
  ChokeManager*       download_choke_manager()                   { return m_downloadChokeManager; }
 
86
  TrackerManager*     tracker_manager() const                    { return m_trackerManager; }
 
87
 
 
88
  DownloadInfo*       info()                                     { return m_info; }
 
89
 
 
90
  // Only retrieve writable chunks when the download is active.
 
91
  ChunkList*          chunk_list()                               { return m_chunkList; }
 
92
  ChunkSelector*      chunk_selector()                           { return m_chunkSelector; }
 
93
  ChunkStatistics*    chunk_statistics()                         { return m_chunkStatistics; }
 
94
  
 
95
  Delegator*          delegator()                                { return &m_delegator; }
 
96
 
 
97
  have_queue_type*    have_queue()                               { return &m_haveQueue; }
 
98
 
 
99
  InitialSeeding*     initial_seeding()                          { return m_initialSeeding; }
 
100
  bool                start_initial_seeding();
 
101
  void                initial_seeding_done(PeerConnectionBase* pcb);
 
102
 
 
103
  ConnectionList*     connection_list()                          { return m_connectionList; }
 
104
  FileList*           file_list()                                { return &m_fileList; }
 
105
  PeerList*           peer_list()                                { return &m_peerList; }
 
106
 
 
107
  std::pair<ThrottleList*, ThrottleList*> throttles(const sockaddr* sa);
 
108
 
 
109
  ThrottleList*       upload_throttle()                          { return m_uploadThrottle; }
 
110
  void                set_upload_throttle(ThrottleList* t)       { m_uploadThrottle = t; }
 
111
 
 
112
  ThrottleList*       download_throttle()                        { return m_downloadThrottle; }
 
113
  void                set_download_throttle(ThrottleList* t)     { m_downloadThrottle = t; }
 
114
 
 
115
  DataBuffer          get_ut_pex(bool initial)                   { return (initial ? m_ut_pex_initial : m_ut_pex_delta).clone(); }
 
116
 
 
117
  bool                want_pex_msg()                             { return m_info->is_pex_active() && m_peerList.available_list()->want_more(); }; 
 
118
 
 
119
  void                set_metadata_size(size_t s);
 
120
 
 
121
  // Carefull with these.
 
122
  void                setup_delegator();
 
123
  void                setup_tracker();
 
124
 
 
125
  typedef rak::const_mem_fun1<HandshakeManager, uint32_t, DownloadMain*>                   SlotCountHandshakes;
 
126
  typedef rak::mem_fun1<DownloadWrapper, void, ChunkHandle>                                SlotHashCheckAdd;
 
127
 
 
128
  typedef rak::mem_fun2<HandshakeManager, void, const rak::socket_address&, DownloadMain*> slot_start_handshake_type;
 
129
  typedef rak::mem_fun1<HandshakeManager, void, DownloadMain*>                             slot_stop_handshakes_type;
 
130
 
 
131
  void                slot_start_handshake(slot_start_handshake_type s) { m_slotStartHandshake = s; }
 
132
  void                slot_stop_handshakes(slot_stop_handshakes_type s) { m_slotStopHandshakes = s; }
 
133
  void                slot_count_handshakes(SlotCountHandshakes s) { m_slotCountHandshakes = s; }
 
134
  void                slot_hash_check_add(SlotHashCheckAdd s)      { m_slotHashCheckAdd = s; }
 
135
 
 
136
  void                add_peer(const rak::socket_address& sa);
 
137
 
 
138
  void                receive_connect_peers();
 
139
  void                receive_chunk_done(unsigned int index);
 
140
  void                receive_corrupt_chunk(PeerInfo* peerInfo);
 
141
 
 
142
  void                receive_tracker_success();
 
143
  void                receive_tracker_request();
 
144
 
 
145
  void                receive_do_peer_exchange();
 
146
 
 
147
  void                do_peer_exchange();
 
148
 
 
149
  void                update_endgame();
 
150
 
 
151
  rak::priority_item& delay_disconnect_peers() { return m_delayDisconnectPeers; }
 
152
  rak::priority_item& delay_download_done() { return m_delayDownloadDone; }
 
153
 
 
154
private:
 
155
  // Disable copy ctor and assignment.
 
156
  DownloadMain(const DownloadMain&);
 
157
  void operator = (const DownloadMain&);
 
158
 
 
159
  void                setup_start();
 
160
  void                setup_stop();
 
161
 
 
162
  DownloadInfo*       m_info;
 
163
 
 
164
  TrackerManager*     m_trackerManager;
 
165
  ChokeManager*       m_uploadChokeManager;
 
166
  ChokeManager*       m_downloadChokeManager;
 
167
 
 
168
  ChunkList*          m_chunkList;
 
169
  ChunkSelector*      m_chunkSelector;
 
170
  ChunkStatistics*    m_chunkStatistics;
 
171
 
 
172
  Delegator           m_delegator;
 
173
  have_queue_type     m_haveQueue;
 
174
  InitialSeeding*     m_initialSeeding;
 
175
 
 
176
  ConnectionList*     m_connectionList;
 
177
  FileList            m_fileList;
 
178
  PeerList            m_peerList;
 
179
 
 
180
  uint32_t            m_lastConnectedSize;
 
181
 
 
182
  DataBuffer          m_ut_pex_delta;
 
183
  DataBuffer          m_ut_pex_initial;
 
184
  pex_list            m_ut_pex_list;
 
185
 
 
186
  ThrottleList*       m_uploadThrottle;
 
187
  ThrottleList*       m_downloadThrottle;
 
188
 
 
189
  slot_start_handshake_type m_slotStartHandshake;
 
190
  slot_stop_handshakes_type m_slotStopHandshakes;
 
191
 
 
192
  SlotCountHandshakes m_slotCountHandshakes;
 
193
  SlotHashCheckAdd    m_slotHashCheckAdd;
 
194
 
 
195
  rak::priority_item  m_delayDownloadDone;
 
196
  rak::priority_item  m_delayDisconnectPeers;
 
197
  rak::priority_item  m_taskTrackerRequest;
 
198
};
 
199
 
 
200
}
 
201
 
 
202
#endif