Merge pull request 'fixed address resolution' (#619) from tron-616 into main
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful

Reviewed-on: #619
This commit was merged in pull request #619.
This commit is contained in:
2026-03-03 18:37:32 +00:00

View File

@@ -52,7 +52,11 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
opts := []grpc.DialOption{transportCreds} opts := []grpc.DialOption{transportCreds}
if forceIPv4 { if forceIPv4 {
opts = append(opts, grpc.WithContextDialer(grpcForceIPv4Dialer)) host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, merrors.InvalidArgument("tronclient: invalid grpc address: " + address)
}
opts = append(opts, grpc.WithContextDialer(newForceIPv4Dialer(host, port)))
} }
if token := strings.TrimSpace(authToken); token != "" { if token := strings.TrimSpace(authToken); token != "" {
opts = append(opts, opts = append(opts,
@@ -71,12 +75,8 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
}, nil }, nil
} }
func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error) { func newForceIPv4Dialer(host, port string) func(context.Context, string) (net.Conn, error) {
host, port, err := net.SplitHostPort(address) return func(ctx context.Context, _ string) (net.Conn, error) {
if err != nil {
return nil, err
}
ips, err := net.DefaultResolver.LookupIP(ctx, "ip4", host) ips, err := net.DefaultResolver.LookupIP(ctx, "ip4", host)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -102,6 +102,7 @@ func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error)
return nil, merrors.Internal(fmt.Sprintf("failed to dial any IPv4 address for %s: %v", host, lastErr)) return nil, merrors.Internal(fmt.Sprintf("failed to dial any IPv4 address for %s: %v", host, lastErr))
} }
return nil, merrors.Internal(fmt.Sprintf("failed to dial IPv4 address for %s", host)) return nil, merrors.Internal(fmt.Sprintf("failed to dial IPv4 address for %s", host))
}
} }
func normalizeGRPCAddress(grpcURL string) (string, bool, error) { func normalizeGRPCAddress(grpcURL string) (string, bool, error) {