Browse Source

common header for repliable datagrams

pull/1514/head
orignal 5 years ago
parent
commit
46ee427ee3
  1. 23
      libi2pd/Datagram.cpp
  2. 2
      libi2pd/Datagram.h

23
libi2pd/Datagram.cpp

@ -1,5 +1,4 @@
#include <string.h> #include <string.h>
#include <vector>
#include "Crypto.h" #include "Crypto.h"
#include "Log.h" #include "Log.h"
#include "TunnelBase.h" #include "TunnelBase.h"
@ -14,6 +13,10 @@ namespace datagram
DatagramDestination::DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner, bool gzip): DatagramDestination::DatagramDestination (std::shared_ptr<i2p::client::ClientDestination> owner, bool gzip):
m_Owner (owner), m_Receiver (nullptr), m_RawReceiver (nullptr), m_Gzip (gzip) m_Owner (owner), m_Receiver (nullptr), m_RawReceiver (nullptr), m_Gzip (gzip)
{ {
auto identityLen = m_Owner->GetIdentity ()->GetFullLen ();
m_From.resize (identityLen);
m_Owner->GetIdentity ()->ToBuffer (m_From.data (), identityLen);
m_Signature.resize (m_Owner->GetIdentity ()->GetSignatureLen ());
} }
DatagramDestination::~DatagramDestination () DatagramDestination::~DatagramDestination ()
@ -23,26 +26,18 @@ namespace datagram
void DatagramDestination::SendDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort) void DatagramDestination::SendDatagramTo(const uint8_t * payload, size_t len, const i2p::data::IdentHash & identity, uint16_t fromPort, uint16_t toPort)
{ {
auto owner = m_Owner; if (m_Owner->GetIdentity ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
auto localIdentity = m_Owner->GetIdentity ();
auto identityLen = localIdentity->GetFullLen ();
auto signatureLen = localIdentity->GetSignatureLen ();
size_t headerLen = identityLen + signatureLen;
std::vector<uint8_t> header(headerLen);
localIdentity->ToBuffer (header.data (), identityLen);
uint8_t * signature = header.data () + identityLen;
if (localIdentity->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
{ {
uint8_t hash[32]; uint8_t hash[32];
SHA256(payload, len, hash); SHA256(payload, len, hash);
owner->Sign (hash, 32, signature); m_Owner->Sign (hash, 32, m_Signature.data ());
} }
else else
owner->Sign (payload, len, signature); m_Owner->Sign (payload, len, m_Signature.data ());
auto session = ObtainSession(identity); auto session = ObtainSession(identity);
auto msg = CreateDataMessage ({{header.data (), headerLen}, {payload, len}}, fromPort, toPort, false, !session->IsRatchets ()); // datagram auto msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {m_Signature.data (), m_Signature.size ()}, {payload, len}},
fromPort, toPort, false, !session->IsRatchets ()); // datagram
session->SendMsg(msg); session->SendMsg(msg);
} }

2
libi2pd/Datagram.h

@ -5,6 +5,7 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <map> #include <map>
#include <vector>
#include "Base.h" #include "Base.h"
#include "Identity.h" #include "Identity.h"
#include "LeaseSet.h" #include "LeaseSet.h"
@ -154,6 +155,7 @@ namespace datagram
i2p::data::GzipInflator m_Inflator; i2p::data::GzipInflator m_Inflator;
i2p::data::GzipDeflator m_Deflator; i2p::data::GzipDeflator m_Deflator;
std::vector<uint8_t> m_From, m_Signature;
}; };
} }
} }

Loading…
Cancel
Save