*Update types

*Remove timer
This commit is contained in:
Derrick Hammer 2022-08-21 21:42:39 -04:00
parent 564306bed2
commit afdeca0bca
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import PQueue from "p-queue";
import { ipfsPath, ipnsPath } from "is-ipfs";
import { DHT } from "@lumeweb/kernel-dht-client";
import { pack, unpack } from "msgpackr";
import { clearTimeout } from "timers";
import { DataFn } from "libskynet";
onmessage = handleMessage;
@ -18,7 +18,7 @@ interface StatFileResponse {
let blockingGatewayUpdate = Promise.resolve();
let activeRelays = [];
let activeRelays: string | any[] = [];
let relays = [
"25c2a0a833782d64213c08879b95dd5a60af244b44a058f3a7a70d6722f4bda7",
];
@ -106,7 +106,7 @@ async function handleStat(
try {
let resp = (await fetchFromRelays(hash, path, method)) as StatFileResponse;
aq.respond(resp);
} catch (e) {
} catch (e: any) {
aq.reject(e);
}
}
@ -125,7 +125,7 @@ async function handleFetch(
try {
await fetchFromRelays(hash, path, method, aq.sendUpdate);
aq.respond();
} catch (e) {
} catch (e: any) {
aq.reject(e);
}
}
@ -134,7 +134,7 @@ async function fetchFromRelays(
hash: string,
path: string,
method: string,
stream = undefined
stream: DataFn | undefined = undefined
) {
let error = new Error("NOT_FOUND");
if (0 == activeRelays.length) {
@ -168,7 +168,7 @@ async function relayHasMethods(
methodList: string[],
relay: string
): Promise<boolean> {
let methods = [];
let methods: string | string[] = [];
try {
methods = (await rpcCall(relay, "misc", "get_methods")) as [];
} catch (e) {
@ -190,7 +190,7 @@ async function rpcCall(
relay: string,
chain: string,
query: string,
stream?: (data) => void,
stream?: (data: any) => void,
data = {}
) {
const socket = await dht.connect(relay);
@ -246,7 +246,7 @@ async function refreshGatewayList() {
});
const queue = new PQueue({ concurrency: 10 });
let latencies = [];
let latencies: any[] = [];
relays.forEach((item) => {
queue.add(checkRelayLatency(item, latencies));
@ -268,10 +268,11 @@ function checkRelayLatency(relay: string, list: any[]) {
let resp;
try {
resp = await rpcCall(relay, "misc", "ping", null, {});
resp = await rpcCall(relay, "misc", "ping", undefined, {});
} catch {
return;
}
// @ts-ignore
if (!resp.pong) {
return;
}