diff options
author | Gabor X Toth <*@tg-x.net> | 2016-05-06 20:30:18 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-05-06 20:30:18 +0000 |
commit | 9f79f8dc3087234641ac623097ce12ad7838bcb4 (patch) | |
tree | 8f6134cfedbb7ed7905fdca61a3aa724dc02b4a0 /src/social/gnunet-social.c | |
parent | 9416d745bf3a7abafc895e8bc1083afefaa45755 (diff) | |
download | gnunet-9f79f8dc3087234641ac623097ce12ad7838bcb4.tar.gz gnunet-9f79f8dc3087234641ac623097ce12ad7838bcb4.zip |
social cli
Diffstat (limited to 'src/social/gnunet-social.c')
-rw-r--r-- | src/social/gnunet-social.c | 344 |
1 files changed, 256 insertions, 88 deletions
diff --git a/src/social/gnunet-social.c b/src/social/gnunet-social.c index b9b26496e..4eb427f57 100644 --- a/src/social/gnunet-social.c +++ b/src/social/gnunet-social.c | |||
@@ -43,6 +43,9 @@ static int op_status; | |||
43 | /** --host-enter */ | 43 | /** --host-enter */ |
44 | static int op_host_enter; | 44 | static int op_host_enter; |
45 | 45 | ||
46 | /** --host-reconnect */ | ||
47 | static int op_host_reconnect; | ||
48 | |||
46 | /** --host-leave */ | 49 | /** --host-leave */ |
47 | static int op_host_leave; | 50 | static int op_host_leave; |
48 | 51 | ||
@@ -52,6 +55,9 @@ static int op_host_announce; | |||
52 | /** --guest-enter */ | 55 | /** --guest-enter */ |
53 | static int op_guest_enter; | 56 | static int op_guest_enter; |
54 | 57 | ||
58 | /** --guest-reconnect */ | ||
59 | static int op_guest_reconnect; | ||
60 | |||
55 | /** --guest-leave */ | 61 | /** --guest-leave */ |
56 | static int op_guest_leave; | 62 | static int op_guest_leave; |
57 | 63 | ||
@@ -82,12 +88,21 @@ static char *opt_place; | |||
82 | /** --ego */ | 88 | /** --ego */ |
83 | static char *opt_ego; | 89 | static char *opt_ego; |
84 | 90 | ||
91 | /** --gns */ | ||
92 | static char *opt_gns; | ||
93 | |||
85 | /** --peer */ | 94 | /** --peer */ |
86 | static char *opt_peer; | 95 | static char *opt_peer; |
87 | 96 | ||
88 | /** --follow */ | 97 | /** --follow */ |
89 | static int opt_follow; | 98 | static int opt_follow; |
90 | 99 | ||
100 | /** --admit */ | ||
101 | static int opt_admit; | ||
102 | |||
103 | /** --refuse */ | ||
104 | static int opt_refuse; | ||
105 | |||
91 | /** --method */ | 106 | /** --method */ |
92 | static char *opt_method; | 107 | static char *opt_method; |
93 | 108 | ||
@@ -119,16 +134,13 @@ struct GNUNET_SCHEDULER_Task *timeout_task; | |||
119 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 134 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
120 | 135 | ||
121 | struct GNUNET_CORE_Handle *core; | 136 | struct GNUNET_CORE_Handle *core; |
122 | struct GNUNET_PeerIdentity peer; | 137 | struct GNUNET_PeerIdentity peer, this_peer; |
123 | 138 | ||
124 | struct GNUNET_SOCIAL_App *app; | 139 | struct GNUNET_SOCIAL_App *app; |
125 | 140 | ||
126 | /** public key of connected place */ | 141 | /** public key of connected place */ |
127 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; | 142 | struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; |
128 | 143 | ||
129 | /** hash of @a place_pub_key */ | ||
130 | struct GNUNET_HashCode place_pub_hash; | ||
131 | |||
132 | struct GNUNET_PSYC_Slicer *slicer; | 144 | struct GNUNET_PSYC_Slicer *slicer; |
133 | 145 | ||
134 | struct GNUNET_SOCIAL_Ego *ego; | 146 | struct GNUNET_SOCIAL_Ego *ego; |
@@ -145,6 +157,15 @@ struct GNUNET_SOCIAL_Place *plc; | |||
145 | static void | 157 | static void |
146 | disconnect () | 158 | disconnect () |
147 | { | 159 | { |
160 | if (hst) | ||
161 | { | ||
162 | GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL); | ||
163 | } | ||
164 | if (gst) | ||
165 | { | ||
166 | GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL); | ||
167 | } | ||
168 | |||
148 | GNUNET_SOCIAL_app_disconnect (app); | 169 | GNUNET_SOCIAL_app_disconnect (app); |
149 | GNUNET_CORE_disconnect (core); | 170 | GNUNET_CORE_disconnect (core); |
150 | GNUNET_SCHEDULER_shutdown (); | 171 | GNUNET_SCHEDULER_shutdown (); |
@@ -163,7 +184,7 @@ timeout (void *cls) | |||
163 | } | 184 | } |
164 | 185 | ||
165 | static void | 186 | static void |
166 | schedule_end (void *cls) | 187 | schedule_success (void *cls) |
167 | { | 188 | { |
168 | ret = 0; | 189 | ret = 0; |
169 | disconnect (); | 190 | disconnect (); |
@@ -171,16 +192,33 @@ schedule_end (void *cls) | |||
171 | 192 | ||
172 | 193 | ||
173 | static void | 194 | static void |
174 | end () | 195 | schedule_fail (void *cls) |
175 | { | 196 | { |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "The end.\n"); | 197 | disconnect (); |
198 | } | ||
177 | 199 | ||
200 | |||
201 | static void | ||
202 | exit_success () | ||
203 | { | ||
178 | if (timeout_task != NULL) | 204 | if (timeout_task != NULL) |
179 | { | 205 | { |
180 | GNUNET_SCHEDULER_cancel (timeout_task); | 206 | GNUNET_SCHEDULER_cancel (timeout_task); |
181 | timeout_task = NULL; | 207 | timeout_task = NULL; |
182 | } | 208 | } |
183 | GNUNET_SCHEDULER_add_now (&schedule_end, NULL); | 209 | GNUNET_SCHEDULER_add_now (&schedule_success, NULL); |
210 | } | ||
211 | |||
212 | |||
213 | static void | ||
214 | exit_fail () | ||
215 | { | ||
216 | if (timeout_task != NULL) | ||
217 | { | ||
218 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
219 | timeout_task = NULL; | ||
220 | } | ||
221 | GNUNET_SCHEDULER_add_now (&schedule_fail, NULL); | ||
184 | } | 222 | } |
185 | 223 | ||
186 | 224 | ||
@@ -192,7 +230,7 @@ host_left () | |||
192 | { | 230 | { |
193 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 231 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
194 | "The host has left the place.\n"); | 232 | "The host has left the place.\n"); |
195 | end (); | 233 | exit_success (); |
196 | } | 234 | } |
197 | 235 | ||
198 | 236 | ||
@@ -251,7 +289,18 @@ notify_data (void *cls, uint16_t *data_size, void *data) | |||
251 | tmit->size -= size; | 289 | tmit->size -= size; |
252 | tmit->data += size; | 290 | tmit->data += size; |
253 | 291 | ||
254 | return 0 == tmit->size ? GNUNET_NO : GNUNET_YES; | 292 | if (0 == tmit->size) |
293 | { | ||
294 | if (op_host_announce || op_guest_talk) | ||
295 | { | ||
296 | exit_success (); | ||
297 | } | ||
298 | return GNUNET_NO; | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | return GNUNET_YES; | ||
303 | } | ||
255 | } | 304 | } |
256 | 305 | ||
257 | 306 | ||
@@ -297,10 +346,15 @@ static void | |||
297 | recv_history_replay_result (void *cls, int64_t result, | 346 | recv_history_replay_result (void *cls, int64_t result, |
298 | const void *data, uint16_t data_size) | 347 | const void *data, uint16_t data_size) |
299 | { | 348 | { |
300 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
301 | "Guest received history replay result: %" PRId64 "\n" | 350 | "Received history replay result: %" PRId64 "\n" |
302 | "%.*s\n", | 351 | "%.*s\n", |
303 | result, data_size, (const char *) data); | 352 | result, data_size, (const char *) data); |
353 | |||
354 | if (op_history_replay || op_history_replay_latest) | ||
355 | { | ||
356 | exit_success (); | ||
357 | } | ||
304 | } | 358 | } |
305 | 359 | ||
306 | 360 | ||
@@ -333,9 +387,13 @@ static void | |||
333 | look_result (void *cls, int64_t result_code, | 387 | look_result (void *cls, int64_t result_code, |
334 | const void *data, uint16_t data_size) | 388 | const void *data, uint16_t data_size) |
335 | { | 389 | { |
336 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
337 | "look_result: %" PRId64 "\n", result_code); | 391 | "Received look result: %" PRId64 "\n", result_code); |
338 | 392 | ||
393 | if (op_look_at || op_look_for) | ||
394 | { | ||
395 | exit_success (); | ||
396 | } | ||
339 | } | 397 | } |
340 | 398 | ||
341 | 399 | ||
@@ -348,7 +406,7 @@ look_var (void *cls, | |||
348 | uint32_t full_value_size) | 406 | uint32_t full_value_size) |
349 | { | 407 | { |
350 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
351 | "guest_look_at_var: %s\n%.*s\n", | 409 | "look_at_var: %s\n%.*s\n", |
352 | name, value_size, (const char *) value); | 410 | name, value_size, (const char *) value); |
353 | } | 411 | } |
354 | 412 | ||
@@ -467,22 +525,33 @@ guest_recv_entry_decision (void *cls, | |||
467 | GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); | 525 | GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size); |
468 | GNUNET_free (pmsg); | 526 | GNUNET_free (pmsg); |
469 | 527 | ||
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 528 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
471 | "%s\n%.*s\n", | 529 | "%s\n%.*s\n", |
472 | method_name, data_size, (const char *) data); | 530 | method_name, data_size, (const char *) data); |
473 | } | 531 | } |
532 | |||
533 | if (op_guest_enter && !opt_follow) | ||
534 | { | ||
535 | exit_success (); | ||
536 | } | ||
474 | } | 537 | } |
475 | 538 | ||
476 | 539 | ||
477 | static void | 540 | static void |
478 | guest_recv_local_enter (void *cls, int result, | 541 | guest_recv_local_enter (void *cls, int result, |
479 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 542 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, |
480 | uint64_t max_message_id) | 543 | uint64_t max_message_id) |
481 | { | 544 | { |
545 | char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); | ||
482 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 546 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
483 | "Guest entered to local place: %d, max_message_id: %" PRIu64 "\n", | 547 | "Guest entered to local place: %s, max_message_id: %" PRIu64 "\n", |
484 | result, max_message_id); | 548 | pub_str, max_message_id); |
485 | GNUNET_assert (0 <= result); | 549 | GNUNET_assert (0 <= result); |
550 | |||
551 | if (op_guest_enter && !opt_follow) | ||
552 | { | ||
553 | exit_success (); | ||
554 | } | ||
486 | } | 555 | } |
487 | 556 | ||
488 | 557 | ||
@@ -501,12 +570,20 @@ guest_enter_msg_create () | |||
501 | 570 | ||
502 | 571 | ||
503 | static void | 572 | static void |
504 | guest_enter (struct GNUNET_PeerIdentity *peer) | 573 | guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key, |
574 | const struct GNUNET_PeerIdentity *peer) | ||
505 | { | 575 | { |
506 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
507 | "Entering to place as guest.\n"); | 577 | "Entering to place as guest.\n"); |
508 | 578 | ||
509 | gst = GNUNET_SOCIAL_guest_enter (app, ego, &place_pub_key, | 579 | if (NULL == ego) |
580 | { | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n"); | ||
582 | exit_fail (); | ||
583 | return; | ||
584 | } | ||
585 | |||
586 | gst = GNUNET_SOCIAL_guest_enter (app, ego, pub_key, | ||
510 | GNUNET_PSYC_SLAVE_JOIN_NONE, | 587 | GNUNET_PSYC_SLAVE_JOIN_NONE, |
511 | peer, 0, NULL, guest_enter_msg_create (), | 588 | peer, 0, NULL, guest_enter_msg_create (), |
512 | slicer_create (), | 589 | slicer_create (), |
@@ -519,7 +596,7 @@ guest_enter (struct GNUNET_PeerIdentity *peer) | |||
519 | static void | 596 | static void |
520 | guest_enter_by_name (const char *gns_name) | 597 | guest_enter_by_name (const char *gns_name) |
521 | { | 598 | { |
522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 599 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
523 | "Entering to place by name as guest.\n"); | 600 | "Entering to place by name as guest.\n"); |
524 | 601 | ||
525 | gst = GNUNET_SOCIAL_guest_enter_by_name (app, ego, gns_name, NULL, | 602 | gst = GNUNET_SOCIAL_guest_enter_by_name (app, ego, gns_name, NULL, |
@@ -546,9 +623,28 @@ host_answer_door (void *cls, | |||
546 | char * | 623 | char * |
547 | nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); | 624 | nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); |
548 | 625 | ||
549 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 626 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
550 | "Entry request: %s\n", nym_str); | 627 | "Entry request: %s\n", nym_str); |
551 | GNUNET_free (nym_str); | 628 | GNUNET_free (nym_str); |
629 | |||
630 | if (opt_admit) | ||
631 | { | ||
632 | struct GNUNET_PSYC_Message * | ||
633 | resp = GNUNET_PSYC_message_create ("_notice_place_admit", env, | ||
634 | DATA2ARG ("Welcome, nym!")); | ||
635 | GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, resp); | ||
636 | GNUNET_free (resp); | ||
637 | } | ||
638 | else if (opt_refuse) | ||
639 | { | ||
640 | struct GNUNET_PSYC_Message * | ||
641 | resp = GNUNET_PSYC_message_create ("_notice_place_refuse", NULL, | ||
642 | DATA2ARG ("Go away!")); | ||
643 | GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, resp); | ||
644 | GNUNET_free (resp); | ||
645 | } | ||
646 | |||
647 | |||
552 | } | 648 | } |
553 | 649 | ||
554 | 650 | ||
@@ -562,7 +658,7 @@ host_farewell (void *cls, | |||
562 | char * | 658 | char * |
563 | nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); | 659 | nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); |
564 | 660 | ||
565 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
566 | "Farewell: %s\n", nym_str); | 662 | "Farewell: %s\n", nym_str); |
567 | GNUNET_free (nym_str); | 663 | GNUNET_free (nym_str); |
568 | } | 664 | } |
@@ -574,10 +670,15 @@ host_entered (void *cls, int result, | |||
574 | uint64_t max_message_id) | 670 | uint64_t max_message_id) |
575 | { | 671 | { |
576 | place_pub_key = *pub_key; | 672 | place_pub_key = *pub_key; |
577 | GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash); | 673 | char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key); |
578 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 674 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
579 | "Entered: %s, max_message_id: %" PRIu64 "\n", | 675 | "Host entered: %s, max_message_id: %" PRIu64 "\n", |
580 | GNUNET_h2s_full (&place_pub_hash), max_message_id); | 676 | pub_str, max_message_id); |
677 | |||
678 | if (op_host_enter && !opt_follow) | ||
679 | { | ||
680 | exit_success (); | ||
681 | } | ||
581 | } | 682 | } |
582 | 683 | ||
583 | 684 | ||
@@ -586,6 +687,13 @@ host_enter () | |||
586 | { | 687 | { |
587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "host_enter()\n"); | 688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "host_enter()\n"); |
588 | 689 | ||
690 | if (NULL == ego) | ||
691 | { | ||
692 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n"); | ||
693 | exit_fail (); | ||
694 | return; | ||
695 | } | ||
696 | |||
589 | hst = GNUNET_SOCIAL_host_enter (app, ego, | 697 | hst = GNUNET_SOCIAL_host_enter (app, ego, |
590 | GNUNET_PSYC_CHANNEL_PRIVATE, | 698 | GNUNET_PSYC_CHANNEL_PRIVATE, |
591 | slicer_create (), host_entered, | 699 | slicer_create (), host_entered, |
@@ -620,8 +728,8 @@ host_reconnected (void *cls, int result, | |||
620 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 728 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, |
621 | uint64_t max_message_id) | 729 | uint64_t max_message_id) |
622 | { | 730 | { |
623 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 731 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
624 | "Host reconnected\n"); | 732 | "Host reconnected.\n"); |
625 | 733 | ||
626 | if (op_host_leave) { | 734 | if (op_host_leave) { |
627 | host_leave (); | 735 | host_leave (); |
@@ -640,8 +748,8 @@ guest_reconnected (void *cls, int result, | |||
640 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, | 748 | const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key, |
641 | uint64_t max_message_id) | 749 | uint64_t max_message_id) |
642 | { | 750 | { |
643 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
644 | "Guest reconnected\n"); | 752 | "Guest reconnected.\n"); |
645 | 753 | ||
646 | if (op_guest_leave) { | 754 | if (op_guest_leave) { |
647 | guest_leave (); | 755 | guest_leave (); |
@@ -661,19 +769,43 @@ guest_reconnected (void *cls, int result, | |||
661 | static void | 769 | static void |
662 | app_connected (void *cls) | 770 | app_connected (void *cls) |
663 | { | 771 | { |
664 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
665 | "App connected: %p\n", cls); | 773 | "App connected: %p\n", cls); |
666 | 774 | ||
667 | if (op_status) | 775 | if (op_status) |
668 | { | 776 | { |
669 | GNUNET_SCHEDULER_add_now (&schedule_end, NULL); | 777 | exit_success (); |
670 | } | 778 | } |
671 | else if (op_host_enter) { | 779 | else if (op_host_enter) |
780 | { | ||
672 | host_enter (); | 781 | host_enter (); |
673 | } | 782 | } |
674 | else if (op_guest_enter) { | 783 | else if (op_guest_enter) |
675 | guest_enter (&peer); | 784 | { |
676 | // FIXME: guest_enter_by_name | 785 | if (opt_gns) |
786 | { | ||
787 | guest_enter_by_name (opt_gns); | ||
788 | } | ||
789 | else | ||
790 | { | ||
791 | if (opt_peer) | ||
792 | { | ||
793 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_peer, | ||
794 | strlen (opt_peer), | ||
795 | &peer.public_key)) | ||
796 | { | ||
797 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
798 | "--peer invalid"); | ||
799 | exit_fail (); | ||
800 | return; | ||
801 | } | ||
802 | } | ||
803 | else | ||
804 | { | ||
805 | peer = this_peer; | ||
806 | } | ||
807 | guest_enter (&place_pub_key, &peer); | ||
808 | } | ||
677 | } | 809 | } |
678 | } | 810 | } |
679 | 811 | ||
@@ -685,17 +817,15 @@ app_recv_host (void *cls, | |||
685 | const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key, | 817 | const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key, |
686 | enum GNUNET_SOCIAL_AppPlaceState place_state) | 818 | enum GNUNET_SOCIAL_AppPlaceState place_state) |
687 | { | 819 | { |
688 | struct GNUNET_HashCode host_pub_hash; | 820 | char *host_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (host_pub_key); |
689 | GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash); | 821 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
690 | char * | 822 | "Host: %s\n", host_pub_str); |
691 | host_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (host_pub_key); | ||
692 | |||
693 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
694 | "Host: %s (%s)\n", | ||
695 | GNUNET_h2s_full (&host_pub_hash), host_pub_str); | ||
696 | GNUNET_free (host_pub_str); | 823 | GNUNET_free (host_pub_str); |
697 | 824 | ||
698 | if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key))) | 825 | if ((op_host_reconnect || op_host_leave || op_host_announce |
826 | || op_history_replay || op_history_replay_latest | ||
827 | || op_look_at || op_look_for) | ||
828 | && 0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key))) | ||
699 | { | 829 | { |
700 | hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, slicer_create (), host_reconnected, | 830 | hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, slicer_create (), host_reconnected, |
701 | host_answer_door, host_farewell, NULL); | 831 | host_answer_door, host_farewell, NULL); |
@@ -711,17 +841,15 @@ app_recv_guest (void *cls, | |||
711 | const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key, | 841 | const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key, |
712 | enum GNUNET_SOCIAL_AppPlaceState place_state) | 842 | enum GNUNET_SOCIAL_AppPlaceState place_state) |
713 | { | 843 | { |
714 | struct GNUNET_HashCode guest_pub_hash; | 844 | char *guest_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (guest_pub_key); |
715 | GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash); | 845 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
716 | char * | 846 | "Guest: %s\n", guest_pub_str); |
717 | guest_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (guest_pub_key); | ||
718 | |||
719 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
720 | "Guest: %s (%s)\n", | ||
721 | GNUNET_h2s_full (&guest_pub_hash), guest_pub_str); | ||
722 | GNUNET_free (guest_pub_str); | 847 | GNUNET_free (guest_pub_str); |
723 | 848 | ||
724 | if (0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key))) | 849 | if ((op_guest_reconnect || op_guest_leave || op_guest_talk |
850 | || op_history_replay || op_history_replay_latest | ||
851 | || op_look_at || op_look_for) | ||
852 | && 0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key))) | ||
725 | { | 853 | { |
726 | gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE, | 854 | gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE, |
727 | slicer_create (), guest_reconnected, NULL); | 855 | slicer_create (), guest_reconnected, NULL); |
@@ -736,12 +864,12 @@ app_recv_ego (void *cls, | |||
736 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key, | 864 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key, |
737 | const char *name) | 865 | const char *name) |
738 | { | 866 | { |
739 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
740 | "Ego: %s\t%s\n", | 868 | "Ego: %s\t%s\n", |
741 | name, GNUNET_CRYPTO_ecdsa_public_key_to_string (pub_key)); | 869 | GNUNET_CRYPTO_ecdsa_public_key_to_string (pub_key), name); |
742 | 870 | ||
743 | if (0 == memcmp (&ego_pub_key, pub_key, sizeof (*pub_key)) | 871 | if (0 == memcmp (&ego_pub_key, pub_key, sizeof (*pub_key)) |
744 | || 0 == strcmp (opt_ego, name)) | 872 | || (NULL != opt_ego && 0 == strcmp (opt_ego, name))) |
745 | { | 873 | { |
746 | ego = e; | 874 | ego = e; |
747 | } | 875 | } |
@@ -767,7 +895,7 @@ app_connect () | |||
767 | static void | 895 | static void |
768 | core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity) | 896 | core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
769 | { | 897 | { |
770 | peer = *my_identity; | 898 | this_peer = *my_identity; |
771 | app_connect (); | 899 | app_connect (); |
772 | } | 900 | } |
773 | 901 | ||
@@ -789,8 +917,16 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
789 | { | 917 | { |
790 | cfg = c; | 918 | cfg = c; |
791 | 919 | ||
792 | if (! (op_status || op_host_enter || op_host_leave || op_host_announce | 920 | if (!opt_method) |
793 | || op_guest_enter || op_guest_leave || op_guest_talk | 921 | opt_method = "message"; |
922 | if (!opt_data) | ||
923 | opt_data = ""; | ||
924 | if (!opt_name) | ||
925 | opt_name = ""; | ||
926 | |||
927 | if (! (op_status | ||
928 | || op_host_enter || op_host_reconnect || op_host_leave || op_host_announce | ||
929 | || op_guest_enter || op_guest_reconnect || op_guest_leave || op_guest_talk | ||
794 | || op_history_replay || op_history_replay_latest | 930 | || op_history_replay || op_history_replay_latest |
795 | || op_look_at || op_look_for)) | 931 | || op_look_at || op_look_for)) |
796 | { | 932 | { |
@@ -802,7 +938,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
802 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout, NULL); | 938 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout, NULL); |
803 | } | 939 | } |
804 | 940 | ||
805 | if (!op_status && !op_host_enter | 941 | if ((op_host_reconnect || op_host_leave || op_host_announce |
942 | || op_guest_reconnect || (op_guest_enter && !opt_gns) | ||
943 | || op_guest_leave || op_guest_talk | ||
944 | || op_history_replay || op_history_replay_latest | ||
945 | || op_look_at || op_look_for) | ||
806 | && (!opt_place | 946 | && (!opt_place |
807 | || GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_place, | 947 | || GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_place, |
808 | strlen (opt_place), | 948 | strlen (opt_place), |
@@ -810,6 +950,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
810 | { | 950 | { |
811 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 951 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
812 | _("--place missing or invalid.\n")); | 952 | _("--place missing or invalid.\n")); |
953 | exit_fail (); | ||
813 | return; | 954 | return; |
814 | } | 955 | } |
815 | 956 | ||
@@ -820,11 +961,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
820 | &ego_pub_key); | 961 | &ego_pub_key); |
821 | } | 962 | } |
822 | 963 | ||
823 | if (opt_peer) | ||
824 | { | ||
825 | // FIXME: peer ID from string | ||
826 | } | ||
827 | |||
828 | core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL, | 964 | core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL, |
829 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | 965 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); |
830 | } | 966 | } |
@@ -854,14 +990,18 @@ main (int argc, char *const *argv) | |||
854 | 990 | ||
855 | /* operations */ | 991 | /* operations */ |
856 | 992 | ||
857 | { 's', "status", NULL, | 993 | { 'u', "status", NULL, |
858 | gettext_noop ("list of egos and subscribed places"), | 994 | gettext_noop ("list of egos and subscribed places"), |
859 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_status }, | 995 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_status }, |
860 | 996 | ||
861 | { 'E', "host-enter", NULL, | 997 | { 'E', "host-enter", NULL, |
862 | gettext_noop ("create a place for nyms to join"), | 998 | gettext_noop ("create a place"), |
863 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_enter }, | 999 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_enter }, |
864 | 1000 | ||
1001 | { 'H', "host-reconnect", NULL, | ||
1002 | gettext_noop ("reconnect to a previously created place"), | ||
1003 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_reconnect }, | ||
1004 | |||
865 | { 'D', "host-leave", NULL, | 1005 | { 'D', "host-leave", NULL, |
866 | gettext_noop ("destroy a place we were hosting"), | 1006 | gettext_noop ("destroy a place we were hosting"), |
867 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_leave }, | 1007 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_leave }, |
@@ -874,6 +1014,10 @@ main (int argc, char *const *argv) | |||
874 | gettext_noop ("join somebody else's place"), | 1014 | gettext_noop ("join somebody else's place"), |
875 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_enter }, | 1015 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_enter }, |
876 | 1016 | ||
1017 | { 'g', "guest-reconnect", NULL, | ||
1018 | gettext_noop ("reconnect to a previously entered place"), | ||
1019 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_reconnect }, | ||
1020 | |||
877 | { 'd', "guest-leave", NULL, | 1021 | { 'd', "guest-leave", NULL, |
878 | gettext_noop ("leave somebody else's place"), | 1022 | gettext_noop ("leave somebody else's place"), |
879 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_leave }, | 1023 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_leave }, |
@@ -890,51 +1034,72 @@ main (int argc, char *const *argv) | |||
890 | gettext_noop ("replay history of latest messages up to the given --limit"), | 1034 | gettext_noop ("replay history of latest messages up to the given --limit"), |
891 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_history_replay_latest }, | 1035 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_history_replay_latest }, |
892 | 1036 | ||
1037 | { 's', "look-for", NULL, | ||
1038 | gettext_noop ("query state matching name prefix"), | ||
1039 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_for }, | ||
1040 | |||
1041 | { 'S', "look-at", NULL, | ||
1042 | gettext_noop ("query state matching exact name"), | ||
1043 | GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_at }, | ||
1044 | |||
1045 | |||
893 | /* options */ | 1046 | /* options */ |
894 | 1047 | ||
895 | { 'A', "app", "APPLICATION_ID", | 1048 | { 'A', "app", "APPLICATION_ID", |
896 | gettext_noop ("application ID to use when connecting"), | 1049 | gettext_noop ("application ID to use when connecting"), |
897 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_app }, | 1050 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_app }, |
898 | 1051 | ||
899 | { 'p', "place", "PUBKEY", | 1052 | { 'p', "place", "PUBKEY", |
900 | gettext_noop ("public key of place"), | 1053 | gettext_noop ("public key of place"), |
901 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_place }, | 1054 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_place }, |
902 | 1055 | ||
903 | { 'P', "peer", "PEER_ID", | 1056 | { 'P', "peer", "PEER_ID", |
904 | gettext_noop ("peer ID for --guest-enter"), | 1057 | gettext_noop ("peer ID for --guest-enter"), |
905 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_peer }, | 1058 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_peer }, |
906 | 1059 | ||
907 | { 'g', "ego", "NAME|PUBKEY", | 1060 | { 'g', "gns", "ADDRESS", |
908 | gettext_noop ("public key of ego"), | 1061 | gettext_noop ("GNS address"), |
909 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_place }, | 1062 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_gns }, |
1063 | |||
1064 | { 'i', "ego", "NAME|PUBKEY", | ||
1065 | gettext_noop ("name or public key of ego"), | ||
1066 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_ego }, | ||
910 | 1067 | ||
911 | { 'f', "follow", NULL, | 1068 | { 'f', "follow", NULL, |
912 | gettext_noop ("wait for incoming messages"), | 1069 | gettext_noop ("wait for incoming messages"), |
913 | GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_follow }, | 1070 | GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_follow }, |
914 | 1071 | ||
1072 | { 'x', "admit", NULL, | ||
1073 | gettext_noop ("respond to entry requests by admitting all guests"), | ||
1074 | GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_admit }, | ||
1075 | |||
1076 | { 'X', "refuse", NULL, | ||
1077 | gettext_noop ("respond to entry requests by refusing all guests"), | ||
1078 | GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_refuse }, | ||
1079 | |||
915 | { 'm', "method", "METHOD_NAME", | 1080 | { 'm', "method", "METHOD_NAME", |
916 | gettext_noop ("method name"), | 1081 | gettext_noop ("method name"), |
917 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_method }, | 1082 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_method }, |
918 | 1083 | ||
919 | { 'b', "body", "DATA", | 1084 | { 'b', "data", "DATA", |
920 | gettext_noop ("message body to transmit"), | 1085 | gettext_noop ("message body to transmit"), |
921 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_data }, | 1086 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_data }, |
922 | 1087 | ||
923 | { 'k', "name", "VAR_NAME", | 1088 | { 'k', "name", "VAR_NAME", |
924 | gettext_noop ("state var name to query"), | 1089 | gettext_noop ("state var name to query"), |
925 | GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_name }, | 1090 | GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_name }, |
926 | 1091 | ||
927 | { 'a', "start", NULL, | 1092 | { 'a', "start", NULL, |
928 | gettext_noop ("start message ID for history replay"), | 1093 | gettext_noop ("start message ID for history replay"), |
929 | GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_start }, | 1094 | GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_start }, |
930 | 1095 | ||
931 | { 'z', "end", NULL, | 1096 | { 'z', "end", NULL, |
932 | gettext_noop ("end message ID for history replay"), | 1097 | gettext_noop ("end message ID for history replay"), |
933 | GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_end }, | 1098 | GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_end }, |
934 | 1099 | ||
935 | { 'n', "limit", NULL, | 1100 | { 'n', "limit", NULL, |
936 | gettext_noop ("number of messages to replay from history"), | 1101 | gettext_noop ("number of messages to replay from history"), |
937 | GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_limit }, | 1102 | GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_limit }, |
938 | 1103 | ||
939 | GNUNET_GETOPT_OPTION_END | 1104 | GNUNET_GETOPT_OPTION_END |
940 | }; | 1105 | }; |
@@ -943,15 +1108,18 @@ main (int argc, char *const *argv) | |||
943 | return 2; | 1108 | return 2; |
944 | 1109 | ||
945 | const char *help = | 1110 | const char *help = |
946 | _ ("Interact with the social service: enter/leave, send/receive messages, access history and state.\n"); | 1111 | _ ("gnunet-social - Interact with the social service: enter/leave, send/receive messages, access history and state.\n"); |
947 | const char *usage = | 1112 | const char *usage = |
948 | "gnunet-social [--status]\n" | 1113 | "gnunet-social [--status]\n" |
949 | "\n" | 1114 | "\n" |
950 | "gnunet-social --host-enter --ego <NAME or PUBKEY> [--listen]\n" | 1115 | "gnunet-social --host-enter --ego <NAME or PUBKEY> [--follow] [--admit | --refuse]\n" |
1116 | "gnunet-social --host-reconnect --place <PUBKEY> [--follow] [--admit | --refuse]\n" | ||
951 | "gnunet-social --host-leave --place <PUBKEY>\n" | 1117 | "gnunet-social --host-leave --place <PUBKEY>\n" |
952 | "gnunet-social --host-announce --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE BODY>\n" | 1118 | "gnunet-social --host-announce --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE BODY>\n" |
953 | "\n" | 1119 | "\n" |
954 | "gnunet-social --guest-enter --place <PUBKEY> --ego <NAME or PUBKEY> [--listen]\n" | 1120 | "gnunet-social --guest-enter --place <PUBKEY> --peer <PEERID> --ego <NAME or PUBKEY> [--follow]\n" |
1121 | "gnunet-social --guest-enter --gns <GNS_ADDRESS> --ego <NAME or PUBKEY> [--follow]\n" | ||
1122 | "gnunet-social --guest-reconnect --place <PUBKEY> [--follow]\n" | ||
955 | "gnunet-social --guest-leave --place <PUBKEY>\n" | 1123 | "gnunet-social --guest-leave --place <PUBKEY>\n" |
956 | "gnunet-social --guest-talk --place <PUBKEY> --method <METHOD_NMAE> --data <DATA>\n" | 1124 | "gnunet-social --guest-talk --place <PUBKEY> --method <METHOD_NMAE> --data <DATA>\n" |
957 | "\n" | 1125 | "\n" |