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 dependency graph for gnunet-service-messenger_service.c:

Go to the source code of this file.

Functions

static void callback_shutdown_service (void *cls)
 
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_rooms (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_EgoStoreget_service_ego_store (struct GNUNET_MESSENGER_Service *service)
 Returns the used EGO-store of a given service. More...
 
struct GNUNET_MESSENGER_ContactStoreget_service_contact_store (struct GNUNET_MESSENGER_Service *service)
 Returns the used contact store of a given service. 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_SrvRoomget_service_room (const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
 Returns the room identified by a given key for a service. More...
 
int open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Tries to open a room using a given key for a service by a specific handle. More...
 
int entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Tries to enter a room using a given key for a service by a specific handle. More...
 
int close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
 Tries to close a room using a given key for a service by a specific handle. More...
 
void handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_MemberSession *session, 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 31 of file gnunet-service-messenger_service.c.

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

Referenced by create_service().

32 {
33  struct GNUNET_MESSENGER_Service *service = cls;
34 
35  if (service)
36  {
37  service->shutdown = NULL;
38 
39  destroy_service (service);
40  }
41 }
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:

◆ 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
[in]configConfiguration

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

References GNUNET_MESSENGER_Service::cadet, callback_shutdown_service(), config, GNUNET_MESSENGER_Service::config, GNUNET_MESSENGER_Service::dir, get_service_contact_store(), get_service_ego_store(), GNUNET_assert, GNUNET_CADET_connect(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_MESSENGER_SERVICE_NAME, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_YES, GNUNET_MESSENGER_Service::handles, init_contact_store(), init_ego_store(), init_list_handles(), GNUNET_MESSENGER_Service::rooms, GNUNET_MESSENGER_Service::service, service, and GNUNET_MESSENGER_Service::shutdown.

Referenced by run().

45 {
46  GNUNET_assert((config) && (service_handle));
47 
49 
50  service->config = config;
51  service->service = service_handle;
52 
54 
55  service->dir = NULL;
56 
59  "MESSENGER_DIR", &(service->dir)))
60  {
61  if (service->dir)
62  GNUNET_free(service->dir);
63 
64  service->dir = NULL;
65  }
66  else
67  {
69  != GNUNET_DISK_directory_create (service->dir)))
70  {
71  GNUNET_free(service->dir);
72 
73  service->dir = NULL;
74  }
75  }
76 
77  service->cadet = GNUNET_CADET_connect (service->config);
78 
79  init_ego_store(get_service_ego_store(service), service->config);
80 
81  init_list_handles (&(service->handles));
82 
84 
86 
87  return service;
88 }
struct GNUNET_MESSENGER_ContactStore * get_service_contact_store(struct GNUNET_MESSENGER_Service *service)
Returns the used contact store of a given service.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListHandles handles
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
void init_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Initializes a contact store as fully empty.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void callback_shutdown_service(void *cls)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue 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.
void init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, const struct GNUNET_CONFIGURATION_Handle *config)
Initializes an EGO-store as fully empty.
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_MESSENGER_EgoStore * get_service_ego_store(struct GNUNET_MESSENGER_Service *service)
Returns the used EGO-store of a given service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
static const struct GNUNET_CONFIGURATION_Handle * config
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:476
struct GNUNET_SERVICE_Handle * service
void init_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Initializes list of handles as empty list.
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
const struct GNUNET_CONFIGURATION_Handle * config
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
#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_rooms()

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

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

References destroy_room(), GNUNET_YES, and value.

Referenced by destroy_service().

92 {
93  struct GNUNET_MESSENGER_SrvRoom *room = value;
94  destroy_room (room);
95  return GNUNET_YES;
96 }
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:

◆ destroy_service()

void destroy_service ( struct GNUNET_MESSENGER_Service service)

Destroys a service and frees its memory fully.

Parameters

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

References GNUNET_MESSENGER_Service::cadet, clear_contact_store(), clear_ego_store(), clear_list_handles(), GNUNET_MESSENGER_Service::dir, get_service_contact_store(), get_service_ego_store(), GNUNET_assert, GNUNET_CADET_disconnect(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_shutdown(), GNUNET_MESSENGER_Service::handles, iterate_destroy_rooms(), GNUNET_MESSENGER_Service::rooms, GNUNET_MESSENGER_Service::service, and GNUNET_MESSENGER_Service::shutdown.

Referenced by callback_shutdown_service().

100 {
101  GNUNET_assert(service);
102 
103  if (service->shutdown)
104  {
106 
107  service->shutdown = NULL;
108  }
109 
111  clear_list_handles (&(service->handles));
112 
115 
117 
118  if (service->cadet)
119  {
120  GNUNET_CADET_disconnect (service->cadet);
121 
122  service->cadet = NULL;
123  }
124 
125  if (service->dir)
126  {
127  GNUNET_free(service->dir);
128 
129  service->dir = NULL;
130  }
131 
132  GNUNET_SERVICE_shutdown (service->service);
133 
134  GNUNET_free(service);
135 }
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:775
struct GNUNET_MESSENGER_ContactStore * get_service_contact_store(struct GNUNET_MESSENGER_Service *service)
Returns the used contact store of a given service.
struct GNUNET_CADET_Handle * cadet
struct GNUNET_MESSENGER_ListHandles handles
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store)
Clears an EGO-store, wipes its content and deallocates its memory.
struct GNUNET_SCHEDULER_Task * shutdown
struct GNUNET_MESSENGER_EgoStore * get_service_ego_store(struct GNUNET_MESSENGER_Service *service)
Returns the used EGO-store of a given service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_SERVICE_Handle * service
void clear_list_handles(struct GNUNET_MESSENGER_ListHandles *handles)
Destroys remaining handles and clears the list.
static int iterate_destroy_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
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.
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:

◆ get_service_ego_store()

struct GNUNET_MESSENGER_EgoStore* get_service_ego_store ( struct GNUNET_MESSENGER_Service service)

Returns the used EGO-store of a given service.

Parameters

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

References GNUNET_MESSENGER_Service::ego_store, and GNUNET_assert.

Referenced by callback_set_handle_name(), callback_update_handle(), create_service(), destroy_service(), set_handle_name(), setup_handle_name(), and update_handle().

139 {
140  GNUNET_assert(service);
141 
142  return &(service->ego_store);
143 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_EgoStore ego_store
Here is the caller graph for this function:

◆ get_service_contact_store()

struct GNUNET_MESSENGER_ContactStore* get_service_contact_store ( struct GNUNET_MESSENGER_Service service)

Returns the used contact store of a given service.

Parameters

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

References GNUNET_MESSENGER_Service::contact_store, and GNUNET_assert.

Referenced by create_service(), destroy_service(), and get_member_contact_store().

147 {
148  GNUNET_assert(service);
149 
150  return &(service->contact_store);
151 }
struct GNUNET_MESSENGER_ContactStore contact_store
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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

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

References add_list_handle(), create_handle(), GNUNET_assert, handle, and GNUNET_MESSENGER_Service::handles.

Referenced by callback_client_connect().

155 {
156  GNUNET_assert((service) && (mq));
157 
158  struct GNUNET_MESSENGER_SrvHandle *handle = create_handle (service, mq);
159 
160  if (handle)
161  {
162  add_list_handle (&(service->handles), handle);
163  }
164 
165  return handle;
166 }
struct GNUNET_MESSENGER_ListHandles handles
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void add_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *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

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

References destroy_handle(), GNUNET_assert, GNUNET_YES, GNUNET_MESSENGER_Service::handles, and remove_list_handle().

Referenced by callback_client_disconnect().

170 {
171  GNUNET_assert((service) && (handle));
172 
173  if (!handle)
174  return;
175 
176  if (GNUNET_YES == remove_list_handle (&(service->handles), handle))
177  destroy_handle (handle);
178 }
int remove_list_handle(struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle)
Removes the first entry matching with a specific handle from the list of handles and returns GNUNET_Y...
struct GNUNET_MESSENGER_ListHandles handles
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
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
[in]serviceService
[out]peerPeer identity
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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

References GNUNET_MESSENGER_Service::config, GNUNET_assert, and GNUNET_CRYPTO_get_peer_identity().

Referenced by create_message_peer(), enter_room_at(), and rebuild_room_basement_structure().

182 {
183  GNUNET_assert((service) && (peer));
184 
185  return GNUNET_CRYPTO_get_peer_identity (service->config, peer);
186 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_room()

struct GNUNET_MESSENGER_SrvRoom* get_service_room ( const struct GNUNET_MESSENGER_Service service,
const struct GNUNET_HashCode key 
)

Returns the room identified by a given key for a service.

If the service doesn't know any room using the given key, NULL gets returned.

Parameters
[in]serviceService
[in]keyKey of room
Returns
Room or NULL

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

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_Service::rooms.

Referenced by close_service_room(), entry_service_room(), handle_get_message(), open_service_room(), and send_handle_message().

190 {
191  GNUNET_assert((service) && (key));
192 
193  return GNUNET_CONTAINER_multihashmap_get (service->rooms, key);
194 }
#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.
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

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

References create_room(), destroy_room(), get_service_room(), GNUNET_assert, 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().

199 {
200  GNUNET_assert((service) && (handle) && (key));
201 
202  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
203 
204  if (room)
205  return open_room (room, handle);
206 
207  room = create_room (handle, key);
208 
209  if ((GNUNET_YES == open_room (room, handle)) &&
211  key, room,
213  return GNUNET_YES;
214 
215  destroy_room (room);
216  return GNUNET_NO;
217 }
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
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

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

References create_room(), destroy_room(), enter_room_at(), get_service_room(), GNUNET_assert, 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().

222 {
223  GNUNET_assert((service) && (handle) && (door) && (key));
224 
225  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
226 
227  if (room)
228  {
229  if (GNUNET_YES == enter_room_at (room, handle, door))
230  return GNUNET_YES;
231  else
232  return GNUNET_NO;
233  }
234 
235  room = create_room (handle, key);
236 
237  if ((GNUNET_YES == enter_room_at (room, handle, door)) &&
239  key, room,
241  {
242  return GNUNET_YES;
243  }
244  else
245  {
246  destroy_room (room);
247  return GNUNET_NO;
248  }
249 
250 }
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.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
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 enter_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

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

References create_message_leave(), 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().

255 {
256  GNUNET_assert((service) && (handle) && (key));
257 
258  struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
259 
260  if (!room)
261  return GNUNET_NO;
262 
263  send_room_message (room, handle, create_message_leave ());
264 
265  const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key);
266 
267  GNUNET_assert(id);
268 
270  return GNUNET_NO;
271 
273  &(service->handles), key);
274 
275  if (!member_handle)
276  {
277  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room))
278  {
279  destroy_room (room);
280  return GNUNET_YES;
281  }
282  else
283  return GNUNET_NO;
284  }
285 
286  if (room->host == handle)
287  room->host = member_handle;
288 
289  return GNUNET_YES;
290 }
struct GNUNET_MESSENGER_SrvHandle * find_list_handle_by_member(const 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...
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.
int send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
A 256-bit hashcode.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
struct GNUNET_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_HashCode key
The key used in the DHT.
struct GNUNET_MESSENGER_SrvHandle * host
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.
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_MemberSession session,
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

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

References get_room_key(), GNUNET_assert, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_Service::handles, GNUNET_MESSENGER_ListHandles::head, GNUNET_MESSENGER_ListHandle::next, and notify_handle_message().

Referenced by handle_room_messages().

296 {
297  GNUNET_assert((service) && (room) && (session) && (message) && (hash));
298 
299  struct GNUNET_MESSENGER_ListHandle *element = service->handles.head;
300 
301  while (element)
302  {
303  notify_handle_message (element->handle, get_room_key(room), session, message, hash);
304  element = element->next;
305  }
306 }
struct GNUNET_MESSENGER_ListHandles handles
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListHandle * next
void notify_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Notifies the handle that a new message was received or sent.
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
struct GNUNET_MESSENGER_ListHandle * head
struct GNUNET_MESSENGER_SrvHandle * handle
Here is the call graph for this function:
Here is the caller graph for this function: