@@ -16,6 +16,7 @@ import (
16
16
"github.com/golang/protobuf/proto"
17
17
"github.com/hyperledger/fabric/common/flogging"
18
18
commonledger "github.com/hyperledger/fabric/common/ledger"
19
+ "github.com/hyperledger/fabric/common/resourcesconfig"
19
20
"github.com/hyperledger/fabric/common/util"
20
21
"github.com/hyperledger/fabric/core/aclmgmt"
21
22
"github.com/hyperledger/fabric/core/aclmgmt/resources"
@@ -61,6 +62,16 @@ type pendingQueryResult struct {
61
62
62
63
type stateHandlers map [pb.ChaincodeMessage_Type ]func (* pb.ChaincodeMessage )
63
64
65
+ // internal interface to scope dependencies on ChaincodeSupport
66
+ type handlerSupport interface {
67
+ deregisterHandler (* Handler ) error
68
+ registerHandler (* Handler ) error
69
+
70
+ GetChaincodeDefinition (ctxt context.Context , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , chainID string , chaincodeID string ) (resourcesconfig.ChaincodeDefinition , error )
71
+ Launch (context context.Context , cccid * ccprovider.CCContext , spec interface {}) (* pb.ChaincodeID , * pb.ChaincodeInput , error )
72
+ Execute (ctxt context.Context , cccid * ccprovider.CCContext , msg * pb.ChaincodeMessage , timeout time.Duration ) (* pb.ChaincodeMessage , error )
73
+ }
74
+
64
75
// Handler responsible for management of Peer's side of chaincode stream
65
76
type Handler struct {
66
77
sync.Mutex
@@ -71,9 +82,9 @@ type Handler struct {
71
82
ChaincodeID * pb.ChaincodeID
72
83
ccInstance * sysccprovider.ChaincodeInstance
73
84
74
- chaincodeSupport * ChaincodeSupport
75
- registered bool
76
- readyNotify chan bool
85
+ handlerSupport handlerSupport
86
+ registered bool
87
+ readyNotify chan bool
77
88
78
89
//chan to pass error in sync and nonsync mode
79
90
errChan chan error
@@ -86,6 +97,9 @@ type Handler struct {
86
97
//handlers for each state of the handler
87
98
readyStateHandlers stateHandlers
88
99
createStateHandlers stateHandlers
100
+
101
+ keepalive time.Duration
102
+ userRunsCC bool
89
103
}
90
104
91
105
func shorttxid (txid string ) string {
@@ -261,14 +275,14 @@ func (handler *Handler) checkACL(signedProp *pb.SignedProposal, proposal *pb.Pro
261
275
262
276
func (handler * Handler ) deregister () error {
263
277
if handler .registered {
264
- handler .chaincodeSupport .deregisterHandler (handler )
278
+ handler .handlerSupport .deregisterHandler (handler )
265
279
}
266
280
return nil
267
281
}
268
282
269
283
func (handler * Handler ) waitForKeepaliveTimer () <- chan time.Time {
270
- if handler .chaincodeSupport . keepalive > 0 {
271
- c := time .After (handler .chaincodeSupport . keepalive )
284
+ if handler .keepalive > 0 {
285
+ c := time .After (handler .keepalive )
272
286
return c
273
287
}
274
288
//no one will signal this channel, listener blocks forever
@@ -339,8 +353,8 @@ func (handler *Handler) processStream() error {
339
353
chaincodeLogger .Errorf ("%s" , err )
340
354
return err
341
355
case <- handler .waitForKeepaliveTimer ():
342
- if handler .chaincodeSupport . keepalive <= 0 {
343
- chaincodeLogger .Errorf ("Invalid select: keepalive not on (keepalive=%d)" , handler .chaincodeSupport . keepalive )
356
+ if handler .keepalive <= 0 {
357
+ chaincodeLogger .Errorf ("Invalid select: keepalive not on (keepalive=%d)" , handler .keepalive )
344
358
continue
345
359
}
346
360
@@ -369,10 +383,12 @@ func HandleChaincodeStream(chaincodeSupport *ChaincodeSupport, ctxt context.Cont
369
383
370
384
func newChaincodeSupportHandler (chaincodeSupport * ChaincodeSupport , peerChatStream ccintf.ChaincodeStream ) * Handler {
371
385
v := & Handler {
372
- ChatStream : peerChatStream ,
373
- chaincodeSupport : chaincodeSupport ,
374
- state : created ,
375
- errChan : make (chan error , 1 ),
386
+ ChatStream : peerChatStream ,
387
+ handlerSupport : chaincodeSupport ,
388
+ state : created ,
389
+ errChan : make (chan error , 1 ),
390
+ keepalive : chaincodeSupport .keepalive ,
391
+ userRunsCC : chaincodeSupport .userRunsCC ,
376
392
}
377
393
378
394
v .readyStateHandlers = stateHandlers {
@@ -466,7 +482,7 @@ func (handler *Handler) notifyDuringStartup(val bool) {
466
482
//environment where we can attach a chaincode manually. This could be
467
483
//useful .... but for now lets just be conservative and allow manual
468
484
//chaincode only in dev mode (ie, peer started with --peer-chaincodedev=true)
469
- if handler .chaincodeSupport . userRunsCC {
485
+ if handler .userRunsCC {
470
486
if val {
471
487
handler .sendReady ()
472
488
} else {
@@ -489,7 +505,7 @@ func (handler *Handler) handleRegister(msg *pb.ChaincodeMessage) {
489
505
490
506
// Now register with the chaincodeSupport
491
507
handler .ChaincodeID = chaincodeID
492
- err = handler .chaincodeSupport .registerHandler (handler )
508
+ err = handler .handlerSupport .registerHandler (handler )
493
509
if err != nil {
494
510
handler .notifyDuringStartup (false )
495
511
return
@@ -1191,7 +1207,7 @@ func (handler *Handler) handleModState(msg *pb.ChaincodeMessage) {
1191
1207
var version string
1192
1208
if ! isscc {
1193
1209
//if its a user chaincode, get the details
1194
- cd , err := handler .chaincodeSupport .GetChaincodeDefinition (ctxt , msg .Txid , txContext .signedProp , txContext .proposal , calledCcIns .ChainID , calledCcIns .ChaincodeName )
1210
+ cd , err := handler .handlerSupport .GetChaincodeDefinition (ctxt , msg .Txid , txContext .signedProp , txContext .proposal , calledCcIns .ChainID , calledCcIns .ChaincodeName )
1195
1211
if err != nil {
1196
1212
errHandler ([]byte (err .Error ()), "[%s]Failed to get chaincode data (%s) for invoked chaincode. Sending %s" , shorttxid (msg .Txid ), err , pb .ChaincodeMessage_ERROR )
1197
1213
return
@@ -1215,7 +1231,7 @@ func (handler *Handler) handleModState(msg *pb.ChaincodeMessage) {
1215
1231
chaincodeLogger .Debugf ("[%s] launching chaincode %s on channel %s" ,
1216
1232
shorttxid (msg .Txid ), calledCcIns .ChaincodeName , calledCcIns .ChainID )
1217
1233
cciSpec := & pb.ChaincodeInvocationSpec {ChaincodeSpec : chaincodeSpec }
1218
- _ , chaincodeInput , launchErr := handler .chaincodeSupport .Launch (ctxt , cccid , cciSpec )
1234
+ _ , chaincodeInput , launchErr := handler .handlerSupport .Launch (ctxt , cccid , cciSpec )
1219
1235
if launchErr != nil {
1220
1236
payload := []byte (launchErr .Error ())
1221
1237
chaincodeLogger .Debugf ("[%s]Failed to launch invoked chaincode. Sending %s" ,
@@ -1230,7 +1246,7 @@ func (handler *Handler) handleModState(msg *pb.ChaincodeMessage) {
1230
1246
ccMsg , _ := createCCMessage (pb .ChaincodeMessage_TRANSACTION , calledCcIns .ChainID , msg .Txid , chaincodeInput )
1231
1247
1232
1248
// Execute the chaincode... this CANNOT be an init at least for now
1233
- response , execErr := handler .chaincodeSupport .Execute (ctxt , cccid , ccMsg , timeout )
1249
+ response , execErr := handler .handlerSupport .Execute (ctxt , cccid , ccMsg , timeout )
1234
1250
1235
1251
//payload is marshalled and send to the calling chaincode's shim which unmarshals and
1236
1252
//sends it to chaincode
0 commit comments