Ejemplo n.º 1
0
    def receive_message(self, message, sender, connection, ban_score):
        if message.testnet != self.multiplexer.testnet:
            self.log.warning(
                "received message from %s with incorrect network parameters." %
                str(connection.dest_addr))
            connection.shutdown()
            return False

        if message.protoVer < PROTOCOL_VERSION:
            self.log.warning(
                "received message from %s with incompatible protocol version."
                % str(connection.dest_addr))
            connection.shutdown()
            return False

        self.multiplexer.vendors[sender.id] = sender

        msgID = message.messageID
        if message.command == NOT_FOUND:
            data = None
        else:
            data = tuple(message.arguments)
        if msgID in self._outstanding:
            self._acceptResponse(msgID, data, sender)
        elif message.command != NOT_FOUND:
            # ban_score.process_message(message)
            self._acceptRequest(msgID,
                                str(Command.Name(message.command)).lower(),
                                data, sender, connection)
Ejemplo n.º 2
0
 def ban(self, message_type):
     self.log.warning("Banned %s. Reason: too many %s messages." %
                      (self.peer_ip[0], Command.Name(message_type)))
     self.multiplexer.ban_ip(self.peer_ip[0])
     self.multiplexer[self.peer_ip].shutdown()
     reactor.callLater(self.ban_time, self.multiplexer.remove_ip_ban,
                       self.peer_ip[0])
Ejemplo n.º 3
0
    def receive_message(self, datagram, connection):
        m = Message()
        try:
            m.ParseFromString(datagram)
            sender = node.Node(m.sender.guid, m.sender.ip, m.sender.port, m.sender.signedPublicKey, m.sender.vendor)
        except Exception:
            # If message isn't formatted property then ignore
            self.log.warning("Received unknown message from %s, ignoring" % str(connection.dest_addr))
            return False

        # Check that the GUID is valid. If not, ignore
        if self.router.isNewNode(sender):
            try:
                pubkey = m.sender.signedPublicKey[len(m.sender.signedPublicKey) - 32:]
                verify_key = nacl.signing.VerifyKey(pubkey)
                verify_key.verify(m.sender.signedPublicKey)
                h = nacl.hash.sha512(m.sender.signedPublicKey)
                pow_hash = h[64:128]
                if int(pow_hash[:6], 16) >= 50 or hexlify(m.sender.guid) != h[:40]:
                    raise Exception('Invalid GUID')

            except Exception:
                self.log.warning("Received message from sender with invalid GUID, ignoring")
                return False

        if m.sender.vendor:
            VendorStore().save_vendor(m.sender.guid, m.sender.ip, m.sender.port, m.sender.signedPublicKey)

        msgID = m.messageID
        data = tuple(m.arguments)
        if msgID in self._outstanding:
            self._acceptResponse(msgID, data, sender)
        else:
            self._acceptRequest(msgID, str(Command.Name(m.command)).lower(), data, sender, connection)
Ejemplo n.º 4
0
    def receive_message(self, message, connection, ban_score):
        sender = Node(
            message.sender.guid, message.sender.nodeAddress.ip,
            message.sender.nodeAddress.port, message.sender.signedPublicKey,
            None if not message.sender.HasField("relayAddress") else
            (message.sender.relayAddress.ip, message.sender.relayAddress.port),
            message.sender.natType, message.sender.vendor)

        if message.testnet != self.multiplexer.testnet:
            self.log.warning(
                "received message from %s with incorrect network parameters." %
                str(connection.dest_addr))
            connection.shutdown()
            return False

        if message.protoVer < PROTOCOL_VERSION:
            self.log.warning(
                "received message from %s with incompatible protocol version."
                % str(connection.dest_addr))
            connection.shutdown()
            return False

        # Check that the GUID is valid. If not, ignore
        if self.router.isNewNode(sender):
            try:
                pubkey = message.sender.signedPublicKey[len(message.sender.
                                                            signedPublicKey) -
                                                        32:]
                verify_key = nacl.signing.VerifyKey(pubkey)
                verify_key.verify(message.sender.signedPublicKey)
                h = nacl.hash.sha512(message.sender.signedPublicKey)
                pow_hash = h[64:128]
                if int(pow_hash[:6], 16) >= 50 or hexlify(
                        message.sender.guid) != h[:40]:
                    raise Exception('Invalid GUID')

            except Exception:
                self.log.warning(
                    "received message from sender with invalid GUID, ignoring")
                connection.shutdown()
                return False

        if message.sender.vendor:
            self.db.VendorStore().save_vendor(
                message.sender.guid.encode("hex"),
                message.sender.SerializeToString())

        msgID = message.messageID
        if message.command == NOT_FOUND:
            data = None
        else:
            data = tuple(message.arguments)
        if msgID in self._outstanding:
            self._acceptResponse(msgID, data, sender)
        elif message.command != NOT_FOUND:
            #ban_score.process_message(m)
            self._acceptRequest(msgID,
                                str(Command.Name(message.command)).lower(),
                                data, sender, connection)
Ejemplo n.º 5
0
 def ban(self, peer, message_type):
     reason = Command.Name(message_type)
     self.log.warning("Banned %s. Reason: too many %s messages." %
                      (peer[0], reason))
     self.multiplexer.ban_ip(peer[0])
     if peer in self.multiplexer:
         self.multiplexer[peer].shutdown()
     reactor.callLater(self.ban_time, self.multiplexer.remove_ip_ban,
                       peer[0])
Ejemplo n.º 6
0
 def ban(self, peer, message_type):
     if message_type == 100:
         reason = "RECONNECTIONS"
     elif message_type == 110:
         reason = "MALFORMATTED"
     else:
         reason = Command.Name(message_type)
     self.log.warning("Banned %s. Reason: too many %s messages." %
                      (peer[0], reason))
     self.multiplexer.ban_ip(peer[0])
     if peer in self.multiplexer:
         self.multiplexer[peer].shutdown()
     reactor.callLater(self.ban_time, self.multiplexer.remove_ip_ban,
                       peer[0])
Ejemplo n.º 7
0
    def receive_message(self, datagram, connection, ban_score):
        m = Message()
        try:
            m.ParseFromString(datagram)
            sender = node.Node(m.sender.guid, m.sender.ip, m.sender.port,
                               m.sender.signedPublicKey, m.sender.vendor)
        except Exception:
            # If message isn't formatted property then ignore
            self.log.warning("received unknown message from %s, ignoring" %
                             str(connection.dest_addr))
            return False

        if m.testnet != self.multiplexer.testnet:
            self.log.warning(
                "received message from %s with incorrect network parameters." %
                str(connection.dest_addr))
            connection.shutdown()
            return False

        if m.protoVer < PROTOCOL_VERSION:
            self.log.warning(
                "received message from %s with incompatible protocol version."
                % str(connection.dest_addr))
            connection.shutdown()
            return False

        # Check that the GUID is valid. If not, ignore
        if self.router.isNewNode(sender):
            try:
                pubkey = m.sender.signedPublicKey[len(m.sender.signedPublicKey
                                                      ) - 32:]
                verify_key = nacl.signing.VerifyKey(pubkey)
                verify_key.verify(m.sender.signedPublicKey)
                h = nacl.hash.sha512(m.sender.signedPublicKey)
                pow_hash = h[64:128]
                if int(pow_hash[:6], 16) >= 50 or hexlify(
                        m.sender.guid) != h[:40]:
                    raise Exception('Invalid GUID')

            except Exception:
                self.log.warning(
                    "received message from sender with invalid GUID, ignoring")
                connection.shutdown()
                return False

        if m.sender.vendor:
            self.db.VendorStore().save_vendor(m.sender.guid.encode("hex"),
                                              m.sender.ip, m.sender.port,
                                              m.sender.signedPublicKey)

        msgID = m.messageID
        if m.command == NOT_FOUND:
            data = None
        else:
            data = tuple(m.arguments)
        if msgID in self._outstanding:
            self._acceptResponse(msgID, data, sender)
        elif m.command != NOT_FOUND:
            ban_score.process_message(m)
            self._acceptRequest(msgID,
                                str(Command.Name(m.command)).lower(), data,
                                sender, connection)