diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-28 17:08:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-28 17:08:07 +0000 |
commit | 3e719ecc0f2252bfb01ce6ee057e6d63dd4b7037 (patch) | |
tree | 613635d211366eda3ac83eccee08f49e78e125e5 /src/datastore/datastore_api.c | |
parent | a913b5f73410eb3f0568670046d3ecf3b233744f (diff) | |
download | gnunet-3e719ecc0f2252bfb01ce6ee057e6d63dd4b7037.tar.gz gnunet-3e719ecc0f2252bfb01ce6ee057e6d63dd4b7037.zip |
airplane hackery
Diffstat (limited to 'src/datastore/datastore_api.c')
-rw-r--r-- | src/datastore/datastore_api.c | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 968e09b20..3b9e22a3a 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c | |||
@@ -113,6 +113,32 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct | |||
113 | 113 | ||
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Transmit DROP message to Database service. | ||
117 | */ | ||
118 | static size_t | ||
119 | transmit_drop (void *cls, | ||
120 | size_t size, void *buf) | ||
121 | { | ||
122 | struct GNUNET_DATASTORE_Handle *h = cls; | ||
123 | struct GNUNET_MessageHeader *hdr; | ||
124 | |||
125 | if (buf == NULL) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
128 | _("Failed to transmit request to drop database.\n")); | ||
129 | GNUNET_DATASTORE_disconnect (h, GNUNET_NO); | ||
130 | return 0; | ||
131 | } | ||
132 | GNUNET_assert (size >= sizeof(struct GNUNET_MessageHeader)); | ||
133 | hdr = buf; | ||
134 | hdr->size = htons(sizeof(struct GNUNET_MessageHeader)); | ||
135 | hdr->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DROP)); | ||
136 | GNUNET_DATASTORE_disconnect (h, GNUNET_NO); | ||
137 | return sizeof(struct GNUNET_MessageHeader); | ||
138 | } | ||
139 | |||
140 | |||
141 | /** | ||
116 | * Disconnect from the datastore service (and free | 142 | * Disconnect from the datastore service (and free |
117 | * associated resources). | 143 | * associated resources). |
118 | * | 144 | * |
@@ -124,7 +150,14 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, | |||
124 | { | 150 | { |
125 | if (GNUNET_YES == drop) | 151 | if (GNUNET_YES == drop) |
126 | { | 152 | { |
127 | /* FIXME: send 'drop' request */ | 153 | if (NULL != |
154 | GNUNET_CLIENT_notify_transmit_ready (h->client, | ||
155 | sizeof(struct GNUNET_MessageHeader), | ||
156 | GNUNET_TIME_UNIT_MINUTES, | ||
157 | &transmit_drop, | ||
158 | h)) | ||
159 | return; | ||
160 | GNUNET_break (0); | ||
128 | } | 161 | } |
129 | GNUNET_CLIENT_disconnect (h->client); | 162 | GNUNET_CLIENT_disconnect (h->client); |
130 | GNUNET_free (h); | 163 | GNUNET_free (h); |
@@ -132,6 +165,45 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, | |||
132 | 165 | ||
133 | 166 | ||
134 | /** | 167 | /** |
168 | * The closure is followed by the data message. | ||
169 | */ | ||
170 | struct PutClosure | ||
171 | { | ||
172 | struct GNUNET_DATASTORE_Handle *h; | ||
173 | GNUNET_DATASTORE_ContinuationWithStatus cont; | ||
174 | void *cont_cls; | ||
175 | }; | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Transmit PUT message to Database service. | ||
180 | */ | ||
181 | static size_t | ||
182 | transmit_put (void *cls, | ||
183 | size_t size, void *buf) | ||
184 | { | ||
185 | struct PutClosure *pc = cls; | ||
186 | struct DataMessage *dm; | ||
187 | uint16_t msize; | ||
188 | |||
189 | if (buf == NULL) | ||
190 | { | ||
191 | pc->cont (pc->cont_cls, GNUNET_SYSERR, | ||
192 | gettext_noop ("Error transmitting `PUT' message to datastore service.\n")); | ||
193 | GNUNET_free (pc); | ||
194 | return 0; | ||
195 | } | ||
196 | dm = (struct DataMessage*) &pc[1]; | ||
197 | msize = ntohs(dm->size); | ||
198 | GNUNET_assert (msize <= size); | ||
199 | memcpy (buf, dm, msize); | ||
200 | /* FIXME: wait for response from datastore, then | ||
201 | call our continuation! */ | ||
202 | return msize; | ||
203 | } | ||
204 | |||
205 | |||
206 | /** | ||
135 | * Store an item in the datastore. If the item is already present, | 207 | * Store an item in the datastore. If the item is already present, |
136 | * the priorities are summed up and the higher expiration time and | 208 | * the priorities are summed up and the higher expiration time and |
137 | * lower anonymity level is used. | 209 | * lower anonymity level is used. |
@@ -144,6 +216,7 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, | |||
144 | * @param priority priority of the content | 216 | * @param priority priority of the content |
145 | * @param anonymity anonymity-level for the content | 217 | * @param anonymity anonymity-level for the content |
146 | * @param expiration expiration time for the content | 218 | * @param expiration expiration time for the content |
219 | * @param timeout timeout for the operation | ||
147 | * @param cont continuation to call when done | 220 | * @param cont continuation to call when done |
148 | * @param cont_cls closure for cont | 221 | * @param cont_cls closure for cont |
149 | */ | 222 | */ |
@@ -157,10 +230,41 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
157 | uint32_t priority, | 230 | uint32_t priority, |
158 | uint32_t anonymity, | 231 | uint32_t anonymity, |
159 | struct GNUNET_TIME_Absolute expiration, | 232 | struct GNUNET_TIME_Absolute expiration, |
233 | struct GNUNET_TIME_Relative timeout, | ||
160 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 234 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
161 | void *cont_cls) | 235 | void *cont_cls) |
162 | { | 236 | { |
163 | cont (cont_cls, GNUNET_SYSERR, "not implemented"); | 237 | struct PutClosure *pc; |
238 | struct DataMessage *dm; | ||
239 | |||
240 | pc = GNUNET_malloc (sizeof(struct PutClosure) + | ||
241 | sizeof(struct DataMessage) + | ||
242 | size); | ||
243 | dm = (struct DataMessage*) &pc[1]; | ||
244 | pc->h = h; | ||
245 | pc->cont = cont; | ||
246 | pc->cont_cls = cont_cls; | ||
247 | dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT); | ||
248 | dm->header.size = htons(sizeof(struct DataMessage) + size); | ||
249 | dm->rid = htonl(rid); | ||
250 | dm->size = htonl(size); | ||
251 | dm->type = htonl(type); | ||
252 | dm->priority = htonl(priority); | ||
253 | dm->anonymity = htonl(anonymity); | ||
254 | dm->uid = GNUNET_htonll(0); | ||
255 | dm->expiration = GNUNET_htonll(expiration); | ||
256 | dm->key = *key; | ||
257 | memcpy (&dm[1], data, size); | ||
258 | if (NULL == GNUNET_CLIENT_notify_transmit_ready (h->client, | ||
259 | sizeof(struct DataMessage) + size, | ||
260 | timeout, | ||
261 | &transmit_put, | ||
262 | pc)) | ||
263 | { | ||
264 | GNUNET_break (0); | ||
265 | cont (cont_cls, GNUNET_SYSERR, | ||
266 | gettext_noop ("Not ready to transmit request to datastore service")); | ||
267 | } | ||
164 | } | 268 | } |
165 | 269 | ||
166 | 270 | ||