2013-10-23 06:45:40 +04:00
|
|
|
#ifndef ROUTER_CONTEXT_H__
|
|
|
|
#define ROUTER_CONTEXT_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <cryptopp/dsa.h>
|
|
|
|
#include <cryptopp/osrng.h>
|
2014-04-01 21:42:04 +04:00
|
|
|
#include "Identity.h"
|
2013-10-23 06:45:40 +04:00
|
|
|
#include "RouterInfo.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
const char ROUTER_INFO[] = "router.info";
|
|
|
|
const char ROUTER_KEYS[] = "router.keys";
|
|
|
|
|
2014-04-01 21:42:04 +04:00
|
|
|
class RouterContext: public i2p::data::LocalDestination
|
2013-10-23 06:45:40 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RouterContext ();
|
|
|
|
|
|
|
|
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
2013-12-21 05:22:55 +04:00
|
|
|
const uint8_t * GetPrivateKey () const { return m_Keys.privateKey; };
|
|
|
|
const uint8_t * GetSigningPrivateKey () const { return m_Keys.signingPrivateKey; };
|
2013-12-20 06:19:44 +04:00
|
|
|
const i2p::data::Identity& GetRouterIdentity () const { return m_RouterInfo.GetRouterIdentity (); };
|
2013-10-23 06:45:40 +04:00
|
|
|
CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; };
|
2013-12-10 17:10:49 +04:00
|
|
|
|
|
|
|
void OverrideNTCPAddress (const char * host, int port); // temporary
|
2014-02-09 06:06:40 +04:00
|
|
|
void UpdateAddress (const char * host); // called from SSU
|
2013-10-23 06:45:40 +04:00
|
|
|
|
2014-04-01 21:42:04 +04:00
|
|
|
// implements LocalDestination
|
|
|
|
const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); };
|
2014-07-29 21:44:54 +04:00
|
|
|
const i2p::data::Identity& GetIdentity () const { return GetRouterIdentity (); };
|
2014-04-02 02:58:47 +04:00
|
|
|
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };
|
|
|
|
const uint8_t * GetEncryptionPublicKey () const { return m_Keys.publicKey; };
|
2014-07-29 21:44:54 +04:00
|
|
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
|
2014-08-16 03:21:30 +04:00
|
|
|
void SetLeaseSetUpdated () {};
|
2014-04-02 02:58:47 +04:00
|
|
|
|
2013-10-23 06:45:40 +04:00
|
|
|
private:
|
|
|
|
|
|
|
|
void CreateNewRouter ();
|
2014-02-23 20:48:09 +04:00
|
|
|
void UpdateRouterInfo ();
|
2013-10-23 06:45:40 +04:00
|
|
|
bool Load ();
|
2014-02-23 20:48:09 +04:00
|
|
|
void Save (bool infoOnly = false);
|
2013-10-23 06:45:40 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
i2p::data::RouterInfo m_RouterInfo;
|
2013-12-21 05:22:55 +04:00
|
|
|
i2p::data::Keys m_Keys;
|
2013-10-23 06:45:40 +04:00
|
|
|
CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
|
|
|
|
CryptoPP::AutoSeededRandomPool m_Rnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern RouterContext context;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|