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

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
anonimal committed Jun 19, 2016
2 parents 70941e5 + 425ff5e commit 32cc1db
Show file tree
Hide file tree
Showing 35 changed files with 774 additions and 708 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ env:
- secure: J4o/q57D7PAqV+hG5VUhwGJLH4ryFWy8YGVAlAOyrRVv9UxfbiihhyE5Yh68tjukdFqLt3WcHB3hoPz0VfbxWGdLQ9OR0r7xxYPetA0qVYcttpumcVSBra17CCRBYOcyRCfbgUY/LVRbKlr8zgkubRUW0skUcAgELyZJA6k/k+3pd1oDjdBLMLp+TeQvQnUtekw7eEzBl31bgpku3vHQEiYxMRY6FhBC0vojNJSjT56pqYzA/bOVrPNDATxHqDAxuEWfNiNQym4P2T+LmkC2utCWlwLBSqTauy54z4nKM6+0xEmRq2hmBWZeSv1tYuKJi8rmtAH5OozyVGSaXpuelcaWE4YrNCGEXOJZQvuD+IEuFVSkqXItoUIjlE1kP/zIDAZERMaISzXkp2xpPQFes8NLE3lNdcvMYYUjVfyUpYN0qE5/XX6Opii6Y8Sj6wQaz1Y5n3g1Lp5TMlQIVmmTUPAWoCq3U2BTPn+Ub8O8Z7Y/9Zr1xdz3gBEJaYv1CuxrSb3z3lQ9BjodBL1u+l5me+16dBe4RbpPwoWvLramJAvKEuDHMx93UnYU+PWs9B9UyIwEh/FxpvRyu8iyI6pfNWIsrc1jJ2nzf1YrnXOHb0C0CdwHH6p6Nzy/bOfaBOihiwc6o9r80AHq0RBbkH7euPOGFAo4iUgYTaS7R9Pw6Rk=
sudo: required
dist: trusty
before_install:
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
language: cpp
compiler:
- gcc
addons:
apt:
packages:
- ca-certificates
- gcc-5
- g++-5
- libboost-all-dev
Expand All @@ -20,14 +23,14 @@ addons:
- doxygen
sources:
- ubuntu-toolchain-r-test
coverity_scan:
project:
name: monero-project/kovri
description: The Kovri I2P Router Project
notification_email: [email protected]
build_command_prepend: export CC=gcc-${GCC_VERSION} CXX=g++-${GCC_VERSION} && cd build && cmake -DWITH_TESTS=ON -DWITH_BENCHMARKS=ON -DWITH_UPNP=ON -DWITH_DOXYGEN=ON ../
build_command: make -j2
branch_pattern: coverity_scan
coverity_scan:
project:
name: monero-project/kovri
description: The Kovri I2P Router Project
notification_email: [email protected]
build_command_prepend: export CC=gcc-${GCC_VERSION} CXX=g++-${GCC_VERSION} && cd build && cmake -DWITH_TESTS=ON -DWITH_BENCHMARKS=ON -DWITH_UPNP=ON -DWITH_DOXYGEN=ON ../
build_command: make -j2
branch_pattern: coverity_scan
before_script: export CC=gcc-${GCC_VERSION} CXX=g++-${GCC_VERSION}
script: if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then cd build && cmake -DWITH_TESTS=ON -DWITH_BENCHMARKS=ON -DWITH_UPNP=ON -DWITH_DOXYGEN=ON ../ && make doc && make -j2 ; fi
notifications:
Expand Down
10 changes: 5 additions & 5 deletions src/app/Daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace util {

Daemon_Singleton::Daemon_Singleton()
: m_IsRunning(true),
m_log(i2p::util::log::Log::Get()) {}
m_Log(i2p::util::log::Log::Get()) {}
Daemon_Singleton::~Daemon_Singleton() {}

bool Daemon_Singleton::IsService() const {
Expand Down Expand Up @@ -123,7 +123,7 @@ bool Daemon_Singleton::Start() {
StartLog(""); // write to stdout
}
} else {
m_log->Stop();
m_Log->Stop();
}
try {
LogPrint(eLogInfo, "Daemon_Singleton: starting NetDb");
Expand Down Expand Up @@ -206,7 +206,7 @@ void Daemon_Singleton::SetupTunnels() {
try {
boost::property_tree::read_ini(path_tunnels_config_file, pt);
} catch(const std::exception& ex) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"Daemon_Singleton: can't read ",
path_tunnels_config_file, ": ", ex.what());
return;
Expand Down Expand Up @@ -287,7 +287,7 @@ void Daemon_Singleton::SetupTunnels() {
local_destination->GetIdentHash()),
" already exists");
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"Daemon_Singleton: unknown section type=",
type, " of ", name, " in ", path_tunnels_config_file);
}
Expand All @@ -309,7 +309,7 @@ void Daemon_Singleton::ReloadTunnels() {
try {
boost::property_tree::read_ini(tunnels_config_file, pt);
} catch (const std::exception& ex) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"Daemon_Singleton: can't read ",
tunnels_config_file, ": ", ex.what());
return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/Daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Daemon_Singleton {
Daemon_Singleton();
virtual ~Daemon_Singleton();
bool IsService() const;
std::shared_ptr<i2p::util::log::Log> m_log;
std::shared_ptr<i2p::util::log::Log> m_Log;
};

#ifdef _WIN32
Expand Down
50 changes: 49 additions & 1 deletion src/app/util/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
#include "Config.h"

#include <string>
#include <vector>

#include <crypto/Rand.h>
#include "core/util/Log.h"
#include "crypto/Rand.h"

namespace i2p {
namespace util {
Expand Down Expand Up @@ -104,6 +106,17 @@ bool ParseArgs(
"Enable or disable logging to file\n"
"1 = enabled, 0 = disabled\n")

("log-levels", bpo::value<std::vector<std::string>>()->
// Note: we set a default value during validation and
// leave blank here to prevent bad_any_cast exception.
default_value(std::vector<std::string>(), "")->multitoken(),
"Log levels to report.\n"
"Options: info warn error debug\n"
"Examples:\n"
"./kovri --log-levels info # produces info only\n"
"./kovri --log-levels warn error # warn/error only\n"
"Default: all levels [info warn error debug]\n")

("daemon,d", bpo::value<bool>()->default_value(0),
"Enable or disable daemon mode\n"
"1 = enabled, 0 = disabled\n")
Expand Down Expand Up @@ -220,6 +233,9 @@ bool ParseArgs(
bpo::notify(var_map);
// Parse config after mapping cli
ParseConfigFile(kovri_config, config_options, var_map);
// Validate user input where possible
if (!ValidateUserInput())
return false;
/*
* Display --help and --help-with
*/
Expand Down Expand Up @@ -271,6 +287,38 @@ void ParseConfigFile(
}
}

bool ValidateUserInput() {
/**
* TODO(unassigned): write custom validator for log-levels
* so we can set values via config file.
*/
// Test for valid log-levels input
auto arg_levels = var_map["log-levels"].as<std::vector<std::string>>();
auto global_levels = i2p::util::log::GetGlobalLogLevels();
if (arg_levels.size()) {
if (arg_levels.size() > global_levels.size()) {
std::cout << "Invalid number of log levels. Maximum allowed: "
<< global_levels.size() << std::endl;
return false;
}
// Verify validity of log levels
for (auto& level : arg_levels) {
auto result = global_levels.find(level);
if (result == global_levels.end()) {
std::cout << "Invalid log-level(s). See help for options" << std::endl;
return false;
}
}
} else {
// Set default log-levels if none present
for (auto& level : global_levels)
arg_levels.push_back(level.first);
}
// Set new global log-levels
i2p::util::log::SetGlobalLogLevels(arg_levels);
return true;
}

} // namespace config
} // namespace util
} // namespace i2p
4 changes: 4 additions & 0 deletions src/app/util/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void ParseConfigFile(
boost::program_options::options_description& config_options,
boost::program_options::variables_map& var_map);

/// @brief Validates user input where possible
/// @return False on failure
bool ValidateUserInput();

} // namespace config
} // namespace util
} // namespace i2p
Expand Down
6 changes: 3 additions & 3 deletions src/client/AddressBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int AddressBookFilesystemStorage::Load(
LogPrint(eLogInfo,
"AddressBookFilesystemStorage: ", num, " addresses loaded");
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"AddressBookFilesystemStorage: ", filename, " not found");
}
return num;
Expand Down Expand Up @@ -390,7 +390,7 @@ void AddressBook::LoadSubscriptions() {
LogPrint(eLogInfo,
"AddressBook: ", m_Subscriptions.size(), " subscriptions loaded");
} else {
LogPrint(eLogWarning, "AddressBook: subscriptions.txt not found");
LogPrint(eLogWarn, "AddressBook: subscriptions.txt not found");
}
} else {
LogPrint(eLogError, "AddressBook: subscriptions already loaded");
Expand Down Expand Up @@ -602,7 +602,7 @@ void AddressBookSubscription::Request() {
LogPrint(eLogInfo,
"AddressBookSubscription: no updates from ", m_Link);
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"AddressBookSubscription: HTTP response ", status);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/client/ClientContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ std::shared_ptr<ClientDestination> ClientContext::LoadLocalDestination(
std::unique_lock<std::mutex> l(m_DestinationsMutex);
auto it = m_Destinations.find(keys.GetPublic().GetIdentHash());
if (it != m_Destinations.end()) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientContext: local destination ",
m_AddressBook.ToAddress(keys.GetPublic().GetIdentHash()),
" already exists");
Expand Down
10 changes: 5 additions & 5 deletions src/client/Datagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void DatagramDestination::SendMsg(
outboundTunnel->SendTunnelDataMsg(msgs);
} else {
if (outboundTunnel)
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"DatagramDestination: failed to send datagram: all leases expired");
else
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"DatagramDestination: failed to send datagram: no outbound tunnels");
DeleteI2NPMessage(msg);
}
Expand Down Expand Up @@ -152,10 +152,10 @@ void DatagramDestination::HandleDatagram(
m_Receiver(
identity, fromPort, toPort, buf + headerLen, len - headerLen);
else
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"DatagramDestination: receiver for datagram is not set");
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"DatagramDestination: datagram signature verification failed");
}
}
Expand All @@ -174,7 +174,7 @@ void DatagramDestination::HandleDataMessagePayload(
decompressor.Get(uncompressed, uncompressedLen);
HandleDatagram(fromPort, toPort, uncompressed, uncompressedLen);
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"DatagramDestination: the received datagram size ",
uncompressedLen, " exceeds max size");
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void ClientDestination::HandleDatabaseSearchReplyMessage(
m_LeaseSetRequests.erase(key);
}
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientDestination: request for ", key.ToBase64(), " not found");
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ void ClientDestination::HandlePublishConfirmationTimer(
const boost::system::error_code& ecode) {
if (ecode != boost::asio::error::operation_aborted) {
if (m_PublishReplyToken) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientDestination: publish confirmation was not received in ",
PUBLISH_CONFIRMATION_TIMEOUT, "seconds. Try again");
m_PublishReplyToken = 0;
Expand All @@ -512,7 +512,7 @@ void ClientDestination::HandleDataMessage(
if (dest)
dest->HandleDataMessagePayload(buf, length);
else
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientDestination: missing streaming destination");
}
break;
Expand All @@ -525,11 +525,11 @@ void ClientDestination::HandleDataMessage(
buf,
length);
else
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientDestination: missing streaming destination");
break;
default:
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"ClientDestination: HandleDataMessage(): unexpected protocol ", buf[9]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/I2PControl/I2PControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ I2PControlSession::Response I2PControlSession::HandleRequest(
std::string method = pt.get<std::string>(constants::PROPERTY_METHOD);
auto it = m_MethodHandlers.find(method);
if (it == m_MethodHandlers.end()) { // Not found
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"I2PControlSession: unknown I2PControl method ", method);
response.SetError(ErrorCode::e_MethodNotFound);
return response;
}
ptree params = pt.get_child(constants::PROPERTY_PARAMS);
if (method != constants::METHOD_AUTHENTICATE &&
!Authenticate(params, response)) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"I2PControlSession: invalid token presented");
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/I2PService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void I2PService::CreateStream(
identHash,
port);
} else {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"I2PService: remote destination ", dest, " not found");
streamRequestComplete(nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/I2PTunnel/HTTPProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void HTTPProxyHandler::HandleSockRecv(
std::size_t len) {
LogPrint(eLogDebug, "HTTPProxyHandler: sock recv: ", len);
if (ecode) {
LogPrint(eLogWarning, "HTTPProxyHandler: sock recv got error: ", ecode);
LogPrint(eLogWarn, "HTTPProxyHandler: sock recv got error: ", ecode);
Terminate();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/I2PTunnel/I2PTunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ std::unique_ptr<const i2p::data::IdentHash> I2PClientTunnel::GetIdentHash() {
if (i2p::client::context.GetAddressBook().GetIdentHash(m_Destination, identHash))
m_DestinationIdentHash = std::make_unique<i2p::data::IdentHash>(identHash);
else
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"I2PClientTunnel: remote destination ", m_Destination, " not found");
}
return std::move(m_DestinationIdentHash);
Expand Down Expand Up @@ -558,7 +558,7 @@ void I2PServerTunnel::HandleAccept(
if (stream) {
if (m_IsAccessList) {
if (!m_AccessList.count(stream->GetRemoteIdentity().GetIdentHash())) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"I2PServerTunnel: address ",
stream->GetRemoteIdentity().GetIdentHash().ToBase32(),
" is not in white list, incoming connection dropped");
Expand Down
6 changes: 3 additions & 3 deletions src/client/I2PTunnel/SOCKS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ bool SOCKSHandler::Socks5ChooseAuth() {
m_response[1] = m_authchosen; // Response code
boost::asio::const_buffers_1 response(m_response, 2);
if (m_authchosen == AUTH_UNACCEPTABLE) {
LogPrint(eLogWarning,
LogPrint(eLogWarn,
"SOCKSHandler: SOCKS5 authentication negotiation failed");
boost::asio::async_write(
*m_sock,
Expand Down Expand Up @@ -319,7 +319,7 @@ void SOCKSHandler::SocksRequestFailed(
assert(error != SOCKS4_OK && error != SOCKS5_OK);
switch (m_socksv) {
case SOCKS4:
LogPrint(eLogWarning, "SOCKSHandler: SOCKS4 failed: ", error);
LogPrint(eLogWarn, "SOCKSHandler: SOCKS4 failed: ", error);
// Transparently map SOCKS5 errors
if (error < SOCKS4_OK) error = SOCKS4_FAIL;
response = GenerateSOCKS4Response(
Expand All @@ -328,7 +328,7 @@ void SOCKSHandler::SocksRequestFailed(
m_port);
break;
case SOCKS5:
LogPrint(eLogWarning, "SOCKSHandler: SOCKS5 failed: ", error);
LogPrint(eLogWarn, "SOCKSHandler: SOCKS5 failed: ", error);
response = GenerateSOCKS5Response(
error,
m_addrtype,
Expand Down
Loading

0 comments on commit 32cc1db

Please sign in to comment.