GNUnet  0.20.0
gnunet-service-messenger_list_handles.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-service-messenger_list_handles.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_ListHandle
 
struct  GNUNET_MESSENGER_ListHandles
 

Functions

void init_list_handles (struct GNUNET_MESSENGER_ListHandles *handles)
 Initializes list of handles as empty list. More...
 
void clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles)
 Destroys remaining handles and clears the list. More...
 
void add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, struct GNUNET_MESSENGER_SrvHandle *handle)
 Adds a specific handle to the end of the list. More...
 
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_YES on success or GNUNET_NO on failure. More...
 
struct GNUNET_MESSENGER_SrvHandlefind_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 given key. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_list_handles.h.

Function Documentation

◆ init_list_handles()

void init_list_handles ( struct GNUNET_MESSENGER_ListHandles handles)

Initializes list of handles as empty list.

Parameters
[out]handlesList of handles

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

33 {
34  GNUNET_assert(handles);
35 
36  handles->head = NULL;
37  handles->tail = NULL;
38 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListHandle * tail
struct GNUNET_MESSENGER_ListHandle * head

References GNUNET_assert, GNUNET_MESSENGER_ListHandles::head, and GNUNET_MESSENGER_ListHandles::tail.

Referenced by create_service().

Here is the caller graph for this function:

◆ clear_list_handles()

void clear_list_handles ( struct GNUNET_MESSENGER_ListHandles handles)

Destroys remaining handles and clears the list.

Parameters
[in,out]handlesList of handles

Definition at line 41 of file gnunet-service-messenger_list_handles.c.

42 {
43  GNUNET_assert(handles);
44 
45  while (handles->head)
46  {
47  struct GNUNET_MESSENGER_ListHandle *element = handles->head;
48 
49  GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element);
50  destroy_srv_handle (element->handle);
51  GNUNET_free(element);
52  }
53 
54  handles->head = NULL;
55  handles->tail = NULL;
56 }
void destroy_srv_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MESSENGER_SrvHandle * handle

References destroy_srv_handle(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_ListHandles::head, and GNUNET_MESSENGER_ListHandles::tail.

Referenced by destroy_service().

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

◆ add_list_handle()

void add_list_handle ( struct GNUNET_MESSENGER_ListHandles handles,
struct GNUNET_MESSENGER_SrvHandle handle 
)

Adds a specific handle to the end of the list.

Parameters
[in,out]handlesList of handles
[in,out]handleHandle

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

61 {
62  GNUNET_assert((handles) && (handle));
63 
65 
66  element->handle = handle;
67 
68  GNUNET_CONTAINER_DLL_insert_tail(handles->head, handles->tail, element);
69 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, handle, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_ListHandles::head, and GNUNET_MESSENGER_ListHandles::tail.

Referenced by add_service_handle().

Here is the caller graph for this function:

◆ remove_list_handle()

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_YES on success or GNUNET_NO on failure.

Parameters
[in,out]handlesList of handles
[in,out]handleHandle
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 72 of file gnunet-service-messenger_list_handles.c.

74 {
75  GNUNET_assert((handles) && (handle));
76 
77  struct GNUNET_MESSENGER_ListHandle *element;
78 
79  for (element = handles->head; element; element = element->next)
80  if (element->handle == handle)
81  break;
82 
83  if (!element)
84  return GNUNET_NO;
85 
86  GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element);
87  GNUNET_free(element);
88 
89  return GNUNET_YES;
90 }
@ GNUNET_YES
@ GNUNET_NO
struct GNUNET_MESSENGER_ListHandle * next

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, GNUNET_YES, handle, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_ListHandles::head, GNUNET_MESSENGER_ListHandle::next, and GNUNET_MESSENGER_ListHandles::tail.

Referenced by remove_service_handle().

Here is the caller graph for this function:

◆ find_list_handle_by_member()

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 given key.

If no handle is found which is a current member, NULL gets returned.

Parameters
[in]handlesList of handles
[in]keyCommon key of a room
Returns
First handle which is a current member

Definition at line 93 of file gnunet-service-messenger_list_handles.c.

95 {
96  GNUNET_assert((handles) && (key));
97 
98  struct GNUNET_MESSENGER_ListHandle *element;
99 
100  for (element = handles->head; element; element = element->next)
102  return element->handle;
103 
104  return NULL;
105 }
struct GNUNET_HashCode key
The key used in the DHT.
const struct GNUNET_ShortHashCode * get_srv_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.

References get_srv_handle_member_id(), GNUNET_assert, GNUNET_MESSENGER_ListHandle::handle, GNUNET_MESSENGER_ListHandles::head, key, and GNUNET_MESSENGER_ListHandle::next.

Referenced by close_service_room().

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