mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
allow to cancel request without network engine
This commit is contained in:
1 parent
040e3770ad
commit
91bf5bb41b
3 files changed
+16
-11
No files matched your search
@@ -400,8 +400,11 @@ private:
|
||||
bool isNodeBlacklisted(const sockaddr*, socklen_t) const;
|
||||
|
||||
void requestStep(std::shared_ptr<Request> req) {
|
||||
if (not req->pending())
|
||||
if (not req->pending()) {
|
||||
if (req->cancelled())
|
||||
requests.erase(req->tid);
|
||||
return;
|
||||
}
|
||||
|
||||
auto now = scheduler.time();
|
||||
if (req->isExpired(now)) {
|
||||
|
||||
@@ -75,12 +75,6 @@ struct Request {
|
||||
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() {
|
||||
if (pending()) {
|
||||
@@ -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() {
|
||||
on_done = {};
|
||||
on_expired = {};
|
||||
|
||||
@@ -273,13 +273,14 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr*
|
||||
} else
|
||||
node->update(from, fromlen);
|
||||
|
||||
if (req->cancelled()) {
|
||||
DHT_LOG.ERROR("Request is cancelled: %d", msg.tid);
|
||||
onNewNode(node, 2);
|
||||
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;
|
||||
}
|
||||
|
||||
onNewNode(node, 2);
|
||||
onReportedAddr(msg.id, (sockaddr*)&msg.addr.first, msg.addr.second);
|
||||
switch (msg.type) {
|
||||
case MessageType::Error: {
|
||||
if (msg.error_code == DhtProtocolException::UNAUTHORIZED
|
||||
|
||||
Reference in new issue
Block a user