libktorrent  2.1.1
magnetdownloader.h
1 /***************************************************************************
2  * Copyright (C) 2009 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #ifndef BT_MAGNETDOWNLOADER_H
22 #define BT_MAGNETDOWNLOADER_H
23 
24 #include <QObject>
25 #include <kio/job.h>
26 #include <ktorrent_export.h>
27 #include <torrent/torrent.h>
28 #include <tracker/tracker.h>
29 #include "magnetlink.h"
30 
31 namespace dht
32 {
33  class DHTPeerSource;
34 }
35 
36 namespace bt
37 {
38  class Peer;
39  class PeerManager;
40 
46  class KTORRENT_EXPORT MagnetDownloader : public QObject, public TrackerDataSource
47  {
48  Q_OBJECT
49  public:
50  MagnetDownloader(const MagnetLink & mlink,QObject* parent);
51  ~MagnetDownloader() override;
52 
56  void update();
57 
59  bool running() const;
60 
62  Uint32 numPeers() const;
63 
65  const MagnetLink & magnetLink() const {return mlink;}
66 
67  public Q_SLOTS:
71  void start();
72 
76  void stop();
77 
78  Q_SIGNALS:
82  void foundMetadata(bt::MagnetDownloader* self,const QByteArray & metadata);
83 
84  private Q_SLOTS:
85  void onNewPeer(Peer* p);
86  void onMetadataDownloaded(const QByteArray & data);
87  void onTorrentDownloaded(KJob*);
88  void dhtStarted();
89  void dhtStopped();
90 
91  private:
92  Uint64 bytesDownloaded() const override;
93  Uint64 bytesUploaded() const override;
94  Uint64 bytesLeft() const override;
95  const SHA1Hash & infoHash() const override;
96  bool isPartialSeed() const override;
97 
98  private:
99  MagnetLink mlink;
100  QList<Tracker*> trackers;
101  PeerManager* pman;
102  dht::DHTPeerSource* dht_ps;
103  QByteArray metadata;
104  Torrent tor;
105  bool found;
106  };
107 
108 }
109 
110 #endif // BT_MAGNETDOWNLOADER_H
bt::MagnetDownloader::numPeers
Uint32 numPeers() const
How many peers are we connected to.
bt::MagnetDownloader
Definition: magnetdownloader.h:47
bt::MagnetDownloader::start
void start()
bt::PeerManager
Manages all the Peers.
Definition: peermanager.h:67
bt::Peer
Manages the connection with a peer.
Definition: peer.h:59
bt::MagnetDownloader::stop
void stop()
bt::TrackerDataSource
Definition: tracker.h:40
bt::Torrent
Loads a .torrent file.
Definition: torrent.h:80
bt::MagnetDownloader::update
void update()
bt::MagnetDownloader::foundMetadata
void foundMetadata(bt::MagnetDownloader *self, const QByteArray &metadata)
bt::MagnetDownloader::running
bool running() const
Is the magnet download running.
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::MagnetDownloader::magnetLink
const MagnetLink & magnetLink() const
Get the MagnetLink.
Definition: magnetdownloader.h:65
dht::DHTPeerSource
Definition: dhtpeersource.h:46