Skip to content

Commit

Permalink
deliverservice: update DialerAdapter signature
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm authored and Jason Yellick committed Mar 5, 2021
1 parent a402702 commit 3a91146
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
6 changes: 3 additions & 3 deletions core/deliverservice/deliveryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package deliverservice

import (
"context"
"crypto/x509"
"errors"
"fmt"
"sync"
Expand Down Expand Up @@ -88,13 +87,14 @@ type DialerAdapter struct {
ClientConfig comm.ClientConfig
}

func (da DialerAdapter) Dial(address string, certPool *x509.CertPool) (*grpc.ClientConn, error) {
func (da DialerAdapter) Dial(address string, rootCerts [][]byte) (*grpc.ClientConn, error) {
cc := da.ClientConfig
cc.SecOpts.ServerRootCAs = rootCerts
client, err := comm.NewGRPCClient(cc)
if err != nil {
return nil, err
}
return client.NewConnection(address, comm.CertPoolOverride(certPool))
return client.NewConnection(address)
}

type DeliverAdapter struct{}
Expand Down
13 changes: 2 additions & 11 deletions internal/pkg/peer/blocksprovider/blocksprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package blocksprovider

import (
"context"
"crypto/x509"
"math"
"time"

Expand All @@ -17,7 +16,6 @@ import (
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/common/flogging"
gossipcommon "github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/internal/pkg/comm"
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/hyperledger/fabric/internal/pkg/peer/orderers"
"github.com/hyperledger/fabric/protoutil"
Expand Down Expand Up @@ -75,7 +73,7 @@ type OrdererConnectionSource interface {

//go:generate counterfeiter -o fake/dialer.go --fake-name Dialer . Dialer
type Dialer interface {
Dial(address string, certPool *x509.CertPool) (*grpc.ClientConn, error)
Dial(address string, rootCerts [][]byte) (*grpc.ClientConn, error)
}

//go:generate counterfeiter -o fake/deliver_streamer.go --fake-name DeliverStreamer . DeliverStreamer
Expand Down Expand Up @@ -285,14 +283,7 @@ func (d *Deliverer) connect(seekInfoEnv *common.Envelope) (orderer.AtomicBroadca
return nil, nil, nil, errors.WithMessage(err, "could not get orderer endpoints")
}

certPool := x509.NewCertPool()
for _, cert := range endpoint.RootCerts {
if err := comm.AddPemToCertPool(cert, certPool); err != nil {
return nil, nil, nil, err
}
}

conn, err := d.Dialer.Dial(endpoint.Address, certPool)
conn, err := d.Dialer.Dial(endpoint.Address, endpoint.RootCerts)
if err != nil {
return nil, nil, nil, errors.WithMessagef(err, "could not dial endpoint '%s'", endpoint.Address)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/peer/blocksprovider/blocksprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package blocksprovider_test

import (
"crypto/x509"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -59,7 +58,7 @@ var _ = Describe("Blocksprovider", func() {

fakeDialer = &fake.Dialer{}
ccs = nil
fakeDialer.DialStub = func(string, *x509.CertPool) (*grpc.ClientConn, error) {
fakeDialer.DialStub = func(string, [][]byte) (*grpc.ClientConn, error) {
mutex.Lock()
defer mutex.Unlock()
cc, err := grpc.Dial("", grpc.WithInsecure())
Expand Down Expand Up @@ -216,7 +215,7 @@ var _ = Describe("Blocksprovider", func() {
Eventually(fakeDialer.DialCallCount).Should(Equal(1))
addr, tlsCerts := fakeDialer.DialArgsForCall(0)
Expect(addr).To(Equal("orderer-address"))
Expect(tlsCerts).NotTo(BeNil()) // TODO
Expect(tlsCerts).To(BeNil()) // TODO
})

When("the dialer returns an error", func() {
Expand Down
22 changes: 13 additions & 9 deletions internal/pkg/peer/blocksprovider/fake/dialer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a91146

Please sign in to comment.