|
|
|
@ -1,16 +1,14 @@
|
|
|
|
|
import Queue
|
|
|
|
|
from random import randint, shuffle
|
|
|
|
|
import threading
|
|
|
|
|
import random
|
|
|
|
|
from time import time
|
|
|
|
|
|
|
|
|
|
import addresses
|
|
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
|
import protocol
|
|
|
|
|
import state
|
|
|
|
|
from helper_threading import StoppableThread
|
|
|
|
|
from network.connectionpool import BMConnectionPool
|
|
|
|
|
from network.dandelion import Dandelion
|
|
|
|
|
from queues import invQueue
|
|
|
|
|
import protocol
|
|
|
|
|
import state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handleExpiredDandelion(expired):
|
|
|
|
@ -33,11 +31,8 @@ def handleExpiredDandelion(expired):
|
|
|
|
|
i.objectsNewToThem[hashid] = time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InvThread(threading.Thread, StoppableThread):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
threading.Thread.__init__(self, name="InvBroadcaster")
|
|
|
|
|
self.initStop()
|
|
|
|
|
self.name = "InvBroadcaster"
|
|
|
|
|
class InvThread(StoppableThread):
|
|
|
|
|
name = "InvBroadcaster"
|
|
|
|
|
|
|
|
|
|
def handleLocallyGenerated(self, stream, hashId):
|
|
|
|
|
Dandelion().addHash(hashId, stream=stream)
|
|
|
|
@ -80,7 +75,7 @@ class InvThread(threading.Thread, StoppableThread):
|
|
|
|
|
if connection == Dandelion().objectChildStem(inv[1]):
|
|
|
|
|
# Fluff trigger by RNG
|
|
|
|
|
# auto-ignore if config set to 0, i.e. dandelion is off
|
|
|
|
|
if randint(1, 100) >= state.dandelion:
|
|
|
|
|
if random.randint(1, 100) >= state.dandelion:
|
|
|
|
|
fluffs.append(inv[1])
|
|
|
|
|
# send a dinv only if the stem node supports dandelion
|
|
|
|
|
elif connection.services & protocol.NODE_DANDELION > 0:
|
|
|
|
@ -91,13 +86,15 @@ class InvThread(threading.Thread, StoppableThread):
|
|
|
|
|
fluffs.append(inv[1])
|
|
|
|
|
|
|
|
|
|
if fluffs:
|
|
|
|
|
shuffle(fluffs)
|
|
|
|
|
connection.append_write_buf(protocol.CreatePacket('inv', \
|
|
|
|
|
addresses.encodeVarint(len(fluffs)) + "".join(fluffs)))
|
|
|
|
|
random.shuffle(fluffs)
|
|
|
|
|
connection.append_write_buf(protocol.CreatePacket(
|
|
|
|
|
'inv', addresses.encodeVarint(len(fluffs)) +
|
|
|
|
|
"".join(fluffs)))
|
|
|
|
|
if stems:
|
|
|
|
|
shuffle(stems)
|
|
|
|
|
connection.append_write_buf(protocol.CreatePacket('dinv', \
|
|
|
|
|
addresses.encodeVarint(len(stems)) + "".join(stems)))
|
|
|
|
|
random.shuffle(stems)
|
|
|
|
|
connection.append_write_buf(protocol.CreatePacket(
|
|
|
|
|
'dinv', addresses.encodeVarint(len(stems)) +
|
|
|
|
|
"".join(stems)))
|
|
|
|
|
|
|
|
|
|
invQueue.iterate()
|
|
|
|
|
for i in range(len(chunk)):
|
|
|
|
|