forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
64 lines (52 loc) · 1.46 KB
/
opts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package pkcs11
const (
defaultSessionCacheSize = 10
defaultOpenSessionRetry = 10
)
//ctxOpts options for conext handler
type ctxOpts struct {
//sessionCacheSize size of session cache pool
sessionCacheSize int
//openSessionRetry number of retry for open session logic
openSessionRetry int
//connectionName do maintain unique instances in cache for connections under same label and lib
connectionName string
}
//Options for PKCS11 ContextHandle
type Options func(opts *ctxOpts)
func getCtxOpts(opts ...Options) ctxOpts {
ctxOptions := ctxOpts{}
for _, option := range opts {
option(&ctxOptions)
}
if ctxOptions.sessionCacheSize == 0 {
ctxOptions.sessionCacheSize = defaultSessionCacheSize
}
if ctxOptions.openSessionRetry == 0 {
ctxOptions.openSessionRetry = defaultOpenSessionRetry
}
return ctxOptions
}
//WithSessionCacheSize size of session cache pool
func WithSessionCacheSize(size int) Options {
return func(o *ctxOpts) {
o.sessionCacheSize = size
}
}
//WithOpenSessionRetry number of retry for open session logic
func WithOpenSessionRetry(count int) Options {
return func(o *ctxOpts) {
o.openSessionRetry = count
}
}
//WithConnectionName name of connection to avoild collision with other connection instances in cache
//under same label and lib
func WithConnectionName(name string) Options {
return func(o *ctxOpts) {
o.connectionName = name
}
}