Skip to content

Commit

Permalink
Network status updates
Browse files Browse the repository at this point in the history
- now lists each node with its info instead of a per-stream summary
  • Loading branch information
PeterSurda committed Jun 24, 2017
1 parent bfbdd7e commit 26eb54a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
70 changes: 31 additions & 39 deletions src/bitmessageqt/networkstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __init__(self, parent=None):
super(NetworkStatus, self).__init__(parent)
widgets.load('networkstatus.ui', self)

self.tableWidgetConnectionCount.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)

self.startup = time.localtime()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup)))
Expand Down Expand Up @@ -74,51 +76,41 @@ def updateNumberOfBytes(self):
"networkstatus", "Up: %1/s Total: %2").arg(self.formatByteRate(network.stats.uploadSpeed()), self.formatBytes(network.stats.sentBytes())))

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()
for host, streamNumber in connectedHosts:
if not streamNumber in streamNumberTotals:
streamNumberTotals[streamNumber] = 1
else:
streamNumberTotals[streamNumber] += 1

while self.tableWidgetConnectionCount.rowCount() > 0:
self.tableWidgetConnectionCount.removeRow(0)
for streamNumber, connectionCount in streamNumberTotals.items():
self.tableWidgetConnectionCount.setUpdatesEnabled(False)
#self.tableWidgetConnectionCount.setSortingEnabled(False)
#self.tableWidgetConnectionCount.clearContents()
self.tableWidgetConnectionCount.setRowCount(0)
for i in connectedHosts:
self.tableWidgetConnectionCount.insertRow(0)
if streamNumber == 0:
newItem = QtGui.QTableWidgetItem("?")
self.tableWidgetConnectionCount.setItem(0, 0,
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:
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)
"""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"""
brush = QtGui.QBrush(QtGui.QColor("green"), QtCore.Qt.SolidPattern)
for j in (range(1)):
self.tableWidgetConnectionCount.item(0, j).setBackground(brush)
self.tableWidgetConnectionCount.setUpdatesEnabled(True)
#self.tableWidgetConnectionCount.setSortingEnabled(True)
#self.tableWidgetConnectionCount.horizontalHeader().setSortIndicator(1, QtCore.Qt.AscendingOrder)
self.labelTotalConnections.setText(_translate(
"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')
elif len(connectedHosts) == 0:
elif not connectedHosts and shared.statusIconColor != "red":
self.window().setStatusIcon('red')

# timer driven
Expand All @@ -133,6 +125,6 @@ def runEveryTwoSeconds(self):
self.updateNumberOfPubkeysProcessed()

def retranslateUi(self):
super(QtGui.QWidget, self).retranslateUi()
super(NetworkStatus, self).retranslateUi()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup)))
32 changes: 24 additions & 8 deletions src/bitmessageqt/networkstatus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>602</width>
<height>252</height>
<height>254</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -18,20 +18,20 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0">
<property name="spacing">
<number>20</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>20</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QLabel" name="labelTotalConnections">
Expand Down Expand Up @@ -89,13 +89,16 @@
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>80</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
Expand All @@ -108,12 +111,22 @@
</attribute>
<column>
<property name="text">
<string>Stream #</string>
<string>Peer</string>
</property>
</column>
<column>
<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>
</column>
</widget>
Expand All @@ -125,6 +138,9 @@
<property name="spacing">
<number>4</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<widget class="QLabel" name="labelStartupTime">
<property name="sizePolicy">
Expand Down
2 changes: 1 addition & 1 deletion src/network/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def connectedHostsList():
if not i.fullyEstablished:
continue
try:
retval.append((i.destination, i.streams[0]))
retval.append(i)
except AttributeError:
pass
return retval
Expand Down

0 comments on commit 26eb54a

Please sign in to comment.