Browse Source

compression threshold

pull/93/head
orignal 11 years ago
parent
commit
49c57db6b7
  1. 23
      Streaming.cpp
  2. 5
      Streaming.h

23
Streaming.cpp

@ -20,7 +20,7 @@ namespace stream @@ -20,7 +20,7 @@ namespace stream
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
m_IsOutgoing(true), m_LeaseSetUpdated (true), m_LocalDestination (local),
m_LeaseSetUpdated (true), m_LocalDestination (local),
m_RemoteLeaseSet (&remote), m_ReceiveTimer (m_Service)
{
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
@ -29,7 +29,7 @@ namespace stream @@ -29,7 +29,7 @@ namespace stream
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
m_IsOpen (false), m_IsOutgoing(true), m_LeaseSetUpdated (true), m_LocalDestination (local),
m_IsOpen (false), m_LeaseSetUpdated (true), m_LocalDestination (local),
m_RemoteLeaseSet (nullptr), m_ReceiveTimer (m_Service)
{
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
@ -482,10 +482,14 @@ namespace stream @@ -482,10 +482,14 @@ namespace stream
if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ())
{
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
// TODO: make it atomic
auto oldLeaseSet = m_LeaseSet;
m_LeaseSet = newLeaseSet;
delete oldLeaseSet;
if (!m_LeaseSet)
m_LeaseSet = newLeaseSet;
else
{
// TODO: implement it better
*m_LeaseSet = *newLeaseSet;
delete newLeaseSet;
}
for (auto it: m_Streams)
it.second->SetLeaseSetUpdated ();
}
@ -648,9 +652,10 @@ namespace stream @@ -648,9 +652,10 @@ namespace stream
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
{
I2NPMessage * msg = NewI2NPMessage ();
CryptoPP::Gzip compressor;
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
I2NPMessage * msg = NewI2NPShortMessage ();
CryptoPP::Gzip compressor; // DEFAULT_DEFLATE_LEVEL
if (len <= COMPRESSION_THRESHOLD_SIZE)
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
compressor.Put (payload, len);
compressor.MessageEnd();
int size = compressor.MaxRetrievable ();

5
Streaming.h

@ -35,7 +35,8 @@ namespace stream @@ -35,7 +35,8 @@ namespace stream
const size_t STREAMING_MTU = 1730;
const size_t MAX_PACKET_SIZE = 4096;
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
struct Packet
{
uint8_t buf[MAX_PACKET_SIZE];
@ -113,7 +114,7 @@ namespace stream @@ -113,7 +114,7 @@ namespace stream
boost::asio::io_service& m_Service;
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
int32_t m_LastReceivedSequenceNumber;
bool m_IsOpen, m_IsOutgoing, m_LeaseSetUpdated;
bool m_IsOpen, m_LeaseSetUpdated;
StreamingDestination * m_LocalDestination;
i2p::data::Identity m_RemoteIdentity;
const i2p::data::LeaseSet * m_RemoteLeaseSet;

Loading…
Cancel
Save