mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
templated remoteaddress object
- eliminated {client,relay}address - better loops in new key types
This commit is contained in:
parent
a8c6673da3
commit
d8f97028b5
@ -3,118 +3,4 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
auto parse_addr_string = [](std::string_view arg, std::string_view tld) -> std::optional<std::string> {
|
||||
std::optional<std::string> ret = std::nullopt;
|
||||
|
||||
if (auto pos = arg.find_first_of('.'); pos != std::string_view::npos)
|
||||
{
|
||||
auto _prefix = arg.substr(0, pos);
|
||||
// check the pubkey prefix is the right length
|
||||
if (_prefix.length() != PUBKEYSIZE)
|
||||
return ret;
|
||||
|
||||
// verify the tld is allowed
|
||||
auto _tld = arg.substr(pos + 1);
|
||||
|
||||
if (_tld == tld and TLD::allowed.count(_tld))
|
||||
ret = _prefix;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
RemoteAddr& RemoteAddr::operator=(RemoteAddr&& other)
|
||||
{
|
||||
_pubkey = std::move(other._pubkey);
|
||||
_name = std::move(other._name);
|
||||
_tld = std::move(other._tld);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool RemoteAddr::operator<(const RemoteAddr& other) const
|
||||
{
|
||||
return std::tie(_pubkey, _name, _tld) < std::tie(other._pubkey, other._name, other._tld);
|
||||
}
|
||||
|
||||
bool RemoteAddr::operator==(const RemoteAddr& other) const
|
||||
{
|
||||
return _pubkey == other._pubkey and _name == other._name && _tld == other._tld;
|
||||
}
|
||||
|
||||
bool RemoteAddr::operator!=(const RemoteAddr& other) const
|
||||
{
|
||||
return not(*this == other);
|
||||
}
|
||||
|
||||
RelayAddress& RelayAddress::operator=(RelayAddress&& other)
|
||||
{
|
||||
_pubkey = std::move(other._pubkey);
|
||||
_name = std::move(other._name);
|
||||
_tld = std::move(other._tld);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool RelayAddress::operator<(const RelayAddress& other) const
|
||||
{
|
||||
return std::tie(_pubkey, _name, _tld) < std::tie(other._pubkey, other._name, other._tld);
|
||||
}
|
||||
|
||||
bool RelayAddress::operator==(const RelayAddress& other) const
|
||||
{
|
||||
return _pubkey == other._pubkey and _name == other._name && _tld == other._tld;
|
||||
}
|
||||
|
||||
bool RelayAddress::operator!=(const RelayAddress& other) const
|
||||
{
|
||||
return not(*this == other);
|
||||
}
|
||||
|
||||
ClientAddress& ClientAddress::operator=(ClientAddress&& other)
|
||||
{
|
||||
_pubkey = std::move(other._pubkey);
|
||||
_name = std::move(other._name);
|
||||
_tld = std::move(other._tld);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ClientAddress::operator<(const ClientAddress& other) const
|
||||
{
|
||||
return std::tie(_pubkey, _name, _tld) < std::tie(other._pubkey, other._name, other._tld);
|
||||
}
|
||||
|
||||
bool ClientAddress::operator==(const ClientAddress& other) const
|
||||
{
|
||||
return _pubkey == other._pubkey and _name == other._name && _tld == other._tld;
|
||||
}
|
||||
|
||||
bool ClientAddress::operator!=(const ClientAddress& other) const
|
||||
{
|
||||
return not(*this == other);
|
||||
}
|
||||
|
||||
bool RelayAddress::from_pubkey_addr(std::string arg)
|
||||
{
|
||||
if (auto maybe_addr = parse_addr_string(arg, TLD::RELAY))
|
||||
{
|
||||
_pubkey.from_string(*maybe_addr);
|
||||
_tld = TLD::RELAY;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClientAddress::from_pubkey_addr(std::string arg)
|
||||
{
|
||||
if (auto maybe_addr = parse_addr_string(arg, TLD::CLIENT))
|
||||
{
|
||||
_pubkey.from_string(*maybe_addr);
|
||||
_tld = TLD::CLIENT;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
{} // namespace llarp
|
||||
|
@ -1,58 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "keys.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <llarp/util/aligned.hpp>
|
||||
#include <llarp/util/fs.hpp>
|
||||
#include <llarp/util/types.hpp>
|
||||
|
||||
#include <oxen/quic.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace TLD
|
||||
template <typename pubkey_t = PubKey, std::enable_if_t<std::is_base_of_v<PubKey, pubkey_t>, int> = 0>
|
||||
struct RemoteAddress
|
||||
{
|
||||
inline constexpr auto RELAY = ".snode"sv;
|
||||
inline constexpr auto CLIENT = ".loki"sv;
|
||||
pubkey_t _pubkey;
|
||||
std::optional<std::string> _name = std::nullopt;
|
||||
std::string _tld;
|
||||
|
||||
std::set<std::string_view> allowed = {RELAY, CLIENT};
|
||||
} // namespace TLD
|
||||
RemoteAddress() = default;
|
||||
|
||||
struct RemoteAddr
|
||||
{
|
||||
public:
|
||||
RemoteAddr() = default;
|
||||
explicit RemoteAddress(std::string addr) : _name{std::move(addr)}
|
||||
{
|
||||
_pubkey.from_string(*_name);
|
||||
|
||||
explicit RemoteAddr(PublicKey pk, std::string_view tld, std::optional<std::string> n = std::nullopt)
|
||||
if constexpr (std::is_same_v<pubkey_t, ClientPubKey>)
|
||||
_tld = std::string{TLD::CLIENT};
|
||||
else if constexpr (std::is_same_v<pubkey_t, RelayPubKey>)
|
||||
_tld = std::string{TLD::RELAY};
|
||||
else
|
||||
throw std::invalid_argument{"Something seriously weird just happened."};
|
||||
}
|
||||
|
||||
explicit RemoteAddress(PubKey pk, std::string_view tld, std::optional<std::string> n = std::nullopt)
|
||||
: _pubkey{std::move(pk)}, _name{std::move(n)}, _tld{tld}
|
||||
{}
|
||||
RemoteAddr(const RemoteAddr& other) : RemoteAddr{other._pubkey, other._tld, other._name}
|
||||
RemoteAddress(const RemoteAddress& other) : RemoteAddress{other._pubkey, other._tld, other._name}
|
||||
{}
|
||||
RemoteAddr(RemoteAddr&& other)
|
||||
: RemoteAddr{std::move(other._pubkey), std::move(other._tld), std::move(other._name)}
|
||||
RemoteAddress(RemoteAddress&& other)
|
||||
: RemoteAddress{std::move(other._pubkey), std::move(other._tld), std::move(other._name)}
|
||||
{}
|
||||
RemoteAddr& operator=(const RemoteAddr& other) = default;
|
||||
RemoteAddr& operator=(RemoteAddr&& other);
|
||||
|
||||
bool operator<(const RemoteAddr& other) const;
|
||||
bool operator==(const RemoteAddr& other) const;
|
||||
bool operator!=(const RemoteAddr& other) const;
|
||||
RemoteAddress& operator=(const RemoteAddress& other) = default;
|
||||
|
||||
virtual ~RemoteAddr() = default;
|
||||
RemoteAddress& operator=(RemoteAddress&& other)
|
||||
{
|
||||
_pubkey = std::move(other._pubkey);
|
||||
_name = std::move(other._name);
|
||||
_tld = std::move(other._tld);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator<(const RemoteAddress& other) const
|
||||
{
|
||||
return std::tie(_pubkey, _name, _tld) < std::tie(other._pubkey, other._name, other._tld);
|
||||
}
|
||||
bool operator==(const RemoteAddress& other) const
|
||||
{
|
||||
return _pubkey == other._pubkey and _name == other._name && _tld == other._tld;
|
||||
}
|
||||
bool operator!=(const RemoteAddress& other) const
|
||||
{
|
||||
return not(*this == other);
|
||||
}
|
||||
|
||||
~RemoteAddress() = default;
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
return remote_name();
|
||||
}
|
||||
|
||||
protected:
|
||||
PublicKey _pubkey;
|
||||
std::optional<std::string> _name = std::nullopt;
|
||||
std::string _tld;
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return _name.value_or(_pubkey.to_string());
|
||||
@ -67,85 +86,36 @@ namespace llarp
|
||||
{
|
||||
return name() + tld();
|
||||
}
|
||||
};
|
||||
|
||||
/// This function currently assumes the remote address string is a pubkey, rather than
|
||||
/// an ONS name (TODO:)
|
||||
virtual bool from_pubkey_addr(std::string)
|
||||
/// This function currently assumes the remote address string is a pubkey, rather than
|
||||
/// an ONS name (TODO:)
|
||||
template <typename pubkey_t>
|
||||
std::optional<RemoteAddress<pubkey_t>> from_pubkey_addr(const std::string& arg)
|
||||
{
|
||||
if (auto maybe_addr = parse_addr_string(arg, TLD::CLIENT))
|
||||
{
|
||||
return true;
|
||||
return RemoteAddress<ClientPubKey>(*maybe_addr);
|
||||
}
|
||||
if (auto maybe_addr = parse_addr_string(arg, TLD::RELAY))
|
||||
{
|
||||
return RemoteAddress<RelayPubKey>(*maybe_addr);
|
||||
}
|
||||
};
|
||||
|
||||
struct RelayAddress final : public RemoteAddr
|
||||
{
|
||||
RelayAddress() = default;
|
||||
|
||||
explicit RelayAddress(RelayPubKey rpk, std::optional<std::string> n = std::nullopt)
|
||||
: RemoteAddr{std::move(rpk), TLD::RELAY, std::move(n)}
|
||||
{}
|
||||
RelayAddress(const RelayAddress& other) : RemoteAddr{other._pubkey, TLD::RELAY, other._name}
|
||||
{}
|
||||
RelayAddress(RelayAddress&& other) : RemoteAddr{std::move(other._pubkey), TLD::RELAY, std::move(other._name)}
|
||||
{}
|
||||
RelayAddress& operator=(const RelayAddress& other) = default;
|
||||
RelayAddress& operator=(RelayAddress&& other);
|
||||
|
||||
bool operator<(const RelayAddress& other) const;
|
||||
bool operator==(const RelayAddress& other) const;
|
||||
bool operator!=(const RelayAddress& other) const;
|
||||
|
||||
~RelayAddress() override = default;
|
||||
|
||||
bool from_pubkey_addr(std::string arg) override;
|
||||
};
|
||||
|
||||
struct ClientAddress final : public RemoteAddr
|
||||
{
|
||||
ClientAddress() = default;
|
||||
|
||||
explicit ClientAddress(ClientPubKey cpk, std::optional<std::string> n = std::nullopt)
|
||||
: RemoteAddr{std::move(cpk), TLD::CLIENT, std::move(n)}
|
||||
{}
|
||||
ClientAddress(const ClientAddress& other) : RemoteAddr{other._pubkey, TLD::RELAY, other._name}
|
||||
{}
|
||||
ClientAddress(ClientAddress&& other) : RemoteAddr{std::move(other._pubkey), TLD::RELAY, std::move(other._name)}
|
||||
{}
|
||||
ClientAddress& operator=(const ClientAddress& other) = default;
|
||||
ClientAddress& operator=(ClientAddress&& other);
|
||||
|
||||
bool operator<(const ClientAddress& other) const;
|
||||
bool operator==(const ClientAddress& other) const;
|
||||
bool operator!=(const ClientAddress& other) const;
|
||||
|
||||
~ClientAddress() override = default;
|
||||
|
||||
bool from_pubkey_addr(std::string arg) override;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline constexpr bool IsToStringFormattable<RemoteAddr> = true;
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool IsToStringFormattable<T, std::enable_if_t<std::is_base_of_v<RemoteAddr, T>>> = true;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
template <typename pk_t>
|
||||
inline constexpr bool IsToStringFormattable<RemoteAddress<pk_t>> = true;
|
||||
} // namespace llarp
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<llarp::RemoteAddr>
|
||||
template <typename pk_t>
|
||||
struct hash<llarp::RemoteAddress<pk_t>>
|
||||
{
|
||||
virtual size_t operator()(const llarp::RemoteAddr& r) const
|
||||
virtual size_t operator()(const llarp::RemoteAddress<pk_t>& r) const
|
||||
{
|
||||
return std::hash<std::string>{}(r.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<llarp::RelayAddress> : public hash<llarp::RemoteAddr>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct hash<llarp::ClientAddress> : public hash<llarp::RemoteAddr>
|
||||
{};
|
||||
} // namespace std
|
||||
|
@ -4,28 +4,42 @@
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
std::string PublicKey::to_string() const
|
||||
bool PubKey::from_hex(const std::string& str)
|
||||
{
|
||||
if (str.size() != 2 * size())
|
||||
return false;
|
||||
oxenc::from_hex(str.begin(), str.end(), begin());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string PubKey::to_string() const
|
||||
{
|
||||
return oxenc::to_hex(begin(), end());
|
||||
}
|
||||
|
||||
PublicKey& PublicKey::operator=(const PublicKey& other)
|
||||
PubKey& PubKey::operator=(const uint8_t* ptr)
|
||||
{
|
||||
std::copy(ptr, ptr + SIZE, begin());
|
||||
return *this;
|
||||
}
|
||||
|
||||
PubKey& PubKey::operator=(const PubKey& other)
|
||||
{
|
||||
std::memcpy(begin(), other.begin(), PUBKEYSIZE);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool PublicKey::operator<(const PublicKey& other) const
|
||||
bool PubKey::operator<(const PubKey& other) const
|
||||
{
|
||||
return as_array() < other.as_array();
|
||||
}
|
||||
|
||||
bool PublicKey::operator==(const PublicKey& other) const
|
||||
bool PubKey::operator==(const PubKey& other) const
|
||||
{
|
||||
return as_array() == other.as_array();
|
||||
}
|
||||
|
||||
bool PublicKey::operator!=(const PublicKey& other) const
|
||||
bool PubKey::operator!=(const PubKey& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
@ -10,41 +10,46 @@
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
struct PublicKey : public AlignedBuffer<PUBKEYSIZE>
|
||||
struct PubKey : public AlignedBuffer<PUBKEYSIZE>
|
||||
{
|
||||
PublicKey() = default;
|
||||
PubKey() = default;
|
||||
|
||||
bool from_hex(const std::string& str);
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
explicit PublicKey(const uint8_t* data) : AlignedBuffer<PUBKEYSIZE>{data}
|
||||
explicit PubKey(const uint8_t* data) : AlignedBuffer<PUBKEYSIZE>{data}
|
||||
{}
|
||||
explicit PublicKey(const std::array<uint8_t, PUBKEYSIZE>& data) : AlignedBuffer<PUBKEYSIZE>{data}
|
||||
explicit PubKey(const std::array<uint8_t, PUBKEYSIZE>& data) : AlignedBuffer<PUBKEYSIZE>{data}
|
||||
{}
|
||||
explicit PublicKey(ustring_view data) : AlignedBuffer<PUBKEYSIZE>{data.data()}
|
||||
explicit PubKey(ustring_view data) : AlignedBuffer<PUBKEYSIZE>{data.data()}
|
||||
{}
|
||||
explicit PublicKey(std::string_view data) : PublicKey{to_usv(data)}
|
||||
explicit PubKey(std::string_view data) : PubKey{to_usv(data)}
|
||||
{}
|
||||
PublicKey(const PublicKey& other) : PublicKey{other.data()}
|
||||
PubKey(const PubKey& other) : PubKey{other.data()}
|
||||
{}
|
||||
PublicKey(PublicKey&& other) : PublicKey{other.data()}
|
||||
PubKey(PubKey&& other) : PubKey{other.data()}
|
||||
{}
|
||||
|
||||
PublicKey& operator=(const PublicKey& other);
|
||||
PubKey& operator=(const PubKey& other);
|
||||
|
||||
bool operator<(const PublicKey& other) const;
|
||||
bool operator==(const PublicKey& other) const;
|
||||
bool operator!=(const PublicKey& other) const;
|
||||
// revisit this
|
||||
PubKey& operator=(const uint8_t* ptr);
|
||||
|
||||
bool operator<(const PubKey& other) const;
|
||||
bool operator==(const PubKey& other) const;
|
||||
bool operator!=(const PubKey& other) const;
|
||||
};
|
||||
|
||||
struct RelayPubKey final : public PublicKey
|
||||
struct RelayPubKey final : public PubKey
|
||||
{
|
||||
RelayPubKey() = delete;
|
||||
RelayPubKey() = default;
|
||||
|
||||
explicit RelayPubKey(const uint8_t* data) : PublicKey{data}
|
||||
explicit RelayPubKey(const uint8_t* data) : PubKey{data}
|
||||
{}
|
||||
explicit RelayPubKey(const std::array<uint8_t, PUBKEYSIZE>& data) : PublicKey{data}
|
||||
explicit RelayPubKey(const std::array<uint8_t, PUBKEYSIZE>& data) : PubKey{data}
|
||||
{}
|
||||
explicit RelayPubKey(ustring_view data) : PublicKey{data.data()}
|
||||
explicit RelayPubKey(ustring_view data) : PubKey{data.data()}
|
||||
{}
|
||||
explicit RelayPubKey(std::string_view data) : RelayPubKey{to_usv(data)}
|
||||
{}
|
||||
@ -60,15 +65,15 @@ namespace llarp
|
||||
bool operator!=(const RelayPubKey& other) const;
|
||||
};
|
||||
|
||||
struct ClientPubKey final : public PublicKey
|
||||
struct ClientPubKey final : public PubKey
|
||||
{
|
||||
ClientPubKey() = delete;
|
||||
ClientPubKey() = default;
|
||||
|
||||
explicit ClientPubKey(const uint8_t* data) : PublicKey{data}
|
||||
explicit ClientPubKey(const uint8_t* data) : PubKey{data}
|
||||
{}
|
||||
explicit ClientPubKey(const std::array<uint8_t, PUBKEYSIZE>& data) : PublicKey{data}
|
||||
explicit ClientPubKey(const std::array<uint8_t, PUBKEYSIZE>& data) : PubKey{data}
|
||||
{}
|
||||
explicit ClientPubKey(ustring_view data) : PublicKey{data.data()}
|
||||
explicit ClientPubKey(ustring_view data) : PubKey{data.data()}
|
||||
{}
|
||||
explicit ClientPubKey(std::string_view data) : ClientPubKey{to_usv(data)}
|
||||
{}
|
||||
@ -85,24 +90,32 @@ namespace llarp
|
||||
};
|
||||
|
||||
template <>
|
||||
inline constexpr bool IsToStringFormattable<PublicKey> = true;
|
||||
inline constexpr bool IsToStringFormattable<PubKey> = true;
|
||||
|
||||
template <typename pk_t>
|
||||
inline constexpr bool IsToStringFormattable<pk_t, std::enable_if_t<std::is_base_of_v<PublicKey, pk_t>>> = true;
|
||||
inline constexpr bool IsToStringFormattable<pk_t, std::enable_if_t<std::is_base_of_v<PubKey, pk_t>>> = true;
|
||||
|
||||
template <typename PK_t, std::enable_if_t<std::is_base_of_v<PubKey, PK_t>, int> = 0>
|
||||
PK_t make_from_hex(const std::string& str)
|
||||
{
|
||||
PK_t p;
|
||||
oxenc::from_hex(str.begin(), str.end(), p.begin());
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<llarp::PublicKey> : public hash<llarp::AlignedBuffer<PUBKEYSIZE>>
|
||||
struct hash<llarp::PubKey> : public hash<llarp::AlignedBuffer<PUBKEYSIZE>>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct hash<llarp::ClientPubKey> : public hash<llarp::PublicKey>
|
||||
struct hash<llarp::ClientPubKey> : public hash<llarp::PubKey>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct hash<llarp::RelayPubKey> : public hash<llarp::PublicKey>
|
||||
struct hash<llarp::RelayPubKey> : public hash<llarp::PubKey>
|
||||
{};
|
||||
} // namespace std
|
||||
|
@ -2,15 +2,26 @@
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
#include <llarp/crypto/constants.hpp>
|
||||
#include <llarp/util/logging.hpp>
|
||||
#include <llarp/util/types.hpp>
|
||||
|
||||
#include <charconv>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace TLD
|
||||
{
|
||||
inline constexpr auto RELAY = ".snode"sv;
|
||||
inline constexpr auto CLIENT = ".loki"sv;
|
||||
|
||||
std::set<std::string_view> allowed = {RELAY, CLIENT};
|
||||
} // namespace TLD
|
||||
|
||||
uint16_t checksum_ipv4(const void *header, uint8_t header_len);
|
||||
|
||||
uint32_t tcpudp_checksum_ipv4(uint32_t src, uint32_t dest, uint32_t len, uint8_t proto, uint32_t sum);
|
||||
@ -19,6 +30,27 @@ namespace llarp
|
||||
|
||||
uint32_t udp_checksum_ipv6(const struct in6_addr *saddr, const struct in6_addr *daddr, uint32_t len, uint32_t csum);
|
||||
|
||||
inline static std::optional<std::string> parse_addr_string(std::string_view arg, std::string_view tld)
|
||||
{
|
||||
std::optional<std::string> ret = std::nullopt;
|
||||
|
||||
if (auto pos = arg.find_first_of('.'); pos != std::string_view::npos)
|
||||
{
|
||||
auto _prefix = arg.substr(0, pos);
|
||||
// check the pubkey prefix is the right length
|
||||
if (_prefix.length() != PUBKEYSIZE)
|
||||
return ret;
|
||||
|
||||
// verify the tld is allowed
|
||||
auto _tld = arg.substr(pos);
|
||||
|
||||
if (_tld == tld and TLD::allowed.count(_tld))
|
||||
ret = _prefix;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static bool parse_int(const std::string_view str, T &value, int base = 10)
|
||||
{
|
||||
|
@ -642,7 +642,7 @@ namespace llarp
|
||||
throw std::invalid_argument{"[endpoint]:mapaddr invalid entry: {}"_format(arg)};
|
||||
}
|
||||
|
||||
ClientAddress remote;
|
||||
RemoteAddress remote;
|
||||
|
||||
if (not remote.from_pubkey_addr(arg.substr(0, pos)))
|
||||
{
|
||||
|
@ -149,9 +149,10 @@ namespace llarp
|
||||
|
||||
IPRange _local_ip_range; // rename to _local_ip_range
|
||||
std::optional<IPRange> _base_ipv6_range = std::nullopt;
|
||||
std::unordered_map<ClientAddress, oxen::quic::Address> _addr_map;
|
||||
|
||||
std::unordered_map<ClientAddress, IPRange> _range_map;
|
||||
std::unordered_map<RemoteAddress<PubKey>, oxen::quic::Address> _addr_map;
|
||||
|
||||
std::unordered_map<RemoteAddress<PubKey>, IPRange> _range_map;
|
||||
std::unordered_map<std::string, IPRange> _ons_range_map;
|
||||
|
||||
std::set<IPRange> _owned_ranges;
|
||||
|
@ -10,36 +10,36 @@
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
bool PubKey::from_hex(const std::string& str)
|
||||
{
|
||||
if (str.size() != 2 * size())
|
||||
return false;
|
||||
oxenc::from_hex(str.begin(), str.end(), begin());
|
||||
return true;
|
||||
}
|
||||
// bool PubKey::from_hex(const std::string& str)
|
||||
// {
|
||||
// if (str.size() != 2 * size())
|
||||
// return false;
|
||||
// oxenc::from_hex(str.begin(), str.end(), begin());
|
||||
// return true;
|
||||
// }
|
||||
|
||||
PubKey PubKey::make_from_hex(const std::string& s)
|
||||
{
|
||||
PubKey p;
|
||||
oxenc::from_hex(s.begin(), s.end(), p.begin());
|
||||
return p;
|
||||
}
|
||||
// PubKey PubKey::make_from_hex(const std::string& s)
|
||||
// {
|
||||
// PubKey p;
|
||||
// oxenc::from_hex(s.begin(), s.end(), p.begin());
|
||||
// return p;
|
||||
// }
|
||||
|
||||
std::string PubKey::to_string() const
|
||||
{
|
||||
return oxenc::to_hex(begin(), end());
|
||||
}
|
||||
// std::string PubKey::to_string() const
|
||||
// {
|
||||
// return oxenc::to_hex(begin(), end());
|
||||
// }
|
||||
|
||||
PubKey& PubKey::operator=(const uint8_t* ptr)
|
||||
{
|
||||
std::copy(ptr, ptr + SIZE, begin());
|
||||
return *this;
|
||||
}
|
||||
// PubKey& PubKey::operator=(const uint8_t* ptr)
|
||||
// {
|
||||
// std::copy(ptr, ptr + SIZE, begin());
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
bool operator==(const PubKey& lhs, const PubKey& rhs)
|
||||
{
|
||||
return lhs.as_array() == rhs.as_array();
|
||||
}
|
||||
// bool operator==(const PubKey& lhs, const PubKey& rhs)
|
||||
// {
|
||||
// return lhs.as_array() == rhs.as_array();
|
||||
// }
|
||||
|
||||
bool SecretKey::load_from_file(const fs::path& fname)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "constants.hpp"
|
||||
|
||||
#include <llarp/address/keys.hpp>
|
||||
#include <llarp/util/aligned.hpp>
|
||||
#include <llarp/util/fs.hpp>
|
||||
#include <llarp/util/types.hpp>
|
||||
@ -14,29 +15,29 @@ namespace llarp
|
||||
using SharedSecret = AlignedBuffer<SHAREDKEYSIZE>;
|
||||
using KeyExchangeNonce = AlignedBuffer<32>;
|
||||
|
||||
struct PubKey : public AlignedBuffer<PUBKEYSIZE>
|
||||
{
|
||||
PubKey() = default;
|
||||
// struct PubKey : public AlignedBuffer<PUBKEYSIZE>
|
||||
// {
|
||||
// PubKey() = default;
|
||||
|
||||
explicit PubKey(const uint8_t* ptr) : AlignedBuffer<SIZE>(ptr)
|
||||
{}
|
||||
// explicit PubKey(const uint8_t* ptr) : AlignedBuffer<SIZE>(ptr)
|
||||
// {}
|
||||
|
||||
explicit PubKey(const std::array<uint8_t, SIZE>& data) : AlignedBuffer<SIZE>(data)
|
||||
{}
|
||||
// explicit PubKey(const std::array<uint8_t, SIZE>& data) : AlignedBuffer<SIZE>(data)
|
||||
// {}
|
||||
|
||||
explicit PubKey(const AlignedBuffer<SIZE>& other) : AlignedBuffer<SIZE>(other)
|
||||
{}
|
||||
// explicit PubKey(const AlignedBuffer<SIZE>& other) : AlignedBuffer<SIZE>(other)
|
||||
// {}
|
||||
|
||||
std::string to_string() const;
|
||||
// std::string to_string() const;
|
||||
|
||||
bool from_hex(const std::string& str);
|
||||
// bool from_hex(const std::string& str);
|
||||
|
||||
static PubKey make_from_hex(const std::string& s);
|
||||
// static PubKey make_from_hex(const std::string& s);
|
||||
|
||||
PubKey& operator=(const uint8_t* ptr);
|
||||
};
|
||||
// PubKey& operator=(const uint8_t* ptr);
|
||||
// };
|
||||
|
||||
bool operator==(const PubKey& lhs, const PubKey& rhs);
|
||||
// bool operator==(const PubKey& lhs, const PubKey& rhs);
|
||||
|
||||
struct PrivateKey;
|
||||
|
||||
@ -121,8 +122,6 @@ namespace llarp
|
||||
bool to_pubkey(PubKey& pubkey) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline constexpr bool IsToStringFormattable<PubKey> = true;
|
||||
template <>
|
||||
inline constexpr bool IsToStringFormattable<SecretKey> = true;
|
||||
template <>
|
||||
@ -150,10 +149,3 @@ namespace llarp
|
||||
/// SH(result, body)
|
||||
using shorthash_func = bool (*)(ShortHash&, const llarp_buffer_t&);
|
||||
} // namespace llarp
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<llarp::PubKey> : hash<llarp::AlignedBuffer<llarp::PubKey::SIZE>>
|
||||
{};
|
||||
}; // namespace std
|
||||
|
@ -27,7 +27,7 @@ namespace llarp
|
||||
{
|
||||
protected:
|
||||
std::string _name;
|
||||
std::unordered_map<RemoteAddr, oxen::quic::Address> _ip_map;
|
||||
std::unordered_map<RemoteAddress<PubKey>, oxen::quic::Address> _ip_map;
|
||||
|
||||
DnsConfig _dns_config;
|
||||
NetworkConfig _net_config;
|
||||
|
@ -531,7 +531,7 @@ namespace llarp
|
||||
const auto& remote_addr = rc->addr();
|
||||
|
||||
if (auto rv = ep.establish_and_send(
|
||||
oxen::quic::RemoteAddress{router.ToView(), remote_addr},
|
||||
KeyedAddress{router.ToView(), remote_addr},
|
||||
*rc,
|
||||
std::move(endpoint),
|
||||
std::move(body),
|
||||
@ -563,7 +563,7 @@ namespace llarp
|
||||
const auto& remote_addr = rc.addr();
|
||||
|
||||
if (auto rv = ep.establish_connection(
|
||||
oxen::quic::RemoteAddress{rid.ToView(), remote_addr}, rc, std::move(on_open), std::move(on_close));
|
||||
KeyedAddress{rid.ToView(), remote_addr}, rc, std::move(on_open), std::move(on_close));
|
||||
rv)
|
||||
{
|
||||
log::info(logcat, "Begun establishing connection to {}", remote_addr);
|
||||
@ -1156,7 +1156,7 @@ namespace llarp
|
||||
|
||||
if (rc_index >= 0)
|
||||
{
|
||||
log::info(logcat, "Received PublishIntroMessage for {} (TXID: {}); we are candidate {}");
|
||||
log::info(logcat, "Received PublishIntroMessage for {}; we are candidate {}", addr, relay_order);
|
||||
|
||||
_router.contacts().put_intro(std::move(enc));
|
||||
respond(serialize_response({{messages::STATUS_KEY, ""}}));
|
||||
|
@ -38,6 +38,8 @@ namespace llarp
|
||||
|
||||
using static_secret = oxen::quic::opt::static_secret;
|
||||
|
||||
using KeyedAddress = oxen::quic::RemoteAddress;
|
||||
|
||||
inline const keep_alive ROUTER_KEEP_ALIVE{10s};
|
||||
inline const keep_alive CLIENT_KEEP_ALIVE{10s};
|
||||
|
||||
@ -95,11 +97,11 @@ namespace llarp
|
||||
size_t num_router_conns() const;
|
||||
|
||||
template <typename... Opt>
|
||||
bool establish_connection(const oxen::quic::RemoteAddress& remote, const RemoteRC& rc, Opt&&... opts);
|
||||
bool establish_connection(const KeyedAddress& remote, const RemoteRC& rc, Opt&&... opts);
|
||||
|
||||
template <typename... Opt>
|
||||
bool establish_and_send(
|
||||
const oxen::quic::RemoteAddress& remote,
|
||||
const KeyedAddress& remote,
|
||||
const RemoteRC& rc,
|
||||
std::optional<std::string> endpoint,
|
||||
std::string body,
|
||||
@ -318,9 +320,11 @@ namespace llarp
|
||||
|
||||
namespace link
|
||||
{
|
||||
static auto logcat = log::Cat("link_manager");
|
||||
|
||||
template <typename... Opt>
|
||||
bool Endpoint::establish_and_send(
|
||||
const oxen::quic::RemoteAddress& remote,
|
||||
const KeyedAddress& remote,
|
||||
const RemoteRC& rc,
|
||||
std::optional<std::string> ep,
|
||||
std::string body,
|
||||
@ -383,14 +387,14 @@ namespace llarp
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
|
||||
log::error(logcat, "Error: failed to establish connection to {}", remote);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template <typename... Opt>
|
||||
bool Endpoint::establish_connection(const oxen::quic::RemoteAddress& remote, const RemoteRC& rc, Opt&&... opts)
|
||||
bool Endpoint::establish_connection(const KeyedAddress& remote, const RemoteRC& rc, Opt&&... opts)
|
||||
{
|
||||
return link_manager.router().loop()->call_get([&]() {
|
||||
try
|
||||
@ -430,7 +434,7 @@ namespace llarp
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
log::error(quic_cat, "Error: failed to establish connection to {}", remote);
|
||||
log::error(logcat, "Error: failed to establish connection to {}", remote);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ namespace llarp::service
|
||||
introset_payload{reinterpret_cast<uint8_t*>(enc_payload.data()), enc_payload.size()},
|
||||
nonce{reinterpret_cast<uint8_t*>(nonce.data())}
|
||||
{
|
||||
derived_signing_key = PubKey::make_from_hex(signing_key);
|
||||
derived_signing_key = make_from_hex<PubKey>(signing_key);
|
||||
sig.from_string(std::move(s));
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ namespace llarp::service
|
||||
{
|
||||
oxenc::bt_dict_consumer btdc{bt_payload};
|
||||
|
||||
derived_signing_key = PubKey::make_from_hex(btdc.require<std::string>("d"));
|
||||
derived_signing_key = make_from_hex<PubKey>(btdc.require<std::string>("d"));
|
||||
nonce.from_string(btdc.require<std::string>("n"));
|
||||
signed_at = std::chrono::milliseconds{btdc.require<uint64_t>("s")};
|
||||
introset_payload = btdc.require<ustring>("x");
|
||||
|
Loading…
Reference in New Issue
Block a user