diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-12 19:47:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-12 19:47:04 +0000 |
commit | b5d9a152c861625cd3301a26011945f589ad2893 (patch) | |
tree | 9438766cd3595829e22d9399516d75b88ab71984 | |
parent | 738e60b131a2e23a562788cde7047ae4596b208d (diff) | |
download | gnunet-b5d9a152c861625cd3301a26011945f589ad2893.tar.gz gnunet-b5d9a152c861625cd3301a26011945f589ad2893.zip |
first design for social service API
-rw-r--r-- | src/include/gnunet_gns_service.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_social_service.h | 491 |
2 files changed, 488 insertions, 5 deletions
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index a3d78bfdf..cbb9e81c9 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h | |||
@@ -329,7 +329,7 @@ typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls, | |||
329 | */ | 329 | */ |
330 | struct GNUNET_GNS_GetAuthRequest* | 330 | struct GNUNET_GNS_GetAuthRequest* |
331 | GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, | 331 | GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, |
332 | const char * name, | 332 | const char *name, |
333 | GNUNET_GNS_GetAuthResultProcessor proc, | 333 | GNUNET_GNS_GetAuthResultProcessor proc, |
334 | void *proc_cls); | 334 | void *proc_cls); |
335 | 335 | ||
diff --git a/src/include/gnunet_social_service.h b/src/include/gnunet_social_service.h index 3c524158c..3aaea333e 100644 --- a/src/include/gnunet_social_service.h +++ b/src/include/gnunet_social_service.h | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file include/gnunet_social_service.h | 22 | * @file include/gnunet_social_service.h |
23 | * @brief Social service; implements social functionality using the PSYC service | 23 | * @brief Social service; implements social functionality using the PSYC service |
24 | * @author tg | 24 | * @author tg |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | #ifndef GNUNET_SOCIAL_SERVICE_H | 27 | #ifndef GNUNET_SOCIAL_SERVICE_H |
27 | #define GNUNET_SOCIAL_SERVICE_H | 28 | #define GNUNET_SOCIAL_SERVICE_H |
@@ -36,21 +37,503 @@ extern "C" | |||
36 | 37 | ||
37 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
38 | #include "gnunet_psyc_service.h" | 39 | #include "gnunet_psyc_service.h" |
40 | #include "gnunet_multicast_service.h" | ||
41 | |||
39 | 42 | ||
40 | /** | 43 | /** |
41 | * Version number of GNUnet Social API. | 44 | * Version number of GNUnet Social API. |
42 | */ | 45 | */ |
43 | #define GNUNET_SOCIAL_VERSION 0x00000000 | 46 | #define GNUNET_SOCIAL_VERSION 0x00000000 |
44 | 47 | ||
48 | |||
49 | /** | ||
50 | * Handle for a place where social interactions happen. | ||
51 | */ | ||
52 | struct GNUNET_SOCIAL_Place; | ||
53 | |||
54 | /** | ||
55 | * Handle for a place that one of our egos hosts. | ||
56 | */ | ||
57 | struct GNUNET_SOCIAL_Home; | ||
58 | |||
59 | /** | ||
60 | * Handle for our own presence in the network (we can of course have | ||
61 | * alter-egos). | ||
62 | */ | ||
63 | struct GNUNET_SOCIAL_Ego; | ||
64 | |||
65 | /** | ||
66 | * Handle for another user (who is likely pseudonymous) in the network. | ||
67 | */ | ||
68 | struct GNUNET_SOCIAL_Nym; | ||
69 | |||
70 | /** | ||
71 | * Handle to an implementation of try-and-slice. | ||
72 | */ | ||
73 | struct GNUNET_SOCIAL_Slicer; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Method called from SOCIAL upon receiving a message indicating a call | ||
78 | * to a 'method'. | ||
79 | * | ||
80 | * @param cls closure | ||
81 | * @param full_method_name original method name from PSYC (may be more | ||
82 | * specific than the registered method name due to try-and-slice matching) | ||
83 | * @param message_id unique message counter for this message; | ||
84 | * (unique only in combination with the given sender for | ||
85 | * this channel) | ||
86 | * @param data_off byte offset of 'data' in the overall data of the method | ||
87 | * @param data_size number of bytes in 'data'; | ||
88 | * @param data data stream given to the method (might not be zero-terminated | ||
89 | * if data is binary) | ||
90 | * @param frag fragmentation status for the data | ||
91 | */ | ||
92 | typedef int (*GNUNET_SOCIAL_Method)(void *cls, | ||
93 | const char *full_method_name, | ||
94 | uint64_t message_id, | ||
95 | uint64_t data_off, | ||
96 | size_t data_size, | ||
97 | const void *data, | ||
98 | enum GNUNET_PSYC_FragmentStatus frag); | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Create a try-and-slice instance. | ||
103 | * | ||
104 | * @return try-and-slice construct | ||
105 | */ | ||
106 | struct GNUNET_SOCIAL_Slicer * | ||
107 | GNUNET_SOCIAL_slicer_create (void); | ||
108 | |||
109 | |||
110 | /** | ||
111 | * Add a method to the try-and-slice instance. | ||
112 | * | ||
113 | * @param slicer try-and-slice instance to extend | ||
114 | * @param method_name name of the given method, use empty string for default | ||
115 | * @param method method to invoke | ||
116 | * @param method_cls closure for method | ||
117 | */ | ||
118 | void | ||
119 | GNUNET_SOCIAL_slicer_add (struct GNUNET_SOCIAL_Slicer *slicer, | ||
120 | const char *method_name, | ||
121 | GNUNET_SOCIAL_Method method, | ||
122 | void *method_cls); | ||
123 | |||
124 | |||
125 | /** | ||
126 | * Destroy a given try-and-slice instance. | ||
127 | * | ||
128 | * @param slicer slicer to destroy | ||
129 | */ | ||
130 | void | ||
131 | GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer); | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Create an ego using the private key from the given | ||
136 | * file. If the file does not exist, a fresh key is | ||
137 | * created. | ||
138 | * | ||
139 | * @param keyfile name of the file with the private key for the ego, | ||
140 | * NULL for ephemeral egos | ||
141 | * @return handle to the ego, NULL on error | ||
142 | */ | ||
143 | struct GNUNET_SOCIAL_Ego * | ||
144 | GNUNET_SOCIAL_ego_create (const char *keyfile); | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Destroy a handle to an ego. | ||
149 | * | ||
150 | * @param ego ego to destroy | ||
151 | */ | ||
152 | void | ||
153 | GNUNET_SOCIAL_ego_destroy (struct GNUNET_SOCIAL_Ego *ego); | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Function called asking for nym to be admitted to the room. Should | ||
158 | * call either 'GNUNET_SOCIAL_home_admit' or | ||
159 | * 'GNUNET_SOCIAL_home_reject_entry' (possibly asynchronously). The | ||
160 | * 'nym' reference remains valid until the | ||
161 | * 'GNUNET_SOCIAL_FarewellCallback' is invoked for it. | ||
162 | * | ||
163 | * @param cls closure | ||
164 | * @param nym handle for the user who wants to join | ||
165 | * @param join_msg_size number of bytes in 'join_msg' | ||
166 | * @param join_msg payload given on join | ||
167 | */ | ||
168 | typedef void (*GNUNET_SOCIAL_AnswerDoorCallback)(void *cls, | ||
169 | struct GNUNET_SOCIAL_Nym *nym, | ||
170 | size_t join_msg_size, | ||
171 | const void *join_msg); | ||
172 | |||
173 | |||
174 | /** | ||
175 | * Function called when a 'nym' leaves the room. This is | ||
176 | * also called if the 'nym' was never given permission to | ||
177 | * enter (i.e. the 'nym' stopped asking to get in). | ||
178 | * | ||
179 | * @param cls closure | ||
180 | * @param nym handle for the user who left | ||
181 | */ | ||
182 | typedef void (*GNUNET_SOCIAL_FarewellCallback)(void *cls, | ||
183 | struct GNUNET_SOCIAL_Nym *nym); | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Create a new home to host guests (nyms). | ||
188 | * | ||
189 | * @param cfg configuration to contact the social service | ||
190 | * @param home_keyfile file with the private key for the home, | ||
191 | * created if the file does not exist; | ||
192 | * pass NULL for ephemeral homes | ||
193 | * @param join_policy what is our policy for allowing people in? | ||
194 | * @param ego owner of the home (host) | ||
195 | * @param slicer slicer to handle guests talking | ||
196 | * @param listener_cb function to handle new nyms that want to join | ||
197 | * @param farewell_cb function to handle departing nyms | ||
198 | * @param cls closure for 'listener_cb' and 'farewell_cb' | ||
199 | * @return handle for a new home | ||
200 | */ | ||
201 | struct GNUNET_SOCIAL_Home * | ||
202 | GNUNET_SOCIAL_home_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
203 | const char *home_keyfile, | ||
204 | enum GNUNET_MULTICAST_JoinPolicy join_policy, | ||
205 | struct GNUNET_SOCIAL_Ego *ego, | ||
206 | struct GNUNET_SOCIAL_Slicer *slicer, | ||
207 | GNUNET_SOCIAL_AnswerDoorCallback listener_cb, | ||
208 | GNUNET_SOCIAL_FarewellCallback farewell_cb, | ||
209 | void *cls); | ||
210 | |||
211 | |||
212 | /** | ||
213 | * Admit 'nym' to the 'home'. 'nym' will remain valid until either | ||
214 | * the home is destroyed or 'nym' leaves. | ||
215 | * | ||
216 | * @param home home to allow 'nym' to join | ||
217 | * @param nym handle for the entity that wants to join | ||
218 | */ | ||
219 | void | ||
220 | GNUNET_SOCIAL_home_admit (struct GNUNET_SOCIAL_Home *home, | ||
221 | struct GNUNET_SOCIAL_Nym *nym); | ||
222 | |||
223 | |||
224 | /** | ||
225 | * Throw 'nym' out of the 'home'. 'nym' will remain valid | ||
226 | * until the 'GNUNET_SOCIAL_FarewellCallback' is invoked, which | ||
227 | * should be very soon after this call. | ||
228 | * | ||
229 | * @param home home to allow 'nym' to join | ||
230 | * @param nym handle for the entity that wants to join | ||
231 | */ | ||
232 | void | ||
233 | GNUNET_SOCIAL_home_evict (struct GNUNET_SOCIAL_Home *home, | ||
234 | struct GNUNET_SOCIAL_Nym *nym); | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Refuse 'nym' entry into the 'home'. | ||
239 | * | ||
240 | * @param home home to disallow 'nym' to join | ||
241 | * @param nym handle for the entity that wanted to join | ||
242 | */ | ||
243 | void | ||
244 | GNUNET_SOCIAL_home_reject_entry (struct GNUNET_SOCIAL_Home *home, | ||
245 | struct GNUNET_SOCIAL_Nym *nym); | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Get the identity of a user (suitable, for example, to be used | ||
250 | * with 'GNUNET_NAMESTORE_zone_to_name'). | ||
251 | * | ||
252 | * @param nym pseydonym to map to a cryptographic identifier | ||
253 | * @param identity set to the identity of the nym (short hash of the public key) | ||
254 | */ | ||
255 | void | ||
256 | GNUNET_SOCIAL_nym_get_identity (struct GNUNET_SOCIAL_Nym *nym, | ||
257 | struct GNUNET_CRYPTO_ShortHashCode *identity); | ||
258 | |||
259 | |||
45 | /** | 260 | /** |
46 | * Handle for a social channel | 261 | * Obtain the (cryptographic, binary) address for the home. |
262 | * | ||
263 | * @param home home to get the (public) address from | ||
264 | * @param crypto_address address suitable for storing in GADS, | ||
265 | * i.e. in 'HEX.place' or within the respective GADS record type ("PLACE") | ||
47 | */ | 266 | */ |
48 | struct GNUNET_SOCIAL_Channel; | 267 | void |
268 | GNUNET_SOCIAL_home_get_address (struct GNUNET_SOCIAL_Home *home, | ||
269 | struct GNUNET_HashCode *crypto_address); | ||
270 | |||
271 | |||
272 | /** | ||
273 | * (re)decorate the home by changing objects in it. If | ||
274 | * the operation is 'GNUNET_PSYC_SOT_SET_VARIABLE' then | ||
275 | * the decoration only applies to the next announcement | ||
276 | * by the home owner. | ||
277 | * | ||
278 | * @param home the home to decorate | ||
279 | * @param operation operation to perform on the object | ||
280 | * @param object_name name of the object to modify | ||
281 | * @param object_value_size size of the given 'object_value' | ||
282 | * @param object_value value to use for the modification | ||
283 | */ | ||
284 | void | ||
285 | GNUNET_SOCIAL_home_decorate (struct GNUNET_SOCIAL_Home *home, | ||
286 | enum GNUNET_PSYC_Operator operation, | ||
287 | const char *object_name, | ||
288 | size_t object_value_size, | ||
289 | const void *object_value); | ||
290 | |||
49 | 291 | ||
50 | /** | 292 | /** |
51 | * Handle for a social client | 293 | * Handle for an announcement request. |
52 | */ | 294 | */ |
53 | struct GNUNET_SOCIAL_Client; | 295 | struct GNUNET_SOCIAL_Announcement; |
296 | |||
297 | |||
298 | /** | ||
299 | * This function allows the home owner to send a message to all | ||
300 | * nyms that are present in the home. | ||
301 | * | ||
302 | * @param home home to address the announcement to | ||
303 | * @param full_method_name method to use for the announcement | ||
304 | * @param notify function to call to get the payload of the announcement | ||
305 | * @param notify_cls closure for 'notify' | ||
306 | * @return NULL on error (announcement already in progress?) | ||
307 | */ | ||
308 | struct GNUNET_SOCIAL_Announcement * | ||
309 | GNUNET_SOCIAL_place_announce (struct GNUNET_SOCIAL_Home *home, | ||
310 | const char *full_method_name, | ||
311 | GNUNET_PSYC_OriginReadyNotify notify, | ||
312 | void *notify_cls); | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Cancel announcement. | ||
317 | * | ||
318 | * @param a the announcement to cancel | ||
319 | */ | ||
320 | void | ||
321 | GNUNET_SOCIAL_place_announce_cancel (struct GNUNET_SOCIAL_Announcement *a); | ||
322 | |||
323 | |||
324 | /** | ||
325 | * Convert our home to a place so we can access it via the place API. | ||
326 | * | ||
327 | * @param home handle for the home | ||
328 | * @return place handle for the same home, valid as long as 'home' is valid; | ||
329 | * do NOT try to 'GNUNET_SOCIAL_place_leave' this place, it's your home! | ||
330 | */ | ||
331 | struct GNUNET_SOCIAL_Place * | ||
332 | GNUNET_SOCIAL_home_to_place (struct GNUNET_SOCIAL_Home *home); | ||
333 | |||
334 | |||
335 | /** | ||
336 | * Leave a home, visitors can stay. | ||
337 | * | ||
338 | * @param home home to leave (handle becomes invalid). | ||
339 | */ | ||
340 | void | ||
341 | GNUNET_SOCIAL_home_leave (struct GNUNET_SOCIAL_Home *home); | ||
342 | |||
343 | |||
344 | /** | ||
345 | * Destroy a home, all guests will be evicted. | ||
346 | * | ||
347 | * @param home home to destroy | ||
348 | */ | ||
349 | void | ||
350 | GNUNET_SOCIAL_home_destroy (struct GNUNET_SOCIAL_Home *home); | ||
351 | |||
352 | |||
353 | /** | ||
354 | * Join a place (home hosted by someone else). | ||
355 | * | ||
356 | * @param cfg configuration to contact the social service | ||
357 | * @param ego owner of the home (host) | ||
358 | * @param address address of the place to join (GADS name, i.e. 'room.friend.gads'), | ||
359 | * if the name has the form 'HEX.place', GADS is not | ||
360 | * used and HEX is assumed to be the hash of the public | ||
361 | * key already; 'HEX.zkey' however would refer to | ||
362 | * the 'PLACE' record in the GADS zone with the public key | ||
363 | * 'HEX'. | ||
364 | * @param join_msg_size number of bytes in 'join_msg' | ||
365 | * @param join_msg message to give to the join callback | ||
366 | * @return NULL on errors, otherwise handle to the place | ||
367 | */ | ||
368 | struct GNUNET_SOCIAL_Place * | ||
369 | GNUNET_SOCIAL_place_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
370 | struct GNUNET_SOCIAL_Ego *ego, | ||
371 | const char *address, | ||
372 | struct GNUNET_SOCIAL_Slicer *slicer, | ||
373 | size_t join_msg_size, | ||
374 | const void *join_msg); | ||
375 | |||
376 | |||
377 | /** | ||
378 | * | ||
379 | */ | ||
380 | struct GNUNET_SOCIAL_WatchHandle; | ||
381 | |||
382 | /** | ||
383 | * | ||
384 | * | ||
385 | * @param | ||
386 | * @param | ||
387 | * @param | ||
388 | * @param | ||
389 | */ | ||
390 | struct GNUNET_SOCIAL_WatchHandle * | ||
391 | GNUNET_SOCIAL_place_watch (struct GNUNET_SOCIAL_Place *place, | ||
392 | const char *object_filter, | ||
393 | GNUNET_PSYC_StateCallback state_cb, | ||
394 | void *state_cb_cls); | ||
395 | |||
396 | |||
397 | /** | ||
398 | * | ||
399 | * | ||
400 | * @param | ||
401 | */ | ||
402 | void | ||
403 | GNUNET_SOCIAL_place_watch_cancel (struct GNUNET_SOCIAL_WatchHandle *wh); | ||
404 | |||
405 | |||
406 | /** | ||
407 | * | ||
408 | */ | ||
409 | struct GNUNET_SOCIAL_LookHandle; | ||
410 | |||
411 | /** | ||
412 | * Look at all objects in the place. | ||
413 | * | ||
414 | */ | ||
415 | struct GNUNET_SOCIAL_LookHandle * | ||
416 | GNUNET_SOCIAL_place_look (struct GNUNET_SOCIAL_Place *place, | ||
417 | GNUNET_PSYC_StateCallback state_cb, | ||
418 | void *state_cb_cls); | ||
419 | |||
420 | |||
421 | /** | ||
422 | * Look at matching objects in the place. | ||
423 | * | ||
424 | */ | ||
425 | struct GNUNET_SOCIAL_LookHandle * | ||
426 | GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *place, | ||
427 | const char *object_filter, | ||
428 | GNUNET_PSYC_StateCallback state_cb, | ||
429 | void *state_cb_cls); | ||
430 | |||
431 | |||
432 | /** | ||
433 | * | ||
434 | * | ||
435 | */ | ||
436 | void | ||
437 | GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh); | ||
438 | |||
439 | |||
440 | |||
441 | /** | ||
442 | * Look at a particular object in the place. | ||
443 | * | ||
444 | * @param | ||
445 | * @param | ||
446 | * @param | ||
447 | * @return | ||
448 | */ | ||
449 | const void * | ||
450 | GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *place, | ||
451 | const char *object_name, | ||
452 | size_t *value_size); | ||
453 | |||
454 | |||
455 | /** | ||
456 | * Frame the (next) talk by setting some variables for it. | ||
457 | * | ||
458 | * @param | ||
459 | * @param | ||
460 | * @param | ||
461 | * @param | ||
462 | */ | ||
463 | void | ||
464 | GNUNET_SOCIAL_place_frame_talk (struct GNUNET_SOCIAL_Place *place, | ||
465 | const char *variable_name, | ||
466 | size_t value_size, | ||
467 | const void *value); | ||
468 | |||
469 | |||
470 | /** | ||
471 | * | ||
472 | */ | ||
473 | struct GNUNET_SOCIAL_TalkRequest; | ||
474 | |||
475 | |||
476 | /** | ||
477 | * Talk to the host of the place. | ||
478 | * | ||
479 | * @param | ||
480 | * @param | ||
481 | * @param | ||
482 | * @param cb_cls closure for 'cb' | ||
483 | * @return NULL if we are already trying to talk to the host, | ||
484 | * otherwise handle to cancel the request | ||
485 | */ | ||
486 | struct GNUNET_SOCIAL_TalkRequest * | ||
487 | GNUNET_SOCIAL_place_talk (struct GNUNET_SOCIAL_Place *place, | ||
488 | const char *method_name, | ||
489 | GNUNET_PSYC_OriginReadyNotify cb, | ||
490 | void *cb_cls); | ||
491 | |||
492 | |||
493 | /** | ||
494 | * | ||
495 | * | ||
496 | * @param | ||
497 | */ | ||
498 | void | ||
499 | GNUNET_SOCIAL_place_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr); | ||
500 | |||
501 | |||
502 | struct GNUNET_SOCIAL_HistoryLesson; | ||
503 | |||
504 | |||
505 | /** | ||
506 | * | ||
507 | * @param | ||
508 | * @param | ||
509 | * @param | ||
510 | * @param | ||
511 | * @return | ||
512 | */ | ||
513 | struct GNUNET_SOCIAL_HistoryLesson * | ||
514 | GNUNET_SOCIAL_place_get_history (struct GNUNET_SOCIAL_Place *place, | ||
515 | uint64_t start_message_id, | ||
516 | uint64_t end_message_id, | ||
517 | struct GNUNET_SOCIAL_Slicer *slicer); | ||
518 | |||
519 | |||
520 | /** | ||
521 | * | ||
522 | * | ||
523 | * @param | ||
524 | */ | ||
525 | void | ||
526 | GNUNET_SOCIAL_place_get_history_cancel (struct GNUNET_SOCIAL_HistoryLesson *hist); | ||
527 | |||
528 | |||
529 | /** | ||
530 | * Leave a place (destroys the place handle). | ||
531 | * | ||
532 | * @param place place to leave | ||
533 | */ | ||
534 | void | ||
535 | GNUNET_SOCIAL_place_leave (struct GNUNET_SOCIAL_Place *place); | ||
536 | |||
54 | 537 | ||
55 | 538 | ||
56 | #if 0 /* keep Emacsens' auto-indent happy */ | 539 | #if 0 /* keep Emacsens' auto-indent happy */ |