Skip to content

Commit

Permalink
better socks address parser and enhance robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteist authored and zizifn committed Jun 17, 2023
1 parent 598546d commit 3831c84
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/worker-vless.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let proxyIP = '';
// Example: user:pass@host:port or host:port
let socks5Address = '';


if (!isValidUUID(userID)) {
throw new Error('uuid is not valid');
}
Expand All @@ -33,13 +32,15 @@ export default {
userID = env.UUID || userID;
proxyIP = env.PROXYIP || proxyIP;
socks5Address = env.SOCKS5 || socks5Address;
try {
parsedSocks5Address = socks5AddressParser(socks5Address);
enableSocks = true;
} catch (err) {
if (socks5Address) {
try {
parsedSocks5Address = socks5AddressParser(socks5Address);
enableSocks = true;
} catch (err) {
/** @type {Error} */ let e = err;
console.log(e.toString());
enableSocks = false;
console.log(e.toString());
enableSocks = false;
}
}
const upgradeHeader = request.headers.get('Upgrade');
if (!upgradeHeader || upgradeHeader !== 'websocket') {
Expand Down Expand Up @@ -200,7 +201,7 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
// if the cf connect tcp socket have no incoming data, we retry to redirect ip
async function retry() {
if (enableSocks) {
tcpSocket = await connectAndWrite(addressRemote, portRemote, enableSocks);
tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
} else {
tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote);
}
Expand Down

0 comments on commit 3831c84

Please sign in to comment.