Skip to content

Commit

Permalink
Replaced state.streamsInWhichIAmParticipating with pool.streams
Browse files Browse the repository at this point in the history
  • Loading branch information
anand-skss committed May 15, 2024
1 parent 657c1de commit e571ba8
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/bitmessagemain.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ def start(self):
upnpThread = upnp.uPnPThread()
upnpThread.start()
else:
# Populate with hardcoded value (same as connectToStream above)
state.streamsInWhichIAmParticipating.append(1)
network.connectionpool.pool.connectToStream(1)

if not daemon and state.enableGUI:
if state.curses:
Expand Down
4 changes: 2 additions & 2 deletions src/bitmessageqt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from bmconfigparser import config as config_obj
from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network import knownnodes
from network import connectionpool, knownnodes
from network.announcethread import AnnounceThread
from network.asyncore_pollchoose import set_rates
from tr import _translate
Expand Down Expand Up @@ -165,7 +165,7 @@ def adjust_from_config(self, config):
if self._proxy_type:
for node, info in six.iteritems(
knownnodes.knownNodes.get(
min(state.streamsInWhichIAmParticipating), [])
min(connectionpool.pool.streams), [])
):
if (
node.host.endswith('.onion') and len(node.host) > 22
Expand Down
2 changes: 1 addition & 1 deletion src/class_singleCleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def run(self): # pylint: disable=too-many-branches
# Cleanup knownnodes and handle possible severe exception
# while writing it to disk
if state.enableNetwork:
knownnodes.cleanupKnownNodes()
knownnodes.cleanupKnownNodes(connectionpool.pool)
except Exception as err:
if "Errno 28" in str(err):
self.logger.fatal(
Expand Down
3 changes: 1 addition & 2 deletions src/network/announcethread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time

# magic imports!
import state
import connectionpool
from bmconfigparser import config
from protocol import assembleAddrMessage
Expand Down Expand Up @@ -34,7 +33,7 @@ def announceSelf():
for connection in connectionpool.pool.udpSockets.values():
if not connection.announcing:
continue
for stream in state.streamsInWhichIAmParticipating:
for stream in connectionpool.pool.streams:
addr = (
stream,
Peer(
Expand Down
3 changes: 2 additions & 1 deletion src/network/bmobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import protocol
import state
import connectionpool
from highlevelcrypto import calculateInventoryHash

logger = logging.getLogger('default')
Expand Down Expand Up @@ -98,7 +99,7 @@ def checkStream(self):
logger.warning(
'The object has invalid stream: %s', self.streamNumber)
raise BMObjectInvalidError()
if self.streamNumber not in state.streamsInWhichIAmParticipating:
if self.streamNumber not in connectionpool.pool.streams:
logger.debug(
'The streamNumber %i isn\'t one we are interested in.',
self.streamNumber)
Expand Down
2 changes: 1 addition & 1 deletion src/network/bmproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def bm_command_addr(self):
for seenTime, stream, _, ip, port in self._decode_addr():
ip = str(ip)
if (
stream not in state.streamsInWhichIAmParticipating
stream not in connectionpool.pool.streams
# FIXME: should check against complete list
or ip.startswith('bootstrap')
):
Expand Down
1 change: 0 additions & 1 deletion src/network/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def establishedConnections(self):
def connectToStream(self, streamNumber):
"""Connect to a bitmessage stream"""
self.streams.append(streamNumber)
state.streamsInWhichIAmParticipating.append(streamNumber)

def getConnectionByAddr(self, addr):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/network/knownnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def dns():
1, Peer('bootstrap%s.bitmessage.org' % port, port))


def cleanupKnownNodes():
def cleanupKnownNodes(pool):
"""
Cleanup knownnodes: remove old nodes and nodes with low rating
"""
Expand All @@ -236,7 +236,7 @@ def cleanupKnownNodes():

with knownNodesLock:
for stream in knownNodes:
if stream not in state.streamsInWhichIAmParticipating:
if stream not in pool.streams:
continue
keys = knownNodes[stream].keys()
for node in keys:
Expand Down
3 changes: 2 additions & 1 deletion src/network/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# magic imports!
import protocol
import state
import connectionpool
from queues import receiveDataQueue

from bmproto import BMProto
Expand Down Expand Up @@ -81,7 +82,7 @@ def bm_command_addr(self):
remoteport = False
for seenTime, stream, _, ip, port in addresses:
decodedIP = protocol.checkIPAddress(str(ip))
if stream not in state.streamsInWhichIAmParticipating:
if stream not in connectionpool.pool.streams:
continue
if (seenTime < time.time() - protocol.MAX_TIME_OFFSET
or seenTime > time.time() + protocol.MAX_TIME_OFFSET):
Expand Down
1 change: 0 additions & 1 deletion src/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

neededPubkeys = {}
streamsInWhichIAmParticipating = []

extPort = None
"""For UPnP"""
Expand Down
4 changes: 2 additions & 2 deletions src/tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_0_cleaner(self):
"""test knownnodes starvation leading to IndexError in Asyncore"""
self._outdate_knownnodes()
# time.sleep(303) # singleCleaner wakes up every 5 min
knownnodes.cleanupKnownNodes()
knownnodes.cleanupKnownNodes(connectionpool.pool)
self.assertTrue(knownnodes.knownNodes[1])
while True:
try:
Expand All @@ -179,7 +179,7 @@ def _initiate_bootstrap(self):
config.set('bitmessagesettings', 'dontconnect', 'true')
self._wipe_knownnodes()
knownnodes.addKnownNode(1, Peer('127.0.0.1', 8444), is_self=True)
knownnodes.cleanupKnownNodes()
knownnodes.cleanupKnownNodes(connectionpool.pool)
time.sleep(5)

def _check_connection(self, full=False):
Expand Down

0 comments on commit e571ba8

Please sign in to comment.