libktorrent  2.2.0
node.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 DHTNODE_H
21 #define DHTNODE_H
22 
23 #include <qobject.h>
24 #include "key.h"
25 #include "kbucket.h"
26 
27 
28 using bt::Uint8;
29 
30 namespace dht
31 {
32  class DHT;
33  class RPCMsg;
34  class RPCServer;
35  class KClosestNodesSearch;
36 
37 
38  const bt::Uint32 WANT_IPV4 = 1;
39  const bt::Uint32 WANT_IPV6 = 2;
40  const bt::Uint32 WANT_BOTH = WANT_IPV4 | WANT_IPV6;
41 
50  class Node : public QObject
51  {
52  Q_OBJECT
53  public:
54  Node(RPCServer* srv, const QString & key_file);
55  ~Node() override;
56 
64  void received(DHT* dh_table, const RPCMsg & msg);
65 
67  const dht::Key & getOurID() const {return our_id;}
68 
75  void findKClosestNodes(KClosestNodesSearch & kns, bt::Uint32 want);
76 
80  void onTimeout(RPCMsg::Ptr msg);
81 
83  void refreshBuckets(DHT* dh_table);
84 
86  void saveTable(const QString & file);
87 
89  void loadTable(const QString & file);
90 
92  bt::Uint32 getNumEntriesInRoutingTable() const {return num_entries;}
93 
94  private:
95  class Private;
96  Private* d;
97  dht::Key our_id;
98  bt::Uint32 num_entries;
99  };
100 
101 }
102 
103 #endif
dht::Node::getNumEntriesInRoutingTable
bt::Uint32 getNumEntriesInRoutingTable() const
Get the number of entries in the routing table.
Definition: node.h:92
dht::Node::findKClosestNodes
void findKClosestNodes(KClosestNodesSearch &kns, bt::Uint32 want)
dht::Key
Key in the distributed hash table.
Definition: key.h:39
dht::RPCMsg
Definition: rpcmsg.h:70
dht::KClosestNodesSearch
Definition: kclosestnodessearch.h:38
dht::Node
Definition: node.h:51
dht::RPCServer
Definition: rpcserver.h:46
dht::Node::refreshBuckets
void refreshBuckets(DHT *dh_table)
Check if a buckets needs to be refreshed, and refresh if necesarry.
dht::Node::onTimeout
void onTimeout(RPCMsg::Ptr msg)
dht::Node::saveTable
void saveTable(const QString &file)
Save the routing table to a file.
dht::Node::getOurID
const dht::Key & getOurID() const
Get our own ID.
Definition: node.h:67
dht::Node::received
void received(DHT *dh_table, const RPCMsg &msg)
dht::Node::loadTable
void loadTable(const QString &file)
Load the routing table from a file.
dht::DHT
Definition: dht.h:63