37 Node(
const InfoHash&
id,
const SockAddr& addr, std::mt19937_64& rd,
bool client =
false);
38 Node(
const InfoHash&
id,
SockAddr&& addr, std::mt19937_64& rd,
bool client =
false);
39 Node(
const InfoHash&
id,
const sockaddr* sa, socklen_t salen, std::mt19937_64& rd)
43 const InfoHash& getId()
const {
return id; }
44 const SockAddr& getAddr()
const {
return addr; }
45 std::string getAddrStr()
const {
return addr.toString(); }
46 bool isClient()
const {
return is_client; }
47 bool isIncoming() {
return time > reply_time; }
49 const time_point& getTime()
const {
return time; }
50 const time_point& getReplyTime()
const {
return reply_time; }
51 void setTime(
const time_point& t) { time = t; }
60 if (++auth_errors > MAX_AUTH_ERRORS)
63 void authSuccess() { auth_errors = 0; }
65 bool isExpired()
const {
return expired_; }
66 bool isGood(time_point now)
const;
67 bool isPendingMessage()
const;
68 size_t getPendingMessageCount()
const;
70 bool isOld(
const time_point& now)
const {
return time + NODE_EXPIRE_TIME < now; }
71 bool isRemovable(
const time_point& now)
const {
return isExpired() and isOld(now); }
73 NodeExport exportNode()
const
80 sa_family_t getFamily()
const {
return addr.getFamily(); }
82 void update(
const SockAddr&);
84 void requested(
const Sp<net::Request>& req);
85 void received(time_point now,
const Sp<net::Request>& req);
86 Sp<net::Request> getRequest(Tid tid);
87 void cancelRequest(
const Sp<net::Request>& req);
102 Sp<Socket> getSocket(Tid
id);
117 reply_time = time_point::min();
128 return transaction_id ? transaction_id : ++transaction_id;
131 std::string toString()
const;
133 OPENDHT_PUBLIC
friend std::ostream& operator<<(std::ostream& s,
const Node& h);
135 static constexpr const std::chrono::minutes NODE_GOOD_TIME {120};
138 static constexpr const std::chrono::minutes NODE_EXPIRE_TIME {10};
141 static constexpr const std::chrono::seconds MAX_RESPONSE_TIME {1};
145 static const constexpr unsigned MAX_AUTH_ERRORS {3};
148 bool is_client {
false};
149 time_point time {time_point::min()};
150 time_point reply_time {time_point::min()};
151 unsigned auth_errors {0};
152 bool expired_ {
false};
154 using TransactionDist = std::uniform_int_distribution<
decltype(transaction_id)>;
156 std::map<Tid, Sp<net::Request>> requests_ {};
157 std::map<Tid, Sp<Socket>> sockets_;