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

Method ProcessData

libi2pd/SSU2Session.cpp:1712–1753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1710 }
1711
1712 void SSU2Session::ProcessData (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from)
1713 {
1714 Header header;
1715 header.ll[0] = m_SourceConnID;
1716 memcpy (header.buf + 8, buf + 8, 8);
1717 header.ll[1] ^= CreateHeaderMask (m_KeyDataReceive + 32, buf + (len - 12));
1718 if (header.h.type != eSSU2Data)
1719 {
1720 LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type, " instead ", (int)eSSU2Data);
1721 if (IsEstablished ())
1722 SendQuickAck (); // in case it was SessionConfirmed
1723 else
1724 ResendHandshakePacket (); // assume we receive
1725 return;
1726 }
1727 if (from != m_RemoteEndpoint && !i2p::transport::transports.IsInReservedRange (from.address ()) &&
1728 (!m_PathChallenge || from != m_PathChallenge->second)) // path challenge was not sent to this endpoint yet
1729 {
1730 LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
1731 SendPathChallenge (from);
1732 }
1733 if (len < 32)
1734 {
1735 LogPrint (eLogWarning, "SSU2: Data message too short ", len);
1736 return;
1737 }
1738 uint8_t payload[SSU2_MAX_PACKET_SIZE];
1739 size_t payloadSize = len - 32;
1740 uint32_t packetNum = be32toh (header.h.packetNum);
1741 uint8_t nonce[12];
1742 CreateNonce (packetNum, nonce);
1743 if (!m_Server.AEADChaCha20Poly1305Decrypt (buf + 16, payloadSize, header.buf, 16,
1744 m_KeyDataReceive, nonce, payload, payloadSize))
1745 {
1746 LogPrint (eLogWarning, "SSU2: Data AEAD verification failed ");
1747 return;
1748 }
1749 UpdateNumReceivedBytes (len);
1750 if (header.h.flags[0] & SSU2_FLAG_IMMEDIATE_ACK_REQUESTED) m_IsDataReceived = true;
1751 if (!packetNum || UpdateReceivePacketNum (packetNum))
1752 HandlePayload (payload, payloadSize);
1753 }
1754
1755 void SSU2Session::HandlePayload (const uint8_t * buf, size_t len)
1756 {

Callers 1

ProcessNextPacketMethod · 0.80

Calls 6

CreateHeaderMaskFunction · 0.85
LogPrintFunction · 0.85
be32tohFunction · 0.85
CreateNonceFunction · 0.85
IsInReservedRangeMethod · 0.80

Tested by

no test coverage detected