Skip to content

Commit 6b90332

Browse files
g1itchLee Miller
authored andcommitted
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
1 parent a902c3a commit 6b90332

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

src/bitmessagemain.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,8 @@ def start(self):
235235
# start network components if networking is enabled
236236
if state.enableNetwork:
237237
start_proxyconfig()
238-
network.start()
239-
240-
# Optional components
241-
for i in range(config.getint('threads', 'receive')):
242-
receiveQueueThread = network.ReceiveQueueThread(i)
243-
receiveQueueThread.daemon = True
244-
receiveQueueThread.start()
245-
if config.safeGetBoolean('bitmessagesettings', 'udp'):
246-
state.announceThread = network.AnnounceThread()
247-
state.announceThread.daemon = True
248-
state.announceThread.start()
238+
network.start(config, state)
239+
249240
if config.safeGetBoolean('bitmessagesettings', 'upnp'):
250241
import upnp
251242
upnpThread = upnp.uPnPThread()

src/network/__init__.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,42 @@
22
Network subsystem package
33
"""
44

5-
from announcethread import AnnounceThread
6-
from connectionpool import BMConnectionPool
7-
from receivequeuethread import ReceiveQueueThread
8-
from threads import StoppableThread
5+
from .connectionpool import BMConnectionPool
6+
from .threads import StoppableThread
97

108

11-
__all__ = [
12-
"AnnounceThread", "BMConnectionPool",
13-
"ReceiveQueueThread", "StoppableThread"
14-
# "AddrThread", "AnnounceThread", "BMNetworkThread", "Dandelion",
15-
# "DownloadThread", "InvThread", "UploadThread",
16-
]
9+
__all__ = ["BMConnectionPool", "StoppableThread"]
1710

1811

19-
def start():
12+
def start(config, state):
2013
"""Start network threads"""
21-
from addrthread import AddrThread
22-
from dandelion import Dandelion
23-
from downloadthread import DownloadThread
24-
from invthread import InvThread
25-
from networkthread import BMNetworkThread
26-
from knownnodes import readKnownNodes
27-
from uploadthread import UploadThread
14+
from .addrthread import AddrThread
15+
from .announcethread import AnnounceThread
16+
from .dandelion import Dandelion
17+
from .downloadthread import DownloadThread
18+
from .invthread import InvThread
19+
from .networkthread import BMNetworkThread
20+
from .knownnodes import readKnownNodes
21+
from .receivequeuethread import ReceiveQueueThread
22+
from .uploadthread import UploadThread
2823

2924
readKnownNodes()
3025
# init, needs to be early because other thread may access it early
3126
Dandelion()
3227
BMConnectionPool().connectToStream(1)
33-
asyncoreThread = BMNetworkThread()
34-
asyncoreThread.daemon = True
35-
asyncoreThread.start()
36-
invThread = InvThread()
37-
invThread.daemon = True
38-
invThread.start()
39-
addrThread = AddrThread()
40-
addrThread.daemon = True
41-
addrThread.start()
42-
downloadThread = DownloadThread()
43-
downloadThread.daemon = True
44-
downloadThread.start()
45-
uploadThread = UploadThread()
46-
uploadThread.daemon = True
47-
uploadThread.start()
28+
for thread in (
29+
BMNetworkThread(), InvThread(), AddrThread(),
30+
DownloadThread(), UploadThread()
31+
):
32+
thread.daemon = True
33+
thread.start()
34+
35+
# Optional components
36+
for i in range(config.getint('threads', 'receive')):
37+
thread = ReceiveQueueThread(i)
38+
thread.daemon = True
39+
thread.start()
40+
if config.safeGetBoolean('bitmessagesettings', 'udp'):
41+
state.announceThread = AnnounceThread()
42+
state.announceThread.daemon = True
43+
state.announceThread.start()

0 commit comments

Comments
 (0)