* * @param { ArrayBuffer} vlessBuffer * @param {string} userID * @returns
(vlessBuffer, userID)
| 314 | * @returns |
| 315 | */ |
| 316 | function processVlessHeader(vlessBuffer, userID) { |
| 317 | if (vlessBuffer.byteLength < 24) { |
| 318 | return { |
| 319 | hasError: true, |
| 320 | message: "invalid data", |
| 321 | }; |
| 322 | } |
| 323 | const version = new Uint8Array(vlessBuffer.slice(0, 1)); |
| 324 | let isValidUser = false; |
| 325 | let isUDP = false; |
| 326 | if (stringify(new Uint8Array(vlessBuffer.slice(1, 17))) === userID) { |
| 327 | isValidUser = true; |
| 328 | } |
| 329 | if (!isValidUser) { |
| 330 | return { |
| 331 | hasError: true, |
| 332 | message: "invalid user", |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | const optLength = new Uint8Array(vlessBuffer.slice(17, 18))[0]; |
| 337 | //skip opt for now |
| 338 | |
| 339 | const command = new Uint8Array( |
| 340 | vlessBuffer.slice(18 + optLength, 18 + optLength + 1) |
| 341 | )[0]; |
| 342 | |
| 343 | // 0x01 TCP |
| 344 | // 0x02 UDP |
| 345 | // 0x03 MUX |
| 346 | if (command === 1) { |
| 347 | } else if (command === 2) { |
| 348 | isUDP = true; |
| 349 | } else { |
| 350 | return { |
| 351 | hasError: true, |
| 352 | message: `command ${command} is not support, command 01-tcp,02-udp,03-mux`, |
| 353 | }; |
| 354 | } |
| 355 | const portIndex = 18 + optLength + 1; |
| 356 | const portBuffer = vlessBuffer.slice(portIndex, portIndex + 2); |
| 357 | // port is big-Endian in raw data etc 80 == 0x005d |
| 358 | const portRemote = new DataView(portBuffer).getUint16(0); |
| 359 | |
| 360 | let addressIndex = portIndex + 2; |
| 361 | const addressBuffer = new Uint8Array( |
| 362 | vlessBuffer.slice(addressIndex, addressIndex + 1) |
| 363 | ); |
| 364 | |
| 365 | // 1--> ipv4 addressLength =4 |
| 366 | // 2--> domain name addressLength=addressBuffer[1] |
| 367 | // 3--> ipv6 addressLength =16 |
| 368 | const addressType = addressBuffer[0]; |
| 369 | let addressLength = 0; |
| 370 | let addressValueIndex = addressIndex + 1; |
| 371 | let addressValue = ""; |
| 372 | switch (addressType) { |
| 373 | case 1: |