dial.go 663 B

12345678910111213141516171819
  1. package core
  2. import (
  3. "context"
  4. "v2ray.com/core/common/net"
  5. )
  6. // Dial provides an easy way for upstream caller to create net.Conn through V2Ray.
  7. // It dispatches the request to the given destination by the given V2Ray instance.
  8. // Since it is under a proxy context, the LocalAddr() and RemoteAddr() in returned net.Conn
  9. // will not show real addresses being used for communication.
  10. func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) {
  11. r, err := v.Dispatcher().Dispatch(ctx, dest)
  12. if err != nil {
  13. return nil, err
  14. }
  15. return net.NewConnection(net.ConnectionInputMulti(r.Writer), net.ConnectionOutputMulti(r.Reader)), nil
  16. }