mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridge/crypto: add ShareKeys function to CryptoHelper
Signed-off-by: Sumner Evans <sumner@beeper.com>
This commit is contained in:
parent
16a756dc31
commit
c273e40a12
3 changed files with 9 additions and 2 deletions
|
|
@ -7,6 +7,7 @@
|
|||
package bridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -219,6 +220,7 @@ type Crypto interface {
|
|||
Stop()
|
||||
Reset(startAfterReset bool)
|
||||
Client() *mautrix.Client
|
||||
ShareKeys(context.Context) error
|
||||
}
|
||||
|
||||
func (br *Bridge) GenerateRegistration() {
|
||||
|
|
|
|||
|
|
@ -436,6 +436,11 @@ func (helper *CryptoHelper) HandleMemberEvent(evt *event.Event) {
|
|||
helper.mach.HandleMemberEvent(0, evt)
|
||||
}
|
||||
|
||||
// ShareKeys uploads the given number of one-time-keys to the server.
|
||||
func (helper *CryptoHelper) ShareKeys(ctx context.Context) error {
|
||||
return helper.mach.ShareKeys(ctx, -1)
|
||||
}
|
||||
|
||||
type cryptoSyncer struct {
|
||||
*crypto.OlmMachine
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue