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...
 
void load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
 Loads the list of tunnels peer identities from a file under a given path. More...
 
void save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const char *path)
 Saves the list of tunnels peer identities to a file under a given path. 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
[out]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

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

Definition at line 63 of file messenger_api_list_tunnels.c.

References compare_list_tunnels(), GNUNET_assert, 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(), handle_message_peer(), and load_list_tunnels().

64 {
65  GNUNET_assert((tunnels) && (peer));
66 
68 
69  element->peer = GNUNET_PEER_intern (peer);
70 
72  tunnels->tail, element);
73 }
#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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 overridden 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

Definition at line 76 of file messenger_api_list_tunnels.c.

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

77 {
78  GNUNET_assert((tunnels) && (peer));
79 
80  struct GNUNET_MESSENGER_ListTunnel *element;
81  struct GNUNET_PeerIdentity pid;
82 
83  if (index)
84  *index = 0;
85 
86  for (element = tunnels->head; element; element = element->next)
87  {
88  GNUNET_PEER_resolve (element->peer, &pid);
89 
90  if (0 == GNUNET_memcmp(&pid, peer))
91  return element;
92 
93  if (index)
94  (*index) = (*index) + 1;
95  }
96 
97  return NULL;
98 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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

Definition at line 101 of file messenger_api_list_tunnels.c.

References find_list_tunnels(), GNUNET_assert, GNUNET_NO, and GNUNET_YES.

Referenced by callback_room_disconnect(), handle_message_peer(), and recv_message_info().

102 {
103  GNUNET_assert((tunnels) && (peer));
104 
105  return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES : GNUNET_NO;
106 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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

Definition at line 109 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::next, GNUNET_MESSENGER_ListTunnel::peer, and GNUNET_MESSENGER_ListTunnels::tail.

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

110 {
111  GNUNET_assert((tunnels) && (element));
112 
113  struct GNUNET_MESSENGER_ListTunnel *next = element->next;
114 
115  GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element);
116  GNUNET_PEER_change_rc (element->peer, -1);
117  GNUNET_free(element);
118 
119  return next;
120 }
#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 * 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:

◆ load_list_tunnels()

void load_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const char *  path 
)

Loads the list of tunnels peer identities from a file under a given path.

Parameters
[out]messagesList of hashes
[in]pathPath of file

Definition at line 123 of file messenger_api_list_tunnels.c.

References add_to_list_tunnels(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_YES, handle, and len.

Referenced by load_room().

124 {
125  GNUNET_assert((tunnels) && (path));
126 
127  if (GNUNET_YES != GNUNET_DISK_file_test (path))
128  return;
129 
131 
133  path, GNUNET_DISK_OPEN_READ, permission
134  );
135 
136  if (!handle)
137  return;
138 
140 
141  struct GNUNET_PeerIdentity peer;
142  ssize_t len;
143 
144  do {
145  len = GNUNET_DISK_file_read(handle, &peer, sizeof(peer));
146 
147  if (len != sizeof(peer))
148  break;
149 
150  add_to_list_tunnels(tunnels, &peer);
151  } while (len == sizeof(peer));
152 
153  GNUNET_DISK_file_close(handle);
154 }
Open the file for reading.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1283
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.
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
The identity of the host (wraps the signing key of the peer).
Seek an absolute position (from the start of the file).
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1212
Handle used to access files (and pipes).
enum GNUNET_GenericReturnValue 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:482
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_list_tunnels()

void save_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const char *  path 
)

Saves the list of tunnels peer identities to a file under a given path.

Parameters
[in]messagesList of hashes
[in]pathPath of file

Definition at line 157 of file messenger_api_list_tunnels.c.

References GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_sync(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_PEER_resolve(), handle, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, and GNUNET_MESSENGER_ListTunnel::peer.

Referenced by save_room().

158 {
159  GNUNET_assert((tunnels) && (path));
160 
162 
165  );
166 
167  if (!handle)
168  return;
169 
171 
172  struct GNUNET_MESSENGER_ListTunnel *element;
173  struct GNUNET_PeerIdentity pid;
174 
175  for (element = tunnels->head; element; element = element->next)
176  {
177  GNUNET_PEER_resolve (element->peer, &pid);
178 
179  GNUNET_DISK_file_write(handle, &pid, sizeof(pid));
180  }
181 
182  GNUNET_DISK_file_sync(handle);
183  GNUNET_DISK_file_close(handle);
184 }
Create file if it doesn't exist.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1283
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * next
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
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
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
Open the file for writing.
The identity of the host (wraps the signing key of the peer).
Seek an absolute position (from the start of the file).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1402
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1212
Handle used to access files (and pipes).
Here is the call graph for this function:
Here is the caller graph for this function: