GNUnet 0.21.1
messenger_api_list_tunnels.c File Reference
Include dependency graph for messenger_api_list_tunnels.c:

Go to the source code of this file.

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...
 
static int compare_list_tunnels (void *cls, struct GNUNET_MESSENGER_ListTunnel *element0, struct GNUNET_MESSENGER_ListTunnel *element1)
 
void add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
 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...
 
struct GNUNET_MESSENGER_ListTunnelfind_list_tunnels_alternate (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
 Searches linearly through the list of tunnels peer identities for matching against a specific peer identity and returns an element of the list which does not match it. More...
 
enum GNUNET_GenericReturnValue verify_list_tunnels_flag_token (const struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MESSENGER_ConnectionFlags flag)
 Verifies that a specific tunnel selected by its peer identity in a list of tunnels is the first in order with a given connection flag. More...
 
void update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
 Updates a specific peer from a tunnel in the list. More...
 
enum GNUNET_GenericReturnValue 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...
 

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 tunnels

Definition at line 29 of file messenger_api_list_tunnels.c.

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 * tail
struct GNUNET_MESSENGER_ListTunnel * head

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

Referenced by create_room(), and create_srv_room().

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
[in,out]tunnelsList of tunnels

Definition at line 39 of file messenger_api_list_tunnels.c.

40{
41 GNUNET_assert (tunnels);
42
43 struct GNUNET_MESSENGER_ListTunnel *element;
44 for (element = tunnels->head; element;
45 element = remove_from_list_tunnels (tunnels, element))
46
47 tunnels->head = NULL;
48 tunnels->tail = NULL;
49}
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 t...

References GNUNET_assert, GNUNET_MESSENGER_ListTunnels::head, remove_from_list_tunnels(), and GNUNET_MESSENGER_ListTunnels::tail.

Referenced by destroy_room(), and destroy_srv_room().

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

◆ compare_list_tunnels()

static int compare_list_tunnels ( void *  cls,
struct GNUNET_MESSENGER_ListTunnel element0,
struct GNUNET_MESSENGER_ListTunnel element1 
)
static

Definition at line 53 of file messenger_api_list_tunnels.c.

56{
57 struct GNUNET_PeerIdentity peer0, peer1;
58
59 GNUNET_PEER_resolve (element0->peer, &peer0);
60 GNUNET_PEER_resolve (element1->peer, &peer1);
61
62 return GNUNET_memcmp (&peer0, &peer1);
63}
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:220
The identity of the host (wraps the signing key of the peer).

References GNUNET_memcmp, GNUNET_PEER_resolve(), and GNUNET_MESSENGER_ListTunnel::peer.

Referenced by add_to_list_tunnels().

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,
const struct GNUNET_HashCode hash 
)

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

Optionally adds the hash of the peer message from the specific peer.

Parameters
[in,out]tunnelsList of tunnels
[in]peerPeer identity of tunnel
[in]hashHash of peer message or NULL

Definition at line 67 of file messenger_api_list_tunnels.c.

70{
71 GNUNET_assert ((tunnels) && (peer));
72
73 struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new (struct
75
76 element->peer = GNUNET_PEER_intern (peer);
77 element->hash = hash ? GNUNET_memdup (hash, sizeof (struct GNUNET_HashCode)) :
78 NULL;
79
80 memset (&(element->connection), 0, sizeof (element->connection));
81
83 compare_list_tunnels, NULL, tunnels->head,
84 tunnels->tail, element);
85}
#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_new(type)
Allocate a struct or union of the given type.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:108
static int compare_list_tunnels(void *cls, struct GNUNET_MESSENGER_ListTunnel *element0, struct GNUNET_MESSENGER_ListTunnel *element1)
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessageConnection connection

References compare_list_tunnels(), GNUNET_MESSENGER_ListTunnel::connection, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_sorted, GNUNET_memdup, GNUNET_new, GNUNET_PEER_intern(), GNUNET_MESSENGER_ListTunnel::hash, 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().

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
[in,out]tunnelsList of tunnels
[in]peerPeer identity of tunnel
[out]indexIndex of found element (optional)
Returns
Element in the list with matching peer identity

Definition at line 89 of file messenger_api_list_tunnels.c.

92{
93 GNUNET_assert ((tunnels) && (peer));
94
95 struct GNUNET_MESSENGER_ListTunnel *element;
97
98 if (index)
99 *index = 0;
100
101 for (element = tunnels->head; element; element = element->next)
102 {
103 GNUNET_PEER_resolve (element->peer, &pid);
104
105 if (0 == GNUNET_memcmp (&pid, peer))
106 return element;
107
108 if (index)
109 (*index) = (*index) + 1;
110 }
111
112 return NULL;
113}
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_MESSENGER_ListTunnel * next

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

Referenced by contains_list_tunnels(), handle_message_connection(), handle_message_miss(), handle_miss_message(), rebuild_srv_room_basement_structure(), and update_to_list_tunnels().

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

◆ find_list_tunnels_alternate()

struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels_alternate ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer 
)

Searches linearly through the list of tunnels peer identities for matching against a specific peer identity and returns an element of the list which does not match it.

Parameters
[in,out]tunnelsList of tunnels
[in]peerPeer identity of tunnel
Returns
Element in the list with unmatching peer identity

Definition at line 117 of file messenger_api_list_tunnels.c.

119{
120 GNUNET_assert ((tunnels) && (peer));
121
122 struct GNUNET_MESSENGER_ListTunnel *element;
124
125 for (element = tunnels->head; element; element = element->next)
126 {
127 GNUNET_PEER_resolve (element->peer, &pid);
128
129 if (0 != GNUNET_memcmp (&pid, peer))
130 return element;
131 }
132
133 return NULL;
134}

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

Referenced by callback_room_disconnect().

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

◆ verify_list_tunnels_flag_token()

enum GNUNET_GenericReturnValue verify_list_tunnels_flag_token ( const struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer,
enum GNUNET_MESSENGER_ConnectionFlags  flag 
)

Verifies that a specific tunnel selected by its peer identity in a list of tunnels is the first in order with a given connection flag.

Parameters
[in]tunnelsList of tunnels
[in]peerPeer identity of tunnel
[in]flagConnection flag mask
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 138 of file messenger_api_list_tunnels.c.

142{
143 GNUNET_assert ((tunnels) && (peer) && (flag));
144
145 struct GNUNET_MESSENGER_ListTunnel *element;
147
148 for (element = tunnels->head; element; element = element->next)
149 {
150 if ((element->connection.flags & flag) != flag)
151 continue;
152
153 GNUNET_PEER_resolve (element->peer, &pid);
154
155 if (0 == GNUNET_memcmp (&pid, peer))
156 return GNUNET_OK;
157 }
158
159 return GNUNET_SYSERR;
160}
@ GNUNET_OK
@ GNUNET_SYSERR
uint32_t flags
The flags about the connections of a peer.

References GNUNET_MESSENGER_ListTunnel::connection, GNUNET_MESSENGER_MessageConnection::flags, GNUNET_assert, GNUNET_memcmp, GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_SYSERR, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_ListTunnel::peer, and pid.

Referenced by rebuild_srv_room_basement_structure().

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

◆ update_to_list_tunnels()

void update_to_list_tunnels ( struct GNUNET_MESSENGER_ListTunnels tunnels,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HashCode hash 
)

Updates a specific peer from a tunnel in the list.

This function exists to add the hash of a newer peer message from the specific peer to the list element. It can also remove the hash when NULL is provided as new hash value.

Parameters
[in,out]tunnelsList of tunnels
[in]peerPeer identity of tunnel
[in]hashHash of peer message or NULL

Definition at line 164 of file messenger_api_list_tunnels.c.

167{
168 GNUNET_assert ((tunnels) && (peer));
169
170 struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (tunnels,
171 peer,
172 NULL);
173 if (! element)
174 return;
175
176 if (element->hash)
177 {
178 if (hash)
179 GNUNET_memcpy (element->hash, hash, sizeof(struct GNUNET_HashCode));
180 else
181 {
182 GNUNET_free (element->hash);
183 element->hash = NULL;
184 }
185 }
186 else if (hash)
187 element->hash = GNUNET_memdup (hash, sizeof(struct GNUNET_HashCode));
188}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_free(ptr)
Wrapper around free.
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...

References find_list_tunnels(), GNUNET_assert, GNUNET_free, GNUNET_memcpy, GNUNET_memdup, GNUNET_MESSENGER_ListTunnel::hash, and GNUNET_MESSENGER_ListTunnel::peer.

Referenced by recv_message_peer().

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

◆ contains_list_tunnels()

enum GNUNET_GenericReturnValue 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
[in,out]tunnelsList of tunnels
[in]peerPeer identity of tunnel
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 192 of file messenger_api_list_tunnels.c.

194{
195 GNUNET_assert ((tunnels) && (peer));
196
197 return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES :
198 GNUNET_NO;
199}
@ GNUNET_YES
@ GNUNET_NO

References find_list_tunnels(), GNUNET_assert, GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_ListTunnel::peer.

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

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
[in,out]tunnelsList of tunnels
[in,out]elementElement of the list
Returns
Next element in the list

Definition at line 203 of file messenger_api_list_tunnels.c.

205{
206 GNUNET_assert ((tunnels) && (element));
207
208 struct GNUNET_MESSENGER_ListTunnel *next = element->next;
209
210 if ((tunnels->head) && (tunnels->tail))
211 GNUNET_CONTAINER_DLL_remove (tunnels->head, tunnels->tail, element);
212
213 if (element->hash)
214 GNUNET_free (element->hash);
215
216 GNUNET_PEER_change_rc (element->peer, -1);
217 GNUNET_free (element);
218
219 return next;
220}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:192

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

Referenced by clear_list_tunnels(), handle_message_miss(), handle_miss_message(), and rebuild_srv_room_basement_structure().

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]tunnelsList of tunnels
[in]pathPath of file

Definition at line 224 of file messenger_api_list_tunnels.c.

226{
227 GNUNET_assert ((tunnels) && (path));
228
229 if (GNUNET_YES != GNUNET_DISK_file_test (path))
230 return;
231
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load list of tunnels from path: %s\n",
233 path);
234
237
239 path, GNUNET_DISK_OPEN_READ, permission
240 );
241
242 if (! handle)
243 return;
244
246
247 struct GNUNET_PeerIdentity peer;
248 ssize_t len;
249
250 do {
251 len = GNUNET_DISK_file_read (handle, &peer, sizeof(peer));
252
253 if (len != sizeof(peer))
254 break;
255
256 add_to_list_tunnels (tunnels, &peer, NULL);
257 } while (len == sizeof(peer));
258
260}
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
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:1237
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
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:205
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
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
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_SEEK_SET
Seek an absolute position (from the start of the file).
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
Adds a specific peer from a tunnel to the end of the list.
Handle used to access files (and pipes).

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_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, and handle.

Referenced by load_srv_room().

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]tunnelsList of tunnels
[in]pathPath of file

Definition at line 264 of file messenger_api_list_tunnels.c.

266{
267 GNUNET_assert ((tunnels) && (path));
268
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save list of tunnels to path: %s\n",
270 path);
271
274
277 );
278
279 if (! handle)
280 return;
281
283
284 struct GNUNET_MESSENGER_ListTunnel *element;
286
287 for (element = tunnels->head; element; element = element->next)
288 {
289 GNUNET_PEER_resolve (element->peer, &pid);
290
292 }
293
296}
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
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1427
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.

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_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_PEER_resolve(), handle, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_ListTunnel::peer, and pid.

Referenced by save_srv_room().

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