This file is indexed.

/usr/include/libktorrent/dht/kbucket.h is in libktorrent-dev 1.3.1-5.

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
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***************************************************************************
 *   Copyright (C) 2005 by Joris Guisson                                   *
 *   joris.guisson@gmail.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 2 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#ifndef DHTKBUCKET_H
#define DHTKBUCKET_H

#include <set>
#include <QList>
#include <util/constants.h>
#include <net/address.h>
#include "key.h"
#include "rpccall.h"
#include "kbucketentry.h"

namespace bt
{
	class File;
	class BEncoder;
}

namespace dht
{
	class RPCServerInterface;
	class KClosestNodesSearch;
	class Task;

	const bt::Uint32 K = 20;
	const bt::Uint32 BUCKET_MAGIC_NUMBER = 0xB0C4B0C4;
	const bt::Uint32 BUCKET_REFRESH_INTERVAL = 15 * 60 * 1000;


	/**
	 * @author Joris Guisson
	 *
	 * A KBucket is just a list of KBucketEntry objects.
	 * The list is sorted by time last seen :
	 * The first element is the least recently seen, the last
	 * the most recently seen.
	 */
	class KBucket : public RPCCallListener
	{
		Q_OBJECT

	public:
		KBucket(RPCServerInterface* srv, const Key & our_id);
		KBucket(const dht::Key & min_key, const dht::Key & max_key, RPCServerInterface* srv, const Key & our_id);
		virtual ~KBucket();
		
		typedef QSharedPointer<KBucket> Ptr;
		
		/// Get the min key
		const dht::Key & minKey() const {return min_key;}
		
		/// Get the max key
		const dht::Key & maxKey() const {return max_key;}

		/// Does the key k lies in in the range of this bucket
		bool keyInRange(const dht::Key & k) const;
		
		/// Are we allowed to split
		bool splitAllowed() const;
		
		class UnableToSplit
		{};
		
		/**
		 * Split the bucket in two new buckets, each containing half the range of the original one.
		 * @return A pair of KBucket's
		 * @throw UnableToSplit if something goes wrong
		 */
		std::pair<KBucket::Ptr, KBucket::Ptr> split() throw (UnableToSplit);
		
		/**
		 * Inserts an entry into the bucket.
		 * @param entry The entry to insert
		 * @return true If the bucket needs to be splitted, false otherwise
		 */
		bool insert(const KBucketEntry & entry);

		/// Get the least recently seen node
		const KBucketEntry & leastRecentlySeen() const {return entries[0];}

		/// Get the number of entries
		bt::Uint32 getNumEntries() const {return entries.count();}

		/// See if this bucket contains an entry
		bool contains(const KBucketEntry & entry) const;

		/**
		 * Find the K closest entries to a key and store them in the KClosestNodesSearch
		 * object.
		 * @param kns The object to storre the search results
		 */
		void findKClosestNodes(KClosestNodesSearch & kns);

		/**
		 * A peer failed to respond
		 * @param addr Address of the peer
		 */
		bool onTimeout(const net::Address & addr);

		/// Check if the bucket needs to be refreshed
		bool needsToBeRefreshed() const;

		/// save the bucket to a file
		void save(bt::BEncoder & enc);

		/// Load the bucket from a file
		void load(bt::BDictNode* dict);

		/// Update the refresh timer of the bucket
		void updateRefreshTimer();

		/// Set the refresh task
		void setRefreshTask(Task* t);

	private:
		virtual void onResponse(RPCCall* c, RPCMsg::Ptr rsp);
		virtual void onTimeout(RPCCall* c);
		void pingQuestionable(const KBucketEntry & replacement_entry);
		bool replaceBadEntry(const KBucketEntry & entry);

	private slots:
		void onFinished(Task* t);
		
	private:
		dht::Key min_key, max_key;
		QList<KBucketEntry> entries, pending_entries;
		RPCServerInterface* srv;
		Key our_id;
		QMap<RPCCall*, KBucketEntry> pending_entries_busy_pinging;
		mutable bt::TimeStamp last_modified;
		Task* refresh_task;
	};
}

template <class T>
inline uint qHash(const T & e)
{
	return e.hash();
}

#endif