mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
43 lines
801 B
Go
43 lines
801 B
Go
package shadowsocks
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
M "github.com/sagernet/sing/common/metadata"
|
|
"github.com/sagernet/sing/protocol/socks"
|
|
)
|
|
|
|
type Service interface {
|
|
M.TCPConnectionHandler
|
|
}
|
|
|
|
type MultiUserService interface {
|
|
Service
|
|
AddUser(key []byte)
|
|
RemoveUser(key []byte)
|
|
}
|
|
|
|
type Handler interface {
|
|
M.TCPConnectionHandler
|
|
}
|
|
|
|
type NoneService struct {
|
|
handler Handler
|
|
}
|
|
|
|
func NewNoneService(handler Handler) Service {
|
|
return &NoneService{
|
|
handler: handler,
|
|
}
|
|
}
|
|
|
|
func (s *NoneService) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
|
|
destination, err := socks.AddressSerializer.ReadAddrPort(conn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
metadata.Protocol = "shadowsocks"
|
|
metadata.Destination = destination
|
|
return s.handler.NewConnection(ctx, conn, metadata)
|
|
}
|