aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/datastore_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-06-15 04:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2009-06-15 04:46:35 +0000
commitf90483fc8b2a7ee72c0c5f82e714b3de1dd26a71 (patch)
treeefa70facdba2a31f4e5bdfbef5f87b85aa807e10 /src/datastore/datastore_api.c
parent17b95ebf7226cc5ca4ee7d90ff0de874b0dc7576 (diff)
downloadgnunet-f90483fc8b2a7ee72c0c5f82e714b3de1dd26a71.tar.gz
gnunet-f90483fc8b2a7ee72c0c5f82e714b3de1dd26a71.zip
stuff
Diffstat (limited to 'src/datastore/datastore_api.c')
-rw-r--r--src/datastore/datastore_api.c98
1 files changed, 95 insertions, 3 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index cc563ba79..95ae25f03 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -22,17 +22,88 @@
22 * @file datastore/datastore_api.c 22 * @file datastore/datastore_api.c
23 * @brief Management for the datastore for files stored on a GNUnet node 23 * @brief Management for the datastore for files stored on a GNUnet node
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 *
26 * TODO:
27 * 1) clarify API (wrt. efficient UPDATE of priority/expiration after GET)
28 * 2) implement INIT
29 * 3) implement SIZE handling (=> API impact?)
30 * 4) implement DROP
31 * 5) implement PUT
32 * 6) implement GET
33 * 7) implement GET_RANDOM
34 * 8) implement REMOVE
25 */ 35 */
26 36
27#include "platform.h" 37#include "platform.h"
28#include "gnunet_datastore_service.h" 38#include "gnunet_datastore_service.h"
29#include "datastore.h" 39#include "datastore.h"
30 40
41
42struct MessageQueue
43{
44 /**
45 * This is a linked list.
46 */
47 struct MessageQueue *next;
48
49 /**
50 * Message we will transmit (allocated at the end
51 * of this struct; do not free!).
52 */
53 struct GNUNET_MessageHeader *msg;
54
55 /**
56 * Function to call on the response.
57 */
58 GNUNET_CLIENT_MessageHandler response_processor;
59
60 /**
61 * Closure for response_processor.
62 */
63 void *response_processor_cls;
64
65};
66
67
31/** 68/**
32 * Handle to the datastore service. 69 * Handle to the datastore service.
33 */ 70 */
34struct GNUNET_DATASTORE_Handle 71struct GNUNET_DATASTORE_Handle
35{ 72{
73
74 /**
75 * Current connection to the datastore service.
76 */
77 struct GNUNET_CLIENT_Connection *client;
78
79 /**
80 * Linked list of messages waiting to be transmitted.
81 */
82 struct MessageQueue *messages;
83
84 /**
85 * Current response processor (NULL if we are not waiting
86 * for a response). Largely used only to know if we have
87 * a 'receive' request pending.
88 */
89 GNUNET_CLIENT_MessageHandler response_proc;
90
91 /**
92 * Closure for response_proc.
93 */
94 void *response_proc_cls;
95
96 /**
97 * Current size of the datastore (cached).
98 */
99 unsigned long long size;
100
101 /**
102 * Set to GNUNET_YES if we have received the size
103 * from the datastore.
104 */
105 int ready;
106
36}; 107};
37 108
38 109
@@ -50,7 +121,16 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
50 GNUNET_SCHEDULER_Handle 121 GNUNET_SCHEDULER_Handle
51 *sched) 122 *sched)
52{ 123{
53 return NULL; 124 struct GNUNET_CLIENT_Connection *c;
125 struct GNUNET_DATASTORE_Handle *h;
126
127 c = GNUNET_CLIENT_connect (sched, "datastore", cfg);
128 if (c == NULL)
129 return NULL; /* oops */
130 h = GNUNET_malloc (sizeof(struct GNUNET_DATASTORE_Handle));
131 h->client = c;
132 /* FIXME: send 'join' request */
133 return h;
54} 134}
55 135
56 136
@@ -64,6 +144,12 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (struct
64void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, 144void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
65 int drop) 145 int drop)
66{ 146{
147 if (GNUNET_YES == drop)
148 {
149 /* FIXME: send 'drop' request */
150 }
151 GNUNET_CLIENT_disconnect (h->client);
152 GNUNET_free (h);
67} 153}
68 154
69 155
@@ -74,7 +160,9 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
74 */ 160 */
75unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h) 161unsigned long long GNUNET_DATASTORE_size (struct GNUNET_DATASTORE_Handle *h)
76{ 162{
77 return 0; 163 if (GNUNET_YES != h->ready)
164 return (unsigned long long) -1LL;
165 return h->size;
78} 166}
79 167
80 168
@@ -129,7 +217,7 @@ GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
129 * Get a random value from the datastore. 217 * Get a random value from the datastore.
130 * 218 *
131 * @param h handle to the datastore 219 * @param h handle to the datastore
132 * @param iter function to call on each matching value; 220 * @param iter function to call on a random value; it
133 * will be called exactly once; if no values 221 * will be called exactly once; if no values
134 * are available, the value will be NULL. 222 * are available, the value will be NULL.
135 * @param iter_cls closure for iter 223 * @param iter_cls closure for iter
@@ -138,6 +226,10 @@ void
138GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h, 226GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
139 GNUNET_DATASTORE_Iterator iter, void *iter_cls) 227 GNUNET_DATASTORE_Iterator iter, void *iter_cls)
140{ 228{
229 static struct GNUNET_TIME_Absolute zero;
230
231 iter (iter_cls,
232 NULL, 0, NULL, 0, 0, 0, zero, 0);
141} 233}
142 234
143 235