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