*update ipfs and skynet provider to use the available dht relays as status proxies

This commit is contained in:
Derrick Hammer 2022-08-14 08:19:45 -04:00
parent fc0ca7d847
commit 5be2d72d48
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 31 additions and 6 deletions

View File

@ -10,7 +10,7 @@
"eslint": "eslint src --fix", "eslint": "eslint src --fix",
"lint": "npm run deps && npm run prettier && npm run eslint", "lint": "npm run deps && npm run prettier && npm run eslint",
"compile": "node build.js", "compile": "node build.js",
"build": "npm run compile && rimraf node_modules/@lumeweb/kernel-dns-client/node_modules && rimraf node_modules/@lumeweb/kernel-ipfs-client/node_modules && cpy \"assets/*\" dist" "build": "rimraf node_modules/@lumeweb/kernel-dns-client/node_modules node_modules/@lumeweb/kernel-dht-client/node_modules node_modules/@lumeweb/kernel-ipfs-client/node_modules && npm run compile && cpy \"assets/*\" dist"
}, },
"author": "David Vorick", "author": "David Vorick",
"license": "MIT", "license": "MIT",
@ -38,6 +38,7 @@
"webextension-polyfill": "^0.9.0" "webextension-polyfill": "^0.9.0"
}, },
"dependencies": { "dependencies": {
"@lumeweb/kernel-dht-client": "https://github.com/LumeWeb/kernel-dht-client.git",
"@lumeweb/kernel-ipfs-client": "https://github.com/LumeWeb/kernel-ipfs-client.git", "@lumeweb/kernel-ipfs-client": "https://github.com/LumeWeb/kernel-ipfs-client.git",
"@lumeweb/tld-enum": "https://github.com/LumeWeb/list-of-top-level-domains.git", "@lumeweb/tld-enum": "https://github.com/LumeWeb/list-of-top-level-domains.git",
"ejs": "^3.1.8", "ejs": "^3.1.8",

View File

@ -7,7 +7,7 @@ import {
OnRequestDetailsType, OnRequestDetailsType,
StreamFilter, StreamFilter,
} from "../types.js"; } from "../types.js";
import { requestProxies } from "../util.js"; import { getRelayProxies } from "../util.js";
import browser from "@lumeweb/webextension-polyfill"; import browser from "@lumeweb/webextension-polyfill";
import { ipfsPath, ipnsPath, path } from "is-ipfs"; import { ipfsPath, ipnsPath, path } from "is-ipfs";
import { import {
@ -105,7 +105,7 @@ export default class IpfsProvider extends BaseProvider {
} }
async handleProxy(details: OnRequestDetailsType): Promise<any> { async handleProxy(details: OnRequestDetailsType): Promise<any> {
return requestProxies; return getRelayProxies();
} }
async handleReqHeaders( async handleReqHeaders(

View File

@ -7,7 +7,7 @@ import {
OnRequestDetailsType, OnRequestDetailsType,
} from "../types.js"; } from "../types.js";
import { validSkylink } from "libskynet"; import { validSkylink } from "libskynet";
import { downloadSkylink, requestProxies } from "../util.js"; import { downloadSkylink, getRelayProxies } from "../util.js";
import browser from "@lumeweb/webextension-polyfill"; import browser from "@lumeweb/webextension-polyfill";
export default class SkynetProvider extends BaseProvider { export default class SkynetProvider extends BaseProvider {
@ -24,7 +24,7 @@ export default class SkynetProvider extends BaseProvider {
} }
async handleProxy(details: OnRequestDetailsType): Promise<any> { async handleProxy(details: OnRequestDetailsType): Promise<any> {
return requestProxies; return getRelayProxies();
} }
async handleRequest( async handleRequest(

View File

@ -9,6 +9,9 @@ import {
validSkylink, validSkylink,
verifyDownloadResponse, verifyDownloadResponse,
} from "libskynet"; } from "libskynet";
import { DHT } from "@lumeweb/kernel-dht-client";
const relayDht = new DHT();
export function isIp(ip: string) { export function isIp(ip: string) {
return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test( return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
@ -26,6 +29,17 @@ export function normalizeDomain(domain: string): string {
return domain.replace(/^\.+|\.+$/g, "").replace(/^\/+|\/+$/g, ""); return domain.replace(/^\.+|\.+$/g, "").replace(/^\/+|\/+$/g, "");
} }
export async function getRelayProxies() {
let relays: string[] = await relayDht.getRelayServers();
let proxies = [{ type: "http", host: "localhost", port: 25252 }];
for (const relay of relays) {
proxies.push({ type: "http", host: new URL(relay).hostname, port: 25252 });
}
return proxies;
}
export const requestProxies = [ export const requestProxies = [
{ type: "http", host: "localhost", port: 25252 }, { type: "http", host: "localhost", port: 25252 },
{ type: "http", host: "web3portal.com", port: 80 }, { type: "http", host: "web3portal.com", port: 80 },

View File

@ -52,9 +52,19 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
"@lumeweb/kernel-dht-client@https://github.com/LumeWeb/kernel-dht-client.git":
version "0.1.0"
resolved "https://github.com/LumeWeb/kernel-dht-client.git#4799cf4a989afd2ef63a38abd5fbff250576885b"
dependencies:
buffer "^6.0.3"
events "^3.3.0"
libkernel "^0.1.43"
libkmodule "^0.2.44"
libskynet "^0.0.62"
"@lumeweb/kernel-dns-client@https://github.com/LumeWeb/kernel-dns-client.git": "@lumeweb/kernel-dns-client@https://github.com/LumeWeb/kernel-dns-client.git":
version "0.1.0" version "0.1.0"
resolved "https://github.com/LumeWeb/kernel-dns-client.git#ac9cc4cf0dc58a5047a7b0c3bcc70705f51ae65f" resolved "https://github.com/LumeWeb/kernel-dns-client.git#1ba24bee76ab7f746252a21fc48d34044924feb8"
dependencies: dependencies:
buffer "^6.0.3" buffer "^6.0.3"
libkernel "^0.1.43" libkernel "^0.1.43"