Merge pull request 'fixed address resolution' (#619) from tron-616 into main
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful
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:
@@ -52,7 +52,11 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
|
||||
|
||||
opts := []grpc.DialOption{transportCreds}
|
||||
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 != "" {
|
||||
opts = append(opts,
|
||||
@@ -71,12 +75,8 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv
|
||||
}, nil
|
||||
}
|
||||
|
||||
func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error) {
|
||||
host, port, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func newForceIPv4Dialer(host, port string) func(context.Context, string) (net.Conn, error) {
|
||||
return func(ctx context.Context, _ string) (net.Conn, error) {
|
||||
ips, err := net.DefaultResolver.LookupIP(ctx, "ip4", host)
|
||||
if err != nil {
|
||||
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 IPv4 address for %s", host))
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeGRPCAddress(grpcURL string) (string, bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user