mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-27 04:39:02 +03:00
Add ssm api server
This commit is contained in:
@@ -22,7 +22,7 @@ func NewShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte
|
||||
if len(options.Users) > 0 && len(options.Destinations) > 0 {
|
||||
return nil, E.New("users and destinations options must not be combined")
|
||||
}
|
||||
if len(options.Users) > 0 {
|
||||
if len(options.Users) > 0 || options.Managed {
|
||||
return newShadowsocksMulti(ctx, router, logger, tag, options)
|
||||
} else if len(options.Destinations) > 0 {
|
||||
return newShadowsocksRelay(ctx, router, logger, tag, options)
|
||||
@@ -32,8 +32,9 @@ func NewShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte
|
||||
}
|
||||
|
||||
var (
|
||||
_ adapter.Inbound = (*Shadowsocks)(nil)
|
||||
_ adapter.InjectableInbound = (*Shadowsocks)(nil)
|
||||
_ adapter.Inbound = (*Shadowsocks)(nil)
|
||||
_ adapter.InjectableInbound = (*Shadowsocks)(nil)
|
||||
_ adapter.ManagedShadowsocksServer = (*Shadowsocks)(nil)
|
||||
)
|
||||
|
||||
type Shadowsocks struct {
|
||||
@@ -76,6 +77,18 @@ func newShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *Shadowsocks) Method() string {
|
||||
return h.service.Name()
|
||||
}
|
||||
|
||||
func (h *Shadowsocks) Password() string {
|
||||
return h.service.Password()
|
||||
}
|
||||
|
||||
func (h *Shadowsocks) UpdateUsers(names []string, uPSKs []string) error {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
|
||||
func (h *Shadowsocks) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||
return h.service.NewConnection(adapter.WithContext(log.ContextWithNewID(ctx), &metadata), conn, adapter.UpstreamMetadata(metadata))
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ adapter.Inbound = (*ShadowsocksMulti)(nil)
|
||||
_ adapter.InjectableInbound = (*ShadowsocksMulti)(nil)
|
||||
_ adapter.Inbound = (*ShadowsocksMulti)(nil)
|
||||
_ adapter.InjectableInbound = (*ShadowsocksMulti)(nil)
|
||||
_ adapter.ManagedShadowsocksServer = (*ShadowsocksMulti)(nil)
|
||||
)
|
||||
|
||||
type ShadowsocksMulti struct {
|
||||
@@ -61,11 +62,13 @@ func newShadowsocksMulti(ctx context.Context, router adapter.Router, logger log.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = service.UpdateUsersWithPasswords(common.MapIndexed(options.Users, func(index int, user option.ShadowsocksUser) int {
|
||||
return index
|
||||
}), common.Map(options.Users, func(user option.ShadowsocksUser) string {
|
||||
return user.Password
|
||||
}))
|
||||
if len(options.Users) > 0 {
|
||||
err = service.UpdateUsersWithPasswords(common.MapIndexed(options.Users, func(index int, user option.ShadowsocksUser) int {
|
||||
return index
|
||||
}), common.Map(options.Users, func(user option.ShadowsocksUser) string {
|
||||
return user.Password
|
||||
}))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,6 +78,29 @@ func newShadowsocksMulti(ctx context.Context, router adapter.Router, logger log.
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *ShadowsocksMulti) Method() string {
|
||||
return h.service.Name()
|
||||
}
|
||||
|
||||
func (h *ShadowsocksMulti) Password() string {
|
||||
return h.service.Password()
|
||||
}
|
||||
|
||||
func (h *ShadowsocksMulti) UpdateUsers(users []string, uPSKs []string) error {
|
||||
err := h.service.UpdateUsersWithPasswords(common.MapIndexed(users, func(index int, user string) int {
|
||||
return index
|
||||
}), uPSKs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.users = common.Map(users, func(user string) option.ShadowsocksUser {
|
||||
return option.ShadowsocksUser{
|
||||
Name: user,
|
||||
}
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ShadowsocksMulti) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||
return h.service.NewConnection(adapter.WithContext(log.ContextWithNewID(ctx), &metadata), conn, adapter.UpstreamMetadata(metadata))
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ adapter.Inbound = (*ShadowsocksRelay)(nil)
|
||||
_ adapter.InjectableInbound = (*ShadowsocksRelay)(nil)
|
||||
_ adapter.Inbound = (*ShadowsocksRelay)(nil)
|
||||
_ adapter.InjectableInbound = (*ShadowsocksRelay)(nil)
|
||||
_ adapter.ManagedShadowsocksServer = (*ShadowsocksRelay)(nil)
|
||||
)
|
||||
|
||||
type ShadowsocksRelay struct {
|
||||
@@ -71,6 +72,18 @@ func newShadowsocksRelay(ctx context.Context, router adapter.Router, logger log.
|
||||
return inbound, err
|
||||
}
|
||||
|
||||
func (h *ShadowsocksRelay) Method() string {
|
||||
return h.service.Name()
|
||||
}
|
||||
|
||||
func (h *ShadowsocksRelay) Password() string {
|
||||
return h.service.Password()
|
||||
}
|
||||
|
||||
func (h *ShadowsocksRelay) UpdateUsers(users []string, uPSKs []string) error {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
|
||||
func (h *ShadowsocksRelay) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
||||
return h.service.NewConnection(adapter.WithContext(log.ContextWithNewID(ctx), &metadata), conn, adapter.UpstreamMetadata(metadata))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user