mirror of
https://github.com/nadoo/glider.git
synced 2025-02-24 17:55:41 +08:00
40 lines
670 B
Go
40 lines
670 B
Go
![]() |
package protocol
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/sun8911879/shadowsocksR/ssr"
|
||
|
)
|
||
|
|
||
|
type creator func() IProtocol
|
||
|
|
||
|
var (
|
||
|
creatorMap = make(map[string]creator)
|
||
|
)
|
||
|
|
||
|
type IProtocol interface {
|
||
|
SetServerInfo(s *ssr.ServerInfoForObfs)
|
||
|
GetServerInfo() *ssr.ServerInfoForObfs
|
||
|
PreEncrypt(data []byte) ([]byte, error)
|
||
|
PostDecrypt(data []byte) ([]byte, int, error)
|
||
|
SetData(data interface{})
|
||
|
GetData() interface{}
|
||
|
}
|
||
|
|
||
|
type authData struct {
|
||
|
clientID []byte
|
||
|
connectionID uint32
|
||
|
}
|
||
|
|
||
|
func register(name string, c creator) {
|
||
|
creatorMap[name] = c
|
||
|
}
|
||
|
|
||
|
func NewProtocol(name string) IProtocol {
|
||
|
c, ok := creatorMap[strings.ToLower(name)]
|
||
|
if ok {
|
||
|
return c()
|
||
|
}
|
||
|
return nil
|
||
|
}
|