From 4c6ba2cdc8499ad0445f8d9f9da408ea06ba885a Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 25 Aug 2023 16:19:00 +0800 Subject: [PATCH] feat: hysteria --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 2 ++ backend/src/core/proxy-utils/parsers/index.js | 1 + .../src/core/proxy-utils/producers/clash.js | 4 +++- .../proxy-utils/producers/shadowrocket.js | 22 +++++++++++++++++++ .../src/core/proxy-utils/producers/stash.js | 22 ++++++++++++++++++- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 2298bab..63a4fd0 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.26", + "version": "2.14.27", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 0695a7f..57e3ce9 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -188,6 +188,8 @@ function lastParse(proxy) { if (proxy.network === 'tcp') { delete proxy.network; } + } + if (['trojan', 'tuic', 'hysteria'].includes(proxy.type)) { proxy.tls = true; } if (proxy.tls && !proxy.sni) { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index 7a1c4ef..7804793 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -344,6 +344,7 @@ function Clash_All() { 'trojan', 'tuic', 'vless', + 'hysteria', ].includes(proxy.type) ) { throw new Error( diff --git a/backend/src/core/proxy-utils/producers/clash.js b/backend/src/core/proxy-utils/producers/clash.js index 8b6519e..9cac0e5 100644 --- a/backend/src/core/proxy-utils/producers/clash.js +++ b/backend/src/core/proxy-utils/producers/clash.js @@ -74,7 +74,9 @@ export default function Clash_Producer() { proxy['http-opts'].headers.Host = [httpHost]; } } - + if (['trojan', 'tuic', 'hysteria'].includes(proxy.type)) { + delete proxy.tls; + } delete proxy['tls-fingerprint']; return ' - ' + JSON.stringify(proxy) + '\n'; }) diff --git a/backend/src/core/proxy-utils/producers/shadowrocket.js b/backend/src/core/proxy-utils/producers/shadowrocket.js index 0174bff..5ae7bdf 100644 --- a/backend/src/core/proxy-utils/producers/shadowrocket.js +++ b/backend/src/core/proxy-utils/producers/shadowrocket.js @@ -49,6 +49,12 @@ export default function Stash_Producer() { } else { proxy.alpn = ['h3']; } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/adapter/outbound/tuic.go#L197 if ( (!proxy.token || proxy.token.length === 0) && @@ -56,6 +62,18 @@ export default function Stash_Producer() { ) { proxy.version = 5; } + } else if (proxy.type === 'hysteria') { + if (isPresent(proxy, 'alpn')) { + proxy.alpn = Array.isArray(proxy.alpn) + ? proxy.alpn + : [proxy.alpn]; + } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } } if ( @@ -78,6 +96,10 @@ export default function Stash_Producer() { } } + if (['trojan', 'tuic', 'hysteria'].includes(proxy.type)) { + delete proxy.tls; + } + delete proxy['tls-fingerprint']; return ' - ' + JSON.stringify(proxy) + '\n'; }) diff --git a/backend/src/core/proxy-utils/producers/stash.js b/backend/src/core/proxy-utils/producers/stash.js index 1014f2a..bce8231 100644 --- a/backend/src/core/proxy-utils/producers/stash.js +++ b/backend/src/core/proxy-utils/producers/stash.js @@ -61,6 +61,12 @@ export default function Stash_Producer() { } else { proxy.alpn = ['h3']; } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/adapter/outbound/tuic.go#L197 if ( (!proxy.token || proxy.token.length === 0) && @@ -68,6 +74,18 @@ export default function Stash_Producer() { ) { proxy.version = 5; } + } else if (proxy.type === 'hysteria') { + if (isPresent(proxy, 'alpn')) { + proxy.alpn = Array.isArray(proxy.alpn) + ? proxy.alpn + : [proxy.alpn]; + } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } } if ( @@ -89,7 +107,9 @@ export default function Stash_Producer() { proxy['http-opts'].headers.Host = [httpHost]; } } - + if (['trojan', 'tuic', 'hysteria'].includes(proxy.type)) { + delete proxy.tls; + } delete proxy['tls-fingerprint']; return ' - ' + JSON.stringify(proxy) + '\n'; })