This file is indexed.

/usr/include/opendht/routing_table.h is in libopendht-dev 1.6.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 *  Copyright (C) 2014-2017 Savoir-faire Linux Inc.
 *  Author(s) : Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
 *              Simon DĂ©saulniers <simon.desaulniers@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once

#include "node.h"

namespace dht {

static constexpr unsigned TARGET_NODES {8};
namespace net {
class NetworkEngine;
}

struct Bucket {
    Bucket() : cached() {}
    Bucket(sa_family_t af, const InfoHash& f = {}, time_point t = time_point::min())
        : af(af), first(f), time(t), cached() {}
    sa_family_t af {0};
    InfoHash first {};
    time_point time {time_point::min()}; /* time of last reply in this bucket */
    std::list<Sp<Node>> nodes {};
    Sp<Node> cached;                    /* the address of a likely candidate */

    /** Return a random node in a bucket. */
    Sp<Node> randomNode();

    void sendCachedPing(net::NetworkEngine& ne);
};

class RoutingTable : public std::list<Bucket> {
public:
    using std::list<Bucket>::list;

    time_point grow_time {time_point::min()};
    bool is_client {false};

    InfoHash middle(const RoutingTable::const_iterator&) const;

    std::vector<Sp<Node>> findClosestNodes(const InfoHash id, time_point now, size_t count = TARGET_NODES) const;

    RoutingTable::iterator findBucket(const InfoHash& id);
    RoutingTable::const_iterator findBucket(const InfoHash& id) const;

    /**
     * Return true if the id is in the bucket's range.
     */
    inline bool contains(const RoutingTable::const_iterator& bucket, const InfoHash& id) const {
        return InfoHash::cmp(bucket->first, id) <= 0
            && (std::next(bucket) == end() || InfoHash::cmp(id, std::next(bucket)->first) < 0);
    }

    /**
     * Return true if the table has no bucket ore one empty buket.
     */
    inline bool isEmpty() const {
        return empty() || (size() == 1 && front().nodes.empty());
    }

    void connectivityChanged(const time_point& now) {
        grow_time = now;
        for (auto& b : *this)
            b.time = time_point::min();
    }

    bool onNewNode(const Sp<Node>& node, int comfirm, const time_point& now, const InfoHash& myid, net::NetworkEngine& ne);

    /**
     * Return a random id in the bucket's range.
     */
    InfoHash randomId(const RoutingTable::const_iterator& bucket) const;

    unsigned depth(const RoutingTable::const_iterator& bucket) const;

    /**
     * Split a bucket in two equal parts.
     */
    bool split(const RoutingTable::iterator& b);
};

}