GNUnet  0.17.6
Data Structures | Functions
gnunet-service-messenger_handle.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_cadet_service.h"
#include "gnunet_container_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_peer_lib.h"
#include "gnunet_mq_lib.h"
#include "gnunet-service-messenger_service.h"
#include "gnunet-service-messenger_member_session.h"
#include "messenger_api_ego.h"
#include "messenger_api_message.h"
Include dependency graph for gnunet-service-messenger_handle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_SrvHandle
 

Functions

struct GNUNET_MESSENGER_SrvHandlecreate_srv_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
 Creates and allocates a new handle related to a service and using a given mq (message queue). More...
 
void destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
 Destroys a handle and frees its memory fully. More...
 
void get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir)
 Writes the path of the directory for a given handle using a specific name to the parameter dir. More...
 
const struct GNUNET_ShortHashCodeget_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Returns the member id of a given handle in a specific room. More...
 
int change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *unique_id)
 Changes the member id of a given handle in a specific room to match a unique_id and returns GNUNET_OK on success. More...
 
void set_srv_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego)
 Sets the EGO used by a given handle. More...
 
const struct GNUNET_MESSENGER_Egoget_srv_handle_ego (const struct GNUNET_MESSENGER_SrvHandle *handle)
 Returns the EGO used by a given handle. More...
 
void setup_srv_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
 Tries to set the name and EGO key of a handle initially by looking up a specific name. More...
 
void update_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
 Tries to change the key pair of an EGO of a handle under the same name and informs all rooms about the change automatically. More...
 
void set_srv_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
 Tries to rename the handle which implies renaming the EGO its using and moving all related data into the directory fitting to the changed name. More...
 
int open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Makes a given handle a member of the room using a specific key and opens the room from the handles service. More...
 
int entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Makes a given handle a member of the room using a specific key and enters the room through a tunnel to a peer identified by a given door (peer identity). More...
 
int close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Removes the membership of the room using a specific key and closes it if no other handle from this service is still a member of it. More...
 
int send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message)
 Sends a message from a given handle to the room using a specific key. More...
 
void notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Notifies the handle that a new message was received or sent. More...
 
void load_srv_handle_configuration (struct GNUNET_MESSENGER_SrvHandle *handle)
 Loads member ids and other potential configuration from a given handle which depends on the given name the handle uses. More...
 
void save_srv_handle_configuration (struct GNUNET_MESSENGER_SrvHandle *handle)
 Saves member ids and other potential configuration from a given handle which depends on the given name the handle uses. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_handle.h.

Function Documentation

◆ create_srv_handle()

struct GNUNET_MESSENGER_SrvHandle* create_srv_handle ( struct GNUNET_MESSENGER_Service service,
struct GNUNET_MQ_Handle mq 
)

Creates and allocates a new handle related to a service and using a given mq (message queue).

Parameters
[in/out]service MESSENGER Service
[in/out]mq Message queue
Returns
New handle

Definition at line 34 of file gnunet-service-messenger_handle.c.

36 {
37  GNUNET_assert((service) && (mq));
38 
40 
41  handle->service = service;
42  handle->mq = mq;
43 
44  handle->name = NULL;
45  handle->ego = NULL;
46 
48 
49  return handle;
50 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
Definition: gnunet_common.h:98
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, handle, mq, GNUNET_DNS_Handle::mq, and service.

Referenced by add_service_handle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_srv_handle()

void destroy_srv_handle ( struct GNUNET_MESSENGER_SrvHandle handle)

Destroys a handle and frees its memory fully.

Parameters
[in/out]handle Handle

Definition at line 63 of file gnunet-service-messenger_handle.c.

64 {
66 
67  if (handle->service->dir)
69 
70  if (handle->name)
71  {
72  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
73 
74  unbind_store_ego(store, handle->name, handle);
75 
76  GNUNET_free(handle->name);
77  }
78 
81 
83 }
void unbind_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, void *handle)
Binds an EGO which was registered to a store under a specific identifier to a given handle
void save_srv_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle)
Saves member ids and other potential configuration from a given handle which depends on the given nam...
int iterate_free_member_ids(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_MESSENGER_EgoStore * get_service_ego_store(struct GNUNET_MESSENGER_Service *service)
Returns the used EGO-store of a given service.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.

References get_service_ego_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, handle, iterate_free_member_ids(), save_srv_handle_configuration(), and unbind_store_ego().

Referenced by clear_list_handles(), and remove_service_handle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_srv_handle_data_subdir()

void get_srv_handle_data_subdir ( const struct GNUNET_MESSENGER_SrvHandle handle,
const char *  name,
char **  dir 
)

Writes the path of the directory for a given handle using a specific name to the parameter dir.

This directory will be used to store data regarding the handle and its messages.

Parameters
[in]handleHandle
[in]namePotential name of the handle
[out]dirPath to store data

Definition at line 86 of file gnunet-service-messenger_handle.c.

89 {
90  GNUNET_assert((handle) && (dir));
91 
92  if (name)
93  GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities",
95  else
96  GNUNET_asprintf (dir, "%s%s%c", handle->service->dir, "anonymous",
98 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
const char * name

References dir, DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, handle, and name.

Referenced by callback_set_handle_name(), iterate_save_rooms(), load_srv_handle_configuration(), and save_srv_handle_configuration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_srv_handle_member_id()

const struct GNUNET_ShortHashCode* get_srv_handle_member_id ( const struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key 
)

Returns the member id of a given handle in a specific room.

If the handle is not a member of the specific room, NULL gets returned.

Parameters
[in]handleHandle
[in]keyKey of a room
Returns
Member id or NULL

Definition at line 127 of file gnunet-service-messenger_handle.c.

129 {
130  GNUNET_assert((handle) && (key));
131 
132  return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
133 }
struct GNUNET_HashCode key
The key used in the DHT.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by close_service_room(), close_srv_handle_room(), entry_srv_handle_room(), find_list_handle_by_member(), get_handle_member_session(), handle_get_message(), handle_room_entry(), handle_room_open(), join_room_locally(), notify_srv_handle_message(), open_srv_handle_room(), open_srv_room(), pack_srv_room_message(), send_srv_handle_message(), send_srv_room_message(), and solve_srv_room_member_collisions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_srv_handle_member_id()

int change_srv_handle_member_id ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key,
const struct GNUNET_ShortHashCode unique_id 
)

Changes the member id of a given handle in a specific room to match a unique_id and returns GNUNET_OK on success.

The client connected to the handle will be informed afterwards automatically.

Parameters
[in/out]handle Handle
[in]keyKey of a room
[in]unique_idUnique member id
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 136 of file gnunet-service-messenger_handle.c.

139 {
140  GNUNET_assert((handle) && (key) && (unique_id));
141 
142  struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
143 
144  if (!member_id)
145  {
146  member_id = GNUNET_new(struct GNUNET_ShortHashCode);
147  GNUNET_memcpy(member_id, unique_id, sizeof(*member_id));
148 
149  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id,
151  {
152  GNUNET_free(member_id);
153  return GNUNET_SYSERR;
154  }
155  }
156 
157  if (0 == GNUNET_memcmp(unique_id, member_id))
158  goto send_message_to_client;
159 
160  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Change a member id (%s) for room (%s).\n", GNUNET_sh2s (member_id),
161  GNUNET_h2s (key));
162 
163  GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id));
164 
165  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", GNUNET_sh2s (unique_id));
166 
168  struct GNUNET_MQ_Envelope *env;
169 
170 send_message_to_client:
171 
173 
174  GNUNET_memcpy(&(msg->key), key, sizeof(*key));
175  GNUNET_memcpy(&(msg->id), member_id, sizeof(*member_id));
176 
178  return GNUNET_OK;
179 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:302
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:71
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
Message to receive the current member id of a handle in room.
A 256-bit hashcode.

References env, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, GNUNET_OK, GNUNET_sh2s(), GNUNET_SYSERR, handle, key, GNUNET_DNS_Handle::mq, and msg.

Referenced by callback_scan_for_rooms(), join_room(), and send_message_id().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_srv_handle_ego()

void set_srv_handle_ego ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_MESSENGER_Ego ego 
)

Sets the EGO used by a given handle.

Parameters
[in/out]handle Handle
[in]egoEGO key pair

Definition at line 253 of file gnunet-service-messenger_handle.c.

255 {
256  GNUNET_assert((handle) && (ego));
257 
258  struct GNUNET_MESSENGER_MessageHandle msg_handle;
259 
260  msg_handle.handle = handle;
261  msg_handle.message = create_message_key (&(ego->priv));
262 
264 
265  destroy_message (msg_handle.message);
266 
267  change_handle_ego (handle, ego);
268 }
static int iterate_send_message(void *cls, const struct GNUNET_HashCode *key, void *value)
static void change_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Ego *ego)
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_IDENTITY_PrivateKey priv
struct GNUNET_MESSENGER_SrvHandle * handle

References change_handle_ego(), create_message_key(), destroy_message(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), handle, GNUNET_MESSENGER_MessageHandle::handle, iterate_send_message(), GNUNET_MESSENGER_MessageHandle::message, and GNUNET_MESSENGER_Ego::priv.

Referenced by iterate_create_ego().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_srv_handle_ego()

const struct GNUNET_MESSENGER_Ego* get_srv_handle_ego ( const struct GNUNET_MESSENGER_SrvHandle handle)

Returns the EGO used by a given handle.

Parameters
[in]handleHandle
Returns
EGO key pair

Definition at line 271 of file gnunet-service-messenger_handle.c.

272 {
274 
275  static struct GNUNET_MESSENGER_Ego anonymous;
276  static int read_keys = 0;
277 
278  if (handle->ego)
279  return handle->ego;
280 
281  if (!read_keys)
282  {
284  GNUNET_memcpy(&(anonymous.priv), GNUNET_IDENTITY_ego_get_private_key (ego), sizeof(anonymous.priv));
285  GNUNET_IDENTITY_ego_get_public_key (ego, &(anonymous.pub));
286  read_keys = 1;
287  }
288 
289  return &anonymous;
290 }
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:652
struct GNUNET_IDENTITY_Ego * GNUNET_IDENTITY_ego_get_anonymous()
Obtain the ego representing 'anonymous' users.
Definition: identity_api.c:156
Handle for an ego.
Definition: identity.h:37

References GNUNET_assert, GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_ego_get_public_key(), GNUNET_memcpy, handle, GNUNET_MESSENGER_Ego::priv, and GNUNET_MESSENGER_Ego::pub.

Referenced by change_handle_ego(), get_handle_member_session(), handle_get_message(), join_room(), join_room_locally(), notify_srv_handle_message(), pack_srv_room_message(), recv_message_info(), send_room_info(), and solve_srv_room_member_collisions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_srv_handle_name()

void setup_srv_handle_name ( struct GNUNET_MESSENGER_SrvHandle handle,
const char *  name 
)

Tries to set the name and EGO key of a handle initially by looking up a specific name.

Parameters
[in/out]handle Handle
[in]nameName (optionally: valid EGO name)

Definition at line 309 of file gnunet-service-messenger_handle.c.

311 {
313 
314  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
315 
317 }
void lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, const char *identifier, GNUNET_MESSENGER_EgoLookupCallback lookup, void *cls)
Lookups an EGO which was registered to a store under a specific identifier.
static void callback_setup_handle_name(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)

References callback_setup_handle_name(), get_service_ego_store(), GNUNET_assert, handle, lookup_store_ego(), and name.

Referenced by handle_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_srv_handle()

void update_srv_handle ( struct GNUNET_MESSENGER_SrvHandle handle)

Tries to change the key pair of an EGO of a handle under the same name and informs all rooms about the change automatically.

Parameters
[in/out]handle Handle

Definition at line 339 of file gnunet-service-messenger_handle.c.

340 {
342 
343  if (!handle->name)
344  {
345  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
346  return;
347  }
348 
349  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
350 
352 }
static void callback_update_handle(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)
@ GNUNET_ERROR_TYPE_WARNING

References callback_update_handle(), get_service_ego_store(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, handle, and lookup_store_ego().

Referenced by handle_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_srv_handle_name()

void set_srv_handle_name ( struct GNUNET_MESSENGER_SrvHandle handle,
const char *  name 
)

Tries to rename the handle which implies renaming the EGO its using and moving all related data into the directory fitting to the changed name.

The client connected to the handle will be informed afterwards automatically.

Parameters
[in/out]handle Handle
[in]nameNew name

Definition at line 406 of file gnunet-service-messenger_handle.c.

408 {
410 
411  if (!name)
412  {
413  if (handle->ego)
414  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Renaming handle failed: Name is required!\n");
415  else
417 
418  return;
419  }
420 
421  struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
422 
424 }
static void callback_set_handle_name(void *cls, const char *name, const struct GNUNET_MESSENGER_Ego *ego)
static void change_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
@ GNUNET_ERROR_TYPE_ERROR

References callback_set_handle_name(), change_handle_name(), get_service_ego_store(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, handle, lookup_store_ego(), and name.

Referenced by handle_set_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_srv_handle_room()

int open_srv_handle_room ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key 
)

Makes a given handle a member of the room using a specific key and opens the room from the handles service.

Parameters
[in/out]handle Handle
[in]keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 427 of file gnunet-service-messenger_handle.c.

429 {
430  GNUNET_assert((handle) && (key));
431 
433  return GNUNET_NO;
434 
435  return open_service_room (handle->service, handle, key);
436 }
const struct GNUNET_ShortHashCode * get_srv_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
static int create_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
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.
@ GNUNET_YES

References create_handle_member_id(), get_srv_handle_member_id(), GNUNET_assert, GNUNET_NO, GNUNET_YES, handle, key, and open_service_room().

Referenced by handle_room_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entry_srv_handle_room()

int entry_srv_handle_room ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_PeerIdentity door,
const struct GNUNET_HashCode key 
)

Makes a given handle a member of the room using a specific key and enters the room through a tunnel to a peer identified by a given door (peer identity).

Parameters
[in/out]handle Handle
[in]doorPeer identity
[in]keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 439 of file gnunet-service-messenger_handle.c.

442 {
443  GNUNET_assert((handle) && (door) && (key));
444 
446  return GNUNET_NO;
447 
448  return entry_service_room (handle->service, handle, door, key);
449 }
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.

References create_handle_member_id(), entry_service_room(), get_srv_handle_member_id(), GNUNET_assert, GNUNET_NO, GNUNET_YES, handle, and key.

Referenced by handle_room_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_srv_handle_room()

int close_srv_handle_room ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key 
)

Removes the membership of the room using a specific key and closes it if no other handle from this service is still a member of it.

Parameters
[in/out]handle Handle
[in]keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 452 of file gnunet-service-messenger_handle.c.

454 {
455  GNUNET_assert((handle) && (key));
456 
458  return GNUNET_NO;
459 
460  return close_service_room (handle->service, handle, key);
461 }
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.

References close_service_room(), get_srv_handle_member_id(), GNUNET_assert, GNUNET_NO, handle, and key.

Referenced by handle_room_close().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_srv_handle_message()

int send_srv_handle_message ( struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key,
const struct GNUNET_MESSENGER_Message message 
)

Sends a message from a given handle to the room using a specific key.

Parameters
[in/out]handle Handle
[in]keyKey of a room
[in]messageMessage
Returns
GNUNET_YES on success, GNUNET_NO or GNUNET_SYSERR otherwise.

Definition at line 464 of file gnunet-service-messenger_handle.c.

467 {
468  GNUNET_assert((handle) && (key) && (message));
469 
471 
472  if (!id)
473  {
474  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n");
475  return GNUNET_NO;
476  }
477 
478  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key);
479 
480  if (!room)
481  {
482  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key));
483  return GNUNET_NO;
484  }
485 
486  struct GNUNET_MESSENGER_Message *msg = copy_message(message);
487 
488  GNUNET_memcpy(&(msg->header.sender_id), id, sizeof(*id));
489 
490  return send_srv_room_message (room, handle, msg);
491 }
int send_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.

References copy_message(), get_service_room(), get_srv_handle_member_id(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, handle, key, msg, and send_srv_room_message().

Referenced by handle_send_message(), and iterate_send_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_srv_handle_message()

void notify_srv_handle_message ( struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_MESSENGER_MemberSession session,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Notifies the handle that a new message was received or sent.

Parameters
[in/out]handle Handle
[in]roomRoom of the message
[in]sessionMember session
[in]messageMessage
[in]hashHash of message

Definition at line 526 of file gnunet-service-messenger_handle.c.

531 {
532  GNUNET_assert((handle) && (room) && (session) && (message) && (hash));
533 
534  const struct GNUNET_HashCode *key = get_srv_room_key(room);
535 
536  if ((!handle->mq) || (!get_srv_handle_member_id (handle, key)))
537  {
538  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notifying client about message requires membership!\n");
539  return;
540  }
541 
542  const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key(session->contact);
543 
544  struct GNUNET_HashCode sender;
545  GNUNET_CRYPTO_hash(pubkey, sizeof(*pubkey), &sender);
546 
547  const struct GNUNET_HashCode *context = get_next_member_session_contect (session);
548 
549  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying client about message: %s\n", GNUNET_h2s (hash));
550 
551  struct GNUNET_MESSENGER_Message *private_message = NULL;
552 
553  if (GNUNET_MESSENGER_KIND_PRIVATE == message->header.kind)
554  {
555  private_message = copy_message(message);
556 
557  if (GNUNET_YES != decrypt_message(private_message, &(get_srv_handle_ego(handle)->priv)))
558  {
559  destroy_message(private_message);
560  private_message = NULL;
561  }
562  else
563  message = private_message;
564  }
565 
567  struct GNUNET_MQ_Envelope *env;
568 
569  uint16_t length = get_message_size (message, GNUNET_YES);
570 
572 
573  GNUNET_memcpy(&(msg->key), key, sizeof(msg->key));
574  GNUNET_memcpy(&(msg->sender), &sender, sizeof(msg->sender));
575  GNUNET_memcpy(&(msg->context), context, sizeof(msg->context));
576  GNUNET_memcpy(&(msg->hash), hash, sizeof(msg->hash));
577 
578  msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE;
579 
580  if (get_handle_member_session(handle, room, key) == session)
581  msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT;
582 
583  if (private_message)
584  msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PRIVATE;
585 
586  char *buffer = ((char*) msg) + sizeof(*msg);
587  encode_message (message, length, buffer, GNUNET_YES);
588 
589  if (private_message)
590  destroy_message(private_message);
591 
593 }
static pa_context * context
Pulseaudio context.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static const struct GNUNET_HashCode * get_next_member_session_contect(const struct GNUNET_MESSENGER_MemberSession *session)
const struct GNUNET_MESSENGER_Ego * get_srv_handle_ego(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
static const struct GNUNET_MESSENGER_MemberSession * get_handle_member_session(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *key)
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_FLAG_PRIVATE
The private flag.
@ GNUNET_MESSENGER_FLAG_SENT
The sent flag.
@ GNUNET_MESSENGER_FLAG_NONE
The none flag.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:56
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
int decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_header)
Encodes a given message into a buffer of a maximal length in bytes.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_header)
Returns the exact size in bytes to encode a given message.
A 512-bit hashcode.
An identity key as per LSD0001.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
Message to receive something from a room.

References GNUNET_MESSENGER_MemberSession::contact, context, copy_message(), decrypt_message(), destroy_message(), encode_message(), env, get_contact_key(), get_handle_member_session(), get_message_size(), get_next_member_session_contect(), get_srv_handle_ego(), get_srv_handle_member_id(), get_srv_room_key(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, GNUNET_MESSENGER_FLAG_NONE, GNUNET_MESSENGER_FLAG_PRIVATE, GNUNET_MESSENGER_FLAG_SENT, GNUNET_MESSENGER_KIND_PRIVATE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_YES, handle, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_DNS_Handle::mq, msg, and pubkey.

Referenced by callback_found_message(), handle_service_message(), and notify_about_members().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_srv_handle_configuration()

void load_srv_handle_configuration ( struct GNUNET_MESSENGER_SrvHandle handle)

Loads member ids and other potential configuration from a given handle which depends on the given name the handle uses.

Parameters
[out]handleHandle

Definition at line 623 of file gnunet-service-messenger_handle.c.

624 {
626 
627  char *id_dir;
628  get_srv_handle_data_subdir (handle, handle->name, &id_dir);
629 
631  {
632  char *scan_dir;
633  GNUNET_asprintf (&scan_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
634 
637 
639  }
640 
641  GNUNET_free(id_dir);
642 }
static int callback_scan_for_rooms(void *cls, const char *filename)
void get_srv_handle_data_subdir(const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir)
Writes the path of the directory for a given handle using a specific name to the parameter dir.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814

References callback_scan_for_rooms(), DIR_SEPARATOR, get_srv_handle_data_subdir(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, handle, and find_typedefs::scan_dir().

Referenced by callback_setup_handle_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_srv_handle_configuration()

void save_srv_handle_configuration ( struct GNUNET_MESSENGER_SrvHandle handle)

Saves member ids and other potential configuration from a given handle which depends on the given name the handle uses.

Parameters
[in]handleHandle

Definition at line 690 of file gnunet-service-messenger_handle.c.

691 {
693 
694  char *id_dir;
695  get_srv_handle_data_subdir (handle, handle->name, &id_dir);
696 
698  == GNUNET_DISK_directory_create (id_dir)))
699  {
700  char *save_dir;
701  GNUNET_asprintf (&save_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
702 
703  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
704  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
706 
707  GNUNET_free(save_dir);
708  }
709 
710  GNUNET_free(id_dir);
711 }
static int iterate_save_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496

References DIR_SEPARATOR, get_srv_handle_data_subdir(), GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, handle, and iterate_save_rooms().

Referenced by destroy_srv_handle().

Here is the call graph for this function:
Here is the caller graph for this function: