GNUnet  0.11.x
Data Structures | Functions
gnunet-service-messenger_handle.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_handle.h"
#include "gnunet-service-messenger.h"
#include "gnunet-service-messenger_message_kind.h"
Include dependency graph for gnunet-service-messenger_handle.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageHandle
 

Functions

struct GNUNET_MESSENGER_SrvHandlecreate_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...
 
int iterate_free_member_ids (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
 Destroys a handle and frees its memory fully. More...
 
void get_handle_data_subdir (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...
 
static int create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 
const struct GNUNET_ShortHashCodeget_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...
 
void change_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. More...
 
static void change_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
 
static void change_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Ego *ego)
 
struct GNUNET_MESSENGER_Egoget_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle)
 Returns the EGO used by a given handle. More...
 
void setup_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...
 
static int iterate_send_message (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void callback_ego_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg)
 
int update_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
 Tries to change the keypair of an EGO of a handle under the same name and informs all rooms about the change automatically. More...
 
int set_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_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_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_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_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, struct GNUNET_MESSENGER_Message *message)
 Sends a message from a given handle to the room using a specific key. More...
 
static int callback_scan_for_rooms (void *cls, const char *filename)
 
void load_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...
 
static int iterate_save_rooms (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void save_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.c.

Function Documentation

◆ create_handle()

struct GNUNET_MESSENGER_SrvHandle* create_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
serviceMESSENGER Service
mqMessage queue
Returns
New handle

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

References GNUNET_MESSENGER_SrvHandle::ego, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, handle, GNUNET_MESSENGER_SrvHandle::member_ids, mq, GNUNET_MESSENGER_SrvHandle::mq, GNUNET_MESSENGER_SrvHandle::name, GNUNET_MESSENGER_SrvHandle::operation, GNUNET_MESSENGER_SrvHandle::service, and service.

Referenced by add_service_handle(), and GNUNET_MESSENGER_connect().

33 {
35 
36  handle->service = service;
37  handle->mq = mq;
38 
39  handle->name = NULL;
40 
41  handle->operation = NULL;
42 
43  handle->ego = NULL;
44 
46 
47  return handle;
48 }
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_MESSENGER_Service * service
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MESSENGER_Ego * ego
struct GNUNET_IDENTITY_Operation * operation
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_CONTAINER_MultiHashMap * member_ids
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_free_member_ids()

int iterate_free_member_ids ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)

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

References GNUNET_free, and GNUNET_YES.

Referenced by destroy_handle().

52 {
54 
55  return GNUNET_YES;
56 }
static char * value
Value of the record to add/remove.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ destroy_handle()

void destroy_handle ( struct GNUNET_MESSENGER_SrvHandle handle)

Destroys a handle and frees its memory fully.

Parameters
handleHandle

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

References GNUNET_MESSENGER_Service::dir, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_IDENTITY_cancel(), iterate_free_member_ids(), GNUNET_MESSENGER_SrvHandle::member_ids, GNUNET_MESSENGER_SrvHandle::name, GNUNET_MESSENGER_SrvHandle::operation, save_handle_configuration(), and GNUNET_MESSENGER_SrvHandle::service.

Referenced by clear_list_handles(), GNUNET_MESSENGER_connect(), GNUNET_MESSENGER_disconnect(), and remove_service_handle().

60 {
61  if (handle->service->dir)
63 
64  if (handle->operation)
66 
67  if (handle->name)
68  GNUNET_free(handle->name);
69 
72 
73  GNUNET_free(handle);
74 }
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:904
struct GNUNET_MESSENGER_Service * service
struct GNUNET_IDENTITY_Operation * operation
void save_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle)
Saves member ids and other potential configuration from a given handle which depends on the given nam...
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
int iterate_free_member_ids(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * member_ids
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_handle_data_subdir()

void get_handle_data_subdir ( 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
handleHandle
namePotential name of the handle
dir[out]Path to store data

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

References GNUNET_MESSENGER_Service::dir, DIR_SEPARATOR, GNUNET_asprintf(), and GNUNET_MESSENGER_SrvHandle::service.

Referenced by iterate_save_rooms(), load_handle_configuration(), save_handle_configuration(), and set_handle_name().

78 {
79  if (name)
80  GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities",
82  else
83  GNUNET_asprintf (dir, "%s%s%c", handle->service->dir, "anonymous",
85 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
struct GNUNET_MESSENGER_Service * service
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:170
const char * name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_handle_member_id()

static int create_handle_member_id ( const struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_HashCode key 
)
static

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

References generate_service_new_member_id(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_YES, GNUNET_MESSENGER_SrvHandle::member_ids, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by entry_handle_room(), and open_handle_room().

89 {
90  struct GNUNET_ShortHashCode *random_id = generate_service_new_member_id (handle->service, key);
91 
92  if (!random_id)
93  return GNUNET_NO;
94 
95  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, random_id,
97  {
98  GNUNET_free(random_id);
99  return GNUNET_NO;
100  }
101 
102  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Created a new member id (%s) for room: %s\n",
103  GNUNET_sh2s(random_id), GNUNET_h2s(key));
104 
105  return GNUNET_YES;
106 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_MESSENGER_Service * service
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...
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
A 256-bit hashcode.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
int 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.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * member_ids
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_handle_member_id()

const struct GNUNET_ShortHashCode* get_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
handleHandle
keyKey of a room
Returns
Member id or NULL

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

References GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_SrvHandle::member_ids.

Referenced by close_handle_room(), close_service_room(), entry_handle_room(), find_list_handle_by_member(), get_room_host_id(), handle_room_close(), handle_room_entry(), handle_room_open(), handle_service_message(), join_room_locally(), open_handle_room(), open_room(), pack_room_message(), and send_handle_message().

110 {
111  return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
112 }
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.
struct GNUNET_CONTAINER_MultiHashMap * member_ids
Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_handle_member_id()

void change_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.

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

Parameters
handleHandle
keyKey of a room
unique_idUnique member id

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

References env, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, GNUNET_OK, GNUNET_sh2s(), GNUNET_MESSENGER_MemberMessage::id, GNUNET_MESSENGER_MemberMessage::key, GNUNET_MESSENGER_SrvHandle::member_ids, GNUNET_MESSENGER_SrvHandle::mq, and msg.

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

117 {
118  struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
119 
120  if (member_id)
121  {
122  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Changed a member id (%s) for room (%s) ",
123  GNUNET_sh2s(member_id), GNUNET_h2s(key));
124  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "into (%s).\n",
125  GNUNET_sh2s(unique_id));
126 
127  GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id));
128 
130  struct GNUNET_MQ_Envelope *env;
131 
133 
134  GNUNET_memcpy(&(msg->key), key, sizeof(*key));
135  GNUNET_memcpy(&(msg->id), member_id, sizeof(*member_id));
136 
137  GNUNET_MQ_send (handle->mq, env);
138  }
139  else
140  {
141  member_id = GNUNET_new(struct GNUNET_ShortHashCode);
142  GNUNET_memcpy(member_id, unique_id, sizeof(*member_id));
143 
144  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id,
146  GNUNET_free(member_id);
147  }
148 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Message to receive the current member id of a handle in room.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 256-bit hashcode.
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.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int 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.
struct GNUNET_ShortHashCode id
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * member_ids
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:355
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_handle_name()

static void change_handle_name ( struct GNUNET_MESSENGER_SrvHandle handle,
const char *  name 
)
static

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

References env, GNUNET_free, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_strdup, GNUNET_MESSENGER_SrvHandle::mq, msg, and GNUNET_MESSENGER_SrvHandle::name.

Referenced by set_handle_name(), and setup_handle_name().

152 {
153  if (handle->name)
154  GNUNET_free(handle->name);
155 
156  handle->name = name ? GNUNET_strdup(name) : NULL;
157 
158  const uint16_t name_len = handle->name ? strlen (handle->name) : 0;
159 
161  struct GNUNET_MQ_Envelope *env;
162 
164 
165  char *extra = ((char*) msg) + sizeof(*msg);
166 
167  if (name_len)
168  GNUNET_memcpy(extra, handle->name, name_len);
169 
170  extra[name_len] = '\0';
171 
172  GNUNET_MQ_send (handle->mq, env);
173 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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:52
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const char * name
Message to receive the current name of a handle.
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:355
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_handle_ego()

static void change_handle_ego ( struct GNUNET_MESSENGER_SrvHandle handle,
struct GNUNET_MESSENGER_Ego ego 
)
static

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

References GNUNET_MESSENGER_SrvHandle::ego, env, get_handle_ego(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_SrvHandle::mq, msg, GNUNET_MESSENGER_Ego::pub, and GNUNET_MESSENGER_KeyMessage::pubkey.

Referenced by callback_ego_create(), setup_handle_name(), and update_handle().

177 {
178  handle->ego = ego;
179 
180  ego = get_handle_ego(handle);
181 
183  struct GNUNET_MQ_Envelope *env;
184 
186 
187  GNUNET_memcpy(&(msg->pubkey), &(ego->pub), sizeof(ego->pub));
188 
189  GNUNET_MQ_send (handle->mq, env);
190 }
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MESSENGER_Ego * get_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.
struct GNUNET_IDENTITY_PublicKey pubkey
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MESSENGER_Ego * ego
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Message to receive the current public key of a handle.
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:355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_handle_ego()

struct GNUNET_MESSENGER_Ego* get_handle_ego ( struct GNUNET_MESSENGER_SrvHandle handle)

Returns the EGO used by a given handle.

Parameters
handleHandle
Returns
EGO keypair

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

References GNUNET_MESSENGER_SrvHandle::ego, GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_IDENTITY_ego_get_public_key(), GNUNET_memcpy, GNUNET_MESSENGER_Ego::priv, and GNUNET_MESSENGER_Ego::pub.

Referenced by change_handle_ego(), join_room(), pack_room_message(), and send_room_info().

194 {
195  static struct GNUNET_MESSENGER_Ego anonymous;
196  static int read_keys = 0;
197 
198  if (handle->ego)
199  return handle->ego;
200 
201  if (!read_keys)
202  {
204  GNUNET_memcpy(&(anonymous.priv), GNUNET_IDENTITY_ego_get_private_key(ego), sizeof(anonymous.priv));
205  GNUNET_IDENTITY_ego_get_public_key(ego, &(anonymous.pub));
206  read_keys = 1;
207  }
208 
209  return &anonymous;
210 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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_MESSENGER_Ego * ego
Handle for an ego.
Definition: identity.h:36
struct GNUNET_IDENTITY_Ego * GNUNET_IDENTITY_ego_get_anonymous()
Obtain the ego representing 'anonymous' users.
Definition: identity_api.c:156
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_handle_name()

void setup_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
handleHandle
nameName (optionally: valid EGO name)

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

References change_handle_ego(), change_handle_name(), GNUNET_MESSENGER_Service::dir, load_handle_configuration(), lookup_service_ego(), GNUNET_MESSENGER_SrvHandle::name, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_create().

214 {
215  change_handle_name (handle, name);
216  change_handle_ego (handle, handle->name? lookup_service_ego(handle->service, handle->name) : NULL);
217 
218  if (handle->service->dir)
220 }
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.
struct GNUNET_MESSENGER_Service * service
static void change_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Ego *ego)
const char * name
void load_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle)
Loads member ids and other potential configuration from a given handle which depends on the given nam...
static void change_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_send_message()

static int iterate_send_message ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

References GNUNET_YES, GNUNET_MESSENGER_MessageHandle::handle, GNUNET_MESSENGER_MessageHandle::message, and send_handle_message().

Referenced by callback_ego_create(), and set_handle_name().

230 {
231  struct GNUNET_MESSENGER_MessageHandle *msg_handle = cls;
232 
233  send_handle_message (msg_handle->handle, key, msg_handle->message);
234 
235  return GNUNET_YES;
236 }
struct GNUNET_MESSENGER_SrvHandle * handle
int send_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle to the room using a specific key.
struct GNUNET_MESSENGER_Message * message
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_ego_create()

static void callback_ego_create ( void *  cls,
const struct GNUNET_IDENTITY_PrivateKey key,
const char *  emsg 
)
static

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

References change_handle_ego(), create_message_key(), destroy_message(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_MessageHandle::handle, iterate_send_message(), lookup_service_ego(), GNUNET_MESSENGER_SrvHandle::member_ids, GNUNET_MESSENGER_MessageHandle::message, GNUNET_MESSENGER_SrvHandle::name, GNUNET_MESSENGER_SrvHandle::operation, GNUNET_MESSENGER_SrvHandle::service, and update_service_ego().

Referenced by update_handle().

240 {
241  struct GNUNET_MESSENGER_SrvHandle *handle = cls;
242 
243  handle->operation = NULL;
244 
245  if (emsg)
246  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
247 
248  if (key)
249  {
250  struct GNUNET_MESSENGER_MessageHandle msg_handle;
251 
252  msg_handle.handle = handle;
253  msg_handle.message = create_message_key (key);
254 
256 
257  destroy_message (msg_handle.message);
258 
259  update_service_ego(handle->service, handle->name, key);
260 
261  change_handle_ego (handle, lookup_service_ego(handle->service, handle->name));
262  }
263 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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.
struct GNUNET_MESSENGER_Service * service
struct GNUNET_MESSENGER_SrvHandle * handle
struct GNUNET_IDENTITY_Operation * operation
static void change_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Ego *ego)
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int iterate_send_message(void *cls, const struct GNUNET_HashCode *key, void *value)
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...
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * member_ids
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_handle()

int update_handle ( struct GNUNET_MESSENGER_SrvHandle handle)

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

Parameters
handleHandle
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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

References callback_ego_create(), change_handle_ego(), GNUNET_assert, GNUNET_IDENTITY_create(), GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_OK, GNUNET_SYSERR, GNUNET_MESSENGER_Service::identity, lookup_service_ego(), GNUNET_MESSENGER_SrvHandle::name, GNUNET_MESSENGER_SrvHandle::operation, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_update().

267 {
268  GNUNET_assert(handle);
269 
270  if (!handle->name)
271  return GNUNET_SYSERR;
272 
273  struct GNUNET_MESSENGER_Ego *ego = lookup_service_ego(handle->service, handle->name);
274 
275  if (!ego)
276  handle->operation = GNUNET_IDENTITY_create (handle->service->identity, handle->name, NULL,
278  else
279  change_handle_ego (handle, ego);
280 
281  return GNUNET_OK;
282 }
static void callback_ego_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg)
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.
struct GNUNET_MESSENGER_Service * service
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:757
struct GNUNET_IDENTITY_Operation * operation
static void change_handle_ego(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Ego *ego)
struct GNUNET_IDENTITY_Handle * identity
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_handle_name()

int set_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
handleHandle
nameNew name
Returns
GNUNET_OK on success, otherwise GNUNET_NO

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

References change_handle_name(), create_message_name(), destroy_message(), get_handle_data_subdir(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_IDENTITY_cancel(), GNUNET_IDENTITY_rename(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_MessageHandle::handle, GNUNET_MESSENGER_Service::identity, iterate_send_message(), lookup_service_ego(), GNUNET_MESSENGER_SrvHandle::member_ids, GNUNET_MESSENGER_MessageHandle::message, GNUNET_MESSENGER_SrvHandle::name, GNUNET_MESSENGER_SrvHandle::operation, result, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_get_name(), and handle_set_name().

286 {
287  GNUNET_assert(handle);
288 
289  if ((name) && (lookup_service_ego(handle->service, name)))
290  return GNUNET_NO;
291 
292  struct GNUNET_IDENTITY_Operation *operation = handle->operation;
293 
294  if (handle->name)
295  handle->operation = GNUNET_IDENTITY_rename (handle->service->identity, handle->name, name, NULL, NULL);
296 
297  char *old_dir;
298  get_handle_data_subdir (handle, handle->name, &old_dir);
299 
300  char *new_dir;
301  get_handle_data_subdir (handle, name, &new_dir);
302 
303  int result = 0;
304 
306  {
308 
309  result = rename (old_dir, new_dir);
310  }
311  else if (GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO))
312  result = -1;
313 
314  if (0 == result)
315  {
316  struct GNUNET_MESSENGER_MessageHandle msg_handle;
317 
318  msg_handle.handle = handle;
319  msg_handle.message = create_message_name (name);
320 
322 
323  destroy_message (msg_handle.message);
324 
325  change_handle_name (handle, name);
326 
327  if (operation)
328  GNUNET_IDENTITY_cancel (operation);
329  }
330  else
331  {
332  if (handle->operation)
333  {
335 
336  handle->operation = operation;
337  }
338  }
339 
340  GNUNET_free(old_dir);
341  GNUNET_free(new_dir);
342 
343  return (result == 0 ? GNUNET_OK : GNUNET_NO);
344 }
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:904
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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.
struct GNUNET_MESSENGER_Service * service
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:684
struct GNUNET_MESSENGER_SrvHandle * handle
void get_handle_data_subdir(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...
Handle for an operation with the identity service.
Definition: identity_api.c:39
struct GNUNET_IDENTITY_Operation * operation
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
static int iterate_send_message(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
const char * name
struct GNUNET_CONTAINER_MultiHashMap * member_ids
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing identity.
Definition: identity_api.c:810
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static void change_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
struct GNUNET_IDENTITY_Handle * identity
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_handle_room()

int open_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
handleHandle
keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

References create_handle_member_id(), get_handle_member_id(), GNUNET_NO, GNUNET_YES, open_service_room(), and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_room_open().

348 {
349  if ((!get_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key)))
350  return GNUNET_NO;
351 
352  return open_service_room (handle->service, handle, key);
353 }
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.
struct GNUNET_MESSENGER_Service * service
static int create_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
const struct GNUNET_ShortHashCode * get_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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ entry_handle_room()

int entry_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
handleHandle
doorPeer identity
keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

References create_handle_member_id(), entry_service_room(), get_handle_member_id(), GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_room_entry().

358 {
359  if ((!get_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key)))
360  return GNUNET_NO;
361 
362  return entry_service_room (handle->service, handle, door, key);
363 }
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.
struct GNUNET_MESSENGER_Service * service
static int create_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
const struct GNUNET_ShortHashCode * get_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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_handle_room()

int close_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
handleHandle
keyKey of a room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

References close_service_room(), get_handle_member_id(), GNUNET_NO, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_room_close().

367 {
368  if (!get_handle_member_id (handle, key))
369  return GNUNET_NO;
370 
371  return close_service_room (handle->service, handle, key);
372 }
struct GNUNET_MESSENGER_Service * service
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.
const struct GNUNET_ShortHashCode * get_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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_handle_message()

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

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

Parameters
handleHandle
keyKey of a room
messageMessage
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

References get_handle_member_id(), get_service_room(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_Message::header, send_room_message(), GNUNET_MESSENGER_MessageHeader::sender_id, and GNUNET_MESSENGER_SrvHandle::service.

Referenced by handle_send_message(), and iterate_send_message().

377 {
378  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key);
379 
380  if (!id)
381  {
382  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n");
383  return GNUNET_NO;
384  }
385 
386  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key);
387 
388  if (!room)
389  {
390  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key));
391  return GNUNET_NO;
392  }
393 
394  struct GNUNET_HashCode hash;
395 
396  GNUNET_memcpy(&(message->header.sender_id), id, sizeof(*id));
397 
398  send_room_message (room, handle, message, &hash);
399  return GNUNET_YES;
400 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_Service * service
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
A 256-bit hashcode.
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.
A 512-bit hashcode.
void send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
Sends a message from a given handle into a room.
#define GNUNET_log(kind,...)
const struct GNUNET_ShortHashCode * get_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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_scan_for_rooms()

static int callback_scan_for_rooms ( void *  cls,
const char *  filename 
)
static

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

References cfg, change_handle_member_id(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_file_test(), GNUNET_OK, GNUNET_YES, and GNUNET_MESSENGER_MessageHandle::handle.

Referenced by load_handle_configuration().

402  {
403  struct GNUNET_MESSENGER_SrvHandle* handle = cls;
404 
406 
409  {
410  struct GNUNET_HashCode key;
411  struct GNUNET_ShortHashCode member_id;
412 
413  if ((GNUNET_OK == GNUNET_CONFIGURATION_get_data(cfg, "room", "key", &key, sizeof(key))) &&
414  (GNUNET_OK == GNUNET_CONFIGURATION_get_data(cfg, "room", "member_id", &member_id, sizeof(member_id))))
415  change_handle_member_id(handle, &key, &member_id);
416  }
417 
419  return GNUNET_OK;
420 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:544
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void change_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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
int GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
A 256-bit hashcode.
int GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * filename
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
configuration data
Definition: configuration.c:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_handle_configuration()

void load_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
handleHandle

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

References callback_scan_for_rooms(), DIR_SEPARATOR, get_handle_data_subdir(), GNUNET_asprintf(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_SrvHandle::name, and find_typedefs::scan_dir().

Referenced by setup_handle_name().

422  {
423  char* id_dir;
424  get_handle_data_subdir(handle, handle->name, &id_dir);
425 
427  {
428  char* scan_dir;
429  GNUNET_asprintf(&scan_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
430 
433 
434  GNUNET_free(scan_dir);
435  }
436 
437  GNUNET_free(id_dir);
438 }
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:911
void get_handle_data_subdir(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...
static int callback_scan_for_rooms(void *cls, const char *filename)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:170
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_save_rooms()

static int iterate_save_rooms ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

References cfg, DIR_SEPARATOR, filename, get_handle_data_subdir(), GNUNET_asprintf(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_free, GNUNET_h2s(), GNUNET_STRINGS_data_to_string_alloc(), GNUNET_YES, GNUNET_MESSENGER_MessageHandle::handle, GNUNET_MESSENGER_SrvHandle::name, and value.

Referenced by save_handle_configuration().

442 {
443  struct GNUNET_MESSENGER_SrvHandle* handle = cls;
444  struct GNUNET_ShortHashCode* member_id = value;
445 
446  char* id_dir;
447  get_handle_data_subdir(handle, handle->name, &id_dir);
448 
449  char* filename;
450  GNUNET_asprintf(&filename, "%s%s%c%s.cfg",
451  id_dir, "rooms", DIR_SEPARATOR,
452  GNUNET_h2s(key));
453 
454  GNUNET_free(id_dir);
455 
457 
458  char* key_data = GNUNET_STRINGS_data_to_string_alloc(key, sizeof(*key));
459 
460  if (key_data)
461  {
462  GNUNET_CONFIGURATION_set_value_string(cfg, "room", "key", key_data);
463 
464  GNUNET_free(key_data);
465  }
466 
467  char* member_id_data = GNUNET_STRINGS_data_to_string_alloc(member_id, sizeof(*member_id));
468 
469  if (member_id_data)
470  {
471  GNUNET_CONFIGURATION_set_value_string(cfg, "room", "member_id", member_id_data);
472 
473  GNUNET_free(member_id_data);
474  }
475 
476  GNUNET_CONFIGURATION_write(cfg, filename);
478 
479  GNUNET_free(filename);
480 
481  return GNUNET_YES;
482 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void get_handle_data_subdir(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...
A 256-bit hashcode.
static char * value
Value of the record to add/remove.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static char * filename
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:170
configuration data
Definition: configuration.c:84
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_handle_configuration()

void save_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
handleHandle

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

References DIR_SEPARATOR, get_handle_data_subdir(), GNUNET_asprintf(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, iterate_save_rooms(), GNUNET_MESSENGER_SrvHandle::member_ids, and GNUNET_MESSENGER_SrvHandle::name.

Referenced by destroy_handle().

485 {
486  char* id_dir;
487  get_handle_data_subdir(handle, handle->name, &id_dir);
488 
489  if ((GNUNET_YES == GNUNET_DISK_directory_test(id_dir, GNUNET_NO)) ||
491  {
492  char* save_dir;
493  GNUNET_asprintf(&save_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR);
494 
495  if ((GNUNET_YES == GNUNET_DISK_directory_test(save_dir, GNUNET_NO)) ||
498 
499  GNUNET_free(save_dir);
500  }
501 
502  GNUNET_free(id_dir);
503 }
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:589
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
void get_handle_data_subdir(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...
static int iterate_save_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:170
struct GNUNET_CONTAINER_MultiHashMap * member_ids
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: