mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-16 19:00:05 +07:00
feat: support to dial domain for udp and support udp for ssr (#17)
This commit is contained in:
@ -7,12 +7,11 @@ package netutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"golang.org/x/net/proxy"
|
||||
"net"
|
||||
)
|
||||
|
||||
type ContextDialer struct {
|
||||
Dialer proxy.Dialer
|
||||
Dialer net.Dialer
|
||||
}
|
||||
|
||||
func (d *ContextDialer) DialContext(ctx context.Context, network, addr string) (c net.Conn, err error) {
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/mzz2017/softwind/netproxy"
|
||||
"github.com/mzz2017/softwind/pkg/fastrand"
|
||||
"github.com/mzz2017/softwind/pool"
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
"golang.org/x/net/proxy"
|
||||
"io"
|
||||
"math"
|
||||
"net/netip"
|
||||
@ -70,7 +70,7 @@ func SystemDns() (dns netip.AddrPort, err error) {
|
||||
return systemDns, nil
|
||||
}
|
||||
|
||||
func ResolveNetip(ctx context.Context, d proxy.Dialer, dns netip.AddrPort, host string, typ dnsmessage.Type, tcp bool) (addrs []netip.Addr, err error) {
|
||||
func ResolveNetip(ctx context.Context, d netproxy.Dialer, dns netip.AddrPort, host string, typ dnsmessage.Type, tcp bool) (addrs []netip.Addr, err error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
if addr, err := netip.ParseAddr(host); err == nil {
|
||||
@ -122,14 +122,13 @@ func ResolveNetip(ctx context.Context, d proxy.Dialer, dns netip.AddrPort, host
|
||||
}
|
||||
|
||||
// Dial and write.
|
||||
var network string
|
||||
cd := &netproxy.ContextDialer{Dialer: d}
|
||||
var c netproxy.Conn
|
||||
if tcp {
|
||||
network = "tcp"
|
||||
c, err = cd.DialTcpContext(ctx, dns.String())
|
||||
} else {
|
||||
network = "udp"
|
||||
c, err = cd.DialUdpContext(ctx, dns.String())
|
||||
}
|
||||
cd := ContextDialer{d}
|
||||
c, err := cd.DialContext(ctx, network, dns.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package netutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/mzz2017/softwind/netproxy"
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
"golang.org/x/net/proxy"
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
@ -17,7 +17,7 @@ type Ip46 struct {
|
||||
Ip6 netip.Addr
|
||||
}
|
||||
|
||||
func ParseIp46(ctx context.Context, dialer proxy.Dialer, dns netip.AddrPort, host string, tcp bool) (ipv46 *Ip46, err error) {
|
||||
func ParseIp46(ctx context.Context, dialer netproxy.Dialer, dns netip.AddrPort, host string, tcp bool) (ipv46 *Ip46, err error) {
|
||||
addrs4, err := ResolveNetip(ctx, dialer, dns, host, dnsmessage.TypeA, tcp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user