Browse Source

handle incoming datagramms

pull/106/head
orignal 10 years ago
parent
commit
2dfd351e7a
  1. 27
      Datagram.cpp
  2. 1
      Datagram.h

27
Datagram.cpp

@ -67,6 +67,31 @@ namespace datagram @@ -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 @@ -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");

1
Datagram.h

@ -28,6 +28,7 @@ namespace datagram @@ -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:

Loading…
Cancel
Save