26static 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 {};
49 using std::list<Bucket>::list;
51 time_point grow_time {time_point::min()};
52 bool is_client {
false};
54 InfoHash middle(
const RoutingTable::const_iterator&)
const;
56 std::vector<Sp<Node>> findClosestNodes(
const InfoHash id, time_point now,
size_t count = TARGET_NODES)
const;
58 RoutingTable::iterator findBucket(
const InfoHash&
id);
59 RoutingTable::const_iterator findBucket(
const InfoHash&
id)
const;
64 inline bool contains(
const RoutingTable::const_iterator& bucket,
const InfoHash&
id)
const {
66 && (std::next(bucket) == end() ||
InfoHash::cmp(
id, std::next(bucket)->first) < 0);
73 return empty() || (size() == 1 && front().nodes.empty());
76 void connectivityChanged(
const time_point& now) {
79 b.time = time_point::min();
82 bool onNewNode(
const Sp<Node>& node,
int comfirm,
const time_point& now,
const InfoHash& myid, net::NetworkEngine& ne);
89 unsigned depth(
const RoutingTable::const_iterator& bucket)
const;
94 bool split(
const RoutingTable::iterator& b);
static int cmp(const Hash &id1, const Hash &id2)
bool contains(const RoutingTable::const_iterator &bucket, const InfoHash &id) const
bool split(const RoutingTable::iterator &b)
InfoHash randomId(const RoutingTable::const_iterator &bucket) const
An abstraction of communication protocol on the network.