Skip to content

Commit

Permalink
AES/ElGamal session tags per local destination
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 7, 2014
1 parent 0af9633 commit 49d67ba
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 221 deletions.
27 changes: 14 additions & 13 deletions Destination.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <fstream>
#include <algorithm>
#include <cryptopp/dh.h>
#include <cryptopp/gzip.h>
#include "Log.h"
#include "util.h"
#include "Destination.h"
Expand Down Expand Up @@ -177,22 +178,22 @@ namespace stream
if (buf[9] == 6) // streaming protocol
{
// unzip it
CryptoPP::Gunzip m_Decompressor;
m_Decompressor.Put (buf, length);
m_Decompressor.MessageEnd();
CryptoPP::Gunzip decompressor;
decompressor.Put (buf, length);
decompressor.MessageEnd();
Packet * uncompressed = new Packet;
uncompressed->offset = 0;
uncompressed->len = m_Decompressor.MaxRetrievable ();
uncompressed->len = decompressor.MaxRetrievable ();
if (uncompressed->len <= MAX_PACKET_SIZE)
{
m_Decompressor.Get (uncompressed->buf, uncompressed->len);
decompressor.Get (uncompressed->buf, uncompressed->len);
// then forward to streaming thread
m_Service.post (boost::bind (&StreamingDestination::HandleNextPacket, this, uncompressed));
}
else
{
LogPrint ("Received packet size ", uncompressed->len, " exceeds max packet size. Skipped");
m_Decompressor.Skip ();
decompressor.Skip ();
delete uncompressed;
}
}
Expand All @@ -203,18 +204,18 @@ namespace stream
I2NPMessage * StreamingDestination::CreateDataMessage (const uint8_t * payload, size_t len)
{
I2NPMessage * msg = NewI2NPShortMessage ();
CryptoPP::Gzip m_Compressor;
CryptoPP::Gzip compressor;
if (len <= COMPRESSION_THRESHOLD_SIZE)
m_Compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
else
m_Compressor.SetDeflateLevel (CryptoPP::Gzip::DEFAULT_DEFLATE_LEVEL);
m_Compressor.Put (payload, len);
m_Compressor.MessageEnd();
int size = m_Compressor.MaxRetrievable ();
compressor.SetDeflateLevel (CryptoPP::Gzip::DEFAULT_DEFLATE_LEVEL);
compressor.Put (payload, len);
compressor.MessageEnd();
int size = compressor.MaxRetrievable ();
uint8_t * buf = msg->GetPayload ();
*(uint32_t *)buf = htobe32 (size); // length
buf += 4;
m_Compressor.Get (buf, size);
compressor.Get (buf, size);
memset (buf + 4, 0, 4); // source and destination ports. TODO: fill with proper values later
buf[9] = 6; // streaming protocol
msg->len += size + 4;
Expand Down
4 changes: 0 additions & 4 deletions Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <thread>
#include <mutex>
#include <cryptopp/gzip.h>
#include "Identity.h"
#include "TunnelPool.h"
#include "CryptoConst.h"
Expand Down Expand Up @@ -64,9 +63,6 @@ namespace stream
bool m_IsPublic;

std::function<void (Stream *)> m_Acceptor;

//CryptoPP::Gzip m_Compressor;
//CryptoPP::Gunzip m_Decompressor;
};

class StreamingDestinations
Expand Down
Loading

0 comments on commit 49d67ba

Please sign in to comment.