diff options
author | Gabor X Toth <*@tg-x.net> | 2016-05-12 01:50:28 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-05-12 01:50:28 +0000 |
commit | 235521e7893c3f6be82103700f5056a4df285afa (patch) | |
tree | b5a9137bee42539cfc2d2709f5179de7489a8701 /src/social | |
parent | 9ced7c72a9acfe9c99b4d2f07bb81e11a1a23707 (diff) | |
download | gnunet-235521e7893c3f6be82103700f5056a4df285afa.tar.gz gnunet-235521e7893c3f6be82103700f5056a4df285afa.zip |
social cli docs
Diffstat (limited to 'src/social')
-rw-r--r-- | src/social/gnunet-social.c | 156 |
1 files changed, 146 insertions, 10 deletions
diff --git a/src/social/gnunet-social.c b/src/social/gnunet-social.c index 9e69208b5..bb6f1e694 100644 --- a/src/social/gnunet-social.c +++ b/src/social/gnunet-social.c | |||
@@ -157,6 +157,9 @@ struct GNUNET_SOCIAL_Place *plc; | |||
157 | /* DISCONNECT */ | 157 | /* DISCONNECT */ |
158 | 158 | ||
159 | 159 | ||
160 | /** | ||
161 | * Callback called after the host or guest place disconnected. | ||
162 | */ | ||
160 | static void | 163 | static void |
161 | disconnected (void *cls) | 164 | disconnected (void *cls) |
162 | { | 165 | { |
@@ -164,6 +167,9 @@ disconnected (void *cls) | |||
164 | } | 167 | } |
165 | 168 | ||
166 | 169 | ||
170 | /** | ||
171 | * Callback called after the application disconnected. | ||
172 | */ | ||
167 | static void | 173 | static void |
168 | app_disconnected (void *cls) | 174 | app_disconnected (void *cls) |
169 | { | 175 | { |
@@ -185,6 +191,9 @@ app_disconnected (void *cls) | |||
185 | } | 191 | } |
186 | 192 | ||
187 | 193 | ||
194 | /** | ||
195 | * Disconnect from connected GNUnet services. | ||
196 | */ | ||
188 | static void | 197 | static void |
189 | disconnect () | 198 | disconnect () |
190 | { | 199 | { |
@@ -193,9 +202,7 @@ disconnect () | |||
193 | } | 202 | } |
194 | 203 | ||
195 | /** | 204 | /** |
196 | * Terminate the test case (failure). | 205 | * Callback called when the program failed to finish the requested operation in time. |
197 | * | ||
198 | * @param cls NULL | ||
199 | */ | 206 | */ |
200 | static void | 207 | static void |
201 | timeout (void *cls) | 208 | timeout (void *cls) |
@@ -219,6 +226,9 @@ schedule_fail (void *cls) | |||
219 | } | 226 | } |
220 | 227 | ||
221 | 228 | ||
229 | /** | ||
230 | * Schedule exit with succes result. | ||
231 | */ | ||
222 | static void | 232 | static void |
223 | exit_success () | 233 | exit_success () |
224 | { | 234 | { |
@@ -231,6 +241,9 @@ exit_success () | |||
231 | } | 241 | } |
232 | 242 | ||
233 | 243 | ||
244 | /** | ||
245 | * Schedule exit with failure result. | ||
246 | */ | ||
234 | static void | 247 | static void |
235 | exit_fail () | 248 | exit_fail () |
236 | { | 249 | { |
@@ -246,6 +259,11 @@ exit_fail () | |||
246 | /* LEAVE */ | 259 | /* LEAVE */ |
247 | 260 | ||
248 | 261 | ||
262 | /** | ||
263 | * Callback notifying about the host has left and stopped hosting the place. | ||
264 | * | ||
265 | * This also indicates the end of the connection to the service. | ||
266 | */ | ||
249 | static void | 267 | static void |
250 | host_left () | 268 | host_left () |
251 | { | 269 | { |
@@ -255,6 +273,9 @@ host_left () | |||
255 | } | 273 | } |
256 | 274 | ||
257 | 275 | ||
276 | /** | ||
277 | * Leave a place permanently and stop hosting a place. | ||
278 | */ | ||
258 | static void | 279 | static void |
259 | host_leave () | 280 | host_leave () |
260 | { | 281 | { |
@@ -264,6 +285,11 @@ host_leave () | |||
264 | } | 285 | } |
265 | 286 | ||
266 | 287 | ||
288 | /** | ||
289 | * Callback notifying about the guest has left the place. | ||
290 | * | ||
291 | * This also indicates the end of the connection to the service. | ||
292 | */ | ||
267 | static void | 293 | static void |
268 | guest_left (void *cls) | 294 | guest_left (void *cls) |
269 | { | 295 | { |
@@ -272,13 +298,15 @@ guest_left (void *cls) | |||
272 | } | 298 | } |
273 | 299 | ||
274 | 300 | ||
301 | /** | ||
302 | * Leave a place permanently as guest. | ||
303 | */ | ||
275 | static void | 304 | static void |
276 | guest_leave () | 305 | guest_leave () |
277 | { | 306 | { |
278 | struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); | 307 | struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create (); |
279 | // method in the middle of vars? FIXME | ||
280 | GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET, | 308 | GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET, |
281 | "_notice_place_leave", DATA2ARG ("Leaving.")); | 309 | "_message", DATA2ARG ("Leaving.")); |
282 | GNUNET_SOCIAL_guest_leave (gst, env, guest_left, NULL); | 310 | GNUNET_SOCIAL_guest_leave (gst, env, guest_left, NULL); |
283 | GNUNET_PSYC_env_destroy (env); | 311 | GNUNET_PSYC_env_destroy (env); |
284 | gst = NULL; | 312 | gst = NULL; |
@@ -296,6 +324,10 @@ struct TransmitClosure | |||
296 | } tmit; | 324 | } tmit; |
297 | 325 | ||
298 | 326 | ||
327 | /** | ||
328 | * Callback notifying about available buffer space to write message data | ||
329 | * when transmitting messages using host_announce() or guest_talk() | ||
330 | */ | ||
299 | static int | 331 | static int |
300 | notify_data (void *cls, uint16_t *data_size, void *data) | 332 | notify_data (void *cls, uint16_t *data_size, void *data) |
301 | { | 333 | { |
@@ -326,6 +358,9 @@ notify_data (void *cls, uint16_t *data_size, void *data) | |||
326 | } | 358 | } |
327 | 359 | ||
328 | 360 | ||
361 | /** | ||
362 | * Host announcement - send a message to the place. | ||
363 | */ | ||
329 | static void | 364 | static void |
330 | host_announce (const char *method, const char *data, size_t data_size) | 365 | host_announce (const char *method, const char *data, size_t data_size) |
331 | { | 366 | { |
@@ -342,6 +377,10 @@ host_announce (const char *method, const char *data, size_t data_size) | |||
342 | GNUNET_SOCIAL_ANNOUNCE_NONE); | 377 | GNUNET_SOCIAL_ANNOUNCE_NONE); |
343 | } | 378 | } |
344 | 379 | ||
380 | |||
381 | /** | ||
382 | * Assign a state var of @a name to the value of @a data. | ||
383 | */ | ||
345 | static void | 384 | static void |
346 | host_assign (const char *name, const char *data, size_t data_size) | 385 | host_assign (const char *name, const char *data, size_t data_size) |
347 | { | 386 | { |
@@ -356,6 +395,9 @@ host_assign (const char *name, const char *data, size_t data_size) | |||
356 | } | 395 | } |
357 | 396 | ||
358 | 397 | ||
398 | /** | ||
399 | * Guest talk request to host. | ||
400 | */ | ||
359 | static void | 401 | static void |
360 | guest_talk (const char *method, | 402 | guest_talk (const char *method, |
361 | const char *data, size_t data_size) | 403 | const char *data, size_t data_size) |
@@ -377,6 +419,9 @@ guest_talk (const char *method, | |||
377 | /* HISTORY REPLAY */ | 419 | /* HISTORY REPLAY */ |
378 | 420 | ||
379 | 421 | ||
422 | /** | ||
423 | * Callback notifying about the end of history replay results. | ||
424 | */ | ||
380 | static void | 425 | static void |
381 | recv_history_replay_result (void *cls, int64_t result, | 426 | recv_history_replay_result (void *cls, int64_t result, |
382 | const void *data, uint16_t data_size) | 427 | const void *data, uint16_t data_size) |
@@ -393,6 +438,10 @@ recv_history_replay_result (void *cls, int64_t result, | |||
393 | } | 438 | } |
394 | 439 | ||
395 | 440 | ||
441 | /** | ||
442 | * Replay history between a given @a start and @a end message IDs, | ||
443 | * optionally filtered by a method @a prefix. | ||
444 | */ | ||
396 | static void | 445 | static void |
397 | history_replay (uint64_t start, uint64_t end, const char *prefix) | 446 | history_replay (uint64_t start, uint64_t end, const char *prefix) |
398 | { | 447 | { |
@@ -404,6 +453,9 @@ history_replay (uint64_t start, uint64_t end, const char *prefix) | |||
404 | } | 453 | } |
405 | 454 | ||
406 | 455 | ||
456 | /** | ||
457 | * Replay latest @a limit messages. | ||
458 | */ | ||
407 | static void | 459 | static void |
408 | history_replay_latest (uint64_t limit, const char *prefix) | 460 | history_replay_latest (uint64_t limit, const char *prefix) |
409 | { | 461 | { |
@@ -418,6 +470,9 @@ history_replay_latest (uint64_t limit, const char *prefix) | |||
418 | /* LOOK AT/FOR */ | 470 | /* LOOK AT/FOR */ |
419 | 471 | ||
420 | 472 | ||
473 | /** | ||
474 | * Callback notifying about the end of state var results. | ||
475 | */ | ||
421 | static void | 476 | static void |
422 | look_result (void *cls, int64_t result_code, | 477 | look_result (void *cls, int64_t result_code, |
423 | const void *data, uint16_t data_size) | 478 | const void *data, uint16_t data_size) |
@@ -432,6 +487,9 @@ look_result (void *cls, int64_t result_code, | |||
432 | } | 487 | } |
433 | 488 | ||
434 | 489 | ||
490 | /** | ||
491 | * Callback notifying about a state var result. | ||
492 | */ | ||
435 | static void | 493 | static void |
436 | look_var (void *cls, | 494 | look_var (void *cls, |
437 | const struct GNUNET_MessageHeader *mod, | 495 | const struct GNUNET_MessageHeader *mod, |
@@ -441,28 +499,37 @@ look_var (void *cls, | |||
441 | uint32_t full_value_size) | 499 | uint32_t full_value_size) |
442 | { | 500 | { |
443 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 501 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
444 | "look_at_var: %s\n%.*s\n", | 502 | "Received var: %s\n%.*s\n", |
445 | name, value_size, (const char *) value); | 503 | name, value_size, (const char *) value); |
446 | } | 504 | } |
447 | 505 | ||
448 | 506 | ||
507 | /** | ||
508 | * Look for a state var using exact match of the name. | ||
509 | */ | ||
449 | static void | 510 | static void |
450 | look_at (const char *name) | 511 | look_at (const char *full_name) |
451 | { | 512 | { |
452 | GNUNET_SOCIAL_place_look_at (plc, name, look_var, look_result, NULL); | 513 | GNUNET_SOCIAL_place_look_at (plc, full_name, look_var, look_result, NULL); |
453 | } | 514 | } |
454 | 515 | ||
455 | 516 | ||
517 | /** | ||
518 | * Look for state vars by name prefix. | ||
519 | */ | ||
456 | static void | 520 | static void |
457 | look_for (const char *name) | 521 | look_for (const char *name_prefix) |
458 | { | 522 | { |
459 | GNUNET_SOCIAL_place_look_for (plc, name, look_var, look_result, NULL); | 523 | GNUNET_SOCIAL_place_look_for (plc, name_prefix, look_var, look_result, NULL); |
460 | } | 524 | } |
461 | 525 | ||
462 | 526 | ||
463 | /* SLICER */ | 527 | /* SLICER */ |
464 | 528 | ||
465 | 529 | ||
530 | /** | ||
531 | * Callback notifying about the start of a new incoming message. | ||
532 | */ | ||
466 | static void | 533 | static void |
467 | slicer_recv_method (void *cls, | 534 | slicer_recv_method (void *cls, |
468 | const struct GNUNET_PSYC_MessageHeader *msg, | 535 | const struct GNUNET_PSYC_MessageHeader *msg, |
@@ -477,6 +544,9 @@ slicer_recv_method (void *cls, | |||
477 | } | 544 | } |
478 | 545 | ||
479 | 546 | ||
547 | /** | ||
548 | * Callback notifying about an incoming modifier. | ||
549 | */ | ||
480 | static void | 550 | static void |
481 | slicer_recv_modifier (void *cls, | 551 | slicer_recv_modifier (void *cls, |
482 | const struct GNUNET_PSYC_MessageHeader *msg, | 552 | const struct GNUNET_PSYC_MessageHeader *msg, |
@@ -495,6 +565,9 @@ slicer_recv_modifier (void *cls, | |||
495 | } | 565 | } |
496 | 566 | ||
497 | 567 | ||
568 | /** | ||
569 | * Callback notifying about an incoming data fragment. | ||
570 | */ | ||
498 | static void | 571 | static void |
499 | slicer_recv_data (void *cls, | 572 | slicer_recv_data (void *cls, |
500 | const struct GNUNET_PSYC_MessageHeader *msg, | 573 | const struct GNUNET_PSYC_MessageHeader *msg, |
@@ -510,6 +583,9 @@ slicer_recv_data (void *cls, | |||
510 | } | 583 | } |
511 | 584 | ||
512 | 585 | ||
586 | /** | ||
587 | * Callback notifying about the end of a message. | ||
588 | */ | ||
513 | static void | 589 | static void |
514 | slicer_recv_eom (void *cls, | 590 | slicer_recv_eom (void *cls, |
515 | const struct GNUNET_PSYC_MessageHeader *msg, | 591 | const struct GNUNET_PSYC_MessageHeader *msg, |
@@ -524,6 +600,9 @@ slicer_recv_eom (void *cls, | |||
524 | } | 600 | } |
525 | 601 | ||
526 | 602 | ||
603 | /** | ||
604 | * Create a slicer for receiving message parts. | ||
605 | */ | ||
527 | static struct GNUNET_PSYC_Slicer * | 606 | static struct GNUNET_PSYC_Slicer * |
528 | slicer_create () | 607 | slicer_create () |
529 | { | 608 | { |
@@ -540,6 +619,12 @@ slicer_create () | |||
540 | /* GUEST ENTER */ | 619 | /* GUEST ENTER */ |
541 | 620 | ||
542 | 621 | ||
622 | /** | ||
623 | * Callback called when the guest receives an entry decision from the host. | ||
624 | * | ||
625 | * It is called once after using guest_enter() or guest_enter_by_name(), | ||
626 | * in case of a reconnection only the local enter callback is called. | ||
627 | */ | ||
543 | static void | 628 | static void |
544 | guest_recv_entry_decision (void *cls, | 629 | guest_recv_entry_decision (void *cls, |
545 | int is_admitted, | 630 | int is_admitted, |
@@ -572,6 +657,9 @@ guest_recv_entry_decision (void *cls, | |||
572 | } | 657 | } |
573 | 658 | ||
574 | 659 | ||
660 | /** | ||
661 | * Callback called after a guest connection is established to the local service. | ||
662 | */ | ||
575 | static void | 663 | static void |
576 | guest_recv_local_enter (void *cls, int result, | 664 | guest_recv_local_enter (void *cls, int result, |
577 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, | 665 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, |
@@ -590,6 +678,9 @@ guest_recv_local_enter (void *cls, int result, | |||
590 | } | 678 | } |
591 | 679 | ||
592 | 680 | ||
681 | /** | ||
682 | * Create entry requset message. | ||
683 | */ | ||
593 | static struct GNUNET_PSYC_Message * | 684 | static struct GNUNET_PSYC_Message * |
594 | guest_enter_msg_create () | 685 | guest_enter_msg_create () |
595 | { | 686 | { |
@@ -604,6 +695,9 @@ guest_enter_msg_create () | |||
604 | } | 695 | } |
605 | 696 | ||
606 | 697 | ||
698 | /** | ||
699 | * Enter a place as guest, using its public key and peer ID. | ||
700 | */ | ||
607 | static void | 701 | static void |
608 | guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, | 702 | guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, |
609 | const struct GNUNET_PeerIdentity *peer) | 703 | const struct GNUNET_PeerIdentity *peer) |
@@ -628,6 +722,9 @@ guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, | |||
628 | } | 722 | } |
629 | 723 | ||
630 | 724 | ||
725 | /** | ||
726 | * Enter a place as guest using its GNS address. | ||
727 | */ | ||
631 | static void | 728 | static void |
632 | guest_enter_by_name (const char *gns_name) | 729 | guest_enter_by_name (const char *gns_name) |
633 | { | 730 | { |
@@ -645,6 +742,11 @@ guest_enter_by_name (const char *gns_name) | |||
645 | /* HOST ENTER */ | 742 | /* HOST ENTER */ |
646 | 743 | ||
647 | 744 | ||
745 | /** | ||
746 | * Callback called when a @a nym wants to enter the place. | ||
747 | * | ||
748 | * The request needs to be replied with an entry decision. | ||
749 | */ | ||
648 | static void | 750 | static void |
649 | host_answer_door (void *cls, | 751 | host_answer_door (void *cls, |
650 | struct GNUNET_SOCIAL_Nym *nym, | 752 | struct GNUNET_SOCIAL_Nym *nym, |
@@ -683,6 +785,9 @@ host_answer_door (void *cls, | |||
683 | } | 785 | } |
684 | 786 | ||
685 | 787 | ||
788 | /** | ||
789 | * Callback called when a @a nym has left the place. | ||
790 | */ | ||
686 | static void | 791 | static void |
687 | host_farewell (void *cls, | 792 | host_farewell (void *cls, |
688 | const struct GNUNET_SOCIAL_Nym *nym, | 793 | const struct GNUNET_SOCIAL_Nym *nym, |
@@ -699,6 +804,9 @@ host_farewell (void *cls, | |||
699 | } | 804 | } |
700 | 805 | ||
701 | 806 | ||
807 | /** | ||
808 | * Callback called after the host entered the place. | ||
809 | */ | ||
702 | static void | 810 | static void |
703 | host_entered (void *cls, int result, | 811 | host_entered (void *cls, int result, |
704 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, | 812 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, |
@@ -717,6 +825,9 @@ host_entered (void *cls, int result, | |||
717 | } | 825 | } |
718 | 826 | ||
719 | 827 | ||
828 | /** | ||
829 | * Enter and start hosting a place. | ||
830 | */ | ||
720 | static void | 831 | static void |
721 | host_enter () | 832 | host_enter () |
722 | { | 833 | { |
@@ -740,6 +851,9 @@ host_enter () | |||
740 | /* PLACE RECONNECT */ | 851 | /* PLACE RECONNECT */ |
741 | 852 | ||
742 | 853 | ||
854 | /** | ||
855 | * Perform operations common to both host & guest places. | ||
856 | */ | ||
743 | static void | 857 | static void |
744 | place_reconnected () | 858 | place_reconnected () |
745 | { | 859 | { |
@@ -763,6 +877,9 @@ place_reconnected () | |||
763 | } | 877 | } |
764 | 878 | ||
765 | 879 | ||
880 | /** | ||
881 | * Callback called after reconnecting to a host place. | ||
882 | */ | ||
766 | static void | 883 | static void |
767 | host_reconnected (void *cls, int result, | 884 | host_reconnected (void *cls, int result, |
768 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 885 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, |
@@ -786,6 +903,9 @@ host_reconnected (void *cls, int result, | |||
786 | } | 903 | } |
787 | 904 | ||
788 | 905 | ||
906 | /** | ||
907 | * Callback called after reconnecting to a guest place. | ||
908 | */ | ||
789 | static void | 909 | static void |
790 | guest_reconnected (void *cls, int result, | 910 | guest_reconnected (void *cls, int result, |
791 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 911 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, |
@@ -809,6 +929,9 @@ guest_reconnected (void *cls, int result, | |||
809 | /* APP */ | 929 | /* APP */ |
810 | 930 | ||
811 | 931 | ||
932 | /** | ||
933 | * Callback called after the ego and place callbacks. | ||
934 | */ | ||
812 | static void | 935 | static void |
813 | app_connected (void *cls) | 936 | app_connected (void *cls) |
814 | { | 937 | { |
@@ -853,6 +976,9 @@ app_connected (void *cls) | |||
853 | } | 976 | } |
854 | 977 | ||
855 | 978 | ||
979 | /** | ||
980 | * Callback notifying about a host place available for reconnection. | ||
981 | */ | ||
856 | static void | 982 | static void |
857 | app_recv_host (void *cls, | 983 | app_recv_host (void *cls, |
858 | struct GNUNET_SOCIAL_HostConnection *hconn, | 984 | struct GNUNET_SOCIAL_HostConnection *hconn, |
@@ -877,6 +1003,9 @@ app_recv_host (void *cls, | |||
877 | } | 1003 | } |
878 | 1004 | ||
879 | 1005 | ||
1006 | /** | ||
1007 | * Callback notifying about a guest place available for reconnection. | ||
1008 | */ | ||
880 | static void | 1009 | static void |
881 | app_recv_guest (void *cls, | 1010 | app_recv_guest (void *cls, |
882 | struct GNUNET_SOCIAL_GuestConnection *gconn, | 1011 | struct GNUNET_SOCIAL_GuestConnection *gconn, |
@@ -901,6 +1030,9 @@ app_recv_guest (void *cls, | |||
901 | } | 1030 | } |
902 | 1031 | ||
903 | 1032 | ||
1033 | /** | ||
1034 | * Callback notifying about an available ego. | ||
1035 | */ | ||
904 | static void | 1036 | static void |
905 | app_recv_ego (void *cls, | 1037 | app_recv_ego (void *cls, |
906 | struct GNUNET_SOCIAL_Ego *e, | 1038 | struct GNUNET_SOCIAL_Ego *e, |
@@ -920,6 +1052,10 @@ app_recv_ego (void *cls, | |||
920 | } | 1052 | } |
921 | 1053 | ||
922 | 1054 | ||
1055 | |||
1056 | /** | ||
1057 | * Establish application connection to receive available egos and places. | ||
1058 | */ | ||
923 | static void | 1059 | static void |
924 | app_connect () | 1060 | app_connect () |
925 | { | 1061 | { |