Skip to content

Commit

Permalink
fix: 没有在 getQuantumultXNodes 中正确输出支持 udp 的 ssr 节点
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 3, 2019
1 parent fc275da commit 7815b42
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 9 deletions.
5 changes: 4 additions & 1 deletion lib/class/ShadowsocksrSubscribeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Provider from './Provider';

export default class ShadowsocksrSubscribeProvider extends Provider {
public readonly url: string;
public readonly udpRelay?: boolean;

constructor(config: ShadowsocksrSubscribeProviderConfig) {
super(config);
Expand All @@ -18,6 +19,7 @@ export default class ShadowsocksrSubscribeProvider extends Provider {
],
})
.required(),
udpRelay: Joi.boolean(),
})
.unknown();

Expand All @@ -29,9 +31,10 @@ export default class ShadowsocksrSubscribeProvider extends Provider {
}

this.url = config.url;
this.udpRelay = config.udpRelay;
}

public getNodeList(): ReturnType<typeof getShadowsocksrSubscription> {
return getShadowsocksrSubscription(this.url, this.tfo);
return getShadowsocksrSubscription(this.url, this.udpRelay, this.tfo);
}
}
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface ShadowsocksSubscribeProviderConfig extends ProviderConfig {

export interface ShadowsocksrSubscribeProviderConfig extends ProviderConfig {
readonly url: string;
readonly udpRelay?: boolean;
}

export interface V2rayNSubscribeProviderConfig extends ProviderConfig {
Expand Down Expand Up @@ -148,6 +149,7 @@ export interface ShadowsocksrNodeConfig extends SimpleNodeConfig {
readonly password: string;
readonly obfsparam: string;
readonly protoparam: string;
readonly 'udp-relay'?: boolean;
}

export interface VmessNodeConfig extends SimpleNodeConfig {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const mergeFilters = (filters: ReadonlyArray<NodeNameFilterType>, isStric
export const useKeywords = (keywords: ReadonlyArray<string>, isStrict?: boolean): NodeNameFilterType => {
// istanbul ignore next
if (!Array.isArray(keywords)) {
throw new Error('keywords 请使用数组');
throw new Error('keywords 请使用数组');
}

return item => keywords[isStrict ? 'every' : 'some'](keyword => item.nodeName.includes(keyword));
Expand All @@ -20,7 +20,7 @@ export const useKeywords = (keywords: ReadonlyArray<string>, isStrict?: boolean)
export const discardKeywords = (keywords: ReadonlyArray<string>, isStrict?: boolean): NodeNameFilterType => {
// istanbul ignore next
if (!Array.isArray(keywords)) {
throw new Error('keywords 请使用数组');
throw new Error('keywords 请使用数组');
}

return item => !keywords[isStrict ? 'every' : 'some'](keyword => item.nodeName.includes(keyword));
Expand All @@ -29,7 +29,7 @@ export const discardKeywords = (keywords: ReadonlyArray<string>, isStrict?: bool
export const useRegexp = (regexp: RegExp): NodeNameFilterType => {
// istanbul ignore next
if (!_.isRegExp(regexp)) {
throw new Error('入参不是一个合法的正则表达式');
throw new Error('入参不是一个合法的正则表达式');
}

return item => regexp.test(item.nodeName);
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const getShadowsocksSubscription = async (

export const getShadowsocksrSubscription = async (
url: string,
udpRelay?: boolean,
tfo?: boolean,
): Promise<ReadonlyArray<ShadowsocksrNodeConfig>> => {
assert(url, '未指定订阅地址 url');
Expand All @@ -217,6 +218,9 @@ export const getShadowsocksrSubscription = async (
if (tfo !== void 0) {
(nodeConfig.tfo as boolean) = tfo;
}
if (udpRelay !== void 0) {
(nodeConfig['udp-relay'] as boolean) = udpRelay;
}

return nodeConfig;
});
Expand Down Expand Up @@ -855,6 +859,9 @@ export const getQuantumultXNodes = (
`ssr-protocol-param=${nodeConfig.protoparam}`,
`obfs=${nodeConfig.obfs}`,
`obfs-host=${nodeConfig.obfsparam}`,
...(nodeConfig['udp-relay'] ? [
`udp-relay=${nodeConfig['udp-relay']}`,
] : []),
...(nodeConfig.tfo ? [
`fast-open=${nodeConfig.tfo}`,
] : []),
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/plain/provider/ssr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = {
url: 'http://example.com/test-ssr-sub.txt',
url: 'http://example.com/test-ssr-sub.txt?v=1',
type: 'shadowsocksr_subscribe',
};
8 changes: 8 additions & 0 deletions test/fixture/plain/provider/ssr_with_udp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
url: 'http://example.com/test-ssr-sub.txt?v=2',
type: 'shadowsocksr_subscribe',
udpRelay: true,
tfo: true,
};
2 changes: 1 addition & 1 deletion test/fixture/plain/surgio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
name: 'template-functions.conf',
template: 'template-functions',
provider: 'ss',
combineProviders: ['custom', 'ss_json', 'v2rayn', 'clash'],
combineProviders: ['custom', 'ss_json', 'v2rayn', 'clash', 'ssr_with_udp'],
},
],
urlBase: 'https://example.com/',
Expand Down
4 changes: 3 additions & 1 deletion test/snapshots/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Generated by [AVA](https://ava.li).
ss1 = custom, server, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true␊
ss2 = custom, server, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=false, obfs=tls, obfs-host=www.bing.com␊
ss4 = custom, server, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=false, obfs=tls, obfs-host=example.com␊
测试中文 = external, exec = "/usr/local/bin/ssr-local", args = "-s", args = "127.0.0.1", args = "-p", args = "1234", args = "-m", args = "aes-128-cfb", args = "-o", args = "tls1.2_ticket_auth", args = "-O", args = "auth_aes128_md5", args = "-k", args = "aaabbb", args = "-l", args = "61107", args = "-b", args = "127.0.0.1", args = "-g", args = "breakwa11.moe", local-port = 61107, addresses = 127.0.0.1␊
----␊
🇺🇸US 1, 🇺🇸US 2, 🇺🇲 US, Snell, HTTPS, 🇺🇸US 1, 🇺🇸US 2, 🇺🇸US 3, 🇺🇸US 4, 测试 1, 测试 2, ss1, ss2, ss4␊
🇺🇸US 1, 🇺🇸US 2, 🇺🇲 US, Snell, HTTPS, 🇺🇸US 1, 🇺🇸US 2, 🇺🇸US 3, 🇺🇸US 4, 测试 1, 测试 2, ss1, ss2, ss4, 测试中文
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
Expand All @@ -38,4 +39,5 @@ Generated by [AVA](https://ava.li).
shadowsocks=server:443, method=chacha20-ietf-poly1305, password=password, udp-relay=true, tag=ss1␊
shadowsocks=server:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=www.bing.com, tag=ss2␊
shadowsocks=server:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=example.com, tag=ss4␊
shadowsocks=127.0.0.1:1234, method=aes-128-cfb, password=aaabbb, ssr-protocol=auth_aes128_md5, ssr-protocol-param=, obfs=tls1.2_ticket_auth, obfs-host=breakwa11.moe, udp-relay=true, fast-open=true, tag=测试中文␊
`
Binary file modified test/snapshots/cli.test.ts.snap
Binary file not shown.
6 changes: 4 additions & 2 deletions test/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ test('getShadowsocksSubscription without udp', async t => {
});

test('getShadowsocksrSubscription', async t => {
const nodeList = await utils.getShadowsocksrSubscription('http://example.com/test-ssr-sub.txt?v=1');
const nodeList2 = await utils.getShadowsocksrSubscription('http://example.com/test-ssr-sub.txt?v=2', true);
const nodeList = await utils.getShadowsocksrSubscription('http://example.com/test-ssr-sub.txt?v=1', false);
const nodeList2 = await utils.getShadowsocksrSubscription('http://example.com/test-ssr-sub.txt?v=2', true, true);

t.deepEqual(nodeList[0], {
nodeName: '测试中文',
Expand All @@ -873,6 +873,7 @@ test('getShadowsocksrSubscription', async t => {
obfsparam: 'breakwa11.moe',
protocol: 'auth_aes128_md5',
protoparam: '',
'udp-relay': false,
});
t.deepEqual(nodeList2[0], {
nodeName: '测试中文',
Expand All @@ -886,5 +887,6 @@ test('getShadowsocksrSubscription', async t => {
protocol: 'auth_aes128_md5',
protoparam: '',
tfo: true,
'udp-relay': true,
});
});

0 comments on commit 7815b42

Please sign in to comment.