Esempio n. 1
0
 def test_restore_with_contacts_and_blacklist(self):
     """
     Ensures that any contacts also in the blacklist are actually
     blacklisted and removed from the routing table.
     """
     blacklist = [BAD_PUBLIC_KEY, ]
     contacts = []
     uri = 'netstring://192.168.0.1:9999/'
     contacts.append({
         'public_key': PUBLIC_KEY,
         'version': self.version,
         'uri': uri,
     })
     contacts.append({
         'public_key': BAD_PUBLIC_KEY,
         'version': self.version,
         'uri': uri,
     })
     data_dump = {
         'contacts': contacts,
         'blacklist': blacklist,
     }
     parent_node_id = 'deadbeef'
     rt = RoutingTable(parent_node_id)
     rt.restore(data_dump)
     self.assertEqual(len(rt._buckets[0]), 1)
     self.assertEqual(len(rt._blacklist), 1)
Esempio n. 2
0
 def test_dump(self):
     """
     Ensures that the expected dictionary is returned from a call to the
     dump method (used to back up the routing table).
     """
     contacts = []
     blacklist = [BAD_PUBLIC_KEY, ]
     uri = 'netstring://192.168.0.1:9999/'
     contacts.append({
         'public_key': PUBLIC_KEY,
         'version': self.version,
         'uri': uri,
     })
     data_dump = {
         'contacts': contacts,
         'blacklist': blacklist,
     }
     parent_node_id = 'deadbeef'
     rt = RoutingTable(parent_node_id)
     rt.restore(data_dump)
     result = rt.dump()
     self.assertIn('blacklist', result)
     self.assertIn('contacts', result)
     self.assertEqual(1, len(result['blacklist']))
     self.assertIn(BAD_PUBLIC_KEY, result['blacklist'])
     self.assertEqual(1, len(result['contacts']))
     self.assertEqual(PUBLIC_KEY, result['contacts'][0]['public_key'])
     self.assertEqual(self.version, result['contacts'][0]['version'])
     self.assertEqual(uri, result['contacts'][0]['uri'])
     # check it can be serialised into JSON
     dump = json.dumps(result)
     self.assertIsInstance(dump, str)
Esempio n. 3
0
 def test_restore_with_blacklist(self):
     """
     Ensures that a list of network_ids of blacklisted peers can be restored
     into the newly created object.
     """
     data_dump = {
         'blacklist': [PUBLIC_KEY, ],
     }
     parent_node_id = 'deadbeef'
     r = RoutingTable(parent_node_id)
     self.assertEqual(len(r._blacklist), 0)
     r.restore(data_dump)
     self.assertEqual(len(r._blacklist), 1)
     self.assertIn(PUBLIC_KEY, r._blacklist)
Esempio n. 4
0
 def test_restore_with_contacts(self):
     """
     Ensures the routing table can be restored with a list of contacts.
     """
     contacts = []
     uri = 'netstring://192.168.0.1:9999/'
     contacts.append({
         'public_key': PUBLIC_KEY,
         'version': self.version,
         'uri': uri,
     })
     data_dump = {
         'contacts': contacts,
     }
     parent_node_id = 'deadbeef'
     r = RoutingTable(parent_node_id)
     self.assertEqual(len(r._buckets[0]), 0)
     r.restore(data_dump)
     self.assertEqual(len(r._buckets[0]), 1)
     self.assertEqual(PUBLIC_KEY, r._buckets[0]._contacts[0].public_key)