Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: High-level boundary management interface #2180

Closed
beryll1um opened this issue Oct 15, 2024 · 2 comments
Closed

Feature: High-level boundary management interface #2180

beryll1um opened this issue Oct 15, 2024 · 2 comments
Labels

Comments

@beryll1um
Copy link

beryll1um commented Oct 15, 2024

I believe that any server-side management logic requires high-level boundary management interfaces to implement it. Manually restarting the service with a new configuration is not the best choice for a high-loaded environment where many users and protocols are handled.

Such interfaces are already implemented in v2fly/v2ray-core, but I find their implementation generally messy, so I prefer to switch to sing-box. Unfortunately, such functionality is not implemented there yet, as far as I understand...
I decided to implement this myself, so check out my contribution. I'm still working on it, but overall it's done and working fine as far as I can verify.

I have some suspicions that this might break something, because some experimental tools like the Clash API can get a pointer to outgoing connections to work with them separately, and during work time these outgoing connections can be removed from the router, but so far I haven't found any problems with this (doesn't means there is no of them).

Please check my pull request: #2177

@beryll1um
Copy link
Author

How it looks like at this time:

package main

import (
	"context"
	"net/netip"
	"time"

	"github.com/sagernet/sing-box"
	"github.com/sagernet/sing-box/option"

	C "github.com/sagernet/sing-box/constant"
)

func main() {
	boxInstance, err := box.New(box.Options{
		Context: context.TODO(),
		Options: option.Options{
			Inbounds: []option.Inbound{
				{
					Tag:  "shadowsocks",
					Type: C.TypeShadowsocks,
					ShadowsocksOptions: option.ShadowsocksInboundOptions{
						ListenOptions: option.ListenOptions{
							Listen:     option.NewListenAddress(netip.IPv4Unspecified()),
							ListenPort: 1024,
						},
						Method:   "chacha20-ietf-poly1305",
						Password: "1234567890",
					},
				},
			},
			Outbounds: []option.Outbound{
				{
					Tag:  "direct",
					Type: C.TypeDirect,
				},
			},
		},
	})
	if err != nil {
		panic(err)
	}
	if err := boxInstance.Start(); err != nil {
		panic(err)
	}
	time.Sleep(10 * time.Second)
	if err := boxInstance.RemoveOutbound("direct"); err != nil {
		panic(err)
	}
	time.Sleep(10 * time.Second)
	if err := boxInstance.RemoveInbound("shadowsocks"); err != nil {
		panic(err)
	}
	time.Sleep(10 * time.Second)
	if err := boxInstance.Close(); err != nil {
		panic(err)
	}
}

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Dec 17, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant