![]() |
GNUnet
0.11.x
|
GNUnet MESSENGER service. More...
#include "platform.h"
#include "gnunet_configuration_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_container_lib.h"
#include "gnunet_disk_lib.h"
#include "gnunet_identity_service.h"
#include "messenger_api_ego.h"
#include "gnunet-service-messenger_list_handles.h"
#include "gnunet-service-messenger_contact.h"
#include "gnunet-service-messenger_room.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_MESSENGER_Service |
Functions | |
struct GNUNET_MESSENGER_Service * | create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle) |
Creates and allocates a new service using a given config and a GNUnet service handle. More... | |
void | destroy_service (struct GNUNET_MESSENGER_Service *service) |
Destroys a service and frees its memory fully. More... | |
struct GNUNET_MESSENGER_Ego * | lookup_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier) |
Lookups an EGO which was registered to a service under a specific identifier. More... | |
void | update_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier, const struct GNUNET_IDENTITY_PrivateKey *key) |
Updates the registration of an EGO to a service under a specific identifier with a new key. More... | |
struct GNUNET_MESSENGER_SrvHandle * | add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq) |
Creates and adds a new handle to a service using a given message queue. More... | |
void | remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle) |
Removes a handle from a service and destroys it. More... | |
int | get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer) |
Tries to write the peer identity of the peer running a service on to the peer parameter. More... | |
struct GNUNET_MESSENGER_SrvContact * | get_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey) |
Returns a contact of a service identified by a given public key. More... | |
void | swap_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, const struct GNUNET_IDENTITY_PublicKey *pubkey) |
Changes the public key for a contact known to a service to a specific public key and updates local map entries to access the contact by its updated key. More... | |
struct GNUNET_ShortHashCode * | generate_service_new_member_id (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key) |
Tries to generate and allocate a new unique member id for a given room of a service identified by its key. More... | |
struct GNUNET_MESSENGER_SrvRoom * | get_service_room (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key) |
Returns the room identified by a given key for a service. More... | |
int | open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) |
Tries to open a room using a given key for a service by a specific handle. More... | |
int | entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) |
Tries to enter a room using a given key for a service by a specific handle. More... | |
int | close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) |
Tries to close a room using a given key for a service by a specific handle. More... | |
void | load_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room) |
Loads the local configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members. More... | |
void | save_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room) |
Saves the configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members locally. More... | |
void | handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) |
Sends a received or sent message with a given hash to each handle of a service which is currently member of a specific room for handling it in the client API. More... | |
GNUnet MESSENGER service.
Definition in file gnunet-service-messenger_service.h.
struct GNUNET_MESSENGER_Service* create_service | ( | const struct GNUNET_CONFIGURATION_Handle * | config, |
struct GNUNET_SERVICE_Handle * | service_handle | ||
) |
Creates and allocates a new service using a given config and a GNUnet service handle.
config | Configuration |
service_handle | GNUnet service handle |
Definition at line 61 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::cadet, callback_shutdown_service(), callback_update_ego(), config, GNUNET_MESSENGER_Service::config, GNUNET_MESSENGER_Service::contacts, GNUNET_MESSENGER_Service::dir, GNUNET_MESSENGER_Service::egos, GNUNET_CADET_connect(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_IDENTITY_connect(), GNUNET_MESSENGER_SERVICE_NAME, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_YES, GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_Service::identity, init_list_handles(), GNUNET_MESSENGER_Service::rooms, GNUNET_MESSENGER_Service::service, service, and GNUNET_MESSENGER_Service::shutdown.
Referenced by run().
void destroy_service | ( | struct GNUNET_MESSENGER_Service * | service | ) |
Destroys a service and frees its memory fully.
service | Service |
Definition at line 130 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::cadet, clear_list_handles(), GNUNET_MESSENGER_Service::contacts, GNUNET_MESSENGER_Service::dir, GNUNET_MESSENGER_Service::egos, GNUNET_CADET_disconnect(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_shutdown(), GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_Service::identity, iterate_destroy_contacts(), iterate_destroy_egos(), iterate_destroy_rooms(), GNUNET_MESSENGER_Service::rooms, GNUNET_MESSENGER_Service::service, and GNUNET_MESSENGER_Service::shutdown.
Referenced by callback_shutdown_service().
struct GNUNET_MESSENGER_Ego* lookup_service_ego | ( | struct GNUNET_MESSENGER_Service * | service, |
const char * | identifier | ||
) |
Lookups an EGO which was registered to a service under a specific identifier.
service | Service |
identifier | Identifier string |
Definition at line 177 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::egos, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), and GNUNET_CRYPTO_hash().
Referenced by callback_ego_create(), set_handle_name(), setup_handle_name(), and update_handle().
void update_service_ego | ( | struct GNUNET_MESSENGER_Service * | service, |
const char * | identifier, | ||
const struct GNUNET_IDENTITY_PrivateKey * | key | ||
) |
Updates the registration of an EGO to a service under a specific identifier with a new key.
service | Service |
identifier | Identifier string |
key | Private EGO key |
Definition at line 188 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::egos, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_WARNING, GNUNET_IDENTITY_key_get_public(), GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_MESSENGER_Ego::priv, and GNUNET_MESSENGER_Ego::pub.
Referenced by callback_ego_create(), and callback_update_ego().
struct GNUNET_MESSENGER_SrvHandle* add_service_handle | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MQ_Handle * | mq | ||
) |
Creates and adds a new handle to a service using a given message queue.
service | Service |
mq | Message queue |
Definition at line 212 of file gnunet-service-messenger_service.c.
References add_list_handle(), create_handle(), handle, and GNUNET_MESSENGER_Service::handles.
Referenced by callback_client_connect().
void remove_service_handle | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvHandle * | handle | ||
) |
Removes a handle from a service and destroys it.
service | Service |
handle | Handle |
Definition at line 225 of file gnunet-service-messenger_service.c.
References destroy_handle(), GNUNET_YES, GNUNET_MESSENGER_Service::handles, and remove_list_handle().
Referenced by callback_client_disconnect().
int get_service_peer_identity | ( | const struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_PeerIdentity * | peer | ||
) |
Tries to write the peer identity of the peer running a service on to the peer parameter.
The functions returns GNUNET_OK on success, otherwise GNUNET_SYSERR.
service | Service | |
[out] | peer | Peer identity |
Definition at line 235 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::config, and GNUNET_CRYPTO_get_peer_identity().
Referenced by create_message_peer(), and rebuild_room_basement_structure().
struct GNUNET_MESSENGER_SrvContact* get_service_contact_by_pubkey | ( | struct GNUNET_MESSENGER_Service * | service, |
const struct GNUNET_IDENTITY_PublicKey * | pubkey | ||
) |
Returns a contact of a service identified by a given public key.
If no matching contact exists, it will tried to create one with the specific public key. If the function still fails to do so, NULL gets returned.
service | Service |
pubkey | Public key of EGO |
Definition at line 241 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::contacts, create_contact(), destroy_contact(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), and GNUNET_OK.
Referenced by add_room_contact(), and callback_verify_room_message().
void swap_service_contact_by_pubkey | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvContact * | contact, | ||
const struct GNUNET_IDENTITY_PublicKey * | pubkey | ||
) |
Changes the public key for a contact known to a service to a specific public key and updates local map entries to access the contact by its updated key.
service | Service |
contact | Contact |
pubkey | Public key of EGO |
Definition at line 263 of file gnunet-service-messenger_service.c.
References GNUNET_MESSENGER_Service::contacts, get_contact_id_from_key(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_memcpy, GNUNET_YES, and GNUNET_MESSENGER_SrvContact::public_key.
Referenced by handle_message_key().
struct GNUNET_ShortHashCode* generate_service_new_member_id | ( | struct GNUNET_MESSENGER_Service * | service, |
const struct GNUNET_HashCode * | key | ||
) |
Tries to generate and allocate a new unique member id for a given room of a service identified by its key.
If the generation fails caused by too many tries of duplicates, it returns NULL.
service | Service |
key | Key of room |
Definition at line 280 of file gnunet-service-messenger_service.c.
References generate_free_member_id(), generate_room_member_id(), get_service_room(), and GNUNET_new.
Referenced by create_handle_member_id().
struct GNUNET_MESSENGER_SrvRoom* get_service_room | ( | struct GNUNET_MESSENGER_Service * | service, |
const struct GNUNET_HashCode * | key | ||
) |
Returns the room identified by a given key for a service.
If the service doesn't know any room using the given key, NULL gets returned.
service | Service |
key | Key of room |
Definition at line 297 of file gnunet-service-messenger_service.c.
References GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_Service::rooms.
Referenced by close_service_room(), entry_service_room(), generate_service_new_member_id(), handle_get_message(), open_service_room(), and send_handle_message().
int open_service_room | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvHandle * | handle, | ||
const struct GNUNET_HashCode * | key | ||
) |
Tries to open a room using a given key for a service by a specific handle.
The room will be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO.
service | Service |
handle | Handle |
key | Key of room |
Definition at line 303 of file gnunet-service-messenger_service.c.
References create_room(), destroy_room(), get_service_room(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_NO, GNUNET_OK, GNUNET_YES, open_room(), and GNUNET_MESSENGER_Service::rooms.
Referenced by open_handle_room().
int entry_service_room | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvHandle * | handle, | ||
const struct GNUNET_PeerIdentity * | door, | ||
const struct GNUNET_HashCode * | key | ||
) |
Tries to enter a room using a given key for a service by a specific handle.
The room will be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO.
The room will be entered through the peer identitied by the peer identity provided as door parameter and a new connection will be made.
service | Service |
handle | Handle |
door | Peer identity |
key | Key of room |
Definition at line 322 of file gnunet-service-messenger_service.c.
References create_room(), destroy_room(), entry_room_at(), get_service_room(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_NO, GNUNET_OK, GNUNET_YES, and GNUNET_MESSENGER_Service::rooms.
Referenced by entry_handle_room().
int close_service_room | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvHandle * | handle, | ||
const struct GNUNET_HashCode * | key | ||
) |
Tries to close a room using a given key for a service by a specific handle.
The room will be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO.
If the specific handle is currently the host of the room for this service, a new handle which is a member will take its place. Otherwise the room will be destroyed for this service.
service | Service |
handle | Handle |
key | Key of room |
Definition at line 351 of file gnunet-service-messenger_service.c.
References create_message_leave(), destroy_message(), destroy_room(), find_list_handle_by_member(), get_handle_member_id(), get_service_room(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_SrvRoom::host, key, GNUNET_MESSENGER_SrvHandle::member_ids, GNUNET_MESSENGER_Service::rooms, and send_room_message().
Referenced by close_handle_room().
void load_service_room_and_messages | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvRoom * | room | ||
) |
Loads the local configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members.
service | Service |
room | Room |
Definition at line 403 of file gnunet-service-messenger_service.c.
References cfg, config_file, get_room_data_subdir(), get_room_message(), GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_parse(), GNUNET_CRYPTO_hash_from_string, GNUNET_DISK_directory_test(), GNUNET_DISK_file_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, load_message_store(), GNUNET_MESSENGER_SrvRoom::store, GNUNET_MESSENGER_SrvRoom::strict_access, and update_room_last_messages().
Referenced by create_room().
void save_service_room_and_messages | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvRoom * | room | ||
) |
Saves the configuration for a given room of a service which contains the last messages hash and the ruleset for general access of new members locally.
service | Service |
room | Room |
Definition at line 451 of file gnunet-service-messenger_service.c.
References cfg, config_file, get_room_data_subdir(), GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_h2s_full(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvRoom::last_messages, GNUNET_MESSENGER_Service::rooms, save_message_store(), GNUNET_MESSENGER_SrvRoom::store, and GNUNET_MESSENGER_SrvRoom::strict_access.
Referenced by destroy_room().
void handle_service_message | ( | struct GNUNET_MESSENGER_Service * | service, |
struct GNUNET_MESSENGER_SrvRoom * | room, | ||
const struct GNUNET_MESSENGER_Message * | message, | ||
const struct GNUNET_HashCode * | hash | ||
) |
Sends a received or sent message with a given hash to each handle of a service which is currently member of a specific room for handling it in the client API.
service | Service |
room | Room |
message | Message |
hash | Hash of message |
Definition at line 487 of file gnunet-service-messenger_service.c.
References encode_message(), env, get_handle_member_id(), get_message_size(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handle, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_RecvMessage::hash, GNUNET_MESSENGER_ListHandles::head, GNUNET_MESSENGER_RecvMessage::key, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_SrvHandle::mq, msg, and GNUNET_MESSENGER_ListHandle::next.
Referenced by handle_room_messages().