mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
moved LeaseSet creation away from StreamingDestination
This commit is contained in:
parent
220637b29d
commit
2200133ce3
@ -209,16 +209,15 @@ namespace i2p
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet)
|
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet)
|
||||||
{
|
{
|
||||||
if (!leaseSet) return nullptr;
|
|
||||||
I2NPMessage * m = NewI2NPMessage ();
|
I2NPMessage * m = NewI2NPMessage ();
|
||||||
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
|
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
|
||||||
memcpy (msg->key, leaseSet->GetIdentHash (), 32);
|
memcpy (msg->key, leaseSet.GetIdentHash (), 32);
|
||||||
msg->type = 1; // LeaseSet
|
msg->type = 1; // LeaseSet
|
||||||
msg->replyToken = 0;
|
msg->replyToken = 0;
|
||||||
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
|
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet.GetBuffer (), leaseSet.GetBufferLen ());
|
||||||
m->len += leaseSet->GetBufferLen () + sizeof (I2NPDatabaseStoreMsg);
|
m->len += leaseSet.GetBufferLen () + sizeof (I2NPDatabaseStoreMsg);
|
||||||
FillI2NPMessageHeader (m, eI2NPDatabaseStore);
|
FillI2NPMessageHeader (m, eI2NPDatabaseStore);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ namespace tunnel
|
|||||||
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
|
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
|
||||||
|
|
||||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
|
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
|
||||||
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet);
|
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet);
|
||||||
|
|
||||||
I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
|
I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
|
||||||
const uint8_t * ourIdent, uint32_t receiveTunnelID,
|
const uint8_t * ourIdent, uint32_t receiveTunnelID,
|
||||||
|
@ -426,41 +426,10 @@ namespace stream
|
|||||||
|
|
||||||
I2NPMessage * StreamingDestination::CreateLeaseSet () const
|
I2NPMessage * StreamingDestination::CreateLeaseSet () const
|
||||||
{
|
{
|
||||||
I2NPMessage * m = NewI2NPMessage ();
|
// TODO: should store actual LeaseSet rather than msg
|
||||||
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
|
if (!m_Pool) return nullptr;
|
||||||
memcpy (msg->key, (const uint8_t *)m_IdentHash, 32);
|
i2p::data::LeaseSet leaseSet(*m_Pool);
|
||||||
msg->type = 1; // LeaseSet
|
return CreateDatabaseStoreMsg (leaseSet);
|
||||||
msg->replyToken = 0;
|
|
||||||
|
|
||||||
uint8_t * buf = m->GetPayload () + sizeof (I2NPDatabaseStoreMsg);
|
|
||||||
size_t size = 0;
|
|
||||||
memcpy (buf + size, &m_Keys.pub, sizeof (m_Keys.pub));
|
|
||||||
size += sizeof (m_Keys.pub); // destination
|
|
||||||
memcpy (buf + size, m_Pool->GetEncryptionPublicKey (), 256);
|
|
||||||
size += 256; // encryption key
|
|
||||||
memset (buf + size, 0, 128);
|
|
||||||
size += 128; // signing key
|
|
||||||
auto tunnels = m_Pool->GetInboundTunnels (5); // 5 tunnels maximum
|
|
||||||
buf[size] = tunnels.size (); // num leases
|
|
||||||
size++; // num
|
|
||||||
for (auto it: tunnels)
|
|
||||||
{
|
|
||||||
auto tunnel = it;
|
|
||||||
memcpy (buf + size, (const uint8_t *)tunnel->GetNextIdentHash (), 32);
|
|
||||||
size += 32; // tunnel_gw
|
|
||||||
*(uint32_t *)(buf + size) = htobe32 (tunnel->GetNextTunnelID ());
|
|
||||||
size += 4; // tunnel_id
|
|
||||||
uint64_t ts = tunnel->GetCreationTime () + i2p::tunnel::TUNNEL_EXPIRATION_TIMEOUT - 60; // 1 minute before expiration
|
|
||||||
ts *= 1000; // in milliseconds
|
|
||||||
*(uint64_t *)(buf + size) = htobe64 (ts);
|
|
||||||
size += 8; // end_date
|
|
||||||
}
|
|
||||||
Sign (buf, size, buf+ size);
|
|
||||||
size += 40; // signature
|
|
||||||
LogPrint ("Local LeaseSet of ", tunnels.size (), " leases created");
|
|
||||||
m->len += size + sizeof (I2NPDatabaseStoreMsg);
|
|
||||||
FillI2NPMessageHeader (m, eI2NPDatabaseStore);
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user