diff options
Diffstat (limited to 'src/messenger/messenger_api_list_tunnels.c')
-rw-r--r-- | src/messenger/messenger_api_list_tunnels.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/messenger/messenger_api_list_tunnels.c b/src/messenger/messenger_api_list_tunnels.c index a4126c286..4d0deb95d 100644 --- a/src/messenger/messenger_api_list_tunnels.c +++ b/src/messenger/messenger_api_list_tunnels.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -41,13 +41,7 @@ clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) | |||
41 | GNUNET_assert(tunnels); | 41 | GNUNET_assert(tunnels); |
42 | 42 | ||
43 | struct GNUNET_MESSENGER_ListTunnel *element; | 43 | struct GNUNET_MESSENGER_ListTunnel *element; |
44 | 44 | for (element = tunnels->head; element; element = remove_from_list_tunnels(tunnels, element)) | |
45 | for (element = tunnels->head; element; element = tunnels->head) | ||
46 | { | ||
47 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | ||
48 | GNUNET_PEER_change_rc (element->peer, -1); | ||
49 | GNUNET_free(element); | ||
50 | } | ||
51 | 45 | ||
52 | tunnels->head = NULL; | 46 | tunnels->head = NULL; |
53 | tunnels->tail = NULL; | 47 | tunnels->tail = NULL; |
@@ -63,13 +57,15 @@ compare_list_tunnels (void *cls, | |||
63 | 57 | ||
64 | void | 58 | void |
65 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 59 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
66 | const struct GNUNET_PeerIdentity *peer) | 60 | const struct GNUNET_PeerIdentity *peer, |
61 | const struct GNUNET_HashCode *hash) | ||
67 | { | 62 | { |
68 | GNUNET_assert((tunnels) && (peer)); | 63 | GNUNET_assert((tunnels) && (peer)); |
69 | 64 | ||
70 | struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new(struct GNUNET_MESSENGER_ListTunnel); | 65 | struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new(struct GNUNET_MESSENGER_ListTunnel); |
71 | 66 | ||
72 | element->peer = GNUNET_PEER_intern (peer); | 67 | element->peer = GNUNET_PEER_intern (peer); |
68 | element->hash = hash ? GNUNET_memdup(hash, sizeof(struct GNUNET_HashCode)) : NULL; | ||
73 | 69 | ||
74 | GNUNET_CONTAINER_DLL_insert_sorted(struct GNUNET_MESSENGER_ListTunnel, compare_list_tunnels, NULL, tunnels->head, | 70 | GNUNET_CONTAINER_DLL_insert_sorted(struct GNUNET_MESSENGER_ListTunnel, compare_list_tunnels, NULL, tunnels->head, |
75 | tunnels->tail, element); | 71 | tunnels->tail, element); |
@@ -102,6 +98,31 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
102 | return NULL; | 98 | return NULL; |
103 | } | 99 | } |
104 | 100 | ||
101 | void | ||
102 | update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | ||
103 | const struct GNUNET_PeerIdentity *peer, | ||
104 | const struct GNUNET_HashCode *hash) | ||
105 | { | ||
106 | GNUNET_assert((tunnels) && (peer)); | ||
107 | |||
108 | struct GNUNET_MESSENGER_ListTunnel* element = find_list_tunnels(tunnels, peer, NULL); | ||
109 | if (!element) | ||
110 | return; | ||
111 | |||
112 | if (element->hash) | ||
113 | { | ||
114 | if (hash) | ||
115 | GNUNET_memcpy(element->hash, hash, sizeof(struct GNUNET_HashCode)); | ||
116 | else | ||
117 | { | ||
118 | GNUNET_free(element->hash); | ||
119 | element->hash = NULL; | ||
120 | } | ||
121 | } | ||
122 | else if (hash) | ||
123 | element->hash = GNUNET_memdup(hash, sizeof(struct GNUNET_HashCode)); | ||
124 | } | ||
125 | |||
105 | int | 126 | int |
106 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 127 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
107 | const struct GNUNET_PeerIdentity *peer) | 128 | const struct GNUNET_PeerIdentity *peer) |
@@ -119,7 +140,12 @@ remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
119 | 140 | ||
120 | struct GNUNET_MESSENGER_ListTunnel *next = element->next; | 141 | struct GNUNET_MESSENGER_ListTunnel *next = element->next; |
121 | 142 | ||
122 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | 143 | if ((tunnels->head) && (tunnels->tail)) |
144 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | ||
145 | |||
146 | if (element->hash) | ||
147 | GNUNET_free(element->hash); | ||
148 | |||
123 | GNUNET_PEER_change_rc (element->peer, -1); | 149 | GNUNET_PEER_change_rc (element->peer, -1); |
124 | GNUNET_free(element); | 150 | GNUNET_free(element); |
125 | 151 | ||
@@ -155,7 +181,7 @@ load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
155 | if (len != sizeof(peer)) | 181 | if (len != sizeof(peer)) |
156 | break; | 182 | break; |
157 | 183 | ||
158 | add_to_list_tunnels(tunnels, &peer); | 184 | add_to_list_tunnels(tunnels, &peer, NULL); |
159 | } while (len == sizeof(peer)); | 185 | } while (len == sizeof(peer)); |
160 | 186 | ||
161 | GNUNET_DISK_file_close(handle); | 187 | GNUNET_DISK_file_close(handle); |