26 static constexpr
unsigned TARGET_NODES {8};
33 Bucket(sa_family_t af,
const InfoHash& f = {}, time_point t = time_point::min())
34 : af(af), first(f), time(t), cached() {}
37 time_point time {time_point::min()};
38 std::list<Sp<Node>> nodes {};
45 void connectivityChanged() {
46 time = time_point::min();
47 for (
auto& node : nodes)
48 node->setTime(time_point::min());
54 using std::list<Bucket>::list;
56 time_point grow_time {time_point::min()};
57 bool is_client {
false};
59 InfoHash middle(
const RoutingTable::const_iterator&)
const;
61 std::vector<Sp<Node>> findClosestNodes(
const InfoHash id, time_point now,
size_t count = TARGET_NODES)
const;
63 RoutingTable::iterator findBucket(
const InfoHash&
id);
64 RoutingTable::const_iterator findBucket(
const InfoHash&
id)
const;
69 inline bool contains(
const RoutingTable::const_iterator& bucket,
const InfoHash&
id)
const {
71 && (std::next(bucket) == end() ||
InfoHash::cmp(
id, std::next(bucket)->first) < 0);
78 return empty() || (size() == 1 && front().nodes.empty());
81 void connectivityChanged(
const time_point& now) {
84 b.connectivityChanged();
87 bool onNewNode(
const Sp<Node>& node,
int comfirm,
const time_point& now,
const InfoHash& myid, net::NetworkEngine& ne);
92 InfoHash
randomId(
const RoutingTable::const_iterator& bucket)
const;
94 unsigned depth(
const RoutingTable::const_iterator& bucket)
const;
99 bool split(
const RoutingTable::iterator& b);
bool contains(const RoutingTable::const_iterator &bucket, const InfoHash &id) const
An abstraction of communication protocol on the network.
static int cmp(const Hash &id1, const Hash &id2)
bool split(const RoutingTable::iterator &b)
InfoHash randomId(const RoutingTable::const_iterator &bucket) const