-skeletons for transport-ng
[oweals/gnunet.git] / src / peerstore / peerstore_common.h
1 /*
2       This file is part of GNUnet
3       Copyright (C)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @file peerstore/peerstore_common.h
23  * @brief Helper peerstore functions
24  * @author Omar Tarabai
25  */
26
27 #include "platform.h"
28 #include "peerstore.h"
29
30 /**
31  * Creates a hash of the given key combination
32  *
33  */
34 void
35 PEERSTORE_hash_key (const char *sub_system,
36                     const struct GNUNET_PeerIdentity *peer, const char *key,
37                     struct GNUNET_HashCode *ret);
38
39 /**
40  * Creates a record message ready to be sent
41  *
42  * @param sub_system sub system string
43  * @param peer Peer identity (can be NULL)
44  * @param key record key string (can be NULL)
45  * @param value record value BLOB (can be NULL)
46  * @param value_size record value size in bytes (set to 0 if value is NULL)
47  * @param expiry absolute time after which the record expires
48  * @param msg_type message type to be set in header
49  * @return pointer to record message struct
50  */
51 struct StoreRecordMessage *
52 PEERSTORE_create_record_message (const char *sub_system,
53                                  const struct GNUNET_PeerIdentity *peer,
54                                  const char *key, const void *value,
55                                  size_t value_size,
56                                  struct GNUNET_TIME_Absolute *expiry,
57                                  uint16_t msg_type);
58
59 /**
60  * Creates a MQ envelope for a single record
61  *
62  * @param sub_system sub system string
63  * @param peer Peer identity (can be NULL)
64  * @param key record key string (can be NULL)
65  * @param value record value BLOB (can be NULL)
66  * @param value_size record value size in bytes (set to 0 if value is NULL)
67  * @param expiry time after which the record expires
68  * @param options options specific to the storage operation
69  * @param msg_type message type to be set in header
70  * @return pointer to record message struct
71  */
72 struct GNUNET_MQ_Envelope *
73 PEERSTORE_create_record_mq_envelope (const char *sub_system,
74                                      const struct GNUNET_PeerIdentity *peer,
75                                      const char *key, const void *value,
76                                      size_t value_size,
77                                      struct GNUNET_TIME_Absolute *expiry,
78                                      enum GNUNET_PEERSTORE_StoreOption options,
79                                      uint16_t msg_type);
80
81 /**
82  * Parses a message carrying a record
83  *
84  * @param message the actual message
85  * @return Pointer to record or NULL if error
86  */
87 struct GNUNET_PEERSTORE_Record *
88 PEERSTORE_parse_record_message (const struct GNUNET_MessageHeader *message);
89
90 /**
91  * Free any memory allocated for this record
92  *
93  * @param record
94  */
95 void
96 PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record);