grr/server/grr_response_server/databases/mem_flows.py
def LeaseClientMessages(self, client_id, lease_time=None, limit=sys.maxsize):
    """Leases available client messages for the client with the given id."""
    leased_messages = []

    now = rdfvalue.RDFDatetime.Now()
    expiration_time = now + lease_time
    process_id_str = utils.ProcessIdString()

    leases = self.client_message_leases
    for msgs_by_id in itervalues(self.client_messages):
      for msg in sorted(itervalues(msgs_by_id), key=lambda m: m.task_id):
        if db_utils.ClientIdFromGrrMessage(msg) != client_id:
          continue

        existing_lease = leases.get(msg.task_id)
        if not existing_lease or existing_lease[0] < now:
          if existing_lease:
            lease_count = existing_lease[-1] + 1
            # >= comparison since this check happens before the lease.
            if lease_count >= db.Database.CLIENT_MESSAGES_TTL:
              self._DeleteClientMessage(client_id, msg.task_id)
              continue
            leases[msg.task_id] = (expiration_time, process_id_str, lease_count)
          else:
            leases[msg.task_id] = (expiration_time, process_id_str, 0)

          msg.leased_until = expiration_time
          msg.leased_by = process_id_str
          leased_messages.append(msg)
          if len(leased_messages) >= limit:
            break

    return leased_messages
Leases available client messages for the client with the given id.
Leases available client messages for the client with the given id.
Leases available client messages for the client with the given id .
def LeaseClientMessages(self, client_id, lease_time=None, limit=sys.maxsize):
    leased_messages = []
    now = rdfvalue.RDFDatetime.Now()
    expiration_time = now + lease_time
    process_id_str = utils.ProcessIdString()
    leases = self.client_message_leases
    for msgs_by_id in itervalues(self.client_messages):
      for msg in sorted(itervalues(msgs_by_id), key=lambda m: m.task_id):
        if db_utils.ClientIdFromGrrMessage(msg) != client_id:
          continue
        existing_lease = leases.get(msg.task_id)
        if not existing_lease or existing_lease[0] < now:
          if existing_lease:
            lease_count = existing_lease[-1] + 1
            if lease_count >= db.Database.CLIENT_MESSAGES_TTL:
              self._DeleteClientMessage(client_id, msg.task_id)
              continue
            leases[msg.task_id] = (expiration_time, process_id_str, lease_count)
          else:
            leases[msg.task_id] = (expiration_time, process_id_str, 0)
          msg.leased_until = expiration_time
          msg.leased_by = process_id_str
          leased_messages.append(msg)
          if len(leased_messages) >= limit:
            break
    return leased_messages
def LeaseClientMessages ( self , client_id , lease_time = None , limit = sys . maxsize ) : leased_messages = [ ] now = rdfvalue . RDFDatetime . Now ( ) expiration_time = now + lease_time process_id_str = utils . ProcessIdString ( ) leases = self . client_message_leases for msgs_by_id in itervalues ( self . client_messages ) : for msg in sorted ( itervalues ( msgs_by_id ) , key = lambda m : m . task_id ) : if db_utils . ClientIdFromGrrMessage ( msg ) != client_id : continue existing_lease = leases . get ( msg . task_id ) if not existing_lease or existing_lease [ 0 ] < now : if existing_lease : lease_count = existing_lease [ - 1 ] + 1 if lease_count >= db . Database . CLIENT_MESSAGES_TTL : self . _DeleteClientMessage ( client_id , msg . task_id ) continue leases [ msg . task_id ] = ( expiration_time , process_id_str , lease_count ) else : leases [ msg . task_id ] = ( expiration_time , process_id_str , 0 ) msg . leased_until = expiration_time msg . leased_by = process_id_str leased_messages . append ( msg ) if len ( leased_messages ) >= limit : break return leased_messages
Leases available client messages for the client with the given id.
Leases available client messages for the client with the given id .
"""Leases available client messages for the client with the given id.""" # >= comparison since this check happens before the lease.
self
client_id
lease_time
limit