socket-function 1.2.21 → 1.2.22
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/package.json +1 -1
- package/src/protocolNegotiation.ts +13 -1
package/package.json
CHANGED
|
@@ -35,6 +35,17 @@ function encodeFlagBit(b: boolean): string { return b ? "1" : "0"; }
|
|
|
35
35
|
// connecting through a Let's Encrypt cert on a public domain.
|
|
36
36
|
const WILDCARD_TARGET = "";
|
|
37
37
|
|
|
38
|
+
// The target match is on the host portion only, not the exact listening port. A
|
|
39
|
+
// server can restart (or rebind) on a new port while keeping the same host identity,
|
|
40
|
+
// and a client still holding the old nodeId (host:oldPort) should be accepted rather
|
|
41
|
+
// than rejected as a stale thread. Strip only the trailing :port (last colon segment),
|
|
42
|
+
// so hosts that themselves contain colons survive.
|
|
43
|
+
function stripPort(nodeId: string): string {
|
|
44
|
+
let idx = nodeId.lastIndexOf(":");
|
|
45
|
+
if (idx < 0) return nodeId;
|
|
46
|
+
return nodeId.slice(0, idx);
|
|
47
|
+
}
|
|
48
|
+
|
|
38
49
|
function encodeOne(target: string, flags: ConnectionFlags): string {
|
|
39
50
|
let plain = `${PROTOCOL_VERSION}|${target}|clz4=${encodeFlagBit(flags.clientLZ4)}|slz4=${encodeFlagBit(flags.serverLZ4)}`;
|
|
40
51
|
return hexEncode(plain);
|
|
@@ -105,7 +116,8 @@ export function chooseProtocol(
|
|
|
105
116
|
for (let hex of proposed) {
|
|
106
117
|
let decoded = decodeProtocol(hex);
|
|
107
118
|
if (!decoded) continue;
|
|
108
|
-
|
|
119
|
+
// NOTE: We allow the pork to be different. This doesn't degrade security as we're still using TLS, so proxies don't reduce our security, However, it does make it a lot easier for a server to listen on multiple ports and redirect them all to the single-mounted port (As socket function doesn't support mounting on multiple ports because it makes it complicated for code that wants to say where we mounted to if we could be mounted to multiple ports at once).
|
|
120
|
+
if (decoded.target !== WILDCARD_TARGET && stripPort(decoded.target) !== stripPort(serverNodeId)) continue;
|
|
109
121
|
// Server capability check: if the proposal asks the server to receive
|
|
110
122
|
// LZ4 (slz4=1) but the server doesn't support it, skip.
|
|
111
123
|
if (decoded.flags.serverLZ4 && !serverCapabilities.lz4) continue;
|