libktorrent  2.2.0
dhtbase.h
1 /***************************************************************************
2  * Copyright (C) 2005 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 #ifndef DHTDHTBASE_H
21 #define DHTDHTBASE_H
22 
23 #include <qobject.h>
24 #include <qmap.h>
25 #include <util/constants.h>
26 
27 class QString;
28 
29 namespace bt
30 {
31  class SHA1Hash;
32 }
33 
34 namespace dht
35 {
36  class AnnounceTask;
37 
38  struct Stats
39  {
41  bt::Uint32 num_peers;
43  bt::Uint32 num_tasks;
44  };
45 
52  class DHTBase : public QObject
53  {
54  Q_OBJECT
55  public:
56  DHTBase();
57  ~DHTBase() override;
58 
59 
66  virtual void start(const QString & table,const QString & key_file,bt::Uint16 port) = 0;
67 
71  virtual void stop() = 0;
72 
76  virtual void update() = 0;
77 
83  virtual void portReceived(const QString & ip,bt::Uint16 port) = 0;
84 
91  virtual AnnounceTask* announce(const bt::SHA1Hash & info_hash,bt::Uint16 port) = 0;
92 
96  bool isRunning() const {return running;}
97 
99  bt::Uint16 getPort() const {return port;}
100 
102  const dht::Stats & getStats() const {return stats;}
103 
109  virtual void addDHTNode(const QString & host,bt::Uint16 hport) = 0;
110 
116  virtual QMap<QString, int> getClosestGoodNodes(int maxNodes) = 0;
117 
118  Q_SIGNALS:
119  void started();
120  void stopped();
121 
122  protected:
123  bool running;
124  bt::Uint16 port;
125  dht::Stats stats;
126  };
127 
128 }
129 
130 #endif
dht::DHTBase::start
virtual void start(const QString &table, const QString &key_file, bt::Uint16 port)=0
dht::Stats
Definition: dhtbase.h:39
dht::DHTBase::getClosestGoodNodes
virtual QMap< QString, int > getClosestGoodNodes(int maxNodes)=0
dht::DHTBase::portReceived
virtual void portReceived(const QString &ip, bt::Uint16 port)=0
dht::Stats::num_peers
bt::Uint32 num_peers
number of peers in the routing table
Definition: dhtbase.h:41
dht::DHTBase::getPort
bt::Uint16 getPort() const
Get the DHT port.
Definition: dhtbase.h:99
dht::DHTBase::getStats
const dht::Stats & getStats() const
Get statistics about the DHT.
Definition: dhtbase.h:102
dht::DHTBase::update
virtual void update()=0
dht::DHTBase::isRunning
bool isRunning() const
Definition: dhtbase.h:96
dht::Stats::num_tasks
bt::Uint32 num_tasks
Number of running tasks.
Definition: dhtbase.h:43
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
dht::DHTBase::stop
virtual void stop()=0
dht::DHTBase::announce
virtual AnnounceTask * announce(const bt::SHA1Hash &info_hash, bt::Uint16 port)=0
dht::DHTBase
Definition: dhtbase.h:53
dht::DHTBase::addDHTNode
virtual void addDHTNode(const QString &host, bt::Uint16 hport)=0
dht::AnnounceTask
Definition: announcetask.h:50