Network status updates

- now lists each node with its info instead of a per-stream summary
This commit is contained in:
Peter Šurda 2017-06-24 12:16:12 +02:00
parent bfbdd7e140
commit 26eb54a82e
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 56 additions and 48 deletions

View File

@ -16,6 +16,8 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
super(NetworkStatus, self).__init__(parent) super(NetworkStatus, self).__init__(parent)
widgets.load('networkstatus.ui', self) widgets.load('networkstatus.ui', self)
self.tableWidgetConnectionCount.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
self.startup = time.localtime() self.startup = time.localtime()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg( self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup))) l10n.formatTimestamp(self.startup)))
@ -74,51 +76,41 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"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):
totalNumberOfConnectionsFromAllStreams = 0 # One would think we could use len(sendDataQueues) for this but the number doesn't always match: just because we have a sendDataThread running doesn't mean that the connection has been fully established (with the exchange of version messages).
streamNumberTotals = {}
connectedHosts = network.stats.connectedHostsList() connectedHosts = network.stats.connectedHostsList()
for host, streamNumber in connectedHosts:
if not streamNumber in streamNumberTotals:
streamNumberTotals[streamNumber] = 1
else:
streamNumberTotals[streamNumber] += 1
while self.tableWidgetConnectionCount.rowCount() > 0: self.tableWidgetConnectionCount.setUpdatesEnabled(False)
self.tableWidgetConnectionCount.removeRow(0) #self.tableWidgetConnectionCount.setSortingEnabled(False)
for streamNumber, connectionCount in streamNumberTotals.items(): #self.tableWidgetConnectionCount.clearContents()
self.tableWidgetConnectionCount.setRowCount(0)
for i in connectedHosts:
self.tableWidgetConnectionCount.insertRow(0) self.tableWidgetConnectionCount.insertRow(0)
if streamNumber == 0: self.tableWidgetConnectionCount.setItem(0, 0,
newItem = QtGui.QTableWidgetItem("?") QtGui.QTableWidgetItem("%s:%i" % (i.destination.host, i.destination.port))
)
self.tableWidgetConnectionCount.setItem(0, 1,
QtGui.QTableWidgetItem("%s" % (i.userAgent))
)
self.tableWidgetConnectionCount.setItem(0, 2,
QtGui.QTableWidgetItem("%s" % (i.tlsVersion))
)
self.tableWidgetConnectionCount.setItem(0, 3,
QtGui.QTableWidgetItem("%s" % (",".join(map(str,i.streams))))
)
if i.isOutbound:
brush = QtGui.QBrush(QtGui.QColor("yellow"), QtCore.Qt.SolidPattern)
else: else:
newItem = QtGui.QTableWidgetItem(str(streamNumber)) brush = QtGui.QBrush(QtGui.QColor("green"), QtCore.Qt.SolidPattern)
newItem.setFlags( for j in (range(1)):
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.tableWidgetConnectionCount.item(0, j).setBackground(brush)
self.tableWidgetConnectionCount.setItem(0, 0, newItem) self.tableWidgetConnectionCount.setUpdatesEnabled(True)
newItem = QtGui.QTableWidgetItem(str(connectionCount)) #self.tableWidgetConnectionCount.setSortingEnabled(True)
newItem.setFlags( #self.tableWidgetConnectionCount.horizontalHeader().setSortIndicator(1, QtCore.Qt.AscendingOrder)
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.tableWidgetConnectionCount.setItem(0, 1, newItem)
"""for currentRow in range(self.tableWidgetConnectionCount.rowCount()):
rowStreamNumber = int(self.tableWidgetConnectionCount.item(currentRow,0).text())
if streamNumber == rowStreamNumber:
foundTheRowThatNeedsUpdating = True
self.tableWidgetConnectionCount.item(currentRow,1).setText(str(connectionCount))
#totalNumberOfConnectionsFromAllStreams += connectionCount
if foundTheRowThatNeedsUpdating == False:
#Add a line to the table for this stream number and update its count with the current connection count.
self.tableWidgetConnectionCount.insertRow(0)
newItem = QtGui.QTableWidgetItem(str(streamNumber))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.tableWidgetConnectionCount.setItem(0,0,newItem)
newItem = QtGui.QTableWidgetItem(str(connectionCount))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.tableWidgetConnectionCount.setItem(0,1,newItem)
totalNumberOfConnectionsFromAllStreams += connectionCount"""
self.labelTotalConnections.setText(_translate( self.labelTotalConnections.setText(_translate(
"networkstatus", "Total Connections: %1").arg(str(len(connectedHosts)))) "networkstatus", "Total Connections: %1").arg(str(len(connectedHosts))))
if len(connectedHosts) > 0 and shared.statusIconColor == 'red': # 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':
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
elif len(connectedHosts) == 0: elif not connectedHosts and shared.statusIconColor != "red":
self.window().setStatusIcon('red') self.window().setStatusIcon('red')
# timer driven # timer driven
@ -133,6 +125,6 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.updateNumberOfPubkeysProcessed() self.updateNumberOfPubkeysProcessed()
def retranslateUi(self): def retranslateUi(self):
super(QtGui.QWidget, self).retranslateUi() super(NetworkStatus, self).retranslateUi()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg( self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup))) l10n.formatTimestamp(self.startup)))

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>602</width> <width>602</width>
<height>252</height> <height>254</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -18,12 +18,12 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1"> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0">
<property name="spacing"> <property name="spacing">
<number>20</number> <number>20</number>
</property> </property>
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetNoConstraint</enum>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
@ -31,7 +31,7 @@
<number>20</number> <number>20</number>
</property> </property>
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<item> <item>
<widget class="QLabel" name="labelTotalConnections"> <widget class="QLabel" name="labelTotalConnections">
@ -89,13 +89,16 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum> <enum>QAbstractItemView::NoSelection</enum>
</property> </property>
<attribute name="horizontalHeaderCascadingSectionResizes"> <attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool> <bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>80</number>
</attribute> </attribute>
<attribute name="horizontalHeaderHighlightSections"> <attribute name="horizontalHeaderHighlightSections">
<bool>false</bool> <bool>false</bool>
@ -108,12 +111,22 @@
</attribute> </attribute>
<column> <column>
<property name="text"> <property name="text">
<string>Stream #</string> <string>Peer</string>
</property> </property>
</column> </column>
<column> <column>
<property name="text"> <property name="text">
<string>Connections</string> <string>User agent</string>
</property>
</column>
<column>
<property name="text">
<string>TLS</string>
</property>
</column>
<column>
<property name="text">
<string>Stream #</string>
</property> </property>
</column> </column>
</widget> </widget>
@ -125,6 +138,9 @@
<property name="spacing"> <property name="spacing">
<number>4</number> <number>4</number>
</property> </property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item> <item>
<widget class="QLabel" name="labelStartupTime"> <widget class="QLabel" name="labelStartupTime">
<property name="sizePolicy"> <property name="sizePolicy">

View File

@ -21,7 +21,7 @@ def connectedHostsList():
if not i.fullyEstablished: if not i.fullyEstablished:
continue continue
try: try:
retval.append((i.destination, i.streams[0])) retval.append(i)
except AttributeError: except AttributeError:
pass pass
return retval return retval