(self)
| 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: |
no test coverage detected