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
b98cc78b
Commit
b98cc78b
authored
5 years ago
by
Seva
Browse files
Options
Downloads
Patches
Plain Diff
dhtproxy: add if logger before using it
parent
789d41ff
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
src/dht_proxy_server.cpp
+18
-9
18 additions, 9 deletions
src/dht_proxy_server.cpp
src/http.cpp
+18
-9
18 additions, 9 deletions
src/http.cpp
with
36 additions
and
18 deletions
src/dht_proxy_server.cpp
+
18
−
9
View file @
b98cc78b
...
...
@@ -139,11 +139,13 @@ DhtProxyServer::makeHttpServerSettings()
void
DhtProxyServer
::
stop
()
{
if
(
logger_
)
logger_
->
d
(
"[restinio] closing http server async operations"
);
httpServer_
->
io_context
().
reset
();
httpServer_
->
io_context
().
stop
();
if
(
httpServerThread_
.
joinable
())
httpServerThread_
.
join
();
if
(
logger_
)
logger_
->
d
(
"[restinio] http server closed"
);
}
...
...
@@ -177,6 +179,7 @@ DhtProxyServer::asyncPrintStats()
nodeInfo_
=
std
::
move
(
newInfo
);
auto
json
=
nodeInfo_
.
toJson
();
auto
str
=
Json
::
writeString
(
jsonBuilder_
,
json
);
if
(
logger_
)
logger_
->
d
(
"[stats] %s"
,
str
.
c_str
());
}
printStatsTimer_
->
expires_at
(
printStatsTimer_
->
expiry
()
+
PRINT_STATS_PERIOD
);
...
...
@@ -413,6 +416,7 @@ DhtProxyServer::subscribe(restinio::request_handle_t request,
auto
isAndroid
=
platform
==
"android"
;
auto
clientId
=
root
.
isMember
(
"client_id"
)
?
root
[
"client_id"
].
asString
()
:
std
::
string
();
if
(
logger_
)
logger_
->
w
(
"[subscribe] %s client: %s"
,
infoHash
.
toString
().
c_str
(),
clientId
.
c_str
());
// ================ Search for existing listener ===================
// start the timer
...
...
@@ -424,6 +428,7 @@ DhtProxyServer::subscribe(restinio::request_handle_t request,
auto
pushListeners
=
pushListener
->
second
.
listeners
.
emplace
(
infoHash
,
std
::
vector
<
Listener
>
{}).
first
;
for
(
auto
&
listener
:
pushListeners
->
second
){
if
(
logger_
)
logger_
->
w
(
"[subscribe] found client_id: %s"
,
listener
.
clientId
.
c_str
());
// Found -> Resubscribe
if
(
listener
.
clientId
==
clientId
){
...
...
@@ -490,9 +495,12 @@ DhtProxyServer::subscribe(restinio::request_handle_t request,
listener
.
expireNotifyTimer
->
async_wait
(
[
this
,
infoHash
,
pushToken
,
isAndroid
,
clientId
](
const
asio
::
error_code
&
ec
){
if
(
logger_
)
logger_
->
d
(
"[subscribe] sending refresh %s"
,
infoHash
.
toString
().
c_str
());
if
(
ec
)
if
(
ec
){
if
(
logger_
)
logger_
->
d
(
"[subscribe] error sending refresh: %s"
,
ec
.
message
().
c_str
());
}
Json
::
Value
json
;
json
[
"timeout"
]
=
infoHash
.
toString
();
json
[
"to"
]
=
clientId
;
...
...
@@ -561,6 +569,7 @@ DhtProxyServer::unsubscribe(restinio::request_handle_t request,
void
DhtProxyServer
::
cancelPushListen
(
const
std
::
string
&
pushToken
,
const
dht
::
InfoHash
&
key
,
const
std
::
string
&
clientId
)
{
if
(
logger_
)
logger_
->
d
(
"[cancelpushlisten] %s %s"
,
key
.
toString
().
c_str
(),
clientId
.
c_str
());
std
::
lock_guard
<
std
::
mutex
>
lock
(
*
lockListener_
);
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
18
−
9
View file @
b98cc78b
...
...
@@ -90,10 +90,12 @@ ConnectionListener::state_changed(const restinio::connection_state::notice_t &no
if
(
listeners_
->
find
(
id
)
!=
listeners_
->
end
()){
if
(
notice
.
cause
()
==
restinio
::
connection_state
::
cause_t
::
closed
){
if
(
logger_
)
logger_
->
d
(
"[restinio] [connection:%li] cancelling listener"
,
id
);
dht_
->
cancelListen
(
listeners_
->
at
(
id
).
hash
,
std
::
move
(
listeners_
->
at
(
id
).
token
));
listeners_
->
erase
(
id
);
if
(
logger_
)
logger_
->
d
(
"[restinio] %li listeners are connected"
,
listeners_
->
size
());
}
}
...
...
@@ -160,6 +162,7 @@ Client::open_conn(){
connId_
,
std
::
move
(
asio
::
ip
::
tcp
::
socket
{
resolver_
.
get_io_context
()})
);
if
(
logger_
)
logger_
->
d
(
"[connection:%i] created"
,
conn
->
id
());
connId_
++
;
return
conn
;
...
...
@@ -226,17 +229,20 @@ Client::async_request(std::string request,
resolver_
.
async_resolve
(
build_query
(),
[
=
](
std
::
error_code
ec
,
tcp
::
resolver
::
results_type
res
){
if
(
ec
or
res
.
empty
()){
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error resolving"
,
conn
->
id
());
conn
->
close
();
return
;
}
for
(
auto
da
=
res
.
begin
();
da
!=
res
.
end
();
++
da
){
if
(
logger_
)
logger_
->
d
(
"[connection:%i] resolved host=%s service=%s"
,
conn
->
id
(),
da
->
host_name
().
c_str
(),
da
->
service_name
().
c_str
());
conn
->
start
(
da
);
break
;
}
if
(
!
conn
->
is_open
()){
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error closed connection"
,
conn
->
id
());
return
;
}
...
...
@@ -244,6 +250,7 @@ Client::async_request(std::string request,
logger_
->
d
(
"[connection:%i] request write"
,
conn
->
id
());
conn
->
write
(
request
,
ec
);
if
(
ec
and
ec
!=
asio
::
error
::
eof
){
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error: %s"
,
conn
->
id
(),
ec
.
message
().
c_str
());
return
;
}
...
...
@@ -262,6 +269,7 @@ Client::async_request(std::string request,
// detect parsing errors
if
(
HPE_OK
!=
parser
->
http_errno
&&
HPE_PAUSED
!=
parser
->
http_errno
){
auto
err
=
HTTP_PARSER_ERRNO
(
parser
.
get
());
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error parsing: %s"
,
conn
->
id
(),
http_errno_name
(
err
));
}
...
...
@@ -269,6 +277,7 @@ Client::async_request(std::string request,
if
(
ec
!=
asio
::
error
::
eof
)
throw
std
::
runtime_error
{
fmt
::
format
(
"[connection:{}] error parsing: {}"
,
conn
->
id
(),
ec
)};
if
(
logger_
)
logger_
->
d
(
"[connection:%i] request finished"
,
conn
->
id
());
});
}
...
...
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