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
00cc4ebe
Commit
00cc4ebe
authored
6 years ago
by
Adrien Béraud
Committed by
Sébastien Blin
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
proxy server: send push notification on thread pool
parent
aa93db4f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/dht_proxy_server.h
+2
-0
2 additions, 0 deletions
include/opendht/dht_proxy_server.h
src/dht_proxy_server.cpp
+14
-10
14 additions, 10 deletions
src/dht_proxy_server.cpp
with
16 additions
and
10 deletions
include/opendht/dht_proxy_server.h
+
2
−
0
View file @
00cc4ebe
...
...
@@ -45,6 +45,7 @@ namespace Json {
namespace
dht
{
class
DhtRunner
;
class
ThreadPool
;
/**
* Describes the REST API
...
...
@@ -277,6 +278,7 @@ private:
std
::
condition_variable
schedulerCv_
;
Scheduler
scheduler_
;
std
::
thread
schedulerThread_
;
std
::
unique_ptr
<
ThreadPool
>
threadPool_
;
Sp
<
Scheduler
::
Job
>
printStatsJob_
;
mutable
std
::
mutex
statsMutex_
;
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_server.cpp
+
14
−
10
View file @
00cc4ebe
...
...
@@ -20,6 +20,7 @@
#if OPENDHT_PROXY_SERVER
#include
"dht_proxy_server.h"
#include
"thread_pool.h"
#include
"default_types.h"
#include
"dhtrunner.h"
...
...
@@ -47,9 +48,11 @@ struct DhtProxyServer::SearchPuts {
};
constexpr
const
std
::
chrono
::
minutes
PRINT_STATS_PERIOD
{
2
};
constexpr
const
size_t
IO_THREADS_MAX
{
64
};
DhtProxyServer
::
DhtProxyServer
(
std
::
shared_ptr
<
DhtRunner
>
dht
,
in_port_t
port
,
const
std
::
string
&
pushServer
)
:
dht_
(
dht
)
,
pushServer_
(
pushServer
)
:
dht_
(
dht
)
,
threadPool_
(
new
ThreadPool
(
IO_THREADS_MAX
))
,
pushServer_
(
pushServer
)
{
if
(
not
dht_
)
throw
std
::
invalid_argument
(
"A DHT instance must be provided"
);
...
...
@@ -177,6 +180,7 @@ DhtProxyServer::stop()
schedulerThread_
.
join
();
if
(
server_thread
.
joinable
())
server_thread
.
join
();
threadPool_
->
stop
();
}
void
...
...
@@ -441,9 +445,7 @@ DhtProxyServer::subscribe(const std::shared_ptr<restbed::Session>& session)
Json
::
StreamWriterBuilder
wbuilder
;
wbuilder
[
"commentStyle"
]
=
"None"
;
wbuilder
[
"indentation"
]
=
""
;
auto
output
=
Json
::
writeString
(
wbuilder
,
value
->
toJson
())
+
"
\n
"
;
auto
output
=
Json
::
writeString
(
wbuilder
,
value
->
toJson
())
+
"
\n
"
;
s
->
yield
(
output
,
[](
const
Sp
<
restbed
::
Session
>
&
/*session*/
)
{});
return
true
;
...
...
@@ -473,12 +475,14 @@ DhtProxyServer::subscribe(const std::shared_ptr<restbed::Session>& session)
// The listener is not found, so add it.
listener
.
internalToken
=
dht_
->
listen
(
infoHash
,
[
this
,
infoHash
,
pushToken
,
isAndroid
,
clientId
](
std
::
vector
<
std
::
shared_ptr
<
Value
>>
/*value*/
)
{
// Build message content.
[
this
,
infoHash
,
pushToken
,
isAndroid
,
clientId
](
const
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
/*values*/
)
{
threadPool_
->
run
([
this
,
infoHash
,
pushToken
,
isAndroid
,
clientId
](){
// Build message content
Json
::
Value
json
;
json
[
"key"
]
=
infoHash
.
toString
();
json
[
"to"
]
=
clientId
;
sendPushNotification
(
pushToken
,
std
::
move
(
json
),
isAndroid
);
});
return
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