1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 03:25:23 +00:00
v2fly/transport/internet/conn_authenticator.go

37 lines
852 B
Go
Raw Normal View History

2016-10-31 21:26:46 +00:00
package internet
import (
2016-11-02 21:26:21 +00:00
"net"
2016-10-31 21:26:46 +00:00
"v2ray.com/core/common"
)
type ConnectionAuthenticator interface {
2016-11-02 21:26:21 +00:00
Client(net.Conn) net.Conn
Server(net.Conn) net.Conn
2016-10-31 21:26:46 +00:00
}
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
}