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

Method SendRetry

libi2pd/SSU2Session.cpp:1541–1579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1539 }
1540
1541 void SSU2Session::SendRetry ()
1542 {
1543 // we are Bob
1544 Header header;
1545 uint8_t h[32], payload[72];
1546 // fill packet
1547 header.h.connID = m_DestConnID; // dest id
1548 RAND_bytes (header.buf + 8, 4); // random packet num
1549 header.h.type = eSSU2Retry;
1550 header.h.flags[0] = GetVersion (); // ver
1551 header.h.flags[1] = (uint8_t)i2p::context.GetNetID (); // netID
1552 header.h.flags[2] = 0; // flag
1553 memcpy (h, header.buf, 16);
1554 memcpy (h + 16, &m_SourceConnID, 8); // source id
1555 uint64_t token = 0;
1556 if (m_TerminationReason == eSSU2TerminationReasonNormalClose)
1557 token = m_Server.GetIncomingToken (m_RemoteEndpoint);
1558 memcpy (h + 24, &token, 8); // token
1559 // payload
1560 payload[0] = eSSU2BlkDateTime;
1561 htobe16buf (payload + 1, 4);
1562 htobe32buf (payload + 3, (i2p::util::GetMillisecondsSinceEpoch () + 500)/1000);
1563 size_t payloadSize = 7;
1564 payloadSize += CreateAddressBlock (payload + payloadSize, 56 - payloadSize, m_RemoteEndpoint);
1565 if (m_TerminationReason != eSSU2TerminationReasonNormalClose)
1566 payloadSize += CreateTerminationBlock (payload + payloadSize, 56 - payloadSize);
1567 payloadSize += CreatePaddingBlock (payload + payloadSize, 56 - payloadSize);
1568 // encrypt
1569 uint8_t nonce[12];
1570 CreateNonce (be32toh (header.h.packetNum), nonce);
1571 i2p::crypto::AEADChaCha20Poly1305 (payload, payloadSize, h, 32, i2p::context.GetSSU2IntroKey (), nonce, payload, payloadSize + 16, true);
1572 payloadSize += 16;
1573 header.ll[0] ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), payload + (payloadSize - 24));
1574 header.ll[1] ^= CreateHeaderMask (i2p::context.GetSSU2IntroKey (), payload + (payloadSize - 12));
1575 memset (nonce, 0, 12);
1576 m_Server.ChaCha20 (h + 16, 16, i2p::context.GetSSU2IntroKey (), nonce, h + 16);
1577 // send
1578 m_Server.Send (header.buf, 16, h + 16, 16, payload, payloadSize, m_RemoteEndpoint);
1579 }
1580
1581 bool SSU2Session::ProcessRetry (uint8_t * buf, size_t len)
1582 {

Callers

nothing calls this directly

Calls 12

htobe16bufFunction · 0.85
htobe32bufFunction · 0.85
CreateNonceFunction · 0.85
be32tohFunction · 0.85
AEADChaCha20Poly1305Function · 0.85
CreateHeaderMaskFunction · 0.85
GetNetIDMethod · 0.80
GetIncomingTokenMethod · 0.80
GetSSU2IntroKeyMethod · 0.80
ChaCha20Method · 0.80
SendMethod · 0.45

Tested by

no test coverage detected