Skip to content

Commit 704dbc3

Browse files
committed
update and imporvement and fix bugs
1 parent 086a855 commit 704dbc3

24 files changed

+310
-408
lines changed

docs/hiddifyrpc.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- [v2/hcore/hcore.proto](#v2_hcore_hcore-proto)
1515
- [ChangeHiddifySettingsRequest](#hcore-ChangeHiddifySettingsRequest)
16+
- [CloseRequest](#hcore-CloseRequest)
1617
- [CoreInfoResponse](#hcore-CoreInfoResponse)
1718
- [GenerateConfigRequest](#hcore-GenerateConfigRequest)
1819
- [GenerateConfigResponse](#hcore-GenerateConfigResponse)
@@ -24,7 +25,6 @@
2425
- [OutboundInfo](#hcore-OutboundInfo)
2526
- [ParseRequest](#hcore-ParseRequest)
2627
- [ParseResponse](#hcore-ParseResponse)
27-
- [PauseRequest](#hcore-PauseRequest)
2828
- [SelectOutboundRequest](#hcore-SelectOutboundRequest)
2929
- [SetSystemProxyEnabledRequest](#hcore-SetSystemProxyEnabledRequest)
3030
- [SetupRequest](#hcore-SetupRequest)
@@ -243,6 +243,21 @@
243243

244244

245245

246+
<a name="hcore-CloseRequest"></a>
247+
248+
### CloseRequest
249+
250+
251+
252+
| Field | Type | Label | Description |
253+
| ----- | ---- | ----- | ----------- |
254+
| mode | [SetupMode](#hcore-SetupMode) | | |
255+
256+
257+
258+
259+
260+
246261
<a name="hcore-CoreInfoResponse"></a>
247262

248263
### CoreInfoResponse
@@ -447,21 +462,6 @@
447462

448463

449464

450-
<a name="hcore-PauseRequest"></a>
451-
452-
### PauseRequest
453-
454-
455-
456-
| Field | Type | Label | Description |
457-
| ----- | ---- | ----- | ----------- |
458-
| mode | [SetupMode](#hcore-SetupMode) | | |
459-
460-
461-
462-
463-
464-
465465
<a name="hcore-SelectOutboundRequest"></a>
466466

467467
### SelectOutboundRequest
@@ -783,7 +783,7 @@ Define the message equivalent of SetupParameters
783783
| GetSystemProxyStatus | [.hcommon.Empty](#hcommon-Empty) | [SystemProxyStatus](#hcore-SystemProxyStatus) | |
784784
| SetSystemProxyEnabled | [SetSystemProxyEnabledRequest](#hcore-SetSystemProxyEnabledRequest) | [.hcommon.Response](#hcommon-Response) | |
785785
| LogListener | [.hcommon.Empty](#hcommon-Empty) | [LogMessage](#hcore-LogMessage) stream | |
786-
| Pause | [PauseRequest](#hcore-PauseRequest) | [.hcommon.Empty](#hcommon-Empty) | |
786+
| Close | [CloseRequest](#hcore-CloseRequest) | [.hcommon.Empty](#hcommon-Empty) | |
787787

788788

789789

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ require (
173173
github.com/sagernet/sing-shadowsocks v0.2.8 // indirect
174174
github.com/sagernet/sing-shadowsocks2 v0.2.1 // indirect
175175
github.com/sagernet/sing-shadowtls v0.2.1-0.20250503051639-fcd445d33c11 // indirect
176-
github.com/sagernet/sing-tun v0.8.0-beta.12
176+
github.com/sagernet/sing-tun v0.8.0-beta.12 // indirect
177177
github.com/sagernet/sing-vmess v0.2.8-0.20250909125414-3aed155119a1 // indirect
178178
github.com/sagernet/smux v1.5.50-sing-box-mod.1 // indirect
179179
github.com/sagernet/wireguard-go v0.0.2-beta.1.0.20250917110311-16510ac47288 // indirect
@@ -207,7 +207,7 @@ require (
207207
github.com/sagernet/sing-box v1.13.0
208208
)
209209

210-
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20260131205637-f075aba2dbc7
210+
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.9-0.20260201231246-98f27edbe59d
211211

212212
// replace github.com/sagernet/sing-box => ../../h-sing-box
213213

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N
287287
github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo=
288288
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb h1:PGufWXXDq9yaev6xX1YQauaO1MV90e6Mpoq1I7Lz/VM=
289289
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb/go.mod h1:QiyDdbZLaJ/mZP4Zwc9g2QsfaEA4o7XvvgZegSci5/E=
290-
github.com/hiddify/hiddify-sing-box v1.8.9-0.20260131205637-f075aba2dbc7 h1:iPU6L3P7RIs60G4NxVBQAdt3QMiBfyPthK71T6oxHA8=
291-
github.com/hiddify/hiddify-sing-box v1.8.9-0.20260131205637-f075aba2dbc7/go.mod h1:cXDQteIVhnQMAQUL2Bh7EZ0e3rkyyMV/ad05i4Rio/o=
290+
github.com/hiddify/hiddify-sing-box v1.8.9-0.20260201231246-98f27edbe59d h1:IrHp0LBzYt4gTzvdvXtnlPN6qgV+40M9VigjYt00NEE=
291+
github.com/hiddify/hiddify-sing-box v1.8.9-0.20260201231246-98f27edbe59d/go.mod h1:cXDQteIVhnQMAQUL2Bh7EZ0e3rkyyMV/ad05i4Rio/o=
292292
github.com/hiddify/ray2sing v0.0.0-20260131164420-b2c6a6892ca6 h1:Pjaa53eZgaCPD92PiiHmCTMwbAIG4oJgLvD6iS6d4tA=
293293
github.com/hiddify/ray2sing v0.0.0-20260131164420-b2c6a6892ca6/go.mod h1:YzE/PUCa+UjE6pGYbtUrFNQfXZ9aOj7IpulYgvSyFUw=
294294
github.com/hiddify/warp-plus v0.0.0-20240717223357-4f3122e0d11d h1:vRGKh9ou+/vQGfVYa8MczhbIVjHxlP52OWwrDWO77RA=

v2/config/builder.go

Lines changed: 91 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
)
2222

2323
const (
24-
DNSRemoteTag = "dns-remote"
25-
DNSLocalTag = "dns-local"
26-
DNSStaticTag = "dns-static"
27-
DNSDirectTag = "dns-direct"
24+
DNSRemoteTag = "dns-remote"
25+
DNSLocalTag = "dns-local"
26+
DNSStaticTag = "dns-static"
27+
DNSDirectTag = "dns-direct"
28+
DNSRemoteNoWarpTag = "dns-remote-no-warp"
2829
// DNSBlockTag = "dns-block"
2930
DNSFakeTag = "dns-fake"
3031
DNSTricksDirectTag = "dns-trick-direct"
@@ -36,16 +37,18 @@ const (
3637
OutboundURLTestTag = "auto"
3738
OutboundDNSTag = "dns-out §hide§"
3839
OutboundDirectFragmentTag = "direct-fragment §hide§"
39-
WARPConfigTag = "Hiddify Warp ✅"
40+
41+
WARPConfigTag = "Hiddify Warp ✅"
4042

4143
InboundTUNTag = "tun-in"
4244
InboundMixedTag = "mixed-in"
4345
InboundDNSTag = "dns-in"
4446
)
4547

4648
var (
47-
OutboundMainProxyTag = OutboundSelectTag
48-
PredefinedOutboundTags = []string{OutboundDirectTag, OutboundBypassTag, OutboundSelectTag, OutboundURLTestTag, OutboundDNSTag, OutboundDirectFragmentTag}
49+
OutboundMainDetour = OutboundSelectTag
50+
OutboundWARPConfigDetour = OutboundDirectTag
51+
PredefinedOutboundTags = []string{OutboundDirectTag, OutboundBypassTag, OutboundSelectTag, OutboundURLTestTag, OutboundDNSTag, OutboundDirectFragmentTag, WARPConfigTag}
4952
)
5053

5154
// TODO include selectors
@@ -67,6 +70,7 @@ func BuildConfig(ctx context.Context, hopts *HiddifyOptions, inputOpt *ReadOptio
6770
setLog(&options, hopts)
6871
setInbound(&options, hopts)
6972
staticIPs := make(map[string][]string)
73+
// staticIPs["api.cloudflareclient.com"] = []string{"104.16.192.82", "2606:4700::6810:1854", getRandomWarpIP()}
7074
// setNTP(&options)
7175
if err := setOutbounds(&options, input, hopts, &staticIPs); err != nil {
7276
return nil, err
@@ -87,7 +91,9 @@ func setNTP(options *option.Options) {
8791
Enabled: true,
8892
ServerOptions: option.ServerOptions{ServerPort: 123, Server: "time.apple.com"},
8993
Interval: badoption.Duration(12 * time.Hour),
90-
DialerOptions: option.DialerOptions{},
94+
DialerOptions: option.DialerOptions{
95+
Detour: OutboundDirectTag,
96+
},
9197
}
9298
}
9399

@@ -108,33 +114,9 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp
108114
// OutboundMainProxyTag = OutboundSelectTag
109115
// inbound==warp over proxies
110116
// outbound==proxies over warp
111-
OutboundMainProxyTag = OutboundSelectTag
112-
if opt.Warp.EnableWarp && (opt.Warp.Mode == "warp_over_proxy" || opt.Warp.Mode == "proxy_over_warp") {
113-
// wg := getOrGenerateWarpLocallyIfNeeded(&opt.Warp)
114-
115-
// out, err := GenerateWarpSingbox(wg, opt.Warp.CleanIP, opt.Warp.CleanPort, &option.WireGuardHiddify{
116-
// FakePackets: opt.Warp.FakePackets,
117-
// FakePacketsSize: opt.Warp.FakePacketSize,
118-
// FakePacketsDelay: opt.Warp.FakePacketDelay,
119-
// FakePacketsMode: opt.Warp.FakePacketMode,
120-
// })
121-
out, err := GenerateWarpSingboxNew("p1", &option.WireGuardHiddify{})
122-
if err != nil {
123-
return fmt.Errorf("failed to generate warp config: %v", err)
124-
}
125-
out.Tag = WARPConfigTag
126-
if opts, ok := out.Options.(*option.WireGuardEndpointOptions); ok {
127-
if opt.Warp.Mode == "warp_over_proxy" {
128-
opts.Detour = OutboundSelectTag
129-
} else {
130-
opts.Detour = OutboundDirectTag
131-
}
132-
}
117+
OutboundMainDetour = OutboundSelectTag
118+
OutboundWARPConfigDetour = OutboundDirectFragmentTag
133119

134-
OutboundMainProxyTag = WARPConfigTag
135-
// patchWarp(out, opt, true, nil)
136-
endpoints = append(endpoints, *out)
137-
}
138120
for _, out := range input.Outbounds {
139121
if contains(PredefinedOutboundTags, out.Tag) {
140122
continue
@@ -160,11 +142,47 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp
160142
if !strings.Contains(out.Tag, "§hide§") {
161143
tags = append(tags, out.Tag)
162144
}
145+
OutboundWARPConfigDetour = OutboundSelectTag
163146
out = *patchHiddifyWarpFromConfig(&out, *opt)
164147
outbounds = append(outbounds, out)
165148
}
166149
}
150+
151+
if opt.Warp.EnableWarp {
152+
// wg := getOrGenerateWarpLocallyIfNeeded(&opt.Warp)
153+
154+
// out, err := GenerateWarpSingbox(wg, opt.Warp.CleanIP, opt.Warp.CleanPort, &option.WireGuardHiddify{
155+
// FakePackets: opt.Warp.FakePackets,
156+
// FakePacketsSize: opt.Warp.FakePacketSize,
157+
// FakePacketsDelay: opt.Warp.FakePacketDelay,
158+
// FakePacketsMode: opt.Warp.FakePacketMode,
159+
// })
160+
out, err := GenerateWarpSingboxNew("p1", &option.WireGuardHiddify{})
161+
if err != nil {
162+
return fmt.Errorf("failed to generate warp config: %v", err)
163+
}
164+
out.Tag = WARPConfigTag
165+
if opts, ok := out.Options.(*option.WireGuardWARPEndpointOptions); ok {
166+
if opt.Warp.Mode == "warp_over_proxy" {
167+
opts.Detour = OutboundSelectTag
168+
} else {
169+
opts.Detour = OutboundDirectTag
170+
}
171+
172+
}
173+
174+
OutboundMainDetour = WARPConfigTag
175+
// patchWarp(out, opt, true, nil)
176+
out, err = patchEndpoint(out, *opt, staticIPs)
177+
if err != nil {
178+
return err
179+
}
180+
endpoints = append(endpoints, *out)
181+
}
167182
for _, end := range input.Endpoints {
183+
if contains(PredefinedOutboundTags, end.Tag) {
184+
continue
185+
}
168186
if opt.Warp.EnableWarp {
169187
if end.Type == C.TypeWARP {
170188
if opts, ok := end.Options.(*option.WireGuardWARPEndpointOptions); ok {
@@ -180,12 +198,9 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp
180198
}
181199
}
182200
}
183-
if opt.Warp.Mode == "warp_over_proxy" && end.Tag == WARPConfigTag {
184-
continue
185-
}
186201
}
187202

188-
out, err := patchEndpoint(end, *opt, staticIPs)
203+
out, err := patchEndpoint(&end, *opt, staticIPs)
189204
if err != nil {
190205
return err
191206
}
@@ -314,34 +329,31 @@ func setLog(options *option.Options, opt *HiddifyOptions) {
314329
}
315330
}
316331

317-
func setInbound(options *option.Options, opt *HiddifyOptions) {
318-
var inboundDomainStrategy option.DomainStrategy
319-
if !opt.ResolveDestination {
320-
inboundDomainStrategy = option.DomainStrategy(dns.DomainStrategyAsIS)
321-
} else {
322-
inboundDomainStrategy = opt.IPv6Mode
323-
}
324-
if opt.EnableTun {
332+
func setInbound(options *option.Options, hopt *HiddifyOptions) {
333+
// var inboundDomainStrategy option.DomainStrategy
334+
// if !opt.ResolveDestination {
335+
// inboundDomainStrategy = option.DomainStrategy(dns.DomainStrategyAsIS)
336+
// } else {
337+
// inboundDomainStrategy = opt.IPv6Mode
338+
// }
339+
340+
if hopt.EnableTun {
325341
opts := option.TunInboundOptions{
326-
Stack: opt.TUNStack,
327-
MTU: opt.MTU,
328-
AutoRoute: true,
329-
StrictRoute: opt.StrictRoute,
330-
EndpointIndependentNat: true,
342+
Stack: hopt.TUNStack,
343+
MTU: hopt.MTU,
344+
AutoRoute: true,
345+
StrictRoute: hopt.StrictRoute,
346+
// EndpointIndependentNat: true,
331347
// GSO: runtime.GOOS != "windows",
332-
InboundOptions: option.InboundOptions{
333-
SniffEnabled: true,
334-
SniffOverrideDestination: false,
335-
DomainStrategy: inboundDomainStrategy,
336-
},
348+
337349
}
338350
tunInbound := option.Inbound{
339351
Type: C.TypeTun,
340352
Tag: InboundTUNTag,
341353

342354
Options: &opts,
343355
}
344-
switch opt.IPv6Mode {
356+
switch hopt.IPv6Mode {
345357
case option.DomainStrategy(dns.DomainStrategyUseIPv4):
346358
opts.Address = []netip.Prefix{
347359
netip.MustParsePrefix("172.19.0.1/28"),
@@ -362,7 +374,7 @@ func setInbound(options *option.Options, opt *HiddifyOptions) {
362374
}
363375

364376
var bind string
365-
if opt.AllowConnectionFromLAN {
377+
if hopt.AllowConnectionFromLAN {
366378
bind = "0.0.0.0"
367379
} else {
368380
bind = "127.0.0.1"
@@ -377,14 +389,14 @@ func setInbound(options *option.Options, opt *HiddifyOptions) {
377389
Options: &option.HTTPMixedInboundOptions{
378390
ListenOptions: option.ListenOptions{
379391
Listen: &addr,
380-
ListenPort: opt.MixedPort,
392+
ListenPort: hopt.MixedPort,
381393
// InboundOptions: option.InboundOptions{
382394
// SniffEnabled: true,
383395
// SniffOverrideDestination: true,
384396
// DomainStrategy: inboundDomainStrategy,
385397
// },
386398
},
387-
SetSystemProxy: opt.SetSystemProxy,
399+
SetSystemProxy: hopt.SetSystemProxy,
388400
},
389401
},
390402
)
@@ -397,7 +409,7 @@ func setInbound(options *option.Options, opt *HiddifyOptions) {
397409
Options: &option.DirectInboundOptions{
398410
ListenOptions: option.ListenOptions{
399411
Listen: &addr,
400-
ListenPort: opt.LocalDnsPort,
412+
ListenPort: hopt.LocalDnsPort,
401413
},
402414
// OverrideAddress: "1.1.1.1",
403415
// OverridePort: 53,
@@ -452,6 +464,7 @@ func setRoutingOptions(options *option.Options, hopt *HiddifyOptions) error {
452464
if err != nil {
453465
return err
454466
}
467+
455468
dnsRules = append(dnsRules, forceDirectRules...)
456469

457470
if len(hopt.ConnectionTestUrls) > 0 { //To avoid dns bug when using urltest
@@ -475,6 +488,17 @@ func setRoutingOptions(options *option.Options, hopt *HiddifyOptions) error {
475488
})
476489
}
477490
}
491+
dnsRules = append(dnsRules, option.DefaultDNSRule{
492+
RawDefaultDNSRule: option.RawDefaultDNSRule{
493+
Domain: []string{"api.cloudflareclient.com"},
494+
},
495+
DNSRuleAction: option.DNSRuleAction{
496+
Action: C.RuleActionTypeRoute,
497+
RouteOptions: option.DNSRouteActionOptions{
498+
Server: DNSRemoteNoWarpTag,
499+
},
500+
},
501+
})
478502
if ipinfoDomains := ipinfo.GetAllIPCheckerDomainsDomains(); len(ipinfoDomains) > 0 { //To avoid dns bug when using urltest
479503
dnsRules = append(dnsRules, option.DefaultDNSRule{
480504
RawDefaultDNSRule: option.RawDefaultDNSRule{
@@ -522,7 +546,7 @@ func setRoutingOptions(options *option.Options, hopt *HiddifyOptions) error {
522546
RuleAction: option.RuleAction{
523547
Action: C.RuleActionTypeRoute,
524548
RouteOptions: option.RouteActionOptions{
525-
Outbound: OutboundMainProxyTag,
549+
Outbound: OutboundMainDetour,
526550
},
527551
},
528552
},
@@ -835,14 +859,15 @@ func setRoutingOptions(options *option.Options, hopt *HiddifyOptions) error {
835859
}
836860
options.Route = &option.RouteOptions{
837861
Rules: routeRules,
838-
Final: OutboundMainProxyTag,
839-
AutoDetectInterface: hopt.EnableTun || hopt.EnableTunService,
862+
Final: OutboundMainDetour,
863+
AutoDetectInterface: (!C.IsAndroid) && (hopt.EnableTun || hopt.EnableTunService),
840864
DefaultDomainResolver: &option.DomainResolveOptions{
841865
Server: DNSDirectTag,
842866
Strategy: hopt.DirectDnsDomainStrategy,
843867
},
844-
// OverrideAndroidVPN: true,
845-
RuleSet: rulesets,
868+
// OverrideAndroidVPN: hopt.EnableTun && C.IsAndroid,
869+
RuleSet: rulesets,
870+
FindProcess: false,
846871
// GeoIP: &option.GeoIPOptions{
847872
// Path: opt.GeoIPPath,
848873
// },

0 commit comments

Comments
 (0)