diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index dd67d211..47870046 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -482,6 +482,10 @@ class MyForm(QtGui.QMainWindow): # startup for linux pass + + self.totalNumberOfBytesReceived = 0 + self.totalNumberOfBytesSent = 0 + self.ui.labelSendBroadcastWarning.setVisible(False) self.timer = QtCore.QTimer() @@ -1468,6 +1472,31 @@ class MyForm(QtGui.QMainWindow): self.ui.labelPubkeyCount.setText(_translate( "MainWindow", "Processed %1 public keys.").arg(str(shared.numberOfPubkeysProcessed))) + def formatBytes(self, num): + for x in ['bytes','KB','MB','GB']: + if num < 1000.0: + return "%3.0f %s" % (num, x) + num /= 1000.0 + return "%3.0f %s" % (num, 'TB') + + def formatByteRate(self, num): + num /= 1000 + return "%4.0f KB" % num + + def updateNumberOfBytes(self): + """ + This function is run every two seconds, so we divide the rate of bytes + sent and received by 2. + """ + self.ui.labelBytesRecvCount.setText(_translate( + "MainWindow", "Down: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesReceived/2), self.formatBytes(self.totalNumberOfBytesReceived))) + self.ui.labelBytesSentCount.setText(_translate( + "MainWindow", "Up: %1/s Total: %2").arg(self.formatByteRate(shared.numberOfBytesSent/2), self.formatBytes(self.totalNumberOfBytesSent))) + self.totalNumberOfBytesReceived += shared.numberOfBytesReceived + self.totalNumberOfBytesSent += shared.numberOfBytesSent + shared.numberOfBytesReceived = 0 + shared.numberOfBytesSent = 0 + def updateNetworkStatusTab(self): # print 'updating network status tab' 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). @@ -1521,6 +1550,7 @@ class MyForm(QtGui.QMainWindow): self.ui.labelLookupsPerSecond.setText(_translate( "MainWindow", "Inventory lookups per second: %1").arg(str(shared.numberOfInventoryLookupsPerformed/2))) shared.numberOfInventoryLookupsPerformed = 0 + self.updateNumberOfBytes() # Indicates whether or not there is a connection to the Bitmessage network connected = False diff --git a/src/bitmessageqt/bitmessageui.py b/src/bitmessageqt/bitmessageui.py index b80367dd..fb0056aa 100644 --- a/src/bitmessageqt/bitmessageui.py +++ b/src/bitmessageqt/bitmessageui.py @@ -2,8 +2,8 @@ # Form implementation generated from reading ui file 'bitmessageui.ui' # -# Created: Sat Nov 2 18:01:09 2013 -# by: PyQt4 UI code generator 4.10 +# Created: Fri Aug 01 15:30:14 2014 +# by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -431,15 +431,21 @@ class Ui_MainWindow(object): self.labelBroadcastCount.setGeometry(QtCore.QRect(350, 150, 351, 16)) self.labelBroadcastCount.setObjectName(_fromUtf8("labelBroadcastCount")) self.labelLookupsPerSecond = QtGui.QLabel(self.networkstatus) - self.labelLookupsPerSecond.setGeometry(QtCore.QRect(320, 210, 291, 16)) + self.labelLookupsPerSecond.setGeometry(QtCore.QRect(320, 250, 291, 16)) self.labelLookupsPerSecond.setObjectName(_fromUtf8("labelLookupsPerSecond")) + self.labelBytesRecvCount = QtGui.QLabel(self.networkstatus) + self.labelBytesRecvCount.setGeometry(QtCore.QRect(350, 210, 251, 16)) + self.labelBytesRecvCount.setObjectName(_fromUtf8("labelBytesRecvCount")) + self.labelBytesSentCount = QtGui.QLabel(self.networkstatus) + self.labelBytesSentCount.setGeometry(QtCore.QRect(350, 230, 251, 16)) + self.labelBytesSentCount.setObjectName(_fromUtf8("labelBytesSentCount")) icon9 = QtGui.QIcon() icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/networkstatus.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.tabWidget.addTab(self.networkstatus, icon9, _fromUtf8("")) self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) - self.menubar.setGeometry(QtCore.QRect(0, 0, 885, 27)) + self.menubar.setGeometry(QtCore.QRect(0, 0, 885, 21)) self.menubar.setObjectName(_fromUtf8("menubar")) self.menuFile = QtGui.QMenu(self.menubar) self.menuFile.setObjectName(_fromUtf8("menuFile")) @@ -557,8 +563,8 @@ class Ui_MainWindow(object): self.textEditMessage.setHtml(_translate("MainWindow", "\n" "\n" -"


", None)) +"\n" +"


", None)) self.label.setText(_translate("MainWindow", "To:", None)) self.label_2.setText(_translate("MainWindow", "From:", None)) self.radioButtonBroadcast.setText(_translate("MainWindow", "Broadcast to everyone who is subscribed to your address", None)) @@ -625,6 +631,8 @@ class Ui_MainWindow(object): self.labelPubkeyCount.setText(_translate("MainWindow", "Processed 0 public key.", None)) self.labelBroadcastCount.setText(_translate("MainWindow", "Processed 0 broadcast.", None)) self.labelLookupsPerSecond.setText(_translate("MainWindow", "Inventory lookups per second: 0", None)) + self.labelBytesRecvCount.setText(_translate("MainWindow", "Down: 0 KB/s", None)) + self.labelBytesSentCount.setText(_translate("MainWindow", "Up: 0 KB/s", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.networkstatus), _translate("MainWindow", "Network Status", None)) self.menuFile.setTitle(_translate("MainWindow", "File", None)) self.menuSettings.setTitle(_translate("MainWindow", "Settings", None)) diff --git a/src/bitmessageqt/bitmessageui.ui b/src/bitmessageqt/bitmessageui.ui index e5148ec1..cdc8fdf9 100644 --- a/src/bitmessageqt/bitmessageui.ui +++ b/src/bitmessageqt/bitmessageui.ui @@ -278,8 +278,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2';"><br /></p></body></html> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> @@ -1035,7 +1035,7 @@ p, li { white-space: pre-wrap; } 320 - 210 + 250 291 16 @@ -1044,6 +1044,32 @@ p, li { white-space: pre-wrap; } Inventory lookups per second: 0 + + + + 350 + 210 + 251 + 16 + + + + Down: 0 KB/s + + + + + + 350 + 230 + 251 + 16 + + + + Up: 0 KB/s + + @@ -1055,7 +1081,7 @@ p, li { white-space: pre-wrap; } 0 0 885 - 27 + 21 diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index b8b61bce..a97da9df 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -67,7 +67,9 @@ class receiveDataThread(threading.Thread): while True: dataLen = len(self.data) try: - self.data += self.sock.recv(4096) + dataRecv = self.sock.recv(4096) + self.data += dataRecv + shared.numberOfBytesReceived += len(dataRecv) except socket.timeout: with shared.printLock: print 'Timeout occurred waiting for data from', self.peer, '. Closing receiveData thread. (ID:', str(id(self)) + ')' diff --git a/src/class_sendDataThread.py b/src/class_sendDataThread.py index b8bb61e8..eec23e7b 100644 --- a/src/class_sendDataThread.py +++ b/src/class_sendDataThread.py @@ -56,7 +56,7 @@ class sendDataThread(threading.Thread): print 'Sending version packet: ', repr(datatosend) try: - self.sock.sendall(datatosend) + self.sendBytes(datatosend) except Exception as err: # if not 'Bad file descriptor' in err: with shared.printLock: @@ -64,6 +64,10 @@ class sendDataThread(threading.Thread): self.versionSent = 1 + def sendBytes(self, data): + self.sock.sendall(data) + shared.numberOfBytesSent += len(data) + def run(self): while True: deststream, command, data = self.sendDataThreadQueue.get() @@ -111,7 +115,7 @@ class sendDataThread(threading.Thread): payload = encodeVarint(numberOfAddressesInAddrMessage) + payload packet = shared.CreatePacket('addr', payload) try: - self.sock.sendall(packet) + self.sendBytes(packet) self.lastTimeISentData = int(time.time()) except: print 'sendaddr: self.sock.sendall failed' @@ -130,7 +134,7 @@ class sendDataThread(threading.Thread): payload = encodeVarint(len(payload)/32) + payload packet = shared.CreatePacket('inv', payload) try: - self.sock.sendall(packet) + self.sendBytes(packet) self.lastTimeISentData = int(time.time()) except: print 'sendinv: self.sock.sendall failed' @@ -143,14 +147,14 @@ class sendDataThread(threading.Thread): print 'Sending pong to', self.peer, 'to keep connection alive.' packet = shared.CreatePacket('pong') try: - self.sock.sendall(packet) + self.sendBytes(packet) self.lastTimeISentData = int(time.time()) except: print 'send pong failed' break elif command == 'sendRawData': try: - self.sock.sendall(data) + self.sendBytes(data) self.lastTimeISentData = int(time.time()) except: print 'Sending of data to', self.peer, 'failed. sendDataThread thread', self, 'ending now.' diff --git a/src/shared.py b/src/shared.py index d4df5da1..3f60a852 100644 --- a/src/shared.py +++ b/src/shared.py @@ -71,6 +71,8 @@ numberOfMessagesProcessed = 0 numberOfBroadcastsProcessed = 0 numberOfPubkeysProcessed = 0 numberOfInventoryLookupsPerformed = 0 +numberOfBytesReceived = 0 +numberOfBytesSent = 0 daemon = False inventorySets = {} # key = streamNumer, value = a set which holds the inventory object hashes that we are aware of. This is used whenever we receive an inv message from a peer to check to see what items are new to us. We don't delete things out of it; instead, the singleCleaner thread clears and refills it every couple hours. needToWriteKnownNodesToDisk = False # If True, the singleCleaner will write it to disk eventually.