MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / SendData

Method SendData

libi2pd/SSU2Session.cpp:1687–1710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1685 }
1686
1687 uint32_t SSU2Session::SendData (const uint8_t * buf, size_t len, uint8_t flags)
1688 {
1689 if (len < 8)
1690 {
1691 LogPrint (eLogWarning, "SSU2: Data message payload is too short ", (int)len);
1692 return 0;
1693 }
1694 Header header;
1695 header.h.connID = m_DestConnID;
1696 header.h.packetNum = htobe32 (m_SendPacketNum);
1697 header.h.type = eSSU2Data;
1698 memset (header.h.flags, 0, 3);
1699 if (flags) header.h.flags[0] = flags;
1700 uint8_t nonce[12];
1701 CreateNonce (m_SendPacketNum, nonce);
1702 uint8_t payload[SSU2_MAX_PACKET_SIZE];
1703 m_Server.AEADChaCha20Poly1305Encrypt (buf, len, header.buf, 16, m_KeyDataSend, nonce, payload, SSU2_MAX_PACKET_SIZE);
1704 header.ll[0] ^= CreateHeaderMask (m_Address->i, payload + (len - 8));
1705 header.ll[1] ^= CreateHeaderMask (m_KeyDataSend + 32, payload + (len + 4));
1706 m_Server.Send (header.buf, 16, payload, len + 16, m_RemoteEndpoint);
1707 m_SendPacketNum++;
1708 UpdateNumSentBytes (len + 32);
1709 return m_SendPacketNum - 1;
1710 }
1711
1712 void SSU2Session::ProcessData (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from)
1713 {

Callers 4

SendLocalRouterInfoMethod · 0.80
HandleRelayRequestMethod · 0.80
HandleRelayResponseMethod · 0.80
HandlePeerTestMethod · 0.80

Calls 6

LogPrintFunction · 0.85
htobe32Function · 0.85
CreateNonceFunction · 0.85
CreateHeaderMaskFunction · 0.85
SendMethod · 0.45

Tested by

no test coverage detected