2016-10-31 17:26:46 -04:00
|
|
|
package internet
|
|
|
|
|
|
|
|
import (
|
2017-01-12 16:47:10 -05:00
|
|
|
"errors"
|
2016-11-02 17:26:21 -04:00
|
|
|
"net"
|
|
|
|
|
2017-01-12 16:47:10 -05:00
|
|
|
"context"
|
|
|
|
|
2016-10-31 17:26:46 -04:00
|
|
|
"v2ray.com/core/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConnectionAuthenticator interface {
|
2016-11-02 17:26:21 -04:00
|
|
|
Client(net.Conn) net.Conn
|
|
|
|
Server(net.Conn) net.Conn
|
2016-10-31 17:26:46 -04:00
|
|
|
}
|
|
|
|
|
2017-01-12 16:47:10 -05:00
|
|
|
func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) {
|
|
|
|
auth, err := common.CreateObject(context.Background(), config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-10-31 17:26:46 -04:00
|
|
|
}
|
2017-01-12 16:47:10 -05:00
|
|
|
switch a := auth.(type) {
|
|
|
|
case ConnectionAuthenticator:
|
|
|
|
return a, nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("Internet: Not a ConnectionAuthenticator.")
|
2016-10-31 17:26:46 -04:00
|
|
|
}
|
|
|
|
}
|