Browse Source

moved common code to LocalDestination

pull/93/head
orignal 10 years ago
parent
commit
7aacae30eb
  1. 10
      Identity.h
  2. 13
      RouterContext.cpp
  3. 6
      RouterContext.h
  4. 6
      RouterInfo.cpp
  5. 2
      RouterInfo.h
  6. 5
      Streaming.cpp
  7. 4
      Streaming.h
  8. 2
      TunnelPool.h

10
Identity.h

@ -230,11 +230,17 @@ namespace data
public: public:
virtual ~LocalDestination() {}; 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 * GetEncryptionPrivateKey () const = 0;
virtual const uint8_t * GetEncryptionPublicKey () 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; 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);
};
}; };
} }
} }

13
RouterContext.cpp

@ -36,13 +36,13 @@ namespace i2p
routerInfo.SetProperty ("netId", "2"); routerInfo.SetProperty ("netId", "2");
routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.SetProperty ("router.version", I2P_VERSION);
routerInfo.SetProperty ("start_uptime", "90m"); routerInfo.SetProperty ("start_uptime", "90m");
routerInfo.CreateBuffer (); routerInfo.CreateBuffer (m_Keys);
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ()); m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
} }
void RouterContext::OverrideNTCPAddress (const char * host, int port) 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 ()); auto address = const_cast<i2p::data::RouterInfo::Address *>(m_RouterInfo.GetNTCPAddress ());
if (address) if (address)
{ {
@ -50,7 +50,7 @@ namespace i2p
address->port = port; address->port = port;
} }
m_RouterInfo.CreateBuffer (); m_RouterInfo.CreateBuffer (m_Keys);
Save (true); Save (true);
} }
@ -58,12 +58,7 @@ namespace i2p
{ {
for (auto& address : m_RouterInfo.GetAddresses ()) for (auto& address : m_RouterInfo.GetAddresses ())
address.host = boost::asio::ip::address::from_string (host); address.host = boost::asio::ip::address::from_string (host);
m_RouterInfo.CreateBuffer (); m_RouterInfo.CreateBuffer (m_Keys);
}
void RouterContext::Sign (const uint8_t * buf, int len, uint8_t * signature) const
{
m_Keys.Sign(buf, len, signature);
} }
bool RouterContext::Load () bool RouterContext::Load ()

6
RouterContext.h

@ -20,7 +20,6 @@ namespace i2p
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; }; i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
const uint8_t * GetPrivateKey () const { return m_Keys.GetPrivateKey (); }; 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::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); }; const i2p::data::IdentHash& GetRouterIdentHash () const { return m_RouterInfo.GetIdentHash (); };
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
@ -29,10 +28,9 @@ namespace i2p
void UpdateAddress (const char * host); // called from SSU void UpdateAddress (const char * host); // called from SSU
// implements LocalDestination // 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 GetPrivateKey (); }; const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); };
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; }; const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; };
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
void SetLeaseSetUpdated () {}; void SetLeaseSetUpdated () {};
private: private:

6
RouterInfo.cpp

@ -363,7 +363,7 @@ namespace data
return m_Buffer; return m_Buffer;
} }
void RouterInfo::CreateBuffer () void RouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
{ {
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); // refresh timstamp m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); // refresh timstamp
std::stringstream s; std::stringstream s;
@ -373,8 +373,8 @@ namespace data
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE]; m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
memcpy (m_Buffer, s.str ().c_str (), m_BufferLen); memcpy (m_Buffer, s.str ().c_str (), m_BufferLen);
// signature // signature
i2p::context.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen); privateKeys.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen);
m_BufferLen += 40; m_BufferLen += privateKeys.GetPublic ().GetSignatureLen ();
} }
void RouterInfo::SaveToFile (const std::string& fullPath) void RouterInfo::SaveToFile (const std::string& fullPath)

2
RouterInfo.h

@ -103,7 +103,7 @@ namespace data
const uint8_t * LoadBuffer (); // load if necessary const uint8_t * LoadBuffer (); // load if necessary
int GetBufferLen () const { return m_BufferLen; }; int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer (); void CreateBuffer (const PrivateKeys& privateKeys);
void UpdateRoutingKey (); void UpdateRoutingKey ();
bool IsUpdated () const { return m_IsUpdated; }; bool IsUpdated () const { return m_IsUpdated; };

5
Streaming.cpp

@ -619,11 +619,6 @@ namespace stream
i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool); 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; StreamingDestinations destinations;
void StreamingDestinations::Start () void StreamingDestinations::Start ()
{ {

4
Streaming.h

@ -143,7 +143,6 @@ namespace stream
StreamingDestination (boost::asio::io_service& service, const std::string& fullPath); StreamingDestination (boost::asio::io_service& service, const std::string& fullPath);
~StreamingDestination (); ~StreamingDestination ();
const i2p::data::PrivateKeys& GetKeys () const { return m_Keys; };
const i2p::data::LeaseSet * GetLeaseSet (); const i2p::data::LeaseSet * GetLeaseSet ();
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; }; i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
@ -153,10 +152,9 @@ namespace stream
void HandleNextPacket (Packet * packet); void HandleNextPacket (Packet * packet);
// implements LocalDestination // 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 * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
void SetLeaseSetUpdated (); void SetLeaseSetUpdated ();
private: private:

2
TunnelPool.h

@ -40,7 +40,7 @@ namespace tunnel
std::vector<InboundTunnel *> GetInboundTunnels (int num) const; std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
OutboundTunnel * GetNextOutboundTunnel (OutboundTunnel * suggested = nullptr); OutboundTunnel * GetNextOutboundTunnel (OutboundTunnel * suggested = nullptr);
InboundTunnel * GetNextInboundTunnel (InboundTunnel * 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 TestTunnels ();
void ProcessDeliveryStatus (I2NPMessage * msg); void ProcessDeliveryStatus (I2NPMessage * msg);

Loading…
Cancel
Save