Trying to enable streams 2 and 3 with minimal changes

This commit is contained in:
Dmitri Bogomolov 2020-02-10 14:38:58 +02:00
parent ebdcc363b1
commit 920b5dc25b
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
5 changed files with 24 additions and 12 deletions

View File

@ -249,7 +249,8 @@ class Main(object):
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
start_proxyconfig() start_proxyconfig()
BMConnectionPool().connectToStream(1) BMConnectionPool().connectToStream(
1 if not state.enableObjProc else None)
asyncoreThread = BMNetworkThread() asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True asyncoreThread.daemon = True
asyncoreThread.start() asyncoreThread.start()
@ -279,8 +280,8 @@ class Main(object):
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
upnpThread.start() upnpThread.start()
else: else:
# Populate with hardcoded value (same as connectToStream above) # Populate with hardcoded value just in case
state.streamsInWhichIAmParticipating.append(1) state.streamsInWhichIAmParticipating.add(1)
if not daemon and state.enableGUI: if not daemon and state.enableGUI:
if state.curses: if state.curses:

View File

@ -55,7 +55,7 @@ class BMConnectionPool(object):
self.inboundConnections = {} self.inboundConnections = {}
self.listeningSockets = {} self.listeningSockets = {}
self.udpSockets = {} self.udpSockets = {}
self.streams = [] self.streams = set()
self._lastSpawned = 0 self._lastSpawned = 0
self._spawnWait = 2 self._spawnWait = 2
self._bootstrapped = False self._bootstrapped = False
@ -87,10 +87,18 @@ class BMConnectionPool(object):
return [ return [
x for x in self.connections() if x.fullyEstablished] x for x in self.connections() if x.fullyEstablished]
def connectToStream(self, streamNumber): def connectToStream(self, streamNumber=None):
"""Connect to a bitmessage stream""" """
self.streams.append(streamNumber) Connect to the *streamNumber* bitmessage stream if given;
state.streamsInWhichIAmParticipating.append(streamNumber) otherwice connect to all streams listed in
`state.streamsInWhichIAmParticipating`
"""
if streamNumber:
self.streams.add(streamNumber)
state.streamsInWhichIAmParticipating.add(streamNumber)
else:
for streamNumber in state.streamsInWhichIAmParticipating:
self.streams.add(streamNumber)
def getConnectionByAddr(self, addr): def getConnectionByAddr(self, addr):
""" """
@ -292,8 +300,8 @@ class BMConnectionPool(object):
state.maximumNumberOfHalfOpenConnections - pending): state.maximumNumberOfHalfOpenConnections - pending):
try: try:
chosen = self.trustedPeer or chooseConnection( chosen = self.trustedPeer or chooseConnection(
helper_random.randomchoice(self.streams)) helper_random.randomchoice(list(self.streams)))
except ValueError: except (ValueError, IndexError):
continue continue
if chosen in self.outboundConnections: if chosen in self.outboundConnections:
continue continue

View File

@ -173,8 +173,9 @@ def readKnownNodes():
onionport = config.safeGetInt('bitmessagesettings', 'onionport') onionport = config.safeGetInt('bitmessagesettings', 'onionport')
if onionport: if onionport:
self_peer = Peer(onionhostname, onionport) self_peer = Peer(onionhostname, onionport)
addKnownNode(1, self_peer, is_self=True)
state.ownAddresses[self_peer] = True state.ownAddresses[self_peer] = True
for stream in state.streamsInWhichIAmParticipating:
addKnownNode(stream, self_peer, is_self=True)
def increaseRating(peer): def increaseRating(peer):

View File

@ -122,6 +122,7 @@ def reloadMyAddressHashes():
hasEnabledKeys = True hasEnabledKeys = True
# status # status
addressVersionNumber, streamNumber, hashobj = decodeAddress(addressInKeysFile)[1:] addressVersionNumber, streamNumber, hashobj = decodeAddress(addressInKeysFile)[1:]
state.streamsInWhichIAmParticipating.add(streamNumber)
if addressVersionNumber in (2, 3, 4): if addressVersionNumber in (2, 3, 4):
# Returns a simple 32 bytes of information encoded # Returns a simple 32 bytes of information encoded
# in 64 Hex characters, or null if there was an error. # in 64 Hex characters, or null if there was an error.
@ -160,6 +161,7 @@ def reloadBroadcastSendersForWhichImWatching():
address, = row address, = row
# status # status
addressVersionNumber, streamNumber, hashobj = decodeAddress(address)[1:] addressVersionNumber, streamNumber, hashobj = decodeAddress(address)[1:]
state.streamsInWhichIAmParticipating.add(streamNumber)
if addressVersionNumber == 2: if addressVersionNumber == 2:
broadcastSendersForWhichImWatching[hashobj] = 0 broadcastSendersForWhichImWatching[hashobj] = 0
# Now, for all addresses, even version 2 addresses, # Now, for all addresses, even version 2 addresses,

View File

@ -3,7 +3,7 @@ Global runtime variables.
""" """
neededPubkeys = {} neededPubkeys = {}
streamsInWhichIAmParticipating = [] streamsInWhichIAmParticipating = set()
extPort = None extPort = None
"""For UPnP""" """For UPnP"""