Populate knownnodes from inventory when singleWorker starts
This commit is contained in:
parent
739ff7b439
commit
0dd49761d0
|
@ -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))
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"""
|
||||
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=?', 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 value.tag == tag]
|
||||
values += (InventoryItem(*value) for value in sqlQuery(
|
||||
'SELECT objecttype, streamnumber, payload, expirestime, tag'
|
||||
' FROM inventory WHERE objecttype=? AND tag=?',
|
||||
objectType, sqlite3.Binary(tag)))
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user