conn_authenticator.go 533 B

12345678910111213141516171819202122232425262728
  1. package internet
  2. import (
  3. "errors"
  4. "net"
  5. "context"
  6. "v2ray.com/core/common"
  7. )
  8. type ConnectionAuthenticator interface {
  9. Client(net.Conn) net.Conn
  10. Server(net.Conn) net.Conn
  11. }
  12. func CreateConnectionAuthenticator(config interface{}) (ConnectionAuthenticator, error) {
  13. auth, err := common.CreateObject(context.Background(), config)
  14. if err != nil {
  15. return nil, err
  16. }
  17. switch a := auth.(type) {
  18. case ConnectionAuthenticator:
  19. return a, nil
  20. default:
  21. return nil, errors.New("Internet: Not a ConnectionAuthenticator.")
  22. }
  23. }