This function is called after either receiving an object off of the wire or after receiving one as ackdata. Returns the length of time that we should reserve to process this message if we are receiving it off of the wire.
(data)
| 332 | return 'failed' |
| 333 | |
| 334 | def checkAndShareObjectWithPeers(data): |
| 335 | """ |
| 336 | This function is called after either receiving an object off of the wire |
| 337 | or after receiving one as ackdata. |
| 338 | Returns the length of time that we should reserve to process this message |
| 339 | if we are receiving it off of the wire. |
| 340 | """ |
| 341 | if len(data) > 2 ** 18: |
| 342 | logger.info('The payload length of this object is too large (%s bytes). Ignoring it.' % len(data)) |
| 343 | return 0 |
| 344 | # Let us check to make sure that the proof of work is sufficient. |
| 345 | if not protocol.isProofOfWorkSufficient(data): |
| 346 | logger.info('Proof of work is insufficient.') |
| 347 | return 0 |
| 348 | |
| 349 | endOfLifeTime, = unpack('>Q', data[8:16]) |
| 350 | if endOfLifeTime - int(time.time()) > 28 * 24 * 60 * 60 + 10800: # The TTL may not be larger than 28 days + 3 hours of wiggle room |
| 351 | logger.info('This object\'s End of Life time is too far in the future. Ignoring it. Time is %s' % endOfLifeTime) |
| 352 | return 0 |
| 353 | if endOfLifeTime - int(time.time()) < - 3600: # The EOL time was more than an hour ago. That's too much. |
| 354 | logger.info('This object\'s End of Life time was more than an hour ago. Ignoring the object. Time is %s' % endOfLifeTime) |
| 355 | return 0 |
| 356 | intObjectType, = unpack('>I', data[16:20]) |
| 357 | try: |
| 358 | if intObjectType == 0: |
| 359 | _checkAndShareGetpubkeyWithPeers(data) |
| 360 | return 0.1 |
| 361 | elif intObjectType == 1: |
| 362 | _checkAndSharePubkeyWithPeers(data) |
| 363 | return 0.1 |
| 364 | elif intObjectType == 2: |
| 365 | _checkAndShareMsgWithPeers(data) |
| 366 | return 0.6 |
| 367 | elif intObjectType == 3: |
| 368 | _checkAndShareBroadcastWithPeers(data) |
| 369 | return 0.6 |
| 370 | else: |
| 371 | _checkAndShareUndefinedObjectWithPeers(data) |
| 372 | return 0.6 |
| 373 | except varintDecodeError as e: |
| 374 | logger.debug("There was a problem with a varint while checking to see whether it was appropriate to share an object with peers. Some details: %s" % e) |
| 375 | except Exception as e: |
| 376 | logger.critical('There was a problem while checking to see whether it was appropriate to share an object with peers. This is definitely a bug! \n%s' % traceback.format_exc()) |
| 377 | return 0 |
| 378 | |
| 379 | |
| 380 | def _checkAndShareUndefinedObjectWithPeers(data): |
nothing calls this directly
no test coverage detected