16fdfd1b7b25a7fbeb998d1473355a9c6536929e
[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
16 /**
17  * @file peerstore/peerstore_common.h
18  * @brief Helper peerstore functions
19  * @author Omar Tarabai
20  */
21 #include "platform.h"
22 #include "peerstore.h"
23
24 /**
25  * Creates a hash of the given key combination
26  *
27  */
28 void
29 PEERSTORE_hash_key (const char *sub_system,
30                     const struct GNUNET_PeerIdentity *peer,
31                     const char *key,
32                     struct GNUNET_HashCode *ret);
33
34
35 /**
36  * Creates a MQ envelope for a single record
37  *
38  * @param sub_system sub system string
39  * @param peer Peer identity (can be NULL)
40  * @param key record key string (can be NULL)
41  * @param value record value BLOB (can be NULL)
42  * @param value_size record value size in bytes (set to 0 if value is NULL)
43  * @param expiry time after which the record expires
44  * @param options options specific to the storage operation
45  * @param msg_type message type to be set in header
46  * @return pointer to record message struct
47  */
48 struct GNUNET_MQ_Envelope *
49 PEERSTORE_create_record_mq_envelope (const char *sub_system,
50                                      const struct GNUNET_PeerIdentity *peer,
51                                      const char *key,
52                                      const void *value,
53                                      size_t value_size,
54                                      struct GNUNET_TIME_Absolute expiry,
55                                      enum GNUNET_PEERSTORE_StoreOption options,
56                                      uint16_t msg_type);
57
58
59 /**
60  * Parses a message carrying a record
61  *
62  * @param srm the actual message
63  * @return Pointer to record or NULL on error
64  */
65 struct GNUNET_PEERSTORE_Record *
66 PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm);
67
68
69 /**
70  * Free any memory allocated for this record
71  *
72  * @param record
73  */
74 void
75 PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record);
76
77 /* end of peerstore_common.h */