Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
91bf5bb4
Commit
91bf5bb4
authored
9 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
allow to cancel request without network engine
parent
040e3770
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/network_engine.h
+4
-1
4 additions, 1 deletion
include/opendht/network_engine.h
include/opendht/request.h
+7
-6
7 additions, 6 deletions
include/opendht/request.h
src/network_engine.cpp
+5
-4
5 additions, 4 deletions
src/network_engine.cpp
with
16 additions
and
11 deletions
include/opendht/network_engine.h
+
4
−
1
View file @
91bf5bb4
...
@@ -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
))
{
...
...
This diff is collapsed.
Click to expand it.
include/opendht/request.h
+
7
−
6
View file @
91bf5bb4
...
@@ -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
=
{};
...
...
This diff is collapsed.
Click to expand it.
src/network_engine.cpp
+
5
−
4
View file @
91bf5bb4
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment