mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
compression threshold
This commit is contained in:
parent
6e70c04516
commit
49c57db6b7
@ -20,7 +20,7 @@ namespace stream
|
|||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local,
|
||||||
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
||||||
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
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_RemoteLeaseSet (&remote), m_ReceiveTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
@ -29,7 +29,7 @@ namespace stream
|
|||||||
|
|
||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination * local):
|
||||||
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
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_RemoteLeaseSet (nullptr), m_ReceiveTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
@ -482,10 +482,14 @@ namespace stream
|
|||||||
if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ())
|
if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ())
|
||||||
{
|
{
|
||||||
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
|
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
|
||||||
// TODO: make it atomic
|
if (!m_LeaseSet)
|
||||||
auto oldLeaseSet = m_LeaseSet;
|
m_LeaseSet = newLeaseSet;
|
||||||
m_LeaseSet = newLeaseSet;
|
else
|
||||||
delete oldLeaseSet;
|
{
|
||||||
|
// TODO: implement it better
|
||||||
|
*m_LeaseSet = *newLeaseSet;
|
||||||
|
delete newLeaseSet;
|
||||||
|
}
|
||||||
for (auto it: m_Streams)
|
for (auto it: m_Streams)
|
||||||
it.second->SetLeaseSetUpdated ();
|
it.second->SetLeaseSetUpdated ();
|
||||||
}
|
}
|
||||||
@ -648,9 +652,10 @@ namespace stream
|
|||||||
|
|
||||||
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
|
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
|
||||||
{
|
{
|
||||||
I2NPMessage * msg = NewI2NPMessage ();
|
I2NPMessage * msg = NewI2NPShortMessage ();
|
||||||
CryptoPP::Gzip compressor;
|
CryptoPP::Gzip compressor; // DEFAULT_DEFLATE_LEVEL
|
||||||
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
|
if (len <= COMPRESSION_THRESHOLD_SIZE)
|
||||||
|
compressor.SetDeflateLevel (CryptoPP::Gzip::MIN_DEFLATE_LEVEL);
|
||||||
compressor.Put (payload, len);
|
compressor.Put (payload, len);
|
||||||
compressor.MessageEnd();
|
compressor.MessageEnd();
|
||||||
int size = compressor.MaxRetrievable ();
|
int size = compressor.MaxRetrievable ();
|
||||||
|
@ -35,7 +35,8 @@ namespace stream
|
|||||||
|
|
||||||
const size_t STREAMING_MTU = 1730;
|
const size_t STREAMING_MTU = 1730;
|
||||||
const size_t MAX_PACKET_SIZE = 4096;
|
const size_t MAX_PACKET_SIZE = 4096;
|
||||||
|
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
|
||||||
|
|
||||||
struct Packet
|
struct Packet
|
||||||
{
|
{
|
||||||
uint8_t buf[MAX_PACKET_SIZE];
|
uint8_t buf[MAX_PACKET_SIZE];
|
||||||
@ -113,7 +114,7 @@ namespace stream
|
|||||||
boost::asio::io_service& m_Service;
|
boost::asio::io_service& m_Service;
|
||||||
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
||||||
int32_t m_LastReceivedSequenceNumber;
|
int32_t m_LastReceivedSequenceNumber;
|
||||||
bool m_IsOpen, m_IsOutgoing, m_LeaseSetUpdated;
|
bool m_IsOpen, m_LeaseSetUpdated;
|
||||||
StreamingDestination * m_LocalDestination;
|
StreamingDestination * m_LocalDestination;
|
||||||
i2p::data::Identity m_RemoteIdentity;
|
i2p::data::Identity m_RemoteIdentity;
|
||||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user