~ubuntu-branches/ubuntu/vivid/libktorrent/vivid-proposed

« back to all changes in this revision

Viewing changes to src/dht/kbucketentry.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Thomas
  • Date: 2012-12-23 20:58:00 UTC
  • mfrom: (5.1.9 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121223205800-bsj8jy6qqov5cu2w
Tags: 1.3.0-1ubuntu1
Update symbols file to fix FTBFS with raring toolchain.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "kbucketentry.h"
 
22
#include <util/log.h>
 
23
#include <util/functions.h>
 
24
 
 
25
namespace dht
 
26
{
 
27
        KBucketEntry::KBucketEntry()
 
28
        {
 
29
                last_responded = bt::CurrentTime();
 
30
                failed_queries = 0;
 
31
                questionable_pings = 0;
 
32
        }
 
33
 
 
34
        KBucketEntry::KBucketEntry(const net::Address & addr, const Key & id)
 
35
                        : addr(addr), node_id(id)
 
36
        {
 
37
                last_responded = bt::CurrentTime();
 
38
                failed_queries = 0;
 
39
                questionable_pings = 0;
 
40
        }
 
41
 
 
42
        KBucketEntry::KBucketEntry(const KBucketEntry & other) :
 
43
                        addr(other.addr),
 
44
                        node_id(other.node_id),
 
45
                        last_responded(other.last_responded),
 
46
                        failed_queries(other.failed_queries),
 
47
                        questionable_pings(other.questionable_pings)
 
48
        {}
 
49
 
 
50
 
 
51
        KBucketEntry::~KBucketEntry()
 
52
        {}
 
53
 
 
54
        KBucketEntry & KBucketEntry::operator = (const KBucketEntry & other)
 
55
        {
 
56
                addr = other.addr;
 
57
                node_id = other.node_id;
 
58
                last_responded = other.last_responded;
 
59
                failed_queries = other.failed_queries;
 
60
                questionable_pings = other.questionable_pings;
 
61
                return *this;
 
62
        }
 
63
 
 
64
        bool KBucketEntry::operator == (const KBucketEntry & entry) const
 
65
        {
 
66
                return addr == entry.addr && node_id == entry.node_id;
 
67
        }
 
68
 
 
69
        bool KBucketEntry::isGood() const
 
70
        {
 
71
                if (bt::CurrentTime() - last_responded > 15 * 60 * 1000)
 
72
                        return false;
 
73
                else
 
74
                        return true;
 
75
        }
 
76
 
 
77
        bool KBucketEntry::isQuestionable() const
 
78
        {
 
79
                if (bt::CurrentTime() - last_responded > 15 * 60 * 1000)
 
80
                        return true;
 
81
                else
 
82
                        return false;
 
83
        }
 
84
 
 
85
 
 
86
        bool KBucketEntry::isBad() const
 
87
        {
 
88
                if (isGood())
 
89
                        return false;
 
90
 
 
91
                return failed_queries > 2 || questionable_pings > 2;
 
92
        }
 
93
 
 
94
        void KBucketEntry::hasResponded()
 
95
        {
 
96
                last_responded = bt::CurrentTime();
 
97
                failed_queries = 0; // reset failed queries
 
98
                questionable_pings = 0;
 
99
        }
 
100
 
 
101
        bool KBucketEntry::operator<(const dht::KBucketEntry& entry) const
 
102
        {
 
103
                return node_id < entry.node_id;
 
104
        }
 
105
 
 
106
}
 
107