(self)
| 112 | self.sendBigInv() |
| 113 | |
| 114 | def sendAddr(self): |
| 115 | # We are going to share a maximum number of 1000 addrs (per overlapping |
| 116 | # stream) with our peer. 500 from overlapping streams, 250 from the |
| 117 | # left child stream, and 250 from the right child stream. |
| 118 | maxAddrCount = BMConfigParser().safeGetInt("bitmessagesettings", "maxaddrperstreamsend", 500) |
| 119 | |
| 120 | # init |
| 121 | addressCount = 0 |
| 122 | payload = b'' |
| 123 | |
| 124 | templist = [] |
| 125 | addrs = {} |
| 126 | for stream in self.streams: |
| 127 | with knownnodes.knownNodesLock: |
| 128 | if len(knownnodes.knownNodes[stream]) > 0: |
| 129 | filtered = {k: v for k, v in knownnodes.knownNodes[stream].items() |
| 130 | if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)} |
| 131 | elemCount = len(filtered) |
| 132 | if elemCount > maxAddrCount: |
| 133 | elemCount = maxAddrCount |
| 134 | # only if more recent than 3 hours |
| 135 | addrs[stream] = random.sample(filtered.items(), elemCount) |
| 136 | # sent 250 only if the remote isn't interested in it |
| 137 | if len(knownnodes.knownNodes[stream * 2]) > 0 and stream not in self.streams: |
| 138 | filtered = {k: v for k, v in knownnodes.knownNodes[stream*2].items() |
| 139 | if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)} |
| 140 | elemCount = len(filtered) |
| 141 | if elemCount > maxAddrCount / 2: |
| 142 | elemCount = int(maxAddrCount / 2) |
| 143 | addrs[stream * 2] = random.sample(filtered.items(), elemCount) |
| 144 | if len(knownnodes.knownNodes[(stream * 2) + 1]) > 0 and stream not in self.streams: |
| 145 | filtered = {k: v for k, v in knownnodes.knownNodes[stream*2+1].items() |
| 146 | if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)} |
| 147 | elemCount = len(filtered) |
| 148 | if elemCount > maxAddrCount / 2: |
| 149 | elemCount = int(maxAddrCount / 2) |
| 150 | addrs[stream * 2 + 1] = random.sample(filtered.items(), elemCount) |
| 151 | for substream in addrs.keys(): |
| 152 | for peer, params in addrs[substream]: |
| 153 | templist.append((substream, peer, params["lastseen"])) |
| 154 | if len(templist) > 0: |
| 155 | self.append_write_buf(BMProto.assembleAddr(templist)) |
| 156 | |
| 157 | def sendBigInv(self): |
| 158 | def sendChunk(): |
no test coverage detected