mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-08-27 19:51:45 +00:00
Use core.Transport
This commit is contained in:
@@ -15,6 +15,7 @@ var ErrTimeout = errors.New("inactivity timeout")
|
||||
|
||||
type UDPRelay struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
ListenAddr *net.UDPAddr
|
||||
Remote string
|
||||
Timeout time.Duration
|
||||
@@ -23,14 +24,15 @@ type UDPRelay struct {
|
||||
ErrorFunc func(addr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NewUDPRelay(hyClient *core.Client, listen, remote string, timeout time.Duration,
|
||||
func NewUDPRelay(hyClient *core.Client, transport core.Transport, listen, remote string, timeout time.Duration,
|
||||
connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*UDPRelay, error) {
|
||||
uAddr, err := net.ResolveUDPAddr("udp", listen)
|
||||
uAddr, err := transport.LocalResolveUDPAddr(listen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := &UDPRelay{
|
||||
HyClient: hyClient,
|
||||
Transport: transport,
|
||||
ListenAddr: uAddr,
|
||||
Remote: remote,
|
||||
Timeout: timeout,
|
||||
@@ -49,7 +51,7 @@ type connEntry struct {
|
||||
}
|
||||
|
||||
func (r *UDPRelay) ListenAndServe() error {
|
||||
conn, err := net.ListenUDP("udp", r.ListenAddr)
|
||||
conn, err := r.Transport.LocalListenUDP(r.ListenAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user