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

Method HandleReceivedDatagram

libi2pd_client/SAM.cpp:1658–1745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1656 }
1657
1658 void SAMBridge::HandleReceivedDatagram (const boost::system::error_code& ecode, std::size_t bytes_transferred)
1659 {
1660 if (!ecode)
1661 {
1662 m_DatagramReceiveBuffer[bytes_transferred] = 0;
1663 char * eol = strchr ((char *)m_DatagramReceiveBuffer, '\n');
1664 if(eol)
1665 {
1666 *eol = 0; eol++;
1667 size_t payloadLen = bytes_transferred - ((uint8_t *)eol - m_DatagramReceiveBuffer);
1668 LogPrint (eLogDebug, "SAM: Datagram received ", m_DatagramReceiveBuffer," size=", payloadLen);
1669 char * sessionID = strchr ((char *)m_DatagramReceiveBuffer, ' ');
1670 if (sessionID)
1671 {
1672 sessionID++;
1673 char * destination = strchr (sessionID, ' ');
1674 if (destination)
1675 {
1676 *destination = 0; destination++;
1677 auto session = FindSession (sessionID);
1678 if (session)
1679 {
1680 uint16_t fromPort = 0;
1681 uint16_t toPort = 0;
1682 char *raw_params = strchr(destination, ' ');
1683 if (raw_params)
1684 {
1685 *raw_params = 0; raw_params++;
1686 auto params = SAMSocket::ExtractParams(raw_params);
1687 params.Get(SAM_PARAM_FROM_PORT, fromPort);
1688 params.Get(SAM_PARAM_TO_PORT, toPort);
1689 LogPrint (eLogInfo, "SAM: Datagram params are FROM_PORT=", fromPort, " TO_PORT=", toPort);
1690 }
1691
1692 auto localDest = session->GetLocalDestination ();
1693 auto datagramDest = localDest ? localDest->GetDatagramDestination () : nullptr;
1694 if (datagramDest)
1695 {
1696 i2p::data::IdentHash ident; bool isDest = false;
1697 if (std::string_view (destination).find(".i2p") != std::string_view::npos)
1698 {
1699 auto addr = context.GetAddressBook().GetAddress (destination);
1700 if (addr && addr->IsValid () && addr->IsIdentHash ())
1701 {
1702 ident = addr->identHash;
1703 isDest = true;
1704 }
1705 }
1706 else
1707 {
1708 i2p::data::IdentityEx dest;
1709 if (dest.FromBase64 (destination) > 0)
1710 {
1711 ident = dest.GetIdentHash ();
1712 isDest = true;
1713 }
1714 }
1715 if (isDest)

Callers

nothing calls this directly

Calls 10

LogPrintFunction · 0.85
IsIdentHashMethod · 0.80
FromBase64Method · 0.80
SendDatagramToMethod · 0.80
SendRawDatagramToMethod · 0.80
GetMethod · 0.45
GetLocalDestinationMethod · 0.45
GetAddressMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected