@@ -87,11 +87,12 @@ func NewIdentityMapper(mcs api.MessageCryptoService, selfIdentity api.PeerIdenti
87
87
}
88
88
89
89
func (is * identityMapperImpl ) periodicalPurgeUnusedIdentities () {
90
+ usageTh := GetIdentityUsageThreshold ()
90
91
for {
91
92
select {
92
93
case <- is .stopChan :
93
94
return
94
- case <- time .After (usageThreshold / 10 ):
95
+ case <- time .After (usageTh / 10 ):
95
96
is .SuspectPeers (func (_ api.PeerIdentityType ) bool {
96
97
return false
97
98
})
@@ -197,11 +198,12 @@ func (is *identityMapperImpl) SuspectPeers(isSuspected api.PeerSuspector) {
197
198
// used for a long time
198
199
func (is * identityMapperImpl ) validateIdentities (isSuspected api.PeerSuspector ) []* storedIdentity {
199
200
now := time .Now ()
201
+ usageTh := GetIdentityUsageThreshold ()
200
202
is .RLock ()
201
203
defer is .RUnlock ()
202
204
var revokedIdentities []* storedIdentity
203
205
for pkiID , storedIdentity := range is .pkiID2Cert {
204
- if pkiID != is .selfPKIID && storedIdentity .fetchLastAccessTime ().Add (usageThreshold ).Before (now ) {
206
+ if pkiID != is .selfPKIID && storedIdentity .fetchLastAccessTime ().Add (usageTh ).Before (now ) {
205
207
revokedIdentities = append (revokedIdentities , storedIdentity )
206
208
continue
207
209
}
@@ -275,12 +277,12 @@ func (si *storedIdentity) cancelExpirationTimer() {
275
277
// Identities that are not used at least once during the given time
276
278
// are purged
277
279
func SetIdentityUsageThreshold (duration time.Duration ) {
278
- usageThreshold = duration
280
+ atomic . StoreInt64 (( * int64 )( & usageThreshold ), int64 ( duration ))
279
281
}
280
282
281
283
// GetIdentityUsageThreshold returns the usage threshold of identities.
282
284
// Identities that are not used at least once during the usage threshold
283
285
// duration are purged.
284
286
func GetIdentityUsageThreshold () time.Duration {
285
- return usageThreshold
287
+ return time . Duration ( atomic . LoadInt64 (( * int64 )( & usageThreshold )))
286
288
}
0 commit comments