1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-13 19:37:51 +00:00

handle incoming datagramms

This commit is contained in:
orignal 2014-10-27 16:30:56 -04:00
parent 35d4692f5f
commit 2dfd351e7a
2 changed files with 27 additions and 1 deletions

View File

@ -67,6 +67,31 @@ namespace datagram
}
}
void DatagramDestination::HandleDatagram (const uint8_t * buf, size_t len)
{
i2p::data::IdentityEx identity;
size_t identityLen = identity.FromBuffer (buf, len);
const uint8_t * signature = buf + identityLen;
size_t headerLen = identityLen + identity.GetSignatureLen ();
bool verified = false;
if (identity.GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
{
uint8_t hash[32];
CryptoPP::SHA256().CalculateDigest (hash, buf + headerLen, len - headerLen);
verified = identity.Verify (hash, 32, signature);
}
else
verified = identity.Verify (buf + headerLen, len - headerLen, signature);
if (verified)
{
// TODO: invoke datagram handler
}
else
LogPrint ("Datagram signature verification failed");
}
void DatagramDestination::HandleDataMessagePayload (const uint8_t * buf, size_t len)
{
// unzip it
@ -78,7 +103,7 @@ namespace datagram
if (uncompressedLen <= MAX_DATAGRAM_SIZE)
{
decompressor.Get (uncompressed, uncompressedLen);
//HandleNextPacket (uncompressed);
HandleDatagram (uncompressed, uncompressedLen);
}
else
LogPrint ("Received datagram size ", uncompressedLen, " exceeds max size");

View File

@ -28,6 +28,7 @@ namespace datagram
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
void SendMsg (I2NPMessage * msg, const i2p::data::LeaseSet& remote);
void HandleDatagram (const uint8_t * buf, size_t len);
private: