Merge pull request #699 from Atheros1/master

bytes received/sent resolve merge conflict
This commit is contained in:
Jonathan Warren 2014-08-01 17:27:52 -04:00
commit b58d749723
6 changed files with 88 additions and 16 deletions

View File

@ -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

View File

@ -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", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Sans\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<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>", None))
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
"<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>", 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))

View File

@ -278,8 +278,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-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';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@ -1035,7 +1035,7 @@ p, li { white-space: pre-wrap; }
<property name="geometry">
<rect>
<x>320</x>
<y>210</y>
<y>250</y>
<width>291</width>
<height>16</height>
</rect>
@ -1044,6 +1044,32 @@ p, li { white-space: pre-wrap; }
<string>Inventory lookups per second: 0</string>
</property>
</widget>
<widget class="QLabel" name="labelBytesRecvCount">
<property name="geometry">
<rect>
<x>350</x>
<y>210</y>
<width>251</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Down: 0 KB/s</string>
</property>
</widget>
<widget class="QLabel" name="labelBytesSentCount">
<property name="geometry">
<rect>
<x>350</x>
<y>230</y>
<width>251</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Up: 0 KB/s</string>
</property>
</widget>
</widget>
</widget>
</item>
@ -1055,7 +1081,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>885</width>
<height>27</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View File

@ -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)) + ')'

View File

@ -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.'

View File

@ -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.