Ejemplo n.º 1
0
 def test_blacklist(self):
     """
     Ensures a misbehaving peer is correctly blacklisted. The remove_contact
     method is called and the contact's id is added to the _blacklist set.
     """
     parent_node_id = '0xdeadbeef'
     r = RoutingTable(parent_node_id)
     contact = PeerNode(PUBLIC_KEY, '192.168.0.1', 9999, 0)
     r.remove_contact = MagicMock()
     r.blacklist(contact)
     r.remove_contact.called_once_with(contact, True)
     self.assertIn(contact.network_id, r._blacklist)
Ejemplo n.º 2
0
 def test_add_contact_with_blacklisted_contact(self):
     """
     If the newly discovered contact is, in fact, already in the local
     node's blacklist then ensure it doesn't get re-added.
     """
     parent_node_id = '0xdeadbeef'
     r = RoutingTable(parent_node_id)
     contact1 = PeerNode(PUBLIC_KEY, '192.168.0.1', 9999, 0)
     contact1.network_id = hex(2)
     contact2 = PeerNode(PUBLIC_KEY, '192.168.0.2', 9999, 0)
     contact2.network_id = hex(4)
     r.blacklist(contact2)
     r.add_contact(contact1)
     self.assertEqual(len(r._buckets[0]), 1)
     r.add_contact(contact2)
     self.assertEqual(len(r._buckets[0]), 1)