GODT-1187: Remove IMAP/SMTP blocking when no internet.

This commit is contained in:
Jakub
2021-05-28 09:59:31 +02:00
committed by Jakub Cuth
parent f0ee82fdd2
commit 21dcac9fac
10 changed files with 604 additions and 321 deletions

View File

@ -18,32 +18,24 @@
package serverutil
import (
"time"
"github.com/ProtonMail/proton-bridge/internal/events"
"github.com/ProtonMail/proton-bridge/pkg/listener"
"crypto/tls"
"io"
"net"
)
// Server which can handle disconnected users and lost internet connection.
// Server can handle disconnected users.
type Server interface {
Protocol() Protocol
UseSSL() bool
Address() string
TLSConfig() *tls.Config
DebugServer() bool
DebugClient() bool
SetLoggers(localDebug, remoteDebug io.Writer)
HandlePanic()
DisconnectUser(string)
ListenRetryAndServe(int, time.Duration)
}
func monitorDisconnectedUsers(s Server, l listener.Listener) {
ch := make(chan string)
l.Add(events.CloseConnectionEvent, ch)
for address := range ch {
s.DisconnectUser(address)
}
}
// ListenAndServe starts the server and keeps it on based on internet
// availability. It also monitors and disconnect users if requested.
func ListenAndServe(s Server, l listener.Listener) {
go monitorDisconnectedUsers(s, l)
// When starting the Bridge, we don't want to retry to notify user
// quickly about the issue. Very probably retry will not help anyway.
s.ListenRetryAndServe(0, 0)
Serve(net.Listener) error
StopServe() error
}