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 @@ -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);
};
};
}
}

13
RouterContext.cpp

@ -36,13 +36,13 @@ namespace i2p @@ -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 @@ -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 @@ -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 ()

6
RouterContext.h

@ -20,7 +20,6 @@ namespace i2p @@ -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 @@ -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:

6
RouterInfo.cpp

@ -363,7 +363,7 @@ namespace data @@ -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 @@ -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)

2
RouterInfo.h

@ -103,7 +103,7 @@ namespace data @@ -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; };

5
Streaming.cpp

@ -618,11 +618,6 @@ namespace stream @@ -618,11 +618,6 @@ namespace stream
if (m_IsPublic)
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 ()

4
Streaming.h

@ -143,7 +143,6 @@ namespace stream @@ -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 @@ -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:

2
TunnelPool.h

@ -40,7 +40,7 @@ namespace tunnel @@ -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…
Cancel
Save