diff options
Diffstat (limited to 'src/peerstore/peerstore_common.c')
-rw-r--r-- | src/peerstore/peerstore_common.c | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 0e2cc0514..7fceb1ec0 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -30,10 +30,10 @@ | |||
30 | * | 30 | * |
31 | */ | 31 | */ |
32 | void | 32 | void |
33 | PEERSTORE_hash_key (const char *sub_system, | 33 | PEERSTORE_hash_key(const char *sub_system, |
34 | const struct GNUNET_PeerIdentity *peer, | 34 | const struct GNUNET_PeerIdentity *peer, |
35 | const char *key, | 35 | const char *key, |
36 | struct GNUNET_HashCode *ret) | 36 | struct GNUNET_HashCode *ret) |
37 | { | 37 | { |
38 | size_t sssize; | 38 | size_t sssize; |
39 | size_t psize; | 39 | size_t psize; |
@@ -42,19 +42,19 @@ PEERSTORE_hash_key (const char *sub_system, | |||
42 | void *block; | 42 | void *block; |
43 | void *blockptr; | 43 | void *blockptr; |
44 | 44 | ||
45 | sssize = strlen (sub_system) + 1; | 45 | sssize = strlen(sub_system) + 1; |
46 | psize = sizeof (struct GNUNET_PeerIdentity); | 46 | psize = sizeof(struct GNUNET_PeerIdentity); |
47 | ksize = strlen (key) + 1; | 47 | ksize = strlen(key) + 1; |
48 | totalsize = sssize + psize + ksize; | 48 | totalsize = sssize + psize + ksize; |
49 | block = GNUNET_malloc (totalsize); | 49 | block = GNUNET_malloc(totalsize); |
50 | blockptr = block; | 50 | blockptr = block; |
51 | GNUNET_memcpy (blockptr, sub_system, sssize); | 51 | GNUNET_memcpy(blockptr, sub_system, sssize); |
52 | blockptr += sssize; | 52 | blockptr += sssize; |
53 | GNUNET_memcpy (blockptr, peer, psize); | 53 | GNUNET_memcpy(blockptr, peer, psize); |
54 | blockptr += psize; | 54 | blockptr += psize; |
55 | GNUNET_memcpy (blockptr, key, ksize); | 55 | GNUNET_memcpy(blockptr, key, ksize); |
56 | GNUNET_CRYPTO_hash (block, totalsize, ret); | 56 | GNUNET_CRYPTO_hash(block, totalsize, ret); |
57 | GNUNET_free (block); | 57 | GNUNET_free(block); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
@@ -72,14 +72,14 @@ PEERSTORE_hash_key (const char *sub_system, | |||
72 | * @return pointer to record message struct | 72 | * @return pointer to record message struct |
73 | */ | 73 | */ |
74 | struct GNUNET_MQ_Envelope * | 74 | struct GNUNET_MQ_Envelope * |
75 | PEERSTORE_create_record_mq_envelope (const char *sub_system, | 75 | PEERSTORE_create_record_mq_envelope(const char *sub_system, |
76 | const struct GNUNET_PeerIdentity *peer, | 76 | const struct GNUNET_PeerIdentity *peer, |
77 | const char *key, | 77 | const char *key, |
78 | const void *value, | 78 | const void *value, |
79 | size_t value_size, | 79 | size_t value_size, |
80 | struct GNUNET_TIME_Absolute expiry, | 80 | struct GNUNET_TIME_Absolute expiry, |
81 | enum GNUNET_PEERSTORE_StoreOption options, | 81 | enum GNUNET_PEERSTORE_StoreOption options, |
82 | uint16_t msg_type) | 82 | uint16_t msg_type) |
83 | { | 83 | { |
84 | struct StoreRecordMessage *srm; | 84 | struct StoreRecordMessage *srm; |
85 | struct GNUNET_MQ_Envelope *ev; | 85 | struct GNUNET_MQ_Envelope *ev; |
@@ -88,32 +88,32 @@ PEERSTORE_create_record_mq_envelope (const char *sub_system, | |||
88 | size_t msg_size; | 88 | size_t msg_size; |
89 | void *dummy; | 89 | void *dummy; |
90 | 90 | ||
91 | GNUNET_assert (NULL != sub_system); | 91 | GNUNET_assert(NULL != sub_system); |
92 | ss_size = strlen (sub_system) + 1; | 92 | ss_size = strlen(sub_system) + 1; |
93 | if (NULL == key) | 93 | if (NULL == key) |
94 | key_size = 0; | 94 | key_size = 0; |
95 | else | 95 | else |
96 | key_size = strlen (key) + 1; | 96 | key_size = strlen(key) + 1; |
97 | msg_size = ss_size + key_size + value_size; | 97 | msg_size = ss_size + key_size + value_size; |
98 | ev = GNUNET_MQ_msg_extra (srm, msg_size, msg_type); | 98 | ev = GNUNET_MQ_msg_extra(srm, msg_size, msg_type); |
99 | srm->key_size = htons (key_size); | 99 | srm->key_size = htons(key_size); |
100 | srm->expiry = GNUNET_TIME_absolute_hton (expiry); | 100 | srm->expiry = GNUNET_TIME_absolute_hton(expiry); |
101 | if (NULL == peer) | 101 | if (NULL == peer) |
102 | srm->peer_set = htons (GNUNET_NO); | 102 | srm->peer_set = htons(GNUNET_NO); |
103 | else | 103 | else |
104 | { | 104 | { |
105 | srm->peer_set = htons (GNUNET_YES); | 105 | srm->peer_set = htons(GNUNET_YES); |
106 | srm->peer = *peer; | 106 | srm->peer = *peer; |
107 | } | 107 | } |
108 | srm->sub_system_size = htons (ss_size); | 108 | srm->sub_system_size = htons(ss_size); |
109 | srm->value_size = htons (value_size); | 109 | srm->value_size = htons(value_size); |
110 | srm->options = htonl (options); | 110 | srm->options = htonl(options); |
111 | dummy = &srm[1]; | 111 | dummy = &srm[1]; |
112 | GNUNET_memcpy (dummy, sub_system, ss_size); | 112 | GNUNET_memcpy(dummy, sub_system, ss_size); |
113 | dummy += ss_size; | 113 | dummy += ss_size; |
114 | GNUNET_memcpy (dummy, key, key_size); | 114 | GNUNET_memcpy(dummy, key, key_size); |
115 | dummy += key_size; | 115 | dummy += key_size; |
116 | GNUNET_memcpy (dummy, value, value_size); | 116 | GNUNET_memcpy(dummy, value, value_size); |
117 | return ev; | 117 | return ev; |
118 | } | 118 | } |
119 | 119 | ||
@@ -125,7 +125,7 @@ PEERSTORE_create_record_mq_envelope (const char *sub_system, | |||
125 | * @return Pointer to record or NULL if error | 125 | * @return Pointer to record or NULL if error |
126 | */ | 126 | */ |
127 | struct GNUNET_PEERSTORE_Record * | 127 | struct GNUNET_PEERSTORE_Record * |
128 | PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | 128 | PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm) |
129 | { | 129 | { |
130 | struct GNUNET_PEERSTORE_Record *record; | 130 | struct GNUNET_PEERSTORE_Record *record; |
131 | uint16_t req_size; | 131 | uint16_t req_size; |
@@ -134,39 +134,39 @@ PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | |||
134 | uint16_t value_size; | 134 | uint16_t value_size; |
135 | char *dummy; | 135 | char *dummy; |
136 | 136 | ||
137 | req_size = ntohs (srm->header.size) - sizeof (*srm); | 137 | req_size = ntohs(srm->header.size) - sizeof(*srm); |
138 | ss_size = ntohs (srm->sub_system_size); | 138 | ss_size = ntohs(srm->sub_system_size); |
139 | key_size = ntohs (srm->key_size); | 139 | key_size = ntohs(srm->key_size); |
140 | value_size = ntohs (srm->value_size); | 140 | value_size = ntohs(srm->value_size); |
141 | if (ss_size + key_size + value_size != req_size) | 141 | if (ss_size + key_size + value_size != req_size) |
142 | { | 142 | { |
143 | GNUNET_break (0); | 143 | GNUNET_break(0); |
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | record = GNUNET_new (struct GNUNET_PEERSTORE_Record); | 146 | record = GNUNET_new(struct GNUNET_PEERSTORE_Record); |
147 | if (GNUNET_YES == ntohs (srm->peer_set)) | 147 | if (GNUNET_YES == ntohs(srm->peer_set)) |
148 | { | 148 | { |
149 | record->peer = srm->peer; | 149 | record->peer = srm->peer; |
150 | } | 150 | } |
151 | record->expiry = GNUNET_TIME_absolute_ntoh (srm->expiry); | 151 | record->expiry = GNUNET_TIME_absolute_ntoh(srm->expiry); |
152 | dummy = (char *) &srm[1]; | 152 | dummy = (char *)&srm[1]; |
153 | if (ss_size > 0) | 153 | if (ss_size > 0) |
154 | { | 154 | { |
155 | record->sub_system = GNUNET_strdup (dummy); | 155 | record->sub_system = GNUNET_strdup(dummy); |
156 | dummy += ss_size; | 156 | dummy += ss_size; |
157 | } | 157 | } |
158 | if (key_size > 0) | 158 | if (key_size > 0) |
159 | { | 159 | { |
160 | record->key = GNUNET_strdup (dummy); | 160 | record->key = GNUNET_strdup(dummy); |
161 | dummy += key_size; | 161 | dummy += key_size; |
162 | } | 162 | } |
163 | if (value_size > 0) | 163 | if (value_size > 0) |
164 | { | 164 | { |
165 | record->value = GNUNET_malloc (value_size); | 165 | record->value = GNUNET_malloc(value_size); |
166 | GNUNET_memcpy (record->value, | 166 | GNUNET_memcpy(record->value, |
167 | dummy, | 167 | dummy, |
168 | value_size); | 168 | value_size); |
169 | } | 169 | } |
170 | record->value_size = value_size; | 170 | record->value_size = value_size; |
171 | return record; | 171 | return record; |
172 | } | 172 | } |
@@ -178,16 +178,16 @@ PEERSTORE_parse_record_message (const struct StoreRecordMessage *srm) | |||
178 | * @param record | 178 | * @param record |
179 | */ | 179 | */ |
180 | void | 180 | void |
181 | PEERSTORE_destroy_record (struct GNUNET_PEERSTORE_Record *record) | 181 | PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record) |
182 | { | 182 | { |
183 | if (NULL != record->sub_system) | 183 | if (NULL != record->sub_system) |
184 | GNUNET_free (record->sub_system); | 184 | GNUNET_free(record->sub_system); |
185 | if (NULL != record->key) | 185 | if (NULL != record->key) |
186 | GNUNET_free (record->key); | 186 | GNUNET_free(record->key); |
187 | if (NULL != record->value) | 187 | if (NULL != record->value) |
188 | { | 188 | { |
189 | GNUNET_free (record->value); | 189 | GNUNET_free(record->value); |
190 | record->value = 0; | 190 | record->value = 0; |
191 | } | 191 | } |
192 | GNUNET_free (record); | 192 | GNUNET_free(record); |
193 | } | 193 | } |