mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.4 KiB
130 lines
4.4 KiB
11 years ago
|
#ifndef ROUTER_CONTEXT_H__
|
||
|
#define ROUTER_CONTEXT_H__
|
||
|
|
||
|
#include <inttypes.h>
|
||
10 years ago
|
#include <string>
|
||
10 years ago
|
#include <memory>
|
||
10 years ago
|
#include <mutex>
|
||
10 years ago
|
#include <boost/asio.hpp>
|
||
11 years ago
|
#include "Identity.h"
|
||
11 years ago
|
#include "RouterInfo.h"
|
||
10 years ago
|
#include "Garlic.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
const char ROUTER_INFO[] = "router.info";
|
||
|
const char ROUTER_KEYS[] = "router.keys";
|
||
10 years ago
|
const int ROUTER_INFO_UPDATE_INTERVAL = 1800; // 30 minutes
|
||
10 years ago
|
|
||
10 years ago
|
enum RouterStatus
|
||
|
{
|
||
|
eRouterStatusOK = 0,
|
||
|
eRouterStatusTesting = 1,
|
||
8 years ago
|
eRouterStatusFirewalled = 2,
|
||
|
eRouterStatusError = 3
|
||
10 years ago
|
};
|
||
|
|
||
8 years ago
|
enum RouterError
|
||
|
{
|
||
|
eRouterErrorNone = 0,
|
||
|
eRouterErrorClockSkew = 1
|
||
|
};
|
||
|
|
||
10 years ago
|
class RouterContext: public i2p::garlic::GarlicDestination
|
||
11 years ago
|
{
|
||
|
public:
|
||
|
|
||
|
RouterContext ();
|
||
10 years ago
|
void Init ();
|
||
11 years ago
|
|
||
9 years ago
|
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
|
||
11 years ago
|
i2p::data::RouterInfo& GetRouterInfo () { return m_RouterInfo; };
|
||
10 years ago
|
std::shared_ptr<const i2p::data::RouterInfo> GetSharedRouterInfo () const
|
||
|
{
|
||
|
return std::shared_ptr<const i2p::data::RouterInfo> (&m_RouterInfo,
|
||
|
[](const i2p::data::RouterInfo *) {});
|
||
|
}
|
||
9 years ago
|
std::shared_ptr<i2p::garlic::GarlicDestination> GetSharedDestination ()
|
||
|
{
|
||
|
return std::shared_ptr<i2p::garlic::GarlicDestination> (this,
|
||
|
[](i2p::garlic::GarlicDestination *) {});
|
||
|
}
|
||
|
|
||
10 years ago
|
uint32_t GetUptime () const;
|
||
10 years ago
|
uint32_t GetStartupTime () const { return m_StartupTime; };
|
||
10 years ago
|
uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||
9 years ago
|
uint64_t GetBandwidthLimit () const { return m_BandwidthLimit; };
|
||
10 years ago
|
RouterStatus GetStatus () const { return m_Status; };
|
||
9 years ago
|
void SetStatus (RouterStatus status);
|
||
8 years ago
|
RouterError GetError () const { return m_Error; };
|
||
|
void SetError (RouterError error) { m_Status = eRouterStatusError; m_Error = error; };
|
||
8 years ago
|
int GetNetID () const { return m_NetID; };
|
||
|
void SetNetID (int netID) { m_NetID = netID; };
|
||
|
|
||
10 years ago
|
void UpdatePort (int port); // called from Daemon
|
||
10 years ago
|
void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon
|
||
9 years ago
|
bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer);
|
||
10 years ago
|
void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
|
||
10 years ago
|
bool IsUnreachable () const;
|
||
10 years ago
|
void SetUnreachable ();
|
||
10 years ago
|
void SetReachable ();
|
||
10 years ago
|
bool IsFloodfill () const { return m_IsFloodfill; };
|
||
|
void SetFloodfill (bool floodfill);
|
||
9 years ago
|
void SetFamily (const std::string& family);
|
||
9 years ago
|
std::string GetFamily () const;
|
||
9 years ago
|
void SetBandwidth (int limit); /* in kilobytes */
|
||
|
void SetBandwidth (char L); /* by letter */
|
||
10 years ago
|
bool AcceptsTunnels () const { return m_AcceptsTunnels; };
|
||
|
void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; };
|
||
10 years ago
|
bool SupportsV6 () const { return m_RouterInfo.IsV6 (); };
|
||
9 years ago
|
bool SupportsV4 () const { return m_RouterInfo.IsV4 (); };
|
||
10 years ago
|
void SetSupportsV6 (bool supportsV6);
|
||
9 years ago
|
void SetSupportsV4 (bool supportsV4);
|
||
|
|
||
10 years ago
|
void UpdateNTCPV6Address (const boost::asio::ip::address& host); // called from NTCP session
|
||
9 years ago
|
void UpdateStats ();
|
||
|
void CleanupDestination (); // garlic destination
|
||
10 years ago
|
|
||
11 years ago
|
// implements LocalDestination
|
||
9 years ago
|
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Keys.GetPublic (); };
|
||
10 years ago
|
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); };
|
||
9 years ago
|
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ()->GetStandardIdentity ().publicKey; };
|
||
9 years ago
|
void Sign (const uint8_t * buf, int len, uint8_t * signature) const { m_Keys.Sign (buf, len, signature); };
|
||
10 years ago
|
void SetLeaseSetUpdated () {};
|
||
10 years ago
|
|
||
|
// implements GarlicDestination
|
||
9 years ago
|
std::shared_ptr<const i2p::data::LocalLeaseSet> GetLeaseSet () { return nullptr; };
|
||
10 years ago
|
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const;
|
||
10 years ago
|
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
||
10 years ago
|
|
||
|
// override GarlicDestination
|
||
10 years ago
|
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
|
||
|
void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
|
||
11 years ago
|
|
||
11 years ago
|
private:
|
||
|
|
||
|
void CreateNewRouter ();
|
||
10 years ago
|
void NewRouterInfo ();
|
||
11 years ago
|
void UpdateRouterInfo ();
|
||
11 years ago
|
bool Load ();
|
||
10 years ago
|
void SaveKeys ();
|
||
11 years ago
|
|
||
|
private:
|
||
|
|
||
|
i2p::data::RouterInfo m_RouterInfo;
|
||
10 years ago
|
i2p::data::PrivateKeys m_Keys;
|
||
10 years ago
|
uint64_t m_LastUpdateTime;
|
||
10 years ago
|
bool m_AcceptsTunnels, m_IsFloodfill;
|
||
10 years ago
|
uint64_t m_StartupTime; // in seconds since epoch
|
||
9 years ago
|
uint32_t m_BandwidthLimit; // allowed bandwidth
|
||
10 years ago
|
RouterStatus m_Status;
|
||
8 years ago
|
RouterError m_Error;
|
||
8 years ago
|
int m_NetID;
|
||
10 years ago
|
std::mutex m_GarlicMutex;
|
||
11 years ago
|
};
|
||
|
|
||
|
extern RouterContext context;
|
||
|
}
|
||
|
|
||
|
#endif
|