aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.h
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-07-10 01:31:13 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-07-10 01:31:13 +0000
commit6b8400966a5e6c2194785b3a33f91b748cfa7b7b (patch)
tree0dafa7ba24c7a6dbb852fdedfd1822cd1e4835c0 /src/set/gnunet-service-set.h
parent084cb3e09007ef50a3d9bd29514c8ec455249633 (diff)
downloadgnunet-6b8400966a5e6c2194785b3a33f91b748cfa7b7b.tar.gz
gnunet-6b8400966a5e6c2194785b3a33f91b748cfa7b7b.zip
- set service working
- set profiler
Diffstat (limited to 'src/set/gnunet-service-set.h')
-rw-r--r--src/set/gnunet-service-set.h342
1 files changed, 139 insertions, 203 deletions
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index 74cbf584e..6ababe92f 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -38,67 +38,25 @@
38#include "set.h" 38#include "set.h"
39 39
40 40
41/* FIXME: cfuchs */
42struct IntersectionState;
43
44
45/* FIXME: cfuchs */
46struct IntersectionOperation;
47
48
49/**
50 * Extra state required for set union.
51 */
52struct UnionState;
53
54/** 41/**
55 * State of a union operation being evaluated. 42 * Implementation-specific set state.
43 * Used as opaque pointer, and specified further
44 * in the respective implementation.
56 */ 45 */
57struct UnionEvaluateOperation; 46struct SetState;
58
59 47
60 48
61/** 49/**
62 * A set that supports a specific operation 50 * Implementation-specific set operation.
63 * with other peers. 51 * Used as opaque pointer, and specified further
52 * in the respective implementation.
64 */ 53 */
65struct Set 54struct OperationState;
66{
67 /**
68 * Client that owns the set.
69 * Only one client may own a set.
70 */
71 struct GNUNET_SERVER_Client *client;
72
73 /**
74 * Message queue for the client
75 */
76 struct GNUNET_MQ_Handle *client_mq;
77 55
78 /**
79 * Type of operation supported for this set
80 */
81 uint32_t operation; // use enum from API
82 56
83 /** 57/* forward declarations */
84 * Sets are held in a doubly linked list. 58struct Set;
85 */ 59struct TunnelContext;
86 struct Set *next;
87
88 /**
89 * Sets are held in a doubly linked list.
90 */
91 struct Set *prev;
92
93 /**
94 * Appropriate state for each type of
95 * operation.
96 */
97 union {
98 struct IntersectionState *i;
99 struct UnionState *u;
100 } state;
101};
102 60
103 61
104/** 62/**
@@ -146,96 +104,169 @@ struct OperationSpecification
146 104
147 105
148/** 106/**
149 * A listener is inhabited by a client, and 107 * Signature of functions that create the implementation-specific
150 * waits for evaluation requests from remote peers. 108 * state for a set supporting a specific operation.
109 *
110 * @return a set state specific to the supported operation
111 */
112typedef struct SetState *(*CreateImpl) (void);
113
114
115/**
116 * Signature of functions that implement the add/remove functionality
117 * for a set supporting a specific operation.
118 *
119 * @param set implementation-specific set state
120 * @param msg element message from the client
121 */
122typedef void (*AddRemoveImpl) (struct SetState *state, const struct GNUNET_SET_Element *element);
123
124
125/**
126 * Signature of functions that handle disconnection
127 * of the remote peer.
128 *
129 * @param op the set operation, contains implementation-specific data
130 */
131typedef void (*PeerDisconnectImpl) (struct OperationState *op);
132
133
134/**
135 * Signature of functions that implement the destruction of the
136 * implementation-specific set state.
137 *
138 * @param state the set state, contains implementation-specific data
139 */
140typedef void (*DestroySetImpl) (struct SetState *state);
141
142
143/**
144 * Signature of functions that implement the creation of set operations
145 * (currently evaluate and accept).
146 *
147 * @param spec specification of the set operation to be created
148 * @param tunnel the tunnel with the other peer
149 * @param tc tunnel context
150 */
151typedef void (*OpCreateImpl) (struct OperationSpecification *spec,
152 struct GNUNET_MESH_Tunnel *tunnel,
153 struct TunnelContext *tc);
154
155
156/**
157 * Signature of functions that implement the message handling for
158 * the different set operations.
159 *
160 * @param op operation state
161 * @param msg received message
162 * @return GNUNET_OK on success, GNUNET_SYSERR to
163 * destroy the operation and the tunnel
151 */ 164 */
152struct Listener 165typedef int (*MsgHandlerImpl) (struct OperationState *op,
166 const struct GNUNET_MessageHeader *msg);
167
168typedef void (*CancelImpl) (struct SetState *set,
169 uint32_t request_id);
170
171
172/**
173 * Dispatch table for a specific set operation.
174 * Every set operation has to implement the callback
175 * in this struct.
176 */
177struct SetVT
153{ 178{
154 /** 179 /**
155 * Listeners are held in a doubly linked list. 180 * Callback for the set creation.
156 */ 181 */
157 struct Listener *next; 182 CreateImpl create;
158 183
159 /** 184 /**
160 * Listeners are held in a doubly linked list. 185 * Callback for element insertion
161 */ 186 */
162 struct Listener *prev; 187 AddRemoveImpl add;
163 188
164 /** 189 /**
165 * Client that owns the listener. 190 * Callback for element removal.
166 * Only one client may own a listener.
167 */ 191 */
168 struct GNUNET_SERVER_Client *client; 192 AddRemoveImpl remove;
169 193
170 /** 194 /**
171 * Message queue for the client 195 * Callback for accepting a set operation request
172 */ 196 */
173 struct GNUNET_MQ_Handle *client_mq; 197 OpCreateImpl accept;
174 198
175 /** 199 /**
176 * The type of the operation. 200 * Callback for starting evaluation with a remote peer.
177 */ 201 */
178 enum GNUNET_SET_OperationType operation; 202 OpCreateImpl evaluate;
179 203
180 /** 204 /**
181 * Application ID for the operation, used to distinguish 205 * Callback for destruction of the set state.
182 * multiple operations of the same type with the same peer.
183 */ 206 */
184 struct GNUNET_HashCode app_id; 207 DestroySetImpl destroy_set;
185};
186 208
209 /**
210 * Callback for handling operation-specific messages.
211 */
212 MsgHandlerImpl msg_handler;
187 213
188/** 214 /**
189 * Peer that has connected to us, but is not yet evaluating a set operation. 215 * Callback for handling the remote peer's
190 * Once the peer has sent a request, and the client has 216 * disconnect.
191 * accepted or rejected it, this information will be deleted. 217 */
192 */ 218 PeerDisconnectImpl peer_disconnect;
193struct Incoming; 219
220 /**
221 * Callback for canceling an operation by
222 * its ID.
223 */
224 CancelImpl cancel;
225};
194 226
195 227
196/** 228/**
197 * Different types a tunnel can be. 229 * A set that supports a specific operation
230 * with other peers.
198 */ 231 */
199enum TunnelContextType 232struct Set
200{ 233{
201 /** 234 /**
202 * Tunnel is waiting for a set request from the tunnel, 235 * Client that owns the set.
203 * or for the ack/nack of the client for a received request. 236 * Only one client may own a set.
204 */ 237 */
205 CONTEXT_INCOMING, 238 struct GNUNET_SERVER_Client *client;
206 239
207 /** 240 /**
208 * The tunnel performs a union operation. 241 * Message queue for the client
209 */ 242 */
210 CONTEXT_OPERATION_UNION, 243 struct GNUNET_MQ_Handle *client_mq;
211 244
212 /** 245 /**
213 * The tunnel performs an intersection operation. 246 * Type of operation supported for this set
214 */ 247 */
215 CONTEXT_OPERATION_INTERSECTION, 248 enum GNUNET_SET_OperationType operation;
216};
217 249
250 /**
251 * Virtual table for this set.
252 * Determined by the operation type of this set.
253 */
254 const struct SetVT *vt;
218 255
219/**
220 * State associated with the tunnel, dependent on
221 * tunnel type.
222 */
223union TunnelContextData
224{
225 /** 256 /**
226 * Valid for tag 'CONTEXT_INCOMING' 257 * Sets are held in a doubly linked list.
227 */ 258 */
228 struct Incoming *incoming; 259 struct Set *next;
229 260
230 /** 261 /**
231 * Valid for tag 'CONTEXT_OPERATION_UNION' 262 * Sets are held in a doubly linked list.
232 */ 263 */
233 struct UnionEvaluateOperation *union_op; 264 struct Set *prev;
234 265
235 /** 266 /**
236 * Valid for tag 'CONTEXT_OPERATION_INTERSECTION' 267 * Implementation-specific state.
237 */ 268 */
238 struct IntersectionEvaluateOperation *intersection_op; 269 struct SetState *state;
239}; 270};
240 271
241 272
@@ -246,119 +277,24 @@ union TunnelContextData
246struct TunnelContext 277struct TunnelContext
247{ 278{
248 /** 279 /**
249 * Type of the tunnel. 280 * V-Table for the operation belonging
281 * to the tunnel contest.
250 */ 282 */
251 enum TunnelContextType type; 283 const struct SetVT *vt;
252 284
253 /** 285 /**
254 * State associated with the tunnel, dependent on 286 * Implementation-specific operation state.
255 * tunnel type.
256 */ 287 */
257 union TunnelContextData data; 288 struct OperationState *op;
258}; 289};
259 290
260 291
261
262/**
263 * Configuration of the local peer.
264 */
265extern const struct GNUNET_CONFIGURATION_Handle *configuration;
266
267/**
268 * Handle to the mesh service.
269 */
270extern struct GNUNET_MESH_Handle *mesh;
271
272
273/**
274 * Create a new set supporting the union operation
275 *
276 * @return the newly created set
277 */
278struct Set *
279_GSS_union_set_create (void);
280
281
282/**
283 * Evaluate a union operation with
284 * a remote peer.
285 *
286 * @param spec specification of the operation the evaluate
287 * @param tunnel tunnel already connected to the partner peer
288 * @return a handle to the operation
289 */
290struct UnionEvaluateOperation *
291_GSS_union_evaluate (struct OperationSpecification *spec,
292 struct GNUNET_MESH_Tunnel *tunnel);
293
294
295/**
296 * Add the element from the given element message to the set.
297 *
298 * @param m message with the element
299 * @param set set to add the element to
300 */
301void
302_GSS_union_add (struct GNUNET_SET_ElementMessage *m, struct Set *set);
303
304
305/**
306 * Remove the element given in the element message from the set.
307 * Only marks the element as removed, so that older set operations can still exchange it.
308 *
309 * @param m message with the element
310 * @param set set to remove the element from
311 */
312void
313_GSS_union_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set);
314
315
316/**
317 * Destroy a set that supports the union operation
318 *
319 * @param set the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
320 */
321void
322_GSS_union_set_destroy (struct Set *set);
323
324
325/** 292/**
326 * Accept an union operation request from a remote peer 293 * Get the table with implementing functions for
327 * 294 * set union.
328 * @param spec all necessary information about the operation
329 * @param tunnel open tunnel to the partner's peer
330 * @return operation
331 */
332struct UnionEvaluateOperation *
333_GSS_union_accept (struct OperationSpecification *spec,
334 struct GNUNET_MESH_Tunnel *tunnel);
335
336
337/**
338 * Destroy a union operation, and free all resources
339 * associated with it.
340 *
341 * @param eo the union operation to destroy
342 */
343void
344_GSS_union_operation_destroy (struct UnionEvaluateOperation *eo);
345
346
347/**
348 * Dispatch messages for a union operation.
349 *
350 * @param cls closure
351 * @param tunnel mesh tunnel
352 * @param tunnel_ctx tunnel context
353 * @param mh message to process
354 * @return GNUNET_SYSERR if the tunnel should be disconnected,
355 * GNUNET_OK otherwise
356 */ 295 */
357int 296const struct SetVT *
358_GSS_union_handle_p2p_message (void *cls, 297_GSS_union_vt (void);
359 struct GNUNET_MESH_Tunnel *tunnel,
360 void **tunnel_ctx,
361 const struct GNUNET_MessageHeader *mh);
362 298
363 299
364#endif 300#endif