use mailserver cycle or specific mailserver depending on settings
This commit is contained in:
parent
2a6eb20094
commit
199d5a0342
|
@ -99,7 +99,7 @@ proc isActiveMailserverAvailable*(self:MailserverModel): bool =
|
||||||
|
|
||||||
proc connect(self: MailserverModel, enode: string) =
|
proc connect(self: MailserverModel, enode: string) =
|
||||||
debug "Connecting to mailserver", enode=enode.substr[enode.len-40..enode.len-1]
|
debug "Connecting to mailserver", enode=enode.substr[enode.len-40..enode.len-1]
|
||||||
|
var mailserverTrusted = false
|
||||||
# TODO: this should come from settings
|
# TODO: this should come from settings
|
||||||
var knownMailservers = initHashSet[string]()
|
var knownMailservers = initHashSet[string]()
|
||||||
for m in self.mailservers:
|
for m in self.mailservers:
|
||||||
|
@ -120,14 +120,20 @@ proc connect(self: MailserverModel, enode: string) =
|
||||||
# Connecting and once a peerConnected signal is received, we mark it as
|
# Connecting and once a peerConnected signal is received, we mark it as
|
||||||
# Connected and then as Trusted
|
# Connected and then as Trusted
|
||||||
|
|
||||||
# Attempt to connect to mailserver by adding it as a peer
|
if self.nodes.hasKey(enode) and self.nodes[enode] == MailserverStatus.Connected:
|
||||||
self.nodes[enode] = MailserverStatus.Connecting
|
self.trustPeer(enode)
|
||||||
addPeer(enode)
|
status_mailservers.update(enode)
|
||||||
self.lastConnectionAttempt = cpuTime()
|
mailserverTrusted = true
|
||||||
|
else:
|
||||||
|
# Attempt to connect to mailserver by adding it as a peer
|
||||||
|
self.nodes[enode] = MailserverStatus.Connecting
|
||||||
|
addPeer(enode)
|
||||||
|
self.lastConnectionAttempt = cpuTime()
|
||||||
|
|
||||||
nodesLock.release()
|
nodesLock.release()
|
||||||
activeMailserverLock.release()
|
activeMailserverLock.release()
|
||||||
|
if mailserverTrusted:
|
||||||
|
self.events.emit("mailserverAvailable", Args())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,16 +240,19 @@ proc cycleMailservers(self: MailserverModel) =
|
||||||
|
|
||||||
proc checkConnection() {.thread.} =
|
proc checkConnection() {.thread.} =
|
||||||
{.gcsafe.}:
|
{.gcsafe.}:
|
||||||
#TODO: connect to current mailserver from the settings
|
|
||||||
|
|
||||||
# or setup a random mailserver:
|
|
||||||
let sleepDuration = 10000
|
let sleepDuration = 10000
|
||||||
while true:
|
while true:
|
||||||
trace "Verifying mailserver connection state..."
|
trace "Verifying mailserver connection state..."
|
||||||
withLock modelLock:
|
withLock modelLock:
|
||||||
# TODO: have a timeout for reconnection before changing to a different server
|
let pinnedMailserver = status_settings.getPinnedMailserver()
|
||||||
if not mailserverModel.isActiveMailserverAvailable:
|
if pinnedMailserver != "" and mailserverModel.getActiveMailserver() != pinnedMailserver:
|
||||||
mailserverModel.cycleMailservers()
|
# connect to current mailserver from the settings
|
||||||
|
mailserverModel.connect(pinnedMailserver)
|
||||||
|
else:
|
||||||
|
# or setup a random mailserver:
|
||||||
|
if not mailserverModel.isActiveMailserverAvailable:
|
||||||
|
# TODO: have a timeout for reconnection before changing to a different server
|
||||||
|
mailserverModel.cycleMailservers()
|
||||||
sleep(sleepDuration)
|
sleep(sleepDuration)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue