1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-29 02:35:23 +00:00
v2fly/dial.go

21 lines
659 B
Go
Raw Normal View History

2018-01-10 16:31:52 +00:00
package core
import (
"context"
"v2ray.com/core/common/net"
"v2ray.com/core/transport/ray"
)
// Dial provides an easy way for upstream caller to create net.Conn through V2Ray.
// It dispatches the request to the given destination by the given V2Ray instance.
// Since it is under a proxy context, the LocalAddr() and RemoteAddr() in returned net.Conn
// will not show real addresses being used for communication.
func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) {
r, err := v.Dispatcher().Dispatch(ctx, dest)
if err != nil {
return nil, err
}
2018-02-05 22:38:24 +00:00
return ray.NewConnection(r.InboundOutput(), r.InboundInput()), nil
2018-01-10 16:31:52 +00:00
}