@@ -8,18 +8,14 @@ package chaincode
8
8
9
9
import (
10
10
"fmt"
11
- "strconv"
12
- "strings"
13
11
"time"
14
12
15
13
"github.com/golang/protobuf/proto"
16
- "github.com/hyperledger/fabric/common/flogging"
17
14
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
18
15
"github.com/hyperledger/fabric/core/common/ccprovider"
19
16
"github.com/hyperledger/fabric/core/container"
20
17
"github.com/hyperledger/fabric/core/container/ccintf"
21
18
pb "github.com/hyperledger/fabric/protos/peer"
22
- logging "github.com/op/go-logging"
23
19
"github.com/pkg/errors"
24
20
"github.com/spf13/viper"
25
21
"golang.org/x/net/context"
@@ -70,99 +66,49 @@ func (cs *ChaincodeSupport) preLaunchSetup(chaincode string, notify chan bool) {
70
66
71
67
// NewChaincodeSupport creates a new ChaincodeSupport instance
72
68
func NewChaincodeSupport (
69
+ config * Config ,
73
70
peerAddress string ,
74
71
userrunsCC bool ,
75
72
ccstartuptimeout time.Duration ,
76
73
caCert []byte ,
77
74
certGenerator CertGenerator ,
78
75
) * ChaincodeSupport {
79
76
ccprovider .SetChaincodesPath (ccprovider .GetCCsPath ())
80
- pnid := viper .GetString ("peer.networkId" )
81
- pid := viper .GetString ("peer.id" )
82
77
83
- theChaincodeSupport := & ChaincodeSupport {
84
- caCert : caCert ,
85
- peerNetworkID : pnid ,
86
- peerID : pid ,
78
+ cs := & ChaincodeSupport {
79
+ caCert : caCert ,
80
+ peerNetworkID : config .PeerNetworkID ,
81
+ peerID : config .PeerID ,
82
+ userRunsCC : userrunsCC ,
83
+ ccStartupTimeout : ccstartuptimeout ,
84
+ keepalive : config .Keepalive ,
85
+ executetimeout : config .ExecuteTimeout ,
87
86
runningChaincodes : & runningChaincodes {
88
87
chaincodeMap : make (map [string ]* chaincodeRTEnv ),
89
88
launchStarted : make (map [string ]bool ),
90
89
},
91
90
}
92
91
93
- theChaincodeSupport .userRunsCC = userrunsCC
94
- theChaincodeSupport .ccStartupTimeout = ccstartuptimeout
95
- theChaincodeSupport .peerTLS = viper .GetBool ("peer.tls.enabled" )
96
-
97
- kadef := 0
98
- if ka := viper .GetString ("chaincode.keepalive" ); ka == "" {
99
- theChaincodeSupport .keepalive = time .Duration (kadef ) * time .Second
100
- } else {
101
- t , terr := strconv .Atoi (ka )
102
- if terr != nil {
103
- chaincodeLogger .Errorf ("Invalid keepalive value %s (%s) defaulting to %d" , ka , terr , kadef )
104
- t = kadef
105
- } else if t <= 0 {
106
- chaincodeLogger .Debugf ("Turn off keepalive(value %s)" , ka )
107
- t = kadef
108
- }
109
- theChaincodeSupport .keepalive = time .Duration (t ) * time .Second
110
- }
111
-
112
- //default chaincode execute timeout is 30 secs
113
- execto := time .Duration (30 ) * time .Second
114
- if eto := viper .GetDuration ("chaincode.executetimeout" ); eto <= time .Duration (1 )* time .Second {
115
- chaincodeLogger .Errorf ("Invalid execute timeout value %s (should be at least 1s); defaulting to %s" , eto , execto )
116
- } else {
117
- chaincodeLogger .Debugf ("Setting execute timeout value to %s" , eto )
118
- execto = eto
119
- }
120
-
121
- theChaincodeSupport .executetimeout = execto
122
-
123
- viper .SetEnvPrefix ("CORE" )
124
- viper .AutomaticEnv ()
125
- replacer := strings .NewReplacer ("." , "_" )
126
- viper .SetEnvKeyReplacer (replacer )
127
-
128
- theChaincodeSupport .chaincodeLogLevel = getLogLevelFromViper ("level" )
129
- theChaincodeSupport .shimLogLevel = getLogLevelFromViper ("shim" )
130
- theChaincodeSupport .logFormat = viper .GetString ("chaincode.logging.format" )
131
-
132
92
// Keep TestQueries working
133
- if ! theChaincodeSupport . peerTLS {
93
+ if ! config . TLSEnabled {
134
94
certGenerator = nil
135
95
}
136
96
137
- theChaincodeSupport .ContainerRuntime = & ContainerRuntime {
97
+ cs .ContainerRuntime = & ContainerRuntime {
138
98
CertGenerator : certGenerator ,
139
99
Processor : ProcessFunc (container .VMCProcess ),
140
100
CACert : caCert ,
141
101
PeerAddress : peerAddress ,
142
- PeerID : pid ,
143
- PeerNetworkID : pnid ,
102
+ PeerID : config . PeerID ,
103
+ PeerNetworkID : config . PeerNetworkID ,
144
104
CommonEnv : []string {
145
- "CORE_CHAINCODE_LOGGING_LEVEL=" + theChaincodeSupport . chaincodeLogLevel ,
146
- "CORE_CHAINCODE_LOGGING_SHIM=" + theChaincodeSupport . shimLogLevel ,
147
- "CORE_CHAINCODE_LOGGING_FORMAT=" + theChaincodeSupport . logFormat ,
105
+ "CORE_CHAINCODE_LOGGING_LEVEL=" + config . LogLevel ,
106
+ "CORE_CHAINCODE_LOGGING_SHIM=" + config . ShimLogLevel ,
107
+ "CORE_CHAINCODE_LOGGING_FORMAT=" + config . LogFormat ,
148
108
},
149
109
}
150
110
151
- return theChaincodeSupport
152
- }
153
-
154
- // getLogLevelFromViper gets the chaincode container log levels from viper
155
- func getLogLevelFromViper (module string ) string {
156
- levelString := viper .GetString ("chaincode.logging." + module )
157
- _ , err := logging .LogLevel (levelString )
158
-
159
- if err == nil {
160
- chaincodeLogger .Debugf ("CORE_CHAINCODE_%s set to level %s" , strings .ToUpper (module ), levelString )
161
- } else {
162
- chaincodeLogger .Warningf ("CORE_CHAINCODE_%s has invalid log level %s. defaulting to %s" , strings .ToUpper (module ), levelString , flogging .DefaultLevel ())
163
- levelString = flogging .DefaultLevel ()
164
- }
165
- return levelString
111
+ return cs
166
112
}
167
113
168
114
// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
@@ -174,12 +120,8 @@ type ChaincodeSupport struct {
174
120
peerNetworkID string
175
121
peerID string
176
122
keepalive time.Duration
177
- chaincodeLogLevel string
178
- shimLogLevel string
179
- logFormat string
180
123
executetimeout time.Duration
181
124
userRunsCC bool
182
- peerTLS bool
183
125
ContainerRuntime Runtime
184
126
}
185
127
0 commit comments