mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
DATAGRAM RECEIVED message
This commit is contained in:
parent
3b435f1e1d
commit
f28376bf71
6 changed files with 53 additions and 8 deletions
27
SAM.cpp
27
SAM.cpp
|
@ -226,7 +226,11 @@ namespace client
|
|||
if (m_Session->localDestination->IsReady ())
|
||||
{
|
||||
if (style == SAM_VALUE_DATAGRAM)
|
||||
m_Session->localDestination->CreateDatagramDestination ();
|
||||
{
|
||||
auto dest = m_Session->localDestination->CreateDatagramDestination ();
|
||||
dest->SetReceiver (std::bind (&SAMSocket::HandleI2PDatagramReceive, this,
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
}
|
||||
SendSessionCreateReplyOk ();
|
||||
}
|
||||
else
|
||||
|
@ -548,6 +552,27 @@ namespace client
|
|||
}
|
||||
}
|
||||
|
||||
void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& ident, const uint8_t * buf, size_t len)
|
||||
{
|
||||
uint8_t identBuf[1024];
|
||||
size_t l = ident.ToBuffer (identBuf, 1024);
|
||||
size_t l1 = i2p::data::ByteStreamToBase64 (identBuf, l, m_Buffer, SAM_SOCKET_BUFFER_SIZE);
|
||||
m_Buffer[l1] = 0;
|
||||
#ifdef _MSC_VER
|
||||
size_t l2 = sprintf_s ((char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE, SAM_DATAGRAM_RECEIVED, m_Buffer, len);
|
||||
#else
|
||||
size_t l2 = snprintf ((char *)m_StreamBuffer, SAM_SOCKET_BUFFER_SIZE, SAM_DATAGRAM_RECEIVED, m_Buffer, len);
|
||||
#endif
|
||||
if (len < SAM_SOCKET_BUFFER_SIZE - l2)
|
||||
{
|
||||
memcpy (m_StreamBuffer + l2, buf, len);
|
||||
boost::asio::async_write (m_Socket, boost::asio::buffer (m_StreamBuffer, len + l2),
|
||||
boost::bind (&SAMSocket::HandleWriteI2PData, this, boost::asio::placeholders::error));
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Datagram size ", len," exceeds buffer");
|
||||
}
|
||||
|
||||
SAMBridge::SAMBridge (int port):
|
||||
m_IsRunning (false), m_Thread (nullptr),
|
||||
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue