-Merge branch 'master' of ssh://gnunet.org/gnunet into gsoc2018/rest_api
[oweals/gnunet.git] / src / peerstore / peerstore_common.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2013-2016 GNUnet e.V.
4
5       GNUnet is free software: you can redistribute it and/or modify it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your 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       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /**
20  * @file peerstore/peerstore_common.h
21  * @brief Helper peerstore functions
22  * @author Omar Tarabai
23  */
24 #include "platform.h"
25 #include "peerstore.h"
26
27 /**
28  * Creates a hash of the given key combination
29  *
30  */
31 void
32 PEERSTORE_hash_key (const char *sub_system,
33                     const struct GNUNET_PeerIdentity *peer,
34                     const char *key,
35                     struct GNUNET_HashCode *ret);
36
37
38 /**
39  * Creates a MQ envelope for a single record
40  *
41  * @param sub_system sub system string
42  * @param peer Peer identity (can be NULL)
43  * @param key record key string (can be NULL)
44  * @param value record value BLOB (can be NULL)
45  * @param value_size record value size in bytes (set to 0 if value is NULL)
46  * @param expiry time after which the record expires
47  * @param options options specific to the storage operation
48  * @param msg_type message type to be set in header
49  * @return pointer to record message struct
50  */
51 struct GNUNET_MQ_Envelope *
52 PEERSTORE_create_record_mq_envelope (const char *sub_system,
53                                      const struct GNUNET_PeerIdentity *peer,
54                                      const char *key,
55                                      const void *value,
56                                      size_t value_size,
57                                      struct GNUNET_TIME_Absolute expiry,
58                                      enum GNUNET_PEERSTORE_StoreOption options,
59                                      uint16_t msg_type);
60
61
62 /**
63  * Parses a message carrying a record
64  *
65  * @param srm the actual message
66  * @return Pointer to record or NULL on error
67  */
68 struct GNUNET_PEERSTORE_Record *
69 PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm);
70
71
72 /**
73  * Free any memory allocated for this record
74  *
75  * @param record
76  */
77 void
78 PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record);
79
80 /* end of peerstore_common.h */