GNUnet 0.21.0
peerstore_common.h File Reference

Helper peerstore functions. More...

#include "platform.h"
#include "peerstore.h"
Include dependency graph for peerstore_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void PEERSTORE_hash_key (const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, struct GNUNET_HashCode *ret)
 Creates a hash of the given key combination. More...
 
struct GNUNET_MQ_EnvelopePEERSTORE_create_record_mq_envelope (uint32_t rid, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t value_size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, uint16_t msg_type)
 Creates a MQ envelope for a single record. More...
 
struct GNUNET_PEERSTORE_RecordPEERSTORE_parse_record_message (const struct PeerstoreRecordMessage *srm)
 Parses a message carrying a record. More...
 
void PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record)
 Free any memory allocated for this record. More...
 

Detailed Description

Helper peerstore functions.

Author
Omar Tarabai

Definition in file peerstore_common.h.

Function Documentation

◆ PEERSTORE_hash_key()

void PEERSTORE_hash_key ( const char *  sub_system,
const struct GNUNET_PeerIdentity peer,
const char *  key,
struct GNUNET_HashCode ret 
)

Creates a hash of the given key combination.

Definition at line 34 of file peerstore_common.c.

38{
39 size_t sssize;
40 size_t psize;
41 size_t ksize;
42 size_t totalsize;
43 void *block;
44 void *blockptr;
45
46 sssize = strlen (sub_system) + 1;
47 psize = sizeof(struct GNUNET_PeerIdentity);
48 ksize = strlen (key) + 1;
49 totalsize = sssize + psize + ksize;
50 block = GNUNET_malloc (totalsize);
51 blockptr = block;
52 GNUNET_memcpy (blockptr, sub_system, sssize);
53 blockptr += sssize;
54 GNUNET_memcpy (blockptr, peer, psize);
55 blockptr += psize;
56 GNUNET_memcpy (blockptr, key, ksize);
57 GNUNET_CRYPTO_hash (block, totalsize, ret);
58 GNUNET_free (block);
59}
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
The identity of the host (wraps the signing key of the peer).

References GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, key, and ret.

Here is the call graph for this function:

◆ PEERSTORE_create_record_mq_envelope()

struct GNUNET_MQ_Envelope * PEERSTORE_create_record_mq_envelope ( uint32_t  rid,
const char *  sub_system,
const struct GNUNET_PeerIdentity peer,
const char *  key,
const void *  value,
size_t  value_size,
struct GNUNET_TIME_Absolute  expiry,
enum GNUNET_PEERSTORE_StoreOption  options,
uint16_t  msg_type 
)

Creates a MQ envelope for a single record.

Parameters
ridrequest ID
sub_systemsub system string
peerPeer identity (can be NULL)
keyrecord key string (can be NULL)
valuerecord value BLOB (can be NULL)
value_sizerecord value size in bytes (set to 0 if value is NULL)
expirytime after which the record expires
optionsoptions specific to the storage operation
msg_typemessage type to be set in header
Returns
pointer to record message struct

Definition at line 63 of file peerstore_common.c.

72{
73 struct PeerstoreRecordMessage *srm;
74 struct GNUNET_MQ_Envelope *ev;
75 size_t ss_size;
76 size_t key_size;
77 size_t msg_size;
78 void *dummy;
79
80 GNUNET_assert (NULL != sub_system);
81 ss_size = strlen (sub_system) + 1;
82 if (NULL == key)
83 key_size = 0;
84 else
85 key_size = strlen (key) + 1;
86 msg_size = ss_size + key_size + value_size;
87 ev = GNUNET_MQ_msg_extra (srm, msg_size, msg_type);
88 srm->key_size = htons (key_size);
89 srm->expiry = GNUNET_TIME_absolute_hton (expiry);
90 GNUNET_assert (NULL != peer);
91 srm->peer = *peer;
92 srm->rid = htons (rid);
93 srm->sub_system_size = htons (ss_size);
94 srm->value_size = htons (value_size);
95 srm->options = htonl (options);
96 dummy = &srm[1];
97 GNUNET_memcpy (dummy, sub_system, ss_size);
98 dummy += ss_size;
99 GNUNET_memcpy (dummy, key, key_size);
100 dummy += key_size;
101 GNUNET_memcpy (dummy, value, value_size);
102 return ev;
103}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * value
Value of the record to add/remove.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
Message carrying a PEERSTORE record message.
Definition: peerstore.h:38
uint16_t value_size
Size of value blob Allocated at position 2 after this struct.
Definition: peerstore.h:75
uint16_t key_size
Size of the key string Allocated at position 1 after this struct.
Definition: peerstore.h:69
struct GNUNET_TIME_AbsoluteNBO expiry
Expiry time of entry.
Definition: peerstore.h:52
uint32_t rid
Request id.
Definition: peerstore.h:57
uint32_t options
Options, needed only in case of a store operation.
Definition: peerstore.h:63
uint16_t sub_system_size
Size of the sub_system string Allocated at position 0 after this struct.
Definition: peerstore.h:82
struct GNUNET_PeerIdentity peer
Peer Identity.
Definition: peerstore.h:47

References dummy, PeerstoreRecordMessage::expiry, GNUNET_assert, GNUNET_memcpy, GNUNET_MQ_msg_extra, GNUNET_TIME_absolute_hton(), key, PeerstoreRecordMessage::key_size, options, PeerstoreRecordMessage::options, PeerstoreRecordMessage::peer, PeerstoreRecordMessage::rid, PeerstoreRecordMessage::sub_system_size, value, and PeerstoreRecordMessage::value_size.

Referenced by GNUNET_PEERSTORE_store(), iterate_proc(), monitor_iterate_cb(), and watch_notifier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PEERSTORE_parse_record_message()

struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message ( const struct PeerstoreRecordMessage srm)

Parses a message carrying a record.

Parameters
srmthe actual message
Returns
Pointer to record or NULL on error

Definition at line 107 of file peerstore_common.c.

108{
110 uint16_t req_size;
111 uint16_t ss_size;
112 uint16_t key_size;
113 uint16_t value_size;
114 char *dummy;
115
116 req_size = ntohs (srm->header.size) - sizeof(*srm);
117 ss_size = ntohs (srm->sub_system_size);
118 key_size = ntohs (srm->key_size);
119 value_size = ntohs (srm->value_size);
120 if (ss_size + key_size + value_size != req_size)
121 {
122 GNUNET_break (0);
123 return NULL;
124 }
126 record->peer = srm->peer;
127 record->expiry = GNUNET_TIME_absolute_ntoh (srm->expiry);
128 dummy = (char *) &srm[1];
129 if (ss_size > 0)
130 {
131 record->sub_system = GNUNET_strdup (dummy);
132 dummy += ss_size;
133 }
134 if (key_size > 0)
135 {
136 record->key = GNUNET_strdup (dummy);
137 dummy += key_size;
138 }
139 if (value_size > 0)
140 {
142 GNUNET_memcpy (record->value,
143 dummy,
144 value_size);
145 }
146 record->value_size = value_size;
147 return record;
148}
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Single PEERSTORE record.
size_t value_size
Size of value BLOB.
struct GNUNET_MessageHeader header
GNUnet message header.
Definition: peerstore.h:42

References dummy, PeerstoreRecordMessage::expiry, GNUNET_break, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_strdup, GNUNET_TIME_absolute_ntoh(), PeerstoreRecordMessage::header, PeerstoreRecordMessage::key_size, PeerstoreRecordMessage::peer, record(), GNUNET_MessageHeader::size, PeerstoreRecordMessage::sub_system_size, GNUNET_PEERSTORE_Record::value_size, and PeerstoreRecordMessage::value_size.

Referenced by check_store(), handle_iterate_result(), handle_result(), and handle_store().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PEERSTORE_destroy_record()

void PEERSTORE_destroy_record ( struct GNUNET_PEERSTORE_Record record)

Free any memory allocated for this record.

Parameters
record

Definition at line 157 of file peerstore_common.c.

158{
159 if (NULL != record->sub_system)
160 GNUNET_free (record->sub_system);
161 if (NULL != record->key)
162 GNUNET_free (record->key);
163 if (NULL != record->value)
164 {
165 GNUNET_free (record->value);
166 record->value = 0;
167 }
169}

References GNUNET_free, and record().

Referenced by check_store(), handle_iterate_result(), handle_result(), handle_store(), and store_record_continuation().

Here is the call graph for this function:
Here is the caller graph for this function: