mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-30 05:55:20 -05:00
DialUDP function
This commit is contained in:
15
functions.go
15
functions.go
@@ -7,6 +7,7 @@ import (
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/features/routing"
|
||||
"v2ray.com/core/transport/internet/udp"
|
||||
)
|
||||
|
||||
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
|
||||
@@ -54,3 +55,17 @@ func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, err
|
||||
}
|
||||
return net.NewConnection(net.ConnectionInputMulti(r.Writer), net.ConnectionOutputMulti(r.Reader)), nil
|
||||
}
|
||||
|
||||
// DialUDP provides a way to exchange UDP packets through V2Ray instance to remote servers.
|
||||
// Since it is under a proxy context, the LocalAddr() in returned PacketConn will not show the real address.
|
||||
//
|
||||
// TODO: SetDeadline() / SetReadDeadline() / SetWriteDeadline() are not implemented.
|
||||
//
|
||||
// v2ray:api:beta
|
||||
func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error) {
|
||||
dispatcher := v.GetFeature(routing.DispatcherType())
|
||||
if dispatcher == nil {
|
||||
return nil, newError("routing.Dispatcher is not registered in V2Ray core")
|
||||
}
|
||||
return udp.DialDispatcher(ctx, dispatcher.(routing.Dispatcher))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user