2016-06-14 16:54:08 -04:00
|
|
|
package udp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2016-12-21 09:37:16 -05:00
|
|
|
|
2017-01-03 09:16:48 -05:00
|
|
|
"v2ray.com/core/common"
|
2016-08-20 14:55:45 -04:00
|
|
|
v2net "v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/transport/internet"
|
2016-06-14 16:54:08 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
net.UDPConn
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *Connection) Reusable() bool {
|
2016-06-14 16:54:08 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *Connection) SetReusable(b bool) {}
|
2016-06-14 16:54:08 -04:00
|
|
|
|
|
|
|
func init() {
|
2017-01-03 09:16:48 -05:00
|
|
|
common.Must(internet.RegisterNetworkDialer(v2net.Network_UDP,
|
|
|
|
func(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (internet.Connection, error) {
|
|
|
|
conn, err := internet.DialSystem(src, dest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// TODO: handle dialer options
|
|
|
|
return &Connection{
|
|
|
|
UDPConn: *(conn.(*net.UDPConn)),
|
|
|
|
}, nil
|
|
|
|
}))
|
2016-06-14 16:54:08 -04:00
|
|
|
}
|