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

Method SendClose

libi2pd/Streaming.cpp:1363–1416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1361 }
1362
1363 void Stream::SendClose ()
1364 {
1365 Packet * p = m_LocalDestination.NewPacket ();
1366 uint8_t * packet = p->GetBuffer ();
1367 size_t size = 0;
1368 htobe32buf (packet + size, m_SendStreamID);
1369 size += 4; // sendStreamID
1370 htobe32buf (packet + size, m_RecvStreamID);
1371 size += 4; // receiveStreamID
1372 htobe32buf (packet + size, m_SequenceNumber++);
1373 size += 4; // sequenceNum
1374 htobe32buf (packet + size, m_LastReceivedSequenceNumber >= 0 ? m_LastReceivedSequenceNumber : 0);
1375 size += 4; // ack Through
1376 packet[size] = 0;
1377 size++; // NACK count
1378 packet[size] = 0;
1379 size++; // resend delay
1380 uint16_t flags = PACKET_FLAG_CLOSE;
1381 if (!m_DontSign) flags |= PACKET_FLAG_SIGNATURE_INCLUDED;
1382 bool isOfflineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().IsOfflineSignature ();
1383 if (isOfflineSignature) flags |= PACKET_FLAG_OFFLINE_SIGNATURE;
1384 htobe16buf (packet + size, flags);
1385 size += 2; // flags
1386 if (m_DontSign)
1387 {
1388 memset (packet + size, 0, 2); // no options
1389 size += 2; // options size
1390 }
1391 else
1392 {
1393 if (isOfflineSignature)
1394 {
1395 const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
1396 memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
1397 size += offlineSignature.size (); // offline signature
1398 }
1399 size_t signatureLen = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetSignatureLen ();
1400 htobe16buf (packet + size, signatureLen); // signature only
1401 size += 2; // options size
1402 uint8_t * signature = packet + size;
1403 memset (packet + size, 0, signatureLen);
1404 size += signatureLen; // signature
1405 m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
1406 }
1407
1408 p->len = size;
1409 boost::asio::post (m_Service, std::bind (&Stream::SendPacket, shared_from_this (), p));
1410 if (m_RoutingSession)
1411 {
1412 int numSentPackets = m_RoutingSession->NumSentPackets ();
1413 m_RoutingSession->SetNumSentPackets (numSentPackets + 1);
1414 }
1415 LogPrint (eLogDebug, "Streaming: FIN sent, sSID=", m_SendStreamID);
1416 }
1417
1418 size_t Stream::ConcatenatePackets (uint8_t * buf, size_t len)
1419 {

Callers

nothing calls this directly

Calls 11

htobe32bufFunction · 0.85
htobe16bufFunction · 0.85
LogPrintFunction · 0.85
NewPacketMethod · 0.80
IsOfflineSignatureMethod · 0.80
NumSentPacketsMethod · 0.80
SetNumSentPacketsMethod · 0.80
GetBufferMethod · 0.45
GetOwnerMethod · 0.45
GetSignatureLenMethod · 0.45
SignMethod · 0.45

Tested by

no test coverage detected