From 3755c0f54327b9fd2394fc641be7219cddd34505 Mon Sep 17 00:00:00 2001 From: anytls Date: Thu, 20 Feb 2025 15:15:49 +0900 Subject: [PATCH] Fix AnyTLS UDP outbound --- protocol/anytls/outbound.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/protocol/anytls/outbound.go b/protocol/anytls/outbound.go index 654feb66..fab06bc3 100644 --- a/protocol/anytls/outbound.go +++ b/protocol/anytls/outbound.go @@ -35,7 +35,7 @@ type Outbound struct { func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.AnyTLSOutboundOptions) (adapter.Outbound, error) { outbound := &Outbound{ - Adapter: outbound.NewAdapterWithDialerOptions(C.TypeAnyTLS, tag, []string{N.NetworkTCP}, options.DialerOptions), + Adapter: outbound.NewAdapterWithDialerOptions(C.TypeAnyTLS, tag, []string{N.NetworkTCP, N.NetworkUDP}, options.DialerOptions), server: options.ServerOptions.Build(), logger: logger, } @@ -71,12 +71,22 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL outbound.client = client outbound.uotClient = &uot.Client{ - Dialer: outbound, + Dialer: (anytlsDialer)(client.CreateProxy), Version: uot.Version, } return outbound, nil } +type anytlsDialer func(ctx context.Context, destination M.Socksaddr) (net.Conn, error) + +func (d anytlsDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) { + return d(ctx, destination) +} + +func (d anytlsDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) { + return nil, os.ErrInvalid +} + func (h *Outbound) dialOut(ctx context.Context) (net.Conn, error) { conn, err := h.dialer.DialContext(ctx, N.NetworkTCP, h.server) if err != nil {