1
/***************************************************************************
2
* Copyright (C) 2012 by *
3
* Joris Guisson <joris.guisson@gmail.com> *
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. *
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. *
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
***************************************************************************/
21
#include "kbucketentry.h"
23
#include <util/functions.h>
27
KBucketEntry::KBucketEntry()
29
last_responded = bt::CurrentTime();
31
questionable_pings = 0;
34
KBucketEntry::KBucketEntry(const net::Address & addr, const Key & id)
35
: addr(addr), node_id(id)
37
last_responded = bt::CurrentTime();
39
questionable_pings = 0;
42
KBucketEntry::KBucketEntry(const KBucketEntry & other) :
44
node_id(other.node_id),
45
last_responded(other.last_responded),
46
failed_queries(other.failed_queries),
47
questionable_pings(other.questionable_pings)
51
KBucketEntry::~KBucketEntry()
54
KBucketEntry & KBucketEntry::operator = (const KBucketEntry & other)
57
node_id = other.node_id;
58
last_responded = other.last_responded;
59
failed_queries = other.failed_queries;
60
questionable_pings = other.questionable_pings;
64
bool KBucketEntry::operator == (const KBucketEntry & entry) const
66
return addr == entry.addr && node_id == entry.node_id;
69
bool KBucketEntry::isGood() const
71
if (bt::CurrentTime() - last_responded > 15 * 60 * 1000)
77
bool KBucketEntry::isQuestionable() const
79
if (bt::CurrentTime() - last_responded > 15 * 60 * 1000)
86
bool KBucketEntry::isBad() const
91
return failed_queries > 2 || questionable_pings > 2;
94
void KBucketEntry::hasResponded()
96
last_responded = bt::CurrentTime();
97
failed_queries = 0; // reset failed queries
98
questionable_pings = 0;
101
bool KBucketEntry::operator<(const dht::KBucketEntry& entry) const
103
return node_id < entry.node_id;