Cleanup code

This commit is contained in:
世界 2022-11-12 11:09:15 +08:00
parent 731a30d73b
commit e55284e180
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 39 additions and 0 deletions

View file

@ -194,6 +194,14 @@ func NewNoneService(udpTimeout int64, handler Handler) Service {
return s
}
func (s *NoneService) Name() string {
return MethodNone
}
func (s *NoneService) Password() string {
return ""
}
func (s *NoneService) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
destination, err := M.SocksaddrSerializer.ReadAddrPort(conn)
if err != nil {

View file

@ -32,6 +32,7 @@ type Service struct {
keySaltLength int
constructor func(key []byte) (cipher.AEAD, error)
key []byte
password string
handler shadowsocks.Handler
udpNat *udpnat.Service[netip.AddrPort]
}
@ -71,6 +72,14 @@ func NewService(method string, key []byte, password string, udpTimeout int64, ha
return s, nil
}
func (s *Service) Name() string {
return s.name
}
func (s *Service) Password() string {
return s.password
}
func (s *Service) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
err := s.newConnection(ctx, conn, metadata)
if err != nil {

View file

@ -23,6 +23,8 @@ import (
"lukechampine.com/blake3"
)
var _ shadowsocks.Service = (*RelayService[int])(nil)
type RelayService[U comparable] struct {
name string
keySaltLength int
@ -39,6 +41,14 @@ type RelayService[U comparable] struct {
udpNat *udpnat.Service[uint64]
}
func (s *RelayService[U]) Name() string {
return s.name
}
func (s *RelayService[U]) Password() string {
return base64.StdEncoding.EncodeToString(s.iPSK)
}
func (s *RelayService[U]) UpdateUsers(userList []U, keyList [][]byte, destinationList []M.Socksaddr) error {
uPSKHash := make(map[[aes.BlockSize]byte]U)
uDestination := make(map[U]M.Socksaddr)

View file

@ -36,6 +36,8 @@ var (
ErrBadPadding = E.New("bad request: damaged padding")
)
var _ shadowsocks.Service = (*Service)(nil)
type Service struct {
name string
keySaltLength int
@ -117,6 +119,14 @@ func NewService(method string, psk []byte, udpTimeout int64, handler shadowsocks
return s, nil
}
func (s *Service) Name() string {
return s.name
}
func (s *Service) Password() string {
return base64.StdEncoding.EncodeToString(s.psk)
}
func (s *Service) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
err := s.newConnection(ctx, conn, metadata)
if err != nil {

View file

@ -24,6 +24,8 @@ type Method interface {
}
type Service interface {
Name() string
Password() string
N.TCPConnectionHandler
N.UDPHandler
E.Handler