Skip to content

Commit e571ba8

Browse files
committed
Replaced state.streamsInWhichIAmParticipating with pool.streams
1 parent 657c1de commit e571ba8

11 files changed

+14
-16
lines changed

src/bitmessagemain.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ def start(self):
237237
upnpThread = upnp.uPnPThread()
238238
upnpThread.start()
239239
else:
240-
# Populate with hardcoded value (same as connectToStream above)
241-
state.streamsInWhichIAmParticipating.append(1)
240+
network.connectionpool.pool.connectToStream(1)
242241

243242
if not daemon and state.enableGUI:
244243
if state.curses:

src/bitmessageqt/settings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from bmconfigparser import config as config_obj
2121
from helper_sql import sqlExecute, sqlStoredProcedure
2222
from helper_startup import start_proxyconfig
23-
from network import knownnodes
23+
from network import connectionpool, knownnodes
2424
from network.announcethread import AnnounceThread
2525
from network.asyncore_pollchoose import set_rates
2626
from tr import _translate
@@ -165,7 +165,7 @@ def adjust_from_config(self, config):
165165
if self._proxy_type:
166166
for node, info in six.iteritems(
167167
knownnodes.knownNodes.get(
168-
min(state.streamsInWhichIAmParticipating), [])
168+
min(connectionpool.pool.streams), [])
169169
):
170170
if (
171171
node.host.endswith('.onion') and len(node.host) > 22

src/class_singleCleaner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def run(self): # pylint: disable=too-many-branches
108108
# Cleanup knownnodes and handle possible severe exception
109109
# while writing it to disk
110110
if state.enableNetwork:
111-
knownnodes.cleanupKnownNodes()
111+
knownnodes.cleanupKnownNodes(connectionpool.pool)
112112
except Exception as err:
113113
if "Errno 28" in str(err):
114114
self.logger.fatal(

src/network/announcethread.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import time
55

66
# magic imports!
7-
import state
87
import connectionpool
98
from bmconfigparser import config
109
from protocol import assembleAddrMessage
@@ -34,7 +33,7 @@ def announceSelf():
3433
for connection in connectionpool.pool.udpSockets.values():
3534
if not connection.announcing:
3635
continue
37-
for stream in state.streamsInWhichIAmParticipating:
36+
for stream in connectionpool.pool.streams:
3837
addr = (
3938
stream,
4039
Peer(

src/network/bmobject.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import protocol
88
import state
9+
import connectionpool
910
from highlevelcrypto import calculateInventoryHash
1011

1112
logger = logging.getLogger('default')
@@ -98,7 +99,7 @@ def checkStream(self):
9899
logger.warning(
99100
'The object has invalid stream: %s', self.streamNumber)
100101
raise BMObjectInvalidError()
101-
if self.streamNumber not in state.streamsInWhichIAmParticipating:
102+
if self.streamNumber not in connectionpool.pool.streams:
102103
logger.debug(
103104
'The streamNumber %i isn\'t one we are interested in.',
104105
self.streamNumber)

src/network/bmproto.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def bm_command_addr(self):
445445
for seenTime, stream, _, ip, port in self._decode_addr():
446446
ip = str(ip)
447447
if (
448-
stream not in state.streamsInWhichIAmParticipating
448+
stream not in connectionpool.pool.streams
449449
# FIXME: should check against complete list
450450
or ip.startswith('bootstrap')
451451
):

src/network/connectionpool.py

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def establishedConnections(self):
8888
def connectToStream(self, streamNumber):
8989
"""Connect to a bitmessage stream"""
9090
self.streams.append(streamNumber)
91-
state.streamsInWhichIAmParticipating.append(streamNumber)
9291

9392
def getConnectionByAddr(self, addr):
9493
"""

src/network/knownnodes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def dns():
226226
1, Peer('bootstrap%s.bitmessage.org' % port, port))
227227

228228

229-
def cleanupKnownNodes():
229+
def cleanupKnownNodes(pool):
230230
"""
231231
Cleanup knownnodes: remove old nodes and nodes with low rating
232232
"""
@@ -236,7 +236,7 @@ def cleanupKnownNodes():
236236

237237
with knownNodesLock:
238238
for stream in knownNodes:
239-
if stream not in state.streamsInWhichIAmParticipating:
239+
if stream not in pool.streams:
240240
continue
241241
keys = knownNodes[stream].keys()
242242
for node in keys:

src/network/udp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# magic imports!
99
import protocol
1010
import state
11+
import connectionpool
1112
from queues import receiveDataQueue
1213

1314
from bmproto import BMProto
@@ -81,7 +82,7 @@ def bm_command_addr(self):
8182
remoteport = False
8283
for seenTime, stream, _, ip, port in addresses:
8384
decodedIP = protocol.checkIPAddress(str(ip))
84-
if stream not in state.streamsInWhichIAmParticipating:
85+
if stream not in connectionpool.pool.streams:
8586
continue
8687
if (seenTime < time.time() - protocol.MAX_TIME_OFFSET
8788
or seenTime > time.time() + protocol.MAX_TIME_OFFSET):

src/state.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
neededPubkeys = {}
6-
streamsInWhichIAmParticipating = []
76

87
extPort = None
98
"""For UPnP"""

src/tests/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_0_cleaner(self):
165165
"""test knownnodes starvation leading to IndexError in Asyncore"""
166166
self._outdate_knownnodes()
167167
# time.sleep(303) # singleCleaner wakes up every 5 min
168-
knownnodes.cleanupKnownNodes()
168+
knownnodes.cleanupKnownNodes(connectionpool.pool)
169169
self.assertTrue(knownnodes.knownNodes[1])
170170
while True:
171171
try:
@@ -179,7 +179,7 @@ def _initiate_bootstrap(self):
179179
config.set('bitmessagesettings', 'dontconnect', 'true')
180180
self._wipe_knownnodes()
181181
knownnodes.addKnownNode(1, Peer('127.0.0.1', 8444), is_self=True)
182-
knownnodes.cleanupKnownNodes()
182+
knownnodes.cleanupKnownNodes(connectionpool.pool)
183183
time.sleep(5)
184184

185185
def _check_connection(self, full=False):

0 commit comments

Comments
 (0)