MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / run

Method run

src/network/invthread.py:29–87  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

27 connection.objectsNewToThem[hashId] = time()
28
29 def run(self):
30 while not state.shutdown:
31 chunk = []
32 while True:
33 # Dandelion fluff trigger by expiration
34 Dandelion().expire()
35 try:
36 data = invQueue.get(False)
37 chunk.append((data[0], data[1]))
38 # locally generated
39 if len(data) == 2 or data[2] is None:
40 self.handleLocallyGenerated(data[0], data[1])
41 except Queue.Empty:
42 break
43
44 if chunk:
45 for connection in BMConnectionPool().inboundConnections.values() + \
46 BMConnectionPool().outboundConnections.values():
47 fluffs = []
48 stems = []
49 for inv in chunk:
50 if inv[0] not in connection.streams:
51 continue
52 try:
53 with connection.objectsNewToThemLock:
54 del connection.objectsNewToThem[inv[1]]
55 except KeyError:
56 continue
57 try:
58 if connection == Dandelion().objectChildStem(inv[1]):
59 # Fluff trigger by RNG
60 # auto-ignore if config set to 0, i.e. dandelion is off
61 if randint(1, 100) >= state.dandelion:
62 fluffs.append(inv[1])
63 # send a dinv only if the stem node supports dandelion
64 elif connection.services & protocol.NODE_DANDELION > 0:
65 stems.append(inv[1])
66 else:
67 fluffs.append(inv[1])
68 except KeyError:
69 fluffs.append(inv[1])
70
71 if fluffs:
72 shuffle(fluffs)
73 connection.append_write_buf(protocol.CreatePacket('inv', \
74 addresses.encodeVarint(len(fluffs)) + "".join(fluffs)))
75 if stems:
76 shuffle(stems)
77 connection.append_write_buf(protocol.CreatePacket('dinv', \
78 addresses.encodeVarint(len(stems)) + "".join(stems)))
79
80 invQueue.iterate()
81 for i in range(len(chunk)):
82 invQueue.task_done()
83
84 if Dandelion().refresh < time():
85 Dandelion().reRandomiseStems()
86

Callers

nothing calls this directly

Calls 11

DandelionClass · 0.90
BMConnectionPoolClass · 0.90
expireMethod · 0.80
objectChildStemMethod · 0.80
append_write_bufMethod · 0.80
iterateMethod · 0.80
task_doneMethod · 0.80
reRandomiseStemsMethod · 0.80
waitMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected