Add ssm api server

This commit is contained in:
世界
2023-02-18 16:26:05 +08:00
parent ec4a0c8497
commit d34091f8fc
20 changed files with 938 additions and 26 deletions

View File

@@ -3,4 +3,5 @@ package option
type ExperimentalOptions struct {
ClashAPI *ClashAPIOptions `json:"clash_api,omitempty"`
V2RayAPI *V2RayAPIOptions `json:"v2ray_api,omitempty"`
SSMAPI *SSMAPIOptions `json:"ssm_api,omitempty"`
}

View File

@@ -7,6 +7,7 @@ type ShadowsocksInboundOptions struct {
Password string `json:"password"`
Users []ShadowsocksUser `json:"users,omitempty"`
Destinations []ShadowsocksDestination `json:"destinations,omitempty"`
Managed bool `json:"managed,omitempty"`
}
type ShadowsocksUser struct {

54
option/ssmapi.go Normal file
View File

@@ -0,0 +1,54 @@
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
E "github.com/sagernet/sing/common/exceptions"
)
type SSMAPIOptions struct {
Listen string `json:"listen,omitempty"`
ListenPrefix string `json:"listen_prefix,omitempty"`
Nodes []SSMNode `json:"nodes,omitempty"`
}
type _SSMNode struct {
Type string `json:"type,omitempty"`
ShadowsocksOptions SSMShadowsocksNode `json:"-"`
}
type SSMNode _SSMNode
func (h SSMNode) MarshalJSON() ([]byte, error) {
var v any
switch h.Type {
case C.TypeShadowsocks:
v = h.ShadowsocksOptions
default:
return nil, E.New("unknown ssm node type: ", h.Type)
}
return MarshallObjects((_SSMNode)(h), v)
}
func (h *SSMNode) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, (*_SSMNode)(h))
if err != nil {
return err
}
var v any
switch h.Type {
case C.TypeShadowsocks:
v = &h.ShadowsocksOptions
default:
return E.New("unknown ssm node type: ", h.Type)
}
return UnmarshallExcluded(data, (*_SSMNode)(h), v)
}
type SSMShadowsocksNode struct {
ID string `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Tags []string `json:"tags"`
Inbound string `json:"inbound"`
}