93fb9931b02ea83b737e67f5d6ea24b12b9520bc
[oweals/gnunet.git] / src / peerstore / peerstore_common.h
1 /*
2       This file is part of GNUnet
3       (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., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file peerstore/peerstore_common.h
23  * @brief Helper peerstore functions
24  * @author Omar Tarabai
25  */
26
27 #include "peerstore.h"
28
29 /**
30  * PEERSTORE single record
31  */
32 struct GNUNET_PEERSTORE_Record
33 {
34
35   /**
36    * Responsible sub system string
37    */
38   char *sub_system;
39
40   /**
41    * Peer Identity
42    */
43   struct GNUNET_PeerIdentity *peer;
44
45   /**
46    * Record key string
47    */
48   char *key;
49
50   /**
51    * Record value BLOB
52    */
53   void *value;
54
55   /**
56    * Size of value BLOB
57    */
58   size_t value_size;
59
60   /**
61    * Lifetime of record
62    */
63   struct GNUNET_TIME_Relative lifetime;
64
65 };
66
67 /**
68  * Creates a record message ready to be sent
69  *
70  * @param sub_system sub system string
71  * @param peer Peer identity (can be NULL)
72  * @param key record key string (can be NULL)
73  * @param value record value BLOB (can be NULL)
74  * @param value_size record value size in bytes (set to 0 if value is NULL)
75  * @param lifetime relative time after which the record expires
76  * @return pointer to record message struct
77  */
78 struct StoreRecordMessage *
79 PEERSTORE_create_record_message(const char *sub_system,
80     const struct GNUNET_PeerIdentity *peer,
81     const char *key,
82     const void *value,
83     size_t value_size,
84     struct GNUNET_TIME_Relative lifetime);
85
86 /**
87  * Parses a message carrying a record
88  *
89  * @param message the actual message
90  * @return Pointer to record or NULL if error
91  */
92 struct GNUNET_PEERSTORE_Record *
93 PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message);