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

Method sendBigInv

src/network/tcp.py:157–188  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

155 self.append_write_buf(BMProto.assembleAddr(templist))
156
157 def sendBigInv(self):
158 def sendChunk():
159 if objectCount == 0:
160 return
161 logger.debug('Sending huge inv message with %i objects to just this one peer', objectCount)
162 self.append_write_buf(protocol.CreatePacket('inv', addresses.encodeVarint(objectCount) + payload))
163
164 # Select all hashes for objects in this stream.
165 bigInvList = {}
166 for stream in self.streams:
167 # may lock for a long time, but I think it's better than thousands of small locks
168 with self.objectsNewToThemLock:
169 for objHash in Inventory().unexpired_hashes_by_stream(stream):
170 # don't advertise stem objects on bigInv
171 if Dandelion().hasHash(objHash):
172 continue
173 bigInvList[objHash] = 0
174 self.objectsNewToThem[objHash] = time.time()
175 objectCount = 0
176 payload = b''
177 # Now let us start appending all of these hashes together. They will be
178 # sent out in a big inv message to our new peer.
179 for hash, storedValue in bigInvList.items():
180 payload += hash
181 objectCount += 1
182 if objectCount >= BMProto.maxObjectCount:
183 sendChunk()
184 payload = b''
185 objectCount = 0
186
187 # flush
188 sendChunk()
189
190 def handle_connect(self):
191 try:

Callers 1

Calls 5

InventoryClass · 0.90
DandelionClass · 0.90
itemsMethod · 0.80
hasHashMethod · 0.45

Tested by

no test coverage detected