2017-05-29 00:24:07 +02:00
|
|
|
import time
|
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
import asyncore_pollchoose as asyncore
|
2018-12-10 13:33:07 +01:00
|
|
|
from network.connectionpool import BMConnectionPool
|
|
|
|
from objectracker import missingObjects
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
lastReceivedTimestamp = time.time()
|
|
|
|
lastReceivedBytes = 0
|
|
|
|
currentReceivedSpeed = 0
|
|
|
|
lastSentTimestamp = time.time()
|
|
|
|
lastSentBytes = 0
|
|
|
|
currentSentSpeed = 0
|
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def connectedHostsList():
|
2017-08-09 17:36:52 +02:00
|
|
|
retval = []
|
2017-08-22 13:49:27 +02:00
|
|
|
for i in BMConnectionPool().inboundConnections.values() + \
|
|
|
|
BMConnectionPool().outboundConnections.values():
|
2017-08-09 17:36:52 +02:00
|
|
|
if not i.fullyEstablished:
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
retval.append(i)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return retval
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def sentBytes():
|
2017-08-09 17:36:52 +02:00
|
|
|
return asyncore.sentBytes
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def uploadSpeed():
|
2017-05-29 00:24:07 +02:00
|
|
|
global lastSentTimestamp, lastSentBytes, currentSentSpeed
|
2017-08-09 17:36:52 +02:00
|
|
|
currentTimestamp = time.time()
|
|
|
|
if int(lastSentTimestamp) < int(currentTimestamp):
|
|
|
|
currentSentBytes = asyncore.sentBytes
|
|
|
|
currentSentSpeed = int((currentSentBytes - lastSentBytes) / (currentTimestamp - lastSentTimestamp))
|
|
|
|
lastSentBytes = currentSentBytes
|
|
|
|
lastSentTimestamp = currentTimestamp
|
|
|
|
return currentSentSpeed
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def receivedBytes():
|
2017-08-09 17:36:52 +02:00
|
|
|
return asyncore.receivedBytes
|
2017-05-25 14:59:18 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-25 14:59:18 +02:00
|
|
|
def downloadSpeed():
|
2017-05-29 00:24:07 +02:00
|
|
|
global lastReceivedTimestamp, lastReceivedBytes, currentReceivedSpeed
|
2017-08-09 17:36:52 +02:00
|
|
|
currentTimestamp = time.time()
|
|
|
|
if int(lastReceivedTimestamp) < int(currentTimestamp):
|
|
|
|
currentReceivedBytes = asyncore.receivedBytes
|
2019-09-10 16:14:44 +02:00
|
|
|
currentReceivedSpeed = int(
|
|
|
|
(currentReceivedBytes - lastReceivedBytes) / (currentTimestamp - lastReceivedTimestamp))
|
2017-08-09 17:36:52 +02:00
|
|
|
lastReceivedBytes = currentReceivedBytes
|
|
|
|
lastReceivedTimestamp = currentTimestamp
|
|
|
|
return currentReceivedSpeed
|
2017-05-29 00:24:07 +02:00
|
|
|
|
2019-09-10 16:14:44 +02:00
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
def pendingDownload():
|
2017-10-20 23:11:33 +02:00
|
|
|
return len(missingObjects)
|
2019-09-10 16:14:44 +02:00
|
|
|
# tmp = {}
|
|
|
|
# for connection in BMConnectionPool().inboundConnections.values() + \
|
|
|
|
# BMConnectionPool().outboundConnections.values():
|
|
|
|
# for k in connection.objectsNewToMe.keys():
|
|
|
|
# tmp[k] = True
|
|
|
|
# return len(tmp)
|
|
|
|
|
2017-05-29 00:24:07 +02:00
|
|
|
|
|
|
|
def pendingUpload():
|
2019-09-10 16:14:44 +02:00
|
|
|
# tmp = {}
|
|
|
|
# for connection in BMConnectionPool().inboundConnections.values() + \
|
|
|
|
# BMConnectionPool().outboundConnections.values():
|
|
|
|
# for k in connection.objectsNewToThem.keys():
|
|
|
|
# tmp[k] = True
|
|
|
|
# This probably isn't the correct logic so it's disabled
|
|
|
|
# return len(tmp)
|
2017-08-22 13:49:27 +02:00
|
|
|
return 0
|