mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
moved common code to LocalDestination
This commit is contained in:
parent
04c9a96fcb
commit
7aacae30eb
10
Identity.h
10
Identity.h
@ -230,11 +230,17 @@ namespace data
|
||||
public:
|
||||
|
||||
virtual ~LocalDestination() {};
|
||||
virtual const IdentityEx& GetIdentity () const = 0;
|
||||
virtual const PrivateKeys& GetPrivateKeys () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
|
||||
virtual const uint8_t * GetEncryptionPublicKey () const = 0;
|
||||
virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0;
|
||||
virtual void SetLeaseSetUpdated () = 0;
|
||||
|
||||
const IdentityEx& GetIdentity () const { return GetPrivateKeys ().GetPublic (); };
|
||||
const IdentHash& GetIdentHash () const { return GetIdentity ().GetIdentHash (); };
|
||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||
{
|
||||
GetPrivateKeys ().Sign (buf, len, signature);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ namespace i2p
|
||||
routerInfo.SetProperty ("netId", "2");
|
||||
routerInfo.SetProperty ("router.version", I2P_VERSION);
|
||||
routerInfo.SetProperty ("start_uptime", "90m");
|
||||
routerInfo.CreateBuffer ();
|
||||
routerInfo.CreateBuffer (m_Keys);
|
||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||
}
|
||||
|
||||
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
||||
{
|
||||
m_RouterInfo.CreateBuffer ();
|
||||
m_RouterInfo.CreateBuffer (m_Keys);
|
||||
auto address = const_cast<i2p::data::RouterInfo::Address *>(m_RouterInfo.GetNTCPAddress ());
|
||||
if (address)
|
||||
{
|
||||
@ -50,7 +50,7 @@ namespace i2p
|
||||
address->port = port;
|
||||
}
|
||||
|
||||
m_RouterInfo.CreateBuffer ();
|
||||
m_RouterInfo.CreateBuffer (m_Keys);
|
||||
Save (true);
|
||||
}
|
||||
|
||||
@ -58,12 +58,7 @@ namespace i2p
|
||||
{
|
||||
for (auto& address : m_RouterInfo.GetAddresses ())
|
||||
address.host = boost::asio::ip::address::from_string (host);
|
||||
m_RouterInfo.CreateBuffer ();
|
||||
}
|
||||
|
||||
void RouterContext::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||
{
|
||||
m_Keys.Sign(buf, len, signature);
|
||||
m_RouterInfo.CreateBuffer (m_Keys);
|
||||
}
|
||||
|
||||
bool RouterContext::Load ()
|
||||
|
@ -20,7 +20,6 @@ namespace i2p
|
||||
|
||||
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
||||
const uint8_t * GetPrivateKey () const { return m_Keys.GetPrivateKey (); };
|
||||
const uint8_t * GetSigningPrivateKey () const { return m_Keys.GetSigningPrivateKey (); };
|
||||
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
||||
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
||||
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
||||
@ -29,10 +28,9 @@ namespace i2p
|
||||
void UpdateAddress (const char * host); // called from SSU
|
||||
|
||||
// implements LocalDestination
|
||||
const i2p::data::IdentityEx& GetIdentity () const { return m_Keys.GetPublic (); };
|
||||
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };
|
||||
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
||||
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); };
|
||||
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; };
|
||||
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||
void SetLeaseSetUpdated () {};
|
||||
|
||||
private:
|
||||
|
@ -363,7 +363,7 @@ namespace data
|
||||
return m_Buffer;
|
||||
}
|
||||
|
||||
void RouterInfo::CreateBuffer ()
|
||||
void RouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
|
||||
{
|
||||
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); // refresh timstamp
|
||||
std::stringstream s;
|
||||
@ -373,8 +373,8 @@ namespace data
|
||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||
memcpy (m_Buffer, s.str ().c_str (), m_BufferLen);
|
||||
// signature
|
||||
i2p::context.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen);
|
||||
m_BufferLen += 40;
|
||||
privateKeys.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen);
|
||||
m_BufferLen += privateKeys.GetPublic ().GetSignatureLen ();
|
||||
}
|
||||
|
||||
void RouterInfo::SaveToFile (const std::string& fullPath)
|
||||
|
@ -103,7 +103,7 @@ namespace data
|
||||
const uint8_t * LoadBuffer (); // load if necessary
|
||||
int GetBufferLen () const { return m_BufferLen; };
|
||||
|
||||
void CreateBuffer ();
|
||||
void CreateBuffer (const PrivateKeys& privateKeys);
|
||||
void UpdateRoutingKey ();
|
||||
|
||||
bool IsUpdated () const { return m_IsUpdated; };
|
||||
|
@ -619,11 +619,6 @@ namespace stream
|
||||
i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool);
|
||||
}
|
||||
|
||||
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const
|
||||
{
|
||||
m_Keys.Sign(buf, len, signature);
|
||||
}
|
||||
|
||||
StreamingDestinations destinations;
|
||||
void StreamingDestinations::Start ()
|
||||
{
|
||||
|
@ -143,7 +143,6 @@ namespace stream
|
||||
StreamingDestination (boost::asio::io_service& service, const std::string& fullPath);
|
||||
~StreamingDestination ();
|
||||
|
||||
const i2p::data::PrivateKeys& GetKeys () const { return m_Keys; };
|
||||
const i2p::data::LeaseSet * GetLeaseSet ();
|
||||
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
|
||||
|
||||
@ -153,10 +152,9 @@ namespace stream
|
||||
void HandleNextPacket (Packet * packet);
|
||||
|
||||
// implements LocalDestination
|
||||
const i2p::data::IdentityEx& GetIdentity () const { return m_Keys.GetPublic (); };
|
||||
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 Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
||||
void SetLeaseSetUpdated ();
|
||||
|
||||
private:
|
||||
|
@ -40,7 +40,7 @@ namespace tunnel
|
||||
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
||||
OutboundTunnel * GetNextOutboundTunnel (OutboundTunnel * suggested = nullptr);
|
||||
InboundTunnel * GetNextInboundTunnel (InboundTunnel * suggested = nullptr);
|
||||
const i2p::data::IdentHash& GetIdentHash () const { return m_LocalDestination.GetIdentity ().GetIdentHash (); };
|
||||
const i2p::data::IdentHash& GetIdentHash () const { return m_LocalDestination.GetIdentHash (); };
|
||||
|
||||
void TestTunnels ();
|
||||
void ProcessDeliveryStatus (I2NPMessage * msg);
|
||||
|
Loading…
Reference in New Issue
Block a user