From 3e9629bff18f33eff841ef5c82cf348dbea94116 Mon Sep 17 00:00:00 2001 From: zak Date: Sat, 17 Sep 2022 16:43:43 +0800 Subject: [PATCH] proposal: outbound more readable --- outbound/trojan.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/outbound/trojan.go b/outbound/trojan.go index 20e64802..c837b906 100644 --- a/outbound/trojan.go +++ b/outbound/trojan.go @@ -66,20 +66,28 @@ func NewTrojan(ctx context.Context, router adapter.Router, logger log.ContextLog } func (h *Trojan) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) { + destinationString := destination.String() + if destination.Addr.IsValid() { + metadata := adapter.ContextFrom(ctx) + if metadata.Domain != "" { + destinationString += " (" + metadata.Domain + ")" + } + } + if h.multiplexDialer == nil { switch N.NetworkName(network) { case N.NetworkTCP: - h.logger.InfoContext(ctx, "outbound connection to ", destination) + h.logger.InfoContext(ctx, "outbound connection to ", destinationString) case N.NetworkUDP: - h.logger.InfoContext(ctx, "outbound packet connection to ", destination) + h.logger.InfoContext(ctx, "outbound packet connection to ", destinationString) } return (*trojanDialer)(h).DialContext(ctx, network, destination) } else { switch N.NetworkName(network) { case N.NetworkTCP: - h.logger.InfoContext(ctx, "outbound multiplex connection to ", destination) + h.logger.InfoContext(ctx, "outbound multiplex connection to ", destinationString) case N.NetworkUDP: - h.logger.InfoContext(ctx, "outbound multiplex packet connection to ", destination) + h.logger.InfoContext(ctx, "outbound multiplex packet connection to ", destinationString) } return h.multiplexDialer.DialContext(ctx, network, destination) }