aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_view.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-11-30 21:51:49 +0000
committerJulius Bünger <buenger@mytum.de>2015-11-30 21:51:49 +0000
commit5afa421263a05c91b451ab3674b06953f0172e87 (patch)
tree106aa33731cf7c9d0aa17fb1cd336b646cde9893 /src/rps/gnunet-service-rps_view.c
parent4be584bce0f2b83a6ce0f7cf6d744799faaab258 (diff)
downloadgnunet-5afa421263a05c91b451ab3674b06953f0172e87.tar.gz
gnunet-5afa421263a05c91b451ab3674b06953f0172e87.zip
-fix of issues in helper for "view"
Signed-off-by: Julius Bünger <buenger@mytum.de>
Diffstat (limited to 'src/rps/gnunet-service-rps_view.c')
-rw-r--r--src/rps/gnunet-service-rps_view.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c
index 2cf0287bb..27cd7affc 100644
--- a/src/rps/gnunet-service-rps_view.c
+++ b/src/rps/gnunet-service-rps_view.c
@@ -175,25 +175,23 @@ int
175View_remove_peer (const struct GNUNET_PeerIdentity *peer) 175View_remove_peer (const struct GNUNET_PeerIdentity *peer)
176{ 176{
177 uint32_t *index; 177 uint32_t *index;
178 uint32_t *index_swap;
178 179
179 if (GNUNET_YES == View_contains_peer (peer)) 180 if (GNUNET_NO == View_contains_peer (peer))
180 {
181 index = GNUNET_CONTAINER_multipeermap_get (mpm, peer);
182 GNUNET_assert (NULL != index);
183 if (*index == GNUNET_CONTAINER_multipeermap_size (mpm) - 1)
184 { /* Last peer in array - simply remove */
185 }
186 else
187 { /* Fill the 'gap' in the array with the last peer */
188 array[*index] = array[View_size ()];
189 }
190 GNUNET_CONTAINER_multipeermap_remove_all (mpm, peer);
191 return GNUNET_OK;
192 }
193 else
194 { 181 {
195 return GNUNET_NO; 182 return GNUNET_NO;
196 } 183 }
184 index = GNUNET_CONTAINER_multipeermap_get (mpm, peer);
185 GNUNET_assert (NULL != index);
186 if (*index < (View_size () - 1) )
187 { /* Fill the 'gap' in the array with the last peer */
188 array[*index] = array[(View_size () - 1)];
189 index_swap = GNUNET_CONTAINER_multipeermap_get (mpm, &array[View_size ()]);
190 *index_swap = *index;
191 GNUNET_free (index);
192 }
193 GNUNET_CONTAINER_multipeermap_remove_all (mpm, peer);
194 return GNUNET_OK;
197} 195}
198 196
199/** 197/**
@@ -230,14 +228,16 @@ View_clear ()
230 uint32_t i; 228 uint32_t i;
231 uint32_t *index; 229 uint32_t *index;
232 230
233 for (i = 0; i < GNUNET_CONTAINER_multipeermap_size (mpm); i++) 231 for (i = 0; 0 < View_size (); i++)
234 { /* Need to free indices stored at peers */ 232 { /* Need to free indices stored at peers */
233 GNUNET_assert (GNUNET_YES ==
234 GNUNET_CONTAINER_multipeermap_contains (mpm, &array[i]));
235 index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[i]); 235 index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[i]);
236 GNUNET_assert (NULL != index); 236 GNUNET_assert (NULL != index);
237 GNUNET_free (index); 237 GNUNET_free (index);
238 GNUNET_CONTAINER_multipeermap_remove_all (mpm, &array[i]); 238 GNUNET_CONTAINER_multipeermap_remove_all (mpm, &array[i]);
239 } 239 }
240 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (mpm)); 240 GNUNET_assert (0 == View_size ());
241} 241}
242 242
243/** 243/**