diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/peer.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/util/peer.c')
-rw-r--r-- | src/util/peer.c | 102 |
1 files changed, 50 insertions, 52 deletions
diff --git a/src/util/peer.c b/src/util/peer.c index c88e03c15..2444cb9f8 100644 --- a/src/util/peer.c +++ b/src/util/peer.c | |||
@@ -107,7 +107,7 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid) | |||
107 | * @return the interned identity. | 107 | * @return the interned identity. |
108 | */ | 108 | */ |
109 | GNUNET_PEER_Id | 109 | GNUNET_PEER_Id |
110 | GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) | 110 | GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) |
111 | { | 111 | { |
112 | GNUNET_PEER_Id ret; | 112 | GNUNET_PEER_Id ret; |
113 | struct PeerEntry *e; | 113 | struct PeerEntry *e; |
@@ -121,24 +121,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) | |||
121 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); | 121 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); |
122 | e = (off == 0) ? NULL : &table[off]; | 122 | e = (off == 0) ? NULL : &table[off]; |
123 | if (e != NULL) | 123 | if (e != NULL) |
124 | { | 124 | { |
125 | GNUNET_assert (e->rc > 0); | 125 | GNUNET_assert (e->rc > 0); |
126 | e->rc++; | 126 | e->rc++; |
127 | return e->pid; | 127 | return e->pid; |
128 | } | 128 | } |
129 | ret = free_list_start; | 129 | ret = free_list_start; |
130 | if (ret == size) | 130 | if (ret == size) |
131 | { | 131 | { |
132 | GNUNET_array_grow (table, size, size + 16); | 132 | GNUNET_array_grow (table, size, size + 16); |
133 | for (i = ret; i < size; i++) | 133 | for (i = ret; i < size; i++) |
134 | table[i].pid = i + 1; | 134 | table[i].pid = i + 1; |
135 | } | 135 | } |
136 | if (ret == 0) | 136 | if (ret == 0) |
137 | { | 137 | { |
138 | table[0].pid = 0; | 138 | table[0].pid = 0; |
139 | table[0].rc = 1; | 139 | table[0].rc = 1; |
140 | ret = 1; | 140 | ret = 1; |
141 | } | 141 | } |
142 | GNUNET_assert (ret < size); | 142 | GNUNET_assert (ret < size); |
143 | GNUNET_assert (table[ret].rc == 0); | 143 | GNUNET_assert (table[ret].rc == 0); |
144 | free_list_start = table[ret].pid; | 144 | free_list_start = table[ret].pid; |
@@ -146,9 +146,9 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) | |||
146 | table[ret].rc = 1; | 146 | table[ret].rc = 1; |
147 | table[ret].pid = ret; | 147 | table[ret].pid = ret; |
148 | GNUNET_break (GNUNET_OK == | 148 | GNUNET_break (GNUNET_OK == |
149 | GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, | 149 | GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, |
150 | (void *) (long) ret, | 150 | (void *) (long) ret, |
151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
152 | return ret; | 152 | return ret; |
153 | } | 153 | } |
154 | 154 | ||
@@ -160,7 +160,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) | |||
160 | * @param count size of the ids array | 160 | * @param count size of the ids array |
161 | */ | 161 | */ |
162 | void | 162 | void |
163 | GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) | 163 | GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count) |
164 | { | 164 | { |
165 | int i; | 165 | int i; |
166 | GNUNET_PEER_Id id; | 166 | GNUNET_PEER_Id id; |
@@ -168,25 +168,24 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count) | |||
168 | if (count == 0) | 168 | if (count == 0) |
169 | return; | 169 | return; |
170 | for (i = count - 1; i >= 0; i--) | 170 | for (i = count - 1; i >= 0; i--) |
171 | { | ||
172 | id = ids[i]; | ||
173 | if (id == 0) | ||
174 | continue; | ||
175 | GNUNET_assert (id < size); | ||
176 | GNUNET_assert (table[id].rc > 0); | ||
177 | table[id].rc--; | ||
178 | if (table[id].rc == 0) | ||
171 | { | 179 | { |
172 | id = ids[i]; | 180 | GNUNET_break (GNUNET_OK == |
173 | if (id == 0) | 181 | GNUNET_CONTAINER_multihashmap_remove (map, |
174 | continue; | 182 | &table[id]. |
175 | GNUNET_assert (id < size); | 183 | id.hashPubKey, |
176 | GNUNET_assert (table[id].rc > 0); | 184 | (void *) (long) id)); |
177 | table[id].rc--; | 185 | table[id].pid = free_list_start; |
178 | if (table[id].rc == 0) | 186 | free_list_start = id; |
179 | { | ||
180 | GNUNET_break (GNUNET_OK == | ||
181 | GNUNET_CONTAINER_multihashmap_remove (map, | ||
182 | &table[id]. | ||
183 | id.hashPubKey, | ||
184 | (void *) (long) | ||
185 | id)); | ||
186 | table[id].pid = free_list_start; | ||
187 | free_list_start = id; | ||
188 | } | ||
189 | } | 187 | } |
188 | } | ||
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | ||
@@ -206,16 +205,15 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) | |||
206 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); | 205 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); |
207 | table[id].rc += delta; | 206 | table[id].rc += delta; |
208 | if (table[id].rc == 0) | 207 | if (table[id].rc == 0) |
209 | { | 208 | { |
210 | GNUNET_break (GNUNET_OK == | 209 | GNUNET_break (GNUNET_OK == |
211 | GNUNET_CONTAINER_multihashmap_remove (map, | 210 | GNUNET_CONTAINER_multihashmap_remove (map, |
212 | &table[id]. | 211 | &table[id]. |
213 | id.hashPubKey, | 212 | id.hashPubKey, |
214 | (void *) (long) | 213 | (void *) (long) id)); |
215 | id)); | 214 | table[id].pid = free_list_start; |
216 | table[id].pid = free_list_start; | 215 | free_list_start = id; |
217 | free_list_start = id; | 216 | } |
218 | } | ||
219 | } | 217 | } |
220 | 218 | ||
221 | 219 | ||
@@ -229,11 +227,11 @@ void | |||
229 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) | 227 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) |
230 | { | 228 | { |
231 | if (id == 0) | 229 | if (id == 0) |
232 | { | 230 | { |
233 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); | 231 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); |
234 | GNUNET_break (0); | 232 | GNUNET_break (0); |
235 | return; | 233 | return; |
236 | } | 234 | } |
237 | GNUNET_assert (id < size); | 235 | GNUNET_assert (id < size); |
238 | GNUNET_assert (table[id].rc > 0); | 236 | GNUNET_assert (table[id].rc > 0); |
239 | *pid = table[id].id; | 237 | *pid = table[id].id; |