feat: display mailserver interactions

This commit is contained in:
Richard Ramos 2021-09-17 12:16:58 -04:00 committed by Iuri Matias
parent 46bdec6268
commit 214069cb25
3 changed files with 49 additions and 15 deletions

View File

@ -81,7 +81,7 @@ proc isActiveMailserverAvailable*(self: MailserverModel): bool =
result = self.nodes[self.activeMailserver] == MailserverStatus.Connected result = self.nodes[self.activeMailserver] == MailserverStatus.Connected
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] info "Connecting to mailserver", enode=enode.substr[enode.len-40..enode.len-1]
var connected = false var connected = false
# TODO: this should come from settings # TODO: this should come from settings
var knownMailservers = initHashSet[string]() var knownMailservers = initHashSet[string]()
@ -92,6 +92,7 @@ proc connect(self: MailserverModel, enode: string) =
return return
self.activeMailserver = enode self.activeMailserver = enode
info "Mailserver changed", enode
self.events.emit("mailserver:changed", MailserverArgs(peer: enode)) self.events.emit("mailserver:changed", MailserverArgs(peer: enode))
# Adding a peer and marking it as connected can't be executed sync, because # Adding a peer and marking it as connected can't be executed sync, because
@ -109,6 +110,7 @@ proc connect(self: MailserverModel, enode: string) =
self.lastConnectionAttempt = cpuTime() self.lastConnectionAttempt = cpuTime()
if connected: if connected:
info "Mailserver available"
self.events.emit("mailserverAvailable", MailserverArgs()) self.events.emit("mailserverAvailable", MailserverArgs())
proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) = proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
@ -121,7 +123,7 @@ proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
var mailserverAvailable = false var mailserverAvailable = false
for knownPeer in self.nodes.keys: for knownPeer in self.nodes.keys:
if not peers.contains(knownPeer) and self.nodes[knownPeer] != MailserverStatus.Disconnected: if not peers.contains(knownPeer) and self.nodes[knownPeer] != MailserverStatus.Disconnected:
debug "Peer disconnected", peer=knownPeer info "Peer disconnected", peer=knownPeer
self.nodes[knownPeer] = MailserverStatus.Disconnected self.nodes[knownPeer] = MailserverStatus.Disconnected
self.events.emit("peerDisconnected", MailserverArgs(peer: knownPeer)) self.events.emit("peerDisconnected", MailserverArgs(peer: knownPeer))
if self.activeMailserver == knownPeer: if self.activeMailserver == knownPeer:
@ -130,7 +132,7 @@ proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
for peer in peers: for peer in peers:
if self.nodes.hasKey(peer) and (self.nodes[peer] == MailserverStatus.Connected): continue if self.nodes.hasKey(peer) and (self.nodes[peer] == MailserverStatus.Connected): continue
debug "Peer connected", peer info "Peer connected", peer
self.nodes[peer] = MailserverStatus.Connected self.nodes[peer] = MailserverStatus.Connected
self.events.emit("peerConnected", MailserverArgs(peer: peer)) self.events.emit("peerConnected", MailserverArgs(peer: peer))
@ -140,24 +142,24 @@ proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
mailserverAvailable = true mailserverAvailable = true
if mailserverAvailable: if mailserverAvailable:
debug "Mailserver available" info "Mailserver available"
self.events.emit("mailserverAvailable", MailserverArgs()) self.events.emit("mailserverAvailable", MailserverArgs())
proc requestMessages*(self: MailserverModel) = proc requestMessages*(self: MailserverModel) =
debug "Requesting messages from", mailserver=self.activeMailserver info "Requesting messages from", mailserver=self.activeMailserver
discard status_mailservers.requestAllHistoricMessages() discard status_mailservers.requestAllHistoricMessages()
proc requestStoreMessages*(self: MailserverModel, topics: seq[string], fromValue: int64 = 0, toValue: int64 = 0, force: bool = false) = proc requestStoreMessages*(self: MailserverModel, topics: seq[string], fromValue: int64 = 0, toValue: int64 = 0, force: bool = false) =
debug "Requesting messages from", mailserver=self.activeMailserver info "Requesting messages from", mailserver=self.activeMailserver
let generatedSymKey = status_chat.generateSymKeyFromPassword() let generatedSymKey = status_chat.generateSymKeyFromPassword()
status_mailservers.requestStoreMessages(topics, generatedSymKey, self.activeMailserver, 1000, fromValue, toValue, force) status_mailservers.requestStoreMessages(topics, generatedSymKey, self.activeMailserver, 1000, fromValue, toValue, force)
proc requestMoreMessages*(self: MailserverModel, chatId: string) = proc requestMoreMessages*(self: MailserverModel, chatId: string) =
debug "Requesting more messages from", mailserver=self.activeMailserver, chatId=chatId info "Requesting more messages from", mailserver=self.activeMailserver, chatId=chatId
discard status_mailservers.syncChatFromSyncedFrom(chatId) discard status_mailservers.syncChatFromSyncedFrom(chatId)
proc fillGaps*(self: MailserverModel, chatId: string, messageIds: seq[string]) = proc fillGaps*(self: MailserverModel, chatId: string, messageIds: seq[string]) =
debug "Requesting fill gaps from", mailserver=self.activeMailserver, chatId=chatId info "Requesting fill gaps from", mailserver=self.activeMailserver, chatId=chatId
discard status_mailservers.fillGaps(chatId, messageIds) discard status_mailservers.fillGaps(chatId, messageIds)
proc findNewMailserver(self: MailserverModel) = proc findNewMailserver(self: MailserverModel) =
@ -172,7 +174,9 @@ proc findNewMailserver(self: MailserverModel) =
availableMailservers.sort(cmpMailserverReply) availableMailservers.sort(cmpMailserverReply)
# No mailservers where returned... do nothing. # No mailservers where returned... do nothing.
if availableMailservers.len == 0: return if availableMailservers.len == 0:
warn "No mailservers available"
return
# Picks a random mailserver amongs the ones with the lowest latency # Picks a random mailserver amongs the ones with the lowest latency
# The pool size is 1/4 of the mailservers were pinged successfully # The pool size is 1/4 of the mailservers were pinged successfully
@ -185,7 +189,7 @@ proc findNewMailserver(self: MailserverModel) =
proc cycleMailservers(self: MailserverModel) = proc cycleMailservers(self: MailserverModel) =
warn "Automatically switching mailserver" warn "Automatically switching mailserver"
if self.activeMailserver != "": if self.activeMailserver != "":
warn "Disconnecting active mailserver", peer=self.activeMailserver info "Disconnecting active mailserver", peer=self.activeMailserver
self.nodes[self.activeMailserver] = MailserverStatus.Disconnected self.nodes[self.activeMailserver] = MailserverStatus.Disconnected
removePeer(self.activeMailserver) removePeer(self.activeMailserver)
self.activeMailserver = "" self.activeMailserver = ""
@ -193,7 +197,7 @@ proc cycleMailservers(self: MailserverModel) =
proc checkConnection*(self: MailserverModel) {.async.} = proc checkConnection*(self: MailserverModel) {.async.} =
while true: while true:
debug "Verifying mailserver connection state..." info "Verifying mailserver connection state..."
let pinnedMailserver = status_settings.getPinnedMailserver() let pinnedMailserver = status_settings.getPinnedMailserver()
if pinnedMailserver != "" and self.activeMailserver != pinnedMailserver: if pinnedMailserver != "" and self.activeMailserver != pinnedMailserver:
# connect to current mailserver from the settings # connect to current mailserver from the settings

View File

@ -100,6 +100,26 @@ Item {
} }
} }
ColumnLayout {
id: mailserverLogsContainer
height: 300
StyledText {
color: Style.current.lightBlueText
text: "Mailserver Interactions:"
Layout.rightMargin: Style.current.padding
Layout.leftMargin: Style.current.padding
Layout.fillWidth: true
font.weight: Font.Medium
font.pixelSize: 20
}
StyledTextArea {
id: mailserverLogTxt
text: ""
customHeight: 200
textField.readOnly: true
}
}
ColumnLayout { ColumnLayout {
id: logContainer id: logContainer
height: 300 height: 300
@ -119,10 +139,20 @@ Item {
customHeight: 200 customHeight: 200
textField.readOnly: true textField.readOnly: true
} }
}
Connections { Connections {
target: nodeModel target: nodeModel
function onLog(logContent) { function onLog(logContent) {
// TODO: this is ugly, but there's not even a design for this section
if(logContent.indexOf("mailserver") > 0){
let lines = mailserverLogTxt.text.split("\n");
if (lines.length > 10){
lines.shift();
}
lines.push(logContent.trim())
mailserverLogTxt.text = lines.join("\n")
} else {
let lines = logsTxt.text.split("\n"); let lines = logsTxt.text.split("\n");
if (lines.length > 5){ if (lines.length > 5){
lines.shift(); lines.shift();

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit f42c249395fb969fbdc75be8f4da5902c4a343ad Subproject commit 3655396b572e389a7e4b7e1d2311afa90514ad98