mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2026-02-04 16:28:37 +00:00
GODT-1187: Remove IMAP/SMTP blocking when no internet.
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user