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

Method ProcessDatagramSend

libi2pd_client/SAM.cpp:768–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

766
767
768 size_t SAMSocket::ProcessDatagramSend (char * buf, size_t len, const char * data)
769 {
770 LogPrint (eLogDebug, "SAM: Datagram send: ", buf, " ", len);
771 auto params = ExtractParams (buf);
772 size_t size = 0;
773 std::string_view sizeStr = params[SAM_PARAM_SIZE];
774 auto res = std::from_chars(sizeStr.data(), sizeStr.data() + sizeStr.size(), size);
775 if (res.ec != std::errc()) size = 0;
776 size_t offset = data - buf;
777 if (offset + size <= len)
778 {
779 auto session = m_Owner.FindSession(m_ID);
780 if (session)
781 {
782 auto d = session->GetLocalDestination ()->GetDatagramDestination ();
783 if (d)
784 {
785 i2p::data::IdentityEx dest;
786 dest.FromBase64 (params[SAM_PARAM_DESTINATION]);
787 if (session->Type == SAMSessionType::eSAMSessionTypeDatagram)
788 d->SendDatagramTo ((const uint8_t *)data, size, dest.GetIdentHash ());
789 else // raw
790 d->SendRawDatagramTo ((const uint8_t *)data, size, dest.GetIdentHash ());
791 }
792 else
793 LogPrint (eLogError, "SAM: Missing datagram destination");
794 }
795 else
796 LogPrint (eLogError, "SAM: Session is not created from DATAGRAM SEND");
797 }
798 else
799 {
800 LogPrint (eLogWarning, "SAM: Sent datagram size ", size, " exceeds buffer ", len - offset);
801 return 0; // try to receive more
802 }
803 return offset + size;
804 }
805
806 void SAMSocket::ProcessDestGenerate (std::string_view buf)
807 {

Callers

nothing calls this directly

Calls 7

LogPrintFunction · 0.85
FromBase64Method · 0.80
SendDatagramToMethod · 0.80
SendRawDatagramToMethod · 0.80
FindSessionMethod · 0.45
GetLocalDestinationMethod · 0.45

Tested by

no test coverage detected