(self)
| 456 | return True |
| 457 | |
| 458 | def peerValidityChecks(self): |
| 459 | if self.remoteProtocolVersion < 3: |
| 460 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 461 | errorText="Your is using an old protocol. Closing connection.")) |
| 462 | logger.debug ('Closing connection to old protocol version %s, node: %s', |
| 463 | str(self.remoteProtocolVersion), str(self.destination)) |
| 464 | return False |
| 465 | if self.timeOffset > BMProto.maxTimeOffset: |
| 466 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 467 | errorText="Your time is too far in the future compared to mine. Closing connection.")) |
| 468 | logger.info("%s's time is too far in the future (%s seconds). Closing connection to it.", |
| 469 | self.destination, self.timeOffset) |
| 470 | shared.timeOffsetWrongCount += 1 |
| 471 | return False |
| 472 | elif self.timeOffset < -BMProto.maxTimeOffset: |
| 473 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 474 | errorText="Your time is too far in the past compared to mine. Closing connection.")) |
| 475 | logger.info("%s's time is too far in the past (timeOffset %s seconds). Closing connection to it.", |
| 476 | self.destination, self.timeOffset) |
| 477 | shared.timeOffsetWrongCount += 1 |
| 478 | return False |
| 479 | else: |
| 480 | shared.timeOffsetWrongCount = 0 |
| 481 | if not self.streams: |
| 482 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 483 | errorText="We don't have shared stream interests. Closing connection.")) |
| 484 | logger.debug ('Closed connection to %s because there is no overlapping interest in streams.', |
| 485 | str(self.destination)) |
| 486 | return False |
| 487 | if self.destination in network.connectionpool.BMConnectionPool().inboundConnections: |
| 488 | try: |
| 489 | if not protocol.checkSocksIP(self.destination.host): |
| 490 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 491 | errorText="Too many connections from your IP. Closing connection.")) |
| 492 | logger.debug ('Closed connection to %s because we are already connected to that IP.', |
| 493 | str(self.destination)) |
| 494 | return False |
| 495 | except: |
| 496 | pass |
| 497 | if not self.isOutbound: |
| 498 | # incoming from a peer we're connected to as outbound, or server full |
| 499 | # report the same error to counter deanonymisation |
| 500 | if state.Peer(self.destination.host, self.peerNode.port) in \ |
| 501 | network.connectionpool.BMConnectionPool().inboundConnections or \ |
| 502 | len(network.connectionpool.BMConnectionPool().inboundConnections) + \ |
| 503 | len(network.connectionpool.BMConnectionPool().outboundConnections) > \ |
| 504 | BMConfigParser().safeGetInt("bitmessagesettings", "maxtotalconnections") + \ |
| 505 | BMConfigParser().safeGetInt("bitmessagesettings", "maxbootstrapconnections"): |
| 506 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 507 | errorText="Server full, please try again later.")) |
| 508 | logger.debug ("Closed connection to %s due to server full or duplicate inbound/outbound.", |
| 509 | str(self.destination)) |
| 510 | return False |
| 511 | if network.connectionpool.BMConnectionPool().isAlreadyConnected(self.nonce): |
| 512 | self.append_write_buf(protocol.assembleErrorMessage(fatal=2, |
| 513 | errorText="I'm connected to myself. Closing connection.")) |
| 514 | logger.debug ("Closed connection to %s because I'm connected to myself.", |
| 515 | str(self.destination)) |
no test coverage detected