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 return
peer = Peer(host, port) peer = Peer(host, port)
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
# FIXME: adjust expirestime
knownnodes.addKnownNode( knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer)) stream, peer, is_self=state.ownAddresses.get(peer))

View File

@ -17,6 +17,7 @@ import helper_inbox
import helper_msgcoding import helper_msgcoding
import helper_random import helper_random
import highlevelcrypto import highlevelcrypto
import knownnodes
import l10n import l10n
import proofofwork import proofofwork
import protocol import protocol
@ -114,6 +115,15 @@ class singleWorker(StoppableThread):
) )
del state.ackdataForWhichImWatching[oldack] 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 # give some time for the GUI to start
# before we start on existing POW tasks. # before we start on existing POW tasks.
self.stop.wait(10) self.stop.wait(10)

View File

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