@ -40,7 +40,11 @@ namespace client
// proxies
// proxies
std : : string proxyKeys = i2p : : util : : config : : GetArg ( " -proxykeys " , " " ) ;
std : : string proxyKeys = i2p : : util : : config : : GetArg ( " -proxykeys " , " " ) ;
if ( proxyKeys . length ( ) > 0 )
if ( proxyKeys . length ( ) > 0 )
localDestination = LoadLocalDestination ( proxyKeys , false ) ;
{
i2p : : data : : PrivateKeys keys ;
LoadPrivateKeys ( keys , proxyKeys ) ;
localDestination = CreateNewLocalDestination ( keys , false ) ;
}
LogPrint ( eLogInfo , " Clients: starting HTTP Proxy " ) ;
LogPrint ( eLogInfo , " Clients: starting HTTP Proxy " ) ;
m_HttpProxy = new i2p : : proxy : : HTTPProxy ( i2p : : util : : config : : GetArg ( " -httpproxyaddress " , " 127.0.0.1 " ) , i2p : : util : : config : : GetArg ( " -httpproxyport " , 4446 ) , localDestination ) ;
m_HttpProxy = new i2p : : proxy : : HTTPProxy ( i2p : : util : : config : : GetArg ( " -httpproxyaddress " , " 127.0.0.1 " ) , i2p : : util : : config : : GetArg ( " -httpproxyport " , 4446 ) , localDestination ) ;
m_HttpProxy - > Start ( ) ;
m_HttpProxy - > Start ( ) ;
@ -122,10 +126,8 @@ namespace client
m_SharedLocalDestination = nullptr ;
m_SharedLocalDestination = nullptr ;
}
}
std : : shared_ptr < ClientDestination > ClientContext : : LoadLocalDestination ( const std : : string & filename ,
void ClientContext : : LoadPrivateKeys ( i2p : : data : : PrivateKeys & keys , const std : : string & filename , i2p : : data : : SigningKeyType sigType )
bool isPublic , i2p : : data : : SigningKeyType sigType , const std : : map < std : : string , std : : string > * params )
{
{
i2p : : data : : PrivateKeys keys ;
std : : string fullPath = i2p : : util : : filesystem : : GetFullPath ( filename ) ;
std : : string fullPath = i2p : : util : : filesystem : : GetFullPath ( filename ) ;
std : : ifstream s ( fullPath . c_str ( ) , std : : ifstream : : binary ) ;
std : : ifstream s ( fullPath . c_str ( ) , std : : ifstream : : binary ) ;
if ( s . is_open ( ) )
if ( s . is_open ( ) )
@ -152,22 +154,6 @@ namespace client
LogPrint ( eLogInfo , " Clients: New private keys file " , fullPath , " for " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " created " ) ;
LogPrint ( eLogInfo , " Clients: New private keys file " , fullPath , " for " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " created " ) ;
}
}
std : : shared_ptr < ClientDestination > localDestination = nullptr ;
std : : unique_lock < std : : mutex > l ( m_DestinationsMutex ) ;
auto it = m_Destinations . find ( keys . GetPublic ( ) - > GetIdentHash ( ) ) ;
if ( it ! = m_Destinations . end ( ) )
{
LogPrint ( eLogWarning , " Clients: Local destination " , m_AddressBook . ToAddress ( keys . GetPublic ( ) - > GetIdentHash ( ) ) , " already exists " ) ;
localDestination = it - > second ;
}
else
{
localDestination = std : : make_shared < ClientDestination > ( keys , isPublic , params ) ;
m_Destinations [ localDestination - > GetIdentHash ( ) ] = localDestination ;
localDestination - > Start ( ) ;
}
return localDestination ;
}
}
std : : shared_ptr < ClientDestination > ClientContext : : CreateNewLocalDestination ( bool isPublic , i2p : : data : : SigningKeyType sigType ,
std : : shared_ptr < ClientDestination > ClientContext : : CreateNewLocalDestination ( bool isPublic , i2p : : data : : SigningKeyType sigType ,
@ -225,7 +211,21 @@ namespace client
return nullptr ;
return nullptr ;
}
}
// should be moved in i2p::utils::fs
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 ) ;
}
void ClientContext : : ReadTunnels ( )
void ClientContext : : ReadTunnels ( )
{
{
boost : : property_tree : : ptree pt ;
boost : : property_tree : : ptree pt ;
@ -259,14 +259,15 @@ namespace client
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_CLIENT_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_CLIENT_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
// I2CP
// I2CP
std : : map < std : : string , std : : string > options ;
std : : map < std : : string , std : : string > options ;
options [ I2CP_PARAM_INBOUND_TUNNEL_LENGTH ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_INBOUND_TUNNEL_LENGTH , ' / ' ) , std : : to_string ( DEFAULT_INBOUND_TUNNEL_LENGTH ) ) ;
ReadI2CPOptions ( section , options ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH , ' / ' ) , std : : to_string ( DEFAULT_OUTBOUND_TUNNEL_LENGTH ) ) ;
options [ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_INBOUND_TUNNELS_QUANTITY , ' / ' ) , std : : to_string ( DEFAULT_INBOUND_TUNNELS_QUANTITY ) ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY , ' / ' ) , std : : to_string ( DEFAULT_OUTBOUND_TUNNELS_QUANTITY ) ) ;
std : : shared_ptr < ClientDestination > localDestination = nullptr ;
std : : shared_ptr < ClientDestination > localDestination = nullptr ;
if ( keys . length ( ) > 0 )
if ( keys . length ( ) > 0 )
localDestination = LoadLocalDestination ( keys , false , sigType , & options ) ;
{
i2p : : data : : PrivateKeys k ;
LoadPrivateKeys ( k , keys , sigType ) ;
localDestination = CreateNewLocalDestination ( k , false , & options ) ;
}
auto clientTunnel = new I2PClientTunnel ( name , dest , address , port , localDestination , destinationPort ) ;
auto clientTunnel = new I2PClientTunnel ( name , dest , address , port , localDestination , destinationPort ) ;
if ( m_ClientTunnels . insert ( std : : make_pair ( port , std : : unique_ptr < I2PClientTunnel > ( clientTunnel ) ) ) . second )
if ( m_ClientTunnels . insert ( std : : make_pair ( port , std : : unique_ptr < I2PClientTunnel > ( clientTunnel ) ) ) . second )
clientTunnel - > Start ( ) ;
clientTunnel - > Start ( ) ;
@ -286,12 +287,11 @@ namespace client
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_SERVER_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
i2p : : data : : SigningKeyType sigType = section . second . get ( I2P_SERVER_TUNNEL_SIGNATURE_TYPE , i2p : : data : : SIGNING_KEY_TYPE_ECDSA_SHA256_P256 ) ;
// I2CP
// I2CP
std : : map < std : : string , std : : string > options ;
std : : map < std : : string , std : : string > options ;
options [ I2CP_PARAM_INBOUND_TUNNEL_LENGTH ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_INBOUND_TUNNEL_LENGTH , ' / ' ) , std : : to_string ( DEFAULT_INBOUND_TUNNEL_LENGTH ) ) ;
ReadI2CPOptions ( section , options ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH , ' / ' ) , std : : to_string ( DEFAULT_OUTBOUND_TUNNEL_LENGTH ) ) ;
options [ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_INBOUND_TUNNELS_QUANTITY , ' / ' ) , std : : to_string ( DEFAULT_INBOUND_TUNNELS_QUANTITY ) ) ;
options [ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY ] = section . second . get ( decltype ( pt ) : : path_type ( I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY , ' / ' ) , std : : to_string ( DEFAULT_OUTBOUND_TUNNELS_QUANTITY ) ) ;
auto localDestination = LoadLocalDestination ( keys , true , sigType , & options ) ;
i2p : : data : : PrivateKeys k ;
LoadPrivateKeys ( k , keys , sigType ) ;
auto localDestination = CreateNewLocalDestination ( k , true , & options ) ;
I2PServerTunnel * serverTunnel = ( type = = I2P_TUNNELS_SECTION_TYPE_HTTP ) ?
I2PServerTunnel * serverTunnel = ( type = = I2P_TUNNELS_SECTION_TYPE_HTTP ) ?
new I2PServerTunnelHTTP ( name , host , port , localDestination , inPort ) :
new I2PServerTunnelHTTP ( name , host , port , localDestination , inPort ) :
new I2PServerTunnel ( name , host , port , localDestination , inPort ) ;
new I2PServerTunnel ( name , host , port , localDestination , inPort ) ;