From 84bd5544ccfd677f9041e68b5707175af3937826 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Mon, 13 Apr 2020 13:03:19 -0300 Subject: [PATCH] Move pubkey_set into auth.h header This allows it to be brought in without the full lokimq.h header. --- lokimq/auth.h | 23 +++++++++++++++++++++++ lokimq/connections.h | 15 +-------------- lokimq/lokimq.h | 8 -------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lokimq/auth.h b/lokimq/auth.h index c47a5b8..5aa68cc 100644 --- a/lokimq/auth.h +++ b/lokimq/auth.h @@ -1,5 +1,8 @@ #pragma once #include +#include +#include +#include namespace lokimq { @@ -29,4 +32,24 @@ struct Access { : auth{auth}, remote_sn{remote_sn}, local_sn{local_sn} {} }; +/// Simple hash implementation for a string that is *already* a hash-like value (such as a pubkey). +/// Falls back to std::hash if given a string smaller than a size_t. +struct already_hashed { + size_t operator()(const std::string& s) const { + if (s.size() < sizeof(size_t)) + return std::hash{}(s); + size_t hash; + std::memcpy(&hash, &s[0], sizeof(hash)); + return hash; + } +}; + +/// std::unordered_set specialization for specifying pubkeys (used, in particular, by +/// LokiMQ::set_active_sns and LokiMQ::update_active_sns); this is a std::string unordered_set that +/// also uses a specialized trivial hash function that uses part of the value itself (i.e. the +/// pubkey) directly as a hash value. (This is nice and fast for uniformly distributed values like +/// pubkeys and a terrible hash choice for anything else). +using pubkey_set = std::unordered_set; + + } diff --git a/lokimq/connections.h b/lokimq/connections.h index 680094b..dff3631 100644 --- a/lokimq/connections.h +++ b/lokimq/connections.h @@ -1,6 +1,6 @@ #pragma once +#include "auth.h" #include "string_view.h" -#include namespace lokimq { @@ -72,19 +72,6 @@ private: friend std::ostream& operator<<(std::ostream& o, const ConnectionID& conn); }; -/// Simple hash implementation for a string that is *already* a hash-like value (such as a pubkey). -/// Falls back to std::hash if given a string smaller than a size_t. -struct already_hashed { - size_t operator()(const std::string& s) const { - if (s.size() < sizeof(size_t)) - return std::hash{}(s); - size_t hash; - std::memcpy(&hash, &s[0], sizeof(hash)); - return hash; - } -}; - - } // namespace lokimq namespace std { template <> struct hash { diff --git a/lokimq/lokimq.h b/lokimq/lokimq.h index 2890246..17a0ad4 100644 --- a/lokimq/lokimq.h +++ b/lokimq/lokimq.h @@ -86,14 +86,6 @@ static constexpr size_t MAX_COMMAND_LENGTH = 200; class CatHelper; -/// std::unordered_set specialization for specifying pubkeys (used, in particular, by -/// LokiMQ::set_active_sns and LokiMQ::update_active_sns); this is a std::string unordered_set that -/// also uses a specialized trivial hash function that uses part of the value itself (i.e. the -/// pubkey) directly as a hash value. (This is nice and fast for uniformly distributed values like -/// pubkeys and a terrible hash choice for anything else). -using pubkey_set = std::unordered_set; - - /** * Class that handles LokiMQ listeners, connections, proxying, and workers. An application * typically has just one instance of this class.