replace print statements with logger #1688

Closed
navjotcis wants to merge 2 commits from bug-fixes14 into v0.6
25 changed files with 160 additions and 146 deletions

View File

@ -3,11 +3,11 @@ Announce addresses as they are received from other hosts
"""
import Queue
import state
from helper_random import randomshuffle
from network.assemble import assemble_addr
from network.connectionpool import BMConnectionPool
from queues import addrQueue
from assemble import assemble_addr
from connectionpool import BMConnectionPool
from pybitmessage import state
from pybitmessage.helper_random import randomshuffle
from pybitmessage.queues import addrQueue
from threads import StoppableThread

View File

@ -6,8 +6,8 @@ import socket
import threading
import time
import network.asyncore_pollchoose as asyncore
import state
import asyncore_pollchoose as asyncore
from pybitmessage import state
from threads import BusyError, nonBlocking

View File

@ -3,13 +3,13 @@ Announce myself (node address)
"""
import time
import state
from bmconfigparser import BMConfigParser
from network.assemble import assemble_addr
from network.connectionpool import BMConnectionPool
from network.udp import UDPSocket
from assemble import assemble_addr
from connectionpool import BMConnectionPool
from node import Peer
from pybitmessage import state
from pybitmessage.bmconfigparser import BMConfigParser
from threads import StoppableThread
from udp import UDPSocket
class AnnounceThread(StoppableThread):

View File

@ -3,10 +3,10 @@ Create bitmessage protocol command packets
"""
import struct
import addresses
from network.constants import MAX_ADDR_COUNT
from network.node import Peer
from protocol import CreatePacket, encodeHost
from pybitmessage import addresses
from constants import MAX_ADDR_COUNT
from node import Peer
from pybitmessage.protocol import CreatePacket, encodeHost
def assemble_addr(peerList):

View File

@ -17,9 +17,9 @@ from errno import (
ECONNRESET, EHOSTUNREACH, EINPROGRESS, EINTR, EINVAL, EISCONN, ENETUNREACH,
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:
from errno import WSAEWOULDBLOCK

View File

@ -4,11 +4,11 @@ BMObject and it's exceptions.
import logging
import time
import protocol
import state
from addresses import calculateInventoryHash
from inventory import Inventory
from network.dandelion import Dandelion
from dandelion import Dandelion
from pybitmessage import protocol
from pybitmessage import state
from pybitmessage.addresses import calculateInventoryHash
from pybitmessage.inventory import Inventory
logger = logging.getLogger('default')

View File

@ -10,28 +10,28 @@ import struct
import time
from binascii import hexlify
import addresses
import connectionpool
import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from inventory import Inventory
from network.advanceddispatcher import AdvancedDispatcher
from network.bmobject import (
from advanceddispatcher import AdvancedDispatcher
from bmobject import (
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
BMObjectInvalidError, BMObjectUnwantedStreamError
)
from network.constants import (
from constants import (
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
MAX_OBJECT_PAYLOAD_SIZE, MAX_TIME_OFFSET
)
from network.dandelion import Dandelion
from network.proxy import ProxyError
from dandelion import Dandelion
from proxy import ProxyError
from node import Node, Peer
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
logger = logging.getLogger('default')

View File

@ -6,10 +6,10 @@ import logging
import random # nosec
import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from queues import Queue, portCheckerQueue
from pybitmessage import protocol
from pybitmessage import state
from pybitmessage.bmconfigparser import BMConfigParser
from pybitmessage.queues import Queue, portCheckerQueue
logger = logging.getLogger('default')

View File

@ -9,15 +9,15 @@ import sys
import time
import asyncore_pollchoose as asyncore
import helper_random
import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from connectionchooser import chooseConnection
from node import Peer
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 (
bootstrap, Socks4aBMConnection, Socks5BMConnection,
TCPConnection, TCPServer)

View File

@ -8,9 +8,9 @@ from threading import RLock
from time import time
import connectionpool
import state
from queues import invQueue
from singleton import Singleton
from pybitmessage import state
from pybitmessage.queues import invQueue
from pybitmessage.singleton import Singleton
# randomise routes after 600 seconds
REASSIGN_INTERVAL = 600

View File

@ -3,13 +3,13 @@
"""
import time
import addresses
import helper_random
import protocol
from dandelion import Dandelion
from inventory import Inventory
from network.connectionpool import BMConnectionPool
from connectionpool import BMConnectionPool
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

View File

@ -5,12 +5,12 @@ import Queue
import random
from time import time
import addresses
import protocol
import state
from network.connectionpool import BMConnectionPool
from network.dandelion import Dandelion
from queues import invQueue
from connectionpool import BMConnectionPool
from dandelion import Dandelion
from pybitmessage import addresses
from pybitmessage import protocol
from pybitmessage import state
from pybitmessage.queues import invQueue
from threads import StoppableThread

View File

@ -13,9 +13,9 @@ try:
except ImportError:
from collections import Iterable
import state
from bmconfigparser import BMConfigParser
from network.node import Peer
from node import Peer
from pybitmessage import state
from pybitmessage.bmconfigparser import BMConfigParser
state.Peer = Peer

View File

@ -1,10 +1,10 @@
"""
A thread to handle network concerns
"""
import network.asyncore_pollchoose as asyncore
import state
from network.connectionpool import BMConnectionPool
from queues import excQueue
import asyncore_pollchoose as asyncore
from connectionpool import BMConnectionPool
from pybitmessage import state
from pybitmessage.queues import excQueue
from threads import StoppableThread

View File

@ -4,8 +4,8 @@ Module for tracking objects
import time
from threading import RLock
import network.connectionpool
from network.dandelion import Dandelion
import connectionpool
from dandelion import Dandelion
from randomtrackingdict import RandomTrackingDict
haveBloom = False
@ -100,7 +100,7 @@ class ObjectTracker(object):
def handleReceivedObject(self, streamNumber, hashid):
"""Handling received object"""
for i in network.connectionpool.BMConnectionPool().connections():
for i in connectionpool.BMConnectionPool().connections():
if not i.fullyEstablished:
continue
try:

View File

@ -8,7 +8,7 @@ import time
import asyncore_pollchoose as asyncore
from advanceddispatcher import AdvancedDispatcher
from bmconfigparser import BMConfigParser
from pybitmessage.bmconfigparser import BMConfigParser
from node import Peer
logger = logging.getLogger('default')

View File

@ -1,11 +1,10 @@
"""
Track randomize ordered dict
"""
import random
from threading import RLock
from time import time
import helper_random
from pybitmessage import helper_random
class RandomTrackingDict(object):
@ -128,41 +127,3 @@ class RandomTrackingDict(object):
self.pendingLen += 1
self.lastPoll = time()
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])

View File

@ -5,10 +5,10 @@ import errno
import Queue
import socket
import state
from network.advanceddispatcher import UnknownStateError
from network.connectionpool import BMConnectionPool
from queues import receiveDataQueue
from advanceddispatcher import UnknownStateError
from connectionpool import BMConnectionPool
from pybitmessage import state
from pybitmessage.queues import receiveDataQueue
from threads import StoppableThread

View File

@ -2,35 +2,35 @@
TCP protocol handler
"""
# pylint: disable=too-many-ancestors
import l10n
import logging
import math
import random
import socket
import time
import addresses
import asyncore_pollchoose as asyncore
import connectionpool
import helper_random
import knownnodes
import protocol
import state
from bmconfigparser import BMConfigParser
from helper_random import randomBytes
from inventory import Inventory
from network.advanceddispatcher import AdvancedDispatcher
from network.assemble import assemble_addr
from network.bmproto import BMProto
from network.constants import MAX_OBJECT_COUNT
from network.dandelion import Dandelion
from network.objectracker import ObjectTracker
from network.socks4a import Socks4aConnection
from network.socks5 import Socks5Connection
from network.tls import TLSDispatcher
from advanceddispatcher import AdvancedDispatcher
from assemble import assemble_addr
from bmproto import BMProto
from constants import MAX_OBJECT_COUNT
from dandelion import Dandelion
from objectracker import ObjectTracker
from socks4a import Socks4aConnection
from socks5 import Socks5Connection
from tls import TLSDispatcher
from pybitmessage import addresses
from pybitmessage import helper_random
from pybitmessage import l10n
from pybitmessage import protocol
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 queues import invQueue, receiveDataQueue, UISignalQueue
from tr import _translate
logger = logging.getLogger('default')

View File

@ -7,10 +7,10 @@ import socket
import ssl
import sys
import network.asyncore_pollchoose as asyncore
import paths
from network.advanceddispatcher import AdvancedDispatcher
from queues import receiveDataQueue
import asyncore_pollchoose as asyncore
from advanceddispatcher import AdvancedDispatcher
from pybitmessage import paths
from pybitmessage.queues import receiveDataQueue
logger = logging.getLogger('default')

View File

@ -5,12 +5,12 @@ import logging
import socket
import time
import protocol
import state
from bmproto import BMProto
from node import Peer
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')

View File

@ -3,11 +3,11 @@
"""
import time
import helper_random
import protocol
from inventory import Inventory
from network.connectionpool import BMConnectionPool
from network.dandelion import Dandelion
from connectionpool import BMConnectionPool
from dandelion import Dandelion
from pybitmessage import helper_random
from pybitmessage import protocol
from pybitmessage.inventory import Inventory
from randomtrackingdict import RandomTrackingDict
from threads import StoppableThread

View File

@ -7,7 +7,8 @@ from binascii import hexlify, unhexlify
from os import listdir, makedirs, path, remove, rmdir
from threading import RLock
from paths import lookupAppdataFolder
from pybitmessage.debug import logger
from pybitmessage.paths import lookupAppdataFolder
from storage import InventoryItem, InventoryStorage
@ -162,7 +163,7 @@ class FilesystemInventory(InventoryStorage):
newInventory[streamNumber][hashId] = InventoryItem(
objectType, streamNumber, None, expiresTime, tag)
except KeyError:
print "error loading %s" % (hexlify(hashId))
logger.warning('error loading %s', hexlify(hashId))
self._inventory = newInventory
# for i, v in self._inventory.items():
# print "loaded stream: %s, %i items" % (i, len(v))

View File

@ -5,7 +5,7 @@ import sqlite3
import time
from threading import RLock
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from pybitmessage.helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from storage import InventoryItem, InventoryStorage

View 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)