aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/datastore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/datastore_api.c')
-rw-r--r--src/datastore/datastore_api.c126
1 files changed, 103 insertions, 23 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index c8b4f2e91..72f7faed7 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,6 +29,75 @@
29#include "datastore.h" 29#include "datastore.h"
30 30
31/** 31/**
32 * Entry in our priority queue.
33 */
34struct QueueEntry
35{
36
37 /**
38 * This is a linked list.
39 */
40 struct QueueEntry *next;
41
42 /**
43 * This is a linked list.
44 */
45 struct QueueEntry *prev;
46
47 /**
48 * Handle to the master context.
49 */
50 struct GNUNET_DATASTORE_Handle *h;
51
52 /**
53 * Task for timeout signalling.
54 */
55 GNUNET_SCHEDULER_TaskIdentifier task;
56
57 /**
58 * Timeout for the current operation.
59 */
60 struct GNUNET_TIME_Absolute timeout;
61
62 /**
63 * Priority in the queue.
64 */
65 unsigned int priority;
66
67 /**
68 * Maximum allowed length of queue (otherwise
69 * this request should be discarded).
70 */
71 unsigned int max_queue;
72
73 /**
74 * Number of bytes in the request message following
75 * this struct.
76 */
77 uint16_t message_size;
78
79 /**
80 * Has this message been transmitted to the service?
81 * Only ever GNUNET_YES for the head of the queue.
82 */
83 int16_t was_transmitted;
84
85 /**
86 * Response processor (NULL if we are not waiting for a response).
87 * This struct should be used for the closure, function-specific
88 * arguments can be passed via 'client_ctx'.
89 */
90 GNUNET_CLIENT_MessageHandler response_proc;
91
92 /**
93 * Specific context (variable argument that
94 * can be used by the response processor).
95 */
96 void *client_ctx;
97
98};
99
100/**
32 * Handle to the datastore service. Followed 101 * Handle to the datastore service. Followed
33 * by 65536 bytes used for storing messages. 102 * by 65536 bytes used for storing messages.
34 */ 103 */
@@ -51,27 +120,19 @@ struct GNUNET_DATASTORE_Handle
51 struct GNUNET_CLIENT_Connection *client; 120 struct GNUNET_CLIENT_Connection *client;
52 121
53 /** 122 /**
54 * Current response processor (NULL if we are not waiting for a 123 * Current head of priority queue.
55 * response). The specific type depends on the kind of message we
56 * just transmitted.
57 */ 124 */
58 void *response_proc; 125 struct QueueEntry *queue_head;
59
60 /**
61 * Closure for response_proc.
62 */
63 void *response_proc_cls;
64 126
65 /** 127 /**
66 * Timeout for the current operation. 128 * Current tail of priority queue.
67 */ 129 */
68 struct GNUNET_TIME_Absolute timeout; 130 struct QueueEntry *queue_tail;
69 131
70 /** 132 /**
71 * Number of bytes in the message following 133 * Number of entries in the queue.
72 * this struct, 0 if we have no request pending.
73 */ 134 */
74 size_t message_size; 135 unsigned int queue_size;
75 136
76}; 137};
77 138
@@ -84,12 +145,13 @@ struct GNUNET_DATASTORE_Handle
84 * @param sched scheduler to use 145 * @param sched scheduler to use
85 * @return handle to use to access the service 146 * @return handle to use to access the service
86 */ 147 */
87struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct 148struct GNUNET_DATASTORE_Handle *
88 GNUNET_CONFIGURATION_Handle 149GNUNET_DATASTORE_connect (const struct
89 *cfg, 150 GNUNET_CONFIGURATION_Handle
90 struct 151 *cfg,
91 GNUNET_SCHEDULER_Handle 152 struct
92 *sched) 153 GNUNET_SCHEDULER_Handle
154 *sched)
93{ 155{
94 struct GNUNET_CLIENT_Connection *c; 156 struct GNUNET_CLIENT_Connection *c;
95 struct GNUNET_DATASTORE_Handle *h; 157 struct GNUNET_DATASTORE_Handle *h;
@@ -108,10 +170,16 @@ struct GNUNET_DATASTORE_Handle *GNUNET_DATASTORE_connect (const struct
108 170
109/** 171/**
110 * Transmit DROP message to datastore service. 172 * Transmit DROP message to datastore service.
173 *
174 * @param cls the 'struct GNUNET_DATASTORE_Handle'
175 * @param size number of bytes that can be copied to buf
176 * @param buf where to copy the drop message
177 * @return number of bytes written to buf
111 */ 178 */
112static size_t 179static size_t
113transmit_drop (void *cls, 180transmit_drop (void *cls,
114 size_t size, void *buf) 181 size_t size,
182 void *buf)
115{ 183{
116 struct GNUNET_DATASTORE_Handle *h = cls; 184 struct GNUNET_DATASTORE_Handle *h = cls;
117 struct GNUNET_MessageHeader *hdr; 185 struct GNUNET_MessageHeader *hdr;
@@ -142,9 +210,20 @@ transmit_drop (void *cls,
142void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, 210void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
143 int drop) 211 int drop)
144{ 212{
213 struct QueueEntry *qe;
214
145 if (h->client != NULL) 215 if (h->client != NULL)
146 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 216 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
147 h->client = NULL; 217 h->client = NULL;
218 while (NULL != (qe = h->queue_head))
219 {
220 GNUNET_CONTAINER_DLL_remove (h->queue_head,
221 h->queue_tail,
222 qe);
223 if (NULL != qe->response_proc)
224 qe->response_proc (qe, NULL);
225 GNUNET_free (qe);
226 }
148 if (GNUNET_YES == drop) 227 if (GNUNET_YES == drop)
149 { 228 {
150 h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg); 229 h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
@@ -166,6 +245,7 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
166} 245}
167 246
168 247
248#if 0
169/** 249/**
170 * Type of a function to call when we receive a message 250 * Type of a function to call when we receive a message
171 * from the service. This specific function is used 251 * from the service. This specific function is used
@@ -764,6 +844,6 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
764 memcpy (&dm[1], data, size); 844 memcpy (&dm[1], data, size);
765 transmit_for_status (h, cont, cont_cls, timeout); 845 transmit_for_status (h, cont, cont_cls, timeout);
766} 846}
767 847#endif
768 848
769/* end of datastore_api.c */ 849/* end of datastore_api.c */