bool -> atomic.Bool to prevent "race condition"
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
a6a196a1c1
commit
243b827522
|
@ -50,7 +50,7 @@ type engine struct {
|
|||
authorizations sync.Map // string(onion) => model.Authorization
|
||||
|
||||
// Block Unknown Contacts
|
||||
blockUnknownContacts bool
|
||||
blockUnknownContacts atomic.Bool
|
||||
|
||||
// Pointer to the Global Event Manager
|
||||
eventManager event.Manager
|
||||
|
@ -240,10 +240,10 @@ func (e *engine) eventHandler() {
|
|||
}
|
||||
case event.AllowUnknownPeers:
|
||||
log.Debugf("%v now allows unknown connections", e.identity.Hostname())
|
||||
e.blockUnknownContacts = false
|
||||
e.blockUnknownContacts.Store(false)
|
||||
case event.BlockUnknownPeers:
|
||||
log.Debugf("%v now forbids unknown connections", e.identity.Hostname())
|
||||
e.blockUnknownContacts = true
|
||||
e.blockUnknownContacts.Store(true)
|
||||
case event.ProtocolEngineStartListen:
|
||||
go e.listenFn()
|
||||
case event.ShareManifest:
|
||||
|
@ -285,7 +285,7 @@ func (e *engine) isBlocked(onion string) bool {
|
|||
authorization, known := e.authorizations.Load(onion)
|
||||
if !known {
|
||||
// if we block unknown peers we will block this contact
|
||||
return e.blockUnknownContacts
|
||||
return e.blockUnknownContacts.Load()
|
||||
}
|
||||
return authorization.(model.Authorization) == model.AuthBlocked
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ func (e *engine) isAllowed(onion string) bool {
|
|||
log.Errorf("attempted to lookup authorization of onion not in map...that should never happen")
|
||||
return false
|
||||
}
|
||||
if e.blockUnknownContacts {
|
||||
if e.blockUnknownContacts.Load() {
|
||||
return authorization.(model.Authorization) == model.AuthApproved
|
||||
}
|
||||
return authorization.(model.Authorization) != model.AuthBlocked
|
||||
|
|
Loading…
Reference in New Issue