Skip to content

Commit

Permalink
fix: bugs and issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 13, 2024
1 parent c3cef78 commit 2ddd095
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "./",
"program": "./htest/libbox",
"buildFlags": "-tags with_clash_api,with_gvisor,with_quic,with_wireguard,with_grpc,with_ech,with_utls,with_reality_server"
}
]
}
5 changes: 4 additions & 1 deletion experimental/libbox/command_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func NewCommandServer(handler CommandServerHandler, maxLines int32) *CommandServ
func (s *CommandServer) SetService(newService *BoxService) {
if newService != nil {
service.PtrFromContext[urltest.HistoryStorage](newService.ctx).SetHook(s.urlTestUpdate)
newService.instance.Router().ClashServer().(*clashapi.Server).SetModeUpdateHook(s.modeUpdate)

if clashServer := newService.instance.Router().ClashServer(); clashServer != nil {
newService.instance.Router().ClashServer().(*clashapi.Server).SetModeUpdateHook(s.modeUpdate)
}
s.savedLines.Init()
select {
case s.logReset <- struct{}{}:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ replace github.com/sagernet/sing-box/outbound/houtbound => ./outbound/houtbound

replace github.com/sagernet/sing-box/option => ./option

replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06 h1:2G/TlKV/b7uFk7OOcwmrrvG4qvm2no7P5yqir82raFo=
github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081 h1:6YD1152LOhf/TFx0TlxTUqd0ZFVVHYmL6m3FR5njJjU=
github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b h1:1+115FqGoS8p6Iry9AYmrcWDvSveH0F7P2nX1LU00qg=
github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b/go.mod h1:XCscqBi1KKh7GcVDDAdkT/Cf6WDjnDAA1XM3nwmA0Ag=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down
78 changes: 71 additions & 7 deletions htest/libbox/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (

func main() {
options := option.Options{}
content, err := os.ReadFile("./hconfigs/full.json")
content, err := os.ReadFile("./htest/warp.json")
json.Unmarshal(content, &options)
fmt.Println(string(content))
libbox.Setup("./hconfigs/", "./hconfigs/", "./hconfigs/", true)
libbox.Setup("./htest/", "./htest/", "./htest/tmp/", true)
ctx, cancel := context.WithCancel(context.Background())
ctx = filemanager.WithDefault(ctx, "./hconfigs/", "./hconfigs/", os.Getuid(), os.Getgid())
ctx = filemanager.WithDefault(ctx, "./htest/", "./htest/tmp/", os.Getuid(), os.Getgid())
urlTestHistoryStorage := urltest.NewHistoryStorage()
ctx = service.ContextWithPtr(ctx, urlTestHistoryStorage)

Expand All @@ -39,17 +39,17 @@ func main() {
}
commandServer = libbox.NewCommandServer(&CommandServerHandler{}, 100)
commandServer.Start()
service := libbox.NewBoxService(
libservice := libbox.NewBoxService(
ctx,
cancel,
instance,
service.FromContext[pause.Manager](ctx),
urlTestHistoryStorage,
)
// instance.Start()
service.Start()
libservice.Start()

commandServer.SetService(&service)
commandServer.SetService(&libservice)
<-time.Tick(1 * time.Second)
fmt.Println("command group update")

Expand All @@ -59,7 +59,7 @@ func main() {
},
&libbox.CommandClientOptions{
Command: libbox.CommandGroupInfoOnly,
StatusInterval: 3000000000, //300ms debounce
StatusInterval: 300000000, //300ms debounce
},
)
groupInfoOnlyClient.Connect()
Expand All @@ -69,9 +69,71 @@ func main() {
},
&libbox.CommandClientOptions{
Command: libbox.CommandGroup,
StatusInterval: 300000000, //300ms debounce
},
)
groupClient.Connect()
for i := 0; i < 4; i++ {
<-time.Tick(1000 * time.Millisecond)
fmt.Println("selecting auto")
libbox.NewStandaloneCommandClient().SelectOutbound("Select", "Auto")
<-time.Tick(1000 * time.Millisecond)
fmt.Println("selecting outbound")
libbox.NewStandaloneCommandClient().SelectOutbound("Select", "test")
}
fmt.Println("===========Finished many bounce")
<-time.Tick(2000 * time.Millisecond)
fmt.Println("===========selecting final auto")
libbox.NewStandaloneCommandClient().SelectOutbound("Select", "Auto")

instance.Close()
instance.Close()
libservice.Close()
commandServer.Close()
<-time.After(1 * time.Second)
options = option.Options{}
content, err = os.ReadFile("./htest/yebekhe.json")
json.Unmarshal(content, &options)
fmt.Println(string(content))
libbox.Setup("./htest/", "./htest/", "./htest/", true)

urlTestHistoryStorage = urltest.NewHistoryStorage()

instance, err = B.New(B.Options{
Context: ctx,
Options: options,
})
if err != nil {
cancel()
return
}
commandServer = libbox.NewCommandServer(&CommandServerHandler{}, 100)
commandServer.Start()
libservice = libbox.NewBoxService(
ctx,
cancel,
instance,
service.FromContext[pause.Manager](ctx),
urlTestHistoryStorage,
)
// instance.Start()
libservice.Start()

commandServer.SetService(&libservice)
<-time.Tick(1 * time.Second)
fmt.Println("command group update")

groupInfoOnlyClient = libbox.NewCommandClient(
&CommandClientHandler{
logger: log.NewNOPFactory().NewLogger("[GroupInfoOnly Command Client]"),
},
&libbox.CommandClientOptions{
Command: libbox.CommandGroupInfoOnly,
StatusInterval: 3000000000, //300ms debounce
},
)
groupInfoOnlyClient.Connect()

groupClient.Connect()
for i := 0; i < 4; i++ {
<-time.Tick(1000 * time.Millisecond)
Expand All @@ -86,6 +148,8 @@ func main() {
fmt.Println("===========selecting final auto")
libbox.NewStandaloneCommandClient().SelectOutbound("Select", "Auto")

libservice.Close()

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, os.Kill)
<-sigCh
Expand Down
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ require (
lukechampine.com/blake3 v1.2.1 // indirect
)

replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081
4 changes: 2 additions & 2 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06 h1:2G/TlKV/b7uFk7OOcwmrrvG4qvm2no7P5yqir82raFo=
github.com/hiddify/wireguard-go v0.0.0-20240213080057-78b635f7ef06/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081 h1:6YD1152LOhf/TFx0TlxTUqd0ZFVVHYmL6m3FR5njJjU=
github.com/hiddify/wireguard-go v0.0.0-20240213121818-b8b1209e6081/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b h1:1+115FqGoS8p6Iry9AYmrcWDvSveH0F7P2nX1LU00qg=
github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b/go.mod h1:XCscqBi1KKh7GcVDDAdkT/Cf6WDjnDAA1XM3nwmA0Ag=
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2 h1:9K06NfxkBh25x56yVhWWlKFE8YpicaSfHwoV8SFbueA=
Expand Down

0 comments on commit 2ddd095

Please sign in to comment.