Skip to content
Snippets Groups Projects
Commit 91bf5bb4 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

allow to cancel request without network engine

parent 040e3770
No related branches found
No related tags found
No related merge requests found
...@@ -400,8 +400,11 @@ private: ...@@ -400,8 +400,11 @@ private:
bool isNodeBlacklisted(const sockaddr*, socklen_t) const; bool isNodeBlacklisted(const sockaddr*, socklen_t) const;
void requestStep(std::shared_ptr<Request> req) { void requestStep(std::shared_ptr<Request> req) {
if (not req->pending()) if (not req->pending()) {
if (req->cancelled())
requests.erase(req->tid);
return; return;
}
auto now = scheduler.time(); auto now = scheduler.time();
if (req->isExpired(now)) { if (req->isExpired(now)) {
......
...@@ -75,12 +75,6 @@ struct Request { ...@@ -75,12 +75,6 @@ struct Request {
clear(); clear();
} }
} }
private:
static const constexpr size_t MAX_ATTEMPT_COUNT {3};
bool isExpired(time_point now) const {
return pending() and now > last_try + Node::MAX_RESPONSE_TIME and attempt_count >= Request::MAX_ATTEMPT_COUNT;
}
void cancel() { void cancel() {
if (pending()) { if (pending()) {
...@@ -89,6 +83,13 @@ private: ...@@ -89,6 +83,13 @@ private:
} }
} }
private:
static const constexpr size_t MAX_ATTEMPT_COUNT {3};
bool isExpired(time_point now) const {
return pending() and now > last_try + Node::MAX_RESPONSE_TIME and attempt_count >= Request::MAX_ATTEMPT_COUNT;
}
void clear() { void clear() {
on_done = {}; on_done = {};
on_expired = {}; on_expired = {};
......
...@@ -273,13 +273,14 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr* ...@@ -273,13 +273,14 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
} else } else
node->update(from, fromlen); node->update(from, fromlen);
if (req->cancelled()) { onNewNode(node, 2);
DHT_LOG.ERROR("Request is cancelled: %d", msg.tid); onReportedAddr(msg.id, (sockaddr*)&msg.addr.first, msg.addr.second);
if (req->cancelled() or req->expired() or (req->completed() and not req->persistent)) {
requests.erase(reqp);
return; return;
} }
onNewNode(node, 2);
onReportedAddr(msg.id, (sockaddr*)&msg.addr.first, msg.addr.second);
switch (msg.type) { switch (msg.type) {
case MessageType::Error: { case MessageType::Error: {
if (msg.error_code == DhtProtocolException::UNAUTHORIZED if (msg.error_code == DhtProtocolException::UNAUTHORIZED
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment