mirror of
https://github.com/nadoo/glider.git
synced 2025-02-24 01:45:39 +08:00
37 lines
694 B
Go
37 lines
694 B
Go
package obfs
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/nadoo/glider/proxy/ssr/internal/ssr"
|
|
)
|
|
|
|
type creator func() IObfs
|
|
|
|
var (
|
|
creatorMap = make(map[string]creator)
|
|
)
|
|
|
|
type IObfs interface {
|
|
SetServerInfo(s *ssr.ServerInfo)
|
|
GetServerInfo() (s *ssr.ServerInfo)
|
|
Encode(data []byte) (encodedData []byte, err error)
|
|
Decode(data []byte) (decodedData []byte, needSendBack bool, err error)
|
|
SetData(data any)
|
|
GetData() any
|
|
GetOverhead() int
|
|
}
|
|
|
|
func register(name string, c creator) {
|
|
creatorMap[name] = c
|
|
}
|
|
|
|
// NewObfs create an obfs object by name and return as an IObfs interface
|
|
func NewObfs(name string) IObfs {
|
|
c, ok := creatorMap[strings.ToLower(name)]
|
|
if ok {
|
|
return c()
|
|
}
|
|
return nil
|
|
}
|