libktorrent  2.2.0
kbucketentry.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_KBUCKETENTRY_H
22 #define DHT_KBUCKETENTRY_H
23 
24 #include <set>
25 #include <net/address.h>
26 #include <dht/key.h>
27 
28 namespace dht
29 {
30 
38  {
39  public:
45 
51  KBucketEntry(const net::Address & addr, const Key & id);
52 
58  KBucketEntry(const KBucketEntry & other);
59 
61  virtual ~KBucketEntry();
62 
69 
71  bool operator == (const KBucketEntry & entry) const;
72 
74  const net::Address & getAddress() const {return addr;}
75 
77  const Key & getID() const {return node_id;}
78 
80  bool isGood() const;
81 
83  bool isQuestionable() const;
84 
86  bool isBad() const;
87 
89  void hasResponded();
90 
92  void requestTimeout() {failed_queries++;}
93 
95  void onPingQuestionable() {questionable_pings++;}
96 
98  static KBucketEntry null;
99 
101  bool operator < (const KBucketEntry & entry) const;
102 
103  private:
104  net::Address addr;
105  Key node_id;
106  bt::TimeStamp last_responded;
107  bt::Uint32 failed_queries;
108  bt::Uint32 questionable_pings;
109  };
110 
111  class KBucketEntrySet : public std::set<KBucketEntry>
112  {
113  public:
114  KBucketEntrySet() {}
115  virtual ~KBucketEntrySet() {}
116 
117  bool contains(const KBucketEntry & entry) const
118  {
119  return find(entry) != end();
120  }
121  };
122 
123 }
124 
125 #endif // DHT_KBUCKETENTRY_H
dht::KBucketEntry::operator=
KBucketEntry & operator=(const KBucketEntry &other)
dht::KBucketEntry::~KBucketEntry
virtual ~KBucketEntry()
Destructor.
net::Address
Definition: address.h:41
dht::KBucketEntry::KBucketEntry
KBucketEntry(const net::Address &addr, const Key &id)
dht::Key
Key in the distributed hash table.
Definition: key.h:39
dht::KBucketEntry::getAddress
const net::Address & getAddress() const
Get the socket address of the node.
Definition: kbucketentry.h:74
dht::KBucketEntry::KBucketEntry
KBucketEntry(const KBucketEntry &other)
dht::KBucketEntry::operator<
bool operator<(const KBucketEntry &entry) const
< operator
dht::KBucketEntry::isQuestionable
bool isQuestionable() const
Is this node questionable (haven't heard from it in the last 15 minutes)
dht::KBucketEntry::getID
const Key & getID() const
Get it's ID.
Definition: kbucketentry.h:77
dht::KBucketEntry::requestTimeout
void requestTimeout()
A request timed out.
Definition: kbucketentry.h:92
dht::KBucketEntry::KBucketEntry
KBucketEntry()
dht::KBucketEntry
Definition: kbucketentry.h:38
dht::KBucketEntry::operator==
bool operator==(const KBucketEntry &entry) const
Equality operator.
dht::KBucketEntry::isBad
bool isBad() const
Is it a bad node. (Hasn't responded to a query.
dht::KBucketEntry::isGood
bool isGood() const
Is this node a good node.
dht::KBucketEntrySet
Definition: kbucketentry.h:112
dht::KBucketEntry::hasResponded
void hasResponded()
Signal the entry that the peer has responded.
dht::KBucketEntry::onPingQuestionable
void onPingQuestionable()
The entry has been pinged because it is questionable.
Definition: kbucketentry.h:95