mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
send datagram from SAM
This commit is contained in:
parent
336fa8eed7
commit
47fb6f6e04
|
@ -39,13 +39,14 @@ namespace datagram
|
||||||
|
|
||||||
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
|
||||||
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
uint32_t i = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, leases.size () - 1);
|
||||||
auto msg = m_Owner.WrapMessage (remote, CreateDataMessage (m_OutgoingBuffer, len + m_HeaderLen));
|
auto msg = m_Owner.WrapMessage (remote, CreateDataMessage (m_OutgoingBuffer, len + m_HeaderLen), true);
|
||||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||||
{
|
{
|
||||||
i2p::tunnel::eDeliveryTypeTunnel,
|
i2p::tunnel::eDeliveryTypeTunnel,
|
||||||
leases[i].tunnelGateway, leases[i].tunnelID,
|
leases[i].tunnelGateway, leases[i].tunnelID,
|
||||||
msg
|
msg
|
||||||
});
|
});
|
||||||
|
m_Owner.SendTunnelDataMsgs (msgs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("Failed to send datagram. All leases expired");
|
LogPrint ("Failed to send datagram. All leases expired");
|
||||||
|
|
39
SAM.cpp
39
SAM.cpp
|
@ -677,6 +677,45 @@ namespace client
|
||||||
{
|
{
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
|
m_DatagramReceiveBuffer[bytes_transferred] = 0;
|
||||||
|
char * eol = strchr ((char *)m_DatagramReceiveBuffer, '\n');
|
||||||
|
*eol = 0; eol++;
|
||||||
|
size_t payloadLen = bytes_transferred - ((uint8_t *)eol - m_DatagramReceiveBuffer);
|
||||||
|
LogPrint ("SAM datagram received ", m_DatagramReceiveBuffer," size=", payloadLen);
|
||||||
|
char * sessionID = strchr ((char *)m_DatagramReceiveBuffer, ' ');
|
||||||
|
if (sessionID)
|
||||||
|
{
|
||||||
|
sessionID++;
|
||||||
|
char * destination = strchr (sessionID, ' ');
|
||||||
|
if (destination)
|
||||||
|
{
|
||||||
|
*destination = 0; destination++;
|
||||||
|
auto session = FindSession (sessionID);
|
||||||
|
if (session)
|
||||||
|
{
|
||||||
|
uint8_t ident[1024];
|
||||||
|
size_t l = i2p::data::Base64ToByteStream (destination, strlen(destination), ident, 1024);
|
||||||
|
i2p::data::IdentityEx dest;
|
||||||
|
dest.FromBuffer (ident, l);
|
||||||
|
auto leaseSet = i2p::data::netdb.FindLeaseSet (dest.GetIdentHash ());
|
||||||
|
if (leaseSet)
|
||||||
|
session->localDestination->GetDatagramDestination ()->
|
||||||
|
SendDatagramTo ((uint8_t *)eol, payloadLen, *leaseSet);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint ("SAM datagram destination not found");
|
||||||
|
i2p::data::netdb.RequestDestination (dest.GetIdentHash (), true,
|
||||||
|
session->localDestination->GetTunnelPool ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Session ", sessionID, " not found");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Missing destination key");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Missing sessionID");
|
||||||
ReceiveDatagram ();
|
ReceiveDatagram ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
2
SAM.h
2
SAM.h
|
@ -159,7 +159,7 @@ namespace client
|
||||||
SAMSocket * m_NewSocket;
|
SAMSocket * m_NewSocket;
|
||||||
std::mutex m_SessionsMutex;
|
std::mutex m_SessionsMutex;
|
||||||
std::map<std::string, SAMSession> m_Sessions;
|
std::map<std::string, SAMSession> m_Sessions;
|
||||||
uint8_t m_DatagramReceiveBuffer[i2p::datagram::MAX_DATAGRAM_SIZE];
|
uint8_t m_DatagramReceiveBuffer[i2p::datagram::MAX_DATAGRAM_SIZE+1];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue