Skip to content

Commit

Permalink
fixup! bridge/crypto: add ShareKeys function to CryptoHelper
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <sumner@beeper.com>
  • Loading branch information
sumnerevans committed Aug 3, 2023
1 parent e188814 commit b6bec7b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type Crypto interface {
Stop()
Reset(startAfterReset bool)
Client() *mautrix.Client
ShareKeys(context.Context) error
ShareOneTimeKeys(context.Context) error
}

func (br *Bridge) GenerateRegistration() {
Expand Down
5 changes: 3 additions & 2 deletions bridge/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ func (helper *CryptoHelper) HandleMemberEvent(evt *event.Event) {
helper.mach.HandleMemberEvent(0, evt)
}

func (helper *CryptoHelper) ShareKeys(ctx context.Context) error {
return helper.mach.ShareKeys(ctx, 0)
// ShareOneTimeKeys uploads the given number of one-time-keys to the server.
func (helper *CryptoHelper) ShareOneTimeKeys(ctx context.Context) error {
return helper.mach.ShareKeys(ctx, -1)
}

type cryptoSyncer struct {
Expand Down
4 changes: 2 additions & 2 deletions crypto/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ func (mach *OlmMachine) ShareKeys(ctx context.Context, currentOTKCount int) erro
start := time.Now()
mach.otkUploadLock.Lock()
defer mach.otkUploadLock.Unlock()
if mach.lastOTKUpload.Add(1 * time.Minute).After(start) {
log.Debug().Msg("Checking OTK count from server due to suspiciously close share keys requests")
if mach.lastOTKUpload.Add(1*time.Minute).After(start) || currentOTKCount < 0 {
log.Debug().Msg("Checking OTK count from server due to suspiciously close share keys requests or negative OTK count")
resp, err := mach.Client.UploadKeys(&mautrix.ReqUploadKeys{})
if err != nil {
return fmt.Errorf("failed to check current OTK counts: %w", err)
Expand Down

0 comments on commit b6bec7b

Please sign in to comment.