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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
42671be2
Commit
42671be2
authored
Jan 20, 2017
by
Adrien Béraud
Committed by
GitHub
Jan 20, 2017
Browse files
Options
Downloads
Plain Diff
Merge pull request #168 from sim590/announce-op-fixes
Announce op fixes
parents
435cd554
efa6930d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dht.cpp
+20
-21
20 additions, 21 deletions
src/dht.cpp
with
20 additions
and
21 deletions
src/dht.cpp
+
20
−
21
View file @
42671be2
...
...
@@ -289,7 +289,7 @@ struct Dht::SearchNode {
/**
* Foreach value id, we keep track of a pair (net::Request, time_point) where the
* request is the request returned by the network engine and the time_point
* is the
las
t time at which the value
has
be
en
refreshed.
* is the
nex
t time at which the value
must
be refreshed.
*/
using
AnnounceStatus
=
std
::
map
<
Value
::
Id
,
std
::
pair
<
std
::
shared_ptr
<
net
::
Request
>
,
time_point
>>
;
/**
...
...
@@ -440,11 +440,11 @@ struct Dht::SearchNode {
})
!=
status
.
end
();
}
bool
isAnnounced
(
Value
::
Id
vid
,
time_point
now
)
const
{
bool
isAnnounced
(
Value
::
Id
vid
)
const
{
auto
ack
=
acked
.
find
(
vid
);
if
(
ack
==
acked
.
end
()
or
not
ack
->
second
.
first
)
return
false
;
return
ack
->
second
.
second
>
now
;
return
ack
->
second
.
first
->
completed
()
;
}
bool
isListening
(
time_point
now
)
const
{
...
...
@@ -618,7 +618,7 @@ struct Dht::Search {
time_point
getUpdateTime
(
time_point
now
)
const
;
bool
isAnnounced
(
Value
::
Id
id
,
time_point
now
)
const
;
bool
isAnnounced
(
Value
::
Id
id
)
const
;
bool
isListening
(
time_point
now
)
const
;
/**
...
...
@@ -728,20 +728,20 @@ struct Dht::Search {
* @param types The sequence of existing types.
* @param now The time reference to now.
*/
void
checkAnnounced
(
time_point
now
,
Value
::
Id
vid
=
Value
::
INVALID_ID
)
{
auto
announced
=
std
::
remove_if
(
announce
.
begin
(),
announce
.
end
(),
[
this
,
&
vid
,
&
now
](
Announce
&
a
)
{
void
checkAnnounced
(
Value
::
Id
vid
=
Value
::
INVALID_ID
)
{
auto
announced
=
std
::
partition
(
announce
.
begin
(),
announce
.
end
(),
[
this
,
&
vid
](
Announce
&
a
)
{
if
(
vid
!=
Value
::
INVALID_ID
and
(
!
a
.
value
||
a
.
value
->
id
!=
vid
))
return
fals
e
;
if
(
isAnnounced
(
a
.
value
->
id
,
now
))
{
return
tru
e
;
if
(
isAnnounced
(
a
.
value
->
id
))
{
if
(
a
.
callback
)
{
a
.
callback
(
true
,
getNodes
());
a
.
callback
=
nullptr
;
}
if
(
not
a
.
permanent
)
return
true
;
}
return
false
;
}
return
true
;
});
// remove acked for cleared annouces
for
(
auto
it
=
announced
;
it
!=
announce
.
end
();
++
it
)
{
...
...
@@ -1427,7 +1427,7 @@ Dht::searchStep(std::shared_ptr<Search> sr)
}
/* clearing callbacks for announced values */
sr
->
checkAnnounced
(
now
);
sr
->
checkAnnounced
();
if
(
sr
->
callbacks
.
empty
()
&&
sr
->
announce
.
empty
()
&&
sr
->
listeners
.
empty
())
sr
->
setDone
();
...
...
@@ -1591,7 +1591,7 @@ Dht::Search::getUpdateTime(time_point now) const
}
bool
Dht
::
Search
::
isAnnounced
(
Value
::
Id
id
,
time_point
now
)
const
Dht
::
Search
::
isAnnounced
(
Value
::
Id
id
)
const
{
if
(
nodes
.
empty
())
return
false
;
...
...
@@ -1599,10 +1599,10 @@ Dht::Search::isAnnounced(Value::Id id, time_point now) const
for
(
const
auto
&
n
:
nodes
)
{
if
(
n
.
isBad
())
continue
;
if
(
not
n
.
isAnnounced
(
id
,
now
))
if
(
not
n
.
isAnnounced
(
id
))
return
false
;
if
(
++
i
==
TARGET_NODES
)
b
re
ak
;
re
turn
true
;
}
return
i
;
}
...
...
@@ -1837,7 +1837,7 @@ Dht::announce(const InfoHash& id,
n
.
probe_query
.
reset
();
}
}
if
(
sr
->
isAnnounced
(
value
->
id
,
now
))
{
if
(
sr
->
isAnnounced
(
value
->
id
))
{
if
(
a_sr
->
callback
)
a_sr
->
callback
(
true
,
{});
a_sr
->
callback
=
{};
...
...
@@ -2674,9 +2674,9 @@ Dht::dumpSearch(const Search& sr, std::ostream& out) const
out
<<
*
l
.
second
.
query
<<
std
::
endl
;
}
for
(
const
auto
&
n
:
sr
.
announce
)
{
bool
announced
=
sr
.
isAnnounced
(
n
.
value
->
id
,
now
);
out
<<
"Announcement: "
<<
*
n
.
value
<<
(
announced
?
" [announced]"
:
""
)
<<
std
::
endl
;
for
(
const
auto
&
a
:
sr
.
announce
)
{
bool
announced
=
sr
.
isAnnounced
(
a
.
value
->
id
);
out
<<
"Announcement: "
<<
*
a
.
value
<<
(
announced
?
" [announced]"
:
""
)
<<
std
::
endl
;
}
out
<<
" Common bits InfoHash Conn. Get Ops IP"
<<
std
::
endl
;
...
...
@@ -3566,14 +3566,13 @@ Dht::onRefresh(std::shared_ptr<Node> node, const InfoHash& hash, const Blob& tok
void
Dht
::
onAnnounceDone
(
const
std
::
shared_ptr
<
Node
>&
node
,
net
::
NetworkEngine
::
RequestAnswer
&
answer
,
std
::
shared_ptr
<
Search
>&
sr
)
{
const
auto
&
now
=
scheduler
.
time
();
DHT_LOG
.
d
(
sr
->
id
,
node
->
id
,
"[search %s] [node %s] got reply to put!"
,
sr
->
id
.
toString
().
c_str
(),
node
->
toString
().
c_str
());
searchSendGetValues
(
sr
);
/* if (auto sn = sr->getNode(req->node)) { */
/* sn->setRefreshTime(answer.vid, now + answer) */
/* } */
sr
->
checkAnnounced
(
now
,
answer
.
vid
);
sr
->
checkAnnounced
(
answer
.
vid
);
}
}
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