GNUnet  0.11.x
Data Structures | Functions
messenger_api_list_tunnels.h File Reference

messenger api: client and service implementation of GNUnet MESSENGER service More...

#include "platform.h"
#include "gnunet_peer_lib.h"
#include "gnunet_container_lib.h"
Include dependency graph for messenger_api_list_tunnels.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_ListTunnel
 
struct  GNUNET_MESSENGER_ListTunnels
 

Functions

void init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels)
 Initializes list of tunnels peer identities as empty list. More...
 
void clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels)
 Clears the list of tunnels peer identities. More...
 
void add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
 Adds a specific peer from a tunnel to the end of the list. More...
 
struct GNUNET_MESSENGER_ListTunnelfind_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
 Searches linearly through the list of tunnels peer identities for matching a specific peer identity and returns the matching element of the list. More...
 
int contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
 Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns GNUNET_YES on success, otherwise GNUNET_NO. More...
 
struct GNUNET_MESSENGER_ListTunnelremove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element)
 Removes a specific element from the list of tunnels peer identities and returns the next element in the list. More...
 

Detailed Description

messenger api: client and service implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_list_tunnels.h.

Function Documentation

◆ init_list_tunnels()

void init_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels)

Initializes list of tunnels peer identities as empty list.

Parameters
tunnelsList of peer identities

Definition at line 29 of file messenger_api_list_tunnels.c.

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

Referenced by create_room().

30 {
31  GNUNET_assert(tunnels);
32 
33  tunnels->head = NULL;
34  tunnels->tail = NULL;
35 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * tail
Here is the caller graph for this function:

◆ clear_list_tunnels()

void clear_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels)

Clears the list of tunnels peer identities.

Parameters
tunnelsList of peer identities

Definition at line 38 of file messenger_api_list_tunnels.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PEER_change_rc(), GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::peer, and GNUNET_MESSENGER_ListTunnels::tail.

Referenced by destroy_room().

39 {
40  GNUNET_assert(tunnels);
41 
42  struct GNUNET_MESSENGER_ListTunnel *element;
43 
44  for (element = tunnels->head; element; element = tunnels->head)
45  {
46  GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element);
47  GNUNET_PEER_change_rc (element->peer, -1);
48  GNUNET_free(element);
49  }
50 
51  tunnels->head = NULL;
52  tunnels->tail = NULL;
53 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * tail
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:197
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_list_tunnels()

void add_to_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer 
)

Adds a specific peer from a tunnel to the end of the list.

Parameters
tunnelsList of peer identities
peerPeer identity of tunnel

Definition at line 63 of file messenger_api_list_tunnels.c.

References compare_list_tunnels(), GNUNET_CONTAINER_DLL_insert_sorted, GNUNET_new, GNUNET_PEER_intern(), GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::peer, and GNUNET_MESSENGER_ListTunnels::tail.

Referenced by entry_handle_room_at(), and handle_message_peer().

64 {
66 
67  element->peer = GNUNET_PEER_intern (peer);
68 
70  tunnels->tail, element);
71 }
#define GNUNET_CONTAINER_DLL_insert_sorted(TYPE, comparator, comparator_cls, head, tail, element)
Insertion sort of element into DLL from head to tail sorted by comparator.
struct GNUNET_MESSENGER_ListTunnel * head
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int compare_list_tunnels(void *cls, struct GNUNET_MESSENGER_ListTunnel *element0, struct GNUNET_MESSENGER_ListTunnel *element1)
struct GNUNET_MESSENGER_ListTunnel * tail
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:107
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_list_tunnels()

struct GNUNET_MESSENGER_ListTunnel* find_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer,
size_t *  index 
)

Searches linearly through the list of tunnels peer identities for matching a specific peer identity and returns the matching element of the list.

If no matching element is found, NULL gets returned.

If index is not NULL, index will be overriden with the numeric index of the found element in the list. If no matching element is found, index will contain the total amount of elements in the list.

Parameters
tunnelsList of peer identities
peerPeer identity of tunnel
[out]indexIndex of found element (optional)
Returns
Element in the list with matching peer identity

Definition at line 74 of file messenger_api_list_tunnels.c.

References GNUNET_memcmp, GNUNET_PEER_resolve(), GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, and GNUNET_MESSENGER_ListTunnel::peer.

Referenced by contains_list_tunnels(), handle_message_miss(), handle_miss_message(), and rebuild_room_basement_structure().

75 {
76  struct GNUNET_MESSENGER_ListTunnel *element;
77  struct GNUNET_PeerIdentity pid;
78 
79  if (index)
80  *index = 0;
81 
82  for (element = tunnels->head; element; element = element->next)
83  {
84  GNUNET_PEER_resolve (element->peer, &pid);
85 
86  if (0 == GNUNET_memcmp(&pid, peer))
87  return element;
88 
89  if (index)
90  (*index) = (*index) + 1;
91  }
92 
93  return NULL;
94 }
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * next
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains_list_tunnels()

int contains_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer 
)

Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns GNUNET_YES on success, otherwise GNUNET_NO.

Parameters
tunnelsList of peer identities
peerPeer identity of tunnel
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 97 of file messenger_api_list_tunnels.c.

References find_list_tunnels(), GNUNET_NO, and GNUNET_YES.

Referenced by callback_room_disconnect(), and handle_message_peer().

98 {
99  return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES : GNUNET_NO;
100 }
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
Searches linearly through the list of tunnels peer identities for matching a specific peer identity a...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_from_list_tunnels()

struct GNUNET_MESSENGER_ListTunnel* remove_from_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
struct GNUNET_MESSENGER_ListTunnel element 
)

Removes a specific element from the list of tunnels peer identities and returns the next element in the list.

Parameters
tunnelsList of peer identities
elementElement of the list
Returns
Next element in the list

Definition at line 103 of file messenger_api_list_tunnels.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PEER_change_rc(), GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_ListTunnel::peer, and GNUNET_MESSENGER_ListTunnels::tail.

Referenced by handle_message_miss(), handle_miss_message(), and rebuild_room_basement_structure().

104 {
105  struct GNUNET_MESSENGER_ListTunnel *next = element->next;
106 
107  GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element);
108  GNUNET_PEER_change_rc (element->peer, -1);
109  GNUNET_free(element);
110 
111  return next;
112 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * tail
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:197
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: