mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-27 20:16:44 +00:00
fix: address review comments
This commit is contained in:
@ -29,7 +29,6 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/internal/preferences"
|
||||
"github.com/ProtonMail/proton-bridge/internal/store"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
@ -37,8 +36,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
|
||||
isApplicationOutdated = false //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "bridge") //nolint[gochecknoglobals]
|
||||
isApplicationOutdated = false //nolint[gochecknoglobals]
|
||||
)
|
||||
|
||||
// Bridge is a struct handling users.
|
||||
@ -65,7 +64,8 @@ type Bridge struct {
|
||||
|
||||
lock sync.RWMutex
|
||||
|
||||
cancel chan struct{}
|
||||
// stopAll can be closed to stop all goroutines from looping (watchBridgeOutdated, watchAPIAuths, heartbeat etc).
|
||||
stopAll chan struct{}
|
||||
|
||||
userAgentClientName string
|
||||
userAgentClientVersion string
|
||||
@ -94,7 +94,7 @@ func New(
|
||||
storeCache: store.NewCache(config.GetIMAPCachePath()),
|
||||
idleUpdates: make(chan interface{}),
|
||||
lock: sync.RWMutex{},
|
||||
cancel: make(chan struct{}),
|
||||
stopAll: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Allow DoH before starting bridge if the user has previously set this setting.
|
||||
@ -146,7 +146,7 @@ func (b *Bridge) heartbeat() {
|
||||
b.pref.Set(preferences.NextHeartbeatKey, strconv.FormatInt(nextTime.Unix(), 10))
|
||||
}
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (b *Bridge) watchBridgeOutdated() {
|
||||
isApplicationOutdated = true
|
||||
b.closeAllConnections()
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -218,7 +218,7 @@ func (b *Bridge) watchAPIAuths() {
|
||||
Error("User logout failed while watching API auths")
|
||||
}
|
||||
|
||||
case <-b.cancel:
|
||||
case <-b.stopAll:
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -568,7 +568,7 @@ func (b *Bridge) CheckConnection() error {
|
||||
|
||||
// StopWatchers stops all bridge goroutines.
|
||||
func (b *Bridge) StopWatchers() {
|
||||
close(b.cancel)
|
||||
close(b.stopAll)
|
||||
}
|
||||
|
||||
func (b *Bridge) updateCurrentUserAgent() {
|
||||
|
||||
6
internal/bridge/bridge_test_exports.go
Normal file
6
internal/bridge/bridge_test_exports.go
Normal file
@ -0,0 +1,6 @@
|
||||
package bridge
|
||||
|
||||
// IsAuthorized returns whether the user has received an Auth from the API yet.
|
||||
func (u *User) IsAuthorized() bool {
|
||||
return u.isAuthorized
|
||||
}
|
||||
@ -27,14 +27,13 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/logs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const sep = "\x00"
|
||||
|
||||
var (
|
||||
log = logs.GetLogEntry("bridge") //nolint[gochecknoglobals]
|
||||
log = logrus.WithField("pkg", "bridge") //nolint[gochecknoglobals]
|
||||
|
||||
ErrWrongFormat = errors.New("backend/creds: malformed password")
|
||||
)
|
||||
|
||||
@ -164,7 +164,7 @@ func (u *User) SetIMAPIdleUpdateChannel() {
|
||||
// it tries to connect it.
|
||||
func (u *User) authorizeIfNecessary(emitEvent bool) (err error) {
|
||||
// If user is connected and has an auth channel, then perfect, nothing to do here.
|
||||
if u.creds.IsConnected() && u.HasAPIAuth() {
|
||||
if u.creds.IsConnected() && u.isAuthorized {
|
||||
// The keyring unlock is triggered here to resolve state where apiClient
|
||||
// is authenticated (we have auth token) but it was not possible to download
|
||||
// and unlock the keys (internet not reachable).
|
||||
@ -585,7 +585,3 @@ func (u *User) CloseConnection(address string) {
|
||||
func (u *User) GetStore() *store.Store {
|
||||
return u.store
|
||||
}
|
||||
|
||||
func (u *User) HasAPIAuth() bool {
|
||||
return u.isAuthorized
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user