socket-function 1.2.12 → 1.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/CallFactory.ts +2 -2
- package/src/misc.d.ts +1 -0
- package/src/misc.ts +17 -0
- package/src/protocolNegotiation.ts +6 -0
package/index.d.ts
CHANGED
|
@@ -1149,6 +1149,7 @@ declare module "socket-function/src/misc" {
|
|
|
1149
1149
|
export declare function watchSlowPromise<T>(title: string, promise: Promise<T>, config?: {
|
|
1150
1150
|
interval?: number;
|
|
1151
1151
|
}): Promise<T>;
|
|
1152
|
+
export declare function isIpDomain(nodeIdOrHost: string): boolean;
|
|
1152
1153
|
|
|
1153
1154
|
}
|
|
1154
1155
|
|
package/package.json
CHANGED
package/src/CallFactory.ts
CHANGED
|
@@ -488,7 +488,7 @@ export async function createCallFactory(
|
|
|
488
488
|
let alternates = await SocketFunction.GET_ALTERNATE_NODE_IDS(nodeId);
|
|
489
489
|
if (alternates) {
|
|
490
490
|
for (let alternateNodeId of alternates) {
|
|
491
|
-
let newWebSocket = createWebsocket(alternateNodeId, proposeProtocols(
|
|
491
|
+
let newWebSocket = createWebsocket(alternateNodeId, proposeProtocols(nodeId, { lz4: true }));
|
|
492
492
|
await initializeWebsocket(newWebSocket, true);
|
|
493
493
|
|
|
494
494
|
if (callFactory.isConnected) {
|
|
@@ -500,7 +500,7 @@ export async function createCallFactory(
|
|
|
500
500
|
console.error("Error getting alternate node IDs", e);
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
-
let newWebSocket = createWebsocket(nodeId, proposeProtocols(
|
|
503
|
+
let newWebSocket = createWebsocket(nodeId, proposeProtocols(nodeId, { lz4: true }));
|
|
504
504
|
await initializeWebsocket(newWebSocket);
|
|
505
505
|
|
|
506
506
|
return newWebSocket;
|
package/src/misc.d.ts
CHANGED
|
@@ -98,3 +98,4 @@ export declare function errorToWarning<T>(promise: Promise<T>): void;
|
|
|
98
98
|
export declare function watchSlowPromise<T>(title: string, promise: Promise<T>, config?: {
|
|
99
99
|
interval?: number;
|
|
100
100
|
}): Promise<T>;
|
|
101
|
+
export declare function isIpDomain(nodeIdOrHost: string): boolean;
|
package/src/misc.ts
CHANGED
|
@@ -476,4 +476,21 @@ export function watchSlowPromise<T>(title: string, promise: Promise<T>, config?:
|
|
|
476
476
|
}
|
|
477
477
|
})();
|
|
478
478
|
return promise;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// An ip domain (127-0-0-1.example.com, or a raw ip) is an address alias for a machine, not a node identity — a server's real nodeId will never equal it.
|
|
482
|
+
export function isIpDomain(nodeIdOrHost: string): boolean {
|
|
483
|
+
let host = nodeIdOrHost.split(":")[0];
|
|
484
|
+
return isIpParts(host.split(".")[0].split("-")) || isIpParts(host.split("."));
|
|
485
|
+
}
|
|
486
|
+
function isIpParts(parts: string[]): boolean {
|
|
487
|
+
if (parts.length !== 4) return false;
|
|
488
|
+
for (let part of parts) {
|
|
489
|
+
if (!part || part.length > 3) return false;
|
|
490
|
+
for (let char of part) {
|
|
491
|
+
if (char < "0" || char > "9") return false;
|
|
492
|
+
}
|
|
493
|
+
if (parseInt(part) > 255) return false;
|
|
494
|
+
}
|
|
495
|
+
return true;
|
|
479
496
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// the server returns no protocol and the handshake fails — which is exactly the
|
|
6
6
|
// rejection semantics we want (indistinguishable from "node not reachable").
|
|
7
7
|
|
|
8
|
+
import { isIpDomain } from "./misc";
|
|
9
|
+
|
|
8
10
|
const PROTOCOL_VERSION = "v1";
|
|
9
11
|
|
|
10
12
|
export type ConnectionFlags = {
|
|
@@ -70,6 +72,10 @@ export function decodeProtocol(hex: string): DecodedProtocol | undefined {
|
|
|
70
72
|
// cert). The server then accepts the connection regardless of its identity,
|
|
71
73
|
// while still negotiating flags.
|
|
72
74
|
export function proposeProtocols(target: string | undefined, clientCapabilities: { lz4: boolean }): string[] {
|
|
75
|
+
// An ip domain is an address alias, not a node identity — the server's real nodeId can never match it, so connect as a wildcard client (exactly like browsers do).
|
|
76
|
+
if (target && isIpDomain(target)) {
|
|
77
|
+
target = undefined;
|
|
78
|
+
}
|
|
73
79
|
let out: string[] = [];
|
|
74
80
|
let clientLZ4Options = clientCapabilities.lz4 ? [true, false] : [false];
|
|
75
81
|
let serverLZ4Options = [true, false];
|