mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-14 08:50:12 +00:00
attach LeaseSet clove
This commit is contained in:
parent
7c212bef63
commit
34295adb05
@ -302,18 +302,36 @@ namespace garlic
|
|||||||
|
|
||||||
std::vector<uint8_t> ECIESX25519AEADRatchetSession::CreatePayload (std::shared_ptr<const I2NPMessage> msg)
|
std::vector<uint8_t> ECIESX25519AEADRatchetSession::CreatePayload (std::shared_ptr<const I2NPMessage> msg)
|
||||||
{
|
{
|
||||||
uint16_t cloveSize = msg->GetPayloadLength () + 9 + 1;
|
size_t payloadLen = 0;
|
||||||
std::vector<uint8_t> v(cloveSize + 3);
|
if (payloadLen)
|
||||||
uint8_t * payload = v.data ();
|
payloadLen += msg->GetPayloadLength () + 13;
|
||||||
payload[0] = eECIESx25519BlkGalicClove; // clove type
|
auto leaseSet = CreateDatabaseStoreMsg (GetOwner ()->GetLeaseSet ());
|
||||||
htobe16buf (payload + 1, cloveSize); // size
|
if (leaseSet)
|
||||||
payload[3] = 0; // flag and delivery instructions
|
payloadLen += leaseSet->GetPayloadLength () + 13;
|
||||||
payload[4] = msg->GetTypeID (); // I2NP msg type
|
std::vector<uint8_t> v(payloadLen);
|
||||||
htobe32buf (payload + 5, msg->GetMsgID ()); // msgID
|
size_t offset = 0;
|
||||||
htobe32buf (payload + 9, msg->GetExpiration ()/1000); // expiration in seconds
|
if (leaseSet)
|
||||||
memcpy (payload + 13, msg->GetPayload (), msg->GetPayloadLength ());
|
offset += CreateGarlicClove (leaseSet, v.data () + offset, payloadLen - offset);
|
||||||
|
if (msg)
|
||||||
|
offset += CreateGarlicClove (msg, v.data () + offset, payloadLen - offset);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ECIESX25519AEADRatchetSession::CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
if (!msg) return 0;
|
||||||
|
uint16_t cloveSize = msg->GetPayloadLength () + 9 + 1;
|
||||||
|
if ((int)len < cloveSize + 3) return 0;
|
||||||
|
buf[0] = eECIESx25519BlkGalicClove; // clove type
|
||||||
|
htobe16buf (buf + 1, cloveSize); // size
|
||||||
|
buf[3] = 0; // flag and delivery instructions
|
||||||
|
buf[4] = msg->GetTypeID (); // I2NP msg type
|
||||||
|
htobe32buf (buf + 5, msg->GetMsgID ()); // msgID
|
||||||
|
htobe32buf (buf + 9, msg->GetExpiration ()/1000); // expiration in seconds
|
||||||
|
memcpy (buf + 13, msg->GetPayload (), msg->GetPayloadLength ());
|
||||||
|
return cloveSize + 3;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ namespace garlic
|
|||||||
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
bool NewOutgoingSessionMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||||
bool NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
bool NewSessionReplyMessage (const uint8_t * payload, size_t len, uint8_t * out, size_t outLen);
|
||||||
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
std::vector<uint8_t> CreatePayload (std::shared_ptr<const I2NPMessage> msg);
|
||||||
|
size_t CreateGarlicClove (std::shared_ptr<const I2NPMessage> msg, uint8_t * buf, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user