Skip to content

Commit

Permalink
refine log
Browse files Browse the repository at this point in the history
  • Loading branch information
xyanrch committed Oct 31, 2022
1 parent a07990a commit b7e62ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions Server/ServerSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ServerSession::ServerSession(boost::asio::io_context& ioctx, boost::asio::ssl::c
ServerSession::~ServerSession()
{
connection_num--;
DEBUG_LOG << "Session dectructed, current alive session:" << connection_num.load();
DEBUG_LOG << "Session destructed, current alive session:" << connection_num.load();
}
void ServerSession::start()
{
Expand Down Expand Up @@ -81,7 +81,7 @@ void ServerSession::handle_custom_protocol()
if (valid) {
//
if (!ConfigManage::instance().server_cfg.allowed_passwords.count(password)) {
ERROR_LOG << "Session_num:[" << connection_num.load() << "] unspoorted password from client....,end session";
ERROR_LOG << "Session_num:[" << connection_num.load() << "] unsupported password from client....,end session";
destroy();
return;
}
Expand Down Expand Up @@ -156,8 +156,21 @@ void ServerSession::handle_trojan_udp_proxy()
return;
}
}
udp_async_bidirectional_write(1, udp_packet.payload, iterator);
udp_async_bidirectional_read(3);
downstream_udp_socket.async_send_to(boost::asio::buffer(udp_packet.payload), *iterator,
[this, self](boost::system::error_code ec, std::size_t length) {
if (!ec)
udp_async_bidirectional_read(3);
else {
if (ec != boost::asio::error::operation_aborted) {
ERROR_LOG << "Session_num:[" << connection_num.load() << "] closing session. Client socket write error" << ec.message();
}
// Most probably client closed socket. Let's close both sockets and exit session.
destroy();
return;
}
});
//udp_async_bidirectional_write(1, udp_packet.payload, iterator);

});
}

Expand Down Expand Up @@ -318,7 +331,7 @@ void ServerSession::do_connect(tcp::resolver::iterator& it)
}
});
}
// read packet from both dirction
// read packet from both direction
else
async_bidirectional_read(3);

Expand Down
2 changes: 1 addition & 1 deletion Shared/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ void setLogLevel(Loglevel& level);
if (logger::get_log_level() <= L_NOTICE) \
logger(__FILE__, __func__, __LINE__, L_NOTICE).stream()
#define ERROR_LOG \
logger(L_ERROR_EXIT).stream()
logger(__FILE__, __func__, __LINE__,L_ERROR_EXIT).stream()

0 comments on commit b7e62ef

Please sign in to comment.