aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/src')
-rw-r--r--contrib/epee/src/CMakeLists.txt4
-rw-r--r--contrib/epee/src/mlog.cpp44
-rw-r--r--contrib/epee/src/net_utils_base.cpp60
3 files changed, 102 insertions, 6 deletions
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index c61a6e684..294515f83 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -27,9 +27,9 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if (USE_READLINE AND GNU_READLINE_FOUND)
- add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp string_tools.cpp readline_buffer.cpp)
+ add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp readline_buffer.cpp)
else()
- add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp string_tools.cpp)
+ add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp)
endif()
# Build and install libepee if we're building for GUI
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index 964ba41df..cfb2b7b15 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -144,16 +144,52 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s
void mlog_set_categories(const char *categories)
{
- el::Loggers::setCategories(categories);
- MLOG_LOG("New log categories: " << categories);
+ std::string new_categories;
+ if (*categories)
+ {
+ if (*categories == '+')
+ {
+ ++categories;
+ new_categories = mlog_get_categories();
+ if (*categories)
+ {
+ if (!new_categories.empty())
+ new_categories += ",";
+ new_categories += categories;
+ }
+ }
+ else if (*categories == '-')
+ {
+ ++categories;
+ new_categories = mlog_get_categories();
+ std::vector<std::string> single_categories;
+ boost::split(single_categories, categories, boost::is_any_of(","), boost::token_compress_on);
+ for (const std::string &s: single_categories)
+ {
+ size_t pos = new_categories.find(s);
+ if (pos != std::string::npos)
+ new_categories = new_categories.erase(pos, s.size());
+ }
+ }
+ else
+ {
+ new_categories = categories;
+ }
+ }
+ el::Loggers::setCategories(new_categories.c_str(), true);
+ MLOG_LOG("New log categories: " << el::Loggers::getCategories());
+}
+
+std::string mlog_get_categories()
+{
+ return el::Loggers::getCategories();
}
// maps epee style log level to new logging system
void mlog_set_log_level(int level)
{
const char *categories = get_default_categories(level);
- el::Loggers::setCategories(categories);
- MLOG_LOG("New log categories: " << categories);
+ mlog_set_categories(categories);
}
void mlog_set_log(const char *log)
diff --git a/contrib/epee/src/net_utils_base.cpp b/contrib/epee/src/net_utils_base.cpp
new file mode 100644
index 000000000..22afcf819
--- /dev/null
+++ b/contrib/epee/src/net_utils_base.cpp
@@ -0,0 +1,60 @@
+
+#include "net/net_utils_base.h"
+
+#include <cstring>
+#include <typeindex>
+#include "net/local_ip.h"
+
+namespace epee { namespace net_utils
+{
+ const uint8_t ipv4_network_address::ID;
+
+ bool ipv4_network_address::equal(const ipv4_network_address& other) const noexcept
+ { return is_same_host(other) && port() == other.port(); }
+
+ bool ipv4_network_address::less(const ipv4_network_address& other) const noexcept
+ { return is_same_host(other) ? port() < other.port() : ip() < other.ip(); }
+
+ std::string ipv4_network_address::str() const
+ { return string_tools::get_ip_string_from_int32(ip()) + ":" + std::to_string(port()); }
+
+ std::string ipv4_network_address::host_str() const { return string_tools::get_ip_string_from_int32(ip()); }
+ bool ipv4_network_address::is_loopback() const { return net_utils::is_ip_loopback(ip()); }
+ bool ipv4_network_address::is_local() const { return net_utils::is_ip_local(ip()); }
+
+
+ bool network_address::equal(const network_address& other) const
+ {
+ // clang typeid workaround
+ network_address::interface const* const self_ = self.get();
+ network_address::interface const* const other_self = other.self.get();
+ if (self_ == other_self) return true;
+ if (!self_ || !other_self) return false;
+ if (typeid(*self_) != typeid(*other_self)) return false;
+ return self_->equal(*other_self);
+ }
+
+ bool network_address::less(const network_address& other) const
+ {
+ // clang typeid workaround
+ network_address::interface const* const self_ = self.get();
+ network_address::interface const* const other_self = other.self.get();
+ if (self_ == other_self) return false;
+ if (!self_ || !other_self) return self == nullptr;
+ if (typeid(*self_) != typeid(*other_self))
+ return self_->get_type_id() < other_self->get_type_id();
+ return self_->less(*other_self);
+ }
+
+ bool network_address::is_same_host(const network_address& other) const
+ {
+ // clang typeid workaround
+ network_address::interface const* const self_ = self.get();
+ network_address::interface const* const other_self = other.self.get();
+ if (self_ == other_self) return true;
+ if (!self_ || !other_self) return false;
+ if (typeid(*self_) != typeid(*other_self)) return false;
+ return self_->is_same_host(*other_self);
+ }
+}}
+