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.
131 lines
5.7 KiB
131 lines
5.7 KiB
10 years ago
|
#ifndef CLIENT_CONTEXT_H__
|
||
|
#define CLIENT_CONTEXT_H__
|
||
|
|
||
10 years ago
|
#include <map>
|
||
10 years ago
|
#include <mutex>
|
||
10 years ago
|
#include <memory>
|
||
9 years ago
|
#include <boost/asio.hpp>
|
||
10 years ago
|
#include "Destination.h"
|
||
9 years ago
|
#include "I2PService.h"
|
||
10 years ago
|
#include "HTTPProxy.h"
|
||
|
#include "SOCKS.h"
|
||
|
#include "I2PTunnel.h"
|
||
|
#include "SAM.h"
|
||
10 years ago
|
#include "BOB.h"
|
||
9 years ago
|
#include "I2CP.h"
|
||
10 years ago
|
#include "AddressBook.h"
|
||
10 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace client
|
||
|
{
|
||
10 years ago
|
const char I2P_TUNNELS_SECTION_TYPE[] = "type";
|
||
|
const char I2P_TUNNELS_SECTION_TYPE_CLIENT[] = "client";
|
||
|
const char I2P_TUNNELS_SECTION_TYPE_SERVER[] = "server";
|
||
10 years ago
|
const char I2P_TUNNELS_SECTION_TYPE_HTTP[] = "http";
|
||
9 years ago
|
const char I2P_TUNNELS_SECTION_TYPE_IRC[] = "irc";
|
||
8 years ago
|
const char I2P_TUNNELS_SECTION_TYPE_UDPCLIENT[] = "udpclient";
|
||
|
const char I2P_TUNNELS_SECTION_TYPE_UDPSERVER[] = "udpserver";
|
||
8 years ago
|
const char I2P_TUNNELS_SECTION_TYPE_SOCKS[] = "socks";
|
||
|
const char I2P_TUNNELS_SECTION_TYPE_WEBSOCKS[] = "websocks";
|
||
|
const char I2P_TUNNELS_SECTION_TYPE_HTTPPROXY[] = "httpproxy";
|
||
10 years ago
|
const char I2P_CLIENT_TUNNEL_PORT[] = "port";
|
||
9 years ago
|
const char I2P_CLIENT_TUNNEL_ADDRESS[] = "address";
|
||
10 years ago
|
const char I2P_CLIENT_TUNNEL_DESTINATION[] = "destination";
|
||
|
const char I2P_CLIENT_TUNNEL_KEYS[] = "keys";
|
||
9 years ago
|
const char I2P_CLIENT_TUNNEL_SIGNATURE_TYPE[] = "signaturetype";
|
||
8 years ago
|
const char I2P_CLIENT_TUNNEL_DESTINATION_PORT[] = "destinationport";
|
||
8 years ago
|
const char I2P_CLIENT_TUNNEL_MATCH_TUNNELS[] = "matchtunnels";
|
||
8 years ago
|
const char I2P_SERVER_TUNNEL_HOST[] = "host";
|
||
|
const char I2P_SERVER_TUNNEL_HOST_OVERRIDE[] = "hostoverride";
|
||
10 years ago
|
const char I2P_SERVER_TUNNEL_PORT[] = "port";
|
||
|
const char I2P_SERVER_TUNNEL_KEYS[] = "keys";
|
||
9 years ago
|
const char I2P_SERVER_TUNNEL_SIGNATURE_TYPE[] = "signaturetype";
|
||
10 years ago
|
const char I2P_SERVER_TUNNEL_INPORT[] = "inport";
|
||
8 years ago
|
const char I2P_SERVER_TUNNEL_ACCESS_LIST[] = "accesslist";
|
||
9 years ago
|
const char I2P_SERVER_TUNNEL_GZIP[] = "gzip";
|
||
|
const char I2P_SERVER_TUNNEL_WEBIRC_PASSWORD[] = "webircpassword";
|
||
8 years ago
|
const char I2P_SERVER_TUNNEL_ADDRESS[] = "address";
|
||
8 years ago
|
const char I2P_SERVER_TUNNEL_ENABLE_UNIQUE_LOCAL[] = "enableuniquelocal";
|
||
8 years ago
|
|
||
8 years ago
|
|
||
10 years ago
|
class ClientContext
|
||
|
{
|
||
|
public:
|
||
|
|
||
10 years ago
|
ClientContext ();
|
||
|
~ClientContext ();
|
||
10 years ago
|
|
||
|
void Start ();
|
||
|
void Stop ();
|
||
|
|
||
9 years ago
|
void ReloadConfig ();
|
||
|
|
||
10 years ago
|
std::shared_ptr<ClientDestination> GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||
|
std::shared_ptr<ClientDestination> CreateNewLocalDestination (bool isPublic = false, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1,
|
||
10 years ago
|
const std::map<std::string, std::string> * params = nullptr); // transient
|
||
8 years ago
|
std::shared_ptr<ClientDestination> CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true,
|
||
8 years ago
|
const std::map<std::string, std::string> * params = nullptr);
|
||
|
std::shared_ptr<ClientDestination> CreateNewMatchedTunnelDestination(const i2p::data::PrivateKeys &keys, const std::string & name, const std::map<std::string, std::string> * params = nullptr);
|
||
10 years ago
|
void DeleteLocalDestination (std::shared_ptr<ClientDestination> destination);
|
||
8 years ago
|
std::shared_ptr<ClientDestination> FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||
9 years ago
|
bool LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
|
||
10 years ago
|
|
||
10 years ago
|
AddressBook& GetAddressBook () { return m_AddressBook; };
|
||
10 years ago
|
const SAMBridge * GetSAMBridge () const { return m_SamBridge; };
|
||
8 years ago
|
const I2CPServer * GetI2CPServer () const { return m_I2CPServer; };
|
||
8 years ago
|
|
||
8 years ago
|
std::vector<std::shared_ptr<DatagramSessionInfo> > GetForwardInfosFor(const i2p::data::IdentHash & destination);
|
||
8 years ago
|
|
||
10 years ago
|
private:
|
||
|
|
||
|
void ReadTunnels ();
|
||
9 years ago
|
template<typename Section, typename Type>
|
||
|
std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const;
|
||
|
template<typename Section>
|
||
8 years ago
|
void ReadI2CPOptions (const Section& section, std::map<std::string, std::string>& options) const;
|
||
8 years ago
|
void ReadI2CPOptionsFromConfig (const std::string& prefix, std::map<std::string, std::string>& options) const;
|
||
9 years ago
|
|
||
8 years ago
|
void CleanupUDP(const boost::system::error_code & ecode);
|
||
|
void ScheduleCleanupUDP();
|
||
8 years ago
|
|
||
8 years ago
|
private:
|
||
10 years ago
|
|
||
|
std::mutex m_DestinationsMutex;
|
||
10 years ago
|
std::map<i2p::data::IdentHash, std::shared_ptr<ClientDestination> > m_Destinations;
|
||
8 years ago
|
std::shared_ptr<ClientDestination> m_SharedLocalDestination;
|
||
10 years ago
|
|
||
10 years ago
|
AddressBook m_AddressBook;
|
||
|
|
||
10 years ago
|
i2p::proxy::HTTPProxy * m_HttpProxy;
|
||
|
i2p::proxy::SOCKSProxy * m_SocksProxy;
|
||
8 years ago
|
std::map<boost::asio::ip::tcp::endpoint, std::unique_ptr<I2PService> > m_ClientTunnels; // local endpoint->tunnel
|
||
9 years ago
|
std::map<std::pair<i2p::data::IdentHash, int>, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // <destination,port>->tunnel
|
||
8 years ago
|
|
||
8 years ago
|
std::mutex m_ForwardsMutex;
|
||
8 years ago
|
std::map<boost::asio::ip::udp::endpoint, std::unique_ptr<I2PUDPClientTunnel> > m_ClientForwards; // local endpoint -> udp tunnel
|
||
|
std::map<std::pair<i2p::data::IdentHash, int>, std::unique_ptr<I2PUDPServerTunnel> > m_ServerForwards; // <destination,port> -> udp tunnel
|
||
8 years ago
|
|
||
8 years ago
|
SAMBridge * m_SamBridge;
|
||
10 years ago
|
BOBCommandChannel * m_BOBCommandChannel;
|
||
9 years ago
|
I2CPServer * m_I2CPServer;
|
||
10 years ago
|
|
||
8 years ago
|
std::unique_ptr<boost::asio::deadline_timer> m_CleanupUDPTimer;
|
||
8 years ago
|
|
||
10 years ago
|
public:
|
||
|
// for HTTP
|
||
|
const decltype(m_Destinations)& GetDestinations () const { return m_Destinations; };
|
||
9 years ago
|
const decltype(m_ClientTunnels)& GetClientTunnels () const { return m_ClientTunnels; };
|
||
|
const decltype(m_ServerTunnels)& GetServerTunnels () const { return m_ServerTunnels; };
|
||
8 years ago
|
const decltype(m_ClientForwards)& GetClientForwards () const { return m_ClientForwards; }
|
||
|
const decltype(m_ServerForwards)& GetServerForwards () const { return m_ServerForwards; }
|
||
8 years ago
|
const i2p::proxy::HTTPProxy * GetHttpProxy () const { return m_HttpProxy; }
|
||
8 years ago
|
const i2p::proxy::SOCKSProxy * GetSocksProxy () const { return m_SocksProxy; }
|
||
10 years ago
|
};
|
||
8 years ago
|
|
||
|
extern ClientContext context;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
#endif
|