From 480bfdd0d013055419ec15ad1589d164bc6a420f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 18 Dec 2022 14:44:39 -0500 Subject: [PATCH] *Remove dns module for now, will refactor this back later --- src/index.ts | 2 -- src/modules/dns.ts | 58 ---------------------------------------------- 2 files changed, 60 deletions(-) delete mode 100644 src/modules/dns.ts diff --git a/src/index.ts b/src/index.ts index abcd99a..a2a7760 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,6 @@ import { start as startApp } from "./modules/app"; import log from "loglevel"; import config from "./config.js"; import { loadPlugins } from "./modules/plugin.js"; -import { start as startDns } from "./modules/dns.js"; import { start as startSSl } from "./modules/ssl.js"; import { start as startSwarm } from "./modules/swarm.js"; import * as bip39 from "@scure/bip39"; @@ -23,7 +22,6 @@ async function boot() { await loadPlugins(); await startApp(); await startRpc(); - await startDns(); await startSSl(); await startRelay(); } diff --git a/src/modules/dns.ts b/src/modules/dns.ts deleted file mode 100644 index 4bc5b0d..0000000 --- a/src/modules/dns.ts +++ /dev/null @@ -1,58 +0,0 @@ -import cron from "node-cron"; -import { get as getSwarm } from "./swarm.js"; -import { Buffer } from "buffer"; -import { pack } from "msgpackr"; -import config from "../config.js"; -import log from "loglevel"; -import fetch from "node-fetch"; -import { overwriteRegistryEntry } from "libskynetnode"; -import type { DnsProvider } from "@lumeweb/relay-types"; -// @ts-ignore -import { hashDataKey } from "@lumeweb/kernel-utils"; - -let activeIp: string; -const REGISTRY_NODE_KEY = "lumeweb-dht-node"; - -let dnsProvider: DnsProvider = async (ip) => {}; - -export function setDnsProvider(provider: DnsProvider) { - dnsProvider = provider; -} - -async function ipUpdate() { - let currentIp = await getCurrentIp(); - - if (activeIp && currentIp === activeIp) { - return; - } - - const domain = config.str("domain"); - - await dnsProvider(currentIp, domain); - - activeIp = currentIp; - - log.info(`Updated DynDNS hostname ${domain} to ${activeIp}`); -} - -export async function start() { - if (!config.str("domain")) { - return; - } - - const swarm = getSwarm(); - - await ipUpdate(); - - await overwriteRegistryEntry( - swarm.dht.defaultKeyPair, - hashDataKey(REGISTRY_NODE_KEY), - pack(`${config.str("domain")}:${config.uint("port")}`) - ); - - cron.schedule("0 * * * *", ipUpdate); -} - -async function getCurrentIp(): Promise { - return await (await fetch("http://ip1.dynupdate.no-ip.com/")).text(); -}