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

Method CreateDataMessage

libi2pd/Datagram.cpp:455–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453 }
454
455 std::shared_ptr<I2NPMessage> DatagramDestination::CreateDataMessage (
456 const std::vector<std::pair<const uint8_t *, size_t> >& payloads,
457 uint16_t fromPort, uint16_t toPort, uint8_t protocolType, bool checksum)
458 {
459 size_t size;
460 auto msg = m_I2NPMsgsPool.AcquireShared ();
461 uint8_t * buf = msg->GetPayload ();
462 buf += 4; // reserve for length
463
464 if (m_Gzip && m_Deflator)
465 size = m_Deflator->Deflate (payloads, buf, msg->maxLen - msg->len);
466 else
467 size = i2p::data::GzipNoCompression (payloads, buf, msg->maxLen - msg->len);
468
469 if (size)
470 {
471 htobe32buf (msg->GetPayload (), size); // length
472 htobe16buf (buf + 4, fromPort); // source port
473 htobe16buf (buf + 6, toPort); // destination port
474 buf[9] = protocolType; // raw or datagram protocol
475 msg->len += size + 4;
476 msg->FillI2NPMessageHeader (eI2NPData, 0, checksum);
477 }
478 else
479 msg = nullptr;
480 return msg;
481 }
482
483 void DatagramDestination::CleanUp ()
484 {

Callers

nothing calls this directly

Calls 7

GzipNoCompressionFunction · 0.85
htobe32bufFunction · 0.85
htobe16bufFunction · 0.85
AcquireSharedMethod · 0.80
DeflateMethod · 0.80
FillI2NPMessageHeaderMethod · 0.80
GetPayloadMethod · 0.45

Tested by

no test coverage detected