Move start of network threads to network package,

reduce exported symbols and imports.
This commit is contained in:
Dmitri Bogomolov 2021-01-25 19:07:48 +02:00
parent 19f7817859
commit 54790ac2d9
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 68 additions and 69 deletions

View File

@ -41,11 +41,7 @@ from helper_startup import (
adjustHalfOpenConnectionsLimit, fixSocket, start_proxyconfig) adjustHalfOpenConnectionsLimit, fixSocket, start_proxyconfig)
from inventory import Inventory from inventory import Inventory
# Network objects and threads # Network objects and threads
from network import ( import network
BMConnectionPool, Dandelion, AddrThread, AnnounceThread, BMNetworkThread,
InvThread, ReceiveQueueThread, DownloadThread, UploadThread
)
from network.knownnodes import readKnownNodes
from singleinstance import singleinstance from singleinstance import singleinstance
# Synchronous threads # Synchronous threads
from threads import ( from threads import (
@ -176,8 +172,18 @@ class Main(object):
defaults.networkDefaultPayloadLengthExtraBytes = int( defaults.networkDefaultPayloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes / 100) defaults.networkDefaultPayloadLengthExtraBytes / 100)
# Not needed if objproc is disabled # Start the SQL thread
if state.enableObjProc: sqlLookup = sqlThread()
# DON'T close the main program even if there are threads left.
# The closeEvent should command this thread to exit gracefully.
sqlLookup.daemon = False
sqlLookup.start()
Inventory() # init
if state.enableObjProc: # Not needed if objproc is disabled
shared.reloadMyAddressHashes()
shared.reloadBroadcastSendersForWhichImWatching()
# Start the address generation thread # Start the address generation thread
addressGeneratorThread = addressGenerator() addressGeneratorThread = addressGenerator()
@ -191,19 +197,13 @@ class Main(object):
singleWorkerThread.daemon = True singleWorkerThread.daemon = True
singleWorkerThread.start() singleWorkerThread.start()
# Start the SQL thread # Start the thread that calculates POWs
sqlLookup = sqlThread() objectProcessorThread = objectProcessor()
# DON'T close the main program even if there are threads left. # DON'T close the main program even the thread remains.
# The closeEvent should command this thread to exit gracefully. # This thread checks the shutdown variable after processing
sqlLookup.daemon = False # each object.
sqlLookup.start() objectProcessorThread.daemon = False
objectProcessorThread.start()
Inventory() # init
# init, needs to be early because other thread may access it early
Dandelion()
# Enable object processor and SMTP only if objproc enabled
if state.enableObjProc:
# SMTP delivery thread # SMTP delivery thread
if daemon and config.safeGet( if daemon and config.safeGet(
@ -219,25 +219,6 @@ class Main(object):
smtpServerThread = smtpServer() smtpServerThread = smtpServer()
smtpServerThread.start() smtpServerThread.start()
# Start the thread that calculates POWs
objectProcessorThread = objectProcessor()
# DON'T close the main program even the thread remains.
# This thread checks the shutdown variable after processing
# each object.
objectProcessorThread.daemon = False
objectProcessorThread.start()
# Start the cleanerThread
singleCleanerThread = singleCleaner()
# close the main program even if there are threads left
singleCleanerThread.daemon = True
singleCleanerThread.start()
# Not needed if objproc disabled
if state.enableObjProc:
shared.reloadMyAddressHashes()
shared.reloadBroadcastSendersForWhichImWatching()
# API is also objproc dependent # API is also objproc dependent
if config.safeGetBoolean('bitmessagesettings', 'apienabled'): if config.safeGetBoolean('bitmessagesettings', 'apienabled'):
import api # pylint: disable=relative-import import api # pylint: disable=relative-import
@ -246,35 +227,26 @@ class Main(object):
singleAPIThread.daemon = True singleAPIThread.daemon = True
singleAPIThread.start() singleAPIThread.start()
# Start the cleanerThread
singleCleanerThread = singleCleaner()
# close the main program even if there are threads left
singleCleanerThread.daemon = True
singleCleanerThread.start()
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
readKnownNodes()
start_proxyconfig() start_proxyconfig()
BMConnectionPool().connectToStream(1) network.start()
asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True # Optional components
asyncoreThread.start()
for i in range(config.getint('threads', 'receive')): for i in range(config.getint('threads', 'receive')):
receiveQueueThread = ReceiveQueueThread(i) receiveQueueThread = network.ReceiveQueueThread(i)
receiveQueueThread.daemon = True receiveQueueThread.daemon = True
receiveQueueThread.start() receiveQueueThread.start()
if config.safeGetBoolean('bitmessagesettings', 'udp'): if config.safeGetBoolean('bitmessagesettings', 'udp'):
state.announceThread = AnnounceThread() state.announceThread = network.AnnounceThread()
state.announceThread.daemon = True state.announceThread.daemon = True
state.announceThread.start() state.announceThread.start()
state.invThread = InvThread()
state.invThread.daemon = True
state.invThread.start()
state.addrThread = AddrThread()
state.addrThread.daemon = True
state.addrThread.start()
state.downloadThread = DownloadThread()
state.downloadThread.daemon = True
state.downloadThread.start()
state.uploadThread = UploadThread()
state.uploadThread.daemon = True
state.uploadThread.start()
if config.safeGetBoolean('bitmessagesettings', 'upnp'): if config.safeGetBoolean('bitmessagesettings', 'upnp'):
import upnp import upnp
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()

View File

@ -1,20 +1,47 @@
""" """
Network subsystem packages Network subsystem package
""" """
from addrthread import AddrThread
from announcethread import AnnounceThread from announcethread import AnnounceThread
from connectionpool import BMConnectionPool from connectionpool import BMConnectionPool
from dandelion import Dandelion
from downloadthread import DownloadThread
from invthread import InvThread
from networkthread import BMNetworkThread
from receivequeuethread import ReceiveQueueThread from receivequeuethread import ReceiveQueueThread
from threads import StoppableThread from threads import StoppableThread
from uploadthread import UploadThread
__all__ = [ __all__ = [
"BMConnectionPool", "Dandelion", "AnnounceThread", "BMConnectionPool",
"AddrThread", "AnnounceThread", "BMNetworkThread", "DownloadThread", "ReceiveQueueThread", "StoppableThread"
"InvThread", "ReceiveQueueThread", "UploadThread", "StoppableThread" # "AddrThread", "AnnounceThread", "BMNetworkThread", "Dandelion",
# "DownloadThread", "InvThread", "UploadThread",
] ]
def start():
"""Start network threads"""
from addrthread import AddrThread
from dandelion import Dandelion
from downloadthread import DownloadThread
from invthread import InvThread
from networkthread import BMNetworkThread
from knownnodes import readKnownNodes
from uploadthread import UploadThread
readKnownNodes()
# init, needs to be early because other thread may access it early
Dandelion()
BMConnectionPool().connectToStream(1)
asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True
asyncoreThread.start()
invThread = InvThread()
invThread.daemon = True
invThread.start()
addrThread = AddrThread()
addrThread.daemon = True
addrThread.start()
downloadThread = DownloadThread()
downloadThread.daemon = True
downloadThread.start()
uploadThread = UploadThread()
uploadThread.daemon = True
uploadThread.start()