Commit d4876ea8 authored by waels's avatar waels
Browse files

[FAB-11640]: fix race condition in gossip/identity



Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651
Signed-off-by: default avatarwaels <wael.shama@ibm.com>

"[FAB-11640]: fix and modify to RWMutex"

Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651
Signed-off-by: default avatarwaels <wael.shama@ibm.com>

[FAB-11640]: modify to use atomic operations

Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651
Signed-off-by: default avatarwaels <wael.shama@ibm.com>
parent 2b9a8167
......@@ -87,11 +87,12 @@ func NewIdentityMapper(mcs api.MessageCryptoService, selfIdentity api.PeerIdenti
}
func (is *identityMapperImpl) periodicalPurgeUnusedIdentities() {
usageTh := GetIdentityUsageThreshold()
for {
select {
case <-is.stopChan:
return
case <-time.After(usageThreshold / 10):
case <-time.After(usageTh / 10):
is.SuspectPeers(func(_ api.PeerIdentityType) bool {
return false
})
......@@ -197,11 +198,12 @@ func (is *identityMapperImpl) SuspectPeers(isSuspected api.PeerSuspector) {
// used for a long time
func (is *identityMapperImpl) validateIdentities(isSuspected api.PeerSuspector) []*storedIdentity {
now := time.Now()
usageTh := GetIdentityUsageThreshold()
is.RLock()
defer is.RUnlock()
var revokedIdentities []*storedIdentity
for pkiID, storedIdentity := range is.pkiID2Cert {
if pkiID != is.selfPKIID && storedIdentity.fetchLastAccessTime().Add(usageThreshold).Before(now) {
if pkiID != is.selfPKIID && storedIdentity.fetchLastAccessTime().Add(usageTh).Before(now) {
revokedIdentities = append(revokedIdentities, storedIdentity)
continue
}
......@@ -275,12 +277,12 @@ func (si *storedIdentity) cancelExpirationTimer() {
// Identities that are not used at least once during the given time
// are purged
func SetIdentityUsageThreshold(duration time.Duration) {
usageThreshold = duration
atomic.StoreInt64((*int64)(&usageThreshold), int64(duration))
}
// GetIdentityUsageThreshold returns the usage threshold of identities.
// Identities that are not used at least once during the usage threshold
// duration are purged.
func GetIdentityUsageThreshold() time.Duration {
return usageThreshold
return time.Duration(atomic.LoadInt64((*int64)(&usageThreshold)))
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment