Set mailserverfleet on init

This commit is contained in:
Richard Ramos 2020-11-11 14:22:22 -04:00 committed by RichΛrd
parent 67face5b99
commit 950a7a4241
1 changed files with 5 additions and 3 deletions

View File

@ -39,12 +39,13 @@ type
Trusted = 3, Trusted = 3,
MailserverModel* = ref object MailserverModel* = ref object
fleet*: FleetModel mailservers*: seq[string]
events*: EventEmitter events*: EventEmitter
nodes*: Table[string, MailserverStatus] nodes*: Table[string, MailserverStatus]
activeMailserver*: string activeMailserver*: string
topics*: HashSet[string] topics*: HashSet[string]
lastConnectionAttempt*: float lastConnectionAttempt*: float
fleet*: FleetModel
proc cmpMailserverReply(x, y: (string, int)): int = proc cmpMailserverReply(x, y: (string, int)): int =
@ -98,7 +99,7 @@ proc connect(self: MailserverModel, enode: string) =
# TODO: this should come from settings # TODO: this should come from settings
var knownMailservers = initHashSet[string]() var knownMailservers = initHashSet[string]()
for m in self.fleet.config.getMailservers(status_settings.getFleet()).values(): for m in self.mailservers:
knownMailservers.incl m knownMailservers.incl m
if not knownMailservers.contains(enode): if not knownMailservers.contains(enode):
warn "Mailserver not known", enode warn "Mailserver not known", enode
@ -196,7 +197,7 @@ proc addMailserverTopic*(self: MailserverModel, topic: MailserverTopic) =
proc findNewMailserver(self: MailserverModel) = proc findNewMailserver(self: MailserverModel) =
warn "Finding a new mailserver..." warn "Finding a new mailserver..."
let mailserversReply = parseJson(status_mailservers.ping(toSeq(self.fleet.config.getMailservers(status_settings.getFleet()).values), 500))["result"] let mailserversReply = parseJson(status_mailservers.ping(self.mailservers, 500))["result"]
var availableMailservers:seq[(string, int)] = @[] var availableMailservers:seq[(string, int)] = @[]
for reply in mailserversReply: for reply in mailserversReply:
@ -244,5 +245,6 @@ proc checkConnection() {.thread.} =
proc init*(self: MailserverModel) = proc init*(self: MailserverModel) =
debug "MailserverModel::init()" debug "MailserverModel::init()"
self.mailservers = toSeq(self.fleet.config.getMailservers(status_settings.getFleet()).values)
connThread.createThread(checkConnection) connThread.createThread(checkConnection)