diff options
Diffstat (limited to 'pkg/server/hook')
| -rw-r--r-- | pkg/server/hook/aes.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/alpha.go | 4 | ||||
| -rw-r--r-- | pkg/server/hook/auth.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/b64.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/b85.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/buf.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/dump.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/hex.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/hook.go | 48 | ||||
| -rw-r--r-- | pkg/server/hook/info-http.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/proxy.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/split.go | 2 | ||||
| -rw-r--r-- | pkg/server/hook/zip.go | 2 |
13 files changed, 49 insertions, 25 deletions
diff --git a/pkg/server/hook/aes.go b/pkg/server/hook/aes.go index dc48f49..184d18d 100644 --- a/pkg/server/hook/aes.go +++ b/pkg/server/hook/aes.go @@ -75,5 +75,5 @@ func (aesHook) New(env env.Env) (interface{}, error) { } func init() { - register("aes", aesHook{}) + register("aes", "aes encryption out/in", aesHook{}) } diff --git a/pkg/server/hook/alpha.go b/pkg/server/hook/alpha.go index d1fefcc..f25d4de 100644 --- a/pkg/server/hook/alpha.go +++ b/pkg/server/hook/alpha.go @@ -27,6 +27,6 @@ func alpha(cb func(rune) rune) Func { } func init() { - registerFunc("lower", alpha(unicode.ToLower)) - registerFunc("upper", alpha(unicode.ToUpper)) + registerFunc("lower", "lowercase filter out/", alpha(unicode.ToLower)) + registerFunc("upper", "uppercase filter out/", alpha(unicode.ToUpper)) } diff --git a/pkg/server/hook/auth.go b/pkg/server/hook/auth.go index dbfc9bc..21f900e 100644 --- a/pkg/server/hook/auth.go +++ b/pkg/server/hook/auth.go @@ -170,5 +170,5 @@ func (h *authHook) New(env env.Env) (interface{}, error) { } func init() { - register("auth", authHook{}) + register("auth", "chap authentication out/in", authHook{}) } diff --git a/pkg/server/hook/b64.go b/pkg/server/hook/b64.go index c6637e5..d12d4c9 100644 --- a/pkg/server/hook/b64.go +++ b/pkg/server/hook/b64.go @@ -39,5 +39,5 @@ func (b64Pipe) Recv(rq, wq queue.Q) error { } func init() { - registerPipe("b64", b64Pipe{}) + registerPipe("b64", "base64 filter out/in", b64Pipe{}) } diff --git a/pkg/server/hook/b85.go b/pkg/server/hook/b85.go index d90a1c4..967882d 100644 --- a/pkg/server/hook/b85.go +++ b/pkg/server/hook/b85.go @@ -44,5 +44,5 @@ func (b85Pipe) Recv(rq, wq queue.Q) error { } func init() { - registerPipe("b85", b85Pipe{}) + registerPipe("b85", "base85 filter out/in", b85Pipe{}) } diff --git a/pkg/server/hook/buf.go b/pkg/server/hook/buf.go index 0306c73..98c57c9 100644 --- a/pkg/server/hook/buf.go +++ b/pkg/server/hook/buf.go @@ -47,5 +47,5 @@ func buffering(rq, wq queue.Q) error { } func init() { - registerFunc("buf", buffering) + registerFunc("buf", "stream buffering out/", buffering) } diff --git a/pkg/server/hook/dump.go b/pkg/server/hook/dump.go index d871d63..bcf958f 100644 --- a/pkg/server/hook/dump.go +++ b/pkg/server/hook/dump.go @@ -103,5 +103,5 @@ func (h *dumpHook) New(env env.Env) (interface{}, error) { } func init() { - register("dump", dumpHook{}) + register("dump", "stream dumper out/in", dumpHook{}) } diff --git a/pkg/server/hook/hex.go b/pkg/server/hook/hex.go index 362dbd4..4d7f1e7 100644 --- a/pkg/server/hook/hex.go +++ b/pkg/server/hook/hex.go @@ -24,5 +24,5 @@ func (hexPipe) Recv(rq, wq queue.Q) error { } func init() { - registerPipe("hex", hexPipe{}) + registerPipe("hex", "stream hexify out/", hexPipe{}) } diff --git a/pkg/server/hook/hook.go b/pkg/server/hook/hook.go index 36b01d4..1464272 100644 --- a/pkg/server/hook/hook.go +++ b/pkg/server/hook/hook.go @@ -12,7 +12,17 @@ import ( "tunnel/pkg/server/queue" ) -var hooks = map[string]interface{}{} +type Type struct { + Name string + Desc string + Func bool + + Param []opts.Param + + data interface{} +} + +var hooks = map[string]*Type{} type Pipe struct { priv interface{} @@ -112,9 +122,9 @@ func New(desc string) (H, error) { reverse = true } - if i, ok := hooks[name]; !ok { + if hookType, ok := hooks[name]; !ok { return nil, fmt.Errorf("unknown hook '%s'", name) - } else if h, err := initHook(i, opts); err != nil { + } else if h, err := initHook(hookType.data, opts); err != nil { return nil, fmt.Errorf("%s: %w", name, err) } else { w := &wrapper{ @@ -126,29 +136,39 @@ func New(desc string) (H, error) { } } -func register(name string, i interface{}) { +func register(name string, desc string, i interface{}) { + var param []opts.Param + switch t := reflect.TypeOf(i); t.Kind() { case reflect.Struct: if _, ok := reflect.New(t).Interface().(Hooker); !ok { - log.Panicf("uncompatible hook type '%s'", t.String()) + log.Panicf("uncompatible hook type '%s'", t) } + param = opts.Parametrize(t) case reflect.Func: if _, ok := i.(Func); !ok { - log.Panicf("uncompatible func type '%s'", t.String()) + log.Panicf("uncompatible func type '%s'", t) } default: - log.Panicf("non-struct and non-func type '%s'", t.String()) + log.Panicf("non-struct and non-func type '%s'", t) } if _, ok := hooks[name]; ok { log.Panicf("duplicate hook name '%s'", name) } - hooks[name] = i + hooks[name] = &Type{ + Name: name, + Desc: desc, + + Param: param, + + data: i, + } } -func registerFunc(name string, f Func) { - register(name, f) +func registerFunc(name string, desc string, f Func) { + register(name, desc, f) } type pipeHolder struct { @@ -159,8 +179,8 @@ func (p pipeHolder) New(env.Env) (interface{}, error) { return p.i, nil } -func registerPipe(name string, i interface{}) { - register(name, pipeHolder{i}) +func registerPipe(name string, desc string, i interface{}) { + register(name, desc, pipeHolder{i}) } func GetList() []string { @@ -174,3 +194,7 @@ func GetList() []string { return list } + +func GetType(name string) *Type { + return hooks[name] +} diff --git a/pkg/server/hook/info-http.go b/pkg/server/hook/info-http.go index ec56f87..721c286 100644 --- a/pkg/server/hook/info-http.go +++ b/pkg/server/hook/info-http.go @@ -47,5 +47,5 @@ func (infoHttpHook) New(env env.Env) (interface{}, error) { } func init() { - register("info-http", infoHttpHook{}) + register("info-http", "display http connect host out/", infoHttpHook{}) } diff --git a/pkg/server/hook/proxy.go b/pkg/server/hook/proxy.go index 4276d9a..bba17e3 100644 --- a/pkg/server/hook/proxy.go +++ b/pkg/server/hook/proxy.go @@ -87,5 +87,5 @@ func (h *proxyHook) New(env env.Env) (interface{}, error) { } func init() { - register("proxy", proxyHook{}) + register("proxy", "http connect client out/in", proxyHook{}) } diff --git a/pkg/server/hook/split.go b/pkg/server/hook/split.go index 59c8055..eee36d4 100644 --- a/pkg/server/hook/split.go +++ b/pkg/server/hook/split.go @@ -36,5 +36,5 @@ func (h *splitHook) New(env.Env) (interface{}, error) { } func init() { - register("split", splitHook{}) + register("split", "stream splitter out/", splitHook{}) } diff --git a/pkg/server/hook/zip.go b/pkg/server/hook/zip.go index 615b50d..6283cb5 100644 --- a/pkg/server/hook/zip.go +++ b/pkg/server/hook/zip.go @@ -42,5 +42,5 @@ func (zipPipe) Recv(rq, wq queue.Q) error { } func init() { - registerPipe("zip", zipPipe{}) + registerPipe("zip", "zip compression filter out/in", zipPipe{}) } |
