Skip to content

Commit

Permalink
reduce duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteist authored and zizifn committed Jun 17, 2023
1 parent 319f114 commit 28f507f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/worker-vless.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ async function socks5Connect(addressType, addressRemote, portRemote) {
console.log('Sent socks greeting');

const reader = socket.readable.getReader();
const encoder = new TextEncoder();
let res = (await reader.read()).value;
// Response format (Socks Server -> Worker):
// +----+--------+
Expand Down Expand Up @@ -641,9 +642,9 @@ async function socks5Connect(addressType, addressRemote, portRemote) {
const authRequest = new Uint8Array([
1,
username.length,
...(new TextEncoder()).encode(username),
...encoder.encode(username),
password.length,
...(new TextEncoder()).encode(password)
...encoder.encode(password)
]);
await writer.write(authRequest);
res = (await reader.read()).value;
Expand Down Expand Up @@ -676,7 +677,7 @@ async function socks5Connect(addressType, addressRemote, portRemote) {
DSTADDR = new Uint8Array([1, ...addressRemote.split('.').map(Number)]);
} else if (addressType === 2) {
DSTADDR = new Uint8Array(
[3, addressRemote.length, ...(new TextEncoder()).encode(addressRemote)]
[3, addressRemote.length, ...encoder.encode(addressRemote)]
);
} else if (addressType === 3) {
DSTADDR = new Uint8Array(
Expand Down

0 comments on commit 28f507f

Please sign in to comment.