Smarter advertisement of object hashes and peers #494

Merged
Atheros1 merged 5 commits from master into master 2013-09-10 02:29:20 +02:00
3 changed files with 29 additions and 19 deletions
Showing only changes of commit f0bf3aad48 - Show all commits

View File

@ -1,5 +1,5 @@
# objectHashHolder is a timer-driven thread. One objectHashHolder thread is used
# by each sendDataThread. It uses it whenever a sendDataThread needs to
# by each sendDataThread. The sendDataThread uses it whenever it needs to
# advertise an object to peers. Instead of sending it out immediately, it must
# wait a random number of seconds for each connection so that different peers
# get different objects at different times. Thus an attacker who is

View File

@ -298,6 +298,7 @@ class receiveDataThread(threading.Thread):
bigInvList[hash] = 0
# We also have messages in our inventory in memory (which is a python
# dictionary). Let's fetch those too.
with shared.inventoryLock:
for hash, storedValue in shared.inventory.items():
if hash not in self.someObjectsOfWhichThisRemoteNodeIsAlreadyAware:
objectType, streamNumber, payload, receivedTime = storedValue
@ -1496,11 +1497,14 @@ class receiveDataThread(threading.Thread):
print 'received getdata request for item:', hash.encode('hex')
shared.numberOfInventoryLookupsPerformed += 1
shared.inventoryLock.acquire()
if hash in shared.inventory:
objectType, streamNumber, payload, receivedTime = shared.inventory[
hash]
shared.inventoryLock.release()
self.sendData(objectType, payload)
else:
shared.inventoryLock.release()
queryreturn = sqlQuery(
'''select objecttype, payload from inventory where hash=?''',
hash)

View File

@ -32,6 +32,7 @@ class singleCleaner(threading.Thread):
shared.UISignalQueue.put((
'updateStatusBar', 'Doing housekeeping (Flushing inventory in memory to disk...)'))
with shared.inventoryLock: # If you use both the inventoryLock and the sqlLock, always use the inventoryLock OUTSIDE of the sqlLock.
with SqlBulkExecute() as sql:
for hash, storedValue in shared.inventory.items():
objectType, streamNumber, payload, receivedTime = storedValue
@ -118,4 +119,9 @@ class singleCleaner(threading.Thread):
queryData = sqlQuery('''SELECT hash FROM inventory WHERE streamnumber=?''', streamNumber)
for row in queryData:
shared.inventorySets[streamNumber].add(row[0])
with shared.inventoryLock:
for hash, storedValue in shared.inventory.items():
objectType, streamNumber, payload, receivedTime = storedValue
if streamNumber in shared.inventorySets:
shared.inventorySets[streamNumber].add(hash)
time.sleep(300)