Pass config and state to network.start(),

don't import announcethread in the network init, use dotted imports,

work around too-many-locals pylint warning
This commit is contained in:
Dmitri Bogomolov 2021-03-03 11:51:05 +02:00 committed by Lee Miller
parent a902c3acf7
commit 6b90332730
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 30 additions and 43 deletions

View File

@ -235,17 +235,8 @@ class Main(object):
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
start_proxyconfig() start_proxyconfig()
network.start() network.start(config, state)
# Optional components
for i in range(config.getint('threads', 'receive')):
receiveQueueThread = network.ReceiveQueueThread(i)
receiveQueueThread.daemon = True
receiveQueueThread.start()
if config.safeGetBoolean('bitmessagesettings', 'udp'):
state.announceThread = network.AnnounceThread()
state.announceThread.daemon = True
state.announceThread.start()
if config.safeGetBoolean('bitmessagesettings', 'upnp'): if config.safeGetBoolean('bitmessagesettings', 'upnp'):
import upnp import upnp
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()

View File

@ -2,46 +2,42 @@
Network subsystem package Network subsystem package
""" """
from announcethread import AnnounceThread from .connectionpool import BMConnectionPool
from connectionpool import BMConnectionPool from .threads import StoppableThread
from receivequeuethread import ReceiveQueueThread
from threads import StoppableThread
__all__ = [ __all__ = ["BMConnectionPool", "StoppableThread"]
"AnnounceThread", "BMConnectionPool",
"ReceiveQueueThread", "StoppableThread"
# "AddrThread", "AnnounceThread", "BMNetworkThread", "Dandelion",
# "DownloadThread", "InvThread", "UploadThread",
]
def start(): def start(config, state):
"""Start network threads""" """Start network threads"""
from addrthread import AddrThread from .addrthread import AddrThread
from dandelion import Dandelion from .announcethread import AnnounceThread
from downloadthread import DownloadThread from .dandelion import Dandelion
from invthread import InvThread from .downloadthread import DownloadThread
from networkthread import BMNetworkThread from .invthread import InvThread
from knownnodes import readKnownNodes from .networkthread import BMNetworkThread
from uploadthread import UploadThread from .knownnodes import readKnownNodes
from .receivequeuethread import ReceiveQueueThread
from .uploadthread import UploadThread
readKnownNodes() readKnownNodes()
# init, needs to be early because other thread may access it early # init, needs to be early because other thread may access it early
Dandelion() Dandelion()
BMConnectionPool().connectToStream(1) BMConnectionPool().connectToStream(1)
asyncoreThread = BMNetworkThread() for thread in (
asyncoreThread.daemon = True BMNetworkThread(), InvThread(), AddrThread(),
asyncoreThread.start() DownloadThread(), UploadThread()
invThread = InvThread() ):
invThread.daemon = True thread.daemon = True
invThread.start() thread.start()
addrThread = AddrThread()
addrThread.daemon = True # Optional components
addrThread.start() for i in range(config.getint('threads', 'receive')):
downloadThread = DownloadThread() thread = ReceiveQueueThread(i)
downloadThread.daemon = True thread.daemon = True
downloadThread.start() thread.start()
uploadThread = UploadThread() if config.safeGetBoolean('bitmessagesettings', 'udp'):
uploadThread.daemon = True state.announceThread = AnnounceThread()
uploadThread.start() state.announceThread.daemon = True
state.announceThread.start()