v2ray-core/transport/internet/conn_authenticator.go

29 lines
533 B
Go
Raw Normal View History

2016-10-31 21:26:46 +00:00
package internet
import (
2017-01-12 21:47:10 +00:00
"errors"
2016-11-02 21:26:21 +00:00
"net"
2017-01-12 21:47:10 +00:00
"context"
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
}
2017-01-12 21:47:10 +00:00
func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) {
auth, err := common.CreateObject(context.Background(), config)
if err != nil {
return nil, err
2016-10-31 21:26:46 +00:00
}
2017-01-12 21:47:10 +00:00
switch a := auth.(type) {
case ConnectionAuthenticator:
return a, nil
default:
return nil, errors.New("Internet: Not a ConnectionAuthenticator.")
2016-10-31 21:26:46 +00:00
}
}