| 596 | } |
| 597 | |
| 598 | void I2CPSession::SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len) |
| 599 | { |
| 600 | auto l = len + I2CP_HEADER_SIZE; |
| 601 | if (l > I2CP_MAX_MESSAGE_LENGTH) |
| 602 | { |
| 603 | LogPrint (eLogError, "I2CP: Message to send is too long ", l); |
| 604 | return; |
| 605 | } |
| 606 | auto sendBuf = m_IsSending ? std::make_shared<i2p::stream::SendBuffer> (l) : nullptr; |
| 607 | uint8_t * buf = sendBuf ? sendBuf->buf : m_SendBuffer; |
| 608 | htobe32buf (buf + I2CP_HEADER_LENGTH_OFFSET, len); |
| 609 | buf[I2CP_HEADER_TYPE_OFFSET] = type; |
| 610 | memcpy (buf + I2CP_HEADER_SIZE, payload, len); |
| 611 | if (sendBuf) |
| 612 | { |
| 613 | if (m_SendQueue.GetSize () < I2CP_MAX_SEND_QUEUE_SIZE) |
| 614 | m_SendQueue.Add (std::move(sendBuf)); |
| 615 | else |
| 616 | { |
| 617 | LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE); |
| 618 | return; |
| 619 | } |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | auto socket = m_Socket; |
| 624 | if (socket) |
| 625 | { |
| 626 | m_IsSending = true; |
| 627 | boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l), |
| 628 | boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent, |
| 629 | shared_from_this (), std::placeholders::_1, std::placeholders::_2)); |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
| 635 | { |
no test coverage detected