/ src / network / __init__.py
__init__.py
 1  """
 2  Network subsystem package
 3  """
 4  from six.moves import queue
 5  from .dandelion import Dandelion
 6  from .threads import StoppableThread
 7  from .multiqueue import MultiQueue
 8  
 9  dandelion_ins = Dandelion()
10  
11  # network queues
12  invQueue = MultiQueue()
13  addrQueue = MultiQueue()
14  portCheckerQueue = queue.Queue()
15  receiveDataQueue = queue.Queue()
16  
17  __all__ = ["StoppableThread"]
18  
19  
20  def start(config, state):
21      """Start network threads"""
22      from .announcethread import AnnounceThread
23      from . import connectionpool  # pylint: disable=relative-import
24      from .addrthread import AddrThread
25      from .downloadthread import DownloadThread
26      from .invthread import InvThread
27      from .networkthread import BMNetworkThread
28      from .knownnodes import readKnownNodes
29      from .receivequeuethread import ReceiveQueueThread
30      from .uploadthread import UploadThread
31  
32      # check and set dandelion enabled value at network startup
33      dandelion_ins.init_dandelion_enabled(config)
34      # pass pool instance into dandelion class instance
35      dandelion_ins.init_pool(connectionpool.pool)
36  
37      readKnownNodes()
38      connectionpool.pool.connectToStream(1)
39      for thread in (
40          BMNetworkThread(), InvThread(), AddrThread(),
41          DownloadThread(), UploadThread()
42      ):
43          thread.daemon = True
44          thread.start()
45  
46      # Optional components
47      for i in range(config.getint('threads', 'receive')):
48          thread = ReceiveQueueThread(i)
49          thread.daemon = True
50          thread.start()
51      if config.safeGetBoolean('bitmessagesettings', 'udp'):
52          state.announceThread = AnnounceThread()
53          state.announceThread.daemon = True
54          state.announceThread.start()