|
|
@ -635,7 +635,14 @@ namespace transport |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_t NTCPSession::CreateMsgBuffer (std::shared_ptr<I2NPMessage> msg, uint8_t * buf) |
|
|
|
void NTCPSession::Send (std::shared_ptr<i2p::I2NPMessage> msg) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_IsSending = true; |
|
|
|
|
|
|
|
boost::asio::async_write (m_Socket, CreateMsgBuffer (msg), boost::asio::transfer_all (), |
|
|
|
|
|
|
|
std::bind(&NTCPSession::HandleSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, std::vector<std::shared_ptr<I2NPMessage> >{ msg })); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boost::asio::const_buffers_1 NTCPSession::CreateMsgBuffer (std::shared_ptr<I2NPMessage> msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t * sendBuffer; |
|
|
|
uint8_t * sendBuffer; |
|
|
|
int len; |
|
|
|
int len; |
|
|
@ -667,29 +674,24 @@ namespace transport |
|
|
|
htobe32buf (sendBuffer + len + 2 + padding, adler32 (adler32 (0, Z_NULL, 0), sendBuffer, len + 2+ padding)); |
|
|
|
htobe32buf (sendBuffer + len + 2 + padding, adler32 (adler32 (0, Z_NULL, 0), sendBuffer, len + 2+ padding)); |
|
|
|
|
|
|
|
|
|
|
|
int l = len + padding + 6; |
|
|
|
int l = len + padding + 6; |
|
|
|
m_Encryption.Encrypt(sendBuffer, l, buf); |
|
|
|
m_Encryption.Encrypt(sendBuffer, l, sendBuffer); |
|
|
|
return l; |
|
|
|
return boost::asio::buffer ((const uint8_t *)sendBuffer, l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::Send (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) |
|
|
|
void NTCPSession::Send (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!msgs.size ()) return; |
|
|
|
|
|
|
|
m_IsSending = true; |
|
|
|
m_IsSending = true; |
|
|
|
size_t len = 0; |
|
|
|
std::vector<boost::asio::const_buffer> bufs; |
|
|
|
for (const auto& it: msgs) |
|
|
|
for (const auto& it: msgs) |
|
|
|
len += it->GetLength () + 22; // 6 + 16
|
|
|
|
bufs.push_back (CreateMsgBuffer (it)); |
|
|
|
uint8_t * buf = new uint8_t[len]; |
|
|
|
boost::asio::async_write (m_Socket, bufs, boost::asio::transfer_all (), |
|
|
|
len = 0; |
|
|
|
std::bind(&NTCPSession::HandleSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, msgs)); |
|
|
|
for (const auto& it: msgs) |
|
|
|
|
|
|
|
len += CreateMsgBuffer (it, buf + len); |
|
|
|
|
|
|
|
boost::asio::async_write (m_Socket, boost::asio::buffer (buf, len), boost::asio::transfer_all (), |
|
|
|
|
|
|
|
std::bind(&NTCPSession::HandleSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, buf)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, uint8_t * buf) |
|
|
|
void NTCPSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, std::vector<std::shared_ptr<I2NPMessage> > msgs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delete[] buf; |
|
|
|
(void) msgs; |
|
|
|
m_IsSending = false; |
|
|
|
m_IsSending = false; |
|
|
|
if (ecode) |
|
|
|
if (ecode) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -714,11 +716,7 @@ namespace transport |
|
|
|
|
|
|
|
|
|
|
|
void NTCPSession::SendTimeSyncMessage () |
|
|
|
void NTCPSession::SendTimeSyncMessage () |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t * buf = new uint8_t[16]; |
|
|
|
Send (nullptr); |
|
|
|
m_IsSending = true; |
|
|
|
|
|
|
|
auto len = CreateMsgBuffer (nullptr, buf); // nullptr means timestamp
|
|
|
|
|
|
|
|
boost::asio::async_write (m_Socket, boost::asio::buffer (buf, len), boost::asio::transfer_all (), |
|
|
|
|
|
|
|
std::bind(&NTCPSession::HandleSent, shared_from_this (), std::placeholders::_1, std::placeholders::_2, buf)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|