handle .loki directory, leave .loki namespace

This commit is contained in:
Sean Darcy 2021-01-06 17:04:17 +11:00
parent ed0eb9dc97
commit 2e2fd28a2e
4 changed files with 32 additions and 15 deletions

View file

@ -274,6 +274,10 @@ namespace tools {
{
return get_special_folder_path(CSIDL_COMMON_APPDATA, true) / fs::u8path(CRYPTONOTE_NAME);
}
fs::path get_depreciated_default_data_dir()
{
return get_special_folder_path(CSIDL_COMMON_APPDATA, true) / fs::u8path("loki");
}
#else
// Non-windows: ~/.CRYPTONOTE_NAME
fs::path get_default_data_dir()
@ -281,6 +285,11 @@ namespace tools {
char* home = std::getenv("HOME");
return (home && std::strlen(home) ? fs::u8path(home) : fs::current_path()) / fs::u8path("." CRYPTONOTE_NAME);
}
fs::path get_depreciated_default_data_dir()
{
char* home = std::getenv("HOME");
return (home && std::strlen(home) ? fs::u8path(home) : fs::current_path()) / fs::u8path(".loki");
}
#endif
bool create_directories_if_necessary(const fs::path& path)
@ -291,6 +300,14 @@ namespace tools {
return true;
}
fs::path depreciated_path = get_depreciated_default_data_dir();
if (fs::is_directory(depreciated_path, ec))
{
fs::rename(depreciated_path, path);
fs::create_directory_symlink(depreciated_path, path);
return true;
}
bool res = fs::create_directories(path, ec);
if (res)
{

View file

@ -782,27 +782,27 @@ bool validate_lns_name(mapping_type type, std::string name, std::string *reason)
// Reserved names:
// - localhost.oxen has special meaning within lokinet (it is always a CNAME to the local
// address)
// - oxen.oxen and snode.oxen are prohibited in case someone added .oxen or .snode as search
// domains (in which case the user looking up "foo.oxen" would try end up trying to resolve
// "foo.oxen.oxen").
for (auto& reserved : {"localhost.oxen"sv, "oxen.oxen"sv, "snode.oxen"sv})
// - loki.loki and snode.oxen are prohibited in case someone added .loki or .snode as search
// domains (in which case the user looking up "foo.loki" would try end up trying to resolve
// "foo.loki.loki").
for (auto& reserved : {"localhost.loki"sv, "loki.loki"sv, "snode.loki"sv})
if (check_condition(name == reserved, reason, "LNS type=", type, ", specifies mapping from name->value using protocol reserved name=", name))
return false;
auto constexpr SHORTEST_DOMAIN = "a.oxen"sv;
auto constexpr SHORTEST_DOMAIN = "a.loki"sv;
if (check_condition(name.size() < SHORTEST_DOMAIN.size(), reason, "LNS type=", type, ", specifies mapping from name->value where the name is shorter than the shortest possible name=", SHORTEST_DOMAIN, ", given name=", name))
return false;
// Must end with .oxen
auto constexpr SUFFIX = ".oxen"sv;
if (check_condition(!tools::ends_with(name_view, SUFFIX), reason, "LNS type=", type, ", specifies mapping from name->value where the name does not end with the domain .oxen, name=", name))
// Must end with .loki
auto constexpr SUFFIX = ".loki"sv;
if (check_condition(!tools::ends_with(name_view, SUFFIX), reason, "LNS type=", type, ", specifies mapping from name->value where the name does not end with the domain .loki, name=", name))
return false;
name_view.remove_suffix(SUFFIX.size());
// All domains containing '--' as 3rd/4th letter are reserved except for xn-- punycode domains
if (check_condition(name_view.size() >= 4 && name_view.substr(2, 2) == "--"sv && !tools::starts_with(name_view, "xn--"sv),
reason, "LNS type=", type, ", specifies reserved name `?\?--*.oxen': ", name))
reason, "LNS type=", type, ", specifies reserved name `?\?--*.loki': ", name))
return false;
// Must start with alphanumeric
@ -812,8 +812,8 @@ bool validate_lns_name(mapping_type type, std::string name, std::string *reason)
name_view.remove_prefix(1);
if (!name_view.empty()) {
// Character preceding .oxen must be alphanumeric
if (check_condition(!char_is_alphanum(name_view.back()), reason, "LNS type=", type ,", specifies mapping from name->value where the character preceding the .oxen is not alphanumeric, char=", name_view.back(), ", name=", name))
// Character preceding .loki must be alphanumeric
if (check_condition(!char_is_alphanum(name_view.back()), reason, "LNS type=", type ,", specifies mapping from name->value where the character preceding the .loki is not alphanumeric, char=", name_view.back(), ", name=", name))
return false;
name_view.remove_suffix(1);
}

View file

@ -28,8 +28,8 @@ namespace lns
constexpr size_t WALLET_NAME_MAX = 97; // mainnet addresses are 95 but testnet/devnet are 97
constexpr size_t WALLET_ACCOUNT_BINARY_LENGTH = 2 * sizeof(crypto::public_key);
constexpr size_t LOKINET_DOMAIN_NAME_MAX = 63 + 5; // DNS components name must be at most 63 (+ 5 for .oxen); this limit applies if there is at least one hyphen (and thus includes punycode)
constexpr size_t LOKINET_DOMAIN_NAME_MAX_NOHYPHEN = 32 + 5; // If the name does not contain a - then we restrict it to 32 characters so that it cannot be (and is obviously not) an encoded .oxen address (52 characters)
constexpr size_t LOKINET_DOMAIN_NAME_MAX = 63 + 5; // DNS components name must be at most 63 (+ 5 for .loki); this limit applies if there is at least one hyphen (and thus includes punycode)
constexpr size_t LOKINET_DOMAIN_NAME_MAX_NOHYPHEN = 32 + 5; // If the name does not contain a - then we restrict it to 32 characters so that it cannot be (and is obviously not) an encoded .loki address (52 characters)
constexpr size_t LOKINET_ADDRESS_BINARY_LENGTH = sizeof(crypto::ed25519_public_key);
constexpr size_t SESSION_DISPLAY_NAME_MAX = 64;
constexpr size_t SESSION_PUBLIC_KEY_BINARY_LENGTH = 1 + sizeof(crypto::ed25519_public_key); // Session keys at prefixed with 0x05 + ed25519 key

View file

@ -6426,9 +6426,9 @@ static std::optional<lns::mapping_type> guess_lns_type(tools::wallet2& wallet, s
{
if (typestr.empty())
{
if (tools::ends_with(name, ".oxen") && (tools::ends_with(value, ".oxen") || value.empty()))
if (tools::ends_with(name, ".loki") && (tools::ends_with(value, ".loki") || value.empty()))
return lns::mapping_type::lokinet;
if (!tools::ends_with(name, ".oxen") && tools::starts_with(value, "05") && value.length() == 2*lns::SESSION_PUBLIC_KEY_BINARY_LENGTH)
if (!tools::ends_with(name, ".loki") && tools::starts_with(value, "05") && value.length() == 2*lns::SESSION_PUBLIC_KEY_BINARY_LENGTH)
return lns::mapping_type::session;
fail_msg_writer() << tr("Could not infer LNS type from name/value; trying using the type= argument or see `help' for more details");