mirror of https://github.com/v2ray/v2ray-core
merge functions file
parent
abf0cb1ec4
commit
e3d5a1c279
19
dial.go
19
dial.go
|
@ -1,19 +0,0 @@
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"v2ray.com/core/common/net"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
return net.NewConnection(net.ConnectionInputMulti(r.Writer), net.ConnectionOutputMulti(r.Reader)), nil
|
|
||||||
}
|
|
13
functions.go
13
functions.go
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
|
"v2ray.com/core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
|
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
|
||||||
|
@ -33,3 +34,15 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
|
||||||
}
|
}
|
||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
return net.NewConnection(net.ConnectionInputMulti(r.Writer), net.ConnectionOutputMulti(r.Reader)), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue