/* GNU Guix --- Functional package management for GNU
   Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>

   This file is part of GNU Guix.

   GNU Guix is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or (at
   your option) any later version.

   GNU Guix is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef _GNUNET_REHASH_REHASH_H
#define _GNUNET_REHASH_REHASH_H

#include <gnunet/gnunet_time_lib.h>

/* TODO: are response id's required?
   See GNUNET_DHT_*.
   TODO: replication level?  */
GNUNET_NETWORK_STRUCT_BEGIN

/**
 * Message from client to rehash service to lookup hash->hash mappings
 */
struct GNUNET_REHASH_GetMessage
{
  /**
   * Header of type #GNUNET_MESSAGE_TYPE_REHASH_GET
   */
  struct GNUNET_MessageHeader header;
  uint32_t options; /* NBO, enum GNUNET_FS_SearchOptions */
  /**
   * Requested anonymity level, NBO
   */
  uint32_t anonymity_level;
  /**
   * Hash type to search with,
   * enum GNUNET_REHASH_Hash_Type in NBO.
   */
  uint32_t in_type;
  /**
   * Hash type to search for,
   * enum GNUNET_REHASH_Hash_Type in NBO.
   */
  uint32_t out_type;
  /**
   * Length of input hash, NBO
   */
  uint32_t input_length;
  /* Followed by input_length bytes */
};

/**
 * Message from rehash service to client to return hash->hash mappings
 */
struct GNUNET_REHASH_ResultMessage
{
  /**
   * Header of type #GNUNET_MESSAGE_TYPE_REHASH_RESULT
   */
  struct GNUNET_MessageHeader header;
  /**
   * When will this mapping expire?
   */
  struct GNUNET_TIME_AbsoluteNBO exp;
  /**
   * Length of output hash, in NBO
   */
  uint32_t output_length;
  /* Followed by output_length bytes */
};

/**
 * Message from client to rehash service to stop a hash->hash lookup
 * request
 */
struct GNUNET_REHASH_GetStopMessage
{
  /**
   * Header of type #GNUNET_MESSAGE_TYPE_REHASH_RESULT
   */
  struct GNUNET_MessageHeader header;
};

/**
 * Message from client to rehash service to insert a hash->hash
 * mapping
 */
struct GNUNET_REHASH_PutMessage {
  struct GNUNET_MessageHeader header;
  struct GNUNET_TIME_AbsoluteNBO expiration_time;
  /** NBO */
  uint32_t anonymity_level;
  /** NBO */
  uint32_t content_priority;
  /** NBO */
  uint32_t replication_level;
  /**
   * Hash type to search with,
   * enum GNUNET_REHASH_Hash_Type in NBO.
   */
  uint32_t in_type;
  /**
   * Hash type to search for,
   * enum GNUNET_REHASH_Hash_Type in NBO.
   */
  uint32_t out_type;
  /**
   * Length of hash to search with, NBO
   */
  uint32_t input_length;
  /**
   * Length of hash to search for, NBO
   */
  uint32_t output_length;
  /* Followed by input_length bytes
     for the input hash, and output_length bytes
     for output hash */
};

GNUNET_NETWORK_STRUCT_END
#endif
