dial.go 659 B

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