2014-10-16 04:52:17 +04:00
|
|
|
#ifndef CLIENT_CONTEXT_H__
|
|
|
|
#define CLIENT_CONTEXT_H__
|
|
|
|
|
2015-02-13 18:18:42 +03:00
|
|
|
#include <map>
|
2014-10-16 04:52:17 +04:00
|
|
|
#include <mutex>
|
2015-02-13 00:11:56 +03:00
|
|
|
#include <memory>
|
2016-04-25 00:32:24 +03:00
|
|
|
#include <boost/asio.hpp>
|
2014-10-16 04:52:17 +04:00
|
|
|
#include "Destination.h"
|
2016-05-26 03:00:00 +03:00
|
|
|
#include "I2PService.h"
|
2014-10-16 05:39:39 +04:00
|
|
|
#include "HTTPProxy.h"
|
|
|
|
#include "SOCKS.h"
|
|
|
|
#include "I2PTunnel.h"
|
|
|
|
#include "SAM.h"
|
2014-12-02 18:34:02 +03:00
|
|
|
#include "BOB.h"
|
2016-05-12 22:37:46 +03:00
|
|
|
#include "I2CP.h"
|
2014-10-24 23:22:36 +04:00
|
|
|
#include "AddressBook.h"
|
2014-10-16 04:52:17 +04:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace client
|
|
|
|
{
|
2015-03-14 02:51:31 +03:00
|
|
|
const char I2P_TUNNELS_SECTION_TYPE[] = "type";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_CLIENT[] = "client";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_SERVER[] = "server";
|
2015-05-20 23:00:09 +03:00
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_HTTP[] = "http";
|
2016-02-22 22:33:21 +03:00
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_IRC[] = "irc";
|
2016-08-21 22:02:17 +03:00
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_UDPCLIENT[] = "udpclient";
|
|
|
|
const char I2P_TUNNELS_SECTION_TYPE_UDPSERVER[] = "udpserver";
|
2015-03-14 02:51:31 +03:00
|
|
|
const char I2P_CLIENT_TUNNEL_PORT[] = "port";
|
2015-11-30 17:44:32 +03:00
|
|
|
const char I2P_CLIENT_TUNNEL_ADDRESS[] = "address";
|
2015-03-14 02:51:31 +03:00
|
|
|
const char I2P_CLIENT_TUNNEL_DESTINATION[] = "destination";
|
|
|
|
const char I2P_CLIENT_TUNNEL_KEYS[] = "keys";
|
2016-01-04 05:43:43 +03:00
|
|
|
const char I2P_CLIENT_TUNNEL_SIGNATURE_TYPE[] = "signaturetype";
|
2015-03-14 02:51:31 +03:00
|
|
|
const char I2P_CLIENT_TUNNEL_DESTINATION_PORT[] = "destinationport";
|
|
|
|
const char I2P_SERVER_TUNNEL_HOST[] = "host";
|
2016-02-26 04:32:05 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_HOST_OVERRIDE[] = "hostoverride";
|
2015-03-14 02:51:31 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_PORT[] = "port";
|
|
|
|
const char I2P_SERVER_TUNNEL_KEYS[] = "keys";
|
2016-01-04 05:43:43 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_SIGNATURE_TYPE[] = "signaturetype";
|
2015-03-15 18:28:30 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_INPORT[] = "inport";
|
2015-03-16 21:52:42 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_ACCESS_LIST[] = "accesslist";
|
2016-03-04 09:37:38 +03:00
|
|
|
const char I2P_SERVER_TUNNEL_GZIP[] = "gzip";
|
|
|
|
const char I2P_SERVER_TUNNEL_WEBIRC_PASSWORD[] = "webircpassword";
|
2015-02-13 00:11:56 +03:00
|
|
|
|
2014-10-16 04:52:17 +04:00
|
|
|
class ClientContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-10-16 05:39:39 +04:00
|
|
|
ClientContext ();
|
|
|
|
~ClientContext ();
|
2014-10-16 04:52:17 +04:00
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
|
|
|
|
2016-05-12 18:38:18 +03:00
|
|
|
void ReloadConfig ();
|
|
|
|
|
2015-02-24 23:40:50 +03:00
|
|
|
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,
|
2014-11-30 18:51:22 +03:00
|
|
|
const std::map<std::string, std::string> * params = nullptr); // transient
|
2015-02-24 23:40:50 +03:00
|
|
|
std::shared_ptr<ClientDestination> CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true,
|
2014-11-30 18:51:22 +03:00
|
|
|
const std::map<std::string, std::string> * params = nullptr);
|
2015-02-24 23:40:50 +03:00
|
|
|
void DeleteLocalDestination (std::shared_ptr<ClientDestination> destination);
|
|
|
|
std::shared_ptr<ClientDestination> FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
2016-07-25 18:13:54 +03:00
|
|
|
bool LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
|
2014-10-16 04:52:17 +04:00
|
|
|
|
2014-10-24 23:22:36 +04:00
|
|
|
AddressBook& GetAddressBook () { return m_AddressBook; };
|
2015-02-21 06:47:36 +03:00
|
|
|
const SAMBridge * GetSAMBridge () const { return m_SamBridge; };
|
2015-02-13 00:11:56 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ReadTunnels ();
|
2016-01-15 20:24:40 +03:00
|
|
|
template<typename Section, typename Type>
|
|
|
|
std::string GetI2CPOption (const Section& section, const std::string& name, const Type& value) const;
|
|
|
|
template<typename Section>
|
|
|
|
void ReadI2CPOptions (const Section& section, std::map<std::string, std::string>& options) const;
|
|
|
|
|
2016-08-21 22:02:17 +03:00
|
|
|
void CleanupUDP(const boost::system::error_code & ecode);
|
|
|
|
void ScheduleCleanupUDP();
|
|
|
|
|
|
|
|
private:
|
2014-10-16 04:52:17 +04:00
|
|
|
|
|
|
|
std::mutex m_DestinationsMutex;
|
2015-02-24 23:40:50 +03:00
|
|
|
std::map<i2p::data::IdentHash, std::shared_ptr<ClientDestination> > m_Destinations;
|
|
|
|
std::shared_ptr<ClientDestination> m_SharedLocalDestination;
|
2014-10-16 04:52:17 +04:00
|
|
|
|
2014-10-24 23:22:36 +04:00
|
|
|
AddressBook m_AddressBook;
|
|
|
|
|
2014-10-16 05:39:39 +04:00
|
|
|
i2p::proxy::HTTPProxy * m_HttpProxy;
|
|
|
|
i2p::proxy::SOCKSProxy * m_SocksProxy;
|
2016-04-25 00:32:24 +03:00
|
|
|
std::map<boost::asio::ip::tcp::endpoint, std::unique_ptr<I2PClientTunnel> > m_ClientTunnels; // local endpoint->tunnel
|
|
|
|
std::map<std::pair<i2p::data::IdentHash, int>, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // <destination,port>->tunnel
|
2016-08-21 22:02:17 +03:00
|
|
|
|
|
|
|
std::mutex m_ForwardsMutex;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
SAMBridge * m_SamBridge;
|
2014-12-02 18:34:02 +03:00
|
|
|
BOBCommandChannel * m_BOBCommandChannel;
|
2016-05-12 22:37:46 +03:00
|
|
|
I2CPServer * m_I2CPServer;
|
2014-10-16 05:39:39 +04:00
|
|
|
|
2016-08-21 22:02:17 +03:00
|
|
|
boost::asio::io_service m_Service;
|
|
|
|
std::thread * m_ServiceThread;
|
|
|
|
|
|
|
|
boost::asio::deadline_timer m_CleanupUDPTimer;
|
|
|
|
|
2014-10-16 04:52:17 +04:00
|
|
|
public:
|
|
|
|
// for HTTP
|
|
|
|
const decltype(m_Destinations)& GetDestinations () const { return m_Destinations; };
|
2016-01-14 04:21:53 +03:00
|
|
|
const decltype(m_ClientTunnels)& GetClientTunnels () const { return m_ClientTunnels; };
|
|
|
|
const decltype(m_ServerTunnels)& GetServerTunnels () const { return m_ServerTunnels; };
|
2014-10-16 04:52:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
extern ClientContext context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|