forked from nsjok/gossr
/
base.go
37 lines (30 loc) · 773 Bytes
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package obfs
import (
"errors"
"strings"
"github.com/Echowxsy/gossr/ssr"
)
type creator func() IObfs
var (
creatorMap = make(map[string]creator)
NotSupportObfsError = errors.New("obfs method do not support")
)
type IObfs interface {
SetServerInfo(s *ssr.ServerInfoForObfs)
GetServerInfo() (s *ssr.ServerInfoForObfs)
Encode(data []byte) ([]byte, error)
Decode(data []byte) ([]byte, uint64, error)
SetData(data interface{})
GetData() interface{}
}
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 IObfs, err error) {
c, ok := creatorMap[strings.ToLower(name)]
if ok {
return c(), nil
}
return nil, NotSupportObfsError
}