libktorrent  2.2.0
kbuckettable.h
1 /***************************************************************************
2  * Copyright (C) 2012 by *
3  * Joris Guisson <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 DHT_KBUCKETTABLE_H
22 #define DHT_KBUCKETTABLE_H
23 
24 #include <list>
25 #include <dht/kbucket.h>
26 
27 namespace dht
28 {
29 
34  {
35  public:
36  KBucketTable(const Key & our_id);
37  virtual ~KBucketTable();
38 
40  void insert(const KBucketEntry & entry, RPCServerInterface* srv);
41 
43  int numEntries() const;
44 
46  void refreshBuckets(DHT* dh_table);
47 
49  void onTimeout(const net::Address & addr);
50 
52  void loadTable(const QString& file, dht::RPCServerInterface* srv);
53 
55  void saveTable(const QString & file);
56 
59 
60  private:
61  typedef std::list<KBucket::Ptr> KBucketList;
62  KBucketList::iterator findBucket(const dht::Key & id);
63 
64  private:
65  Key our_id;
66  KBucketList buckets;
67  };
68 
69 }
70 
71 #endif // DHT_KBUCKETTABLE_H
dht::KBucketTable
Definition: kbuckettable.h:34
net::Address
Definition: address.h:41
dht::KBucketTable::refreshBuckets
void refreshBuckets(DHT *dh_table)
Refresh the buckets.
dht::KBucketTable::numEntries
int numEntries() const
Get the number of entries.
dht::Key
Key in the distributed hash table.
Definition: key.h:39
dht::KClosestNodesSearch
Definition: kclosestnodessearch.h:38
dht::KBucketTable::loadTable
void loadTable(const QString &file, dht::RPCServerInterface *srv)
Load the table from a file.
dht::KBucketTable::onTimeout
void onTimeout(const net::Address &addr)
Timeout happened.
dht::KBucketTable::insert
void insert(const KBucketEntry &entry, RPCServerInterface *srv)
Insert a KBucketEntry into the table.
dht::KBucketEntry
Definition: kbucketentry.h:38
dht::RPCServerInterface
Definition: rpcserverinterface.h:34
dht::KBucketTable::saveTable
void saveTable(const QString &file)
Save table to a file.
dht::KBucketTable::findKClosestNodes
void findKClosestNodes(KClosestNodesSearch &kns)
FInd the K closest nodes.
dht::DHT
Definition: dht.h:63