You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1450 lines
40 KiB

  1. /*
  2. * This file is part of GNUnet
  3. * Copyright (C) 2013 GNUnet e.V.
  4. *
  5. * GNUnet is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU Affero General Public License as published
  7. * by the Free Software Foundation, either version 3 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * GNUnet is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. SPDX-License-Identifier: AGPL3.0-or-later
  18. */
  19. /**
  20. * @file social/test_social.c
  21. * @brief Tests for the Social API.
  22. * @author Gabor X Toth
  23. */
  24. #include <inttypes.h>
  25. #include <gnunet/platform.h>
  26. #include <gnunet/gnunet_crypto_lib.h>
  27. #include <gnunet/gnunet_common.h>
  28. #include <gnunet/gnunet_util_lib.h>
  29. #include <gnunet/gnunet_testing_lib.h>
  30. #include "gnunet_psyc_util_lib.h"
  31. #include "gnunet_social_service.h"
  32. #include <gnunet/gnunet_identity_service.h>
  33. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
  34. #define DATA2ARG(data) data, sizeof (data)
  35. /**
  36. * Return value from 'main'.
  37. */
  38. int res;
  39. struct GNUNET_SOCIAL_App *app;
  40. const char *app_id = "test";
  41. /**
  42. * Handle for task for timeout termination.
  43. */
  44. struct GNUNET_SCHEDULER_Task *end_badly_task;
  45. const struct GNUNET_CONFIGURATION_Handle *cfg;
  46. struct GNUNET_PeerIdentity this_peer;
  47. struct GNUNET_IDENTITY_Handle *id;
  48. const struct GNUNET_IDENTITY_Ego *identity_host_ego;
  49. const struct GNUNET_IDENTITY_Ego *identity_guest_ego;
  50. const struct GNUNET_SOCIAL_Ego *host_ego;
  51. const struct GNUNET_SOCIAL_Ego *guest_ego;
  52. const char *host_name = "Host One";
  53. const char *guest_name = "Guest One";
  54. struct GNUNET_CRYPTO_EddsaPrivateKey *place_key;
  55. struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key;
  56. struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
  57. struct GNUNET_HashCode place_pub_hash;
  58. const struct GNUNET_CRYPTO_EcdsaPublicKey *guest_pub_key;
  59. const struct GNUNET_CRYPTO_EcdsaPublicKey *host_pub_key;
  60. struct GNUNET_PSYC_Slicer *host_slicer;
  61. struct GNUNET_PSYC_Slicer *guest_slicer;
  62. struct GNUNET_SOCIAL_Host *hst;
  63. struct GNUNET_SOCIAL_Guest *gst;
  64. struct GNUNET_SOCIAL_Place *hst_plc;
  65. struct GNUNET_SOCIAL_Place *gst_plc;
  66. struct GNUNET_SOCIAL_Nym *nym_eject;
  67. struct GuestEnterMessage
  68. {
  69. struct GNUNET_PSYC_Message *msg;
  70. const char *method_name;
  71. struct GNUNET_PSYC_Environment *env;
  72. void *data;
  73. uint16_t data_size;
  74. } guest_enter_msg;
  75. struct TransmitClosure
  76. {
  77. struct GNUNET_SOCIAL_Announcement *host_ann;
  78. struct GNUNET_SOCIAL_TalkRequest *guest_talk;
  79. struct GNUNET_PSYC_Environment *env;
  80. char *data[16];
  81. uint8_t data_delay[16];
  82. uint8_t data_count;
  83. uint8_t paused;
  84. uint8_t n;
  85. } tmit;
  86. struct ResultClosure {
  87. uint32_t n;
  88. } mod_foo_bar_rcls;
  89. uint8_t join_req_count;
  90. struct GNUNET_PSYC_Message *join_resp;
  91. uint32_t counter;
  92. uint8_t is_guest_nym_added = GNUNET_NO;
  93. uint8_t is_host_reconnected = GNUNET_NO;
  94. uint8_t is_guest_reconnected = GNUNET_NO;
  95. enum
  96. {
  97. TEST_NONE = 0,
  98. TEST_IDENTITIES_CREATE = 1,
  99. TEST_HOST_ENTER = 2,
  100. TEST_GUEST_ENTER = 3,
  101. TEST_HOST_ANSWER_DOOR_REFUSE = 4,
  102. TEST_GUEST_RECV_ENTRY_DCSN_REFUSE = 5,
  103. TEST_HOST_ANSWER_DOOR_ADMIT = 6,
  104. TEST_GUEST_RECV_ENTRY_DCSN_ADMIT = 7,
  105. TEST_HOST_ANNOUNCE = 8,
  106. TEST_HOST_ANNOUNCE_END = 9,
  107. TEST_GUEST_TALK = 10,
  108. TEST_HOST_ANNOUNCE2 = 11,
  109. TEST_HOST_ANNOUNCE2_END = 12,
  110. TEST_GUEST_HISTORY_REPLAY = 13,
  111. TEST_GUEST_HISTORY_REPLAY_LATEST = 14,
  112. TEST_GUEST_LOOK_AT = 15,
  113. TEST_GUEST_LOOK_FOR = 16,
  114. TEST_GUEST_LEAVE = 17,
  115. TEST_ZONE_ADD_PLACE = 18,
  116. TEST_GUEST_ENTER_BY_NAME = 19,
  117. TEST_RECONNECT = 20,
  118. TEST_GUEST_LEAVE2 = 21,
  119. TEST_HOST_LEAVE = 22,
  120. } test;
  121. static void
  122. schedule_guest_leave (void *cls);
  123. static void
  124. host_answer_door (void *cls,
  125. struct GNUNET_SOCIAL_Nym *nym,
  126. const char *method_name,
  127. struct GNUNET_PSYC_Environment *env,
  128. const void *data,
  129. size_t data_size);
  130. static void
  131. host_enter ();
  132. static void
  133. guest_init ();
  134. static void
  135. guest_enter ();
  136. static void
  137. guest_enter_by_name ();
  138. static void
  139. guest_talk ();
  140. static void
  141. host_announce2 ();
  142. /**
  143. * Terminate the test case (failure).
  144. *
  145. * @param cls NULL
  146. */
  147. static void
  148. end_badly (void *cls)
  149. {
  150. end_badly_task = NULL;
  151. GNUNET_SCHEDULER_shutdown ();
  152. res = 2;
  153. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  154. "Test FAILED.\n");
  155. }
  156. /**
  157. * Terminate the test case (failure).
  158. *
  159. * @param cls NULL
  160. */
  161. static void
  162. end_shutdown (void *cls)
  163. {
  164. if (NULL != id)
  165. {
  166. GNUNET_IDENTITY_disconnect (id);
  167. id = NULL;
  168. }
  169. if (NULL != guest_slicer)
  170. {
  171. GNUNET_PSYC_slicer_destroy (guest_slicer);
  172. guest_slicer = NULL;
  173. }
  174. if (NULL != host_slicer)
  175. {
  176. GNUNET_PSYC_slicer_destroy (host_slicer);
  177. host_slicer = NULL;
  178. }
  179. if (NULL != end_badly_task)
  180. {
  181. GNUNET_SCHEDULER_cancel (end_badly_task);
  182. end_badly_task = NULL;
  183. }
  184. if (NULL != gst)
  185. {
  186. GNUNET_SOCIAL_guest_leave (gst, NULL, NULL, NULL);
  187. gst = NULL;
  188. gst_plc = NULL;
  189. }
  190. if (NULL != hst)
  191. {
  192. GNUNET_SOCIAL_host_leave (hst, NULL, NULL, NULL);
  193. hst = NULL;
  194. hst_plc = NULL;
  195. }
  196. GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
  197. }
  198. /**
  199. * Terminate the test case (success).
  200. *
  201. * @param cls NULL
  202. */
  203. static void
  204. end_normally (void *cls)
  205. {
  206. GNUNET_SCHEDULER_shutdown ();
  207. res = 0;
  208. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Test PASSED.\n");
  209. }
  210. /**
  211. * Finish the test case (successfully).
  212. */
  213. static void
  214. end ()
  215. {
  216. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  217. "Test #%u: Ending tests.\n", test);
  218. if (end_badly_task != NULL)
  219. {
  220. GNUNET_SCHEDULER_cancel (end_badly_task);
  221. end_badly_task = NULL;
  222. }
  223. GNUNET_SCHEDULER_add_now (&end_normally, NULL);
  224. }
  225. static void
  226. transmit_resume (void *cls)
  227. {
  228. struct TransmitClosure *tmit = cls;
  229. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  230. "Test #%u: Transmission resumed.\n", test);
  231. if (NULL != tmit->host_ann)
  232. GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
  233. else
  234. GNUNET_SOCIAL_guest_talk_resume (tmit->guest_talk);
  235. }
  236. static int
  237. notify_data (void *cls, uint16_t *data_size, void *data)
  238. {
  239. struct TransmitClosure *tmit = cls;
  240. if (NULL != tmit->env)
  241. {
  242. GNUNET_PSYC_env_destroy (tmit->env);
  243. tmit->env = NULL;
  244. }
  245. if (0 == tmit->data_count)
  246. {
  247. *data_size = 0;
  248. return GNUNET_YES;
  249. }
  250. uint16_t size = strlen (tmit->data[tmit->n]);
  251. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  252. "Test #%u: Transmit notify data: %u bytes available, "
  253. "processing fragment %u/%u (size %u).\n",
  254. test, *data_size, tmit->n + 1, tmit->data_count, size);
  255. if (*data_size < size)
  256. {
  257. *data_size = 0;
  258. GNUNET_assert (0);
  259. return GNUNET_SYSERR;
  260. }
  261. if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
  262. {
  263. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  264. "Test #%u: Transmission paused.\n", test);
  265. tmit->paused = GNUNET_YES;
  266. GNUNET_SCHEDULER_add_delayed (
  267. GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
  268. tmit->data_delay[tmit->n]),
  269. &transmit_resume, tmit);
  270. *data_size = 0;
  271. return GNUNET_NO;
  272. }
  273. tmit->paused = GNUNET_NO;
  274. *data_size = size;
  275. GNUNET_memcpy (data, tmit->data[tmit->n], size);
  276. return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
  277. }
  278. static void
  279. host_left ()
  280. {
  281. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  282. "Test #%u: The host has left the place.\n", test);
  283. end ();
  284. }
  285. static void
  286. schedule_host_leave (void *cls)
  287. {
  288. test = TEST_HOST_LEAVE;
  289. GNUNET_SOCIAL_host_leave (hst, NULL, &host_left, NULL);
  290. hst = NULL;
  291. hst_plc = NULL;
  292. }
  293. static void
  294. host_farewell2 (void *cls,
  295. const struct GNUNET_SOCIAL_Nym *nym,
  296. struct GNUNET_PSYC_Environment *env)
  297. {
  298. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  299. "Nym left the place again.\n");
  300. GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
  301. }
  302. static void
  303. host_reconnected (void *cls, int result,
  304. const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
  305. uint64_t max_message_id)
  306. {
  307. place_pub_key = *home_pub_key;
  308. GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
  309. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  310. "Test #%u: Host reconnected to place %s\n",
  311. test, GNUNET_h2s (&place_pub_hash));
  312. is_host_reconnected = GNUNET_YES;
  313. if (GNUNET_YES == is_guest_reconnected)
  314. {
  315. GNUNET_assert (NULL != gst);
  316. GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
  317. }
  318. }
  319. static void
  320. guest_reconnected (void *cls, int result,
  321. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  322. uint64_t max_message_id)
  323. {
  324. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  325. "Test #%u: Guest reconnected to place: %d\n",
  326. test, result);
  327. GNUNET_assert (0 <= result);
  328. is_guest_reconnected = GNUNET_YES;
  329. if (GNUNET_YES == is_host_reconnected)
  330. {
  331. GNUNET_assert (NULL != gst);
  332. GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
  333. }
  334. }
  335. static void
  336. app_connected (void *cls)
  337. {
  338. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  339. "Test #%u: App connected: %p\n", test, cls);
  340. }
  341. static void
  342. app_recv_host (void *cls,
  343. struct GNUNET_SOCIAL_HostConnection *hconn,
  344. struct GNUNET_SOCIAL_Ego *ego,
  345. const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
  346. enum GNUNET_SOCIAL_AppPlaceState place_state)
  347. {
  348. struct GNUNET_HashCode host_pub_hash;
  349. GNUNET_CRYPTO_hash (host_pub_key,
  350. sizeof (*host_pub_key),
  351. &host_pub_hash);
  352. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  353. "Test #%u: Got app host place notification: %s\n",
  354. test,
  355. GNUNET_h2s (&host_pub_hash));
  356. if (test == TEST_RECONNECT)
  357. {
  358. if (0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
  359. {
  360. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  361. "Test #%u: Reconnecting to host place: %s\n",
  362. test, GNUNET_h2s (&host_pub_hash));
  363. hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, host_slicer,
  364. &host_reconnected,
  365. &host_answer_door,
  366. &host_farewell2,
  367. NULL);
  368. }
  369. }
  370. }
  371. static void
  372. app_recv_guest (void *cls,
  373. struct GNUNET_SOCIAL_GuestConnection *gconn,
  374. struct GNUNET_SOCIAL_Ego *ego,
  375. const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
  376. enum GNUNET_SOCIAL_AppPlaceState place_state)
  377. {
  378. struct GNUNET_HashCode guest_pub_hash;
  379. GNUNET_CRYPTO_hash (guest_pub_key,
  380. sizeof (*guest_pub_key),
  381. &guest_pub_hash);
  382. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  383. "Test #%u: Got app guest place notification: %s\n",
  384. test, GNUNET_h2s (&guest_pub_hash));
  385. if (test == TEST_RECONNECT)
  386. {
  387. if (0 == memcmp (&place_pub_key,
  388. guest_pub_key,
  389. sizeof (*guest_pub_key)))
  390. {
  391. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  392. "Test #%u: Reconnecting to guest place: %s\n",
  393. test, GNUNET_h2s (&guest_pub_hash));
  394. gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn,
  395. GNUNET_PSYC_SLAVE_JOIN_NONE,
  396. guest_slicer,
  397. &guest_reconnected,
  398. NULL);
  399. GNUNET_assert (NULL != gst);
  400. }
  401. }
  402. }
  403. static void
  404. enter_if_ready ()
  405. {
  406. if (NULL == host_ego || NULL == guest_ego)
  407. {
  408. return;
  409. }
  410. host_enter ();
  411. guest_init ();
  412. }
  413. static void
  414. app_recv_ego (void *cls,
  415. struct GNUNET_SOCIAL_Ego *ego,
  416. const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
  417. const char *name)
  418. {
  419. char *ego_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (ego_pub_key);
  420. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  421. "Test #%u: Got app ego notification: %p %s %s\n",
  422. test, ego, name, ego_pub_str);
  423. GNUNET_free (ego_pub_str);
  424. if (NULL != strstr (name, host_name))
  425. {
  426. host_ego = ego;
  427. host_pub_key = ego_pub_key;
  428. if (TEST_IDENTITIES_CREATE == test)
  429. {
  430. enter_if_ready ();
  431. }
  432. else
  433. {
  434. GNUNET_assert (TEST_RECONNECT == test);
  435. }
  436. }
  437. else if (NULL != strstr (name, guest_name))
  438. {
  439. guest_ego = ego;
  440. guest_pub_key = ego_pub_key;
  441. if (TEST_IDENTITIES_CREATE == test)
  442. {
  443. enter_if_ready ();
  444. }
  445. else
  446. {
  447. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  448. "test = %d\n",
  449. test);
  450. GNUNET_assert (TEST_RECONNECT == test);
  451. }
  452. }
  453. }
  454. static void
  455. schedule_reconnect (void *cls)
  456. {
  457. test = TEST_RECONNECT;
  458. GNUNET_SOCIAL_host_disconnect (hst, NULL, NULL);
  459. GNUNET_SOCIAL_guest_disconnect (gst, NULL, NULL);
  460. hst = NULL;
  461. gst = NULL;
  462. GNUNET_SOCIAL_app_disconnect (app, NULL, NULL);
  463. app = GNUNET_SOCIAL_app_connect (cfg, app_id,
  464. &app_recv_ego,
  465. &app_recv_host,
  466. &app_recv_guest,
  467. &app_connected,
  468. NULL);
  469. }
  470. static void
  471. host_recv_zone_add_place_result (void *cls, int64_t result,
  472. const void *data, uint16_t data_size)
  473. {
  474. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  475. "Test #%u: Zone add place result: %" PRId64 " (%.*s).\n",
  476. test, result, data_size, (const char *) data);
  477. GNUNET_assert (GNUNET_YES == result);
  478. GNUNET_assert (GNUNET_YES == is_guest_nym_added);
  479. guest_enter_by_name ();
  480. }
  481. static void
  482. zone_add_place ()
  483. {
  484. test = TEST_ZONE_ADD_PLACE;
  485. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  486. "Test #%u: Adding place to zone.\n", test);
  487. GNUNET_SOCIAL_zone_add_place (app, host_ego, "home", "let.me*in!",
  488. &place_pub_key, &this_peer, 1, &this_peer,
  489. GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
  490. host_recv_zone_add_place_result, app);
  491. }
  492. static void
  493. host_farewell (void *cls,
  494. const struct GNUNET_SOCIAL_Nym *nym,
  495. struct GNUNET_PSYC_Environment *env)
  496. {
  497. const struct GNUNET_CRYPTO_EcdsaPublicKey *
  498. nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
  499. char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
  500. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  501. "Test #%u: Farewell: nym %s (%s) has left the place.\n",
  502. test, GNUNET_h2s (GNUNET_SOCIAL_nym_get_pub_key_hash (nym)), str);
  503. GNUNET_free (str);
  504. GNUNET_assert (1 == GNUNET_PSYC_env_get_count (env));
  505. if (0 != memcmp (guest_pub_key, nym_key, sizeof (*nym_key)))
  506. {
  507. str = GNUNET_CRYPTO_ecdsa_public_key_to_string (guest_pub_key);
  508. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  509. "Test #%u: Farewell: nym does not match guest: %s\n",
  510. test, str);
  511. GNUNET_free (str);
  512. GNUNET_assert (0);
  513. }
  514. zone_add_place ();
  515. }
  516. static void
  517. guest_left (void *cls)
  518. {
  519. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  520. "Test #%u: The guest has left the place.\n", test);
  521. }
  522. static void
  523. guest_leave ()
  524. {
  525. if (test < TEST_RECONNECT)
  526. test = TEST_GUEST_LEAVE;
  527. else
  528. test = TEST_GUEST_LEAVE2;
  529. struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
  530. GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
  531. "_notice_place_leave", DATA2ARG ("Leaving."));
  532. GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
  533. GNUNET_PSYC_env_destroy (env);
  534. gst = NULL;
  535. gst_plc = NULL;
  536. }
  537. static void
  538. schedule_guest_leave (void *cls)
  539. {
  540. guest_leave ();
  541. }
  542. static void
  543. guest_look_for_result (void *cls,
  544. int64_t result_code,
  545. const void *data,
  546. uint16_t data_size)
  547. {
  548. struct ResultClosure *rcls = cls;
  549. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  550. "Test #%u: guest_look_for_result: %" PRId64 "\n",
  551. test, result_code);
  552. GNUNET_assert (GNUNET_OK == result_code);
  553. GNUNET_assert (6 == rcls->n);
  554. GNUNET_free (rcls);
  555. GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
  556. }
  557. static void
  558. guest_look_for_var (void *cls,
  559. const struct GNUNET_MessageHeader *mod,
  560. const char *name,
  561. const void *value,
  562. uint32_t value_size,
  563. uint32_t full_value_size)
  564. {
  565. struct ResultClosure *rcls = cls;
  566. rcls->n++;
  567. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  568. "Test #%u: guest_look_for_var: %s\n%.*s\n",
  569. test, name, value_size, (const char *) value);
  570. }
  571. static void
  572. guest_look_for ()
  573. {
  574. test = TEST_GUEST_LOOK_FOR;
  575. struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
  576. GNUNET_SOCIAL_place_look_for (gst_plc, "_foo", guest_look_for_var, guest_look_for_result, rcls);
  577. }
  578. static void
  579. guest_look_at_result (void *cls, int64_t result_code,
  580. const void *data, uint16_t data_size)
  581. {
  582. struct ResultClosure *rcls = cls;
  583. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  584. "Test #%u: guest_look_at_result: %" PRId64 "\n",
  585. test, result_code);
  586. GNUNET_assert (GNUNET_OK == result_code);
  587. GNUNET_assert (1 == rcls->n);
  588. GNUNET_free (rcls);
  589. guest_look_for ();
  590. }
  591. static void
  592. guest_look_at_var (void *cls,
  593. const struct GNUNET_MessageHeader *mod,
  594. const char *name,
  595. const void *value,
  596. uint32_t value_size,
  597. uint32_t full_value_size)
  598. {
  599. struct ResultClosure *rcls = cls;
  600. rcls->n++;
  601. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  602. "Test #%u: guest_look_at_var: %s\n%.*s\n",
  603. test ,name, value_size, (const char *) value);
  604. }
  605. static void
  606. guest_look_at ()
  607. {
  608. test = TEST_GUEST_LOOK_AT;
  609. struct ResultClosure *rcls = GNUNET_malloc (sizeof (*rcls));
  610. GNUNET_SOCIAL_place_look_at (gst_plc, "_foo_bar", guest_look_at_var, guest_look_at_result, rcls);
  611. }
  612. static void
  613. guest_recv_history_replay_latest_result (void *cls, int64_t result,
  614. const void *data, uint16_t data_size)
  615. {
  616. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  617. "Test #%u: Guest received latest history replay result "
  618. "(%" PRIu32 " messages, %" PRId64 " fragments):\n"
  619. "%.*s\n",
  620. test, counter, result, data_size, (const char *) data);
  621. //GNUNET_assert (2 == counter); /* message count */
  622. //GNUNET_assert (7 == result); /* fragment count */
  623. guest_look_at ();
  624. }
  625. static void
  626. guest_history_replay_latest ()
  627. {
  628. test = TEST_GUEST_HISTORY_REPLAY_LATEST;
  629. counter = 0;
  630. GNUNET_SOCIAL_place_history_replay_latest (gst_plc, 3, "",
  631. GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
  632. guest_slicer,
  633. &guest_recv_history_replay_latest_result,
  634. NULL);
  635. }
  636. static void
  637. guest_recv_history_replay_result (void *cls, int64_t result,
  638. const void *data, uint16_t data_size)
  639. {
  640. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  641. "Test #%u: Guest received history replay result: %" PRId64 "\n"
  642. "%.*s\n",
  643. test, result, data_size, (const char *) data);
  644. // GNUNET_assert (2 == counter); /* message count */
  645. // GNUNET_assert (7 == result); /* fragment count */
  646. guest_history_replay_latest ();
  647. }
  648. static void
  649. guest_history_replay ()
  650. {
  651. test = TEST_GUEST_HISTORY_REPLAY;
  652. counter = 0;
  653. GNUNET_SOCIAL_place_history_replay (gst_plc, 1, 3, "",
  654. GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
  655. guest_slicer,
  656. &guest_recv_history_replay_result,
  657. NULL);
  658. }
  659. static void
  660. guest_recv_method (void *cls,
  661. const struct GNUNET_PSYC_MessageHeader *msg,
  662. const struct GNUNET_PSYC_MessageMethod *meth,
  663. uint64_t message_id,
  664. const char *method_name)
  665. {
  666. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  667. "Test #%u: Guest received method for message ID %" PRIu64 ":\n"
  668. "%s (flags: %x)\n",
  669. test, message_id, method_name, ntohl (meth->flags));
  670. /** @todo FIXME: check message */
  671. }
  672. static void
  673. guest_recv_modifier (void *cls,
  674. const struct GNUNET_PSYC_MessageHeader *msg,
  675. const struct GNUNET_MessageHeader *pmsg,
  676. uint64_t message_id,
  677. enum GNUNET_PSYC_Operator oper,
  678. const char *name,
  679. const void *value,
  680. uint16_t value_size,
  681. uint16_t full_value_size)
  682. {
  683. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  684. "Test #%u: Guest received modifier for message ID %" PRIu64 ":\n"
  685. "%c%s: %.*s (size: %u)\n",
  686. test, message_id, oper, name, value_size, (const char *) value, value_size);
  687. /** @todo FIXME: check modifier */
  688. }
  689. static void
  690. guest_recv_mod_foo_bar (void *cls,
  691. const struct GNUNET_PSYC_MessageHeader *msg,
  692. const struct GNUNET_MessageHeader *pmsg,
  693. uint64_t message_id,
  694. enum GNUNET_PSYC_Operator oper,
  695. const char *name,
  696. const void *value,
  697. uint16_t value_size,
  698. uint16_t full_value_size)
  699. {
  700. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  701. "Test #%u: Guest received modifier matching _foo_bar for message ID %" PRIu64 ":\n"
  702. "%c%s: %.*s (size: %u)\n",
  703. test, message_id, oper, name, value_size, (const char *) value, value_size);
  704. struct ResultClosure *rc = cls;
  705. rc->n++;
  706. /** @todo FIXME: check modifier */
  707. }
  708. static void
  709. guest_recv_data (void *cls,
  710. const struct GNUNET_PSYC_MessageHeader *msg,
  711. const struct GNUNET_MessageHeader *pmsg,
  712. uint64_t message_id,
  713. const void *data,
  714. uint16_t data_size)
  715. {
  716. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  717. "Test #%u: Guest received data for message ID %" PRIu64 ":\n"
  718. "%.*s\n",
  719. test, message_id, data_size, (const char *) data);
  720. /** @todo FIXME: check data */
  721. }
  722. static void
  723. guest_recv_eom (void *cls,
  724. const struct GNUNET_PSYC_MessageHeader *msg,
  725. const struct GNUNET_MessageHeader *pmsg,
  726. uint64_t message_id,
  727. uint8_t is_cancelled)
  728. {
  729. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  730. "Test #%u: Guest received end of message ID %" PRIu64
  731. ", cancelled: %u\n",
  732. test, message_id, is_cancelled);
  733. switch (test)
  734. {
  735. case TEST_HOST_ANNOUNCE:
  736. test = TEST_HOST_ANNOUNCE_END;
  737. break;
  738. case TEST_HOST_ANNOUNCE_END:
  739. guest_talk ();
  740. break;
  741. case TEST_HOST_ANNOUNCE2:
  742. test = TEST_HOST_ANNOUNCE2_END;
  743. break;
  744. case TEST_HOST_ANNOUNCE2_END:
  745. guest_history_replay ();
  746. break;
  747. case TEST_GUEST_HISTORY_REPLAY:
  748. case TEST_GUEST_HISTORY_REPLAY_LATEST:
  749. counter++;
  750. break;
  751. default:
  752. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
  753. GNUNET_assert (0);
  754. }
  755. }
  756. static void
  757. host_recv_method (void *cls,
  758. const struct GNUNET_PSYC_MessageHeader *msg,
  759. const struct GNUNET_PSYC_MessageMethod *meth,
  760. uint64_t message_id,
  761. const char *method_name)
  762. {
  763. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  764. "Test #%u: Host received method for message ID %" PRIu64 ":\n"
  765. "%s\n",
  766. test, message_id, method_name);
  767. /** @todo FIXME: check message */
  768. }
  769. static void
  770. host_recv_modifier (void *cls,
  771. const struct GNUNET_PSYC_MessageHeader *msg,
  772. const struct GNUNET_MessageHeader *pmsg,
  773. uint64_t message_id,
  774. enum GNUNET_PSYC_Operator oper,
  775. const char *name,
  776. const void *value,
  777. uint16_t value_size,
  778. uint16_t full_value_size)
  779. {
  780. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  781. "Test #%u: Host received modifier for message ID %" PRIu64 ":\n"
  782. "%c%s: %.*s\n",
  783. test, message_id, oper, name, value_size, (const char *) value);
  784. }
  785. static void
  786. host_recv_data (void *cls,
  787. const struct GNUNET_PSYC_MessageHeader *msg,
  788. const struct GNUNET_MessageHeader *pmsg,
  789. uint64_t message_id,
  790. const void *data,
  791. uint16_t data_size)
  792. {
  793. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  794. "Test #%u: Host received data for message ID %" PRIu64 ":\n"
  795. "%.*s\n",
  796. test, message_id, data_size, (const char *) data);
  797. }
  798. static void
  799. host_recv_eom (void *cls,
  800. const struct GNUNET_PSYC_MessageHeader *msg,
  801. const struct GNUNET_MessageHeader *pmsg,
  802. uint64_t message_id,
  803. uint8_t is_cancelled)
  804. {
  805. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  806. "Test #%u: Host received end of message ID %" PRIu64
  807. ", cancelled: %u\n",
  808. test, message_id, is_cancelled);
  809. switch (test)
  810. {
  811. case TEST_HOST_ANNOUNCE:
  812. test = TEST_HOST_ANNOUNCE_END;
  813. break;
  814. case TEST_HOST_ANNOUNCE_END:
  815. guest_talk ();
  816. break;
  817. case TEST_HOST_ANNOUNCE2:
  818. test = TEST_HOST_ANNOUNCE2_END;
  819. break;
  820. case TEST_HOST_ANNOUNCE2_END:
  821. guest_history_replay ();
  822. break;
  823. case TEST_GUEST_TALK:
  824. host_announce2 ();
  825. break;
  826. default:
  827. if (TEST_GUEST_LEAVE <= test)
  828. break;
  829. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid test: #%u\n", test);
  830. GNUNET_assert (0);
  831. }
  832. }
  833. static void
  834. guest_talk ()
  835. {
  836. test = TEST_GUEST_TALK;
  837. tmit = (struct TransmitClosure) {};
  838. tmit.env = GNUNET_PSYC_env_create ();
  839. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  840. "_bar_foo", DATA2ARG ("one two three"));
  841. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  842. "_bar_baz", DATA2ARG ("four five"));
  843. tmit.data[0] = "zzz xxx yyy ";
  844. tmit.data[1] = "zyx wvu tsr qpo.\n";
  845. tmit.data_delay[1] = 1;
  846. tmit.data[2] = "testing ten nine eight.\n";
  847. tmit.data_count = 3;
  848. tmit.guest_talk
  849. = GNUNET_SOCIAL_guest_talk (gst, "_converse_guest", tmit.env,
  850. &notify_data, &tmit,
  851. GNUNET_SOCIAL_TALK_NONE);
  852. }
  853. static void
  854. host_announce ()
  855. {
  856. test = TEST_HOST_ANNOUNCE;
  857. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  858. "Test #%u: Host announcement.\n", test);
  859. tmit = (struct TransmitClosure) {};
  860. tmit.env = GNUNET_PSYC_env_create ();
  861. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  862. "_foo", DATA2ARG ("bar baz"));
  863. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  864. "_foo_bar", DATA2ARG ("foo bar"));
  865. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  866. "_foo_bar_baz", DATA2ARG ("foo bar baz"));
  867. tmit.data[0] = "aaa bbb ccc ";
  868. tmit.data[1] = "abc def ghi jkl.\n";
  869. tmit.data_delay[1] = 1;
  870. tmit.data[2] = "testing one two three ";
  871. tmit.data[3] = "four five.\n";
  872. tmit.data_count = 4;
  873. tmit.host_ann
  874. = GNUNET_SOCIAL_host_announce (hst, "_converse_host", tmit.env,
  875. &notify_data, &tmit,
  876. GNUNET_SOCIAL_ANNOUNCE_NONE);
  877. }
  878. static void
  879. host_announce2 ()
  880. {
  881. GNUNET_assert (2 == mod_foo_bar_rcls.n);
  882. GNUNET_PSYC_slicer_modifier_remove (guest_slicer, "_foo_bar",
  883. guest_recv_mod_foo_bar);
  884. test = TEST_HOST_ANNOUNCE2;
  885. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  886. "Test #%u: Host announcement 2.\n", test);
  887. tmit = (struct TransmitClosure) {};
  888. tmit.env = GNUNET_PSYC_env_create ();
  889. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  890. "_foo2", DATA2ARG ("BAR BAZ"));
  891. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  892. "_foo2_bar", DATA2ARG ("FOO BAR"));
  893. GNUNET_PSYC_env_add (tmit.env, GNUNET_PSYC_OP_ASSIGN,
  894. "_foo2_bar_baz", DATA2ARG ("FOO BAR BAZ"));
  895. tmit.data[0] = "AAA BBB CCC ";
  896. tmit.data[1] = "ABC DEF GHI JKL.\n";
  897. tmit.data[2] = "TESTING ONE TWO THREE.\n";
  898. tmit.data_count = 3;
  899. tmit.host_ann
  900. = GNUNET_SOCIAL_host_announce (hst, "_converse_host_two", tmit.env,
  901. &notify_data, &tmit,
  902. GNUNET_SOCIAL_ANNOUNCE_NONE);
  903. }
  904. static void
  905. guest_recv_entry_decision (void *cls,
  906. int is_admitted,
  907. const struct GNUNET_PSYC_Message *entry_msg)
  908. {
  909. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  910. "Test #%u: Guest received entry decision (try %u): %d.\n",
  911. test, join_req_count, is_admitted);
  912. if (NULL != entry_msg)
  913. {
  914. struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
  915. const char *method_name = NULL;
  916. const void *data = NULL;
  917. uint16_t data_size = 0;
  918. struct GNUNET_PSYC_MessageHeader *
  919. pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
  920. GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
  921. GNUNET_free (pmsg);
  922. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  923. "%s\n%.*s\n",
  924. method_name, data_size, (const char *) data);
  925. /** @todo FIXME: check response message */
  926. }
  927. switch (test)
  928. {
  929. case TEST_GUEST_RECV_ENTRY_DCSN_REFUSE:
  930. GNUNET_assert (GNUNET_NO == is_admitted);
  931. test = TEST_HOST_ANSWER_DOOR_ADMIT;
  932. GNUNET_SOCIAL_guest_disconnect (gst, &guest_enter, NULL);
  933. break;
  934. case TEST_GUEST_RECV_ENTRY_DCSN_ADMIT:
  935. GNUNET_assert (GNUNET_YES == is_admitted);
  936. host_announce ();
  937. break;
  938. case TEST_GUEST_ENTER_BY_NAME:
  939. GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
  940. break;
  941. default:
  942. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
  943. GNUNET_assert (0);
  944. }
  945. }
  946. static void
  947. host_answer_door (void *cls,
  948. struct GNUNET_SOCIAL_Nym *nym,
  949. const char *method_name,
  950. struct GNUNET_PSYC_Environment *env,
  951. const void *data,
  952. size_t data_size)
  953. {
  954. join_req_count++;
  955. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  956. "Test #%u: Host received entry request from guest (try %u).\n",
  957. (uint8_t) test, join_req_count);
  958. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  959. "%s\n%.*s\n",
  960. method_name, (int) data_size, (const char *) data);
  961. switch (test)
  962. {
  963. case TEST_HOST_ANSWER_DOOR_REFUSE:
  964. test = TEST_GUEST_RECV_ENTRY_DCSN_REFUSE;
  965. join_resp = GNUNET_PSYC_message_create ("_notice_place_refuse", env,
  966. DATA2ARG ("Go away!"));
  967. GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, join_resp);
  968. break;
  969. case TEST_HOST_ANSWER_DOOR_ADMIT:
  970. test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
  971. // fall through
  972. case TEST_GUEST_ENTER_BY_NAME:
  973. join_resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
  974. DATA2ARG ("Welcome, nym!"));
  975. GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
  976. break;
  977. default:
  978. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid test: #%u\n", test);
  979. GNUNET_assert (0);
  980. }
  981. }
  982. static void
  983. guest_recv_local_enter (void *cls, int result,
  984. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  985. uint64_t max_message_id)
  986. {
  987. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  988. "Test #%u: Guest entered local place: %d\n",
  989. test, result);
  990. GNUNET_assert (GNUNET_OK == result);
  991. }
  992. static void
  993. guest_enter ()
  994. {
  995. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  996. "Test #%u: Entering place as guest.\n", test);
  997. struct GuestEnterMessage *emsg = &guest_enter_msg;
  998. emsg->method_name = "_request_enter";
  999. emsg->env = GNUNET_PSYC_env_create ();
  1000. GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
  1001. "_abc", "abc def", 7);
  1002. GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
  1003. "_abc_def", "abc def ghi", 11);
  1004. emsg->data = "let me in";
  1005. emsg->data_size = strlen (emsg->data) + 1;
  1006. emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
  1007. emsg->data, emsg->data_size);
  1008. gst = GNUNET_SOCIAL_guest_enter (app, guest_ego, &place_pub_key,
  1009. GNUNET_PSYC_SLAVE_JOIN_NONE,
  1010. &this_peer, 0, NULL, emsg->msg, guest_slicer,
  1011. guest_recv_local_enter,
  1012. guest_recv_entry_decision, NULL);
  1013. gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
  1014. GNUNET_SOCIAL_place_msg_proc_set (gst_plc, "_converse",
  1015. GNUNET_SOCIAL_MSG_PROC_SAVE);
  1016. }
  1017. static void
  1018. guest_enter_by_name ()
  1019. {
  1020. test = TEST_GUEST_ENTER_BY_NAME;
  1021. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1022. "Test #%u: Entering place by name as guest.\n", test);
  1023. struct GuestEnterMessage *emsg = &guest_enter_msg;
  1024. emsg->method_name = "_request_enter";
  1025. emsg->env = GNUNET_PSYC_env_create ();
  1026. GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
  1027. "_abc", "abc def", 7);
  1028. GNUNET_PSYC_env_add (emsg->env, GNUNET_PSYC_OP_ASSIGN,
  1029. "_abc_def", "abc def ghi", 11);
  1030. emsg->data = "let me in";
  1031. emsg->data_size = strlen (emsg->data) + 1;
  1032. emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
  1033. emsg->data, emsg->data_size);
  1034. gst = GNUNET_SOCIAL_guest_enter_by_name (app, guest_ego,
  1035. "home.host.gnu", "let.me*in!",
  1036. emsg->msg, guest_slicer,
  1037. guest_recv_local_enter,
  1038. guest_recv_entry_decision, NULL);
  1039. gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
  1040. }
  1041. static void
  1042. app_recv_zone_add_nym_result (void *cls, int64_t result,
  1043. const void *data, uint16_t data_size)
  1044. {
  1045. GNUNET_assert (GNUNET_YES == result);
  1046. is_guest_nym_added = GNUNET_YES;
  1047. }
  1048. static void
  1049. guest_init ()
  1050. {
  1051. guest_pub_key = GNUNET_SOCIAL_ego_get_pub_key (guest_ego);
  1052. guest_slicer = GNUNET_PSYC_slicer_create ();
  1053. GNUNET_PSYC_slicer_method_add (guest_slicer, "", NULL,
  1054. guest_recv_method, guest_recv_modifier,
  1055. guest_recv_data, guest_recv_eom, NULL);
  1056. GNUNET_PSYC_slicer_modifier_add (guest_slicer, "_foo_bar",
  1057. guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
  1058. test = TEST_HOST_ANSWER_DOOR_REFUSE;
  1059. GNUNET_SOCIAL_zone_add_nym (app, guest_ego, "host", host_pub_key,
  1060. GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
  1061. app_recv_zone_add_nym_result, NULL);
  1062. }
  1063. static void
  1064. id_host_created (void *cls, const char *emsg)
  1065. {
  1066. if (NULL != emsg)
  1067. {
  1068. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  1069. "Test #%u: Could not create host identity: %s\n",
  1070. test, emsg);
  1071. #if ! DEBUG_TEST_SOCIAL
  1072. GNUNET_assert (0);
  1073. #endif
  1074. }
  1075. }
  1076. static void
  1077. id_guest_created (void *cls, const char *emsg)
  1078. {
  1079. if (NULL != emsg)
  1080. {
  1081. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  1082. "Test #%u: Could not create guest identity: %s\n",
  1083. test, emsg);
  1084. #if ! DEBUG_TEST_SOCIAL
  1085. GNUNET_assert (0);
  1086. #endif
  1087. }
  1088. //if (NULL != guest_ego)
  1089. // guest_init ();
  1090. }
  1091. static void
  1092. host_entered (void *cls, int result,
  1093. const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
  1094. uint64_t max_message_id)
  1095. {
  1096. place_pub_key = *home_pub_key;
  1097. GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
  1098. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1099. "Test #%u: Host entered place %s\n",
  1100. test, GNUNET_h2s (&place_pub_hash));
  1101. guest_enter ();
  1102. }
  1103. static void
  1104. host_enter ()
  1105. {
  1106. host_slicer = GNUNET_PSYC_slicer_create ();
  1107. GNUNET_PSYC_slicer_method_add (host_slicer, "", NULL,
  1108. host_recv_method, host_recv_modifier,
  1109. host_recv_data, host_recv_eom, NULL);
  1110. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1111. "Test #%u: Entering place as host.\n", test);
  1112. test = TEST_HOST_ENTER;
  1113. hst = GNUNET_SOCIAL_host_enter (app, host_ego,
  1114. GNUNET_PSYC_CHANNEL_PRIVATE,
  1115. host_slicer, host_entered,
  1116. host_answer_door, host_farewell, NULL);
  1117. hst_plc = GNUNET_SOCIAL_host_get_place (hst);
  1118. GNUNET_SOCIAL_place_msg_proc_set (hst_plc, "_converse",
  1119. GNUNET_SOCIAL_MSG_PROC_RELAY);
  1120. }
  1121. static void
  1122. start_app_if_ready ()
  1123. {
  1124. if (NULL == identity_host_ego || NULL == identity_guest_ego)
  1125. {
  1126. return;
  1127. }
  1128. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1129. "starting app...\n");
  1130. app = GNUNET_SOCIAL_app_connect (cfg,
  1131. app_id,
  1132. app_recv_ego,
  1133. app_recv_host,
  1134. app_recv_guest,
  1135. app_connected,
  1136. NULL);
  1137. }
  1138. static void
  1139. identity_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego,
  1140. void **ctx, const char *name)
  1141. {
  1142. if (NULL != ego)
  1143. {
  1144. if (ego == identity_host_ego)
  1145. {
  1146. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1147. "Host ego deleted\n");
  1148. }
  1149. else if (ego == identity_guest_ego)
  1150. {
  1151. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1152. "Guest ego deleted\n");
  1153. }
  1154. else if (0 == strcmp (name, host_name))
  1155. {
  1156. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1157. "Created ego %s\n",
  1158. name);
  1159. identity_host_ego = ego;
  1160. start_app_if_ready ();
  1161. }
  1162. else if (0 == strcmp (name, guest_name))
  1163. {
  1164. GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
  1165. "Created guest ego %s\n",
  1166. name);
  1167. identity_guest_ego = ego;
  1168. start_app_if_ready ();
  1169. }
  1170. }
  1171. }
  1172. /**
  1173. * Main function of the test, run from scheduler.
  1174. *
  1175. * @param cls NULL
  1176. * @param cfg configuration we use (also to connect to Social service)
  1177. * @param peer handle to access more of the peer (not used)
  1178. */
  1179. static void
  1180. #if DEBUG_TEST_SOCIAL
  1181. run (void *cls, char *const *args, const char *cfgfile,
  1182. const struct GNUNET_CONFIGURATION_Handle *c)
  1183. #else
  1184. run (void *cls,
  1185. const struct GNUNET_CONFIGURATION_Handle *c,
  1186. struct GNUNET_TESTING_Peer *peer)
  1187. #endif
  1188. {
  1189. cfg = c;
  1190. res = 1;
  1191. end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
  1192. &end_badly, NULL);
  1193. GNUNET_SCHEDULER_add_shutdown (&end_shutdown,
  1194. NULL);
  1195. GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
  1196. id = GNUNET_IDENTITY_connect (cfg, &identity_ego_cb, NULL);
  1197. test = TEST_IDENTITIES_CREATE;
  1198. GNUNET_IDENTITY_create (id, host_name, &id_host_created, NULL);
  1199. GNUNET_IDENTITY_create (id, guest_name, &id_guest_created, NULL);
  1200. }
  1201. int
  1202. main (int argc, char *argv[])
  1203. {
  1204. res = 1;
  1205. #if DEBUG_TEST_SOCIAL
  1206. const struct GNUNET_GETOPT_CommandLineOption opts[] = {
  1207. GNUNET_GETOPT_OPTION_END
  1208. };
  1209. if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
  1210. "test-social [options]",
  1211. opts, &run, NULL))
  1212. return 1;
  1213. #else
  1214. if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
  1215. return 1;
  1216. #endif
  1217. return res;
  1218. }
  1219. /* end of test_social.c */