mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
create data message inside detination
This commit is contained in:
parent
df518ac5fd
commit
9f1e496fa4
@ -197,6 +197,27 @@ namespace stream
|
||||
LogPrint ("Data: unexpected protocol ", buf[9]);
|
||||
}
|
||||
|
||||
I2NPMessage * StreamingDestination::CreateDataMessage (const uint8_t * payload, size_t len)
|
||||
{
|
||||
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 ();
|
||||
uint8_t * buf = msg->GetPayload ();
|
||||
*(uint32_t *)buf = htobe32 (size); // length
|
||||
buf += 4;
|
||||
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;
|
||||
FillI2NPMessageHeader (msg, eI2NPData);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
void StreamingDestination::SetLeaseSetUpdated ()
|
||||
{
|
||||
UpdateLeaseSet ();
|
||||
@ -385,26 +406,5 @@ namespace stream
|
||||
{
|
||||
return destinations;
|
||||
}
|
||||
|
||||
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
|
||||
{
|
||||
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 ();
|
||||
uint8_t * buf = msg->GetPayload ();
|
||||
*(uint32_t *)buf = htobe32 (size); // length
|
||||
buf += 4;
|
||||
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;
|
||||
FillI2NPMessageHeader (msg, eI2NPData);
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,14 +33,16 @@ namespace stream
|
||||
bool IsAcceptorSet () const { return m_Acceptor != nullptr; };
|
||||
void HandleNextPacket (Packet * packet);
|
||||
void SendTunnelDataMsgs (const std::vector<i2p::tunnel::TunnelMessageBlock>& msgs);
|
||||
void ResetCurrentOutboundTunnel () { m_CurrentOutboundTunnel = nullptr; };
|
||||
// I2CP
|
||||
void HandleDataMessage (const uint8_t * buf, size_t len);
|
||||
I2NPMessage * CreateDataMessage (const uint8_t * payload, size_t len);
|
||||
|
||||
// implements LocalDestination
|
||||
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
||||
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
|
||||
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
|
||||
void SetLeaseSetUpdated ();
|
||||
void HandleDataMessage (const uint8_t * buf, size_t len);
|
||||
void ResetCurrentOutboundTunnel () { m_CurrentOutboundTunnel = nullptr; };
|
||||
|
||||
private:
|
||||
|
||||
@ -117,9 +119,6 @@ namespace stream
|
||||
StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||
// for HTTP
|
||||
const StreamingDestinations& GetLocalDestinations ();
|
||||
|
||||
// assuming data is I2CP message
|
||||
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ namespace stream
|
||||
for (auto it: packets)
|
||||
{
|
||||
auto msg = m_RoutingSession->WrapSingleMessage (
|
||||
CreateDataMessage (this, it->GetBuffer (), it->GetLength ()),
|
||||
m_LocalDestination.CreateDataMessage (it->GetBuffer (), it->GetLength ()),
|
||||
leaseSet);
|
||||
msgs.push_back (i2p::tunnel::TunnelMessageBlock
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user