mirror of
https://github.com/logos-storage/logos-storage-marketplace-ui.git
synced 2026-01-07 16:03:06 +00:00
Use announce address to check the TCP port
This commit is contained in:
parent
37592fcdd5
commit
602516436a
@ -1,8 +1,14 @@
|
||||
import { CodexDebugInfo, SafeValue, CodexError } from "@codex-storage/sdk-js"
|
||||
|
||||
export const PortForwardingUtil = {
|
||||
check: (port: number) => fetch(import.meta.env.VITE_GEO_IP_URL + "/port/" + port)
|
||||
.then((res) => res.json()),
|
||||
check: ([ip, port]: [string, number]) => {
|
||||
const headers = {
|
||||
"X-Real-IP-Custom": ip
|
||||
}
|
||||
|
||||
return fetch(import.meta.env.VITE_GEO_IP_URL + "/port/" + port, { headers })
|
||||
.then((res) => res.json())
|
||||
},
|
||||
|
||||
getTcpPort(info: CodexDebugInfo): SafeValue<number> {
|
||||
if (info.addrs.length === 0) {
|
||||
|
||||
@ -2,6 +2,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { Errors } from "../utils/errors";
|
||||
import { CodexDebugInfo } from "@codex-storage/sdk-js";
|
||||
import { PortForwardingUtil } from "./port-forwarding.util";
|
||||
import { HealthCheckUtils } from "../components/HealthChecks/health-check.utils";
|
||||
|
||||
type PortForwardingResponse = { reachable: boolean };
|
||||
|
||||
@ -9,12 +10,21 @@ export function usePortForwarding(info: CodexDebugInfo | undefined) {
|
||||
const { data, isFetching, refetch } = useQuery({
|
||||
queryFn: (): Promise<PortForwardingResponse> => {
|
||||
const port = PortForwardingUtil.getTcpPort(info!);
|
||||
|
||||
if (port.error) {
|
||||
Errors.report(port);
|
||||
return Promise.resolve({ reachable: false });
|
||||
} else {
|
||||
return PortForwardingUtil.check(port.data).catch((e) =>
|
||||
Errors.report(e)
|
||||
const ip = HealthCheckUtils.extractAnnounceAddresses(
|
||||
info!.announceAddresses
|
||||
);
|
||||
if (ip.error) {
|
||||
Errors.report(ip);
|
||||
return Promise.resolve({ reachable: false });
|
||||
}
|
||||
|
||||
return PortForwardingUtil.check([ip.data, port.data]).catch(
|
||||
Errors.report
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user