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
4ce9292b
Commit
4ce9292b
authored
2 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
proxy server: allow to ping push
parent
655aa074
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/dht_proxy_server.h
+3
-0
3 additions, 0 deletions
include/opendht/dht_proxy_server.h
src/dht_proxy_server.cpp
+39
-0
39 additions, 0 deletions
src/dht_proxy_server.cpp
with
42 additions
and
0 deletions
include/opendht/dht_proxy_server.h
+
3
−
0
View file @
4ce9292b
...
...
@@ -278,6 +278,9 @@ private:
#ifdef OPENDHT_PUSH_NOTIFICATIONS
PushType
getTypeFromString
(
const
std
::
string
&
type
);
std
::
string
getDefaultTopic
(
PushType
type
);
RequestStatus
pingPush
(
restinio
::
request_handle_t
request
,
restinio
::
router
::
route_params_t
/*params*/
);
/**
* Subscribe to push notifications for an iOS or Android device.
* Method: SUBSCRIBE "/{InfoHash: .*}"
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_server.cpp
+
39
−
0
View file @
4ce9292b
...
...
@@ -631,6 +631,8 @@ DhtProxyServer::createRestRouter()
// key.listen
router
->
http_get
(
"/key/:hash/listen"
,
std
::
bind
(
&
DhtProxyServer
::
listen
,
this
,
_1
,
_2
));
#ifdef OPENDHT_PUSH_NOTIFICATIONS
// node.pingPush
router
->
http_post
(
"/node/pingPush"
,
std
::
bind
(
&
DhtProxyServer
::
pingPush
,
this
,
_1
,
_2
));
// key.subscribe
router
->
add_handler
(
restinio
::
http_method_subscribe
(),
"/key/:hash"
,
std
::
bind
(
&
DhtProxyServer
::
subscribe
,
this
,
_1
,
_2
));
...
...
@@ -772,6 +774,43 @@ DhtProxyServer::getDefaultTopic(PushType) {
return
bundleId_
;
}
RequestStatus
DhtProxyServer
::
pingPush
(
restinio
::
request_handle_t
request
,
restinio
::
router
::
route_params_t
/*params*/
)
{
requestNum_
++
;
try
{
std
::
string
err
;
Json
::
Value
r
;
auto
*
char_data
=
reinterpret_cast
<
const
char
*>
(
request
->
body
().
data
());
auto
reader
=
std
::
unique_ptr
<
Json
::
CharReader
>
(
jsonReaderBuilder_
.
newCharReader
());
if
(
!
reader
->
parse
(
char_data
,
char_data
+
request
->
body
().
size
(),
&
r
,
&
err
)){
auto
response
=
initHttpResponse
(
request
->
create_response
(
restinio
::
status_bad_request
()));
response
.
set_body
(
RESP_MSG_JSON_INCORRECT
);
return
response
.
done
();
}
const
Json
::
Value
&
root
(
r
);
// parse using const Json so [] never creates element
auto
pushToken
=
root
[
"key"
].
asString
();
if
(
pushToken
.
empty
()){
auto
response
=
initHttpResponse
(
request
->
create_response
(
restinio
::
status_bad_request
()));
response
.
set_body
(
RESP_MSG_NO_TOKEN
);
return
response
.
done
();
}
auto
type
=
getTypeFromString
(
root
[
"platform"
].
asString
());
auto
topic
=
root
[
"topic"
].
asString
();
if
(
topic
.
empty
())
{
topic
=
getDefaultTopic
(
type
);
}
Json
::
Value
json
;
json
[
"to"
]
=
root
[
"client_id"
];
json
[
"pong"
]
=
true
;
sendPushNotification
(
pushToken
,
std
::
move
(
json
),
type
,
true
,
topic
);
}
catch
(...)
{
return
serverError
(
*
request
);
}
return
restinio
::
request_handling_status_t
::
accepted
;
}
RequestStatus
DhtProxyServer
::
subscribe
(
restinio
::
request_handle_t
request
,
restinio
::
router
::
route_params_t
params
)
...
...
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