feat: display bloom filter usage

This commit is contained in:
Richard Ramos 2021-08-24 21:31:20 -04:00 committed by Iuri Matias
parent 033fb3637d
commit 1969130fad
7 changed files with 79 additions and 2 deletions

View File

@ -36,5 +36,6 @@ proc init*(self: NodeController) =
self.status.events.on(SignalType.Stats.event) do (e:Args):
self.view.setStats(StatsSignal(e).stats)
self.view.getBitsSet()
self.view.init()

View File

@ -1,10 +1,30 @@
import NimQml, chronicles, strutils, json
import ../../status/[status, node, types, settings, accounts]
import ../../status/signals/types as signal_types
import ../../status/tasks/[qt, task_runner_impl]
logScope:
topics = "node-view"
type
BloomBitsSetTaskArg = ref object of QObjectTaskArg
bitsSet: int
const bloomBitsSetTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let
arg = decode[BloomBitsSetTaskArg](argEncoded)
output = getBloomFilterBitsSet(nil)
arg.finish(output)
proc bloomFiltersBitsSet[T](self: T, slot: string) =
let arg = BloomBitsSetTaskArg(
tptr: cast[ByteAddress](bloomBitsSetTask),
vptr: cast[ByteAddress](self.vptr),
slot: slot
)
self.status.tasks.threadpool.start(arg)
QtObject:
type NodeView* = ref object of QObject
status*: Status
@ -14,6 +34,7 @@ QtObject:
fullNode*: bool
stats*: Stats
peerSize: int
bloomBitsSet: int
proc setup(self: NodeView) =
self.QObject.setup
@ -133,6 +154,22 @@ QtObject:
self.stats = stats
self.statsChanged()
proc getBitsSet*(self: NodeView) =
self.bloomFiltersBitsSet("bitsSet")
proc getBloomBitsSet(self: NodeView): int {.slot.} =
self.bloomBitsSet
proc bloomBitsSetChanged(self: NodeView) {.signal.}
proc bitsSet*(self: NodeView, bitsSet: string) {.slot.} =
self.bloomBitsSet = parseInt(bitsSet)
self.bloomBitsSetChanged();
QtProperty[int] bloomBits:
read = getBloomBitsSet
notify = bloomBitsSetChanged
proc uploadRate*(self: NodeView): string {.slot.} = $self.stats.uploadRate
QtProperty[string] uploadRate:

View File

@ -162,9 +162,9 @@ var NODE_CONFIG* = %* {
"URL": "https://mainnet.infura.io/v3/" & INFURA_TOKEN_RESOLVED
},
"WakuConfig": {
"BloomFilterMode": false,
"BloomFilterMode": true,
"Enabled": true,
"LightClient": false,
"LightClient": true,
"MinimumPoW": 0.001
},
"WakuV2Config": {

View File

@ -57,3 +57,6 @@ proc signMessage*(rpcParams: string): string =
proc signTypedData*(data: string, address: string, password: string): string =
return $status_go.signTypedData(data, address, password)
proc getBloomFilter*(): string =
return $callPrivateRPC("bloomFilter".prefix, %* []).parseJSON()["result"].getStr

View File

@ -192,6 +192,7 @@ proc setBloomLevel*(bloomFilterMode: bool, fullNode: bool): StatusGoError =
var nodeConfig = getNodeConfig()
nodeConfig["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
nodeConfig["WakuConfig"]["FullNode"] = newJBool(fullNode)
nodeConfig["WakuConfig"]["LightClient"] = newJBool(not fullNode)
return saveSetting(Setting.NodeConfig, nodeConfig)
proc setFleet*(fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =

View File

@ -5,6 +5,7 @@ import types as libstatus_types
import chat, accounts, wallet, node, network, messages, contacts, profile, stickers, permissions, fleet, settings, mailservers, browser, tokens, provider
import ../eventemitter
import ./tasks/task_runner_impl
import bitops, stew/byteutils, chronicles
export chat, accounts, node, messages, contacts, profile, network, permissions, fleet, task_runner_impl, eventemitter
@ -75,3 +76,13 @@ proc getNodeVersion*(self: Status): string =
# TODO: duplicated??
proc saveSetting*(self: Status, setting: Setting, value: string | bool) =
discard libstatus_settings.saveSetting(setting, value)
proc getBloomFilter*(self: Status): string =
result = libstatus_core.getBloomFilter()
proc getBloomFilterBitsSet*(self: Status): int =
let bloomFilter = libstatus_core.getBloomFilter()
var bitCount = 0;
for b in hexToSeqByte(bloomFilter):
bitCount += countSetBits(b)
return bitCount

View File

@ -45,6 +45,30 @@ Item {
}
}
RowLayout {
id: bloomF
Layout.fillWidth: true
StyledText {
color: Style.current.lightBlueText
text: "Bloom Filter Usage"
Layout.rightMargin: Style.current.padding
Layout.leftMargin: Style.current.padding
Layout.fillWidth: true
font.weight: Font.Medium
font.pixelSize: 20
}
StyledText {
id: bloomPerc
color: Style.current.lightBlueText
text: ((nodeModel.bloomBits / 512) * 100).toFixed(2) + "%"
Layout.rightMargin: Style.current.padding
Layout.leftMargin: Style.current.padding
Layout.fillWidth: true
font.weight: Font.Medium
font.pixelSize: 20
}
}
ColumnLayout {
id: messageContainer
Layout.fillHeight: true