Skip to content

Commit

Permalink
feat: Vmess 配置的 udp 改为 udp-relay
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Custom Provider 如果有使用到 Vmess,需要将 udp 改为 udp-relay,于其他类型节点统一
  • Loading branch information
geekdada committed Jul 9, 2020
1 parent edfbe7a commit 9460bc8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/provider/ClashProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const parseClashConfig = (
uuid: item.uuid,
alterId: item.alterId ? `${item.alterId}` : '0',
method: item.cipher || 'auto',
udp: resolveUdpRelay(item.udp, udpRelay),
'udp-relay': resolveUdpRelay(item.udp, udpRelay),
tls: item.tls ?? false,
network: item.network || 'tcp',
...(item.network === 'ws' ? {
Expand Down
6 changes: 2 additions & 4 deletions lib/provider/V2rayNSubscribeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const getV2rayNSubscription = async (
.filter(item => item.startsWith("vmess://"));

return configList
.map<VmessNodeConfig|undefined>(item => {
.map<VmessNodeConfig|undefined>((item): VmessNodeConfig|undefined => {
const json = JSON.parse(fromBase64(item.replace('vmess://', '')));

// istanbul ignore next
Expand All @@ -119,9 +119,7 @@ export const getV2rayNSubscription = async (
tls: json.tls === 'tls',
host: json.host || '',
path: json.path || '/',
...(udpRelay ? {
udp: udpRelay,
} : null),
'udp-relay': udpRelay === true,
...(json.tls === 'tls' ? {
skipCertVerify: skipCertVerify ?? false,
tls13: tls13 ?? false,
Expand Down
6 changes: 3 additions & 3 deletions lib/provider/__tests__/ClashProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test('getClashSubscription', async t => {
method: 'auto',
tls: false,
network: 'tcp',
udp: false,
'udp-relay': false,
});
t.deepEqual(config.shift(), {
type: NodeTypeEnum.Vmess,
Expand All @@ -113,7 +113,7 @@ test('getClashSubscription', async t => {
alterId: '32',
method: 'auto',
network: 'ws',
udp: false,
'udp-relay': false,
tls: true,
tls13: false,
skipCertVerify: false,
Expand Down Expand Up @@ -221,7 +221,7 @@ test('getClashSubscription udpRelay', async t => {
method: 'auto',
tls: false,
network: 'tcp',
udp: true,
'udp-relay': true,
});
});

Expand Down
5 changes: 4 additions & 1 deletion lib/provider/__tests__/V2rayNSubscribeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('getV2rayNSubscription', async t => {
tls: false,
type: NodeTypeEnum.Vmess,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
'udp-relay': false,
});
t.deepEqual(configList[1], {
alterId: '64',
Expand All @@ -42,6 +43,7 @@ test('getV2rayNSubscription', async t => {
tls: false,
type: NodeTypeEnum.Vmess,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
'udp-relay': false,
});
});

Expand All @@ -61,6 +63,7 @@ test('getV2rayNSubscription compatible mode', async t => {
tls: false,
type: NodeTypeEnum.Vmess,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
'udp-relay': false,
});
});

Expand All @@ -80,6 +83,6 @@ test('getV2rayNSubscription udpRelay skipCertVerify', async t => {
tls: false,
type: NodeTypeEnum.Vmess,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
udp: true,
'udp-relay': true,
});
});
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export interface VmessNodeConfig extends SimpleNodeConfig {
readonly tls: boolean;
readonly host?: string;
readonly path?: string;
readonly udp?: boolean; // TODO: 统一为 udp-relay
readonly 'udp-relay'?: boolean;
readonly tls13?: boolean;
readonly skipCertVerify?: boolean;
readonly wsHeaders?: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ export const getQuantumultXNodes = function(
`method=chacha20-ietf-poly1305` :
`method=${nodeConfig.method}`),
`password=${nodeConfig.uuid}`,
...(nodeConfig.udp ? [
...(nodeConfig['udp-relay'] ? [
'udp-relay=true',
] : []),
...(nodeConfig.tfo ? [
Expand Down
4 changes: 2 additions & 2 deletions test/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ test('getQuantumultXNodes', t => {
port: 8080,
tls: false,
host: '',
udp: true,
'udp-relay': true,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
},
{
Expand Down Expand Up @@ -1264,7 +1264,7 @@ test('getQuantumultXNodes', t => {
port: 443,
tls: true,
tls13: true,
udp: true,
'udp-relay': true,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
}]),
'vmess=1.1.1.1:443, method=chacha20-ietf-poly1305, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=over-tls, tls13=true, tag=测试'
Expand Down

0 comments on commit 9460bc8

Please sign in to comment.