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
fae6b138
Unverified
Commit
fae6b138
authored
7 years ago
by
Sébastien Blin
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #275 from savoirfairelinux/proxy
proxy server: catch exceptions in requests, always close connection
parents
ab0f4f6f
a48a965c
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_server.cpp
+249
-218
249 additions, 218 deletions
src/dht_proxy_server.cpp
with
249 additions
and
218 deletions
src/dht_proxy_server.cpp
+
249
−
218
View file @
fae6b138
...
@@ -49,6 +49,8 @@ struct DhtProxyServer::SearchPuts {
...
@@ -49,6 +49,8 @@ struct DhtProxyServer::SearchPuts {
DhtProxyServer
::
DhtProxyServer
(
std
::
shared_ptr
<
DhtRunner
>
dht
,
in_port_t
port
,
const
std
::
string
&
pushServer
)
DhtProxyServer
::
DhtProxyServer
(
std
::
shared_ptr
<
DhtRunner
>
dht
,
in_port_t
port
,
const
std
::
string
&
pushServer
)
:
dht_
(
dht
)
,
pushServer_
(
pushServer
)
:
dht_
(
dht
)
,
pushServer_
(
pushServer
)
{
{
if
(
not
dht_
)
throw
std
::
invalid_argument
(
"A DHT instance must be provided"
);
// NOTE in c++14, use make_unique
// NOTE in c++14, use make_unique
service_
=
std
::
unique_ptr
<
restbed
::
Service
>
(
new
restbed
::
Service
());
service_
=
std
::
unique_ptr
<
restbed
::
Service
>
(
new
restbed
::
Service
());
...
@@ -187,6 +189,7 @@ DhtProxyServer::getNodeInfo(const std::shared_ptr<restbed::Session>& session) co
...
@@ -187,6 +189,7 @@ DhtProxyServer::getNodeInfo(const std::shared_ptr<restbed::Session>& session) co
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b*/
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b*/
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
Json
::
Value
result
;
Json
::
Value
result
;
auto
id
=
dht_
->
getId
();
auto
id
=
dht_
->
getId
();
...
@@ -204,6 +207,9 @@ DhtProxyServer::getNodeInfo(const std::shared_ptr<restbed::Session>& session) co
...
@@ -204,6 +207,9 @@ DhtProxyServer::getNodeInfo(const std::shared_ptr<restbed::Session>& session) co
}
}
else
else
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -218,6 +224,7 @@ DhtProxyServer::get(const std::shared_ptr<restbed::Session>& session) const
...
@@ -218,6 +224,7 @@ DhtProxyServer::get(const std::shared_ptr<restbed::Session>& session) const
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
InfoHash
infoHash
(
hash
);
InfoHash
infoHash
(
hash
);
if
(
!
infoHash
)
{
if
(
!
infoHash
)
{
...
@@ -244,6 +251,9 @@ DhtProxyServer::get(const std::shared_ptr<restbed::Session>& session) const
...
@@ -244,6 +251,9 @@ DhtProxyServer::get(const std::shared_ptr<restbed::Session>& session) const
}
else
{
}
else
{
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -261,6 +271,7 @@ DhtProxyServer::listen(const std::shared_ptr<restbed::Session>& session)
...
@@ -261,6 +271,7 @@ DhtProxyServer::listen(const std::shared_ptr<restbed::Session>& session)
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
InfoHash
infoHash
(
hash
);
InfoHash
infoHash
(
hash
);
if
(
!
infoHash
)
{
if
(
!
infoHash
)
{
...
@@ -296,6 +307,9 @@ DhtProxyServer::listen(const std::shared_ptr<restbed::Session>& session)
...
@@ -296,6 +307,9 @@ DhtProxyServer::listen(const std::shared_ptr<restbed::Session>& session)
}
else
{
}
else
{
session
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
session
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -399,7 +413,7 @@ DhtProxyServer::subscribe(const std::shared_ptr<restbed::Session>& session)
...
@@ -399,7 +413,7 @@ DhtProxyServer::subscribe(const std::shared_ptr<restbed::Session>& session)
}
}
s
->
close
(
restbed
::
OK
,
"{
\"
token
\"
: "
+
std
::
to_string
(
tokenFromReq
)
+
"}
\n
"
);
s
->
close
(
restbed
::
OK
,
"{
\"
token
\"
: "
+
std
::
to_string
(
tokenFromReq
)
+
"}
\n
"
);
}
catch
(...)
{
}
catch
(...)
{
// do nothing
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
}
);
);
...
@@ -437,8 +451,9 @@ DhtProxyServer::unsubscribe(const std::shared_ptr<restbed::Session>& session)
...
@@ -437,8 +451,9 @@ DhtProxyServer::unsubscribe(const std::shared_ptr<restbed::Session>& session)
if
(
token
==
0
)
return
;
if
(
token
==
0
)
return
;
cancelPushListen
(
pushToken
,
infoHash
,
token
);
cancelPushListen
(
pushToken
,
infoHash
,
token
);
s
->
close
(
restbed
::
OK
);
}
catch
(...)
{
}
catch
(...)
{
// do nothing
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
}
);
);
...
@@ -545,6 +560,7 @@ DhtProxyServer::put(const std::shared_ptr<restbed::Session>& session)
...
@@ -545,6 +560,7 @@ DhtProxyServer::put(const std::shared_ptr<restbed::Session>& session)
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
if
(
b
.
empty
())
{
if
(
b
.
empty
())
{
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
...
@@ -622,6 +638,9 @@ DhtProxyServer::put(const std::shared_ptr<restbed::Session>& session)
...
@@ -622,6 +638,9 @@ DhtProxyServer::put(const std::shared_ptr<restbed::Session>& session)
}
else
{
}
else
{
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -641,6 +660,7 @@ DhtProxyServer::putSigned(const std::shared_ptr<restbed::Session>& session) cons
...
@@ -641,6 +660,7 @@ DhtProxyServer::putSigned(const std::shared_ptr<restbed::Session>& session) cons
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
if
(
b
.
empty
())
{
if
(
b
.
empty
())
{
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
...
@@ -670,6 +690,9 @@ DhtProxyServer::putSigned(const std::shared_ptr<restbed::Session>& session) cons
...
@@ -670,6 +690,9 @@ DhtProxyServer::putSigned(const std::shared_ptr<restbed::Session>& session) cons
}
else
{
}
else
{
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -688,6 +711,7 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
...
@@ -688,6 +711,7 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
b
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
if
(
b
.
empty
())
{
if
(
b
.
empty
())
{
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
std
::
string
response
(
"{
\"
err
\"
:
\"
Missing parameters
\"
}"
);
...
@@ -721,6 +745,9 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
...
@@ -721,6 +745,9 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
}
else
{
}
else
{
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
@@ -751,6 +778,7 @@ DhtProxyServer::getFiltered(const std::shared_ptr<restbed::Session>& session) co
...
@@ -751,6 +778,7 @@ DhtProxyServer::getFiltered(const std::shared_ptr<restbed::Session>& session) co
session
->
fetch
(
content_length
,
session
->
fetch
(
content_length
,
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
[
=
](
const
std
::
shared_ptr
<
restbed
::
Session
>
s
,
const
restbed
::
Bytes
&
/*b* */
)
{
{
try
{
if
(
dht_
)
{
if
(
dht_
)
{
InfoHash
infoHash
(
hash
);
InfoHash
infoHash
(
hash
);
if
(
!
infoHash
)
{
if
(
!
infoHash
)
{
...
@@ -773,6 +801,9 @@ DhtProxyServer::getFiltered(const std::shared_ptr<restbed::Session>& session) co
...
@@ -773,6 +801,9 @@ DhtProxyServer::getFiltered(const std::shared_ptr<restbed::Session>& session) co
}
else
{
}
else
{
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
s
->
close
(
restbed
::
SERVICE_UNAVAILABLE
,
"{
\"
err
\"
:
\"
Incorrect DhtRunner
\"
}"
);
}
}
}
catch
(...)
{
s
->
close
(
restbed
::
INTERNAL_SERVER_ERROR
,
"{
\"
err
\"
:
\"
Internal server error
\"
}"
);
}
}
}
);
);
}
}
...
...
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