Skip to content

Commit 34d0046

Browse files
committed
Improve the reachability check
Node is *unreachable* if any of the following is true - tls is false, - port is empty, - host is empty, - host is an ip address (either v4 or v6).
1 parent dda52f4 commit 34d0046

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/shared/stores/operatorReachability.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ const useOperatorReachabilityStore = create<{
7474
try {
7575
reachable = await new Promise<boolean>((resolve) => {
7676
/**
77-
* Replace the following with a real connectivity
78-
* checking logic.
77+
* @todo Attempt the wss connections to the declared endpoints
78+
* for verification.
7979
*/
80-
resolve(!!url)
80+
resolve(tls && !!port && !!host && !isIPAddress(host))
8181
})
8282
} finally {
8383
ws?.close()
@@ -152,3 +152,13 @@ export function useIsNodeIdReachable(nodeId: string) {
152152

153153
return pending ? 'pending' : reachable
154154
}
155+
156+
const IPv4RegExp =
157+
/^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)){3}$/
158+
159+
const IPv6RegExp =
160+
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4}:){1,7}:|:([0-9a-fA-F]{1,4}:){1,7}|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4})$/
161+
162+
function isIPAddress(value: string): boolean {
163+
return IPv4RegExp.test(value) || IPv6RegExp.test(value)
164+
}

0 commit comments

Comments
 (0)