File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "errors"
1212 "fmt"
1313 "sync"
14+ "sync/atomic"
1415 "time"
1516
1617 "github.com/rs/zerolog"
@@ -67,7 +68,7 @@ type OlmMachine struct {
6768
6869 otkUploadLock sync.Mutex
6970 lastOTKUpload time.Time
70- receivedOTKsForSelf bool
71+ receivedOTKsForSelf atomic. Bool
7172
7273 CrossSigningKeys * CrossSigningKeysCache
7374 crossSigningPubkeys * CrossSigningPublicKeysCache
@@ -258,16 +259,18 @@ func (mach *OlmMachine) otkCountIsForCrossSigningKey(otkCount *mautrix.OTKCount)
258259}
259260
260261func (mach * OlmMachine ) HandleOTKCounts (ctx context.Context , otkCount * mautrix.OTKCount ) {
262+ receivedOTKsForSelf := mach .receivedOTKsForSelf .Load ()
261263 if (len (otkCount .UserID ) > 0 && otkCount .UserID != mach .Client .UserID ) || (len (otkCount .DeviceID ) > 0 && otkCount .DeviceID != mach .Client .DeviceID ) {
262- if otkCount .UserID != mach .Client .UserID || (! mach . receivedOTKsForSelf && ! mach .otkCountIsForCrossSigningKey (otkCount )) {
264+ if otkCount .UserID != mach .Client .UserID || (! receivedOTKsForSelf && ! mach .otkCountIsForCrossSigningKey (otkCount )) {
263265 mach .Log .Warn ().
264266 Str ("target_user_id" , otkCount .UserID .String ()).
265267 Str ("target_device_id" , otkCount .DeviceID .String ()).
266268 Msg ("Dropping OTK counts targeted to someone else" )
267269 }
268270 return
271+ } else if ! receivedOTKsForSelf {
272+ mach .receivedOTKsForSelf .Store (true )
269273 }
270- mach .receivedOTKsForSelf = true
271274
272275 minCount := mach .account .Internal .MaxNumberOfOneTimeKeys () / 2
273276 if otkCount .SignedCurve25519 < int (minCount ) {
You can’t perform that action at this time.
0 commit comments