Пример #1
0
 def __init__(self, certificate, private_key, token=None):
     self.client_cache = utils.FastStore(1000)
     self.token = token
     super(ServerCommunicator, self).__init__(certificate=certificate,
                                              private_key=private_key)
     self.pub_key_cache = utils.FastStore(max_size=50000)
     # Our common name as an RDFURN.
     self.common_name = rdfvalue.RDFURN(self.certificate.GetCN())
Пример #2
0
    def testOpenFilehandlesExpire(self):
        """Test that file handles expire from cache."""
        files.FILE_HANDLE_CACHE = utils.FastStore(max_size=10)

        current_process = psutil.Process(os.getpid())
        num_open_files = len(current_process.open_files())

        path = os.path.join(self.base_path, "morenumbers.txt")
        fd = vfs.VFSOpen(
            rdf_paths.PathSpec(path=path,
                               pathtype=rdf_paths.PathSpec.PathType.OS))

        fds = []
        for filename in fd.ListNames():
            child_fd = vfs.VFSOpen(
                rdf_paths.PathSpec(path=os.path.join(path, filename),
                                   pathtype=rdf_paths.PathSpec.PathType.OS))
            fd.read(20)
            fds.append(child_fd)

        # This should not create any new file handles.
        self.assertTrue(len(current_process.open_files()) - num_open_files < 5)

        # Make sure we exceeded the size of the cache.
        self.assertGreater(fds, 20)
Пример #3
0
    def test03Expire(self):
        """Tests the expire mechanism."""
        s = utils.FastStore(max_size=100)
        key = "test1"
        s.Put(key, 1)

        # This should not raise
        self.assertEqual(s.Get(key), 1)
        s.ExpireObject(key)

        self.assertRaises(KeyError, s.Get, key)
Пример #4
0
    def test02StoreRefresh(self):
        """Test that store keeps recently gotten objects fresh."""
        s = utils.FastStore(max_size=5)
        keys = []
        for i in range(0, 5):
            keys.append(s.Put(i, i))

        # This should not raise because keys[0] should be refreshed each time its
        # gotten
        for i in range(0, 1000):
            s.Get(keys[0])
            s.Put(i, i)
Пример #5
0
    def test01StoreExpiration(self):
        """Testing store removes objects when full."""
        s = utils.FastStore(max_size=5)
        keys = []
        for i in range(0, 100):
            keys.append(s.Put(i, i))

        # This should not raise
        s.Get(keys[-1])

        # This should raise though
        self.assertRaises(KeyError, s.Get, keys[0])
Пример #6
0
    def __init__(self, certificate=None, private_key=None):
        """Creates a communicator.

    Args:
       certificate: Our own certificate.
       private_key: Our own private key.
    """
        self.private_key = private_key
        self.certificate = certificate
        self._ClearServerCipherCache()

        # A cache for encrypted ciphers
        self.encrypted_cipher_cache = utils.FastStore(max_size=50000)
Пример #7
0
                    certificate=cert,
                    first_seen=now,
                    fleetspeak_enabled=False)

            index = client_index.CreateClientIndex(token=self.token)
            index.AddClient(client)
            if data_store.RelationalDBWriteEnabled():
                index = client_index.ClientIndex()
                index.AddClient(data_migration.ConvertVFSGRRClient(client))
        # Publish the client enrollment message.
        self.Publish("ClientEnrollment", self.client_id)

        self.Log("Enrolled %s successfully", self.client_id)


enrolment_cache = utils.FastStore(5000)


class Enroler(flow.WellKnownFlow):
    """Manage enrolment requests."""

    well_known_session_id = rdfvalue.SessionID(queue=queues.ENROLLMENT,
                                               flow_name="Enrol")

    def ProcessMessage(self, message):
        """Begins an enrollment flow for this client.

    Args:
        message: The Certificate sent by the client. Note that this
        message is not authenticated.
    """
Пример #8
0
 def __init__(self, certificate, private_key):
     super(RelationalServerCommunicator,
           self).__init__(certificate=certificate, private_key=private_key)
     self.pub_key_cache = utils.FastStore(max_size=50000)
     self.common_name = self.certificate.GetCN()
Пример #9
0
 def __init__(self):
     self._routing_maps_cache = utils.FastStore()
Пример #10
0
 def __init__(self):
     super(IPResolver, self).__init__()
     self.cache = utils.FastStore(max_size=100)