Network tab updates

- handle add/remove entry instead of recreating the whole connection
list
- update processed object counts after each object
This commit is contained in:
Peter Šurda 2017-10-19 08:39:09 +02:00
parent 1ba1f02686
commit a013814c6b
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
4 changed files with 54 additions and 33 deletions

View File

@ -11,6 +11,7 @@ from retranslateui import RetranslateMixin
from uisignaler import UISignaler from uisignaler import UISignaler
import widgets import widgets
from network.connectionpool import BMConnectionPool
class NetworkStatus(QtGui.QWidget, RetranslateMixin): class NetworkStatus(QtGui.QWidget, RetranslateMixin):
def __init__(self, parent=None): def __init__(self, parent=None):
@ -31,7 +32,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed) "updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateNetworkStatusTab()"), self.updateNetworkStatusTab) "updateNetworkStatusTab(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.updateNetworkStatusTab)
self.timer = QtCore.QTimer() self.timer = QtCore.QTimer()
self.timer.start(2000) # milliseconds self.timer.start(2000) # milliseconds
@ -52,17 +53,17 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.labelSyncStatus.setText(_translate("networkstatus", "Object(s) to be synced: %n", None, QtCore.QCoreApplication.CodecForTr, network.stats.pendingDownload() + network.stats.pendingUpload())) self.labelSyncStatus.setText(_translate("networkstatus", "Object(s) to be synced: %n", None, QtCore.QCoreApplication.CodecForTr, network.stats.pendingDownload() + network.stats.pendingUpload()))
def updateNumberOfMessagesProcessed(self): def updateNumberOfMessagesProcessed(self):
# self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
self.labelMessageCount.setText(_translate( self.labelMessageCount.setText(_translate(
"networkstatus", "Processed %n person-to-person message(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfMessagesProcessed)) "networkstatus", "Processed %n person-to-person message(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfMessagesProcessed))
def updateNumberOfBroadcastsProcessed(self): def updateNumberOfBroadcastsProcessed(self):
# self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
self.labelBroadcastCount.setText(_translate( self.labelBroadcastCount.setText(_translate(
"networkstatus", "Processed %n broadcast message(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfBroadcastsProcessed)) "networkstatus", "Processed %n broadcast message(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfBroadcastsProcessed))
def updateNumberOfPubkeysProcessed(self): def updateNumberOfPubkeysProcessed(self):
# self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
self.labelPubkeyCount.setText(_translate( self.labelPubkeyCount.setText(_translate(
"networkstatus", "Processed %n public key(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfPubkeysProcessed)) "networkstatus", "Processed %n public key(s).", None, QtCore.QCoreApplication.CodecForTr, shared.numberOfPubkeysProcessed))
@ -76,50 +77,71 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.labelBytesSentCount.setText(_translate( self.labelBytesSentCount.setText(_translate(
"networkstatus", "Up: %1/s Total: %2").arg(self.formatByteRate(network.stats.uploadSpeed()), self.formatBytes(network.stats.sentBytes()))) "networkstatus", "Up: %1/s Total: %2").arg(self.formatByteRate(network.stats.uploadSpeed()), self.formatBytes(network.stats.sentBytes())))
def updateNetworkStatusTab(self): def updateNetworkStatusTab(self, outbound, add, destination):
connectedHosts = network.stats.connectedHostsList() if outbound:
try:
c = BMConnectionPool().outboundConnections[destination]
except KeyError:
if add:
return
else:
try:
c = BMConnectionPool().inboundConnections[destination]
except KeyError:
try:
c = BMConnectionPool().inboundConnections[destination.host]
except KeyError:
if add:
return
self.tableWidgetConnectionCount.setUpdatesEnabled(False) self.tableWidgetConnectionCount.setUpdatesEnabled(False)
#self.tableWidgetConnectionCount.setSortingEnabled(False) self.tableWidgetConnectionCount.setSortingEnabled(False)
#self.tableWidgetConnectionCount.clearContents() if add:
self.tableWidgetConnectionCount.setRowCount(0)
for i in connectedHosts:
self.tableWidgetConnectionCount.insertRow(0) self.tableWidgetConnectionCount.insertRow(0)
self.tableWidgetConnectionCount.setItem(0, 0, self.tableWidgetConnectionCount.setItem(0, 0,
QtGui.QTableWidgetItem("%s:%i" % (i.destination.host, i.destination.port)) QtGui.QTableWidgetItem("%s:%i" % (destination.host, destination.port))
) )
self.tableWidgetConnectionCount.setItem(0, 2, self.tableWidgetConnectionCount.setItem(0, 2,
QtGui.QTableWidgetItem("%s" % (i.userAgent)) QtGui.QTableWidgetItem("%s" % (c.userAgent))
) )
self.tableWidgetConnectionCount.setItem(0, 3, self.tableWidgetConnectionCount.setItem(0, 3,
QtGui.QTableWidgetItem("%s" % (i.tlsVersion)) QtGui.QTableWidgetItem("%s" % (c.tlsVersion))
) )
self.tableWidgetConnectionCount.setItem(0, 4, self.tableWidgetConnectionCount.setItem(0, 4,
QtGui.QTableWidgetItem("%s" % (",".join(map(str,i.streams)))) QtGui.QTableWidgetItem("%s" % (",".join(map(str,c.streams))))
) )
try: try:
# FIXME hard coded stream no # FIXME hard coded stream no
rating = knownnodes.knownNodes[1][i.destination]['rating'] rating = "%.1f" % (knownnodes.knownNodes[1][destination]['rating'])
except KeyError: except KeyError:
rating = "-" rating = "-"
self.tableWidgetConnectionCount.setItem(0, 1, self.tableWidgetConnectionCount.setItem(0, 1,
QtGui.QTableWidgetItem("%s" % (rating)) QtGui.QTableWidgetItem("%s" % (rating))
) )
if i.isOutbound: if outbound:
brush = QtGui.QBrush(QtGui.QColor("yellow"), QtCore.Qt.SolidPattern) brush = QtGui.QBrush(QtGui.QColor("yellow"), QtCore.Qt.SolidPattern)
else: else:
brush = QtGui.QBrush(QtGui.QColor("green"), QtCore.Qt.SolidPattern) brush = QtGui.QBrush(QtGui.QColor("green"), QtCore.Qt.SolidPattern)
for j in (range(1)): for j in (range(1)):
self.tableWidgetConnectionCount.item(0, j).setBackground(brush) self.tableWidgetConnectionCount.item(0, j).setBackground(brush)
self.tableWidgetConnectionCount.item(0, 0).setData(QtCore.Qt.UserRole, destination)
self.tableWidgetConnectionCount.item(0, 1).setData(QtCore.Qt.UserRole, outbound)
else:
for i in range(self.tableWidgetConnectionCount.rowCount()):
if self.tableWidgetConnectionCount.item(i, 0).data(QtCore.Qt.UserRole).toPyObject() != destination:
continue
if self.tableWidgetConnectionCount.item(i, 1).data(QtCore.Qt.UserRole).toPyObject() == outbound:
self.tableWidgetConnectionCount.removeRow(i)
break
self.tableWidgetConnectionCount.setUpdatesEnabled(True) self.tableWidgetConnectionCount.setUpdatesEnabled(True)
#self.tableWidgetConnectionCount.setSortingEnabled(True) self.tableWidgetConnectionCount.setSortingEnabled(True)
#self.tableWidgetConnectionCount.horizontalHeader().setSortIndicator(1, QtCore.Qt.AscendingOrder) self.tableWidgetConnectionCount.horizontalHeader().setSortIndicator(0, QtCore.Qt.AscendingOrder)
self.labelTotalConnections.setText(_translate( self.labelTotalConnections.setText(_translate(
"networkstatus", "Total Connections: %1").arg(str(len(connectedHosts)))) "networkstatus", "Total Connections: %1").arg(str(self.tableWidgetConnectionCount.rowCount())))
# FYI: The 'singlelistener' thread sets the icon color to green when it receives an incoming connection, meaning that the user's firewall is configured correctly. # FYI: The 'singlelistener' thread sets the icon color to green when it receives an incoming connection, meaning that the user's firewall is configured correctly.
if connectedHosts and shared.statusIconColor == 'red': if self.tableWidgetConnectionCount.rowCount() and shared.statusIconColor == 'red':
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
elif not connectedHosts and shared.statusIconColor != "red": elif self.tableWidgetConnectionCount.rowCount() == 0 and shared.statusIconColor != "red":
self.window().setStatusIcon('red') self.window().setStatusIcon('red')
# timer driven # timer driven
@ -129,9 +151,6 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
Inventory().numberOfInventoryLookupsPerformed = 0 Inventory().numberOfInventoryLookupsPerformed = 0
self.updateNumberOfBytes() self.updateNumberOfBytes()
self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
self.updateNumberOfMessagesProcessed()
self.updateNumberOfBroadcastsProcessed()
self.updateNumberOfPubkeysProcessed()
def retranslateUi(self): def retranslateUi(self):
super(NetworkStatus, self).retranslateUi() super(NetworkStatus, self).retranslateUi()

View File

@ -45,7 +45,8 @@ class UISignaler(QThread):
"displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), "displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"),
toAddress, fromLabel, fromAddress, subject, message, ackdata) toAddress, fromLabel, fromAddress, subject, message, ackdata)
elif command == 'updateNetworkStatusTab': elif command == 'updateNetworkStatusTab':
self.emit(SIGNAL("updateNetworkStatusTab()")) outbound, add, destination = data
self.emit(SIGNAL("updateNetworkStatusTab(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), outbound, add, destination)
elif command == 'updateNumberOfMessagesProcessed': elif command == 'updateNumberOfMessagesProcessed':
self.emit(SIGNAL("updateNumberOfMessagesProcessed()")) self.emit(SIGNAL("updateNumberOfMessagesProcessed()"))
elif command == 'updateNumberOfPubkeysProcessed': elif command == 'updateNumberOfPubkeysProcessed':

View File

@ -194,8 +194,8 @@ class objectProcessor(threading.Thread):
def processpubkey(self, data): def processpubkey(self, data):
pubkeyProcessingStartTime = time.time() pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1 shared.numberOfPubkeysProcessed += 1
# queues.UISignalQueue.put(( queues.UISignalQueue.put((
# 'updateNumberOfPubkeysProcessed', 'no data')) 'updateNumberOfPubkeysProcessed', 'no data'))
embeddedTime, = unpack('>Q', data[8:16]) embeddedTime, = unpack('>Q', data[8:16])
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
addressVersion, varintLength = decodeVarint( addressVersion, varintLength = decodeVarint(
@ -343,8 +343,8 @@ class objectProcessor(threading.Thread):
def processmsg(self, data): def processmsg(self, data):
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1 shared.numberOfMessagesProcessed += 1
# queues.UISignalQueue.put(( queues.UISignalQueue.put((
# 'updateNumberOfMessagesProcessed', 'no data')) 'updateNumberOfMessagesProcessed', 'no data'))
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
msgVersion, msgVersionLength = decodeVarint(data[readPosition:readPosition + 9]) msgVersion, msgVersionLength = decodeVarint(data[readPosition:readPosition + 9])
if msgVersion != 1: if msgVersion != 1:
@ -613,8 +613,8 @@ class objectProcessor(threading.Thread):
def processbroadcast(self, data): def processbroadcast(self, data):
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1 shared.numberOfBroadcastsProcessed += 1
# queues.UISignalQueue.put(( queues.UISignalQueue.put((
# 'updateNumberOfBroadcastsProcessed', 'no data')) 'updateNumberOfBroadcastsProcessed', 'no data'))
inventoryHash = calculateInventoryHash(data) inventoryHash = calculateInventoryHash(data)
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
broadcastVersion, broadcastVersionLength = decodeVarint( broadcastVersion, broadcastVersionLength = decodeVarint(

View File

@ -72,7 +72,6 @@ class TCPConnection(BMProto, TLSDispatcher):
self.local = False self.local = False
#shared.connectedHostsList[self.destination] = 0 #shared.connectedHostsList[self.destination] = 0
ObjectTracker.__init__(self) ObjectTracker.__init__(self)
UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
self.bm_proto_reset() self.bm_proto_reset()
self.set_state("bm_header", expectBytes=protocol.Header.size) self.set_state("bm_header", expectBytes=protocol.Header.size)
@ -102,7 +101,7 @@ class TCPConnection(BMProto, TLSDispatcher):
if not self.isOutbound and not self.local: if not self.isOutbound and not self.local:
shared.clientHasReceivedIncomingConnections = True shared.clientHasReceivedIncomingConnections = True
UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('setStatusIcon', 'green'))
UISignalQueue.put(('updateNetworkStatusTab', 'no data')) UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, True, self.destination)))
self.antiIntersectionDelay(True) self.antiIntersectionDelay(True)
self.fullyEstablished = True self.fullyEstablished = True
if self.isOutbound: if self.isOutbound:
@ -218,6 +217,8 @@ class TCPConnection(BMProto, TLSDispatcher):
if self.isOutbound and not self.fullyEstablished: if self.isOutbound and not self.fullyEstablished:
knownnodes.decreaseRating(self.destination) knownnodes.decreaseRating(self.destination)
BMProto.handle_close(self, reason) BMProto.handle_close(self, reason)
if self.fullyEstablished:
UISignalQueue.put(('updateNetworkStatusTab', (self.isOutbound, False, self.destination)))
class Socks5BMConnection(Socks5Connection, TCPConnection): class Socks5BMConnection(Socks5Connection, TCPConnection):