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

Method SendMessageMessageHandler

libi2pd_client/I2CP.cpp:896–952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

894 }
895
896 void I2CPSession::SendMessageMessageHandler (const uint8_t * buf, size_t len)
897 {
898 uint16_t sessionID = bufbe16toh (buf);
899 if (sessionID == m_SessionID)
900 {
901 size_t offset = 2;
902 if (m_Destination)
903 {
904 const uint8_t * ident = buf + offset;
905 size_t identSize = i2p::data::GetIdentityBufferLen (ident, len - offset);
906 if (identSize)
907 {
908 offset += identSize;
909 uint32_t payloadLen = bufbe32toh (buf + offset);
910 if (payloadLen + offset <= len)
911 {
912 offset += 4;
913 uint32_t nonce = bufbe32toh (buf + offset + payloadLen);
914 if (m_Destination->IsReady ())
915 {
916 if (m_IsSendAccepted)
917 SendMessageStatusMessage (nonce, eI2CPMessageStatusAccepted); // accepted
918 std::shared_ptr<i2p::garlic::GarlicRoutingSession> remoteSession;
919 {
920 std::lock_guard<std::mutex> l(m_RoutingSessionsMutex);
921 auto it = m_RoutingSessions.find (ident + i2p::data::DEFAULT_IDENTITY_SIZE - 35); // 32 bytes signing key
922 if (it != m_RoutingSessions.end ())
923 {
924 if (!it->second->IsTerminated () && it->second->IsReadyToSend ())
925 remoteSession = it->second;
926 else
927 m_RoutingSessions.erase (it);
928 }
929 }
930 if (!remoteSession || !m_Destination->SendMsg (buf + offset, payloadLen, remoteSession, nonce))
931 {
932 i2p::data::IdentHash identHash;
933 SHA256(ident, identSize, identHash); // calculate ident hash, because we don't need full identity
934 m_Destination->SendMsgTo (buf + offset, payloadLen, identHash, nonce);
935 }
936 }
937 else
938 {
939 LogPrint(eLogInfo, "I2CP: Destination is not ready");
940 SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLocalTunnels);
941 }
942 }
943 else
944 LogPrint(eLogError, "I2CP: Cannot send message, too big");
945 }
946 else
947 LogPrint(eLogError, "I2CP: Invalid identity");
948 }
949 }
950 else
951 LogPrint (eLogError, "I2CP: Unexpected sessionID ", sessionID);
952 }
953

Callers

nothing calls this directly

Calls 9

bufbe16tohFunction · 0.85
GetIdentityBufferLenFunction · 0.85
bufbe32tohFunction · 0.85
LogPrintFunction · 0.85
IsReadyMethod · 0.80
SendMsgToMethod · 0.80
IsTerminatedMethod · 0.45
IsReadyToSendMethod · 0.45
SendMsgMethod · 0.45

Tested by

no test coverage detected