mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
update sing-box core v1.11
This commit is contained in:
@@ -13,9 +13,9 @@ import (
|
||||
"github.com/InazumaV/V2bX/api/panel"
|
||||
"github.com/InazumaV/V2bX/conf"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/sagernet/sing-box/inbound"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
"github.com/sagernet/sing/common/json/badoption"
|
||||
)
|
||||
|
||||
type HttpNetworkConfig struct {
|
||||
@@ -59,9 +59,9 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
domainStrategy = c.SingOptions.DomainStrategy
|
||||
}
|
||||
listen := option.ListenOptions{
|
||||
Listen: (*option.ListenAddress)(&addr),
|
||||
ListenPort: uint16(info.Common.ServerPort),
|
||||
TCPFastOpen: c.SingOptions.TCPFastOpen,
|
||||
Listen: (*badoption.Addr)(&addr),
|
||||
ListenPort: uint16(info.Common.ServerPort),
|
||||
TCPFastOpen: c.SingOptions.TCPFastOpen,
|
||||
InboundOptions: option.InboundOptions{
|
||||
SniffEnabled: c.SingOptions.SniffEnabled,
|
||||
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
||||
@@ -112,14 +112,14 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
Enabled: true,
|
||||
ShortID: []string{v.TlsSettings.ShortId},
|
||||
PrivateKey: v.TlsSettings.PrivateKey,
|
||||
Xver: uint8(v.TlsSettings.Xver),
|
||||
//Xver: uint8(v.TlsSettings.Xver),
|
||||
Handshake: option.InboundRealityHandshakeOptions{
|
||||
ServerOptions: option.ServerOptions{
|
||||
Server: dest,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
},
|
||||
MaxTimeDifference: option.Duration(mtd),
|
||||
MaxTimeDifference: badoption.Duration(mtd),
|
||||
}
|
||||
}
|
||||
in := option.Inbound{
|
||||
@@ -162,7 +162,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
var (
|
||||
path string
|
||||
ed int
|
||||
headers map[string]option.Listable[string]
|
||||
headers map[string]badoption.Listable[string]
|
||||
)
|
||||
if len(n.NetworkSettings) != 0 {
|
||||
network := WsNetworkConfig{}
|
||||
@@ -177,9 +177,9 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
}
|
||||
path = u.Path
|
||||
ed, _ = strconv.Atoi(u.Query().Get("ed"))
|
||||
headers = make(map[string]option.Listable[string], len(network.Headers))
|
||||
headers = make(map[string]badoption.Listable[string], len(network.Headers))
|
||||
for k, v := range network.Headers {
|
||||
headers[k] = option.Listable[string]{
|
||||
headers[k] = badoption.Listable[string]{
|
||||
v,
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
}
|
||||
if info.Type == "vless" {
|
||||
in.Type = "vless"
|
||||
in.VLESSOptions = option.VLESSInboundOptions{
|
||||
in.Options = &option.VLESSInboundOptions{
|
||||
ListenOptions: listen,
|
||||
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
||||
TLS: &tls,
|
||||
@@ -226,7 +226,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
}
|
||||
} else {
|
||||
in.Type = "vmess"
|
||||
in.VMessOptions = option.VMessInboundOptions{
|
||||
in.Options = &option.VMessInboundOptions{
|
||||
ListenOptions: listen,
|
||||
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
||||
TLS: &tls,
|
||||
@@ -247,7 +247,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
default:
|
||||
keyLength = 16
|
||||
}
|
||||
in.ShadowsocksOptions = option.ShadowsocksInboundOptions{
|
||||
ssoption := &option.ShadowsocksInboundOptions{
|
||||
ListenOptions: listen,
|
||||
Method: n.Cipher,
|
||||
Multiplex: multiplex,
|
||||
@@ -256,12 +256,13 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
_, _ = rand.Read(p)
|
||||
randomPasswd := string(p)
|
||||
if strings.Contains(n.Cipher, "2022") {
|
||||
in.ShadowsocksOptions.Password = n.ServerKey
|
||||
ssoption.Password = n.ServerKey
|
||||
randomPasswd = base64.StdEncoding.EncodeToString([]byte(randomPasswd))
|
||||
}
|
||||
in.ShadowsocksOptions.Users = []option.ShadowsocksUser{{
|
||||
ssoption.Users = []option.ShadowsocksUser{{
|
||||
Password: randomPasswd,
|
||||
}}
|
||||
in.Options = ssoption
|
||||
case "trojan":
|
||||
n := info.Trojan
|
||||
t := option.V2RayTransportOptions{
|
||||
@@ -274,7 +275,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
var (
|
||||
path string
|
||||
ed int
|
||||
headers map[string]option.Listable[string]
|
||||
headers map[string]badoption.Listable[string]
|
||||
)
|
||||
if len(n.NetworkSettings) != 0 {
|
||||
network := WsNetworkConfig{}
|
||||
@@ -289,9 +290,9 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
}
|
||||
path = u.Path
|
||||
ed, _ = strconv.Atoi(u.Query().Get("ed"))
|
||||
headers = make(map[string]option.Listable[string], len(network.Headers))
|
||||
headers = make(map[string]badoption.Listable[string], len(network.Headers))
|
||||
for k, v := range network.Headers {
|
||||
headers[k] = option.Listable[string]{
|
||||
headers[k] = badoption.Listable[string]{
|
||||
v,
|
||||
}
|
||||
}
|
||||
@@ -317,7 +318,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
t.Type = ""
|
||||
}
|
||||
in.Type = "trojan"
|
||||
in.TrojanOptions = option.TrojanInboundOptions{
|
||||
trojanoption := &option.TrojanInboundOptions{
|
||||
ListenOptions: listen,
|
||||
InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
|
||||
TLS: &tls,
|
||||
@@ -330,7 +331,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
fallback := c.SingOptions.FallBackConfigs.FallBack
|
||||
fallbackPort, err := strconv.Atoi(fallback.ServerPort)
|
||||
if err == nil {
|
||||
in.TrojanOptions.Fallback = &option.ServerOptions{
|
||||
trojanoption.Fallback = &option.ServerOptions{
|
||||
Server: fallback.Server,
|
||||
ServerPort: uint16(fallbackPort),
|
||||
}
|
||||
@@ -338,12 +339,13 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
fallbackForALPNMap := c.SingOptions.FallBackConfigs.FallBackForALPN
|
||||
fallbackForALPN := make(map[string]*option.ServerOptions, len(fallbackForALPNMap))
|
||||
if err := processFallback(c, fallbackForALPN); err == nil {
|
||||
in.TrojanOptions.FallbackForALPN = fallbackForALPN
|
||||
trojanoption.FallbackForALPN = fallbackForALPN
|
||||
}
|
||||
}
|
||||
in.Options = trojanoption
|
||||
case "hysteria":
|
||||
in.Type = "hysteria"
|
||||
in.HysteriaOptions = option.HysteriaInboundOptions{
|
||||
in.Options = &option.HysteriaInboundOptions{
|
||||
ListenOptions: listen,
|
||||
UpMbps: info.Hysteria.UpMbps,
|
||||
DownMbps: info.Hysteria.DownMbps,
|
||||
@@ -366,7 +368,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
Password: info.Hysteria2.ObfsType,
|
||||
}
|
||||
}
|
||||
in.Hysteria2Options = option.Hysteria2InboundOptions{
|
||||
in.Options = &option.Hysteria2InboundOptions{
|
||||
ListenOptions: listen,
|
||||
UpMbps: info.Hysteria2.UpMbps,
|
||||
DownMbps: info.Hysteria2.DownMbps,
|
||||
@@ -380,32 +382,20 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
||||
}
|
||||
|
||||
func (b *Sing) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||
err := updateDNSConfig(info)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build dns error: %s", err)
|
||||
}
|
||||
c, err := getInboundOptions(tag, info, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
in, err := inbound.New(
|
||||
in := b.box.Inbound()
|
||||
err = in.Create(
|
||||
b.ctx,
|
||||
b.box.Router(),
|
||||
b.logFactory.NewLogger(F.ToString("inbound/", c.Type, "[", tag, "]")),
|
||||
tag,
|
||||
c,
|
||||
nil,
|
||||
c.Type,
|
||||
c.Options,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("init inbound error: %s", err)
|
||||
}
|
||||
err = in.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("start inbound error: %s", err)
|
||||
}
|
||||
b.inbounds[tag] = in
|
||||
err = b.router.AddInbound(in)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("add inbound error: %s", err)
|
||||
}
|
||||
@@ -413,11 +403,8 @@ func (b *Sing) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) e
|
||||
}
|
||||
|
||||
func (b *Sing) DelNode(tag string) error {
|
||||
err := b.inbounds[tag].Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("close inbound error: %s", err)
|
||||
}
|
||||
err = b.router.DelInbound(tag)
|
||||
in := b.box.Inbound()
|
||||
err := in.Remove(tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete inbound error: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user