1 Star 0 Fork 0

赵春/fabric-chaincode-go-gm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
赵春 提交于 2022-02-21 16:01 . 基础版本作成
// Copyright the Hyperledger Fabric contributors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package internal
import (
"context"
"time"
tls "gitee.com/zhaochuninhefei/gmgo/gmtls"
credentials "gitee.com/zhaochuninhefei/gmgo/gmtls/gmcredentials"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
const (
dialTimeout = 10 * time.Second
maxRecvMessageSize = 100 * 1024 * 1024 // 100 MiB
maxSendMessageSize = 100 * 1024 * 1024 // 100 MiB
)
// NewClientConn ...
func NewClientConn(
address string,
tlsConf *tls.Config,
kaOpts keepalive.ClientParameters,
) (*grpc.ClientConn, error) {
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())
}
ctx, cancel := context.WithTimeout(context.Background(), dialTimeout)
defer cancel()
return grpc.DialContext(ctx, address, dialOpts...)
}
// NewRegisterClient ...
func NewRegisterClient(conn *grpc.ClientConn) (peerpb.ChaincodeSupport_RegisterClient, error) {
return peerpb.NewChaincodeSupportClient(conn).Register(context.Background())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zhaochuninhefei/fabric-chaincode-go-gm.git
git@gitee.com:zhaochuninhefei/fabric-chaincode-go-gm.git
zhaochuninhefei
fabric-chaincode-go-gm
fabric-chaincode-go-gm
v0.0.3

搜索帮助

0d507c66 1850385 C8b1a773 1850385