fixed tron ip connection
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful
All checks were successful
ci/woodpecker/push/gateway_tron Pipeline was successful
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user