(self)
| 170 | queues.UISignalQueue.put(('updateStatusBar', tr._translate("MainWindow", "The time on your computer, %1, may be wrong. Please verify your settings.").arg(datetime.datetime.now().strftime("%H:%M:%S")))) |
| 171 | |
| 172 | def processData(self): |
| 173 | if len(self.data) < protocol.Header.size: # if so little of the data has arrived that we can't even read the checksum then wait for more data. |
| 174 | return |
| 175 | |
| 176 | magic,command,payloadLength,checksum = protocol.Header.unpack(self.data[:protocol.Header.size]) |
| 177 | if magic != 0xE9BEB4D9: |
| 178 | self.data = "" |
| 179 | return |
| 180 | if payloadLength > 1600100: # ~1.6 MB which is the maximum possible size of an inv message. |
| 181 | logger.info('The incoming message, which we have not yet download, is too large. Ignoring it. (unfortunately there is no way to tell the other node to stop sending it except to disconnect.) Message size: %s' % payloadLength) |
| 182 | self.data = self.data[payloadLength + protocol.Header.size:] |
| 183 | del magic,command,payloadLength,checksum # we don't need these anymore and better to clean them now before the recursive call rather than after |
| 184 | self.processData() |
| 185 | return |
| 186 | if len(self.data) < payloadLength + protocol.Header.size: # check if the whole message has arrived yet. |
| 187 | return |
| 188 | payload = self.data[protocol.Header.size:payloadLength + protocol.Header.size] |
| 189 | if checksum != hashlib.sha512(payload).digest()[0:4]: # test the checksum in the message. |
| 190 | logger.error('Checksum incorrect. Clearing this message.') |
| 191 | self.data = self.data[payloadLength + protocol.Header.size:] |
| 192 | del magic,command,payloadLength,checksum,payload # better to clean up before the recursive call |
| 193 | self.processData() |
| 194 | return |
| 195 | |
| 196 | # The time we've last seen this node is obviously right now since we |
| 197 | # just received valid data from it. So update the knownNodes list so |
| 198 | # that other peers can be made aware of its existance. |
| 199 | if self.initiatedConnection and self.connectionIsOrWasFullyEstablished: # The remote port is only something we should share with others if it is the remote node's incoming port (rather than some random operating-system-assigned outgoing port). |
| 200 | with knownnodes.knownNodesLock: |
| 201 | for stream in self.streamNumber: |
| 202 | knownnodes.knownNodes[stream][self.peer] = int(time.time()) |
| 203 | |
| 204 | #Strip the nulls |
| 205 | command = command.rstrip('\x00') |
| 206 | logger.debug('remoteCommand ' + repr(command) + ' from ' + str(self.peer)) |
| 207 | |
| 208 | try: |
| 209 | #TODO: Use a dispatcher here |
| 210 | if command == 'error': |
| 211 | self.recerror(payload) |
| 212 | elif not self.connectionIsOrWasFullyEstablished: |
| 213 | if command == 'version': |
| 214 | self.recversion(payload) |
| 215 | elif command == 'verack': |
| 216 | self.recverack() |
| 217 | else: |
| 218 | if command == 'addr': |
| 219 | self.recaddr(payload) |
| 220 | elif command == 'inv': |
| 221 | self.recinv(payload) |
| 222 | elif command == 'getdata': |
| 223 | self.recgetdata(payload) |
| 224 | elif command == 'object': |
| 225 | self.recobject(payload) |
| 226 | elif command == 'ping': |
| 227 | self.sendpong(payload) |
| 228 | elif command == 'pong': |
| 229 | pass |
no test coverage detected