fixed tron ip connection
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful

This commit is contained in:
Stephan D
2026-03-03 18:32:26 +01:00
parent 7cac494509
commit 3f578353da
7 changed files with 33 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"net"
"net/url"
"strings"
"time"
@@ -27,7 +28,7 @@ type Client struct {
}
// NewClient creates a new TRON gRPC client connected to the given endpoint.
func NewClient(grpcURL string, timeout time.Duration, authToken string) (*Client, error) {
func NewClient(grpcURL string, timeout time.Duration, authToken string, forceIPv4 bool) (*Client, error) {
if grpcURL == "" {
return nil, merrors.InvalidArgument("tronclient: grpc url is required")
}
@@ -50,6 +51,9 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string) (*Client
}
opts := []grpc.DialOption{transportCreds}
if forceIPv4 {
opts = append(opts, grpc.WithContextDialer(grpcForceIPv4Dialer))
}
if token := strings.TrimSpace(authToken); token != "" {
opts = append(opts,
grpc.WithUnaryInterceptor(grpcTokenUnaryInterceptor(token)),
@@ -67,6 +71,11 @@ func NewClient(grpcURL string, timeout time.Duration, authToken string) (*Client
}, nil
}
func grpcForceIPv4Dialer(ctx context.Context, address string) (net.Conn, error) {
var dialer net.Dialer
return dialer.DialContext(ctx, "tcp4", address)
}
func normalizeGRPCAddress(grpcURL string) (string, bool, error) {
target := strings.TrimSpace(grpcURL)
useTLS := false

View File

@@ -40,6 +40,7 @@ func Prepare(ctx context.Context, logger mlogger.Logger, networks []shared.Netwo
name := network.Name.String()
grpcURL := strings.TrimSpace(network.GRPCUrl)
grpcToken := strings.TrimSpace(network.GRPCToken)
forceIPv4 := network.GRPCForceIPv4
if !network.Name.IsValid() {
continue
@@ -56,9 +57,10 @@ func Prepare(ctx context.Context, logger mlogger.Logger, networks []shared.Netwo
registry.logger.Info("Initializing TRON gRPC client",
zap.String("network", name),
zap.String("grpc_url", grpcURL),
zap.Bool("force_ipv4", forceIPv4),
)
client, err := NewClient(grpcURL, timeout, grpcToken)
client, err := NewClient(grpcURL, timeout, grpcToken, forceIPv4)
if err != nil {
registry.Close()
registry.logger.Error("Failed to initialize TRON gRPC client",