Populate knownnodes from inventory when singleWorker starts

This commit is contained in:
Dmitri Bogomolov 2019-12-02 14:10:52 +02:00
parent 739ff7b439
commit 0dd49761d0
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
3 changed files with 27 additions and 8 deletions

View File

@ -176,6 +176,7 @@ class objectProcessor(threading.Thread):
return
peer = Peer(host, port)
with knownnodes.knownNodesLock:
# FIXME: adjust expirestime
knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer))

View File

@ -17,6 +17,7 @@ import helper_inbox
import helper_msgcoding
import helper_random
import highlevelcrypto
import knownnodes
import l10n
import proofofwork
import protocol
@ -114,6 +115,15 @@ class singleWorker(StoppableThread):
)
del state.ackdataForWhichImWatching[oldack]
# For the case if user deleted knownnodes
# but is still having onionpeer objects in inventory
if not knownnodes.knownNodesActual:
for item in Inventory().by_type_and_tag(protocol.OBJECT_ONIONPEER):
queues.objectProcessorQueue.put((
protocol.OBJECT_ONIONPEER, item.payload
))
# FIXME: should also delete from inventory
# give some time for the GUI to start
# before we start on existing POW tasks.
self.stop.wait(10)

View File

@ -70,15 +70,23 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
return len(self._inventory) + sqlQuery(
'SELECT count(*) FROM inventory')[0][0]
def by_type_and_tag(self, objectType, tag):
"""Return objects filtered by object type and tag"""
with self.lock:
values = [value for value in self._inventory.values()
if value.type == objectType and value.tag == tag]
values += (InventoryItem(*value) for value in sqlQuery(
def by_type_and_tag(self, objectType, tag=None):
"""
Get all inventory items of certain *objectType*
with *tag* if given.
"""
query = [
'SELECT objecttype, streamnumber, payload, expirestime, tag'
' FROM inventory WHERE objecttype=? AND tag=?',
objectType, sqlite3.Binary(tag)))
' FROM inventory WHERE objecttype=?', objectType]
if tag:
query[0] += ' AND tag=?'
query.append(sqlite3.Binary(tag))
with self.lock:
values = [
value for value in self._inventory.values()
if value.type == objectType
and tag is None or value.tag == tag
] + [InventoryItem(*value) for value in sqlQuery(*query)]
return values
def unexpired_hashes_by_stream(self, stream):