@sanctumterra/raknet 1.3.77 → 1.3.78
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/IDE/notes.md +39 -0
- package/bun.lock +67 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +32 -12
- package/dist/client/framer.d.ts +1 -1
- package/dist/client/framer.d.ts.map +1 -1
- package/dist/client/framer.js +21 -14
- package/dist/proto/decorators/create.d.ts.map +1 -1
- package/dist/proto/decorators/serialize.d.ts.map +1 -1
- package/package.json +1 -1
package/IDE/notes.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Framer Optimization Notes
|
|
2
|
+
|
|
3
|
+
## Performance Issues Identified
|
|
4
|
+
|
|
5
|
+
1. **Memory Management**
|
|
6
|
+
- Frequent array allocations in constructor
|
|
7
|
+
- Large number of Map/Set operations
|
|
8
|
+
- Excessive array copying in batch processing
|
|
9
|
+
|
|
10
|
+
2. **Data Structures**
|
|
11
|
+
- Using Maps for ordered queues
|
|
12
|
+
- Array.from() creating unnecessary copies
|
|
13
|
+
- Multiple array fills in constructor
|
|
14
|
+
|
|
15
|
+
3. **Processing Overhead**
|
|
16
|
+
- Multiple iterations over sequences in ACK/NACK processing
|
|
17
|
+
- Inefficient batch processing
|
|
18
|
+
- Redundant timestamp checks
|
|
19
|
+
|
|
20
|
+
## Optimization Strategies
|
|
21
|
+
|
|
22
|
+
1. **Memory Optimizations**
|
|
23
|
+
- Pre-allocate buffers where possible
|
|
24
|
+
- Reuse arrays instead of creating new ones
|
|
25
|
+
- Use typed arrays for better memory efficiency
|
|
26
|
+
|
|
27
|
+
2. **Data Structure Improvements**
|
|
28
|
+
- Replace Maps with more efficient structures where possible
|
|
29
|
+
- Optimize queue implementations
|
|
30
|
+
- Use Set for faster lookups
|
|
31
|
+
|
|
32
|
+
3. **Processing Improvements**
|
|
33
|
+
- Batch process frames more efficiently
|
|
34
|
+
- Optimize ACK/NACK handling
|
|
35
|
+
- Reduce timestamp comparisons
|
|
36
|
+
|
|
37
|
+
## Implementation Notes
|
|
38
|
+
|
|
39
|
+
Changes will be tracked here as they are implemented...
|
package/bun.lock
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"workspaces": {
|
|
4
|
+
"": {
|
|
5
|
+
"name": "@sanctumterra/raknet",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@serenityjs/binarystream": "^2.6.6",
|
|
8
|
+
"@serenityjs/emitter": "^0.5.2",
|
|
9
|
+
"@serenityjs/protocol": "^0.6.4",
|
|
10
|
+
"reflect-metadata": "^0.2.2",
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@biomejs/biome": "^1.9.4",
|
|
14
|
+
"@types/node": "^22.8.0",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
"packages": {
|
|
19
|
+
"@biomejs/biome": ["@biomejs/biome@1.9.4", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "1.9.4", "@biomejs/cli-darwin-x64": "1.9.4", "@biomejs/cli-linux-arm64": "1.9.4", "@biomejs/cli-linux-arm64-musl": "1.9.4", "@biomejs/cli-linux-x64": "1.9.4", "@biomejs/cli-linux-x64-musl": "1.9.4", "@biomejs/cli-win32-arm64": "1.9.4", "@biomejs/cli-win32-x64": "1.9.4" }, "bin": { "biome": "bin/biome" } }, "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog=="],
|
|
20
|
+
|
|
21
|
+
"@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@1.9.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw=="],
|
|
22
|
+
|
|
23
|
+
"@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@1.9.4", "", { "os": "darwin", "cpu": "x64" }, "sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg=="],
|
|
24
|
+
|
|
25
|
+
"@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@1.9.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g=="],
|
|
26
|
+
|
|
27
|
+
"@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@1.9.4", "", { "os": "linux", "cpu": "arm64" }, "sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA=="],
|
|
28
|
+
|
|
29
|
+
"@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@1.9.4", "", { "os": "linux", "cpu": "x64" }, "sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg=="],
|
|
30
|
+
|
|
31
|
+
"@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@1.9.4", "", { "os": "linux", "cpu": "x64" }, "sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg=="],
|
|
32
|
+
|
|
33
|
+
"@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@1.9.4", "", { "os": "win32", "cpu": "arm64" }, "sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg=="],
|
|
34
|
+
|
|
35
|
+
"@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@1.9.4", "", { "os": "win32", "cpu": "x64" }, "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA=="],
|
|
36
|
+
|
|
37
|
+
"@serenityjs/binarystream": ["@serenityjs/binarystream@2.7.0", "", { "optionalDependencies": { "@serenityjs/binarystream-darwin-arm64": "2.7.0", "@serenityjs/binarystream-darwin-x64": "2.7.0", "@serenityjs/binarystream-linux-x64-gnu": "2.7.0", "@serenityjs/binarystream-win32-x64-msvc": "2.7.0" } }, "sha512-aIWTRqy3Z5mf9qbLiE7sjM96+PKXsJqs4tURe5VlnI5fauNlFIwUUBXGyrR2PiqBSOp8DSjmP1XfO49GP4hdEg=="],
|
|
38
|
+
|
|
39
|
+
"@serenityjs/binarystream-darwin-arm64": ["@serenityjs/binarystream-darwin-arm64@2.7.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-i1MUyRLT6zNWSTOIb5eALFnSxEFmbM+nc/yw5ooqzAOM4qtr/jBrolHyEm157AU8+7ngnkBn9T94Z4zVYJGBhg=="],
|
|
40
|
+
|
|
41
|
+
"@serenityjs/binarystream-darwin-x64": ["@serenityjs/binarystream-darwin-x64@2.7.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-hm2G3dlR4meGp2MqCmdWWPqTZxcsGdT4P/cg1i5Y74BdG9F9CYojvHPN9jaq8fY+ViqBz0hzPvrKPIPEMwBDHQ=="],
|
|
42
|
+
|
|
43
|
+
"@serenityjs/binarystream-linux-x64-gnu": ["@serenityjs/binarystream-linux-x64-gnu@2.7.0", "", { "os": "linux", "cpu": "x64" }, "sha512-C2HgD+coQtlpIxnkpRObE38+rU2xVqsvRRZPcSxpkAzdPaiyVehkF7VZx0cWAZPiLZEZifNDTQV3tQlgfp4USg=="],
|
|
44
|
+
|
|
45
|
+
"@serenityjs/binarystream-win32-x64-msvc": ["@serenityjs/binarystream-win32-x64-msvc@2.7.0", "", { "os": "win32", "cpu": "x64" }, "sha512-VozM9uyBdQQJXl5Cz9zdn2dA6jOpkgzWJHjgop63FSpVAllykMKbd2WU2ZpEbLy0dTScmND2suXcqiPeU5Jrwg=="],
|
|
46
|
+
|
|
47
|
+
"@serenityjs/emitter": ["@serenityjs/emitter@0.5.2", "", {}, "sha512-x+tYqmCbOzSI0wo/0t6Scj5OU883RtTUZ6b0jfhymO0E5GEF1RkWI/4eEGcHUWMtuFDbPtb2pQynPNbt4R4XCQ=="],
|
|
48
|
+
|
|
49
|
+
"@serenityjs/logger": ["@serenityjs/logger@0.8.0", "", { "dependencies": { "colorette": "2.0.20", "moment": "2.30.1" } }, "sha512-GSCbCNYmeSIAPAX0W+TKyB7zTtd9BSg+s/hxqK6JMpMMq679YPKkvv7pmQKme2Da/c2czIvNvbh4x7HGx15grQ=="],
|
|
50
|
+
|
|
51
|
+
"@serenityjs/nbt": ["@serenityjs/nbt@0.8.0", "", { "dependencies": { "@serenityjs/binarystream": "^2.7.0" } }, "sha512-+4l3xwR33+UHTo5+cJD1q+Q/jTIvhbvgsGr5uUaojYaUfpf7UnHcew3LsiSXhzTtCC7VR90lv2XUvq9lDhAhJA=="],
|
|
52
|
+
|
|
53
|
+
"@serenityjs/protocol": ["@serenityjs/protocol@0.6.4", "", { "dependencies": { "@serenityjs/binarystream": "2.7.0", "@serenityjs/nbt": "*", "@serenityjs/raknet": "*" } }, "sha512-tTeB2LmVxbQOOOadUetomjhJS3TO8GzqXBwdHDnrkhivhF8fJR27bUEYL4ZNvKB9nyuXpKxQJiXaatkHq6UroA=="],
|
|
54
|
+
|
|
55
|
+
"@serenityjs/raknet": ["@serenityjs/raknet@0.8.0", "", { "dependencies": { "@serenityjs/binarystream": "^2.7.0", "@serenityjs/emitter": "*", "@serenityjs/logger": "*", "@serenityjs/nbt": "*", "reflect-metadata": "0.2.2" } }, "sha512-A7xOF6nhOljUD/yUrvNfXVAJhdVV+SC4rzBclexcDaLaxn5EqNQP4BFytKSsTb/v15wvlfY+600eBF4/qm9G+Q=="],
|
|
56
|
+
|
|
57
|
+
"@types/node": ["@types/node@22.15.13", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-mkmz+UBGCF/ssSObTp1McwQEvIjO2hUnVvZzck61l0su7btUill8OSvzA4N62+AtkJgMhiniyD+wEL5kocZaEA=="],
|
|
58
|
+
|
|
59
|
+
"colorette": ["colorette@2.0.20", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="],
|
|
60
|
+
|
|
61
|
+
"moment": ["moment@2.30.1", "", {}, "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how=="],
|
|
62
|
+
|
|
63
|
+
"reflect-metadata": ["reflect-metadata@0.2.2", "", {}, "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q=="],
|
|
64
|
+
|
|
65
|
+
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAmB,KAAK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,OAAO,CAAC,YAAY,CAAC;IACzC,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,iBAAiB,CAAC,CAAiB;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAiB;IAClC,aAAa,EAAG,OAAO,GAAG,IAAI,CAAC;IAE/B,MAAM,SAAuB;gBAExB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAwB;IAM3D,UAAU;IAuBJ,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAkB9B,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IA4GvC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAYjD,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAOvD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAiCjC,OAAO,CAAC,aAAa;IAiDrB,OAAO,CAAC,aAAa;IAOd,OAAO,IAAI,IAAI;IAsCf,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAkClC"}
|
package/dist/client/client.js
CHANGED
|
@@ -12,7 +12,7 @@ const disconnect_1 = __importDefault(require("../proto/packets/disconnect"));
|
|
|
12
12
|
const client_options_1 = require("./client-options");
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
const TICK_INTERVAL = 50;
|
|
15
|
-
const REQUEST_INTERVAL =
|
|
15
|
+
const REQUEST_INTERVAL = 500;
|
|
16
16
|
class Client extends emitter_1.Emitter {
|
|
17
17
|
socket;
|
|
18
18
|
framer;
|
|
@@ -35,7 +35,7 @@ class Client extends emitter_1.Emitter {
|
|
|
35
35
|
this.on("tick", () => this.framer?.tick());
|
|
36
36
|
this.socket.removeAllListeners();
|
|
37
37
|
this.socket.on("message", (payload, rinfo) => {
|
|
38
|
-
this.framer?.
|
|
38
|
+
this.framer?.incomingMessage(payload, rinfo);
|
|
39
39
|
});
|
|
40
40
|
this.socket.on("error", (err) => {
|
|
41
41
|
utils_1.Logger.error(`[Client] Socket error: ${err}`);
|
|
@@ -77,7 +77,7 @@ class Client extends emitter_1.Emitter {
|
|
|
77
77
|
throw new Error("Failed to get server advertisement");
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
79
79
|
let isResolved = false;
|
|
80
|
-
let
|
|
80
|
+
let currentStage = "request-one"; // Track connection stage
|
|
81
81
|
const cleanup = () => {
|
|
82
82
|
if (this.connectionTimeout) {
|
|
83
83
|
clearTimeout(this.connectionTimeout);
|
|
@@ -92,30 +92,49 @@ class Client extends emitter_1.Emitter {
|
|
|
92
92
|
this.cleanup();
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
+
// Setup connection timeout
|
|
95
96
|
this.connectionTimeout = setTimeout(() => {
|
|
96
97
|
cleanup();
|
|
97
98
|
reject(new Error("Connection timed out"));
|
|
98
99
|
}, this.options.timeout);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
// Prepare connection request one
|
|
101
|
+
const requestOne = new proto_1.OpenConnectionRequestOne();
|
|
102
|
+
requestOne.mtu = this.options.mtuSize;
|
|
103
|
+
requestOne.protocol = this.options.protocolVersion;
|
|
104
|
+
// Handle open-connection-reply-one event
|
|
105
|
+
this.once("open-connection-reply-one", () => {
|
|
106
|
+
currentStage = "request-two";
|
|
107
|
+
utils_1.Logger.debug("[Client] Received OpenConnectionReplyOne, sending OpenConnectionRequestTwo");
|
|
108
|
+
// Move to next connection stage
|
|
109
|
+
if (this.requestInterval) {
|
|
110
|
+
clearInterval(this.requestInterval);
|
|
111
|
+
}
|
|
112
|
+
// Here we would send OpenConnectionRequestTwo
|
|
113
|
+
// The framer handles this transition
|
|
114
|
+
});
|
|
115
|
+
// Handle open-connection-reply-two event
|
|
102
116
|
this.once("open-connection-reply-two", (packet) => {
|
|
103
117
|
const mtu = packet.mtu;
|
|
104
118
|
if (mtu > 400 && mtu < 1500) {
|
|
105
|
-
|
|
119
|
+
currentStage = "completed";
|
|
120
|
+
utils_1.Logger.debug(`[Client] Received OpenConnectionReplyTwo with MTU: ${mtu}`);
|
|
106
121
|
}
|
|
107
122
|
else {
|
|
108
123
|
cleanup();
|
|
109
124
|
reject(new Error(`Invalid MTU size: ${mtu}`));
|
|
110
125
|
}
|
|
111
126
|
});
|
|
112
|
-
|
|
113
|
-
this.
|
|
127
|
+
// Send initial request
|
|
128
|
+
this.emit("open-connection-request-one", requestOne);
|
|
129
|
+
this.send(requestOne.serialize());
|
|
130
|
+
// Set up interval to resend requests
|
|
114
131
|
this.requestInterval = setInterval(() => {
|
|
115
|
-
if (!isResolved &&
|
|
116
|
-
|
|
132
|
+
if (!isResolved && currentStage === "request-one") {
|
|
133
|
+
utils_1.Logger.debug("[Client] Resending OpenConnectionRequestOne");
|
|
134
|
+
this.send(requestOne.serialize());
|
|
117
135
|
}
|
|
118
136
|
}, REQUEST_INTERVAL);
|
|
137
|
+
// Handle successful connection
|
|
119
138
|
this.once("new-incoming-connection", () => {
|
|
120
139
|
if (!isResolved) {
|
|
121
140
|
isResolved = true;
|
|
@@ -125,6 +144,7 @@ class Client extends emitter_1.Emitter {
|
|
|
125
144
|
resolve(advertisement);
|
|
126
145
|
}
|
|
127
146
|
});
|
|
147
|
+
// Handle connection errors
|
|
128
148
|
this.once("error", (error) => {
|
|
129
149
|
cleanup();
|
|
130
150
|
reject(error);
|
|
@@ -193,7 +213,7 @@ class Client extends emitter_1.Emitter {
|
|
|
193
213
|
state.handle = null;
|
|
194
214
|
}
|
|
195
215
|
this.socket.close(() => {
|
|
196
|
-
|
|
216
|
+
utils_1.Logger.info("[Client] Socket closed");
|
|
197
217
|
this.socket?.removeAllListeners();
|
|
198
218
|
});
|
|
199
219
|
// (this.socket as { _handle?: unknown })._handle = undefined;
|
package/dist/client/framer.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class Framer {
|
|
|
37
37
|
tick(): void;
|
|
38
38
|
private processBatchedAcksAndNacks;
|
|
39
39
|
private processBatchedOrderedFrames;
|
|
40
|
-
|
|
40
|
+
incomingMessage(payload: Buffer, rinfo: RemoteInfo): void;
|
|
41
41
|
private processFrame;
|
|
42
42
|
handle(frameSet: Frameset): void;
|
|
43
43
|
private handleFrame;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framer.d.ts","sourceRoot":"","sources":["../../src/client/framer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,EAGL,QAAQ,EAUR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"framer.d.ts","sourceRoot":"","sources":["../../src/client/framer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,EAGL,QAAQ,EAUR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAS7C,UAAU,WAAW;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,MAAM;IAClB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,iBAAiB,CAAM;IAC/B,OAAO,CAAC,sBAAsB,CAA0B;IACxD,OAAO,CAAC,kBAAkB,CAA0B;IACpD,OAAO,CAAC,yBAAyB,CAAmC;IACpE,OAAO,CAAC,eAAe,CAAmC;IAC1D,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC,GAAG,CA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AAQ,EAAE,QAAQ,GAAG,IAAI;IAiCxD,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,UAAU;IAqBX,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CA6BtC"}
|
package/dist/client/framer.js
CHANGED
|
@@ -6,6 +6,12 @@ const proto_2 = require("../proto");
|
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const binarystream_1 = require("@serenityjs/binarystream");
|
|
8
8
|
const connection_request_accepted_1 = require("../proto/packets/connection-request-accepted");
|
|
9
|
+
// Constants for packet handling
|
|
10
|
+
const PACKET_HEADER_MASK = 0xf0;
|
|
11
|
+
const PACKET_HEADER_FRAMESET = 0x80;
|
|
12
|
+
const PACKET_ENCAPSULATED = 0xfe;
|
|
13
|
+
const PING_INTERVAL = 50; // Send ping every 50 ticks
|
|
14
|
+
const MTU_HEADER_SIZE = 36;
|
|
9
15
|
class Framer {
|
|
10
16
|
client;
|
|
11
17
|
lastInputSequence = -1;
|
|
@@ -36,7 +42,7 @@ class Framer {
|
|
|
36
42
|
this.outputFrameQueue.frames = [];
|
|
37
43
|
this.outputOrderIndex = new Array(32).fill(0);
|
|
38
44
|
this.outputSequenceIndex = new Array(32).fill(0);
|
|
39
|
-
this.mtuDiff = this.client.options.mtuSize -
|
|
45
|
+
this.mtuDiff = this.client.options.mtuSize - MTU_HEADER_SIZE;
|
|
40
46
|
}
|
|
41
47
|
tick() {
|
|
42
48
|
this._tickCount++;
|
|
@@ -45,8 +51,8 @@ class Framer {
|
|
|
45
51
|
this.client.status === proto_1.Status.Disconnecting) {
|
|
46
52
|
return;
|
|
47
53
|
}
|
|
48
|
-
// Send a ping every
|
|
49
|
-
if (this._tickCount %
|
|
54
|
+
// Send a ping every PING_INTERVAL ticks
|
|
55
|
+
if (this._tickCount % PING_INTERVAL === 0) {
|
|
50
56
|
const ping = new proto_1.ConnectedPing();
|
|
51
57
|
ping.timestamp = BigInt(now);
|
|
52
58
|
this.frameAndSend(ping.serialize(), proto_1.Priority.Immediate);
|
|
@@ -111,10 +117,10 @@ class Framer {
|
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
|
-
|
|
120
|
+
incomingMessage(payload, rinfo) {
|
|
115
121
|
let header = payload.readUint8();
|
|
116
|
-
if ((header &
|
|
117
|
-
header =
|
|
122
|
+
if ((header & PACKET_HEADER_MASK) === PACKET_HEADER_FRAMESET)
|
|
123
|
+
header = PACKET_HEADER_FRAMESET;
|
|
118
124
|
switch (header) {
|
|
119
125
|
case proto_1.Packet.Ack: {
|
|
120
126
|
const ack = new proto_1.Ack(payload).deserialize();
|
|
@@ -163,7 +169,7 @@ class Framer {
|
|
|
163
169
|
this.frameAndSend(conReq.serialize(), proto_1.Priority.Immediate);
|
|
164
170
|
break;
|
|
165
171
|
}
|
|
166
|
-
case
|
|
172
|
+
case PACKET_HEADER_FRAMESET: {
|
|
167
173
|
const frameset = new proto_2.Frameset(payload).deserialize();
|
|
168
174
|
this.client.emit("frameset", frameset);
|
|
169
175
|
this.handle(frameset);
|
|
@@ -228,7 +234,7 @@ class Framer {
|
|
|
228
234
|
this.client.emit("connected-pong", packet);
|
|
229
235
|
break;
|
|
230
236
|
}
|
|
231
|
-
case
|
|
237
|
+
case PACKET_ENCAPSULATED: {
|
|
232
238
|
this.client.emit("encapsulated", frame.payload);
|
|
233
239
|
break;
|
|
234
240
|
}
|
|
@@ -256,10 +262,10 @@ class Framer {
|
|
|
256
262
|
return;
|
|
257
263
|
}
|
|
258
264
|
this.receivedFrameSequences.add(frameSet.sequence);
|
|
259
|
-
const
|
|
260
|
-
if (
|
|
265
|
+
const sequenceGap = frameSet.sequence - this.lastInputSequence;
|
|
266
|
+
if (sequenceGap > 1) {
|
|
261
267
|
if (this.client.options.debug) {
|
|
262
|
-
utils_1.Logger.debug(`[Framer] Detected ${
|
|
268
|
+
utils_1.Logger.debug(`[Framer] Detected ${sequenceGap - 1} missing sequences between ${this.lastInputSequence} and ${frameSet.sequence}`);
|
|
263
269
|
}
|
|
264
270
|
for (let index = this.lastInputSequence + 1; index < frameSet.sequence; index++) {
|
|
265
271
|
this.lostFrameSequences.add(index);
|
|
@@ -389,10 +395,11 @@ class Framer {
|
|
|
389
395
|
this.outputSequenceIndex[channel] = 0;
|
|
390
396
|
}
|
|
391
397
|
const maxSize = this.mtuDiff;
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
398
|
+
const payloadSize = frame.payload.byteLength;
|
|
399
|
+
if (payloadSize > maxSize) {
|
|
400
|
+
const splitSize = Math.ceil(payloadSize / maxSize);
|
|
394
401
|
const splitId = this.outputSplitIndex++ & 0xffff;
|
|
395
|
-
for (let index = 0; index <
|
|
402
|
+
for (let index = 0; index < payloadSize; index += maxSize) {
|
|
396
403
|
const nframe = this.createSplitFrame(frame, index, maxSize, splitId, splitSize);
|
|
397
404
|
this.queueFrame(nframe, priority);
|
|
398
405
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/proto/decorators/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,YAAY,CAAC;AAQvD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/proto/decorators/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,YAAY,CAAC;AAQvD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,IACxB,QAAQ,OAAO,UAAU,UAwEjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/proto/decorators/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,wBAAgB,SAAS,CACxB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,UAAU,GAAG,OAAwB,EAC7C,SAAS,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/proto/decorators/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,wBAAgB,SAAS,CACxB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,UAAU,GAAG,OAAwB,EAC7C,SAAS,CAAC,EAAE,MAAM,IAGV,QAAQ,MAAM,EAAE,aAAa,MAAM,UAK3C"}
|