GNUnet  0.11.x
Functions
gnunet-service-messenger_service.c File Reference

GNUnet MESSENGER service. More...

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

Go to the source code of this file.

Functions

static void callback_shutdown_service (void *cls)
 
static void callback_update_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
 
struct GNUNET_MESSENGER_Servicecreate_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...
 
static int iterate_destroy_egos (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int iterate_destroy_rooms (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static int iterate_destroy_contacts (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void destroy_service (struct GNUNET_MESSENGER_Service *service)
 Destroys a service and frees its memory fully. More...
 
struct GNUNET_MESSENGER_Egolookup_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_SrvHandleadd_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_SrvContactget_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_ShortHashCodegenerate_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_SrvRoomget_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...
 
static void get_room_data_subdir (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
 
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...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_service.c.

Function Documentation

◆ callback_shutdown_service()

static void callback_shutdown_service ( void *  cls)
static

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

References destroy_service(), service, and GNUNET_MESSENGER_Service::shutdown.

Referenced by create_service().

35 {
36  struct GNUNET_MESSENGER_Service *service = cls;
37 
38  if (service)
39  {
40  service->shutdown = NULL;
41 
42  destroy_service (service);
43  }
44 }
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_SCHEDULER_Task * shutdown
void destroy_service(struct GNUNET_MESSENGER_Service *service)
Destroys a service and frees its memory fully.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_update_ego()

static void callback_update_ego ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  identifier 
)
static

Definition at line 47 of file gnunet-service-messenger_service.c.

References GNUNET_IDENTITY_ego_get_private_key(), service, and update_service_ego().

Referenced by create_service().

51 {
52  if ((!ego) || (!identifier))
53  return;
54 
55  struct GNUNET_MESSENGER_Service *service = cls;
56 
58 }
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
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...
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:

◆ create_service()

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.

Parameters
configConfiguration
service_handleGNUnet service handle
Returns
New service

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().

62 {
64 
65  service->config = config;
66  service->service = service_handle;
67 
69 
70  service->dir = NULL;
71 
74  "MESSENGER_DIR", &(service->dir)))
75  {
76  if (service->dir)
77  GNUNET_free(service->dir);
78 
79  service->dir = NULL;
80  }
81  else
82  {
84  != GNUNET_DISK_directory_create (service->dir)))
85  {
86  GNUNET_free(service->dir);
87 
88  service->dir = NULL;
89  }
90  }
91 
92  service->cadet = GNUNET_CADET_connect (service->config);
93  service->identity = GNUNET_IDENTITY_connect (service->config, &callback_update_ego, service);
94 
96 
97  init_list_handles (&(service->handles));
98 
101 
102  return service;
103 }
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListHandles handles
static void callback_update_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:589
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
static void callback_shutdown_service(void *cls)
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * shutdown
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:910
struct GNUNET_CONTAINER_MultiHashMap * rooms
static const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_SERVICE_Handle * service
struct GNUNET_CONTAINER_MultiHashMap * egos
void init_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Initializes list of handles as empty list.
#define GNUNET_MESSENGER_SERVICE_NAME
const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_CONTAINER_MultiHashMap * contacts
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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:

◆ iterate_destroy_egos()

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

Definition at line 106 of file gnunet-service-messenger_service.c.

References GNUNET_free, GNUNET_YES, and value.

Referenced by destroy_service().

107 {
108  struct GNUNET_MESSENGER_Ego *ego = value;
109  GNUNET_free(ego);
110  return GNUNET_YES;
111 }
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:

◆ iterate_destroy_rooms()

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

Definition at line 114 of file gnunet-service-messenger_service.c.

References destroy_room(), GNUNET_YES, and value.

Referenced by destroy_service().

115 {
116  struct GNUNET_MESSENGER_SrvRoom *room = value;
117  destroy_room (room);
118  return GNUNET_YES;
119 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
static char * value
Value of the record to add/remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_destroy_contacts()

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

Definition at line 122 of file gnunet-service-messenger_service.c.

References destroy_contact(), GNUNET_YES, and value.

Referenced by destroy_service().

123 {
124  struct GNUNET_MESSENGER_SrvContact *contact = value;
125  destroy_contact (contact);
126  return GNUNET_YES;
127 }
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact and frees its memory fully.
static char * value
Value of the record to add/remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_service()

void destroy_service ( struct GNUNET_MESSENGER_Service service)

Destroys a service and frees its memory fully.

Parameters
serviceService

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().

131 {
132  if (service->shutdown)
133  {
135 
136  service->shutdown = NULL;
137  }
138 
140 
141  clear_list_handles (&(service->handles));
142 
145 
149 
150  if (service->cadet)
151  {
152  GNUNET_CADET_disconnect (service->cadet);
153 
154  service->cadet = NULL;
155  }
156 
157  if (service->identity)
158  {
160 
161  service->identity = NULL;
162  }
163 
164  if (service->dir)
165  {
166  GNUNET_free(service->dir);
167 
168  service->dir = NULL;
169  }
170 
171  GNUNET_SERVICE_shutdown (service->service);
172 
173  GNUNET_free(service);
174 }
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:775
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListHandles handles
struct GNUNET_SCHEDULER_Task * shutdown
struct GNUNET_CONTAINER_MultiHashMap * rooms
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
struct GNUNET_SERVICE_Handle * service
static int iterate_destroy_egos(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * egos
void clear_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Destroys remaining handles and clears the list.
static int iterate_destroy_contacts(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_CONTAINER_MultiHashMap * contacts
static int iterate_destroy_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
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_IDENTITY_Handle * identity
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2384
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_service_ego()

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.

Parameters
serviceService
identifierIdentifier string
Returns
EGO or NULL

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().

178 {
179  GNUNET_assert(identifier);
180 
181  struct GNUNET_HashCode hash;
182 
183  GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash);
184  return GNUNET_CONTAINER_multihashmap_get(service->egos, &hash);
185 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * egos
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_service_ego()

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.

Parameters
serviceService
identifierIdentifier string
keyPrivate 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().

190 {
191  GNUNET_assert((identifier) && (key));
192 
193  struct GNUNET_HashCode hash;
194 
195  GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash);
196 
197  struct GNUNET_MESSENGER_Ego* ego = GNUNET_CONTAINER_multihashmap_get(service->egos, &hash);
198 
199  if (!ego)
200  {
201  ego = GNUNET_new(struct GNUNET_MESSENGER_Ego);
203  }
204 
205  GNUNET_memcpy(&(ego->priv), key, sizeof(*key));
206 
207  if (GNUNET_OK != GNUNET_IDENTITY_key_get_public(key, &(ego->pub)))
208  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n");
209 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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_IDENTITY_PublicKey pub
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
A 512-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * egos
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_IDENTITY_PrivateKey priv
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_service_handle()

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.

Parameters
serviceService
mqMessage queue
Returns
New handle

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().

213 {
214  struct GNUNET_MESSENGER_SrvHandle *handle = create_handle (service, mq);
215 
216  if (handle)
217  {
218  add_list_handle (&(service->handles), handle);
219  }
220 
221  return handle;
222 }
struct GNUNET_MESSENGER_ListHandles handles
void add_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, void *handle)
Adds a specific handle to the end of the list.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_service_handle()

void remove_service_handle ( struct GNUNET_MESSENGER_Service service,
struct GNUNET_MESSENGER_SrvHandle handle 
)

Removes a handle from a service and destroys it.

Parameters
serviceService
handleHandle

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().

226 {
227  if (!handle)
228  return;
229 
230  if (GNUNET_YES == remove_list_handle (&(service->handles), handle))
231  destroy_handle (handle);
232 }
struct GNUNET_MESSENGER_ListHandles handles
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
int remove_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, void *handle)
Removes the first entry matching with a specific handle from the list and returns GNUNET_YES on succe...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_service_peer_identity()

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.

Parameters
serviceService
[out]peerPeer identity
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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().

236 {
237  return GNUNET_CRYPTO_get_peer_identity (service->config, peer);
238 }
const struct GNUNET_CONFIGURATION_Handle * config
int GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host's peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_service_contact_by_pubkey()

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.

Parameters
serviceService
pubkeyPublic key of EGO
Returns
Contact

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().

242 {
243  struct GNUNET_HashCode hash;
244 
245  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
246 
247  struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_CONTAINER_multihashmap_get (service->contacts, &hash);
248 
249  if (contact)
250  return contact;
251 
252  contact = create_contact (pubkey);
253 
254  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->contacts, &hash, contact,
256  return contact;
257 
258  destroy_contact (contact);
259  return NULL;
260 }
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact and frees its memory fully.
struct GNUNET_MESSENGER_SrvContact * create_contact(const struct GNUNET_IDENTITY_PublicKey *key)
Creates and allocates a new contact with a given public key from an EGO.
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_...
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
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_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap_service_contact_by_pubkey()

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.

Parameters
serviceService
contactContact
pubkeyPublic 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().

265 {
266  const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact);
267 
268  if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (service->contacts, hash, contact))
269  {
270  GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey));
271 
272  hash = get_contact_id_from_key (contact);
273 
274  GNUNET_CONTAINER_multihashmap_put (service->contacts, hash, contact,
276  }
277 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
A 512-bit hashcode.
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.
const struct GNUNET_HashCode * get_contact_id_from_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the resulting hashcode of the public key from a given contact.
struct GNUNET_IDENTITY_PublicKey public_key
struct GNUNET_CONTAINER_MultiHashMap * contacts
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_service_new_member_id()

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.

Parameters
serviceService
keyKey of room
Returns
Newly generated member id or NULL

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().

281 {
282  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
283 
284  if (room)
285  {
286  return generate_room_member_id (room);
287  }
288  else
289  {
290  struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode);
291  generate_free_member_id (random_id, NULL);
292  return random_id;
293  }
294 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 256-bit hashcode.
struct GNUNET_ShortHashCode * generate_room_member_id(const struct GNUNET_MESSENGER_SrvRoom *room)
Tries to generate and allocate a new unique member id checking all current members for possible dupli...
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.
int generate_free_member_id(struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members)
Tries to generate an unused member id and store it into the id parameter.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_service_room()

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.

Parameters
serviceService
keyKey of room
Returns
Room or NULL

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().

298 {
299  return GNUNET_CONTAINER_multihashmap_get (service->rooms, key);
300 }
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 * rooms
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_service_room()

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.

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

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().

305 {
306  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
307 
308  if (room)
309  return open_room (room, handle);
310 
311  room = create_room (handle, key);
312 
313  if ((GNUNET_YES == open_room (room, handle)) && (GNUNET_OK
315  return GNUNET_YES;
316 
317  destroy_room (room);
318  return GNUNET_NO;
319 }
int open_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to open a room for a given handle.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
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.
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_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ entry_service_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.

Parameters
serviceService
handleHandle
doorPeer identity
keyKey of room
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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().

324 {
325  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
326 
327  if (room)
328  {
329  if (GNUNET_YES == entry_room_at (room, handle, door))
330  return GNUNET_YES;
331  else
332  return GNUNET_NO;
333  }
334 
335  room = create_room (handle, key);
336 
337  if ((GNUNET_YES == entry_room_at (room, handle, door)) && (GNUNET_OK
339  {
340  return GNUNET_YES;
341  }
342  else
343  {
344  destroy_room (room);
345  return GNUNET_NO;
346  }
347 
348 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
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.
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_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
int entry_room_at(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door)
Connects a tunnel to a hosting peer of a room through a so called door which is represented by a peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_service_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.

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

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().

353 {
354  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
355 
356  if (!room)
357  return GNUNET_NO;
358 
359  struct GNUNET_MESSENGER_Message *message = create_message_leave ();
360 
361  if (message)
362  {
363  struct GNUNET_HashCode hash;
364 
365  send_room_message (room, handle, message, &hash);
366  destroy_message (message);
367  }
368 
369  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key);
370 
371  GNUNET_assert(id);
372 
374  return GNUNET_NO;
375 
377  &(service->handles), key);
378 
379  if (!member_handle)
380  {
381  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room))
382  {
383  destroy_room (room);
384  return GNUNET_YES;
385  }
386  else
387  return GNUNET_NO;
388  }
389 
390  if (room->host == handle)
391  room->host = member_handle;
392 
393  return GNUNET_YES;
394 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_ListHandles handles
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A 256-bit hashcode.
struct GNUNET_CONTAINER_MultiHashMap * rooms
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
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.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_MESSENGER_SrvHandle * host
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.
struct GNUNET_MESSENGER_Message * create_message_leave()
Creates and allocates a new leave message.
struct GNUNET_CONTAINER_MultiHashMap * member_ids
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.
void * find_list_handle_by_member(struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key)
Searches linearly through the list of handles for members of a specific room which is identified by a...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_data_subdir()

static void get_room_data_subdir ( struct GNUNET_MESSENGER_Service service,
struct GNUNET_MESSENGER_SrvRoom room,
char **  dir 
)
static

Definition at line 397 of file gnunet-service-messenger_service.c.

References GNUNET_MESSENGER_Service::dir, DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_h2s(), and GNUNET_MESSENGER_SrvRoom::key.

Referenced by load_service_room_and_messages(), and save_service_room_and_messages().

398 {
399  GNUNET_asprintf (dir, "%s%s%c%s%c", service->dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (&(room->key)), DIR_SEPARATOR);
400 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:170
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_service_room_and_messages()

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.

Parameters
serviceService
roomRoom

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().

404 {
405  char *room_dir;
406  get_room_data_subdir (service, room, &room_dir);
407 
409  {
410  load_message_store (&room->store, room_dir);
411 
412  char *config_file;
413  GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg");
414 
416 
417  if ((GNUNET_YES == GNUNET_DISK_file_test (config_file)) && (GNUNET_OK
418  == GNUNET_CONFIGURATION_parse (cfg, config_file)))
419  {
420  unsigned long long access;
421 
422  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "room", "access-rule", &access))
423  room->strict_access = (int) (access);
424 
425  char *message_string;
426 
427  if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "room", "last-message", &message_string)) && (message_string))
428  {
429  struct GNUNET_HashCode hash;
430 
431  GNUNET_CRYPTO_hash_from_string(message_string, &hash);
432 
433  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, room->host, &hash, GNUNET_NO);
434 
435  if (message)
436  update_room_last_messages (room, message, &hash);
437 
438  GNUNET_free(message_string);
439  }
440  }
441 
443 
444  GNUNET_free(config_file);
445  }
446 
447  GNUNET_free(room_dir);
448 }
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
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static void get_room_data_subdir(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
void update_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Updates the last messages of a room by replacing them if the previous hash of a given message matches...
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...
void load_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Loads messages from a directory into a message store.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
A 512-bit hashcode.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
struct GNUNET_MESSENGER_SrvHandle * host
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
configuration data
Definition: configuration.c:84
#define GNUNET_CRYPTO_hash_from_string(enc, result)
Convert ASCII encoding back to struct GNUNET_HashCode
struct GNUNET_MESSENGER_MessageStore store
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_service_room_and_messages()

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.

Parameters
serviceService
roomRoom

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().

452 {
453  if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (service->rooms, &(room->key)))
454  {
455  return;
456  }
457 
458  char *room_dir;
459  get_room_data_subdir (service, room, &room_dir);
460 
462  == GNUNET_DISK_directory_create (room_dir)))
463  {
464  save_message_store (&room->store, room_dir);
465 
466  char *config_file;
467  GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg");
468 
470 
471  GNUNET_CONFIGURATION_set_value_number (cfg, "room", "access-rule", room->strict_access);
472 
473  if (room->last_messages.head)
474  GNUNET_CONFIGURATION_set_value_string (cfg, "room", "last-message",
475  GNUNET_h2s_full (&(room->last_messages.head->hash)));
476 
477  GNUNET_CONFIGURATION_write (cfg, config_file);
479 
480  GNUNET_free(config_file);
481  }
482 
483  GNUNET_free(room_dir);
484 }
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.
struct GNUNET_MESSENGER_ListMessage * head
void save_message_store(struct GNUNET_MESSENGER_MessageStore *store, const char *directory)
Saves messages from a message store into a directory.
int GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:589
static void get_room_data_subdir(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, char **dir)
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:84
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_CONTAINER_MultiHashMap * rooms
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
configuration data
Definition: configuration.c:84
struct GNUNET_MESSENGER_MessageStore store
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_service_message()

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.

Parameters
serviceService
roomRoom
messageMessage
hashHash 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().

489 {
490  struct GNUNET_MESSENGER_ListHandle *element = service->handles.head;
491 
492  const uint16_t length = get_message_size (message);
493 
494  while (element)
495  {
497 
498  if ((handle->mq) && (get_handle_member_id (handle, &(room->key))))
499  {
501  struct GNUNET_MQ_Envelope *env;
502 
504 
505  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
506  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
507 
508  char *buffer = ((char*) msg) + sizeof(*msg);
509  encode_message (message, length, buffer);
510 
511  GNUNET_MQ_send (handle->mq, env);
512  }
513 
514  element = element->next;
515  }
516 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MESSENGER_ListHandles handles
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_MESSENGER_ListHandle * next
#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
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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.
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
struct GNUNET_MESSENGER_ListHandle * head
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
Message to receive something from a room.
Here is the call graph for this function:
Here is the caller graph for this function: