Skip to content

Commit

Permalink
feat: add snell support for clash output #33
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 7, 2019
1 parent 9adbe77 commit 8c3df9e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,18 @@ export const getClashNodes = (
protocolparam: nodeConfig.protoparam,
cipher: nodeConfig.method,
};

case NodeTypeEnum.Snell:
return {
type: 'snell',
name: nodeConfig.nodeName,
server: nodeConfig.hostname,
port: nodeConfig.port,
psk: nodeConfig.psk,
'obfs-opts': {
mode: nodeConfig.obfs,
},
};

// istanbul ignore next
default:
Expand Down
4 changes: 2 additions & 2 deletions test/asset/clash-sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ Proxy:
port: 44046
psk: yourpsk
# obfs-opts:
# mode: http # or tls
# host: bing.com
# mode: http # or tls
# host: bing.com

- name: "ss4"
type: ss
Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Generated by [AVA](https://ava.li).
shadowsocks=us.example.com:444, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
shadowsocks=us.example.com:445, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=www.bing.com, tag=🇺🇸US 3␊
shadowsocks=us.example.com:80, method=chacha20-ietf-poly1305, password=password, obfs=http, obfs-host=www.bing.com, tag=🇺🇸US 4␊
vmess=1.1.1.1:8080, method=auto, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1␊
vmess=1.1.1.1:8080, method=auto, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, tag=测试 2␊
vmess=1.1.1.1:8080, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1␊
vmess=1.1.1.1:8080, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, tag=测试 2␊
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␊
Expand Down
Binary file modified test/snapshots/cli.test.ts.snap
Binary file not shown.
26 changes: 22 additions & 4 deletions test/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ShadowsocksrNodeConfig,
SimpleNodeConfig,
VmessNodeConfig,
SnellNodeConfig,
} from '../../lib/types';
import * as utils from '../../lib/utils';
import * as filter from '../../lib/utils/filter';
Expand Down Expand Up @@ -137,7 +138,7 @@ test('getNodeNames', async t => {
});

test('getClashNodes', async t => {
const nodeList: ReadonlyArray<ShadowsocksNodeConfig|VmessNodeConfig> = [{
const nodeList: ReadonlyArray<ShadowsocksNodeConfig|VmessNodeConfig|SnellNodeConfig> = [{
nodeName: 'Test Node 1',
type: NodeTypeEnum.Shadowsocks,
hostname: 'example.com',
Expand Down Expand Up @@ -178,6 +179,13 @@ test('getClashNodes', async t => {
tls: false,
type: NodeTypeEnum.Vmess,
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
}, {
nodeName: 'snell',
type: NodeTypeEnum.Snell,
hostname: '1.1.1.1',
port: 443,
psk: 'psk',
obfs: 'tls',
}];
const array = utils.getClashNodes(nodeList);

Expand Down Expand Up @@ -229,6 +237,16 @@ test('getClashNodes', async t => {
type: 'vmess',
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
});
t.deepEqual(array[4], {
name: 'snell',
type: 'snell',
server: '1.1.1.1',
port: 443,
psk: 'psk',
'obfs-opts': {
mode: 'tls',
},
})
});

test('getShadowsocksNodes', async t => {
Expand Down Expand Up @@ -729,9 +747,9 @@ test('getQuantumultXNodes', t => {
])
.split('\n');

t.is(schemeList[0], 'vmess=1.1.1.1:8080, method=auto, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1');
t.is(schemeList[1], 'vmess=1.1.1.1:8080, method=auto, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, tag=测试 2');
t.is(schemeList[2], 'vmess=1.1.1.1:8080, method=auto, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=1.1.1.1, tag=测试 3');
t.is(schemeList[0], 'vmess=1.1.1.1:8080, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=example.com, tag=测试 1');
t.is(schemeList[1], 'vmess=1.1.1.1:8080, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, tag=测试 2');
t.is(schemeList[2], 'vmess=1.1.1.1:8080, password=1386f85e-657b-4d6e-9d56-78badb75e1fd, udp-relay=true, obfs=ws, obfs-uri=/, obfs-host=1.1.1.1, tag=测试 3');
t.is(schemeList[3], 'shadowsocks=hk.example.com:10000, method=chacha20-ietf, password=password, ssr-protocol=auth_aes128_md5, ssr-protocol-param=, obfs=tls1.2_ticket_auth, obfs-host=music.163.com, tag=🇭🇰HK');
t.is(schemeList[4], 'http=a.com:443, username=snsms, password=nndndnd, over-tls=true, tag=test');
t.is(schemeList[5], 'shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇺🇸US 1');
Expand Down

0 comments on commit 8c3df9e

Please sign in to comment.