anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-db_gc.c (2640B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020, 2021, 2022 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file stasis/anastasis-db_gc.c
     18  * @brief garbage collection for the Anastasis database
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "anastasis-db_pg.h"
     23 #include "anastasis/anastasis-database/gc.h"
     24 #include "anastasis/anastasis-database/preflight.h"
     25 #include "anastasis/anastasis-database/transaction.h"
     26 
     27 
     28 enum GNUNET_DB_QueryStatus
     29 ANASTASIS_DB_gc (struct GNUNET_TIME_Absolute expire_backups,
     30                  struct GNUNET_TIME_Absolute expire_pending_payments)
     31 {
     32   struct GNUNET_PQ_QueryParam params[] = {
     33     GNUNET_PQ_query_param_absolute_time (&expire_backups),
     34     GNUNET_PQ_query_param_end
     35   };
     36   struct GNUNET_PQ_QueryParam params2[] = {
     37     GNUNET_PQ_query_param_absolute_time (&expire_pending_payments),
     38     GNUNET_PQ_query_param_end
     39   };
     40   enum GNUNET_DB_QueryStatus qs;
     41 
     42   GNUNET_break (GNUNET_OK ==
     43                 ANASTASIS_DB_preflight ());
     44 #if 0
     45   /* FIXME: should we do this? */
     46   PREPARE ("gc_challenge_pending_payments",
     47            "DELETE FROM anastasis_challenge_payment "
     48            "WHERE"
     49            "  (paid=FALSE"
     50            "   OR"
     51            "   refunded)"
     52            " AND"
     53            "  creation_date < $1;"),
     54 #endif
     55   PREPARE ("gc_accounts",
     56            "DELETE FROM anastasis_user "
     57            "WHERE"
     58            " expiration_date < $1;");
     59   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     60                                            "gc_accounts",
     61                                            params);
     62   if (qs < 0)
     63     return qs;
     64   PREPARE ("gc_recdoc_pending_payments",
     65            "DELETE FROM anastasis_recdoc_payment "
     66            "WHERE"
     67            "  paid=FALSE"
     68            " AND"
     69            "  creation_date < $1;");
     70   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     71                                              "gc_recdoc_pending_payments",
     72                                              params2);
     73 }
     74 
     75 
     76 /* end of anastasis-db_gc.c */