Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #754
Browse files Browse the repository at this point in the history
771340f Core: default RI opts setter + remove deprecation (anonimal)
872c70e Core: rewrite RI address add'er (anonimal)
1f14b65 Core: context/RI trait and state refactor (anonimal)
b254beb Core: fix description logging of SSU address key (anonimal)
a2a49aa Core: new RI ctor + fixes + WIP context init rewrite (anonimal)
18aa94e Core: don't use interface for context initialization (anonimal)
eb37e28 Core: return uint64_t for router uptime (anonimal)
32b9d7c Core: WIP rewrite of router initialization (anonimal)
55df5b9 Core: initial rewrite of router initialization (anonimal)
af6c154 Core: refactor context into core namespace (anonimal)
  • Loading branch information
anonimal committed Nov 27, 2017
2 parents 365c212 + 771340f commit 8a310f7
Show file tree
Hide file tree
Showing 25 changed files with 508 additions and 472 deletions.
7 changes: 4 additions & 3 deletions src/client/api/i2p_control/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ void I2PControlSession::HandleRouterInfo(
case RouterInfo::Uptime:
response->SetParam(
pair.first,
static_cast<std::size_t>(kovri::context.GetUptime()) * 1000);
// TODO(unassigned): do not downcast from uint64_t! Requires interface work.
static_cast<std::size_t>(core::context.GetUptime()) * 1000); // TODO(unassigned): multiplying will not bode well for the distant future...
break;

case RouterInfo::Version:
Expand All @@ -273,7 +274,7 @@ void I2PControlSession::HandleRouterInfo(
case RouterInfo::NetStatus:
response->SetParam(
pair.first,
static_cast<std::size_t>(kovri::context.GetStatus()));
static_cast<std::size_t>(core::context.GetState()));
break;

case RouterInfo::TunnelsParticipating:
Expand Down Expand Up @@ -393,7 +394,7 @@ void I2PControlSession::HandleShutdown(Response* response)
void I2PControlSession::HandleShutdownGraceful(Response* response)
{
// Stop accepting tunnels
kovri::context.SetAcceptsTunnels(false);
core::context.SetAcceptsTunnels(false);
// Get tunnel expiry time
std::uint64_t timeout = kovri::core::tunnels.GetTransitTunnelsExpirationTimeout();
LOG(info)
Expand Down
7 changes: 5 additions & 2 deletions src/client/reseed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ bool Reseed::Start() {
}
}
// Implement SU3
SU3 su3(m_Stream, m_SigningKeys);
SU3 su3(
m_Stream,
m_SigningKeys,
core::context.GetOpts()["disable-su3-verification"].as<bool>());
if (!su3.SU3Impl()) {
LOG(error) << "Reseed: SU3 implementation failed";
return false;
Expand Down Expand Up @@ -239,7 +242,7 @@ bool Reseed::FetchStream(
*/
bool SU3::SU3Impl()
{
if (kovri::context.GetOptionDisableSU3Verification())
if (m_DisableVerification)
{
LOG(warning) << "SU3: verification disabled !";
// TODO(unassigned): detection and implemention of other formats
Expand Down
18 changes: 14 additions & 4 deletions src/client/reseed.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class Reseed {
public:
/// @brief Constructs stream from string
explicit Reseed(
const std::string& stream = kovri::context.GetOptionReseedFrom())
: m_Stream(stream) {}
const std::string& stream =
core::context.GetOpts()["reseed-from"].as<std::string>())
: m_Stream(stream)
{
}

/// @brief Reseed implementation
/// @details Oversees fetching and processing of SU3
Expand Down Expand Up @@ -136,14 +139,18 @@ class Reseed {
/**
* @class SU3
* @brief SU3 implementation
* @param String of bytes that *must* be an SU3
* @param su3 String of bytes that *must* be an SU3
* @param keys Pubkeys to verify with
* @param disable_verification Disable signed SU3 verification?
*/
class SU3 {
public:
SU3(const std::string& su3,
std::map<std::string, kovri::core::PublicKey>& keys)
std::map<std::string, kovri::core::PublicKey>& keys,
bool disable_verification = false)
: m_Stream(su3),
m_SigningKeys(keys),
m_DisableVerification(disable_verification),
m_Data(std::make_unique<Data>()) {}

// Extracted RI's (map of router info files)
Expand Down Expand Up @@ -276,6 +283,9 @@ class SU3 {
// X.509 signing keys for SU3 verification
std::map<std::string, kovri::core::PublicKey> m_SigningKeys;

/// @brief Disable SU3 verification?
bool m_DisableVerification;

// Spec-defined data
std::unique_ptr<Data> m_Data;
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/util/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool HTTP::DownloadViaClearnet() {
LOG(debug) << "HTTP: Download Clearnet with timeout : "
<< kovri::core::GetType(Timeout::Request);
// Ensure that we only download from explicit SSL-enabled hosts
if (kovri::context.GetOptionEnableSSL()) {
if (core::context.GetOpts()["enable-ssl"].as<bool>()) {
const std::string cert = uri.host() + ".crt";
const boost::filesystem::path cert_path = kovri::core::GetSSLCertsPath() / cert;
if (!boost::filesystem::exists(cert_path)) {
Expand Down
42 changes: 2 additions & 40 deletions src/core/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,9 @@ Instance::~Instance() {}
// Note: we'd love Instance RAII but singleton needs to be daemonized (if applicable) before initialization
void Instance::Initialize()
{
// TODO(unassigned): see TODO's for router context and singleton
LOG(debug) << "Instance: initializing core";
auto const& map = m_Config.GetMap();
auto host = map["host"].as<std::string>();

// Random generated port if none is supplied via CLI or config
// See: i2p.i2p/router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java
auto const port =
map["port"].defaulted()
? RandInRange32(RouterInfo::MinPort, RouterInfo::MaxPort)
: map["port"].as<int>();
LOG(info) << "Instance: listening on port " << port;

// TODO(unassigned): context should be in core namespace (see TODO in router context)
context.Init(host, port);
context.UpdatePort(port);

context.UpdateAddress(boost::asio::ip::address::from_string(host));
context.SetSupportsV6(map["v6"].as<bool>());
context.SetFloodfill(map["floodfill"].as<bool>());

auto const bandwidth = map["bandwidth"].as<std::string>();
if (!bandwidth.empty())
{
if (bandwidth[0] > 'L')
context.SetHighBandwidth();
else
context.SetLowBandwidth();
}

// Set reseed options
context.SetOptionReseedFrom(map["reseed-from"].as<std::string>());
context.SetOptionDisableSU3Verification(
map["disable-su3-verification"].as<bool>());

// Set transport options
context.SetSupportsNTCP(map["enable-ntcp"].as<bool>());
context.SetSupportsSSU(map["enable-ssu"].as<bool>());

// Set SSL option
context.SetOptionEnableSSL(map["enable-ssl"].as<bool>());
// TODO(unassigned): see TODOs for router context and singleton
context.Initialize(m_Config.GetMap());
}

void Instance::Start()
Expand Down
Loading

0 comments on commit 8a310f7

Please sign in to comment.