package internal import ( "context" "crypto/tls" "time" pb "schain/proto" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/keepalive" ) const ( dialTimeout = 10 * time.Second maxRecvMessageSize = 100 * 1024 * 1024 // 100 MiB maxSendMessageSize = 100 * 1024 * 1024 // 100 MiB ) func NewClientConn( address string, tlsConf *tls.Config, ) (*grpc.ClientConn, error) { kaOpts := keepalive.ClientParameters{ Time: 1 * time.Minute, Timeout: 20 * time.Second, PermitWithoutStream: true, } dialOpts := []grpc.DialOption{ grpc.WithKeepaliveParams(kaOpts), grpc.WithBlock(), grpc.FailOnNonTempDialError(true), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(maxRecvMessageSize), grpc.MaxCallSendMsgSize(maxSendMessageSize), ), } /*if tlsConf != nil { creds := credentials.NewTLS(tlsConf) dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds)) } else { dialOpts = append(dialOpts, grpc.WithInsecure()) }*/ dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) ctx, cancel := context.WithTimeout(context.Background(), dialTimeout) defer cancel() return grpc.DialContext(ctx, address, dialOpts...) } func NewRegisterClient(conn *grpc.ClientConn) (pb.ChaincodeSupportClient, error) { return pb.NewChaincodeSupportClient(conn), nil }