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.
 
 
 
 

1345 lines
39 KiB

  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Gabor X Toth
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * Social service; implements social interactions through the PSYC service.
  22. */
  23. /** @defgroup social Social service
  24. Social interactions through the PSYC service.
  25. # Overview
  26. The social service provides an API for social interactions based on a one-to-many messaging model.
  27. It manages subscriptions of applications to places, provides messaging functionality in places,
  28. allows access to the local message history and manages the GNS zone of _egos_ (user identities).
  29. The service stores private and public keys of subscribed places, as well as files received in subscribed places.
  30. # Concepts and terminology
  31. ## Ego, Nym
  32. An _ego_ is an identity of a user, a private-public key pair.
  33. A _nym_ is an identity of another user in the network, identified by its public key.
  34. Each user can have multiple identities.
  35. struct GNUNET_SOCIAL_Ego and struct GNUNET_SOCIAL_Nym represents one of these identities.
  36. ## Place, Host, Guest
  37. A _place_ is where social interactions happen. It is owned and created by an _ego_.
  38. Creating a new place happens by an _ego_ entering a new place as a _host_,
  39. where _guests_ can enter later to receive messages sent to the place.
  40. A place is identified by its public key.
  41. - struct GNUNET_SOCIAL_Host represents a place entered as host,
  42. - struct GNUNET_SOCIAL_Guest is used for a place entered as guest.
  43. - A struct GNUNET_SOCIAL_Place can be obtained for both a host and guest place
  44. using GNUNET_SOCIAL_host_get_place() and GNUNET_SOCIAL_guest_get_place()
  45. and can be used with API functions common to hosts and guests.
  46. ## History
  47. Messages sent to places are stored locally by the PSYCstore service, and can be queried any time.
  48. GNUNET_SOCIAL_history_replay_latest() retrieves the latest N messages sent to the place,
  49. while GNUNET_SOCIAL_history_replay() is used to query a given message ID range.
  50. ## GNU Name System
  51. The GNU Name System is used for assigning human-readable names to nyms and places.
  52. There's a _GNS zone_ corresponding to each _nym_.
  53. An _ego_ can publish PKEY and PLACE records in its own zone, pointing to nyms and places, respectively.
  54. ## Announcement, talk request
  55. The host can _announce_ messages to the place, using GNUNET_SOCIAL_host_announce().
  56. Guests can send _talk_ requests to the host, using GNUNET_SOCIAL_guest_talk().
  57. The host receives talk requests of guests and can _relay_ them to the place,
  58. or process it using a message handler function.
  59. # Using the API
  60. ## Connecting to the service
  61. A client first establishes an _application connection_ to the service using
  62. GNUNET_SOCIAL_app_connect() providing its _application ID_, then receives the
  63. public keys of subscribed places and available egos in response.
  64. ## Reconnecting to places
  65. Then the application can reconnect to its subscribed places by establishing
  66. _place connections_ with GNUNET_SOCIAL_host_enter_reconnect() and
  67. GNUNET_SOCIAL_guest_enter_reconnect().
  68. ## Subscribing to a place
  69. Entering and subscribing a new host or guest place is done using
  70. GNUNET_SOCIAL_host_enter() and GNUNET_SOCIAL_guest_enter().
  71. ## Disconnecting from a place
  72. An application can disconnect from a place while the social service keeps its
  73. network connection active, using GNUNET_SOCIAL_host_disconnect() and
  74. GNUNET_SOCIAL_guest_disconnect().
  75. ## Leaving a place
  76. To permanently leave a place, see GNUNET_SOCIAL_host_leave() and GNUNET_SOCIAL_guest_leave().
  77. When leaving a place its network connections are closed and all applications are unsubscribed from the place.
  78. # Message methods
  79. ## _converse
  80. Human conversation in a private or public place.
  81. ### Environment
  82. #### _id_reply
  83. Message ID this message is in reply to.
  84. #### _id_thread
  85. Thread ID, the first message ID in the thread.
  86. #### _nym_author
  87. Nym of the author.
  88. FIXME: Are nyms a different data type from egos and person entities?
  89. Do they have a different format than any other entity address?
  90. Questions and thoughts on how to fix this in "questions.org"
  91. #### _sig_author
  92. Signature of the message body and its variables by the author.
  93. ### Data
  94. Message body.
  95. ## _notice_place
  96. Notification about a place.
  97. TODO: Applications can decide to auto-subscribe to certain places,
  98. e.g. files under a given size.
  99. ### Environment
  100. #### Using GNS
  101. ##### _gns_place
  102. GNS name of the place in a globally unique .zkey zone
  103. FIXME: A custom _gns PSYC data type should be avoidable by parsing
  104. and interpreting PSYC uniforms appropriately.
  105. Thoughts on this in "questions.org"
  106. #### Without GNS
  107. ##### _key_pub_place
  108. Public key of place
  109. FIXME: _key_pub can't be the data type for GNUnet-specific cryptographic
  110. addressing. Questions and thoughts on how to fix this in "questions.org"
  111. ##### _peer_origin
  112. Peer ID of origin
  113. ##### _list_peer_relays
  114. List of peer IDs of relays
  115. ## _notice_place_file
  116. Notification about a place hosting a file.
  117. ### Environment
  118. The environment of _notice_place above, plus the following:
  119. #### _size_file
  120. Size of file
  121. #### _type_file
  122. MIME type of file
  123. #### _name_file
  124. Name of file
  125. #### _description_file
  126. Description of file
  127. ## _file
  128. Messages with a _file method contain a file,
  129. which is saved to disk upon reception at the following location:
  130. $GNUNET_DATA_HOME/social/files/<H(place_pub)>/<H(message_id)>
  131. ### Environment
  132. #### _size_file
  133. Size of file
  134. #### _type_file
  135. MIME type of file
  136. #### _name_file
  137. Name of file
  138. #### _description_file
  139. Description of file
  140. @{
  141. */
  142. #ifndef GNUNET_SOCIAL_SERVICE_H
  143. #define GNUNET_SOCIAL_SERVICE_H
  144. #ifdef __cplusplus
  145. extern "C"
  146. {
  147. #if 0 /* keep Emacsens' auto-indent happy */
  148. }
  149. #endif
  150. #endif
  151. #include <stdint.h>
  152. #include "gnunet_util_lib.h"
  153. #include "gnunet_psyc_util_lib.h"
  154. #include "gnunet_identity_service.h"
  155. #include "gnunet_namestore_service.h"
  156. #include "gnunet_psyc_service.h"
  157. /**
  158. * Version number of GNUnet Social API.
  159. */
  160. #define GNUNET_SOCIAL_VERSION 0x00000000
  161. /**
  162. * Maximum size of client ID including '\0' terminator.
  163. */
  164. #define GNUNET_SOCIAL_APP_MAX_ID_SIZE 256
  165. enum GNUNET_SOCIAL_MsgProcFlags {
  166. GNUNET_SOCIAL_MSG_PROC_NONE = 0,
  167. GNUNET_SOCIAL_MSG_PROC_RELAY = 1,
  168. GNUNET_SOCIAL_MSG_PROC_SAVE= 2,
  169. };
  170. /**
  171. * Handle for an application.
  172. */
  173. struct GNUNET_SOCIAL_App;
  174. /**
  175. * Handle for an ego (own identity)
  176. */
  177. struct GNUNET_SOCIAL_Ego;
  178. /**
  179. * Handle for a pseudonym of another user in the network.
  180. */
  181. struct GNUNET_SOCIAL_Nym;
  182. /**
  183. * Handle for a place where social interactions happen.
  184. */
  185. struct GNUNET_SOCIAL_Place;
  186. /**
  187. * Host handle for a place that we entered.
  188. */
  189. struct GNUNET_SOCIAL_Host;
  190. /**
  191. * Guest handle for place that we entered.
  192. */
  193. struct GNUNET_SOCIAL_Guest;
  194. /**
  195. * Handle that can be used to reconnect to a place as host.
  196. */
  197. struct GNUNET_SOCIAL_HostConnection;
  198. /**
  199. * Handle that can be used to reconnect to a place as guest.
  200. */
  201. struct GNUNET_SOCIAL_GuestConnection;
  202. /**
  203. * Notification about an available identity.
  204. *
  205. * @param cls
  206. * Closure.
  207. * @param pub_key
  208. * Public key of ego.
  209. * @param name
  210. * Name of ego.
  211. */
  212. typedef void
  213. (*GNUNET_SOCIAL_AppEgoCallback) (void *cls,
  214. struct GNUNET_SOCIAL_Ego *ego,
  215. const struct GNUNET_CRYPTO_EcdsaPublicKey *ego_pub_key,
  216. const char *name);
  217. /**
  218. * Entry status of a place per application.
  219. */
  220. enum GNUNET_SOCIAL_AppPlaceState
  221. {
  222. /**
  223. * The place was once entered by the ego, but left since.
  224. * It's possible to establish a local connection to the place
  225. * without re-entering to fetch history from the PSYCstore.
  226. * @see enum GNUNET_PSYC_SlaveJoinFlags and GNUNET_SOCIAL_guest_enter()
  227. */
  228. GNUNET_SOCIAL_PLACE_STATE_ARCHIVED = 0,
  229. /**
  230. * The place is entered by the ego,
  231. * but this application is not subscribed to it.
  232. */
  233. GNUNET_SOCIAL_PLACE_STATE_ENTERED = 1,
  234. /**
  235. * The place is entered by the ego and
  236. * and this application is subscribed to it.
  237. */
  238. GNUNET_SOCIAL_PLACE_STATE_SUBSCRIBED = 2,
  239. };
  240. /**
  241. * Called after receiving initial list of egos and places.
  242. */
  243. typedef void
  244. (*GNUNET_SOCIAL_AppConnectedCallback) (void *cls);
  245. /**
  246. * Notification about a home.
  247. *
  248. * @param cls
  249. * Closure.
  250. * @param hconn
  251. * Host connection, to be used with GNUNET_SOCIAL_host_enter_reconnect()
  252. * @param ego
  253. * Ego used to enter the place.
  254. * @param place_pub_key
  255. * Public key of the place.
  256. * @param place_state
  257. * @see enum GNUNET_SOCIAL_AppPlaceState
  258. */
  259. typedef void
  260. (*GNUNET_SOCIAL_AppHostPlaceCallback) (void *cls,
  261. struct GNUNET_SOCIAL_HostConnection *hconn,
  262. struct GNUNET_SOCIAL_Ego *ego,
  263. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  264. enum GNUNET_SOCIAL_AppPlaceState place_state);
  265. /**
  266. * Notification about a place.
  267. *
  268. * @param cls
  269. * Closure.
  270. * @param gconn
  271. * Guest connection, to be used with GNUNET_SOCIAL_guest_enter_reconnect()
  272. * @param ego
  273. * Ego used to enter the place.
  274. * @param place_pub_key
  275. * Public key of the place.
  276. * @param place_state
  277. * @see enum GNUNET_SOCIAL_AppPlaceState
  278. */
  279. typedef void
  280. (*GNUNET_SOCIAL_AppGuestPlaceCallback) (void *cls,
  281. struct GNUNET_SOCIAL_GuestConnection *gconn,
  282. struct GNUNET_SOCIAL_Ego *ego,
  283. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  284. enum GNUNET_SOCIAL_AppPlaceState place_state);
  285. /**
  286. * Establish application connection to the social service.
  287. *
  288. * The @host_cb and @guest_cb functions are
  289. * initially called for each entered places,
  290. * then later each time a new place is entered with the current app ID.
  291. *
  292. * @param cfg
  293. * Configuration.
  294. * @param ego_cb
  295. * Function to notify about an available ego.
  296. * @param host_cb
  297. * Function to notify about a place entered as host.
  298. * @param guest_cb
  299. * Function to notify about a place entered as guest.
  300. * @param cls
  301. * Closure for the callbacks.
  302. *
  303. * @return Handle that can be used to stop listening.
  304. */
  305. struct GNUNET_SOCIAL_App *
  306. GNUNET_SOCIAL_app_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  307. const char *id,
  308. GNUNET_SOCIAL_AppEgoCallback ego_cb,
  309. GNUNET_SOCIAL_AppHostPlaceCallback host_cb,
  310. GNUNET_SOCIAL_AppGuestPlaceCallback guest_cb,
  311. GNUNET_SOCIAL_AppConnectedCallback connected_cb,
  312. void *cls);
  313. /**
  314. * Disconnect app.
  315. *
  316. * @param app
  317. * Application handle.
  318. * @param disconnect_cb
  319. * Disconnect callback.
  320. * @param disconnect_cls
  321. * Disconnect closure.
  322. */
  323. void
  324. GNUNET_SOCIAL_app_disconnect (struct GNUNET_SOCIAL_App *app,
  325. GNUNET_ContinuationCallback disconnect_cb,
  326. void *disconnect_cls);
  327. /**
  328. * Get the public key of @a ego.
  329. *
  330. * @param ego
  331. * Ego.
  332. *
  333. * @return Public key of ego.
  334. */
  335. const struct GNUNET_CRYPTO_EcdsaPublicKey *
  336. GNUNET_SOCIAL_ego_get_pub_key (const struct GNUNET_SOCIAL_Ego *ego);
  337. /**
  338. * Get the name of @a ego.
  339. *
  340. * @param ego
  341. * Ego.
  342. *
  343. * @return Public key of @a ego.
  344. */
  345. const char *
  346. GNUNET_SOCIAL_ego_get_name (const struct GNUNET_SOCIAL_Ego *ego);
  347. /**
  348. * Get the public key of a @a nym.
  349. *
  350. * Suitable, for example, to be used with GNUNET_SOCIAL_zone_add_nym().
  351. *
  352. * @param nym
  353. * Pseudonym to map to a cryptographic identifier.
  354. *
  355. * @return Public key of nym.
  356. */
  357. const struct GNUNET_CRYPTO_EcdsaPublicKey *
  358. GNUNET_SOCIAL_nym_get_pub_key (const struct GNUNET_SOCIAL_Nym *nym);
  359. /**
  360. * Get the hash of the public key of a @a nym.
  361. *
  362. * @param nym
  363. * Pseudonym to map to a cryptographic identifier.
  364. *
  365. * @return Hash of the public key of nym.
  366. */
  367. const struct GNUNET_HashCode *
  368. GNUNET_SOCIAL_nym_get_pub_key_hash (const struct GNUNET_SOCIAL_Nym *nym);
  369. /**
  370. * Function called asking for nym to be admitted to the place.
  371. *
  372. * Should call either GNUNET_SOCIAL_host_admit() or
  373. * GNUNET_SOCIAL_host_reject_entry() (possibly asynchronously). If this host
  374. * cannot decide, it is fine to call neither function, in which case hopefully
  375. * some other host of the place exists that will make the decision. The @a nym
  376. * reference remains valid until the #GNUNET_SOCIAL_FarewellCallback is invoked
  377. * for it.
  378. *
  379. * @param cls
  380. * Closure.
  381. * @param nym
  382. * Handle for the user who wants to enter.
  383. * @param method_name
  384. * Method name in the entry request.
  385. * @param variable_count
  386. * Number of elements in the @a variables array.
  387. * @param variables
  388. * Variables present in the message.
  389. * @param data
  390. * Payload given on enter (e.g. a password).
  391. * @param data_size
  392. * Number of bytes in @a data.
  393. */
  394. typedef void
  395. (*GNUNET_SOCIAL_AnswerDoorCallback) (void *cls,
  396. struct GNUNET_SOCIAL_Nym *nym,
  397. const char *method_name,
  398. struct GNUNET_PSYC_Environment *env,
  399. const void *data,
  400. size_t data_size);
  401. /**
  402. * Function called when a @a nym leaves the place.
  403. *
  404. * This is also called if the @a nym was never given permission to enter
  405. * (i.e. the @a nym stopped asking to get in).
  406. *
  407. * @param cls
  408. * Closure.
  409. * @param nym
  410. * Handle for the user who left.
  411. */
  412. typedef void
  413. (*GNUNET_SOCIAL_FarewellCallback) (void *cls,
  414. const struct GNUNET_SOCIAL_Nym *nym,
  415. struct GNUNET_PSYC_Environment *env);
  416. /**
  417. * Function called after the host entered a home.
  418. *
  419. * @param cls
  420. * Closure.
  421. * @param result
  422. * #GNUNET_OK on success, or
  423. * #GNUNET_SYSERR on error.
  424. * @param place_pub_key
  425. * Public key of home.
  426. * @param max_message_id
  427. * Last message ID sent to the channel.
  428. * Or 0 if no messages have been sent to the place yet.
  429. */
  430. typedef void
  431. (*GNUNET_SOCIAL_HostEnterCallback) (void *cls, int result,
  432. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  433. uint64_t max_message_id);
  434. /**
  435. * Enter a place as host.
  436. *
  437. * A place is created upon first entering, and it is active until permanently
  438. * left using GNUNET_SOCIAL_host_leave().
  439. *
  440. * @param cfg
  441. * Configuration to contact the social service.
  442. * @param ego
  443. * Identity of the host.
  444. * @param place_key
  445. * Private-public key pair of the place.
  446. * NULL for ephemeral places.
  447. * @param policy
  448. * Policy specifying entry and history restrictions for the place.
  449. * @param slicer
  450. * Slicer to handle incoming messages.
  451. * @param enter_cb
  452. * Function called when the place is entered and ready to use.
  453. * @param answer_door_cb
  454. * Function to handle new nyms that want to enter.
  455. * @param farewell_cb
  456. * Function to handle departing nyms.
  457. * @param cls
  458. * Closure for the callbacks.
  459. *
  460. * @return Handle for the host.
  461. */
  462. struct GNUNET_SOCIAL_Host *
  463. GNUNET_SOCIAL_host_enter (const struct GNUNET_SOCIAL_App *app,
  464. const struct GNUNET_SOCIAL_Ego *ego,
  465. enum GNUNET_PSYC_Policy policy,
  466. struct GNUNET_PSYC_Slicer *slicer,
  467. GNUNET_SOCIAL_HostEnterCallback enter_cb,
  468. GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
  469. GNUNET_SOCIAL_FarewellCallback farewell_cb,
  470. void *cls);
  471. /**
  472. * Reconnect to an already entered place as host.
  473. *
  474. * @param hconn
  475. * Host connection handle.
  476. * @see GNUNET_SOCIAL_app_connect() & GNUNET_SOCIAL_AppHostPlaceCallback()
  477. * @param slicer
  478. * Slicer to handle incoming messages.
  479. * @param enter_cb
  480. * Function called when the place is entered and ready to use.
  481. * @param answer_door_cb
  482. * Function to handle new nyms that want to enter.
  483. * @param farewell_cb
  484. * Function to handle departing nyms.
  485. * @param cls
  486. * Closure for the callbacks.
  487. *
  488. * @return Handle for the host.
  489. */
  490. struct GNUNET_SOCIAL_Host *
  491. GNUNET_SOCIAL_host_enter_reconnect (struct GNUNET_SOCIAL_HostConnection *hconn,
  492. struct GNUNET_PSYC_Slicer *slicer,
  493. GNUNET_SOCIAL_HostEnterCallback enter_cb,
  494. GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
  495. GNUNET_SOCIAL_FarewellCallback farewell_cb,
  496. void *cls);
  497. /**
  498. * Decision whether to admit @a nym into the place or refuse entry.
  499. *
  500. * @param hst
  501. * Host of the place.
  502. * @param nym
  503. * Handle for the entity that wanted to enter.
  504. * @param is_admitted
  505. * #GNUNET_YES if @a nym is admitted,
  506. * #GNUNET_NO if @a nym is refused entry,
  507. * #GNUNET_SYSERR if we cannot answer the request.
  508. * @param entry_resp
  509. * Entry response message, or NULL.
  510. * @return #GNUNET_OK on success,
  511. * #GNUNET_SYSERR if the message is too large.
  512. */
  513. int
  514. GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
  515. struct GNUNET_SOCIAL_Nym *nym,
  516. int is_admitted,
  517. const struct GNUNET_PSYC_Message *entry_resp);
  518. /**
  519. * Throw @a nym out of the place.
  520. *
  521. * Sends a _notice_place_leave announcement to the home.
  522. *
  523. * The @a nym reference will remain valid until the
  524. * #GNUNET_SOCIAL_FarewellCallback is invoked,
  525. * which should be very soon after this call.
  526. *
  527. * @param host
  528. * Host of the place.
  529. * @param nym
  530. * Handle for the entity to be ejected.
  531. * @param env
  532. * Environment for the message or NULL.
  533. * _nym is set to @e nym regardless whether an @e env is provided.
  534. */
  535. void
  536. GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host,
  537. const struct GNUNET_SOCIAL_Nym *nym,
  538. struct GNUNET_PSYC_Environment *env);
  539. /**
  540. * Flags for announcements by a host.
  541. */
  542. enum GNUNET_SOCIAL_AnnounceFlags
  543. {
  544. GNUNET_SOCIAL_ANNOUNCE_NONE = 0,
  545. /**
  546. * Whether this announcement removes all objects from the place.
  547. *
  548. * New objects can be still added to the now empty place using the @e env
  549. * parameter of the same announcement.
  550. */
  551. GNUNET_SOCIAL_ANNOUNCE_CLEAR_OBJECTS = 1 << 0
  552. };
  553. /**
  554. * Handle for an announcement request.
  555. */
  556. struct GNUNET_SOCIAL_Announcement;
  557. /**
  558. * Send a message to all nyms that are present in the place.
  559. *
  560. * This function is restricted to the host. Nyms can only send requests
  561. * to the host who can decide to relay it to everyone in the place.
  562. *
  563. * @param host
  564. * Host of the place.
  565. * @param method_name
  566. * Method to use for the announcement.
  567. * @param env
  568. * Environment containing variables for the message and operations
  569. * on objects of the place.
  570. * Has to remain available until the first call to @a notify_data.
  571. * Can be NULL.
  572. * @param notify_data
  573. * Function to call to get the payload of the announcement.
  574. * @param notify_data_cls
  575. * Closure for @a notify.
  576. * @param flags
  577. * Flags for this announcement.
  578. *
  579. * @return NULL on error (another announcement already in progress?).
  580. */
  581. struct GNUNET_SOCIAL_Announcement *
  582. GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *host,
  583. const char *method_name,
  584. const struct GNUNET_PSYC_Environment *env,
  585. GNUNET_PSYC_TransmitNotifyData notify_data,
  586. void *notify_data_cls,
  587. enum GNUNET_SOCIAL_AnnounceFlags flags);
  588. /**
  589. * Resume transmitting announcement.
  590. *
  591. * @param a
  592. * The announcement to resume.
  593. */
  594. void
  595. GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a);
  596. /**
  597. * Cancel announcement.
  598. *
  599. * @param a
  600. * The announcement to cancel.
  601. */
  602. void
  603. GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a);
  604. /**
  605. * Allow relaying messages from guests matching a given @a method_prefix.
  606. *
  607. * @param host
  608. * The host.
  609. * @param method_prefix
  610. * Method prefix to allow.
  611. */
  612. void
  613. GNUNET_SOCIAL_host_relay_allow_method (struct GNUNET_SOCIAL_Host *host,
  614. const char *method_prefix);
  615. /**
  616. * Allow relaying changes to objects of the place.
  617. *
  618. * Only applies to messages with an allowed method name.
  619. * @see GNUNET_SCOIAL_host_relay_allow_method()
  620. *
  621. * @param host
  622. * The host.
  623. * @param object_prefix
  624. * Object prefix to allow modifying.
  625. */
  626. void
  627. GNUNET_SOCIAL_host_relay_allow_method (struct GNUNET_SOCIAL_Host *host,
  628. const char *object_prefix);
  629. /**
  630. * Stop relaying messages from guests.
  631. *
  632. * Remove all allowed relay rules.
  633. *
  634. *
  635. *
  636. */
  637. void
  638. GNUNET_SOCIAL_host_relay_stop (struct GNUNET_SOCIAL_Host *host);
  639. /**
  640. * Obtain handle for a hosted place.
  641. *
  642. * The returned handle can be used to access the place API.
  643. *
  644. * @param host
  645. * Handle for the host.
  646. *
  647. * @return Handle for the hosted place, valid as long as @a host is valid.
  648. */
  649. struct GNUNET_SOCIAL_Place *
  650. GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *host);
  651. /**
  652. * Disconnect from a home.
  653. *
  654. * Invalidates host handle.
  655. *
  656. * @param hst
  657. * The host to disconnect.
  658. * @param disconnect_cb
  659. * Function called after disconnected from the service.
  660. * @param cls
  661. * Closure for @a disconnect_cb.
  662. */
  663. void
  664. GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
  665. GNUNET_ContinuationCallback disconnect_cb,
  666. void *cls);
  667. /**
  668. * Stop hosting a home.
  669. *
  670. * Sends a _notice_place_closing announcement to the home.
  671. * Invalidates host handle.
  672. *
  673. * @param hst
  674. * Host leaving.
  675. * @param env
  676. * Environment for the message or NULL.
  677. * @param disconnect_cb
  678. * Function called after the host left the place
  679. * and disconnected from the service.
  680. * @param cls
  681. * Closure for @a disconnect_cb.
  682. */
  683. void
  684. GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
  685. const struct GNUNET_PSYC_Environment *env,
  686. GNUNET_ContinuationCallback disconnect_cb,
  687. void *cls);
  688. /**
  689. * Function called after the guest entered the local copy of the place.
  690. *
  691. * History and object query functions can be used after this call,
  692. * but new messages can't be sent or received.
  693. *
  694. * @param cls
  695. * Closure.
  696. * @param result
  697. * #GNUNET_OK on success, or
  698. * #GNUNET_SYSERR on error, e.g. could not connect to the service, or
  699. * could not resolve GNS name.
  700. * @param place_pub_key
  701. * Public key of place.
  702. * @param max_message_id
  703. * Last message ID sent to the place.
  704. * Or 0 if no messages have been sent to the place yet.
  705. */
  706. typedef void
  707. (*GNUNET_SOCIAL_GuestEnterCallback) (void *cls, int result,
  708. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  709. uint64_t max_message_id);
  710. /**
  711. * Function called upon a guest receives a decision about entry to the place.
  712. *
  713. * @param is_admitted
  714. * Is the guest admitted to the place?
  715. * #GNUNET_YES if admitted,
  716. * #GNUNET_NO if refused entry,
  717. * #GNUNET_SYSERR if the request could not be answered.
  718. * @param data
  719. * Entry response message.
  720. */
  721. typedef void
  722. (*GNUNET_SOCIAL_EntryDecisionCallback) (void *cls,
  723. int is_admitted,
  724. const struct GNUNET_PSYC_Message *entry_resp);
  725. /**
  726. * Request entry to a place as a guest.
  727. *
  728. * @param app
  729. * Application handle.
  730. * @param ego
  731. * Identity of the guest.
  732. * @param place_pub_key
  733. * Public key of the place to enter.
  734. * @param flags
  735. * Flags for the entry.
  736. * @param origin
  737. * Peer identity of the origin of the underlying multicast group.
  738. * @param relay_count
  739. * Number of elements in the @a relays array.
  740. * @param relays
  741. * Relays for the underlying multicast group.
  742. * @param entry_msg
  743. * Entry message.
  744. * @param slicer
  745. * Slicer to use for processing incoming requests from guests.
  746. *
  747. * @return NULL on errors, otherwise handle for the guest.
  748. */
  749. struct GNUNET_SOCIAL_Guest *
  750. GNUNET_SOCIAL_guest_enter (const struct GNUNET_SOCIAL_App *app,
  751. const struct GNUNET_SOCIAL_Ego *ego,
  752. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  753. enum GNUNET_PSYC_SlaveJoinFlags flags,
  754. const struct GNUNET_PeerIdentity *origin,
  755. uint32_t relay_count,
  756. const struct GNUNET_PeerIdentity *relays,
  757. const struct GNUNET_PSYC_Message *entry_msg,
  758. struct GNUNET_PSYC_Slicer *slicer,
  759. GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
  760. GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb,
  761. void *cls);
  762. /**
  763. * Request entry to a place by name as a guest.
  764. *
  765. * @param app
  766. * Application handle.
  767. * @param ego
  768. * Identity of the guest.
  769. * @param gns_name
  770. * GNS name of the place to enter. Either in the form of
  771. * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
  772. * the 'PLACE' record of the empty label ("+") in the GNS zone with the
  773. * nym's public key 'NYMPUBKEY', and can be used to request entry to a
  774. * pseudonym's place directly.
  775. * @param password
  776. * Password to decrypt the record, or NULL for cleartext records.
  777. * @param join_msg
  778. * Entry request message.
  779. * @param slicer
  780. * Slicer to use for processing incoming requests from guests.
  781. * @param local_enter_cb
  782. * Called upon connection established to the social service.
  783. * @param entry_decision_cb
  784. * Called upon receiving entry decision.
  785. *
  786. * @return NULL on errors, otherwise handle for the guest.
  787. */
  788. struct GNUNET_SOCIAL_Guest *
  789. GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
  790. const struct GNUNET_SOCIAL_Ego *ego,
  791. const char *gns_name,
  792. const char *password,
  793. const struct GNUNET_PSYC_Message *join_msg,
  794. struct GNUNET_PSYC_Slicer *slicer,
  795. GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
  796. GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
  797. void *cls);
  798. /**
  799. * Reconnect to an already entered place as guest.
  800. *
  801. * @param gconn
  802. * Guest connection handle.
  803. * @see GNUNET_SOCIAL_app_connect() & GNUNET_SOCIAL_AppGuestPlaceCallback()
  804. * @param flags
  805. * Flags for the entry.
  806. * @param slicer
  807. * Slicer to use for processing incoming requests from guests.
  808. * @param local_enter_cb
  809. * Called upon connection established to the social service.
  810. * @param entry_decision_cb
  811. * Called upon receiving entry decision.
  812. *
  813. * @return NULL on errors, otherwise handle for the guest.
  814. */
  815. struct GNUNET_SOCIAL_Guest *
  816. GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn,
  817. enum GNUNET_PSYC_SlaveJoinFlags flags,
  818. struct GNUNET_PSYC_Slicer *slicer,
  819. GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
  820. void *cls);
  821. /**
  822. * Flags for talking to the host of a place.
  823. */
  824. enum GNUNET_SOCIAL_TalkFlags
  825. {
  826. GNUNET_SOCIAL_TALK_NONE = 0
  827. };
  828. /**
  829. * A talk request.
  830. */
  831. struct GNUNET_SOCIAL_TalkRequest;
  832. /**
  833. * Talk to the host of the place.
  834. *
  835. * @param place
  836. * Place where we want to talk to the host.
  837. * @param method_name
  838. * Method to invoke on the host.
  839. * @param env
  840. * Environment containing variables for the message, or NULL.
  841. * @param notify_data
  842. * Function to use to get the payload for the method.
  843. * @param notify_data_cls
  844. * Closure for @a notify_data.
  845. * @param flags
  846. * Flags for the message being sent.
  847. *
  848. * @return NULL if we are already trying to talk to the host,
  849. * otherwise handle to cancel the request.
  850. */
  851. struct GNUNET_SOCIAL_TalkRequest *
  852. GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *guest,
  853. const char *method_name,
  854. const struct GNUNET_PSYC_Environment *env,
  855. GNUNET_PSYC_TransmitNotifyData notify_data,
  856. void *notify_data_cls,
  857. enum GNUNET_SOCIAL_TalkFlags flags);
  858. /**
  859. * Resume talking to the host of the place.
  860. *
  861. * @param tr
  862. * Talk request to resume.
  863. */
  864. void
  865. GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr);
  866. /**
  867. * Cancel talking to the host of the place.
  868. *
  869. * @param tr
  870. * Talk request to cancel.
  871. */
  872. void
  873. GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr);
  874. /**
  875. * Disconnect from a place.
  876. *
  877. * Invalidates guest handle.
  878. *
  879. * @param gst
  880. * The guest to disconnect.
  881. * @param disconnect_cb
  882. * Function called after disconnected from the service.
  883. * @param cls
  884. * Closure for @a disconnect_cb.
  885. */
  886. void
  887. GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
  888. GNUNET_ContinuationCallback disconnect_cb,
  889. void *cls);
  890. /**
  891. * Leave a place temporarily or permanently.
  892. *
  893. * Notifies the owner of the place about leaving, and destroys the place handle.
  894. *
  895. * @param place
  896. * Place to leave.
  897. * @param env
  898. * Optional environment for the leave message if @a keep_active
  899. * is #GNUNET_NO. NULL if not needed.
  900. * @param disconnect_cb
  901. * Called upon disconnecting from the social service.
  902. */
  903. void
  904. GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
  905. struct GNUNET_PSYC_Environment *env,
  906. GNUNET_ContinuationCallback disconnect_cb,
  907. void *leave_cls);
  908. /**
  909. * Obtain handle for a place entered as guest.
  910. *
  911. * The returned handle can be used to access the place API.
  912. *
  913. * @param guest Handle for the guest.
  914. *
  915. * @return Handle for the place, valid as long as @a guest is valid.
  916. */
  917. struct GNUNET_SOCIAL_Place *
  918. GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *guest);
  919. /**
  920. * A history request.
  921. */
  922. struct GNUNET_SOCIAL_HistoryRequest;
  923. /**
  924. * Get the public key of a place.
  925. *
  926. * @param plc
  927. * Place.
  928. *
  929. * @return Public key of the place.
  930. */
  931. const struct GNUNET_CRYPTO_EddsaPublicKey *
  932. GNUNET_SOCIAL_place_get_pub_key (const struct GNUNET_SOCIAL_Place *plc);
  933. /**
  934. * Set message processing @a flags for a @a method_prefix.
  935. *
  936. * @param plc
  937. * Place.
  938. * @param method_prefix
  939. * Method prefix @a flags apply to.
  940. * @param flags
  941. * The flags that apply to a matching @a method_prefix.
  942. */
  943. void
  944. GNUNET_SOCIAL_place_msg_proc_set (struct GNUNET_SOCIAL_Place *plc,
  945. const char *method_prefix,
  946. enum GNUNET_SOCIAL_MsgProcFlags flags);
  947. /**
  948. * Clear all message processing flags previously set for this place.
  949. */
  950. void
  951. GNUNET_SOCIAL_place_msg_proc_clear (struct GNUNET_SOCIAL_Place *plc);
  952. /**
  953. * Learn about the history of a place.
  954. *
  955. * Messages are returned through the @a slicer function
  956. * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
  957. *
  958. * @param place
  959. * Place we want to learn more about.
  960. * @param start_message_id
  961. * First historic message we are interested in.
  962. * @param end_message_id
  963. * Last historic message we are interested in (inclusive).
  964. * @param method_prefix
  965. * Only retrieve messages with this method prefix.
  966. * @param flags
  967. * OR'ed GNUNET_PSYC_HistoryReplayFlags
  968. * @param slicer
  969. * Slicer to use for retrieved messages.
  970. * Can be the same as the slicer of the place.
  971. * @param result_cb
  972. * Function called after all messages retrieved.
  973. * NULL if not needed.
  974. * @param cls Closure for @a result_cb.
  975. */
  976. struct GNUNET_SOCIAL_HistoryRequest *
  977. GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
  978. uint64_t start_message_id,
  979. uint64_t end_message_id,
  980. const char *method_prefix,
  981. uint32_t flags,
  982. struct GNUNET_PSYC_Slicer *slicer,
  983. GNUNET_ResultCallback result_cb,
  984. void *cls);
  985. /**
  986. * Learn about the history of a place.
  987. *
  988. * Sends messages through the slicer function of the place where
  989. * start_message_id <= message_id <= end_message_id.
  990. * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
  991. *
  992. * To get the latest message, use 0 for both the start and end message ID.
  993. *
  994. * @param place
  995. * Place we want to learn more about.
  996. * @param message_limit
  997. * Maximum number of historic messages we are interested in.
  998. * @param result_cb
  999. * Function called after all messages retrieved.
  1000. * NULL if not needed.
  1001. * @param cls Closure for @a result_cb.
  1002. */
  1003. struct GNUNET_SOCIAL_HistoryRequest *
  1004. GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
  1005. uint64_t message_limit,
  1006. const char *method_prefix,
  1007. uint32_t flags,
  1008. struct GNUNET_PSYC_Slicer *slicer,
  1009. GNUNET_ResultCallback result_cb,
  1010. void *cls);
  1011. /**
  1012. * Cancel learning about the history of a place.
  1013. *
  1014. * @param hist
  1015. * History lesson to cancel.
  1016. */
  1017. void
  1018. GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist);
  1019. struct GNUNET_SOCIAL_LookHandle;
  1020. /**
  1021. * Look at a particular object in the place.
  1022. *
  1023. * The best matching object is returned (its name might be less specific than
  1024. * what was requested).
  1025. *
  1026. * @param place
  1027. * The place to look the object at.
  1028. * @param full_name
  1029. * Full name of the object.
  1030. *
  1031. * @return NULL if there is no such object at this place.
  1032. */
  1033. struct GNUNET_SOCIAL_LookHandle *
  1034. GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
  1035. const char *full_name,
  1036. GNUNET_PSYC_StateVarCallback var_cb,
  1037. GNUNET_ResultCallback result_cb,
  1038. void *cls);
  1039. /**
  1040. * Look for objects in the place with a matching name prefix.
  1041. *
  1042. * @param place
  1043. * The place to look its objects at.
  1044. * @param name_prefix
  1045. * Look at objects with names beginning with this value.
  1046. * @param var_cb
  1047. * Function to call for each object found.
  1048. * @param cls
  1049. * Closure for callback function.
  1050. *
  1051. * @return Handle that can be used to stop looking at objects.
  1052. */
  1053. struct GNUNET_SOCIAL_LookHandle *
  1054. GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
  1055. const char *name_prefix,
  1056. GNUNET_PSYC_StateVarCallback var_cb,
  1057. GNUNET_ResultCallback result_cb,
  1058. void *cls);
  1059. /**
  1060. * Stop looking at objects.
  1061. *
  1062. * @param lh Look handle to stop.
  1063. */
  1064. void
  1065. GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
  1066. /**
  1067. * Advertise a @e place in the GNS zone of @a ego.
  1068. *
  1069. * @param app
  1070. * Application handle.
  1071. * @param ego
  1072. * Ego.
  1073. * @param place_pub_key
  1074. * Public key of place to add.
  1075. * @param name
  1076. * The name for the PLACE record to put in the zone.
  1077. * @param password
  1078. * Password used to encrypt the record or NULL to keep it cleartext.
  1079. * @param relay_count
  1080. * Number of elements in the @a relays array.
  1081. * @param relays
  1082. * List of relays to put in the PLACE record to advertise
  1083. * as entry points to the place in addition to the origin.
  1084. * @param expiration_time
  1085. * Expiration time of the record, use 0 to remove the record.
  1086. * @param result_cb
  1087. * Function called with the result of the operation.
  1088. * @param result_cls
  1089. * Closure for @a result_cb
  1090. *
  1091. * @return #GNUNET_OK if the request was sent,
  1092. * #GNUNET_SYSERR on error, e.g. the name/password is too long.
  1093. */
  1094. int
  1095. GNUNET_SOCIAL_zone_add_place (const struct GNUNET_SOCIAL_App *app,
  1096. const struct GNUNET_SOCIAL_Ego *ego,
  1097. const char *name,
  1098. const char *password,
  1099. const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
  1100. const struct GNUNET_PeerIdentity *origin,
  1101. uint32_t relay_count,
  1102. const struct GNUNET_PeerIdentity *relays,
  1103. struct GNUNET_TIME_Absolute expiration_time,
  1104. GNUNET_ResultCallback result_cb,
  1105. void *result_cls);
  1106. /**
  1107. * Add public key to the GNS zone of the @e ego.
  1108. *
  1109. * @param cfg
  1110. * Configuration.
  1111. * @param ego
  1112. * Ego.
  1113. * @param name
  1114. * The name for the PKEY record to put in the zone.
  1115. * @param nym_pub_key
  1116. * Public key of nym to add.
  1117. * @param expiration_time
  1118. * Expiration time of the record, use 0 to remove the record.
  1119. * @param result_cb
  1120. * Function called with the result of the operation.
  1121. * @param result_cls
  1122. * Closure for @a result_cb
  1123. *
  1124. * @return #GNUNET_OK if the request was sent,
  1125. * #GNUNET_SYSERR on error, e.g. the name is too long.
  1126. */
  1127. int
  1128. GNUNET_SOCIAL_zone_add_nym (const struct GNUNET_SOCIAL_App *app,
  1129. const struct GNUNET_SOCIAL_Ego *ego,
  1130. const char *name,
  1131. const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_pub_key,
  1132. struct GNUNET_TIME_Absolute expiration_time,
  1133. GNUNET_ResultCallback result_cb,
  1134. void *result_cls);
  1135. #if 0 /* keep Emacsens' auto-indent happy */
  1136. {
  1137. #endif
  1138. #ifdef __cplusplus
  1139. }
  1140. #endif
  1141. /* ifndef GNUNET_SOCIAL_SERVICE_H */
  1142. #endif
  1143. /** @} */ /* end of group */