|
|
|
@ -225,7 +225,10 @@ namespace transport
@@ -225,7 +225,10 @@ namespace transport
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (port) |
|
|
|
|
{ |
|
|
|
|
OpenSocket (port); |
|
|
|
|
Receive (); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
LogPrint (eLogError, "SSU2: Can't start server because port not specified "); |
|
|
|
|
break; |
|
|
|
@ -256,6 +259,36 @@ namespace transport
@@ -256,6 +259,36 @@ namespace transport
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SSU2Server::Receive () |
|
|
|
|
{ |
|
|
|
|
Packet * packet = m_PacketsPool.AcquireMt (); |
|
|
|
|
m_Socket.async_receive_from (boost::asio::buffer (packet->buf, SSU2_MTU), packet->from, |
|
|
|
|
std::bind (&SSU2Server::HandleReceivedFrom, this, std::placeholders::_1, std::placeholders::_2, packet)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SSU2Server::HandleReceivedFrom (const boost::system::error_code& ecode, size_t bytes_transferred, Packet * packet) |
|
|
|
|
{ |
|
|
|
|
if (!ecode) |
|
|
|
|
{ |
|
|
|
|
packet->len = bytes_transferred; |
|
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
|
Receive (); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
|
if (ecode != boost::asio::error::operation_aborted) |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "SSU2: Receive error: code ", ecode.value(), ": ", ecode.message ()); |
|
|
|
|
auto port = m_Socket.local_endpoint ().port (); |
|
|
|
|
m_Socket.close (); |
|
|
|
|
OpenSocket (port); |
|
|
|
|
Receive (); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SSU2Server::AddSession (uint64_t connID, std::shared_ptr<SSU2Session> session) |
|
|
|
|
{ |
|
|
|
|
m_Sessions.emplace (connID, session); |
|
|
|
|