mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	initial LeaseSet2 support in I2CP
This commit is contained in:
		
							parent
							
								
									a3344c4290
								
							
						
					
					
						commit
						08ddc98303
					
				
					 4 changed files with 53 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
*
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +68,13 @@ namespace client
 | 
			
		|||
		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)
 | 
			
		||||
	{
 | 
			
		||||
		auto msg = NewI2NPMessage ();
 | 
			
		||||
| 
						 | 
				
			
			@ -512,6 +519,36 @@ namespace client
 | 
			
		|||
			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)
 | 
			
		||||
	{
 | 
			
		||||
		uint16_t sessionID = bufbe16toh (buf);
 | 
			
		||||
| 
						 | 
				
			
			@ -704,6 +741,7 @@ namespace client
 | 
			
		|||
		m_MessagesHandlers[I2CP_DESTROY_SESSION_MESSAGE] = &I2CPSession::DestroySessionMessageHandler;
 | 
			
		||||
		m_MessagesHandlers[I2CP_RECONFIGURE_SESSION_MESSAGE] = &I2CPSession::ReconfigureSessionMessageHandler;
 | 
			
		||||
		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_EXPIRES_MESSAGE] = &I2CPSession::SendMessageExpiresMessageHandler;
 | 
			
		||||
		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
 | 
			
		||||
*
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +36,7 @@ namespace client
 | 
			
		|||
	const uint8_t I2CP_DESTROY_SESSION_MESSAGE = 3;
 | 
			
		||||
	const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
 | 
			
		||||
	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_EXPIRES_MESSAGE = 36;
 | 
			
		||||
	const uint8_t I2CP_MESSAGE_PAYLOAD_MESSAGE = 31;
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +69,7 @@ namespace client
 | 
			
		|||
 | 
			
		||||
			void SetEncryptionPrivateKey (const uint8_t * key);
 | 
			
		||||
			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
 | 
			
		||||
 | 
			
		||||
			// implements LocalDestination
 | 
			
		||||
| 
						 | 
				
			
			@ -126,6 +128,7 @@ namespace client
 | 
			
		|||
			void DestroySessionMessageHandler (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 CreateLeaseSet2MessageHandler (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 HostLookupMessageHandler (const uint8_t * buf, size_t len);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue