diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 16:45:43 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 16:45:43 +0000 |
commit | 3c9e8b1b0f7f83f27fefb02bd67b481c67cad0c8 (patch) | |
tree | 525ae2f8cec03f298783aa693d465f789171cf51 /src/peerstore | |
parent | aeaf5c97d7d115d99f30e86be66c622b7a6ebf4f (diff) | |
download | gnunet-3c9e8b1b0f7f83f27fefb02bd67b481c67cad0c8.tar.gz gnunet-3c9e8b1b0f7f83f27fefb02bd67b481c67cad0c8.zip |
peerstore API now uses MQ
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 12 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 178 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.c | 63 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.h | 44 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api.c | 2 |
5 files changed, 214 insertions, 85 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index be5394ff5..50af4342c 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -87,7 +87,7 @@ handle_client_disconnect (void *cls, | |||
87 | * @param sub_system name of the GNUnet sub system responsible | 87 | * @param sub_system name of the GNUnet sub system responsible |
88 | * @param value stored value | 88 | * @param value stored value |
89 | * @param size size of stored value | 89 | * @param size size of stored value |
90 | */ | 90 | * |
91 | int record_iterator(void *cls, | 91 | int record_iterator(void *cls, |
92 | const char *sub_system, | 92 | const char *sub_system, |
93 | const struct GNUNET_PeerIdentity *peer, | 93 | const struct GNUNET_PeerIdentity *peer, |
@@ -108,7 +108,7 @@ int record_iterator(void *cls, | |||
108 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | 108 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); |
109 | GNUNET_SERVER_transmit_context_append_message(tc, (const struct GNUNET_MessageHeader *)srm); | 109 | GNUNET_SERVER_transmit_context_append_message(tc, (const struct GNUNET_MessageHeader *)srm); |
110 | return GNUNET_YES; | 110 | return GNUNET_YES; |
111 | } | 111 | }*/ |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Handle an iterate request from client | 114 | * Handle an iterate request from client |
@@ -116,7 +116,7 @@ int record_iterator(void *cls, | |||
116 | * @param cls unused | 116 | * @param cls unused |
117 | * @param client identification of the client | 117 | * @param client identification of the client |
118 | * @param message the actual message | 118 | * @param message the actual message |
119 | */ | 119 | * |
120 | void handle_iterate (void *cls, | 120 | void handle_iterate (void *cls, |
121 | struct GNUNET_SERVER_Client *client, | 121 | struct GNUNET_SERVER_Client *client, |
122 | const struct GNUNET_MessageHeader *message) | 122 | const struct GNUNET_MessageHeader *message) |
@@ -147,7 +147,7 @@ void handle_iterate (void *cls, | |||
147 | { | 147 | { |
148 | 148 | ||
149 | } | 149 | } |
150 | } | 150 | }*/ |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Handle a store request from client | 153 | * Handle a store request from client |
@@ -190,7 +190,7 @@ void handle_store (void *cls, | |||
190 | record->key, | 190 | record->key, |
191 | record->value, | 191 | record->value, |
192 | record->value_size, | 192 | record->value_size, |
193 | record->expiry)) | 193 | *record->expiry)) |
194 | { | 194 | { |
195 | response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK; | 195 | response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK; |
196 | } | 196 | } |
@@ -220,7 +220,7 @@ run (void *cls, | |||
220 | { | 220 | { |
221 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 221 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
222 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, | 222 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, |
223 | {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, | 223 | // {&handle_iterate, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, 0}, |
224 | {NULL, NULL, 0, 0} | 224 | {NULL, NULL, 0, 0} |
225 | }; | 225 | }; |
226 | char *database; | 226 | char *database; |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index aa798e653..323ba45d0 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -50,6 +50,21 @@ struct GNUNET_PEERSTORE_Handle | |||
50 | */ | 50 | */ |
51 | struct GNUNET_CLIENT_Connection *client; | 51 | struct GNUNET_CLIENT_Connection *client; |
52 | 52 | ||
53 | /** | ||
54 | * Message queue | ||
55 | */ | ||
56 | struct GNUNET_MQ_Handle *mq; | ||
57 | |||
58 | /** | ||
59 | * Head of active STORE requests. | ||
60 | */ | ||
61 | struct GNUNET_PEERSTORE_StoreContext *store_head; | ||
62 | |||
63 | /** | ||
64 | * Tail of active STORE requests. | ||
65 | */ | ||
66 | struct GNUNET_PEERSTORE_StoreContext *store_tail; | ||
67 | |||
53 | }; | 68 | }; |
54 | 69 | ||
55 | /** | 70 | /** |
@@ -57,6 +72,15 @@ struct GNUNET_PEERSTORE_Handle | |||
57 | */ | 72 | */ |
58 | struct GNUNET_PEERSTORE_StoreContext | 73 | struct GNUNET_PEERSTORE_StoreContext |
59 | { | 74 | { |
75 | /** | ||
76 | * Kept in a DLL. | ||
77 | */ | ||
78 | struct GNUNET_PEERSTORE_StoreContext *next; | ||
79 | |||
80 | /** | ||
81 | * Kept in a DLL. | ||
82 | */ | ||
83 | struct GNUNET_PEERSTORE_StoreContext *prev; | ||
60 | 84 | ||
61 | /** | 85 | /** |
62 | * Handle to the PEERSTORE service. | 86 | * Handle to the PEERSTORE service. |
@@ -64,6 +88,11 @@ struct GNUNET_PEERSTORE_StoreContext | |||
64 | struct GNUNET_PEERSTORE_Handle *h; | 88 | struct GNUNET_PEERSTORE_Handle *h; |
65 | 89 | ||
66 | /** | 90 | /** |
91 | * MQ Envelope with store request message | ||
92 | */ | ||
93 | struct GNUNET_MQ_Envelope *ev; | ||
94 | |||
95 | /** | ||
67 | * Continuation called with service response | 96 | * Continuation called with service response |
68 | */ | 97 | */ |
69 | GNUNET_PEERSTORE_Continuation cont; | 98 | GNUNET_PEERSTORE_Continuation cont; |
@@ -73,9 +102,27 @@ struct GNUNET_PEERSTORE_StoreContext | |||
73 | */ | 102 | */ |
74 | void *cont_cls; | 103 | void *cont_cls; |
75 | 104 | ||
105 | /** | ||
106 | * #GNUNET_YES / #GNUNET_NO | ||
107 | * if sent, cannot be canceled | ||
108 | */ | ||
109 | int request_sent; | ||
110 | |||
76 | }; | 111 | }; |
77 | 112 | ||
78 | /******************************************************************************/ | 113 | /******************************************************************************/ |
114 | /******************* DECLARATIONS *********************/ | ||
115 | /******************************************************************************/ | ||
116 | |||
117 | /** | ||
118 | * When a response for store request is received | ||
119 | * | ||
120 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | ||
121 | * @param msg message received, NULL on timeout or fatal error | ||
122 | */ | ||
123 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg); | ||
124 | |||
125 | /******************************************************************************/ | ||
79 | /******************* CONNECTION FUNCTIONS *********************/ | 126 | /******************* CONNECTION FUNCTIONS *********************/ |
80 | /******************************************************************************/ | 127 | /******************************************************************************/ |
81 | 128 | ||
@@ -85,7 +132,7 @@ struct GNUNET_PEERSTORE_StoreContext | |||
85 | * @param h handle to the service | 132 | * @param h handle to the service |
86 | */ | 133 | */ |
87 | static void | 134 | static void |
88 | reconnect (struct GNUNET_PEERSTORE_Handle *h) | 135 | reconnect (struct GNUNET_PEERSTORE_Handle *h) //FIXME: MQ friendly |
89 | { | 136 | { |
90 | 137 | ||
91 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); | 138 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); |
@@ -98,6 +145,12 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
98 | 145 | ||
99 | } | 146 | } |
100 | 147 | ||
148 | static void | ||
149 | handle_client_error (void *cls, enum GNUNET_MQ_Error error) //FIXME: implement | ||
150 | { | ||
151 | //struct GNUNET_PEERSTORE_Handle *h = cls; | ||
152 | } | ||
153 | |||
101 | /** | 154 | /** |
102 | * Connect to the PEERSTORE service. | 155 | * Connect to the PEERSTORE service. |
103 | * | 156 | * |
@@ -106,15 +159,30 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) | |||
106 | struct GNUNET_PEERSTORE_Handle * | 159 | struct GNUNET_PEERSTORE_Handle * |
107 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 160 | GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
108 | { | 161 | { |
109 | struct GNUNET_CLIENT_Connection *client; | ||
110 | struct GNUNET_PEERSTORE_Handle *h; | 162 | struct GNUNET_PEERSTORE_Handle *h; |
163 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { | ||
164 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)}, | ||
165 | {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL, sizeof(struct GNUNET_MessageHeader)}, | ||
166 | GNUNET_MQ_HANDLERS_END | ||
167 | }; | ||
111 | 168 | ||
112 | client = GNUNET_CLIENT_connect ("peerstore", cfg); | ||
113 | if(NULL == client) | ||
114 | return NULL; | ||
115 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); | 169 | h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); |
116 | h->client = client; | 170 | h->client = GNUNET_CLIENT_connect ("peerstore", cfg); |
171 | if(NULL == h->client) | ||
172 | { | ||
173 | GNUNET_free(h); | ||
174 | return NULL; | ||
175 | } | ||
117 | h->cfg = cfg; | 176 | h->cfg = cfg; |
177 | h->mq = GNUNET_MQ_queue_for_connection_client(h->client, | ||
178 | mq_handlers, | ||
179 | &handle_client_error, | ||
180 | h); | ||
181 | if(NULL == h->mq) | ||
182 | { | ||
183 | GNUNET_free(h); | ||
184 | return NULL; | ||
185 | } | ||
118 | LOG(GNUNET_ERROR_TYPE_DEBUG, "New connection created\n"); | 186 | LOG(GNUNET_ERROR_TYPE_DEBUG, "New connection created\n"); |
119 | return h; | 187 | return h; |
120 | } | 188 | } |
@@ -128,6 +196,11 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
128 | void | 196 | void |
129 | GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | 197 | GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) |
130 | { | 198 | { |
199 | if(NULL != h->mq) | ||
200 | { | ||
201 | GNUNET_MQ_destroy(h->mq); | ||
202 | h->mq = NULL; | ||
203 | } | ||
131 | if (NULL != h->client) | 204 | if (NULL != h->client) |
132 | { | 205 | { |
133 | GNUNET_CLIENT_disconnect (h->client); | 206 | GNUNET_CLIENT_disconnect (h->client); |
@@ -139,7 +212,7 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | |||
139 | 212 | ||
140 | 213 | ||
141 | /******************************************************************************/ | 214 | /******************************************************************************/ |
142 | /******************* ADD FUNCTIONS *********************/ | 215 | /******************* STORE FUNCTIONS *********************/ |
143 | /******************************************************************************/ | 216 | /******************************************************************************/ |
144 | 217 | ||
145 | /** | 218 | /** |
@@ -148,41 +221,77 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h) | |||
148 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | 221 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' |
149 | * @param msg message received, NULL on timeout or fatal error | 222 | * @param msg message received, NULL on timeout or fatal error |
150 | */ | 223 | */ |
151 | void store_response_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | 224 | void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg) //FIXME: MQ friendly |
152 | { | 225 | { |
153 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | 226 | struct GNUNET_PEERSTORE_Handle *h = cls; |
227 | struct GNUNET_PEERSTORE_StoreContext *sc; | ||
154 | uint16_t msg_type; | 228 | uint16_t msg_type; |
229 | GNUNET_PEERSTORE_Continuation cont; | ||
230 | void *cont_cls; | ||
155 | 231 | ||
156 | if(NULL == sc->cont) | 232 | sc = h->store_head; |
233 | if(NULL == sc) | ||
234 | { | ||
235 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unexpected store response, this should not happen.\n"); | ||
236 | reconnect(h); | ||
157 | return; | 237 | return; |
158 | if(NULL == msg) | 238 | } |
239 | cont = sc->cont; | ||
240 | cont_cls = sc->cont_cls; | ||
241 | GNUNET_CONTAINER_DLL_remove(h->store_head, h->store_tail, sc); | ||
242 | GNUNET_free(sc); | ||
243 | if(NULL == msg) /* Connection error */ | ||
159 | { | 244 | { |
160 | sc->cont(sc->cont_cls, GNUNET_SYSERR); | 245 | if(NULL != cont) |
161 | reconnect(sc->h); | 246 | cont(cont_cls, GNUNET_SYSERR); |
247 | reconnect(h); | ||
162 | return; | 248 | return; |
163 | } | 249 | } |
164 | msg_type = ntohs(msg->type); | 250 | if(NULL != cont) /* Run continuation */ |
165 | if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK == msg_type) | ||
166 | sc->cont(sc->cont_cls, GNUNET_OK); | ||
167 | else if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL == msg_type) | ||
168 | sc->cont(sc->cont_cls, GNUNET_SYSERR); | ||
169 | else | ||
170 | { | 251 | { |
171 | LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid response from `PEERSTORE' service.\n"); | 252 | msg_type = ntohs(msg->type); |
172 | sc->cont(sc->cont_cls, GNUNET_SYSERR); | 253 | if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK == msg_type) |
254 | cont(cont_cls, GNUNET_OK); | ||
255 | else if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL == msg_type) | ||
256 | cont(cont_cls, GNUNET_SYSERR); | ||
173 | } | 257 | } |
174 | 258 | ||
175 | } | 259 | } |
176 | 260 | ||
177 | /** | 261 | /** |
262 | * Callback after MQ envelope is sent | ||
263 | * | ||
264 | * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' | ||
265 | */ | ||
266 | void store_request_sent (void *cls) | ||
267 | { | ||
268 | struct GNUNET_PEERSTORE_StoreContext *sc = cls; | ||
269 | |||
270 | sc->request_sent = GNUNET_YES; | ||
271 | } | ||
272 | |||
273 | /** | ||
178 | * Cancel a store request | 274 | * Cancel a store request |
179 | * | 275 | * |
180 | * @param sc Store request context | 276 | * @param sc Store request context |
181 | */ | 277 | */ |
182 | void | 278 | void |
183 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 279 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) //FIXME: MQ friendly |
184 | { | 280 | { |
185 | sc->cont = NULL; | 281 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
282 | "Canceling store request.\n"); | ||
283 | if(GNUNET_NO == sc->request_sent) | ||
284 | { | ||
285 | if(NULL != sc->ev) | ||
286 | GNUNET_MQ_discard(sc->ev); | ||
287 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); | ||
288 | GNUNET_free(sc); | ||
289 | } | ||
290 | else | ||
291 | { /* request already sent, will have to wait for response */ | ||
292 | sc->cont = NULL; | ||
293 | } | ||
294 | |||
186 | } | 295 | } |
187 | 296 | ||
188 | /** | 297 | /** |
@@ -209,29 +318,28 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
209 | GNUNET_PEERSTORE_Continuation cont, | 318 | GNUNET_PEERSTORE_Continuation cont, |
210 | void *cont_cls) | 319 | void *cont_cls) |
211 | { | 320 | { |
321 | struct GNUNET_MQ_Envelope *ev; | ||
212 | struct GNUNET_PEERSTORE_StoreContext *sc; | 322 | struct GNUNET_PEERSTORE_StoreContext *sc; |
213 | struct StoreRecordMessage *srm; | ||
214 | 323 | ||
215 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 324 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
216 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", | 325 | "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", |
217 | size, sub_system, GNUNET_i2s (peer), key); | 326 | size, sub_system, GNUNET_i2s (peer), key); |
218 | sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); | 327 | ev = PEERSTORE_create_record_mq_envelope(sub_system, |
219 | sc->cont = cont; | ||
220 | sc->cont_cls = cont_cls; | ||
221 | sc->h = h; | ||
222 | srm = PEERSTORE_create_record_message(sub_system, | ||
223 | peer, | 328 | peer, |
224 | key, | 329 | key, |
225 | value, | 330 | value, |
226 | size, | 331 | size, |
227 | expiry, | 332 | expiry, |
228 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 333 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); |
229 | GNUNET_CLIENT_transmit_and_get_response(h->client, | 334 | GNUNET_MQ_send(h->mq, ev); |
230 | (const struct GNUNET_MessageHeader *)srm, | 335 | GNUNET_MQ_notify_sent(ev, &store_request_sent, ev); |
231 | GNUNET_TIME_UNIT_FOREVER_REL, | 336 | sc = GNUNET_new(struct GNUNET_PEERSTORE_StoreContext); |
232 | GNUNET_YES, | 337 | sc->ev = ev; |
233 | &store_response_receiver, | 338 | sc->cont = cont; |
234 | sc); | 339 | sc->cont_cls = cont_cls; |
340 | sc->h = h; | ||
341 | sc->request_sent = GNUNET_NO; | ||
342 | GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc); | ||
235 | return sc; | 343 | return sc; |
236 | 344 | ||
237 | } | 345 | } |
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 6b8b80985..6c91d9802 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -36,7 +36,7 @@ | |||
36 | * @param expiry absolute time after which the record expires | 36 | * @param expiry absolute time after which the record expires |
37 | * @param msg_type message type to be set in header | 37 | * @param msg_type message type to be set in header |
38 | * @return pointer to record message struct | 38 | * @return pointer to record message struct |
39 | */ | 39 | * |
40 | struct StoreRecordMessage * | 40 | struct StoreRecordMessage * |
41 | PEERSTORE_create_record_message(const char *sub_system, | 41 | PEERSTORE_create_record_message(const char *sub_system, |
42 | const struct GNUNET_PeerIdentity *peer, | 42 | const struct GNUNET_PeerIdentity *peer, |
@@ -83,6 +83,64 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
83 | memcpy(dummy, value, value_size); | 83 | memcpy(dummy, value, value_size); |
84 | return srm; | 84 | return srm; |
85 | 85 | ||
86 | }*/ | ||
87 | |||
88 | /** | ||
89 | * Creates a MQ envelope for a single record | ||
90 | * | ||
91 | * @param sub_system sub system string | ||
92 | * @param peer Peer identity (can be NULL) | ||
93 | * @param key record key string (can be NULL) | ||
94 | * @param value record value BLOB (can be NULL) | ||
95 | * @param value_size record value size in bytes (set to 0 if value is NULL) | ||
96 | * @param expiry time after which the record expires | ||
97 | * @param msg_type message type to be set in header | ||
98 | * @return pointer to record message struct | ||
99 | */ | ||
100 | struct GNUNET_MQ_Envelope * | ||
101 | PEERSTORE_create_record_mq_envelope(const char *sub_system, | ||
102 | const struct GNUNET_PeerIdentity *peer, | ||
103 | const char *key, | ||
104 | const void *value, | ||
105 | size_t value_size, | ||
106 | struct GNUNET_TIME_Absolute expiry, | ||
107 | uint16_t msg_type) | ||
108 | { | ||
109 | struct StoreRecordMessage *srm; | ||
110 | struct GNUNET_MQ_Envelope *ev; | ||
111 | size_t ss_size; | ||
112 | size_t key_size; | ||
113 | size_t msg_size; | ||
114 | void *dummy; | ||
115 | |||
116 | ss_size = strlen(sub_system) + 1; | ||
117 | if(NULL == key) | ||
118 | key_size = 0; | ||
119 | else | ||
120 | key_size = strlen(key) + 1; | ||
121 | msg_size = ss_size + | ||
122 | key_size + | ||
123 | value_size; | ||
124 | ev = GNUNET_MQ_msg_extra(srm, msg_size, msg_type); | ||
125 | srm->key_size = htons(key_size); | ||
126 | srm->expiry = expiry; | ||
127 | if(NULL == peer) | ||
128 | srm->peer_set = htons(GNUNET_NO); | ||
129 | else | ||
130 | { | ||
131 | srm->peer_set = htons(GNUNET_YES); | ||
132 | srm->peer = *peer; | ||
133 | } | ||
134 | srm->sub_system_size = htons(ss_size); | ||
135 | srm->value_size = htons(value_size); | ||
136 | dummy = &srm[1]; | ||
137 | memcpy(dummy, sub_system, ss_size); | ||
138 | dummy += ss_size; | ||
139 | memcpy(dummy, key, key_size); | ||
140 | dummy += key_size; | ||
141 | memcpy(dummy, value, value_size); | ||
142 | |||
143 | return ev; | ||
86 | } | 144 | } |
87 | 145 | ||
88 | /** | 146 | /** |
@@ -118,7 +176,8 @@ PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message) | |||
118 | record->peer = GNUNET_new(struct GNUNET_PeerIdentity); | 176 | record->peer = GNUNET_new(struct GNUNET_PeerIdentity); |
119 | memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity)); | 177 | memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity)); |
120 | } | 178 | } |
121 | record->expiry = srm->expiry; | 179 | record->expiry = GNUNET_new(struct GNUNET_TIME_Absolute); |
180 | *(record->expiry) = srm->expiry; | ||
122 | dummy = (char *)&srm[1]; | 181 | dummy = (char *)&srm[1]; |
123 | if(ss_size > 0) | 182 | if(ss_size > 0) |
124 | { | 183 | { |
diff --git a/src/peerstore/peerstore_common.h b/src/peerstore/peerstore_common.h index 4795edbb1..a15302ed4 100644 --- a/src/peerstore/peerstore_common.h +++ b/src/peerstore/peerstore_common.h | |||
@@ -27,45 +27,7 @@ | |||
27 | #include "peerstore.h" | 27 | #include "peerstore.h" |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * PEERSTORE single record | 30 | * Creates a MQ envelope for a 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 | * Expiry time of record | ||
62 | */ | ||
63 | struct GNUNET_TIME_Absolute expiry; | ||
64 | |||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * Creates a record message ready to be sent | ||
69 | * | 31 | * |
70 | * @param sub_system sub system string | 32 | * @param sub_system sub system string |
71 | * @param peer Peer identity (can be NULL) | 33 | * @param peer Peer identity (can be NULL) |
@@ -76,8 +38,8 @@ struct GNUNET_PEERSTORE_Record | |||
76 | * @param msg_type message type to be set in header | 38 | * @param msg_type message type to be set in header |
77 | * @return pointer to record message struct | 39 | * @return pointer to record message struct |
78 | */ | 40 | */ |
79 | struct StoreRecordMessage * | 41 | struct GNUNET_MQ_Envelope * |
80 | PEERSTORE_create_record_message(const char *sub_system, | 42 | PEERSTORE_create_record_mq_envelope(const char *sub_system, |
81 | const struct GNUNET_PeerIdentity *peer, | 43 | const struct GNUNET_PeerIdentity *peer, |
82 | const char *key, | 44 | const char *key, |
83 | const void *value, | 45 | const void *value, |
diff --git a/src/peerstore/test_peerstore_api.c b/src/peerstore/test_peerstore_api.c index 781187865..74f3e70db 100644 --- a/src/peerstore/test_peerstore_api.c +++ b/src/peerstore/test_peerstore_api.c | |||
@@ -58,7 +58,7 @@ run (void *cls, | |||
58 | "peerstore-test-key", | 58 | "peerstore-test-key", |
59 | val, | 59 | val, |
60 | val_size, | 60 | val_size, |
61 | GNUNET_TIME_UNIT_FOREVER_REL, | 61 | GNUNET_TIME_UNIT_FOREVER_ABS, |
62 | &store_cont, | 62 | &store_cont, |
63 | NULL); | 63 | NULL); |
64 | 64 | ||