2020-11-25 19:01:53 +08:00
|
|
|
package udp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2020-12-04 09:36:16 +08:00
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
2021-12-14 19:28:47 -05:00
|
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
2020-11-25 19:01:53 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
common.Must(internet.RegisterTransportDialer(protocolName,
|
2021-09-20 20:11:21 +08:00
|
|
|
func(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
2026-09-21 02:12:50 +08:00
|
|
|
if streamSettings != nil && streamSettings.FinalMask != nil {
|
|
|
|
|
return streamSettings.FinalMask.DialUDP(ctx, dest)
|
|
|
|
|
} else {
|
|
|
|
|
var sockopt *internet.SocketConfig
|
|
|
|
|
if streamSettings != nil && streamSettings.SocketSettings != nil {
|
|
|
|
|
sockopt = streamSettings.SocketSettings
|
2026-02-04 08:29:45 +08:00
|
|
|
}
|
2026-09-21 02:12:50 +08:00
|
|
|
return internet.DialSystem(ctx, dest, sockopt)
|
2026-02-04 08:29:45 +08:00
|
|
|
}
|
2020-11-25 19:01:53 +08:00
|
|
|
}))
|
|
|
|
|
}
|