Skip to content

Commit

Permalink
Merge pull request monero-project#414
Browse files Browse the repository at this point in the history
b65a32f Build: update CMake include_directories() and more (anonimal)
cf4828b Tests: update namespaces and organization (anonimal)
0e0a384 Kovri: update include guards from previous commits (anonimal)
9f90c9b Client: minor directory/filename organization (anonimal)
29a59a4 Crypto: move directory pimpl -> impl (anonimal)
12f028f Kovri: core namespace refactor + lib organization (anonimal)
c128346 Kovri: remove util namespace from app (anonimal)
47e7dcb Kovri: client namespace refactor + lib organization (anonimal)
50319e9 Kovri: app namespace refactor (anonimal)
20986c4 Kovri: global namespace refactor s/i2p/kovri/g (anonimal)
  • Loading branch information
anonimal committed Oct 29, 2016
2 parents c31dccf + b65a32f commit 95b35bf
Show file tree
Hide file tree
Showing 222 changed files with 2,503 additions and 2,448 deletions.
8 changes: 2 additions & 6 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_directories("../")

set(APP_SRC
"main.cc"
"daemon.cc"
Expand All @@ -17,12 +19,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND APP_SRC "win32_service.cc")
endif()

include_directories(
"."
"../"
"../core/"
"../client/")

if(WITH_BINARY)
add_executable(${APP_NAME} ${APP_SRC})
target_link_libraries(
Expand Down
176 changes: 90 additions & 86 deletions src/app/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Parts of the project are originally copyright (c) 2013-2015 The PurpleI2P Project //
*/

#include "daemon.h"
#include "app/daemon.h"

#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
Expand All @@ -40,22 +40,26 @@
#include <thread>
#include <vector>

#include "client/client_context.h"
#include "destination.h"
#include "garlic.h"
#include "net_db.h"
#include "router_context.h"
#include "router_info.h"
#include "version.h"
#include "streaming.h"
#include "app/util/config.h"

#include "client/api/streaming.h"
#include "client/context.h"
#include "client/destination.h"

#include "core/router/context.h"
#include "core/router/garlic.h"
#include "core/router/info.h"
#include "core/router/net_db/net_db.h"
#include "core/router/transports/ntcp/session.h"
#include "core/router/transports/transports.h"
#include "core/router/tunnel/tunnel.h"

#include "core/util/log.h"
#include "transport/ntcp_session.h"
#include "transport/transports.h"
#include "tunnel/tunnel.h"
#include "util/config.h"

namespace i2p {
namespace util {
#include "core/version.h"

namespace kovri {
namespace app {

Daemon_Singleton::Daemon_Singleton()
: m_IsDaemon(false),
Expand All @@ -66,37 +70,37 @@ Daemon_Singleton::~Daemon_Singleton() {}
// TODO(anonimal): find a better way to initialize
bool Daemon_Singleton::Init() {
LogPrint(eLogInfo, "Daemon_Singleton: initializing");
i2p::context.Init(
i2p::util::config::var_map["host"].as<std::string>(),
i2p::util::config::var_map["port"].as<int>(),
i2p::util::filesystem::GetDataPath());
m_IsDaemon = i2p::util::config::var_map["daemon"].as<bool>();
auto port = i2p::util::config::var_map["port"].as<int>();
i2p::context.UpdatePort(port);
i2p::context.UpdateAddress(
kovri::context.Init(
kovri::app::var_map["host"].as<std::string>(),
kovri::app::var_map["port"].as<int>(),
kovri::app::GetDataPath());
m_IsDaemon = kovri::app::var_map["daemon"].as<bool>();
auto port = kovri::app::var_map["port"].as<int>();
kovri::context.UpdatePort(port);
kovri::context.UpdateAddress(
boost::asio::ip::address::from_string(
i2p::util::config::var_map["host"].as<std::string>()));
i2p::context.SetSupportsV6(
i2p::util::config::var_map["v6"].as<bool>());
i2p::context.SetFloodfill(
i2p::util::config::var_map["floodfill"].as<bool>());
auto bandwidth = i2p::util::config::var_map["bandwidth"].as<std::string>();
kovri::app::var_map["host"].as<std::string>()));
kovri::context.SetSupportsV6(
kovri::app::var_map["v6"].as<bool>());
kovri::context.SetFloodfill(
kovri::app::var_map["floodfill"].as<bool>());
auto bandwidth = kovri::app::var_map["bandwidth"].as<std::string>();
if (bandwidth.length() > 0) {
if (bandwidth[0] > 'L')
i2p::context.SetHighBandwidth();
kovri::context.SetHighBandwidth();
else
i2p::context.SetLowBandwidth();
kovri::context.SetLowBandwidth();
}
// Set reseed options
i2p::context.SetOptionReseedFrom(
i2p::util::config::var_map["reseed-from"].as<std::string>());
i2p::context.SetOptionReseedSkipSSLCheck(
i2p::util::config::var_map["reseed-skip-ssl-check"].as<bool>());
kovri::context.SetOptionReseedFrom(
kovri::app::var_map["reseed-from"].as<std::string>());
kovri::context.SetOptionReseedSkipSSLCheck(
kovri::app::var_map["reseed-skip-ssl-check"].as<bool>());
// Set transport options
i2p::context.SetSupportsNTCP(
i2p::util::config::var_map["enable-ntcp"].as<bool>());
i2p::context.SetSupportsSSU(
i2p::util::config::var_map["enable-ssu"].as<bool>());
kovri::context.SetSupportsNTCP(
kovri::app::var_map["enable-ntcp"].as<bool>());
kovri::context.SetSupportsSSU(
kovri::app::var_map["enable-ssu"].as<bool>());
// Initialize the ClientContext
InitClientContext();
return true;
Expand All @@ -105,27 +109,27 @@ bool Daemon_Singleton::Init() {
bool Daemon_Singleton::Start() {
LogPrint(eLogInfo,
"Daemon_Singleton: listening on port ",
i2p::util::config::var_map["port"].as<int>());
kovri::app::var_map["port"].as<int>());
try {
LogPrint(eLogInfo, "Daemon_Singleton: starting NetDb");
if (!i2p::data::netdb.Start()) {
if (!kovri::core::netdb.Start()) {
LogPrint(eLogError, "Daemon_Singleton: NetDb failed to start");
return false;
}
if (i2p::data::netdb.GetNumRouters() < i2p::data::netdb.MIN_REQUIRED_ROUTERS) {
if (kovri::core::netdb.GetNumRouters() < kovri::core::netdb.MIN_REQUIRED_ROUTERS) {
LogPrint(eLogInfo, "Daemon_Singleton: reseeding NetDb");
i2p::data::Reseed reseed;
kovri::client::Reseed reseed;
if (!reseed.Start()) {
LogPrint(eLogError, "Daemon_Singleton: reseed failed");
return false;
}
}
LogPrint(eLogInfo, "Daemon_Singleton: starting transports");
i2p::transport::transports.Start();
kovri::core::transports.Start();
LogPrint(eLogInfo, "Daemon_Singleton: starting tunnels");
i2p::tunnel::tunnels.Start();
kovri::core::tunnels.Start();
LogPrint(eLogInfo, "Daemon_Singleton: starting client");
i2p::client::context.Start();
kovri::client::context.Start();
} catch (std::runtime_error& e) {
LogPrint(eLogError, "Daemon_Singleton: runtime start exception: ", e.what());
return false;
Expand All @@ -136,13 +140,13 @@ bool Daemon_Singleton::Start() {
bool Daemon_Singleton::Stop() {
try {
LogPrint(eLogInfo, "Daemon_Singleton: stopping client");
i2p::client::context.Stop();
kovri::client::context.Stop();
LogPrint(eLogInfo, "Daemon_Singleton: stopping tunnels");
i2p::tunnel::tunnels.Stop();
kovri::core::tunnels.Stop();
LogPrint(eLogInfo, "Daemon_Singleton: stopping transports");
i2p::transport::transports.Stop();
kovri::core::transports.Stop();
LogPrint(eLogInfo, "Daemon_Singleton: stopping NetDb");
i2p::data::netdb.Stop();
kovri::core::netdb.Stop();
LogPrint(eLogInfo, "Goodbye!");
} catch (std::runtime_error& e) {
LogPrint(eLogError, "Daemon_Singleton: runtime stop exception: ", e.what());
Expand All @@ -160,33 +164,33 @@ void Daemon_Singleton::Reload() {
}

void Daemon_Singleton::InitClientContext() {
i2p::client::context.RegisterShutdownHandler(
kovri::client::context.RegisterShutdownHandler(
[this]() { m_IsRunning = false; });
std::shared_ptr<i2p::client::ClientDestination> local_destination;
std::shared_ptr<kovri::client::ClientDestination> local_destination;
// Setup proxies and services
auto proxy_keys =
i2p::util::config::var_map["proxykeys"].as<std::string>();
kovri::app::var_map["proxykeys"].as<std::string>();
if (proxy_keys.length() > 0)
local_destination = i2p::client::context.LoadLocalDestination(
local_destination = kovri::client::context.LoadLocalDestination(
proxy_keys,
false);
i2p::client::context.SetHTTPProxy(std::make_unique<i2p::proxy::HTTPProxy>(
kovri::client::context.SetHTTPProxy(std::make_unique<kovri::client::HTTPProxy>(
"HTTP Proxy", // TODO(unassigned): what if we want to change the name?
i2p::util::config::var_map["httpproxyaddress"].as<std::string>(),
i2p::util::config::var_map["httpproxyport"].as<int>(),
kovri::app::var_map["httpproxyaddress"].as<std::string>(),
kovri::app::var_map["httpproxyport"].as<int>(),
local_destination));
i2p::client::context.SetSOCKSProxy(std::make_unique<i2p::proxy::SOCKSProxy>(
i2p::util::config::var_map["socksproxyaddress"].as<std::string>(),
i2p::util::config::var_map["socksproxyport"].as<int>(),
kovri::client::context.SetSOCKSProxy(std::make_unique<kovri::client::SOCKSProxy>(
kovri::app::var_map["socksproxyaddress"].as<std::string>(),
kovri::app::var_map["socksproxyport"].as<int>(),
local_destination));
auto i2pcontrol_port = i2p::util::config::var_map["i2pcontrolport"].as<int>();
auto i2pcontrol_port = kovri::app::var_map["i2pcontrolport"].as<int>();
if (i2pcontrol_port) {
i2p::client::context.SetI2PControlService(
std::make_unique<i2p::client::i2pcontrol::I2PControlService>(
i2p::client::context.GetIoService(),
i2p::util::config::var_map["i2pcontroladdress"].as<std::string>(),
kovri::client::context.SetI2PControlService(
std::make_unique<kovri::client::I2PControlService>(
kovri::client::context.GetIoService(),
kovri::app::var_map["i2pcontroladdress"].as<std::string>(),
i2pcontrol_port,
i2p::util::config::var_map["i2pcontrolpassword"].as<std::string>()));
kovri::app::var_map["i2pcontrolpassword"].as<std::string>()));
}
// Setup client and server tunnels
SetupTunnels();
Expand All @@ -195,7 +199,7 @@ void Daemon_Singleton::InitClientContext() {
void Daemon_Singleton::SetupTunnels() {
boost::property_tree::ptree pt;
auto path_tunnels_config_file =
i2p::util::filesystem::GetTunnelsConfigFile().string();
kovri::app::GetTunnelsConfigFile().string();
try {
boost::property_tree::read_ini(path_tunnels_config_file, pt);
} catch(const std::exception& ex) {
Expand All @@ -220,15 +224,15 @@ void Daemon_Singleton::SetupTunnels() {
auto keys = value.get(I2P_CLIENT_TUNNEL_KEYS, "");
auto destination_port = value.get(I2P_CLIENT_TUNNEL_DESTINATION_PORT, 0);
// Get local destination
std::shared_ptr<i2p::client::ClientDestination> local_destination;
std::shared_ptr<kovri::client::ClientDestination> local_destination;
if (keys.length() > 0)
local_destination =
i2p::client::context.LoadLocalDestination(keys, false);
kovri::client::context.LoadLocalDestination(keys, false);
// Insert client tunnel
bool result =
i2p::client::context.InsertClientTunnel(
kovri::client::context.InsertClientTunnel(
port,
std::make_unique<i2p::client::I2PClientTunnel>(
std::make_unique<kovri::client::I2PClientTunnel>(
name,
dest,
address,
Expand All @@ -251,32 +255,32 @@ void Daemon_Singleton::SetupTunnels() {
auto in_port = value.get(I2P_SERVER_TUNNEL_INPORT, 0);
auto accessList = value.get(I2P_SERVER_TUNNEL_ACCESS_LIST, "");
auto local_destination =
i2p::client::context.LoadLocalDestination(keys, true);
kovri::client::context.LoadLocalDestination(keys, true);
auto server_tunnel =
(type == I2P_TUNNELS_SECTION_TYPE_HTTP) ?
std::make_unique<i2p::client::I2PServerTunnelHTTP>(
std::make_unique<kovri::client::I2PServerTunnelHTTP>(
name,
host,
port,
local_destination,
in_port) :
std::make_unique<i2p::client::I2PServerTunnel>(
std::make_unique<kovri::client::I2PServerTunnel>(
name,
host,
port,
local_destination,
in_port);
server_tunnel->SetAccessListString(accessList);
// Insert server tunnel
bool result = i2p::client::context.InsertServerTunnel(
bool result = kovri::client::context.InsertServerTunnel(
local_destination->GetIdentHash(),
std::move(server_tunnel));
if (result)
++num_server_tunnels;
else
LogPrint(eLogError,
"Daemon_Singleton: I2P server tunnel for destination ",
i2p::client::context.GetAddressBook().GetB32AddressFromIdentHash(
kovri::client::context.GetAddressBook().GetB32AddressFromIdentHash(
local_destination->GetIdentHash()),
" already exists");
} else {
Expand All @@ -298,7 +302,7 @@ void Daemon_Singleton::SetupTunnels() {
void Daemon_Singleton::ReloadTunnels() {
boost::property_tree::ptree pt;
auto tunnels_config_file =
i2p::util::filesystem::GetTunnelsConfigFile().string();
kovri::app::GetTunnelsConfigFile().string();
try {
boost::property_tree::read_ini(tunnels_config_file, pt);
} catch (const std::exception& ex) {
Expand All @@ -325,7 +329,7 @@ void Daemon_Singleton::ReloadTunnels() {
auto port = value.get<int>(I2P_SERVER_TUNNEL_PORT, 0);
auto in_port = value.get(I2P_SERVER_TUNNEL_INPORT, 0);
auto access_list = value.get(I2P_SERVER_TUNNEL_ACCESS_LIST, "");
i2p::client::context.UpdateServerTunnel(
kovri::client::context.UpdateServerTunnel(
tunnel_name,
key_file,
host_str,
Expand All @@ -340,7 +344,7 @@ void Daemon_Singleton::ReloadTunnels() {
auto host_str = value.get(I2P_CLIENT_TUNNEL_ADDRESS, "127.0.0.1");
auto port = value.get<int>(I2P_CLIENT_TUNNEL_PORT, 0);
auto dest_port = value.get(I2P_CLIENT_TUNNEL_DESTINATION_PORT, 0);
auto tunnel = i2p::client::context.GetClientTunnel(port);
auto tunnel = kovri::client::context.GetClientTunnel(port);
if (tunnel && tunnel->GetName() != tunnel_name) {
// Conflicting port
// TODO(unassigned): what if we interchange two client tunnels' ports?
Expand All @@ -350,7 +354,7 @@ void Daemon_Singleton::ReloadTunnels() {
tunnel_name, " will not be updated, conflicting port");
continue;
}
i2p::client::context.UpdateClientTunnel(
kovri::client::context.UpdateClientTunnel(
tunnel_name,
key_file,
destination,
Expand All @@ -359,21 +363,21 @@ void Daemon_Singleton::ReloadTunnels() {
dest_port);
}
}
i2p::client::context.RemoveServerTunnels(
[&updated_tunnels](i2p::client::I2PServerTunnel* tunnel) {
kovri::client::context.RemoveServerTunnels(
[&updated_tunnels](kovri::client::I2PServerTunnel* tunnel) {
return std::find(
updated_tunnels.begin(),
updated_tunnels.end(),
tunnel->GetName()) == updated_tunnels.end();
});
i2p::client::context.RemoveClientTunnels(
[&updated_tunnels](i2p::client::I2PClientTunnel* tunnel) {
kovri::client::context.RemoveClientTunnels(
[&updated_tunnels](kovri::client::I2PClientTunnel* tunnel) {
return std::find(
updated_tunnels.begin(),
updated_tunnels.end(),
tunnel->GetName()) == updated_tunnels.end();
});
}

} // namespace util
} // namespace i2p
} // namespace app
} // namespace kovri
Loading

0 comments on commit 95b35bf

Please sign in to comment.