diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-11 09:43:04 +0000 |
commit | d9d94d0e53d26af75ec8241383d166544ebd79f3 (patch) | |
tree | 9080b73624389403a198257fe0547bb4634e64d2 /src/util/peer.c | |
parent | 2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff) | |
download | gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip |
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/peer.c')
-rw-r--r-- | src/util/peer.c | 104 |
1 files changed, 54 insertions, 50 deletions
diff --git a/src/util/peer.c b/src/util/peer.c index 39d11883d..c88e03c15 100644 --- a/src/util/peer.c +++ b/src/util/peer.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_peer_lib.h" | 28 | #include "gnunet_peer_lib.h" |
29 | 29 | ||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
31 | |||
30 | 32 | ||
31 | struct PeerEntry | 33 | struct PeerEntry |
32 | { | 34 | { |
@@ -105,7 +107,7 @@ GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid) | |||
105 | * @return the interned identity. | 107 | * @return the interned identity. |
106 | */ | 108 | */ |
107 | GNUNET_PEER_Id | 109 | GNUNET_PEER_Id |
108 | GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | 110 | GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) |
109 | { | 111 | { |
110 | GNUNET_PEER_Id ret; | 112 | GNUNET_PEER_Id ret; |
111 | struct PeerEntry *e; | 113 | struct PeerEntry *e; |
@@ -119,24 +121,24 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
119 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); | 121 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); |
120 | e = (off == 0) ? NULL : &table[off]; | 122 | e = (off == 0) ? NULL : &table[off]; |
121 | if (e != NULL) | 123 | if (e != NULL) |
122 | { | 124 | { |
123 | GNUNET_assert (e->rc > 0); | 125 | GNUNET_assert (e->rc > 0); |
124 | e->rc++; | 126 | e->rc++; |
125 | return e->pid; | 127 | return e->pid; |
126 | } | 128 | } |
127 | ret = free_list_start; | 129 | ret = free_list_start; |
128 | if (ret == size) | 130 | if (ret == size) |
129 | { | 131 | { |
130 | GNUNET_array_grow (table, size, size + 16); | 132 | GNUNET_array_grow (table, size, size + 16); |
131 | for (i = ret; i < size; i++) | 133 | for (i = ret; i < size; i++) |
132 | table[i].pid = i + 1; | 134 | table[i].pid = i + 1; |
133 | } | 135 | } |
134 | if (ret == 0) | 136 | if (ret == 0) |
135 | { | 137 | { |
136 | table[0].pid = 0; | 138 | table[0].pid = 0; |
137 | table[0].rc = 1; | 139 | table[0].rc = 1; |
138 | ret = 1; | 140 | ret = 1; |
139 | } | 141 | } |
140 | GNUNET_assert (ret < size); | 142 | GNUNET_assert (ret < size); |
141 | GNUNET_assert (table[ret].rc == 0); | 143 | GNUNET_assert (table[ret].rc == 0); |
142 | free_list_start = table[ret].pid; | 144 | free_list_start = table[ret].pid; |
@@ -144,9 +146,9 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
144 | table[ret].rc = 1; | 146 | table[ret].rc = 1; |
145 | table[ret].pid = ret; | 147 | table[ret].pid = ret; |
146 | GNUNET_break (GNUNET_OK == | 148 | GNUNET_break (GNUNET_OK == |
147 | GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, | 149 | GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, |
148 | (void *) (long) ret, | 150 | (void *) (long) ret, |
149 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
150 | return ret; | 152 | return ret; |
151 | } | 153 | } |
152 | 154 | ||
@@ -158,7 +160,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
158 | * @param count size of the ids array | 160 | * @param count size of the ids array |
159 | */ | 161 | */ |
160 | void | 162 | void |
161 | 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) |
162 | { | 164 | { |
163 | int i; | 165 | int i; |
164 | GNUNET_PEER_Id id; | 166 | GNUNET_PEER_Id id; |
@@ -166,24 +168,25 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count) | |||
166 | if (count == 0) | 168 | if (count == 0) |
167 | return; | 169 | return; |
168 | for (i = count - 1; i >= 0; i--) | 170 | for (i = count - 1; i >= 0; i--) |
169 | { | ||
170 | id = ids[i]; | ||
171 | if (id == 0) | ||
172 | continue; | ||
173 | GNUNET_assert (id < size); | ||
174 | GNUNET_assert (table[id].rc > 0); | ||
175 | table[id].rc--; | ||
176 | if (table[id].rc == 0) | ||
177 | { | 171 | { |
178 | GNUNET_break (GNUNET_OK == | 172 | id = ids[i]; |
179 | GNUNET_CONTAINER_multihashmap_remove (map, | 173 | if (id == 0) |
180 | &table[id]. | 174 | continue; |
181 | id.hashPubKey, | 175 | GNUNET_assert (id < size); |
182 | (void *) (long) id)); | 176 | GNUNET_assert (table[id].rc > 0); |
183 | table[id].pid = free_list_start; | 177 | table[id].rc--; |
184 | free_list_start = id; | 178 | if (table[id].rc == 0) |
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 | } | ||
185 | } | 189 | } |
186 | } | ||
187 | } | 190 | } |
188 | 191 | ||
189 | 192 | ||
@@ -203,15 +206,16 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta) | |||
203 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); | 206 | GNUNET_assert ((delta >= 0) || (table[id].rc >= -delta)); |
204 | table[id].rc += delta; | 207 | table[id].rc += delta; |
205 | if (table[id].rc == 0) | 208 | if (table[id].rc == 0) |
206 | { | 209 | { |
207 | GNUNET_break (GNUNET_OK == | 210 | GNUNET_break (GNUNET_OK == |
208 | GNUNET_CONTAINER_multihashmap_remove (map, | 211 | GNUNET_CONTAINER_multihashmap_remove (map, |
209 | &table[id]. | 212 | &table[id]. |
210 | id.hashPubKey, | 213 | id.hashPubKey, |
211 | (void *) (long) id)); | 214 | (void *) (long) |
212 | table[id].pid = free_list_start; | 215 | id)); |
213 | free_list_start = id; | 216 | table[id].pid = free_list_start; |
214 | } | 217 | free_list_start = id; |
218 | } | ||
215 | } | 219 | } |
216 | 220 | ||
217 | 221 | ||
@@ -225,11 +229,11 @@ void | |||
225 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) | 229 | GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid) |
226 | { | 230 | { |
227 | if (id == 0) | 231 | if (id == 0) |
228 | { | 232 | { |
229 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); | 233 | memset (pid, 0, sizeof (struct GNUNET_PeerIdentity)); |
230 | GNUNET_break (0); | 234 | GNUNET_break (0); |
231 | return; | 235 | return; |
232 | } | 236 | } |
233 | GNUNET_assert (id < size); | 237 | GNUNET_assert (id < size); |
234 | GNUNET_assert (table[id].rc > 0); | 238 | GNUNET_assert (table[id].rc > 0); |
235 | *pid = table[id].id; | 239 | *pid = table[id].id; |