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
567fa1c7
Commit
567fa1c7
authored
7 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
proxy client: retrieve search from callback
parent
20ab71ab
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dht_proxy_client.cpp
+22
-12
22 additions, 12 deletions
src/dht_proxy_client.cpp
with
22 additions
and
12 deletions
src/dht_proxy_client.cpp
+
22
−
12
View file @
567fa1c7
...
@@ -350,7 +350,7 @@ DhtProxyClient::doPut(const InfoHash& key, Sp<Value> val, DoneCallback cb, time_
...
@@ -350,7 +350,7 @@ DhtProxyClient::doPut(const InfoHash& key, Sp<Value> val, DoneCallback cb, time_
o
.
thread
=
std
::
thread
([
=
](){
o
.
thread
=
std
::
thread
([
=
](){
auto
ok
=
std
::
make_shared
<
std
::
atomic_bool
>
(
true
);
auto
ok
=
std
::
make_shared
<
std
::
atomic_bool
>
(
true
);
restbed
::
Http
::
async
(
req
,
restbed
::
Http
::
async
(
req
,
[
this
,
ok
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
/*req*/
,
[
ok
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
/*req*/
,
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
auto
code
=
reply
->
get_status_code
();
auto
code
=
reply
->
get_status_code
();
...
@@ -605,6 +605,12 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
...
@@ -605,6 +605,12 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
return
0
;
return
0
;
}
}
struct
State
{
std
::
atomic_bool
ok
{
true
};
std
::
atomic_bool
cancel
{
false
};
};
auto
state
=
std
::
make_shared
<
State
>
();
auto
token
=
++
listener_token_
;
auto
token
=
++
listener_token_
;
auto
l
=
search
->
second
.
listeners
.
find
(
token
);
auto
l
=
search
->
second
.
listeners
.
find
(
token
);
if
(
l
==
search
->
second
.
listeners
.
end
())
{
if
(
l
==
search
->
second
.
listeners
.
end
())
{
...
@@ -626,9 +632,18 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
...
@@ -626,9 +632,18 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
}).
first
;
}).
first
;
}
}
ValueCache
&
cache
=
l
->
second
.
cache
;
l
->
second
.
cb
=
[
this
,
key
,
token
,
state
](
const
std
::
vector
<
Sp
<
Value
>>&
values
,
bool
expired
)
{
auto
&
job
=
l
->
second
.
cacheExpirationJob
;
if
(
state
->
cancel
)
l
->
second
.
cb
=
[
this
,
&
cache
,
&
job
,
key
,
token
](
const
std
::
vector
<
Sp
<
Value
>>&
values
,
bool
expired
)
{
return
false
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
searchLock_
);
auto
s
=
searches_
.
find
(
key
);
if
(
s
==
searches_
.
end
())
{
return
false
;
}
auto
l
=
s
->
second
.
listeners
.
find
(
token
);
if
(
l
==
s
->
second
.
listeners
.
end
())
{
return
false
;
}
const
std
::
vector
<
Sp
<
Value
>>
new_values_empty
;
const
std
::
vector
<
Sp
<
Value
>>
new_values_empty
;
std
::
vector
<
Value
::
Id
>
expired_ids
;
std
::
vector
<
Value
::
Id
>
expired_ids
;
if
(
expired
)
{
if
(
expired
)
{
...
@@ -636,8 +651,8 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
...
@@ -636,8 +651,8 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
for
(
const
auto
&
v
:
values
)
for
(
const
auto
&
v
:
values
)
expired_ids
.
emplace_back
(
v
->
id
);
expired_ids
.
emplace_back
(
v
->
id
);
}
}
auto
next
=
cache
.
onValues
(
expired
?
new_values_empty
:
values
,
std
::
vector
<
Value
::
Id
>
{},
expired_ids
,
types
,
scheduler
.
time
());
auto
next
=
l
->
second
.
cache
.
onValues
(
expired
?
new_values_empty
:
values
,
std
::
vector
<
Value
::
Id
>
{},
expired_ids
,
types
,
scheduler
.
time
());
scheduler
.
edit
(
j
ob
,
next
);
scheduler
.
edit
(
l
->
second
.
cacheExpirationJ
ob
,
next
);
return
true
;
return
true
;
};
};
std
::
weak_ptr
<
bool
>
isCanceledViaClose
(
l
->
second
.
isCanceledViaClose
);
std
::
weak_ptr
<
bool
>
isCanceledViaClose
(
l
->
second
.
isCanceledViaClose
);
...
@@ -656,11 +671,6 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
...
@@ -656,11 +671,6 @@ DhtProxyClient::doListen(const InfoHash& key, ValueCallback cb, Value::Filter fi
fillBodyToGetToken
(
req
);
fillBodyToGetToken
(
req
);
#endif
#endif
struct
State
{
std
::
atomic_bool
ok
{
true
};
std
::
atomic_bool
cancel
{
false
};
};
auto
state
=
std
::
make_shared
<
State
>
();
restbed
::
Http
::
async
(
req
,
restbed
::
Http
::
async
(
req
,
[
this
,
filter
,
vcb
,
pushNotifToken
,
state
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
req
,
[
this
,
filter
,
vcb
,
pushNotifToken
,
state
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
req
,
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
...
@@ -928,7 +938,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener)
...
@@ -928,7 +938,7 @@ DhtProxyClient::resubscribe(const InfoHash& key, Listener& listener)
auto
settings
=
std
::
make_shared
<
restbed
::
Settings
>
();
auto
settings
=
std
::
make_shared
<
restbed
::
Settings
>
();
auto
ok
=
std
::
make_shared
<
std
::
atomic_bool
>
(
true
);
auto
ok
=
std
::
make_shared
<
std
::
atomic_bool
>
(
true
);
restbed
::
Http
::
async
(
req
,
restbed
::
Http
::
async
(
req
,
[
this
,
pushNotifToken
,
ok
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
,
[
pushNotifToken
,
ok
](
const
std
::
shared_ptr
<
restbed
::
Request
>&
,
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
const
std
::
shared_ptr
<
restbed
::
Response
>&
reply
)
{
auto
code
=
reply
->
get_status_code
();
auto
code
=
reply
->
get_status_code
();
if
(
code
==
200
)
{
if
(
code
==
200
)
{
...
...
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