-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmod.test.ts
More file actions
161 lines (150 loc) · 3.63 KB
/
mod.test.ts
File metadata and controls
161 lines (150 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { createDnsServer } from './dns.ts'
import { createInbound } from './inbound.ts'
import { createTypebox } from './mod.ts'
import { createOutbound, createOutbounds } from './outbound.ts'
import { createRule, createRuleSet } from './route.ts'
const rule_set_block = createRuleSet({
tag: 'block',
type: 'remote',
format: 'binary',
url: '',
download_detour: 'direct-out',
})
const rule_set_proxy = createRuleSet({
tag: 'proxy',
type: 'remote',
format: 'binary',
url: '',
// download_detour: 'unkown-outbound',
})
const rule_set_direct = createRuleSet({
tag: 'direct',
type: 'remote',
format: 'binary',
url: '',
})
const ali_dns = createDnsServer({
tag: 'ali-dns',
type: 'https',
server: '223.5.5.5',
})
const fakeip = createDnsServer({
tag: 'fakeip',
type: 'fakeip',
inet4_range: '198.18.0.0/15',
inet6_range: 'fc00::/18',
})
const block_dns = createDnsServer({
tag: 'block-dns',
address: 'rcode://success',
})
const tun_in = createInbound({
tag: 'tun-in',
type: 'tun',
interface_name: 'sing-box',
address: ['172.19.0.1/30', 'fdfe:dcba:9876::1/126'],
auto_route: true,
stack: 'system',
})
const direct_out = createOutbound({
tag: 'direct-out',
type: 'direct',
})
const ss_out = createOutbound({
tag: 'ss-out',
type: 'shadowsocks',
method: '2022-blake3-aes-128-gcm',
password: '',
server: '',
server_port: 0,
})
const final = createOutbound({
tag: 'final',
type: 'selector',
outbounds: ['direct-out', 'proxy'],
})
const proxy = createOutbound({
tag: 'proxy',
type: 'selector',
outbounds: ['ss-out', 'direct-out'],
})
const outbounds = createOutbounds([
final,
proxy,
direct_out,
ss_out,
])
const rule_hijack_dns = createRule({
port: 53,
action: 'hijack-dns',
})
const _c = createTypebox({
log: {
level: 'warn',
output: 'stdout',
},
dns: {
servers: [ali_dns, fakeip, block_dns],
rules: [
{
outbound: 'any',
server: ali_dns.tag,
},
{
rule_set: rule_set_block.tag,
server: block_dns.tag,
},
// { // This error is used to check type safety
// rule_set: 'unkown-rule-set',
// server: 'unkown-dns-server',
// },
{
rule_set: rule_set_direct.tag,
server: ali_dns.tag,
},
{
query_type: 'HTTPS',
rule_set: 'proxy',
server: block_dns.tag,
},
{
query_type: ['A', 'AAAA'],
rule_set: 'proxy',
server: fakeip.tag,
},
],
final: ali_dns.tag,
},
route: {
rule_set: [
rule_set_block,
rule_set_direct,
// Here will be an error when download_detour is 'unkown-outbound'
rule_set_proxy,
],
rules: [
rule_hijack_dns,
{
rule_set: 'block',
action: 'reject',
},
// { // This error is used to check type safety
// rule_set: 'unkown-rule-set',
// action: 'reject',
// },
{
rule_set: rule_set_direct.tag,
outbound: direct_out.tag,
},
{
rule_set: rule_set_proxy.tag,
outbound: 'proxy',
},
],
final: 'final',
},
inbounds: [
tun_in,
],
outbounds: outbounds,
})