github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/common/dialer/router.go (about) 1 package dialer 2 3 import ( 4 "context" 5 "net" 6 7 "github.com/inazumav/sing-box/adapter" 8 M "github.com/sagernet/sing/common/metadata" 9 N "github.com/sagernet/sing/common/network" 10 ) 11 12 type RouterDialer struct { 13 router adapter.Router 14 } 15 16 func NewRouter(router adapter.Router) N.Dialer { 17 return &RouterDialer{router: router} 18 } 19 20 func (d *RouterDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) { 21 return d.router.DefaultOutbound(network).DialContext(ctx, network, destination) 22 } 23 24 func (d *RouterDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) { 25 return d.router.DefaultOutbound(N.NetworkUDP).ListenPacket(ctx, destination) 26 } 27 28 func (d *RouterDialer) Upstream() any { 29 return d.router 30 }