router.go 901 B

123456789101112131415161718192021222324252627282930313233
  1. package dialer
  2. import (
  3. "context"
  4. "net"
  5. "github.com/sagernet/sing-box/adapter"
  6. M "github.com/sagernet/sing/common/metadata"
  7. N "github.com/sagernet/sing/common/network"
  8. "github.com/sagernet/sing/service"
  9. )
  10. type DefaultOutboundDialer struct {
  11. outbound adapter.OutboundManager
  12. }
  13. func NewDefaultOutbound(ctx context.Context) N.Dialer {
  14. return &DefaultOutboundDialer{
  15. outbound: service.FromContext[adapter.OutboundManager](ctx),
  16. }
  17. }
  18. func (d *DefaultOutboundDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
  19. return d.outbound.Default().DialContext(ctx, network, destination)
  20. }
  21. func (d *DefaultOutboundDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
  22. return d.outbound.Default().ListenPacket(ctx, destination)
  23. }
  24. func (d *DefaultOutboundDialer) Upstream() any {
  25. return d.outbound.Default()
  26. }