2014-11-28 21:04:57 +00:00
# include <fstream>
2015-02-12 21:11:56 +00:00
# include <iostream>
2015-03-13 20:05:39 +00:00
# include <boost/property_tree/ptree.hpp>
# include <boost/property_tree/ini_parser.hpp>
2016-01-20 00:00:00 +00:00
# include "Config.h"
2016-02-11 00:00:00 +00:00
# include "FS.h"
2014-10-16 01:39:39 +00:00
# include "Log.h"
2014-11-28 21:04:57 +00:00
# include "Identity.h"
2014-10-16 00:52:17 +00:00
# include "ClientContext.h"
namespace i2p
{
namespace client
{
ClientContext context ;
2014-10-16 01:39:39 +00:00
ClientContext : : ClientContext ( ) : m_SharedLocalDestination ( nullptr ) ,
2015-02-13 20:56:57 +00:00
m_HttpProxy ( nullptr ) , m_SocksProxy ( nullptr ) , m_SamBridge ( nullptr ) ,
2016-05-12 19:37:46 +00:00
m_BOBCommandChannel ( nullptr ) , m_I2CPServer ( nullptr )
2014-10-16 01:39:39 +00:00
{
}
ClientContext : : ~ ClientContext ( )
{
delete m_HttpProxy ;
delete m_SocksProxy ;
delete m_SamBridge ;
2014-12-02 15:34:02 +00:00
delete m_BOBCommandChannel ;
2016-05-12 19:37:46 +00:00
delete m_I2CPServer ;
2014-10-16 01:39:39 +00:00
}
2014-10-16 00:52:17 +00:00
void ClientContext : : Start ( )
{
if ( ! m_SharedLocalDestination )
{
2014-11-30 15:51:22 +00:00
m_SharedLocalDestination = CreateNewLocalDestination ( ) ; // non-public, DSA
2015-11-03 14:15:49 +00:00
m_Destinations [ m_SharedLocalDestination - > GetIdentity ( ) - > GetIdentHash ( ) ] = m_SharedLocalDestination ;
2014-10-16 00:52:17 +00:00
m_SharedLocalDestination - > Start ( ) ;
}
2014-10-16 01:39:39 +00:00
2016-02-19 03:34:14 +00:00
m_AddressBook . Start ( ) ;
2015-03-17 15:44:01 +00:00
std : : shared_ptr < ClientDestination > localDestination ;
2016-01-20 00:00:00 +00:00
bool httproxy ; i2p : : config : : GetOption ( " httpproxy.enabled " , httproxy ) ;
if ( httproxy ) {
std : : string httpProxyKeys ; i2p : : config : : GetOption ( " httpproxy.keys " , httpProxyKeys ) ;
std : : string httpProxyAddr ; i2p : : config : : GetOption ( " httpproxy.address " , httpProxyAddr ) ;
uint16_t httpProxyPort ; i2p : : config : : GetOption ( " httpproxy.port " , httpProxyPort ) ;
LogPrint ( eLogInfo , " Clients: starting HTTP Proxy at " , httpProxyAddr , " : " , httpProxyPort ) ;
if ( httpProxyKeys . length ( ) > 0 )
{
i2p : : data : : PrivateKeys keys ;
LoadPrivateKeys ( keys , httpProxyKeys ) ;
localDestination = CreateNewLocalDestination ( keys , false ) ;
}
2016-03-29 21:55:29 +00:00
try {
m_HttpProxy = new i2p : : proxy : : HTTPProxy ( httpProxyAddr , httpProxyPort , localDestination ) ;
m_HttpProxy - > Start ( ) ;
} catch ( std : : exception & e ) {
2016-03-29 22:03:15 +00:00
LogPrint ( eLogError , " Clients: Exception in HTTP Proxy: " , e . what ( ) ) ;
2016-03-29 21:55:29 +00:00
}
2016-01-15 19:46:29 +00:00
}
2016-01-18 00:00:00 +00:00
2016-01-20 00:00:00 +00:00
bool socksproxy ; i2p : : config : : GetOption ( " socksproxy.enabled " , socksproxy ) ;
if ( socksproxy ) {
std : : string socksProxyKeys ; i2p : : config : : GetOption ( " socksproxy.keys " , socksProxyKeys ) ;
std : : string socksProxyAddr ; i2p : : config : : GetOption ( " socksproxy.address " , socksProxyAddr ) ;
uint16_t socksProxyPort ; i2p : : config : : GetOption ( " socksproxy.port " , socksProxyPort ) ;
2016-01-26 08:03:18 +00:00
std : : string socksOutProxyAddr ; i2p : : config : : GetOption ( " socksproxy.outproxy " , socksOutProxyAddr ) ;
uint16_t socksOutProxyPort ; i2p : : config : : GetOption ( " socksproxy.outproxyport " , socksOutProxyPort ) ;
2016-01-20 00:00:00 +00:00
LogPrint ( eLogInfo , " Clients: starting SOCKS Proxy at " , socksProxyAddr , " : " , socksProxyPort ) ;
if ( socksProxyKeys . length ( ) > 0 )
{
i2p : : data : : PrivateKeys keys ;
LoadPrivateKeys ( keys , socksProxyKeys ) ;
localDestination = CreateNewLocalDestination ( keys , false ) ;
}
2016-03-29 22:03:15 +00:00
try {
m_SocksProxy = new i2p : : proxy : : SOCKSProxy ( socksProxyAddr , socksProxyPort , socksOutProxyAddr , socksOutProxyPort , localDestination ) ;
m_SocksProxy - > Start ( ) ;
} catch ( std : : exception & e ) {
LogPrint ( eLogError , " Clients: Exception in SOCKS Proxy: " , e . what ( ) ) ;
}
2016-01-20 00:00:00 +00:00
}
2015-02-12 21:11:56 +00:00
2016-01-11 02:39:29 +00:00
// I2P tunnels
2015-02-12 21:11:56 +00:00
ReadTunnels ( ) ;
// SAM
2016-01-20 00:00:00 +00:00
bool sam ; i2p : : config : : GetOption ( " sam.enabled " , sam ) ;
if ( sam ) {
std : : string samAddr ; i2p : : config : : GetOption ( " sam.address " , samAddr ) ;
uint16_t samPort ; i2p : : config : : GetOption ( " sam.port " , samPort ) ;
LogPrint ( eLogInfo , " Clients: starting SAM bridge at " , samAddr , " : " , samPort ) ;
2016-03-29 22:03:15 +00:00
try {
m_SamBridge = new SAMBridge ( samAddr , samPort ) ;
m_SamBridge - > Start ( ) ;
} catch ( std : : exception & e ) {
LogPrint ( eLogError , " Clients: Exception in SAM bridge: " , e . what ( ) ) ;
}
2014-10-16 01:39:39 +00:00
}
2015-02-12 21:11:56 +00:00
// BOB
2016-01-20 00:00:00 +00:00
bool bob ; i2p : : config : : GetOption ( " bob.enabled " , bob ) ;
if ( bob ) {
std : : string bobAddr ; i2p : : config : : GetOption ( " bob.address " , bobAddr ) ;
uint16_t bobPort ; i2p : : config : : GetOption ( " bob.port " , bobPort ) ;
2016-01-18 00:00:00 +00:00
LogPrint ( eLogInfo , " Clients: starting BOB command channel at " , bobAddr , " : " , bobPort ) ;
2016-03-29 22:03:15 +00:00
try {
m_BOBCommandChannel = new BOBCommandChannel ( bobAddr , bobPort ) ;
m_BOBCommandChannel - > Start ( ) ;
} catch ( std : : exception & e ) {
LogPrint ( eLogError , " Clients: Exception in BOB bridge: " , e . what ( ) ) ;
}
2014-12-02 20:47:44 +00:00
}
2016-03-26 14:31:47 +00:00
m_AddressBook . StartResolvers ( ) ;
2014-10-16 00:52:17 +00:00
}
void ClientContext : : Stop ( )
{
2016-03-02 17:04:02 +00:00
if ( m_HttpProxy )
{
LogPrint ( eLogInfo , " Clients: stopping HTTP Proxy " ) ;
m_HttpProxy - > Stop ( ) ;
delete m_HttpProxy ;
m_HttpProxy = nullptr ;
}
2015-12-18 12:44:03 +00:00
2016-03-02 17:04:02 +00:00
if ( m_SocksProxy )
{
LogPrint ( eLogInfo , " Clients: stopping SOCKS Proxy " ) ;
m_SocksProxy - > Stop ( ) ;
delete m_SocksProxy ;
m_SocksProxy = nullptr ;
}
2015-12-18 12:44:03 +00:00
2015-02-12 21:11:56 +00:00
for ( auto & it : m_ClientTunnels )
2014-10-16 01:39:39 +00:00
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: stopping I2P client tunnel on port " , it . first ) ;
2015-02-13 15:18:42 +00:00
it . second - > Stop ( ) ;
2014-10-16 01:39:39 +00:00
}
2015-02-13 20:56:57 +00:00
m_ClientTunnels . clear ( ) ;
2015-12-18 12:44:03 +00:00
2015-02-13 20:56:57 +00:00
for ( auto & it : m_ServerTunnels )
2014-10-16 01:39:39 +00:00
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: stopping I2P server tunnel " ) ;
2015-02-13 20:56:57 +00:00
it . second - > Stop ( ) ;
}
m_ServerTunnels . clear ( ) ;
2015-12-18 12:44:03 +00:00
2014-10-16 01:39:39 +00:00
if ( m_SamBridge )
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: stopping SAM bridge " ) ;
2014-10-16 01:39:39 +00:00
m_SamBridge - > Stop ( ) ;
delete m_SamBridge ;
m_SamBridge = nullptr ;
}
2015-12-18 12:44:03 +00:00
2014-12-02 20:47:44 +00:00
if ( m_BOBCommandChannel )
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: stopping BOB command channel " ) ;
2014-12-02 20:47:44 +00:00
m_BOBCommandChannel - > Stop ( ) ;
delete m_BOBCommandChannel ;
m_BOBCommandChannel = nullptr ;
2015-12-18 12:44:03 +00:00
}
LogPrint ( eLogInfo , " Clients: stopping AddressBook " ) ;
2015-03-30 14:21:52 +00:00
m_AddressBook . Stop ( ) ;
2014-10-16 00:52:17 +00:00
for ( auto it : m_Destinations )
it . second - > Stop ( ) ;
m_Destinations . clear ( ) ;
2015-02-24 20:40:50 +00:00
m_SharedLocalDestination = nullptr ;
2014-10-16 00:52:17 +00:00
}
2016-05-12 15:38:18 +00:00
void ClientContext : : ReloadConfig ( )
{
ReadTunnels ( ) ; // TODO: it reads new tunnels only, should be implemented better
}
2014-10-16 00:52:17 +00:00
2016-02-11 00:00:00 +00:00
void ClientContext : : LoadPrivateKeys ( i2p : : data : : PrivateKeys & keys , const std : : string & filename , i2p : : data : : SigningKeyType sigType )
2014-10-16 00:52:17 +00:00
{
2016-02-11 00:00:00 +00:00
std : : string fullPath = i2p : : fs : : DataDirPath ( filename ) ;
std : : ifstream s ( fullPath , std : : ifstream : : binary ) ;
2014-11-28 21:04:57 +00:00
if ( s . is_open ( ) )
{
s . seekg ( 0 , std : : ios : : end ) ;
size_t len = s . tellg ( ) ;
s . seekg ( 0 , std : : ios : : beg ) ;
uint8_t * buf = new uint8_t [ len ] ;
s . read ( ( char * ) buf , len ) ;
keys . FromBuffer ( buf , len ) ;
delete [ ] buf ;
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: Local address " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " loaded " ) ;
2014-11-28 21:04:57 +00:00
}
else
{
2016-01-04 02:43:43 +00:00
LogPrint ( eLogError , " Clients: can't open file " , fullPath , " Creating new one with signature type " , sigType ) ;
keys = i2p : : data : : PrivateKeys : : CreateRandomKeys ( sigType ) ;
2014-11-28 21:04:57 +00:00
std : : ofstream f ( fullPath , std : : ofstream : : binary | std : : ofstream : : out ) ;
size_t len = keys . GetFullLen ( ) ;
uint8_t * buf = new uint8_t [ len ] ;
len = keys . ToBuffer ( buf , len ) ;
f . write ( ( char * ) buf , len ) ;
delete [ ] buf ;
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: New private keys file " , fullPath , " for " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " created " ) ;
2014-11-28 21:04:57 +00:00
}
2014-10-16 00:52:17 +00:00
}
2015-02-24 20:40:50 +00:00
std : : shared_ptr < ClientDestination > ClientContext : : CreateNewLocalDestination ( bool isPublic , i2p : : data : : SigningKeyType sigType ,
2014-11-30 15:51:22 +00:00
const std : : map < std : : string , std : : string > * params )
2014-10-16 00:52:17 +00:00
{
2014-11-28 21:04:57 +00:00
i2p : : data : : PrivateKeys keys = i2p : : data : : PrivateKeys : : CreateRandomKeys ( sigType ) ;
2015-02-24 20:40:50 +00:00
auto localDestination = std : : make_shared < ClientDestination > ( keys , isPublic , params ) ;
2014-10-16 00:52:17 +00:00
std : : unique_lock < std : : mutex > l ( m_DestinationsMutex ) ;
m_Destinations [ localDestination - > GetIdentHash ( ) ] = localDestination ;
localDestination - > Start ( ) ;
return localDestination ;
}
2015-02-24 20:40:50 +00:00
void ClientContext : : DeleteLocalDestination ( std : : shared_ptr < ClientDestination > destination )
2014-10-16 00:52:17 +00:00
{
if ( ! destination ) return ;
auto it = m_Destinations . find ( destination - > GetIdentHash ( ) ) ;
if ( it ! = m_Destinations . end ( ) )
{
auto d = it - > second ;
{
std : : unique_lock < std : : mutex > l ( m_DestinationsMutex ) ;
m_Destinations . erase ( it ) ;
}
d - > Stop ( ) ;
}
}
2015-02-24 20:40:50 +00:00
std : : shared_ptr < ClientDestination > ClientContext : : CreateNewLocalDestination ( const i2p : : data : : PrivateKeys & keys , bool isPublic ,
2014-11-30 15:51:22 +00:00
const std : : map < std : : string , std : : string > * params )
2014-10-16 00:52:17 +00:00
{
2015-11-03 14:15:49 +00:00
auto it = m_Destinations . find ( keys . GetPublic ( ) - > GetIdentHash ( ) ) ;
2014-10-16 00:52:17 +00:00
if ( it ! = m_Destinations . end ( ) )
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogWarning , " Clients: Local destination " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " exists " ) ;
2014-10-16 00:52:17 +00:00
if ( ! it - > second - > IsRunning ( ) )
{
it - > second - > Start ( ) ;
return it - > second ;
}
return nullptr ;
}
2015-02-24 20:40:50 +00:00
auto localDestination = std : : make_shared < ClientDestination > ( keys , isPublic , params ) ;
2014-10-16 00:52:17 +00:00
std : : unique_lock < std : : mutex > l ( m_DestinationsMutex ) ;
2015-11-03 14:15:49 +00:00
m_Destinations [ keys . GetPublic ( ) - > GetIdentHash ( ) ] = localDestination ;
2014-10-16 00:52:17 +00:00
localDestination - > Start ( ) ;
return localDestination ;
}
2015-02-24 20:40:50 +00:00
std : : shared_ptr < ClientDestination > ClientContext : : FindLocalDestination ( const i2p : : data : : IdentHash & destination ) const
2014-10-16 00:52:17 +00:00
{
auto it = m_Destinations . find ( destination ) ;
if ( it ! = m_Destinations . end ( ) )
return it - > second ;
return nullptr ;
}
2015-02-12 21:11:56 +00:00
2016-01-15 17:24:40 +00:00
template < typename Section , typename Type >
std : : string ClientContext : : GetI2CPOption ( const Section & section , const std : : string & name , const Type & value ) const
{
return section . second . get ( boost : : property_tree : : ptree : : path_type ( name , ' / ' ) , std : : to_string ( value ) ) ;
}
template < typename Section >
void ClientContext : : ReadI2CPOptions ( const Section & section , std : : map < std : : string , std : : string > & options ) const
{
options [ I2CP_PARAM_INBOUND_TUNNEL_LENGTH ] = GetI2CPOption ( section , I2CP_PARAM_INBOUND_TUNNEL_LENGTH , DEFAULT_INBOUND_TUNNEL_LENGTH ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH ] = GetI2CPOption ( section , I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH , DEFAULT_OUTBOUND_TUNNEL_LENGTH ) ;
options [ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY ] = GetI2CPOption ( section , I2CP_PARAM_INBOUND_TUNNELS_QUANTITY , DEFAULT_INBOUND_TUNNELS_QUANTITY ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY ] = GetI2CPOption ( section , I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY , DEFAULT_OUTBOUND_TUNNELS_QUANTITY ) ;
2016-01-24 01:52:21 +00:00
options [ I2CP_PARAM_TAGS_TO_SEND ] = GetI2CPOption ( section , I2CP_PARAM_TAGS_TO_SEND , DEFAULT_TAGS_TO_SEND ) ;
2016-01-15 17:24:40 +00:00
}
2015-03-13 23:51:31 +00:00
void ClientContext : : ReadTunnels ( )
2015-03-13 20:05:39 +00:00
{
boost : : property_tree : : ptree pt ;
2016-02-22 20:27:40 +00:00
std : : string tunConf ; i2p : : config : : GetOption ( " tunconf " , tunConf ) ;
2016-03-28 00:00:00 +00:00
if ( tunConf = = " " ) {
// TODO: cleanup this in 2.8.0
2016-02-22 20:27:40 +00:00
tunConf = i2p : : fs : : DataDirPath ( " tunnels.cfg " ) ;
2016-03-28 00:00:00 +00:00
if ( i2p : : fs : : Exists ( tunConf ) ) {
LogPrint ( eLogWarning , " FS: please rename tunnels.cfg -> tunnels.conf here: " , tunConf ) ;
} else {
tunConf = i2p : : fs : : DataDirPath ( " tunnels.conf " ) ;
}
}
2016-02-22 20:27:40 +00:00
LogPrint ( eLogDebug , " FS: tunnels config file: " , tunConf ) ;
try
{
boost : : property_tree : : read_ini ( tunConf , pt ) ;
}
catch ( std : : exception & ex )
{
LogPrint ( eLogWarning , " Clients: Can't read " , tunConf , " : " , ex . what ( ) ) ;
2015-03-13 20:05:39 +00:00
return ;
}
int numClientTunnels = 0 , numServerTunnels = 0 ;
for ( auto & section : pt )
{
2015-03-13 23:51:31 +00:00
std : : string name = section . first ;
try
2015-03-13 20:05:39 +00:00
{
2015-03-13 23:51:31 +00:00
std : : string type = section . second . get < std : : string > ( I2P_TUNNELS_SECTION_TYPE ) ;
if ( type = = I2P_TUNNELS_SECTION_TYPE_CLIENT )
2015-03-13 20:05:39 +00:00
{
// mandatory params
2015-03-13 23:51:31 +00:00
std : : string dest = section . second . get < std : : string > ( I2P_CLIENT_TUNNEL_DESTINATION ) ;
int port = section . second . get < int > ( I2P_CLIENT_TUNNEL_PORT ) ;
2015-03-13 20:05:39 +00:00
// optional params
2015-03-19 14:22:01 +00:00
std : : string keys = section . second . get ( I2P_CLIENT_TUNNEL_KEYS , " " ) ;
2015-11-30 14:44:32 +00:00
std : : string address = section . second . get ( I2P_CLIENT_TUNNEL_ADDRESS , " 127.0.0.1 " ) ;
2015-03-15 15:28:30 +00:00
int destinationPort = section . second . get ( I2P_CLIENT_TUNNEL_DESTINATION_PORT , 0 ) ;
2016-01-04 02:43:43 +00:00
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_CLIENT_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
2016-01-14 20:57:55 +00:00
// I2CP
2016-01-15 17:24:40 +00:00
std : : map < std : : string , std : : string > options ;
ReadI2CPOptions ( section , options ) ;
2015-03-13 20:05:39 +00:00
std : : shared_ptr < ClientDestination > localDestination = nullptr ;
if ( keys . length ( ) > 0 )
2016-01-15 19:46:29 +00:00
{
i2p : : data : : PrivateKeys k ;
LoadPrivateKeys ( k , keys , sigType ) ;
2016-01-21 20:51:08 +00:00
localDestination = FindLocalDestination ( k . GetPublic ( ) - > GetIdentHash ( ) ) ;
if ( ! localDestination )
localDestination = CreateNewLocalDestination ( k , false , & options ) ;
2016-01-15 19:46:29 +00:00
}
2016-01-14 01:21:53 +00:00
auto clientTunnel = new I2PClientTunnel ( name , dest , address , port , localDestination , destinationPort ) ;
2016-04-24 21:32:24 +00:00
if ( m_ClientTunnels . insert ( std : : make_pair ( clientTunnel - > GetAcceptor ( ) . local_endpoint ( ) ,
std : : unique_ptr < I2PClientTunnel > ( clientTunnel ) ) ) . second )
2016-05-12 15:38:18 +00:00
{
2015-03-13 20:05:39 +00:00
clientTunnel - > Start ( ) ;
2016-05-12 15:38:18 +00:00
numClientTunnels + + ;
}
2015-03-13 20:05:39 +00:00
else
2016-05-12 15:38:18 +00:00
LogPrint ( eLogError , " Clients: I2P client tunnel for endpoint " , clientTunnel - > GetAcceptor ( ) . local_endpoint ( ) , " already exists " ) ;
2015-03-13 20:05:39 +00:00
}
2016-02-22 19:33:21 +00:00
else if ( type = = I2P_TUNNELS_SECTION_TYPE_SERVER | | type = = I2P_TUNNELS_SECTION_TYPE_HTTP | | type = = I2P_TUNNELS_SECTION_TYPE_IRC )
2015-03-13 23:51:31 +00:00
{
// mandatory params
std : : string host = section . second . get < std : : string > ( I2P_SERVER_TUNNEL_HOST ) ;
int port = section . second . get < int > ( I2P_SERVER_TUNNEL_PORT ) ;
std : : string keys = section . second . get < std : : string > ( I2P_SERVER_TUNNEL_KEYS ) ;
// optional params
2015-03-15 15:28:30 +00:00
int inPort = section . second . get ( I2P_SERVER_TUNNEL_INPORT , 0 ) ;
2016-02-26 01:32:05 +00:00
std : : string accessList = section . second . get ( I2P_SERVER_TUNNEL_ACCESS_LIST , " " ) ;
std : : string hostOverride = section . second . get ( I2P_SERVER_TUNNEL_HOST_OVERRIDE , " " ) ;
2016-03-04 06:37:38 +00:00
std : : string webircpass = section . second . get < std : : string > ( I2P_SERVER_TUNNEL_WEBIRC_PASSWORD , " " ) ;
2016-02-29 19:44:15 +00:00
bool gzip = section . second . get ( I2P_SERVER_TUNNEL_GZIP , true ) ;
2016-01-04 02:43:43 +00:00
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_SERVER_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
2016-01-14 20:57:55 +00:00
// I2CP
2016-01-14 23:45:47 +00:00
std : : map < std : : string , std : : string > options ;
2016-01-15 17:24:40 +00:00
ReadI2CPOptions ( section , options ) ;
2016-01-14 20:57:55 +00:00
2016-01-21 20:51:08 +00:00
std : : shared_ptr < ClientDestination > localDestination = nullptr ;
2016-01-15 19:46:29 +00:00
i2p : : data : : PrivateKeys k ;
LoadPrivateKeys ( k , keys , sigType ) ;
2016-01-21 20:51:08 +00:00
localDestination = FindLocalDestination ( k . GetPublic ( ) - > GetIdentHash ( ) ) ;
if ( ! localDestination )
localDestination = CreateNewLocalDestination ( k , true , & options ) ;
2016-02-22 19:33:21 +00:00
I2PServerTunnel * serverTunnel ;
2016-02-29 19:44:15 +00:00
if ( type = = I2P_TUNNELS_SECTION_TYPE_HTTP )
serverTunnel = new I2PServerTunnelHTTP ( name , host , port , localDestination , hostOverride , inPort , gzip ) ;
else if ( type = = I2P_TUNNELS_SECTION_TYPE_IRC )
2016-03-04 06:37:38 +00:00
serverTunnel = new I2PServerTunnelIRC ( name , host , port , localDestination , webircpass , inPort , gzip ) ;
2016-02-29 19:44:15 +00:00
else // regular server tunnel by default
serverTunnel = new I2PServerTunnel ( name , host , port , localDestination , inPort , gzip ) ;
2016-02-22 19:33:21 +00:00
2015-03-16 18:52:42 +00:00
if ( accessList . length ( ) > 0 )
{
std : : set < i2p : : data : : IdentHash > idents ;
size_t pos = 0 , comma ;
do
{
comma = accessList . find ( ' , ' , pos ) ;
i2p : : data : : IdentHash ident ;
ident . FromBase32 ( accessList . substr ( pos , comma ! = std : : string : : npos ? comma - pos : std : : string : : npos ) ) ;
idents . insert ( ident ) ;
pos = comma + 1 ;
}
while ( comma ! = std : : string : : npos ) ;
serverTunnel - > SetAccessList ( idents ) ;
}
2016-01-17 23:55:09 +00:00
if ( m_ServerTunnels . insert ( std : : make_pair (
2016-04-24 21:32:24 +00:00
std : : make_pair ( localDestination - > GetIdentHash ( ) , inPort ) ,
2016-01-17 23:55:09 +00:00
std : : unique_ptr < I2PServerTunnel > ( serverTunnel ) ) ) . second )
2016-05-12 15:38:18 +00:00
{
2015-03-13 23:51:31 +00:00
serverTunnel - > Start ( ) ;
2016-05-12 15:38:18 +00:00
numServerTunnels + + ;
}
2015-03-13 23:51:31 +00:00
else
2016-05-12 15:38:18 +00:00
LogPrint ( eLogError , " Clients: I2P server tunnel for destination/port " , m_AddressBook . ToAddress ( localDestination - > GetIdentHash ( ) ) , " / " , inPort , " already exists " ) ;
2015-03-13 20:05:39 +00:00
}
2015-03-13 23:51:31 +00:00
else
2016-02-22 20:27:40 +00:00
LogPrint ( eLogWarning , " Clients: Unknown section type= " , type , " of " , name , " in " , tunConf ) ;
2015-03-13 23:51:31 +00:00
2015-03-13 20:05:39 +00:00
}
2015-03-13 23:51:31 +00:00
catch ( std : : exception & ex )
2015-03-13 20:05:39 +00:00
{
2015-12-18 12:44:03 +00:00
LogPrint ( eLogError , " Clients: Can't read tunnel " , name , " params: " , ex . what ( ) ) ;
2015-03-13 20:05:39 +00:00
}
}
2015-12-18 12:44:03 +00:00
LogPrint ( eLogInfo , " Clients: " , numClientTunnels , " I2P client tunnels created " ) ;
LogPrint ( eLogInfo , " Clients: " , numServerTunnels , " I2P server tunnels created " ) ;
2015-03-13 20:05:39 +00:00
}
2014-10-16 00:52:17 +00:00
}
}