mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
859 B
36 lines
859 B
package internet
|
|
|
|
import (
|
|
"io"
|
|
"v2ray.com/core/common"
|
|
)
|
|
|
|
type ConnectionAuthenticator interface {
|
|
Seal(io.Writer) io.Writer
|
|
Open(io.Reader) (io.Reader, error)
|
|
}
|
|
|
|
type ConnectionAuthenticatorFactory interface {
|
|
Create(interface{}) ConnectionAuthenticator
|
|
}
|
|
|
|
var (
|
|
connectionAuthenticatorCache = make(map[string]ConnectionAuthenticatorFactory)
|
|
)
|
|
|
|
func RegisterConnectionAuthenticator(name string, factory ConnectionAuthenticatorFactory) error {
|
|
if _, found := connectionAuthenticatorCache[name]; found {
|
|
return common.ErrDuplicatedName
|
|
}
|
|
connectionAuthenticatorCache[name] = factory
|
|
return nil
|
|
}
|
|
|
|
func CreateConnectionAuthenticator(name string, config interface{}) (ConnectionAuthenticator, error) {
|
|
factory, found := connectionAuthenticatorCache[name]
|
|
if !found {
|
|
return nil, common.ErrObjectNotFound
|
|
}
|
|
return factory.Create(config), nil
|
|
}
|