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
330ad8ed
Commit
330ad8ed
authored
May 29, 2019
by
Seva
Browse files
Options
Downloads
Patches
Plain Diff
dhtproxy: pipe restinio logs to opendht logger
parent
3252e6da
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/dht_proxy_server.h
+33
-2
33 additions, 2 deletions
include/opendht/dht_proxy_server.h
src/dht_proxy_server.cpp
+4
-3
4 additions, 3 deletions
src/dht_proxy_server.cpp
tools/dhtnode.cpp
+1
-1
1 addition, 1 deletion
tools/dhtnode.cpp
with
38 additions
and
6 deletions
include/opendht/dht_proxy_server.h
+
33
−
2
View file @
330ad8ed
...
@@ -38,10 +38,41 @@
...
@@ -38,10 +38,41 @@
#include
<json/json.h>
#include
<json/json.h>
#endif
#endif
class
opendht_logger_t
{
public:
opendht_logger_t
(
const
dht
::
Logger
&
logger
)
:
m_logger
(
logger
)
{}
template
<
typename
Builder
>
void
trace
(
Builder
&&
msg_builder
){
m_logger
.
d
(
"[restinio] %s"
,
msg_builder
().
c_str
());
}
template
<
typename
Builder
>
void
info
(
Builder
&&
msg_builder
){
m_logger
.
d
(
"[restinio] %s"
,
msg_builder
().
c_str
());
}
template
<
typename
Builder
>
void
warn
(
Builder
&&
msg_builder
){
m_logger
.
w
(
"[restinio] %s"
,
msg_builder
().
c_str
());
}
template
<
typename
Builder
>
void
error
(
Builder
&&
msg_builder
){
m_logger
.
e
(
"[restinio] %s"
,
msg_builder
().
c_str
());
}
private
:
dht
::
Logger
m_logger
;
};
using
RestRouter
=
restinio
::
router
::
express_router_t
<>
;
using
RestRouter
=
restinio
::
router
::
express_router_t
<>
;
using
RestRouterTraits
=
restinio
::
traits_t
<
using
RestRouterTraits
=
restinio
::
traits_t
<
restinio
::
asio_timer_manager_t
,
restinio
::
asio_timer_manager_t
,
restinio
::
single_threaded_ostream_logger_t
,
opendht_logger_t
,
//
restinio::single_threaded_ostream_logger_t,
RestRouter
>
;
RestRouter
>
;
using
RequestStatus
=
restinio
::
request_handling_status_t
;
using
RequestStatus
=
restinio
::
request_handling_status_t
;
using
ResponseByParts
=
restinio
::
chunked_output_t
;
using
ResponseByParts
=
restinio
::
chunked_output_t
;
...
@@ -70,7 +101,7 @@ public:
...
@@ -70,7 +101,7 @@ public:
* @note if the server fails to start (if port is already used or reserved),
* @note if the server fails to start (if port is already used or reserved),
* it will fails silently
* it will fails silently
*/
*/
DhtProxyServer
(
std
::
shared_ptr
<
DhtRunner
>
dht
,
in_port_t
port
=
8000
,
const
std
::
string
&
pushServer
=
""
);
DhtProxyServer
(
std
::
shared_ptr
<
DhtRunner
>
dht
,
in_port_t
port
=
8000
,
const
std
::
string
&
pushServer
=
""
,
const
Logger
&
logger
=
{}
);
virtual
~
DhtProxyServer
();
virtual
~
DhtProxyServer
();
DhtProxyServer
(
const
DhtProxyServer
&
other
)
=
delete
;
DhtProxyServer
(
const
DhtProxyServer
&
other
)
=
delete
;
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_server.cpp
+
4
−
3
View file @
330ad8ed
...
@@ -51,7 +51,7 @@ constexpr const std::chrono::minutes PRINT_STATS_PERIOD {2};
...
@@ -51,7 +51,7 @@ constexpr const std::chrono::minutes PRINT_STATS_PERIOD {2};
constexpr
const
size_t
IO_THREADS_MAX
{
64
};
constexpr
const
size_t
IO_THREADS_MAX
{
64
};
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
,
const
Logger
&
logger
)
:
dht_
(
dht
),
threadPool_
(
new
ThreadPool
(
IO_THREADS_MAX
)),
pushServer_
(
pushServer
)
:
dht_
(
dht
),
threadPool_
(
new
ThreadPool
(
IO_THREADS_MAX
)),
pushServer_
(
pushServer
)
{
{
if
(
not
dht_
)
if
(
not
dht_
)
...
@@ -69,11 +69,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port ,
...
@@ -69,11 +69,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port ,
jsonBuilder_
[
"commentStyle"
]
=
"None"
;
jsonBuilder_
[
"commentStyle"
]
=
"None"
;
jsonBuilder_
[
"indentation"
]
=
""
;
jsonBuilder_
[
"indentation"
]
=
""
;
server_thread
=
std
::
thread
([
this
,
port
](){
server_thread
=
std
::
thread
([
this
,
port
,
&
logger
](){
using
namespace
std
::
chrono
;
using
namespace
std
::
chrono
;
auto
maxThreads
=
std
::
thread
::
hardware_concurrency
()
-
1
;
auto
maxThreads
=
std
::
thread
::
hardware_concurrency
()
-
1
;
auto
restThreads
=
maxThreads
>
1
?
maxThreads
:
1
;
auto
restThreads
=
maxThreads
>
1
?
maxThreads
:
1
;
auto
settings
=
restinio
::
on_thread_pool
<
RestRouterTraits
>
(
restThreads
);
auto
settings
=
restinio
::
on_thread_pool
<
RestRouterTraits
>
(
restThreads
);
settings
.
logger
(
logger
);
settings
.
port
(
port
);
settings
.
port
(
port
);
settings
.
protocol
(
restinio
::
asio_ns
::
ip
::
tcp
::
v6
());
settings
.
protocol
(
restinio
::
asio_ns
::
ip
::
tcp
::
v6
());
settings
.
request_handler
(
this
->
createRestRouter
());
settings
.
request_handler
(
this
->
createRestRouter
());
...
...
This diff is collapsed.
Click to expand it.
tools/dhtnode.cpp
+
1
−
1
View file @
330ad8ed
...
@@ -551,7 +551,7 @@ main(int argc, char **argv)
...
@@ -551,7 +551,7 @@ main(int argc, char **argv)
#endif
#endif
if
(
params
.
proxyserver
!=
0
)
{
if
(
params
.
proxyserver
!=
0
)
{
#ifdef OPENDHT_PROXY_SERVER
#ifdef OPENDHT_PROXY_SERVER
proxies
.
emplace
(
params
.
proxyserver
,
std
::
unique_ptr
<
DhtProxyServer
>
(
new
DhtProxyServer
(
node
,
params
.
proxyserver
,
params
.
pushserver
)));
proxies
.
emplace
(
params
.
proxyserver
,
std
::
unique_ptr
<
DhtProxyServer
>
(
new
DhtProxyServer
(
node
,
params
.
proxyserver
,
params
.
pushserver
,
*
context
.
logger
)));
#else
#else
std
::
cerr
<<
"DHT proxy server requested but OpenDHT built without proxy server support."
<<
std
::
endl
;
std
::
cerr
<<
"DHT proxy server requested but OpenDHT built without proxy server support."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
...
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