mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-24 01:46:36 +02:00
initial LeaseSet2 support in I2CP
This commit is contained in:
parent
a3344c4290
commit
08ddc98303
4 changed files with 53 additions and 2 deletions
|
@ -630,5 +630,14 @@ namespace data
|
||||||
htobe16buf (expiresBuf, expires > 0 ? expires : 0);
|
htobe16buf (expiresBuf, expires > 0 ? expires : 0);
|
||||||
// we don't sign it yet. must be signed later on
|
// we don't sign it yet. must be signed later on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalLeaseSet2::LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity, const uint8_t * buf, size_t len):
|
||||||
|
LocalLeaseSet (identity, nullptr, 0)
|
||||||
|
{
|
||||||
|
m_BufferLen = len;
|
||||||
|
m_Buffer = new uint8_t[m_BufferLen + 1];
|
||||||
|
memcpy (m_Buffer + 1, buf, len);
|
||||||
|
m_Buffer[0] = storeType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,7 @@ namespace data
|
||||||
LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity,
|
LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity,
|
||||||
uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey,
|
uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey,
|
||||||
std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels);
|
std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels);
|
||||||
|
LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity, const uint8_t * buf, size_t len);
|
||||||
virtual ~LocalLeaseSet2 () { delete[] m_Buffer; };
|
virtual ~LocalLeaseSet2 () { delete[] m_Buffer; };
|
||||||
|
|
||||||
uint8_t * GetBuffer () const { return m_Buffer + 1; };
|
uint8_t * GetBuffer () const { return m_Buffer + 1; };
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2016, The PurpleI2P Project
|
* Copyright (c) 2013-2019, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -68,6 +68,13 @@ namespace client
|
||||||
SetLeaseSet (ls);
|
SetLeaseSet (ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2CPDestination::LeaseSet2Created (uint8_t storeType, const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
auto ls = new i2p::data::LocalLeaseSet2 (storeType, m_Identity, buf, len);
|
||||||
|
ls->SetExpirationTime (m_LeaseSetExpirationTime);
|
||||||
|
SetLeaseSet (ls);
|
||||||
|
}
|
||||||
|
|
||||||
void I2CPDestination::SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce)
|
void I2CPDestination::SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce)
|
||||||
{
|
{
|
||||||
auto msg = NewI2NPMessage ();
|
auto msg = NewI2NPMessage ();
|
||||||
|
@ -512,6 +519,36 @@ namespace client
|
||||||
LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID);
|
LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2CPSession::CreateLeaseSet2MessageHandler (const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
uint16_t sessionID = bufbe16toh (buf);
|
||||||
|
if (sessionID == m_SessionID)
|
||||||
|
{
|
||||||
|
size_t offset = 2;
|
||||||
|
if (m_Destination)
|
||||||
|
{
|
||||||
|
uint8_t storeType = buf[offset]; offset++; // store type
|
||||||
|
// TODO: parse LS2 and obtain correct private keys lengths
|
||||||
|
size_t signingPrivateKeyLength = 0, encryptionPrivateKeyLength = 0;
|
||||||
|
if (storeType != i2p::data::NETDB_STORE_TYPE_META_LEASESET2) // no private keys for meta
|
||||||
|
{
|
||||||
|
signingPrivateKeyLength = m_Destination->GetIdentity ()->GetSigningPrivateKeyLen (); // no offline keys
|
||||||
|
encryptionPrivateKeyLength = 256; // ElGamal only
|
||||||
|
if (len < offset + signingPrivateKeyLength + encryptionPrivateKeyLength)
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "I2CP: CreateLeaseSet2 message is too short ", len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_Destination->SetEncryptionPrivateKey (buf + len - encryptionPrivateKeyLength);
|
||||||
|
// ignore signing private key
|
||||||
|
}
|
||||||
|
m_Destination->LeaseSet2Created (storeType, buf + offset, len - offset - signingPrivateKeyLength - encryptionPrivateKeyLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogError, "I2CP: unexpected sessionID ", sessionID);
|
||||||
|
}
|
||||||
|
|
||||||
void I2CPSession::SendMessageMessageHandler (const uint8_t * buf, size_t len)
|
void I2CPSession::SendMessageMessageHandler (const uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
uint16_t sessionID = bufbe16toh (buf);
|
uint16_t sessionID = bufbe16toh (buf);
|
||||||
|
@ -704,6 +741,7 @@ namespace client
|
||||||
m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
|
m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_RECONFIGURE_SESSION_MESSAGE] = &I2CPSession::ReconfigureSessionMessageHandler;
|
m_MessagesHandlers[I2CP_RECONFIGURE_SESSION_MESSAGE] = &I2CPSession::ReconfigureSessionMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler;
|
m_MessagesHandlers[I2CP_CREATE_LEASESET_MESSAGE] = &I2CPSession::CreateLeaseSetMessageHandler;
|
||||||
|
m_MessagesHandlers[I2CP_CREATE_LEASESET2_MESSAGE] = &I2CPSession::CreateLeaseSet2MessageHandler;
|
||||||
m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
|
m_MessagesHandlers[I2CP_SEND_MESSAGE_MESSAGE] = &I2CPSession::SendMessageMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_SEND_MESSAGE_EXPIRES_MESSAGE] = &I2CPSession::SendMessageExpiresMessageHandler;
|
m_MessagesHandlers[I2CP_SEND_MESSAGE_EXPIRES_MESSAGE] = &I2CPSession::SendMessageExpiresMessageHandler;
|
||||||
m_MessagesHandlers[I2CP_HOST_LOOKUP_MESSAGE] = &I2CPSession::HostLookupMessageHandler;
|
m_MessagesHandlers[I2CP_HOST_LOOKUP_MESSAGE] = &I2CPSession::HostLookupMessageHandler;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2016, The PurpleI2P Project
|
* Copyright (c) 2013-2019, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -36,6 +36,7 @@ namespace client
|
||||||
const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
|
const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
|
||||||
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
|
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
|
||||||
const uint8_t I2CP_CREATE_LEASESET_MESSAGE = 4;
|
const uint8_t I2CP_CREATE_LEASESET_MESSAGE = 4;
|
||||||
|
const uint8_t I2CP_CREATE_LEASESET2_MESSAGE = 40;
|
||||||
const uint8_t I2CP_SEND_MESSAGE_MESSAGE = 5;
|
const uint8_t I2CP_SEND_MESSAGE_MESSAGE = 5;
|
||||||
const uint8_t I2CP_SEND_MESSAGE_EXPIRES_MESSAGE = 36;
|
const uint8_t I2CP_SEND_MESSAGE_EXPIRES_MESSAGE = 36;
|
||||||
const uint8_t I2CP_MESSAGE_PAYLOAD_MESSAGE = 31;
|
const uint8_t I2CP_MESSAGE_PAYLOAD_MESSAGE = 31;
|
||||||
|
@ -68,6 +69,7 @@ namespace client
|
||||||
|
|
||||||
void SetEncryptionPrivateKey (const uint8_t * key);
|
void SetEncryptionPrivateKey (const uint8_t * key);
|
||||||
void LeaseSetCreated (const uint8_t * buf, size_t len); // called from I2CPSession
|
void LeaseSetCreated (const uint8_t * buf, size_t len); // called from I2CPSession
|
||||||
|
void LeaseSet2Created (uint8_t storeType, const uint8_t * buf, size_t len); // called from I2CPSession
|
||||||
void SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce); // called from I2CPSession
|
void SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce); // called from I2CPSession
|
||||||
|
|
||||||
// implements LocalDestination
|
// implements LocalDestination
|
||||||
|
@ -126,6 +128,7 @@ namespace client
|
||||||
void DestroySessionMessageHandler (const uint8_t * buf, size_t len);
|
void DestroySessionMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len);
|
void ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len);
|
void CreateLeaseSetMessageHandler (const uint8_t * buf, size_t len);
|
||||||
|
void CreateLeaseSet2MessageHandler (const uint8_t * buf, size_t len);
|
||||||
void SendMessageMessageHandler (const uint8_t * buf, size_t len);
|
void SendMessageMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void SendMessageExpiresMessageHandler (const uint8_t * buf, size_t len);
|
void SendMessageExpiresMessageHandler (const uint8_t * buf, size_t len);
|
||||||
void HostLookupMessageHandler (const uint8_t * buf, size_t len);
|
void HostLookupMessageHandler (const uint8_t * buf, size_t len);
|
||||||
|
|
Loading…
Add table
Reference in a new issue