| 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 | { |
nothing calls this directly
no test coverage detected