*Add basic dns caching

This commit is contained in:
Derrick Hammer 2022-08-15 04:29:13 -04:00
parent 605a699299
commit a462edb4d8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 35 additions and 3 deletions

View File

@ -44,7 +44,8 @@
"ejs": "^3.1.8", "ejs": "^3.1.8",
"is-ipfs": "^6.0.2", "is-ipfs": "^6.0.2",
"libkernel": "https://github.com/LumeWeb/libextension.git", "libkernel": "https://github.com/LumeWeb/libextension.git",
"libskynet": "^0.0.62" "libskynet": "^0.0.62",
"node-cache": "^5.1.2"
}, },
"browser": { "browser": {
"libkmodule": false, "libkmodule": false,

View File

@ -8,8 +8,8 @@ import {
import WebEngine from "../webEngine.js"; import WebEngine from "../webEngine.js";
import { getTld, isDomain, isIp, normalizeDomain } from "../util.js"; import { getTld, isDomain, isIp, normalizeDomain } from "../util.js";
import tldEnum from "@lumeweb/tld-enum"; import tldEnum from "@lumeweb/tld-enum";
import { resolve } from "@lumeweb/kernel-dns-client";
import { getAuthStatus } from "../main/vars.js"; import { getAuthStatus } from "../main/vars.js";
import { resolve } from "../dns.js";
export default abstract class BaseProvider { export default abstract class BaseProvider {
private engine: WebEngine; private engine: WebEngine;

19
src/dns.ts Normal file
View File

@ -0,0 +1,19 @@
import NodeCache from "node-cache";
import { resolve as resolveDns } from "@lumeweb/kernel-dns-client";
const cache = new NodeCache({ stdTTL: 60 });
export async function resolve(domain: string, params: any, force = false) {
if (cache.has(domain)) {
cache.ttl(domain);
return cache.get(domain);
}
let res = await resolveDns(domain, params, force);
if (res) {
cache.set(domain, res);
}
return res;
}

View File

@ -13,7 +13,7 @@ import {
} from "./types"; } from "./types";
import { getTld, isDomain, isIp, normalizeDomain } from "./util.js"; import { getTld, isDomain, isIp, normalizeDomain } from "./util.js";
import tldEnum from "@lumeweb/tld-enum"; import tldEnum from "@lumeweb/tld-enum";
import { resolve } from "@lumeweb/kernel-dns-client"; import { resolve } from "./dns.js";
import { blake2b, bufToHex } from "libskynet"; import { blake2b, bufToHex } from "libskynet";
import { getAuthStatus } from "./main/vars.js"; import { getAuthStatus } from "./main/vars.js";

View File

@ -453,6 +453,11 @@ clean-stack@^4.0.0:
dependencies: dependencies:
escape-string-regexp "5.0.0" escape-string-regexp "5.0.0"
clone@2.x:
version "2.1.2"
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==
clone@~0.1.9: clone@~0.1.9:
version "0.1.19" version "0.1.19"
resolved "https://registry.yarnpkg.com/clone/-/clone-0.1.19.tgz#613fb68639b26a494ac53253e15b1a6bd88ada85" resolved "https://registry.yarnpkg.com/clone/-/clone-0.1.19.tgz#613fb68639b26a494ac53253e15b1a6bd88ada85"
@ -1794,6 +1799,13 @@ nested-error-stacks@^2.0.0, nested-error-stacks@^2.1.0:
resolved "https://registry.yarnpkg.com/nested-error-stacks/-/nested-error-stacks-2.1.1.tgz#26c8a3cee6cc05fbcf1e333cd2fc3e003326c0b5" resolved "https://registry.yarnpkg.com/nested-error-stacks/-/nested-error-stacks-2.1.1.tgz#26c8a3cee6cc05fbcf1e333cd2fc3e003326c0b5"
integrity sha512-9iN1ka/9zmX1ZvLV9ewJYEk9h7RyRRtqdK0woXcqohu8EWIerfPUjYJPg0ULy0UqP7cslmdGc8xKDJcojlKiaw== integrity sha512-9iN1ka/9zmX1ZvLV9ewJYEk9h7RyRRtqdK0woXcqohu8EWIerfPUjYJPg0ULy0UqP7cslmdGc8xKDJcojlKiaw==
node-cache@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-5.1.2.tgz#f264dc2ccad0a780e76253a694e9fd0ed19c398d"
integrity sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==
dependencies:
clone "2.x"
normalize-package-data@^3.0.2: normalize-package-data@^3.0.2:
version "3.0.3" version "3.0.3"
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-3.0.3.tgz#dbcc3e2da59509a0983422884cd172eefdfa525e" resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-3.0.3.tgz#dbcc3e2da59509a0983422884cd172eefdfa525e"