diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 12:54:18 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-05-16 12:54:18 +0000 |
commit | aeaf5c97d7d115d99f30e86be66c622b7a6ebf4f (patch) | |
tree | 13e3f037af1fc84188b91e6054153714ad3f631a /src | |
parent | 369811cfb47a51f240c7c4872e29c6eccd21fb0c (diff) | |
download | gnunet-aeaf5c97d7d115d99f30e86be66c622b7a6ebf4f.tar.gz gnunet-aeaf5c97d7d115d99f30e86be66c622b7a6ebf4f.zip |
towards peerstore iterate
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_peerstore_plugin.h | 18 | ||||
-rw-r--r-- | src/include/gnunet_peerstore_service.h | 20 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 58 | ||||
-rw-r--r-- | src/peerstore/peerstore.h | 4 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 8 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.c | 12 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.h | 10 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_sqlite.c | 12 |
8 files changed, 106 insertions, 36 deletions
diff --git a/src/include/gnunet_peerstore_plugin.h b/src/include/gnunet_peerstore_plugin.h index ce473b508..e9563b508 100644 --- a/src/include/gnunet_peerstore_plugin.h +++ b/src/include/gnunet_peerstore_plugin.h | |||
@@ -39,22 +39,6 @@ extern "C" | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Function called by for each matching record. | ||
43 | * | ||
44 | * @param cls closure | ||
45 | * @param peer peer identity | ||
46 | * @param sub_system name of the GNUnet sub system responsible | ||
47 | * @param value stored value | ||
48 | * @param size size of stored value | ||
49 | */ | ||
50 | typedef void (*GNUNET_PEERSTORE_RecordIterator) (void *cls, | ||
51 | const char *sub_system, | ||
52 | const struct GNUNET_PeerIdentity *peer, | ||
53 | const char *key, | ||
54 | const void *value, | ||
55 | size_t size); | ||
56 | |||
57 | /** | ||
58 | * @brief struct returned by the initialization function of the plugin | 42 | * @brief struct returned by the initialization function of the plugin |
59 | */ | 43 | */ |
60 | struct GNUNET_PEERSTORE_PluginFunctions | 44 | struct GNUNET_PEERSTORE_PluginFunctions |
@@ -103,7 +87,7 @@ struct GNUNET_PEERSTORE_PluginFunctions | |||
103 | const char *sub_system, | 87 | const char *sub_system, |
104 | const struct GNUNET_PeerIdentity *peer, | 88 | const struct GNUNET_PeerIdentity *peer, |
105 | const char *key, | 89 | const char *key, |
106 | GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls); | 90 | GNUNET_PEERSTORE_Processor iter, void *iter_cls); |
107 | 91 | ||
108 | }; | 92 | }; |
109 | 93 | ||
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h index d8b8935cc..6fd059961 100644 --- a/src/include/gnunet_peerstore_service.h +++ b/src/include/gnunet_peerstore_service.h | |||
@@ -56,6 +56,24 @@ struct GNUNET_PEERSTORE_StoreContext; | |||
56 | typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success); | 56 | typedef void (*GNUNET_PEERSTORE_Continuation)(void *cls, int success); |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Function called by for each matching record. | ||
60 | * | ||
61 | * @param cls closure | ||
62 | * @param peer peer identity | ||
63 | * @param sub_system name of the GNUnet sub system responsible | ||
64 | * @param value stored value | ||
65 | * @param size size of stored value | ||
66 | * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop | ||
67 | */ | ||
68 | typedef int (*GNUNET_PEERSTORE_Processor) (void *cls, | ||
69 | const char *sub_system, | ||
70 | const struct GNUNET_PeerIdentity *peer, | ||
71 | const char *key, | ||
72 | const void *value, | ||
73 | size_t size, | ||
74 | struct GNUNET_TIME_Absolute expiry); | ||
75 | |||
76 | /** | ||
59 | * Connect to the PEERSTORE service. | 77 | * Connect to the PEERSTORE service. |
60 | * | 78 | * |
61 | * @return NULL on error | 79 | * @return NULL on error |
@@ -91,7 +109,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
91 | const char *key, | 109 | const char *key, |
92 | const void *value, | 110 | const void *value, |
93 | size_t size, | 111 | size_t size, |
94 | struct GNUNET_TIME_Relative lifetime, | 112 | struct GNUNET_TIME_Absolute expiry, |
95 | GNUNET_PEERSTORE_Continuation cont, | 113 | GNUNET_PEERSTORE_Continuation cont, |
96 | void *cont_cls); | 114 | void *cont_cls); |
97 | 115 | ||
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index ad4d68335..be5394ff5 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -80,6 +80,37 @@ handle_client_disconnect (void *cls, | |||
80 | } | 80 | } |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Function called by for each matching record. | ||
84 | * | ||
85 | * @param cls closure | ||
86 | * @param peer peer identity | ||
87 | * @param sub_system name of the GNUnet sub system responsible | ||
88 | * @param value stored value | ||
89 | * @param size size of stored value | ||
90 | */ | ||
91 | int record_iterator(void *cls, | ||
92 | const char *sub_system, | ||
93 | const struct GNUNET_PeerIdentity *peer, | ||
94 | const char *key, | ||
95 | const void *value, | ||
96 | size_t size, | ||
97 | struct GNUNET_TIME_Absolute expiry) | ||
98 | { | ||
99 | struct GNUNET_SERVER_TransmitContext *tc = cls; | ||
100 | struct StoreRecordMessage *srm; | ||
101 | |||
102 | srm = PEERSTORE_create_record_message(sub_system, | ||
103 | peer, | ||
104 | key, | ||
105 | value, | ||
106 | size, | ||
107 | expiry, | ||
108 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE); | ||
109 | GNUNET_SERVER_transmit_context_append_message(tc, (const struct GNUNET_MessageHeader *)srm); | ||
110 | return GNUNET_YES; | ||
111 | } | ||
112 | |||
113 | /** | ||
83 | * Handle an iterate request from client | 114 | * Handle an iterate request from client |
84 | * | 115 | * |
85 | * @param cls unused | 116 | * @param cls unused |
@@ -90,7 +121,32 @@ void handle_iterate (void *cls, | |||
90 | struct GNUNET_SERVER_Client *client, | 121 | struct GNUNET_SERVER_Client *client, |
91 | const struct GNUNET_MessageHeader *message) | 122 | const struct GNUNET_MessageHeader *message) |
92 | { | 123 | { |
124 | struct GNUNET_PEERSTORE_Record *record; | ||
125 | struct GNUNET_SERVER_TransmitContext *tc; | ||
93 | 126 | ||
127 | record = PEERSTORE_parse_record_message(message); | ||
128 | if(NULL == record) | ||
129 | { | ||
130 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed iterate request from client\n"); | ||
131 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
132 | return; | ||
133 | } | ||
134 | if(NULL == record->sub_system) | ||
135 | { | ||
136 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sub system not supplied in client iterate request\n"); | ||
137 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
138 | return; | ||
139 | } | ||
140 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
141 | if(GNUNET_OK == db->iterate_records(db->cls, | ||
142 | record->sub_system, | ||
143 | record->peer, | ||
144 | record->key, | ||
145 | &record_iterator, | ||
146 | tc)) | ||
147 | { | ||
148 | |||
149 | } | ||
94 | } | 150 | } |
95 | 151 | ||
96 | /** | 152 | /** |
@@ -134,7 +190,7 @@ void handle_store (void *cls, | |||
134 | record->key, | 190 | record->key, |
135 | record->value, | 191 | record->value, |
136 | record->value_size, | 192 | record->value_size, |
137 | GNUNET_TIME_relative_to_absolute(record->lifetime))) | 193 | record->expiry)) |
138 | { | 194 | { |
139 | response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK; | 195 | response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK; |
140 | } | 196 | } |
diff --git a/src/peerstore/peerstore.h b/src/peerstore/peerstore.h index 521c5c11b..7c6e6bdbc 100644 --- a/src/peerstore/peerstore.h +++ b/src/peerstore/peerstore.h | |||
@@ -71,9 +71,9 @@ struct StoreRecordMessage | |||
71 | size_t value_size; | 71 | size_t value_size; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Lifetime of entry | 74 | * Expiry time of entry |
75 | */ | 75 | */ |
76 | struct GNUNET_TIME_Relative lifetime; | 76 | struct GNUNET_TIME_Absolute expiry; |
77 | 77 | ||
78 | }; | 78 | }; |
79 | 79 | ||
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 68c171d52..aa798e653 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -194,7 +194,7 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | |||
194 | * @param key entry key | 194 | * @param key entry key |
195 | * @param value entry value BLOB | 195 | * @param value entry value BLOB |
196 | * @param size size of 'value' | 196 | * @param size size of 'value' |
197 | * @param lifetime relative time after which the entry is (possibly) deleted | 197 | * @param expiry absolute time after which the entry is (possibly) deleted |
198 | * @param cont Continuation function after the store request is processed | 198 | * @param cont Continuation function after the store request is processed |
199 | * @param cont_cls Closure for 'cont' | 199 | * @param cont_cls Closure for 'cont' |
200 | */ | 200 | */ |
@@ -205,7 +205,7 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
205 | const char *key, | 205 | const char *key, |
206 | const void *value, | 206 | const void *value, |
207 | size_t size, | 207 | size_t size, |
208 | struct GNUNET_TIME_Relative lifetime, | 208 | struct GNUNET_TIME_Absolute expiry, |
209 | GNUNET_PEERSTORE_Continuation cont, | 209 | GNUNET_PEERSTORE_Continuation cont, |
210 | void *cont_cls) | 210 | void *cont_cls) |
211 | { | 211 | { |
@@ -224,7 +224,8 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
224 | key, | 224 | key, |
225 | value, | 225 | value, |
226 | size, | 226 | size, |
227 | lifetime); | 227 | expiry, |
228 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | ||
228 | GNUNET_CLIENT_transmit_and_get_response(h->client, | 229 | GNUNET_CLIENT_transmit_and_get_response(h->client, |
229 | (const struct GNUNET_MessageHeader *)srm, | 230 | (const struct GNUNET_MessageHeader *)srm, |
230 | GNUNET_TIME_UNIT_FOREVER_REL, | 231 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -235,5 +236,4 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, | |||
235 | 236 | ||
236 | } | 237 | } |
237 | 238 | ||
238 | |||
239 | /* end of peerstore_api.c */ | 239 | /* end of peerstore_api.c */ |
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index f8c6862de..6b8b80985 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -33,7 +33,8 @@ | |||
33 | * @param key record key string (can be NULL) | 33 | * @param key record key string (can be NULL) |
34 | * @param value record value BLOB (can be NULL) | 34 | * @param value record value BLOB (can be NULL) |
35 | * @param value_size record value size in bytes (set to 0 if value is NULL) | 35 | * @param value_size record value size in bytes (set to 0 if value is NULL) |
36 | * @param lifetime relative 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 | * @return pointer to record message struct | 38 | * @return pointer to record message struct |
38 | */ | 39 | */ |
39 | struct StoreRecordMessage * | 40 | struct StoreRecordMessage * |
@@ -42,7 +43,8 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
42 | const char *key, | 43 | const char *key, |
43 | const void *value, | 44 | const void *value, |
44 | size_t value_size, | 45 | size_t value_size, |
45 | struct GNUNET_TIME_Relative lifetime) | 46 | struct GNUNET_TIME_Absolute expiry, |
47 | uint16_t msg_type) | ||
46 | { | 48 | { |
47 | struct StoreRecordMessage *srm; | 49 | struct StoreRecordMessage *srm; |
48 | size_t ss_size; | 50 | size_t ss_size; |
@@ -61,9 +63,9 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
61 | value_size; | 63 | value_size; |
62 | srm = GNUNET_malloc(request_size); | 64 | srm = GNUNET_malloc(request_size); |
63 | srm->header.size = htons(request_size); | 65 | srm->header.size = htons(request_size); |
64 | srm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); | 66 | srm->header.type = htons(msg_type); |
65 | srm->key_size = htons(key_size); | 67 | srm->key_size = htons(key_size); |
66 | srm->lifetime = lifetime; | 68 | srm->expiry = expiry; |
67 | if(NULL == peer) | 69 | if(NULL == peer) |
68 | srm->peer_set = htons(GNUNET_NO); | 70 | srm->peer_set = htons(GNUNET_NO); |
69 | else | 71 | else |
@@ -116,7 +118,7 @@ PEERSTORE_parse_record_message(const struct GNUNET_MessageHeader *message) | |||
116 | record->peer = GNUNET_new(struct GNUNET_PeerIdentity); | 118 | record->peer = GNUNET_new(struct GNUNET_PeerIdentity); |
117 | memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity)); | 119 | memcpy(record->peer, &srm->peer, sizeof(struct GNUNET_PeerIdentity)); |
118 | } | 120 | } |
119 | record->lifetime = srm->lifetime; | 121 | record->expiry = srm->expiry; |
120 | dummy = (char *)&srm[1]; | 122 | dummy = (char *)&srm[1]; |
121 | if(ss_size > 0) | 123 | if(ss_size > 0) |
122 | { | 124 | { |
diff --git a/src/peerstore/peerstore_common.h b/src/peerstore/peerstore_common.h index 93fb9931b..4795edbb1 100644 --- a/src/peerstore/peerstore_common.h +++ b/src/peerstore/peerstore_common.h | |||
@@ -58,9 +58,9 @@ struct GNUNET_PEERSTORE_Record | |||
58 | size_t value_size; | 58 | size_t value_size; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Lifetime of record | 61 | * Expiry time of record |
62 | */ | 62 | */ |
63 | struct GNUNET_TIME_Relative lifetime; | 63 | struct GNUNET_TIME_Absolute expiry; |
64 | 64 | ||
65 | }; | 65 | }; |
66 | 66 | ||
@@ -72,7 +72,8 @@ struct GNUNET_PEERSTORE_Record | |||
72 | * @param key record key string (can be NULL) | 72 | * @param key record key string (can be NULL) |
73 | * @param value record value BLOB (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) | 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 | 75 | * @param expiry time after which the record expires |
76 | * @param msg_type message type to be set in header | ||
76 | * @return pointer to record message struct | 77 | * @return pointer to record message struct |
77 | */ | 78 | */ |
78 | struct StoreRecordMessage * | 79 | struct StoreRecordMessage * |
@@ -81,7 +82,8 @@ PEERSTORE_create_record_message(const char *sub_system, | |||
81 | const char *key, | 82 | const char *key, |
82 | const void *value, | 83 | const void *value, |
83 | size_t value_size, | 84 | size_t value_size, |
84 | struct GNUNET_TIME_Relative lifetime); | 85 | struct GNUNET_TIME_Absolute expiry, |
86 | uint16_t msg_type); | ||
85 | 87 | ||
86 | /** | 88 | /** |
87 | * Parses a message carrying a record | 89 | * Parses a message carrying a record |
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index c44914f43..c5eabac2d 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c | |||
@@ -116,7 +116,7 @@ peerstore_sqlite_iterate_records (void *cls, | |||
116 | const char *sub_system, | 116 | const char *sub_system, |
117 | const struct GNUNET_PeerIdentity *peer, | 117 | const struct GNUNET_PeerIdentity *peer, |
118 | const char *key, | 118 | const char *key, |
119 | GNUNET_PEERSTORE_RecordIterator iter, void *iter_cls) | 119 | GNUNET_PEERSTORE_Processor iter, void *iter_cls) |
120 | { | 120 | { |
121 | struct Plugin *plugin = cls; | 121 | struct Plugin *plugin = cls; |
122 | sqlite3_stmt *stmt; | 122 | sqlite3_stmt *stmt; |
@@ -127,6 +127,7 @@ peerstore_sqlite_iterate_records (void *cls, | |||
127 | const char *ret_key; | 127 | const char *ret_key; |
128 | const void *ret_value; | 128 | const void *ret_value; |
129 | size_t ret_value_size; | 129 | size_t ret_value_size; |
130 | struct GNUNET_TIME_Absolute ret_expiry; | ||
130 | 131 | ||
131 | if(NULL == peer && NULL == key) | 132 | if(NULL == peer && NULL == key) |
132 | { | 133 | { |
@@ -170,8 +171,15 @@ peerstore_sqlite_iterate_records (void *cls, | |||
170 | ret_key = (const char *)sqlite3_column_text(stmt, 2); | 171 | ret_key = (const char *)sqlite3_column_text(stmt, 2); |
171 | ret_value = sqlite3_column_blob(stmt, 3); | 172 | ret_value = sqlite3_column_blob(stmt, 3); |
172 | ret_value_size = sqlite3_column_bytes(stmt, 3); | 173 | ret_value_size = sqlite3_column_bytes(stmt, 3); |
174 | ret_expiry.abs_value_us = (uint64_t)sqlite3_column_int64(stmt, 4); | ||
173 | if (NULL != iter) | 175 | if (NULL != iter) |
174 | iter (iter_cls, ret_sub_system, ret_peer, ret_key, ret_value, ret_value_size); | 176 | iter (iter_cls, |
177 | ret_sub_system, | ||
178 | ret_peer, | ||
179 | ret_key, | ||
180 | ret_value, | ||
181 | ret_value_size, | ||
182 | ret_expiry); | ||
175 | } | 183 | } |
176 | if (SQLITE_DONE != sret) | 184 | if (SQLITE_DONE != sret) |
177 | { | 185 | { |