From 0e3bf04daf572abccb3a72982e0ab93b4b8406bc Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 25 Feb 2021 17:22:29 +0200 Subject: [PATCH] Improve post-reconnection resending and fix potential encryption races --- go.mod | 2 +- go.sum | 2 ++ portal.go | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 3cb04f0..61a7252 100644 --- a/go.mod +++ b/go.mod @@ -16,4 +16,4 @@ require ( maunium.net/go/mautrix v0.8.4 ) -replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225122703-9332bfd1058f +replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225152147-6bc95e2c807b diff --git a/go.sum b/go.sum index eb82c77..7967efa 100644 --- a/go.sum +++ b/go.sum @@ -307,6 +307,8 @@ github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225114646-8538575a439d h1:qvuNKX github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225114646-8538575a439d/go.mod h1:rwwuTh1bKqhgrRvOBAr8hDqtuz8Cc1Quqw/0BeXb+/E= github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225122703-9332bfd1058f h1:3/OXcaPXdDRfnj8X29JfSfSdkSNVt2n+qzrJQSlFaqY= github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225122703-9332bfd1058f/go.mod h1:rwwuTh1bKqhgrRvOBAr8hDqtuz8Cc1Quqw/0BeXb+/E= +github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225152147-6bc95e2c807b h1:1RezMfaShkQGGygQc+/ICFKYUPTPc1Dp25uTYEtSDVI= +github.com/tulir/go-whatsapp v0.4.0-rc.2.0.20210225152147-6bc95e2c807b/go.mod h1:rwwuTh1bKqhgrRvOBAr8hDqtuz8Cc1Quqw/0BeXb+/E= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= diff --git a/portal.go b/portal.go index c70396a..feb3c9d 100644 --- a/portal.go +++ b/portal.go @@ -171,6 +171,7 @@ type Portal struct { log log.Logger roomCreateLock sync.Mutex + encryptLock sync.Mutex recentlyHandled [recentlyHandledLength]whatsapp.MessageID recentlyHandledLock sync.Mutex @@ -1305,7 +1306,10 @@ func (portal *Portal) sendMessageDirect(intent *appservice.IntentAPI, eventType } } if portal.Encrypted && portal.bridge.Crypto != nil { + // TODO maybe the locking should be inside mautrix-go? + portal.encryptLock.Lock() encrypted, err := portal.bridge.Crypto.Encrypt(portal.MXID, eventType, wrappedContent) + portal.encryptLock.Unlock() if err != nil { return nil, fmt.Errorf("failed to encrypt event: %w", err) }