aboutsummaryrefslogtreecommitdiff
path: root/src/util/peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/peer.c')
-rw-r--r--src/util/peer.c112
1 files changed, 57 insertions, 55 deletions
diff --git a/src/util/peer.c b/src/util/peer.c
index 96ac271c0..91a706040 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -91,14 +91,14 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
91 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); 91 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
92 e = (off == 0) ? NULL : &table[off]; 92 e = (off == 0) ? NULL : &table[off];
93 if (e != NULL) 93 if (e != NULL)
94 { 94 {
95 GNUNET_assert (e->rc > 0); 95 GNUNET_assert (e->rc > 0);
96 return e->pid; 96 return e->pid;
97 } 97 }
98 else 98 else
99 { 99 {
100 return 0; 100 return 0;
101 } 101 }
102} 102}
103 103
104/** 104/**
@@ -123,24 +123,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
123 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); 123 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
124 e = (off == 0) ? NULL : &table[off]; 124 e = (off == 0) ? NULL : &table[off];
125 if (e != NULL) 125 if (e != NULL)
126 { 126 {
127 GNUNET_assert (e->rc > 0); 127 GNUNET_assert (e->rc > 0);
128 e->rc++; 128 e->rc++;
129 return e->pid; 129 return e->pid;
130 } 130 }
131 ret = free_list_start; 131 ret = free_list_start;
132 if (ret == size) 132 if (ret == size)
133 { 133 {
134 GNUNET_array_grow (table, size, size + 16); 134 GNUNET_array_grow (table, size, size + 16);
135 for (i = ret; i < size; i++) 135 for (i = ret; i < size; i++)
136 table[i].pid = i + 1; 136 table[i].pid = i + 1;
137 } 137 }
138 if (ret == 0) 138 if (ret == 0)
139 { 139 {
140 table[0].pid = 0; 140 table[0].pid = 0;
141 table[0].rc = 1; 141 table[0].rc = 1;
142 ret = 1; 142 ret = 1;
143 } 143 }
144 GNUNET_assert (ret < size); 144 GNUNET_assert (ret < size);
145 GNUNET_assert (table[ret].rc == 0); 145 GNUNET_assert (table[ret].rc == 0);
146 free_list_start = table[ret].pid; 146 free_list_start = table[ret].pid;
@@ -148,10 +148,10 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
148 table[ret].rc = 1; 148 table[ret].rc = 1;
149 table[ret].pid = ret; 149 table[ret].pid = ret;
150 GNUNET_break (GNUNET_OK == 150 GNUNET_break (GNUNET_OK ==
151 GNUNET_CONTAINER_multihashmap_put (map, 151 GNUNET_CONTAINER_multihashmap_put (map,
152 &pid->hashPubKey, 152 &pid->hashPubKey,
153 (void *) (long) ret, 153 (void *) (long) ret,
154 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 154 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
155 return ret; 155 return ret;
156} 156}
157 157
@@ -163,7 +163,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
163 * @param count size of the ids array 163 * @param count size of the ids array
164 */ 164 */
165void 165void
166GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) 166GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
167{ 167{
168 int i; 168 int i;
169 GNUNET_PEER_Id id; 169 GNUNET_PEER_Id id;
@@ -171,23 +171,24 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count)
171 if (count == 0) 171 if (count == 0)
172 return; 172 return;
173 for (i = count - 1; i >= 0; i--) 173 for (i = count - 1; i >= 0; i--)
174 {
175 id = ids[i];
176 if (id == 0)
177 continue;
178 GNUNET_assert (id < size);
179 GNUNET_assert (table[id].rc > 0);
180 table[id].rc--;
181 if (table[id].rc == 0)
174 { 182 {
175 id = ids[i]; 183 GNUNET_break (GNUNET_OK ==
176 if (id == 0) 184 GNUNET_CONTAINER_multihashmap_remove (map,
177 continue; 185 &table[id].
178 GNUNET_assert (id < size); 186 id.hashPubKey,
179 GNUNET_assert (table[id].rc > 0); 187 (void *) (long) id));
180 table[id].rc--; 188 table[id].pid = free_list_start;
181 if (table[id].rc == 0) 189 free_list_start = id;
182 {
183 GNUNET_break (GNUNET_OK ==
184 GNUNET_CONTAINER_multihashmap_remove (map,
185 &table[id].id.hashPubKey,
186 (void*) (long) id));
187 table[id].pid = free_list_start;
188 free_list_start = id;
189 }
190 } 190 }
191 }
191} 192}
192 193
193 194
@@ -207,14 +208,15 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
207 GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); 208 GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta));
208 table[id].rc += delta; 209 table[id].rc += delta;
209 if (table[id].rc == 0) 210 if (table[id].rc == 0)
210 { 211 {
211 GNUNET_break (GNUNET_OK == 212 GNUNET_break (GNUNET_OK ==
212 GNUNET_CONTAINER_multihashmap_remove (map, 213 GNUNET_CONTAINER_multihashmap_remove (map,
213 &table[id].id.hashPubKey, 214 &table[id].
214 (void*) (long) id)); 215 id.hashPubKey,
215 table[id].pid = free_list_start; 216 (void *) (long) id));
216 free_list_start = id; 217 table[id].pid = free_list_start;
217 } 218 free_list_start = id;
219 }
218} 220}
219 221
220 222
@@ -228,11 +230,11 @@ void
228GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) 230GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
229{ 231{
230 if (id == 0) 232 if (id == 0)
231 { 233 {
232 memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); 234 memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
233 GNUNET_break (0); 235 GNUNET_break (0);
234 return; 236 return;
235 } 237 }
236 GNUNET_assert (id < size); 238 GNUNET_assert (id < size);
237 GNUNET_assert (table[id].rc > 0); 239 GNUNET_assert (table[id].rc > 0);
238 *pid = table[id].id; 240 *pid = table[id].id;