Failed try to resolve circular imports in network
This commit is contained in:
parent
89f490edbf
commit
d54159f356
|
@ -6,8 +6,8 @@ from six.moves import queue
|
|||
from pybitmessage import state
|
||||
from pybitmessage.helper_random import randomshuffle
|
||||
from pybitmessage.queues import addrQueue
|
||||
from .assemble import assemble_addr
|
||||
from .connectionpool import BMConnectionPool
|
||||
from .assemble import assemble_addr
|
||||
from .threads import StoppableThread
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ from pybitmessage.addresses import calculateInventoryHash
|
|||
from pybitmessage.inventory import Inventory
|
||||
from .dandelion import Dandelion
|
||||
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
||||
|
|
|
@ -14,13 +14,15 @@ from pybitmessage import addresses, protocol, state
|
|||
from pybitmessage.bmconfigparser import BMConfigParser
|
||||
from pybitmessage.inventory import Inventory
|
||||
from pybitmessage.queues import invQueue, objectProcessorQueue, portCheckerQueue
|
||||
from . import connectionpool, knownnodes
|
||||
from pybitmessage.randomtrackingdict import RandomTrackingDict
|
||||
from . import knownnodes
|
||||
from .advanceddispatcher import AdvancedDispatcher
|
||||
from .bmobject import (
|
||||
BMObject, BMObjectAlreadyHaveError, BMObjectExpiredError,
|
||||
BMObjectInsufficientPOWError, BMObjectInvalidDataError,
|
||||
BMObjectInvalidError, BMObjectUnwantedStreamError
|
||||
)
|
||||
from .pool import ConnectionPool
|
||||
from .constants import (
|
||||
ADDRESS_ALIVE, MAX_MESSAGE_SIZE, MAX_OBJECT_COUNT,
|
||||
MAX_OBJECT_PAYLOAD_SIZE, MAX_TIME_OFFSET
|
||||
|
@ -29,7 +31,7 @@ from .dandelion import Dandelion
|
|||
from .proxy import ProxyError
|
||||
from .node import Node, Peer
|
||||
from .objectracker import ObjectTracker, missingObjects
|
||||
from .randomtrackingdict import RandomTrackingDict
|
||||
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
@ -535,7 +537,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
if not self.isOutbound:
|
||||
self.append_write_buf(protocol.assembleVersionMessage(
|
||||
self.destination.host, self.destination.port,
|
||||
connectionpool.BMConnectionPool().streams, True,
|
||||
ConnectionPool.streams, True,
|
||||
nodeid=self.nodeid))
|
||||
logger.debug(
|
||||
'%(host)s:%(port)i sending version',
|
||||
|
@ -591,7 +593,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
'Closed connection to %s because there is no overlapping'
|
||||
' interest in streams.', self.destination)
|
||||
return False
|
||||
if connectionpool.BMConnectionPool().inboundConnections.get(
|
||||
if ConnectionPool.inboundConnections.get(
|
||||
self.destination):
|
||||
try:
|
||||
if not protocol.checkSocksIP(self.destination.host):
|
||||
|
@ -609,8 +611,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
# or server full report the same error to counter deanonymisation
|
||||
if (
|
||||
Peer(self.destination.host, self.peerNode.port)
|
||||
in connectionpool.BMConnectionPool().inboundConnections
|
||||
or len(connectionpool.BMConnectionPool())
|
||||
in ConnectionPool.inboundConnections
|
||||
or len(ConnectionPool)
|
||||
> BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'maxtotalconnections')
|
||||
+ BMConfigParser().safeGetInt(
|
||||
|
@ -622,7 +624,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
'Closed connection to %s due to server full'
|
||||
' or duplicate inbound/outbound.', self.destination)
|
||||
return False
|
||||
if connectionpool.BMConnectionPool().isAlreadyConnected(self.nonce):
|
||||
if ConnectionPool.isAlreadyConnected(self.nonce):
|
||||
self.append_write_buf(protocol.assembleErrorMessage(
|
||||
errorText="I'm connected to myself. Closing connection.",
|
||||
fatal=2))
|
||||
|
@ -636,7 +638,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
|||
@staticmethod
|
||||
def stopDownloadingObject(hashId, forwardAnyway=False):
|
||||
"""Stop downloading object *hashId*"""
|
||||
for connection in connectionpool.BMConnectionPool().connections():
|
||||
for connection in ConnectionPool.connections():
|
||||
try:
|
||||
del connection.objectsNewToMe[hashId]
|
||||
except KeyError:
|
||||
|
|
|
@ -8,18 +8,18 @@ import socket
|
|||
import sys
|
||||
import time
|
||||
|
||||
import asyncore_pollchoose as asyncore
|
||||
import knownnodes
|
||||
from pybitmessage import helper_random, protocol, state
|
||||
from pybitmessage.bmconfigparser import BMConfigParser
|
||||
from pybitmessage.singleton import Singleton
|
||||
from connectionchooser import chooseConnection
|
||||
from node import Peer
|
||||
from proxy import Proxy
|
||||
from tcp import (
|
||||
from . import asyncore_pollchoose as asyncore
|
||||
from . import knownnodes, pool
|
||||
from .connectionchooser import chooseConnection
|
||||
from .node import Peer
|
||||
from .proxy import Proxy
|
||||
from .tcp import (
|
||||
bootstrap, Socks4aBMConnection, Socks5BMConnection,
|
||||
TCPConnection, TCPServer)
|
||||
from udp import UDPSocket
|
||||
from .udp import UDPSocket
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
@ -401,3 +401,6 @@ class BMConnectionPool(object):
|
|||
pass
|
||||
for i in reaper:
|
||||
self.removeConnection(i)
|
||||
|
||||
|
||||
pool.ConnectionPool = BMConnectionPool()
|
||||
|
|
|
@ -10,7 +10,7 @@ from time import time
|
|||
from pybitmessage import state
|
||||
from pybitmessage.queues import invQueue
|
||||
from pybitmessage.singleton import Singleton
|
||||
from .connectionpool import BMConnectionPool
|
||||
from .pool import ConnectionPool
|
||||
|
||||
# randomise routes after 600 seconds
|
||||
REASSIGN_INTERVAL = 600
|
||||
|
@ -185,10 +185,10 @@ class Dandelion: # pylint: disable=old-style-class
|
|||
try:
|
||||
# random two connections
|
||||
self.stem = sample(
|
||||
BMConnectionPool().outboundConnections.values(), MAX_STEMS)
|
||||
ConnectionPool.outboundConnections.values(), MAX_STEMS)
|
||||
# not enough stems available
|
||||
except ValueError:
|
||||
self.stem = BMConnectionPool().outboundConnections.values()
|
||||
self.stem = ConnectionPool.outboundConnections.values()
|
||||
self.nodeMap = {}
|
||||
# hashMap stays to cater for pending stems
|
||||
self.refresh = time() + REASSIGN_INTERVAL
|
||||
|
|
|
@ -4,9 +4,9 @@ Module for tracking objects
|
|||
import time
|
||||
from threading import RLock
|
||||
|
||||
from .connectionpool import BMConnectionPool
|
||||
from pybitmessage.randomtrackingdict import RandomTrackingDict
|
||||
from .dandelion import Dandelion
|
||||
from .randomtrackingdict import RandomTrackingDict
|
||||
from .pool import ConnectionPool
|
||||
|
||||
haveBloom = False
|
||||
|
||||
|
@ -100,7 +100,7 @@ class ObjectTracker(object):
|
|||
|
||||
def handleReceivedObject(self, streamNumber, hashid):
|
||||
"""Handling received object"""
|
||||
for i in BMConnectionPool().connections():
|
||||
for i in ConnectionPool.connections():
|
||||
if not i.fullyEstablished:
|
||||
continue
|
||||
try:
|
||||
|
|
1
src/network/pool.py
Normal file
1
src/network/pool.py
Normal file
|
@ -0,0 +1 @@
|
|||
ConnectionPool = None
|
|
@ -16,10 +16,11 @@ from pybitmessage.inventory import Inventory
|
|||
from pybitmessage.queues import invQueue, receiveDataQueue, UISignalQueue
|
||||
from pybitmessage.tr import _translate
|
||||
from . import asyncore_pollchoose as asyncore
|
||||
from . import connectionpool, knownnodes
|
||||
from . import knownnodes
|
||||
from .advanceddispatcher import AdvancedDispatcher
|
||||
from .assemble import assemble_addr
|
||||
from .bmproto import BMProto
|
||||
from .pool import ConnectionPool
|
||||
from .constants import MAX_OBJECT_COUNT
|
||||
from .dandelion import Dandelion
|
||||
from .objectracker import ObjectTracker
|
||||
|
@ -264,7 +265,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
|||
self.append_write_buf(
|
||||
protocol.assembleVersionMessage(
|
||||
self.destination.host, self.destination.port,
|
||||
connectionpool.BMConnectionPool().streams,
|
||||
ConnectionPool.streams,
|
||||
False, nodeid=self.nodeid))
|
||||
self.connectedAt = time.time()
|
||||
receiveDataQueue.put(self.destination)
|
||||
|
@ -315,7 +316,7 @@ class Socks5BMConnection(Socks5Connection, TCPConnection):
|
|||
self.append_write_buf(
|
||||
protocol.assembleVersionMessage(
|
||||
self.destination.host, self.destination.port,
|
||||
connectionpool.BMConnectionPool().streams,
|
||||
ConnectionPool.streams,
|
||||
False, nodeid=self.nodeid))
|
||||
self.set_state("bm_header", expectBytes=protocol.Header.size)
|
||||
return True
|
||||
|
@ -339,7 +340,7 @@ class Socks4aBMConnection(Socks4aConnection, TCPConnection):
|
|||
self.append_write_buf(
|
||||
protocol.assembleVersionMessage(
|
||||
self.destination.host, self.destination.port,
|
||||
connectionpool.BMConnectionPool().streams,
|
||||
ConnectionPool.streams,
|
||||
False, nodeid=self.nodeid))
|
||||
self.set_state("bm_header", expectBytes=protocol.Header.size)
|
||||
return True
|
||||
|
@ -427,7 +428,7 @@ class TCPServer(AdvancedDispatcher):
|
|||
|
||||
state.ownAddresses[Peer(*sock.getsockname())] = True
|
||||
if (
|
||||
len(connectionpool.BMConnectionPool())
|
||||
len(ConnectionPool)
|
||||
> BMConfigParser().safeGetInt(
|
||||
'bitmessagesettings', 'maxtotalconnections')
|
||||
+ BMConfigParser().safeGetInt(
|
||||
|
@ -439,7 +440,6 @@ class TCPServer(AdvancedDispatcher):
|
|||
sock.close()
|
||||
return
|
||||
try:
|
||||
connectionpool.BMConnectionPool().addConnection(
|
||||
TCPConnection(sock=sock))
|
||||
ConnectionPool.addConnection(TCPConnection(sock=sock))
|
||||
except socket.error:
|
||||
pass
|
||||
|
|
|
@ -5,9 +5,9 @@ import time
|
|||
|
||||
from pybitmessage import helper_random, protocol
|
||||
from pybitmessage.inventory import Inventory
|
||||
from pybitmessage.randomtrackingdict import RandomTrackingDict
|
||||
from .connectionpool import BMConnectionPool
|
||||
from .dandelion import Dandelion
|
||||
from .randomtrackingdict import RandomTrackingDict
|
||||
from .threads import StoppableThread
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user