代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package comm
import (
"time"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/comm"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
const defaultTimeout = time.Second * 5
// Client deals with TLS connections
// to the discovery server
type Client struct {
TLSCertHash []byte
*comm.GRPCClient
}
// NewClient creates a new comm client out of the given configuration
func NewClient(conf Config) (*Client, error) {
if conf.Timeout == time.Duration(0) {
conf.Timeout = defaultTimeout
}
sop, err := conf.ToSecureOptions(newSelfSignedTLSCert)
if err != nil {
return nil, errors.WithStack(err)
}
cl, err := comm.NewGRPCClient(comm.ClientConfig{
SecOpts: sop,
Timeout: conf.Timeout,
})
if err != nil {
return nil, err
}
return &Client{GRPCClient: cl, TLSCertHash: util.ComputeSHA256(sop.Certificate)}, nil
}
// NewDialer creates a new dialer from the given endpoint
func (c *Client) NewDialer(endpoint string) func() (*grpc.ClientConn, error) {
return func() (*grpc.ClientConn, error) {
conn, err := c.NewConnection(endpoint, "")
if err != nil {
return nil, errors.WithStack(err)
}
return conn, nil
}
}
func newSelfSignedTLSCert() (*tlsgen.CertKeyPair, error) {
ca, err := tlsgen.NewCA()
if err != nil {
return nil, err
}
return ca.NewClientCertKeyPair()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。