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
48b0cff0
Commit
48b0cff0
authored
9 years ago
by
Simon Désaulniers
Committed by
Adrien Béraud
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
pht: fix multiple DoneCallBack calls
parent
c8fcffbe
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/indexation/pht.cpp
+20
-10
20 additions, 10 deletions
src/indexation/pht.cpp
with
20 additions
and
10 deletions
src/indexation/pht.cpp
+
20
−
10
View file @
48b0cff0
...
...
@@ -19,9 +19,13 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
auto
mid
=
(
*
lo
+
*
hi
)
/
2
;
auto
first_res
=
std
::
make_shared
<
node_lookup_result
>
();
auto
second_res
=
std
::
make_shared
<
node_lookup_result
>
();
auto
on_done
=
[
=
](){
auto
on_done
=
[
=
](
bool
ok
){
bool
is_leaf
=
first_res
->
is_pht
and
not
second_res
->
is_pht
;
if
(
is_leaf
or
*
lo
>
*
hi
)
{
if
(
not
ok
)
{
if
(
done_cb
)
done_cb
(
false
);
}
else
if
(
is_leaf
or
*
lo
>
*
hi
)
{
// leaf node
if
(
cb
)
if
(
vals
->
size
()
==
0
and
max_common_prefix_len
and
mid
>
0
)
{
...
...
@@ -33,10 +37,14 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
cb
(
*
vals
,
p
.
getPrefix
(
mid
));
if
(
done_cb
)
done_cb
(
true
);
}
else
{
}
else
if
(
first_res
->
is_pht
)
{
// internal node
*
lo
=
mid
+
1
;
lookupStep
(
p
,
lo
,
hi
,
vals
,
cb
,
done_cb
,
max_common_prefix_len
);
}
else
{
// first get failed before second.
if
(
done_cb
)
done_cb
(
false
);
}
};
if
(
*
lo
<=
*
hi
)
{
...
...
@@ -79,8 +87,9 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
[
=
](
bool
ok
)
{
if
(
not
ok
)
{
// DHT failed
if
(
done_cb
)
done_cb
(
false
);
first_res
->
done
=
true
;
if
(
done_cb
and
second_res
->
done
)
on_done
(
false
);
}
else
{
if
(
not
first_res
->
is_pht
)
{
...
...
@@ -90,7 +99,7 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
}
else
{
first_res
->
done
=
true
;
if
(
second_res
->
done
)
on_done
();
on_done
(
true
);
}
}
},
pht_filter
);
...
...
@@ -100,18 +109,19 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
[
=
](
bool
ok
)
{
if
(
not
ok
)
{
// DHT failed
if
(
done_cb
)
done_cb
(
false
);
second_res
->
done
=
true
;
if
(
done_cb
and
first_res
->
done
)
on_done
(
false
);
}
else
{
second_res
->
done
=
true
;
if
(
first_res
->
done
)
on_done
();
on_done
(
true
);
}
},
pht_filter
);
}
else
{
on_done
();
on_done
(
true
);
}
}
...
...
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