replace print statements with logger #1688
|
@ -3,11 +3,11 @@ Announce addresses as they are received from other hosts
|
||||||
"""
|
"""
|
||||||
import Queue
|
import Queue
|
||||||
|
|
||||||
import state
|
from assemble import assemble_addr
|
||||||
from helper_random import randomshuffle
|
from connectionpool import BMConnectionPool
|
||||||
from network.assemble import assemble_addr
|
from pybitmessage import state
|
||||||
from network.connectionpool import BMConnectionPool
|
from pybitmessage.helper_random import randomshuffle
|
||||||
from queues import addrQueue
|
from pybitmessage.queues import addrQueue
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import network.asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
import state
|
from pybitmessage import state
|
||||||
from threads import BusyError, nonBlocking
|
from threads import BusyError, nonBlocking
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@ Announce myself (node address)
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import state
|
from assemble import assemble_addr
|
||||||
from bmconfigparser import BMConfigParser
|
from connectionpool import BMConnectionPool
|
||||||
from network.assemble import assemble_addr
|
|
||||||
from network.connectionpool import BMConnectionPool
|
|
||||||
from network.udp import UDPSocket
|
|
||||||
from node import Peer
|
from node import Peer
|
||||||
|
from pybitmessage import state
|
||||||
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
from udp import UDPSocket
|
||||||
|
|
||||||
|
|
||||||
class AnnounceThread(StoppableThread):
|
class AnnounceThread(StoppableThread):
|
||||||
|
|
|
@ -3,10 +3,10 @@ Create bitmessage protocol command packets
|
||||||
"""
|
"""
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
import addresses
|
from pybitmessage import addresses
|
||||||
from network.constants import MAX_ADDR_COUNT
|
from constants import MAX_ADDR_COUNT
|
||||||
from network.node import Peer
|
from node import Peer
|
||||||
from protocol import CreatePacket, encodeHost
|
from pybitmessage.protocol import CreatePacket, encodeHost
|
||||||
|
|
||||||
|
|
||||||
def assemble_addr(peerList):
|
def assemble_addr(peerList):
|
||||||
|
|
|
@ -17,9 +17,9 @@ from errno import (
|
||||||
ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EINVAL, EISCONN, ENETUNREACH,
|
ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EINVAL, EISCONN, ENETUNREACH,
|
||||||
ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
|
ENOTCONN, ENOTSOCK, EPIPE, ESHUTDOWN, ETIMEDOUT, EWOULDBLOCK, errorcode
|
||||||
)
|
)
|
||||||
from threading import current_thread
|
from pybitmessage import helper_random
|
||||||
|
|
||||||
import helper_random
|
from threading import current_thread
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from errno import WSAEWOULDBLOCK
|
from errno import WSAEWOULDBLOCK
|
||||||
|
|
|
@ -4,11 +4,11 @@ BMObject and it's exceptions.
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import protocol
|
from dandelion import Dandelion
|
||||||
import state
|
from pybitmessage import protocol
|
||||||
from addresses import calculateInventoryHash
|
from pybitmessage import state
|
||||||
from inventory import Inventory
|
from pybitmessage.addresses import calculateInventoryHash
|
||||||
from network.dandelion import Dandelion
|
from pybitmessage.inventory import Inventory
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
|
@ -10,28 +10,28 @@ import struct
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
import addresses
|
|
||||||
import connectionpool
|
import connectionpool
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import protocol
|
from advanceddispatcher import AdvancedDispatcher
|
||||||
import state
|
from bmobject import (
|
||||||
from bmconfigparser import BMConfigParser
|
|
||||||
from inventory import Inventory
|
|
||||||
from network.advanceddispatcher import AdvancedDispatcher
|
|
||||||
from network.bmobject import (
|
|
||||||
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
|
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
|
||||||
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
|
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
|
||||||
BMObjectInvalidError, BMObjectUnwantedStreamError
|
BMObjectInvalidError, BMObjectUnwantedStreamError
|
||||||
)
|
)
|
||||||
from network.constants import (
|
from constants import (
|
||||||
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
|
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
|
||||||
MAX_OBJECT_PAYLOAD_SIZE, MAX_TIME_OFFSET
|
MAX_OBJECT_PAYLOAD_SIZE, MAX_TIME_OFFSET
|
||||||
)
|
)
|
||||||
from network.dandelion import Dandelion
|
from dandelion import Dandelion
|
||||||
from network.proxy import ProxyError
|
from proxy import ProxyError
|
||||||
from node import Node, Peer
|
from node import Node, Peer
|
||||||
from objectracker import ObjectTracker, missingObjects
|
from objectracker import ObjectTracker, missingObjects
|
||||||
from queues import invQueue, objectProcessorQueue, portCheckerQueue
|
from pybitmessage import addresses
|
||||||
|
from pybitmessage import protocol
|
||||||
|
from pybitmessage import state
|
||||||
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
from pybitmessage.inventory import Inventory
|
||||||
|
from pybitmessage.queues import invQueue, objectProcessorQueue, portCheckerQueue
|
||||||
from randomtrackingdict import RandomTrackingDict
|
from randomtrackingdict import RandomTrackingDict
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
|
@ -6,10 +6,10 @@ import logging
|
||||||
import random # nosec
|
import random # nosec
|
||||||
|
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import protocol
|
from pybitmessage import protocol
|
||||||
import state
|
from pybitmessage import state
|
||||||
from bmconfigparser import BMConfigParser
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
from queues import Queue, portCheckerQueue
|
from pybitmessage.queues import Queue, portCheckerQueue
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,15 @@ import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
import helper_random
|
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import protocol
|
|
||||||
import state
|
|
||||||
from bmconfigparser import BMConfigParser
|
|
||||||
from connectionchooser import chooseConnection
|
from connectionchooser import chooseConnection
|
||||||
from node import Peer
|
from node import Peer
|
||||||
from proxy import Proxy
|
from proxy import Proxy
|
||||||
from singleton import Singleton
|
from pybitmessage import helper_random
|
||||||
|
from pybitmessage import protocol
|
||||||
|
from pybitmessage import state
|
||||||
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
from pybitmessage.singleton import Singleton
|
||||||
from tcp import (
|
from tcp import (
|
||||||
bootstrap, Socks4aBMConnection, Socks5BMConnection,
|
bootstrap, Socks4aBMConnection, Socks5BMConnection,
|
||||||
TCPConnection, TCPServer)
|
TCPConnection, TCPServer)
|
||||||
|
|
|
@ -8,9 +8,9 @@ from threading import RLock
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import connectionpool
|
import connectionpool
|
||||||
import state
|
from pybitmessage import state
|
||||||
from queues import invQueue
|
from pybitmessage.queues import invQueue
|
||||||
from singleton import Singleton
|
from pybitmessage.singleton import Singleton
|
||||||
|
|
||||||
# randomise routes after 600 seconds
|
# randomise routes after 600 seconds
|
||||||
REASSIGN_INTERVAL = 600
|
REASSIGN_INTERVAL = 600
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import addresses
|
|
||||||
import helper_random
|
|
||||||
import protocol
|
|
||||||
from dandelion import Dandelion
|
from dandelion import Dandelion
|
||||||
from inventory import Inventory
|
from connectionpool import BMConnectionPool
|
||||||
from network.connectionpool import BMConnectionPool
|
|
||||||
from objectracker import missingObjects
|
from objectracker import missingObjects
|
||||||
|
from pybitmessage import addresses
|
||||||
|
from pybitmessage import helper_random
|
||||||
|
from pybitmessage import protocol
|
||||||
|
from pybitmessage.inventory import Inventory
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ import Queue
|
||||||
import random
|
import random
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import addresses
|
from connectionpool import BMConnectionPool
|
||||||
import protocol
|
from dandelion import Dandelion
|
||||||
import state
|
from pybitmessage import addresses
|
||||||
from network.connectionpool import BMConnectionPool
|
from pybitmessage import protocol
|
||||||
from network.dandelion import Dandelion
|
from pybitmessage import state
|
||||||
from queues import invQueue
|
from pybitmessage.queues import invQueue
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from collections import Iterable
|
from collections import Iterable
|
||||||
|
|
||||||
import state
|
from node import Peer
|
||||||
from bmconfigparser import BMConfigParser
|
from pybitmessage import state
|
||||||
from network.node import Peer
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
state.Peer = Peer
|
state.Peer = Peer
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""
|
"""
|
||||||
A thread to handle network concerns
|
A thread to handle network concerns
|
||||||
"""
|
"""
|
||||||
import network.asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
import state
|
from connectionpool import BMConnectionPool
|
||||||
from network.connectionpool import BMConnectionPool
|
from pybitmessage import state
|
||||||
from queues import excQueue
|
from pybitmessage.queues import excQueue
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ Module for tracking objects
|
||||||
import time
|
import time
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
import network.connectionpool
|
import connectionpool
|
||||||
from network.dandelion import Dandelion
|
from dandelion import Dandelion
|
||||||
from randomtrackingdict import RandomTrackingDict
|
from randomtrackingdict import RandomTrackingDict
|
||||||
|
|
||||||
haveBloom = False
|
haveBloom = False
|
||||||
|
@ -100,7 +100,7 @@ class ObjectTracker(object):
|
||||||
|
|
||||||
def handleReceivedObject(self, streamNumber, hashid):
|
def handleReceivedObject(self, streamNumber, hashid):
|
||||||
"""Handling received object"""
|
"""Handling received object"""
|
||||||
for i in network.connectionpool.BMConnectionPool().connections():
|
for i in connectionpool.BMConnectionPool().connections():
|
||||||
if not i.fullyEstablished:
|
if not i.fullyEstablished:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import time
|
||||||
|
|
||||||
import asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
from advanceddispatcher import AdvancedDispatcher
|
from advanceddispatcher import AdvancedDispatcher
|
||||||
from bmconfigparser import BMConfigParser
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
from node import Peer
|
from node import Peer
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
"""
|
"""
|
||||||
Track randomize ordered dict
|
Track randomize ordered dict
|
||||||
"""
|
"""
|
||||||
import random
|
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
import helper_random
|
from pybitmessage import helper_random
|
||||||
|
|
||||||
|
|
||||||
class RandomTrackingDict(object):
|
class RandomTrackingDict(object):
|
||||||
|
@ -128,41 +127,3 @@ class RandomTrackingDict(object):
|
||||||
self.pendingLen += 1
|
self.pendingLen += 1
|
||||||
self.lastPoll = time()
|
self.lastPoll = time()
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
# pylint: disable=redefined-outer-name
|
|
||||||
def randString():
|
|
||||||
"""helper function for tests, generates a random string"""
|
|
||||||
retval = b''
|
|
||||||
for _ in range(32):
|
|
||||||
retval += chr(random.randint(0, 255))
|
|
||||||
return retval
|
|
||||||
|
|
||||||
a = []
|
|
||||||
k = RandomTrackingDict()
|
|
||||||
d = {}
|
|
||||||
|
|
||||||
print "populating random tracking dict"
|
|
||||||
a.append(time())
|
|
||||||
for i in range(50000):
|
|
||||||
k[randString()] = True
|
|
||||||
a.append(time())
|
|
||||||
print "done"
|
|
||||||
|
|
||||||
while k:
|
|
||||||
retval = k.randomKeys(1000)
|
|
||||||
if not retval:
|
|
||||||
print "error getting random keys"
|
|
||||||
try:
|
|
||||||
k.randomKeys(100)
|
|
||||||
print "bad"
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
for i in retval:
|
|
||||||
del k[i]
|
|
||||||
a.append(time())
|
|
||||||
|
|
||||||
for x in range(len(a) - 1):
|
|
||||||
print "%i: %.3f" % (x, a[x + 1] - a[x])
|
|
||||||
|
|
|
@ -5,10 +5,10 @@ import errno
|
||||||
import Queue
|
import Queue
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
import state
|
from advanceddispatcher import UnknownStateError
|
||||||
from network.advanceddispatcher import UnknownStateError
|
from connectionpool import BMConnectionPool
|
||||||
from network.connectionpool import BMConnectionPool
|
from pybitmessage import state
|
||||||
from queues import receiveDataQueue
|
from pybitmessage.queues import receiveDataQueue
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,35 +2,35 @@
|
||||||
TCP protocol handler
|
TCP protocol handler
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-ancestors
|
# pylint: disable=too-many-ancestors
|
||||||
import l10n
|
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import addresses
|
|
||||||
import asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
import connectionpool
|
import connectionpool
|
||||||
import helper_random
|
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import protocol
|
from advanceddispatcher import AdvancedDispatcher
|
||||||
import state
|
from assemble import assemble_addr
|
||||||
from bmconfigparser import BMConfigParser
|
from bmproto import BMProto
|
||||||
from helper_random import randomBytes
|
from constants import MAX_OBJECT_COUNT
|
||||||
from inventory import Inventory
|
from dandelion import Dandelion
|
||||||
from network.advanceddispatcher import AdvancedDispatcher
|
from objectracker import ObjectTracker
|
||||||
from network.assemble import assemble_addr
|
from socks4a import Socks4aConnection
|
||||||
from network.bmproto import BMProto
|
from socks5 import Socks5Connection
|
||||||
from network.constants import MAX_OBJECT_COUNT
|
from tls import TLSDispatcher
|
||||||
from network.dandelion import Dandelion
|
from pybitmessage import addresses
|
||||||
from network.objectracker import ObjectTracker
|
from pybitmessage import helper_random
|
||||||
from network.socks4a import Socks4aConnection
|
from pybitmessage import l10n
|
||||||
from network.socks5 import Socks5Connection
|
from pybitmessage import protocol
|
||||||
from network.tls import TLSDispatcher
|
from pybitmessage import state
|
||||||
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
from pybitmessage.helper_random import randomBytes
|
||||||
|
from pybitmessage.inventory import Inventory
|
||||||
|
from pybitmessage.queues import invQueue, receiveDataQueue, UISignalQueue
|
||||||
|
from pybitmessage.tr import _translate
|
||||||
from node import Peer
|
from node import Peer
|
||||||
from queues import invQueue, receiveDataQueue, UISignalQueue
|
|
||||||
from tr import _translate
|
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,10 @@ import socket
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import network.asyncore_pollchoose as asyncore
|
import asyncore_pollchoose as asyncore
|
||||||
import paths
|
from advanceddispatcher import AdvancedDispatcher
|
||||||
from network.advanceddispatcher import AdvancedDispatcher
|
from pybitmessage import paths
|
||||||
from queues import receiveDataQueue
|
from pybitmessage.queues import receiveDataQueue
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ import logging
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import protocol
|
|
||||||
import state
|
|
||||||
from bmproto import BMProto
|
from bmproto import BMProto
|
||||||
from node import Peer
|
from node import Peer
|
||||||
from objectracker import ObjectTracker
|
from objectracker import ObjectTracker
|
||||||
from queues import receiveDataQueue
|
from pybitmessage import protocol
|
||||||
|
from pybitmessage import state
|
||||||
|
from pybitmessage.queues import receiveDataQueue
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import helper_random
|
from connectionpool import BMConnectionPool
|
||||||
import protocol
|
from dandelion import Dandelion
|
||||||
from inventory import Inventory
|
from pybitmessage import helper_random
|
||||||
from network.connectionpool import BMConnectionPool
|
from pybitmessage import protocol
|
||||||
from network.dandelion import Dandelion
|
from pybitmessage.inventory import Inventory
|
||||||
from randomtrackingdict import RandomTrackingDict
|
from randomtrackingdict import RandomTrackingDict
|
||||||
from threads import StoppableThread
|
from threads import StoppableThread
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ from binascii import hexlify, unhexlify
|
||||||
from os import listdir, makedirs, path, remove, rmdir
|
from os import listdir, makedirs, path, remove, rmdir
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
from paths import lookupAppdataFolder
|
from pybitmessage.debug import logger
|
||||||
|
from pybitmessage.paths import lookupAppdataFolder
|
||||||
from storage import InventoryItem, InventoryStorage
|
from storage import InventoryItem, InventoryStorage
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,7 +163,7 @@ class FilesystemInventory(InventoryStorage):
|
||||||
newInventory[streamNumber][hashId] = InventoryItem(
|
newInventory[streamNumber][hashId] = InventoryItem(
|
||||||
objectType, streamNumber, None, expiresTime, tag)
|
objectType, streamNumber, None, expiresTime, tag)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print "error loading %s" % (hexlify(hashId))
|
logger.warning('error loading %s', hexlify(hashId))
|
||||||
self._inventory = newInventory
|
self._inventory = newInventory
|
||||||
# for i, v in self._inventory.items():
|
# for i, v in self._inventory.items():
|
||||||
# print "loaded stream: %s, %i items" % (i, len(v))
|
# print "loaded stream: %s, %i items" % (i, len(v))
|
||||||
|
|
|
@ -5,7 +5,7 @@ import sqlite3
|
||||||
import time
|
import time
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
from pybitmessage.helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
||||||
from storage import InventoryItem, InventoryStorage
|
from storage import InventoryItem, InventoryStorage
|
||||||
|
|
||||||
|
|
||||||
|
|
52
src/tests/test_randomtrackdict.py
Normal file
52
src/tests/test_randomtrackdict.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
"""
|
||||||
|
Tests for RandomTrackingDict class
|
||||||
|
"""
|
||||||
|
import random
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
|
class TestRandomTrackingDict(unittest.TestCase):
|
||||||
|
"""
|
||||||
|
Main protocol test case
|
||||||
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def randString():
|
||||||
|
"""helper function for tests, generates a random string"""
|
||||||
|
retval = b''
|
||||||
|
for _ in range(32):
|
||||||
|
retval += chr(random.randint(0, 255))
|
||||||
|
return retval
|
||||||
|
|
||||||
|
def test_check_randomtrackingdict(self):
|
||||||
|
"""Check the logic of RandomTrackingDict class"""
|
||||||
|
# from network import RandomTrackingDict
|
||||||
|
# from pybitmessage.network.randomtrackingdict import RandomTrackingDict
|
||||||
|
# from network.randomtrackingdict import RandomTrackingDict
|
||||||
|
from pybitmessage import network
|
||||||
|
a = []
|
||||||
|
k = network.randomtrackingdict.RandomTrackingDict()
|
||||||
|
|
||||||
|
a.append(time())
|
||||||
|
for i in range(50000):
|
||||||
|
k[self.randString()] = True
|
||||||
|
a.append(time())
|
||||||
|
|
||||||
|
while k:
|
||||||
|
retval = k.randomKeys(1000)
|
||||||
|
if not retval:
|
||||||
|
self.fail("error getting random keys")
|
||||||
|
|
||||||
|
try:
|
||||||
|
k.randomKeys(100)
|
||||||
|
self.fail("bad")
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
for i in retval:
|
||||||
|
del k[i]
|
||||||
|
a.append(time())
|
||||||
|
|
||||||
|
for x in range(len(a) - 1):
|
||||||
|
self.assertLess(a[x + 1] - a[x], 10)
|
Reference in New Issue
Block a user