@@ -18,16 +18,15 @@ package comm
18
18
19
19
import (
20
20
"bytes"
21
+ "crypto/tls"
21
22
"fmt"
22
23
"math/rand"
23
24
"net"
25
+ "os"
24
26
"sync"
25
27
"sync/atomic"
26
28
"time"
27
29
28
- "crypto/tls"
29
- "os"
30
-
31
30
"github.com/hyperledger/fabric/gossip/common"
32
31
"github.com/hyperledger/fabric/gossip/proto"
33
32
"github.com/hyperledger/fabric/gossip/util"
@@ -140,32 +139,36 @@ type commImpl struct {
140
139
}
141
140
142
141
func (c * commImpl ) createConnection (endpoint string , expectedPKIID common.PKIidType ) (* connection , error ) {
142
+ var err error
143
+ var cc * grpc.ClientConn
144
+ var stream proto.Gossip_GossipStreamClient
145
+ var pkiID common.PKIidType
146
+
143
147
c .logger .Debug ("Entering" , endpoint , expectedPKIID )
144
148
defer c .logger .Debug ("Exiting" )
149
+
145
150
if c .isStopping () {
146
151
return nil , fmt .Errorf ("Stopping" )
147
152
}
148
- cc , err : = grpc .Dial (endpoint , append (c .opts , grpc .WithBlock ())... )
153
+ cc , err = grpc .Dial (endpoint , append (c .opts , grpc .WithBlock ())... )
149
154
if err != nil {
150
- if cc != nil {
151
- cc .Close ()
152
- }
153
155
return nil , err
154
156
}
155
157
156
158
cl := proto .NewGossipClient (cc )
157
159
158
- if _ , err : = cl .Ping (context .Background (), & proto.Empty {}); err != nil {
160
+ if _ , err = cl .Ping (context .Background (), & proto.Empty {}); err != nil {
159
161
cc .Close ()
160
162
return nil , err
161
163
}
162
164
163
- if stream , err : = cl .GossipStream (context .Background ()); err == nil {
164
- pkiID , err : = c .authenticateRemotePeer (stream )
165
+ if stream , err = cl .GossipStream (context .Background ()); err == nil {
166
+ pkiID , err = c .authenticateRemotePeer (stream )
165
167
if err == nil {
166
168
if expectedPKIID != nil && ! bytes .Equal (pkiID , expectedPKIID ) {
167
169
// PKIID is nil when we don't know the remote PKI id's
168
170
c .logger .Warning ("Remote endpoint claims to be a different peer, expected" , expectedPKIID , "but got" , pkiID )
171
+ cc .Close ()
169
172
return nil , fmt .Errorf ("Authentication failure" )
170
173
}
171
174
conn := newConnection (cl , cc , stream , nil )
@@ -183,7 +186,6 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
183
186
conn .handler = h
184
187
return conn , nil
185
188
}
186
- return nil , fmt .Errorf ("Authentication failure" )
187
189
}
188
190
cc .Close ()
189
191
return nil , err
0 commit comments