diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/group.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index 4644b837..2fbd341c 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -198,7 +198,7 @@ static uint16_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) | |||
198 | if (pk1[index] == pk2[index]) | 198 | if (pk1[index] == pk2[index]) |
199 | continue; | 199 | continue; |
200 | 200 | ||
201 | cmp2 = abs((int)pk1[index] - (int)pk2[index]); | 201 | cmp2 = pk1[index] - pk2[index]; |
202 | break; | 202 | break; |
203 | } | 203 | } |
204 | 204 | ||
@@ -244,8 +244,20 @@ static int add_to_closest(Group_Chats *g_c, int groupnumber, const uint8_t *real | |||
244 | uint16_t comp_val = calculate_comp_value(g->real_pk, real_pk); | 244 | uint16_t comp_val = calculate_comp_value(g->real_pk, real_pk); |
245 | uint16_t comp_d = 0; | 245 | uint16_t comp_d = 0; |
246 | 246 | ||
247 | for (i = 0; i < DESIRED_CLOSE_CONNECTIONS; ++i) { | 247 | for (i = 0; i < (DESIRED_CLOSE_CONNECTIONS / 2); ++i) { |
248 | uint16_t comp = calculate_comp_value(g->real_pk, g->closest_peers[i].real_pk); | 248 | uint16_t comp; |
249 | comp = calculate_comp_value(g->real_pk, g->closest_peers[i].real_pk); | ||
250 | |||
251 | if (comp > comp_val && comp > comp_d) { | ||
252 | index = i; | ||
253 | comp_d = comp; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | comp_val = calculate_comp_value(real_pk, g->real_pk); | ||
258 | |||
259 | for (i = (DESIRED_CLOSE_CONNECTIONS / 2); i < DESIRED_CLOSE_CONNECTIONS; ++i) { | ||
260 | uint16_t comp = calculate_comp_value(g->closest_peers[i].real_pk, g->real_pk); | ||
249 | 261 | ||
250 | if (comp > comp_val && comp > comp_d) { | 262 | if (comp > comp_val && comp > comp_d) { |
251 | index = i; | 263 | index = i; |
@@ -258,10 +270,24 @@ static int add_to_closest(Group_Chats *g_c, int groupnumber, const uint8_t *real | |||
258 | return -1; | 270 | return -1; |
259 | } | 271 | } |
260 | 272 | ||
273 | uint8_t old_real_pk[crypto_box_PUBLICKEYBYTES]; | ||
274 | uint8_t old_temp_pk[crypto_box_PUBLICKEYBYTES]; | ||
275 | uint8_t old = 0; | ||
276 | |||
277 | if (g->closest_peers[index].entry) { | ||
278 | memcpy(old_real_pk, g->closest_peers[index].real_pk, crypto_box_PUBLICKEYBYTES); | ||
279 | memcpy(old_temp_pk, g->closest_peers[index].temp_pk, crypto_box_PUBLICKEYBYTES); | ||
280 | old = 1; | ||
281 | } | ||
282 | |||
261 | g->closest_peers[index].entry = 1; | 283 | g->closest_peers[index].entry = 1; |
262 | memcpy(g->closest_peers[index].real_pk, real_pk, crypto_box_PUBLICKEYBYTES); | 284 | memcpy(g->closest_peers[index].real_pk, real_pk, crypto_box_PUBLICKEYBYTES); |
263 | memcpy(g->closest_peers[index].temp_pk, temp_pk, crypto_box_PUBLICKEYBYTES); | 285 | memcpy(g->closest_peers[index].temp_pk, temp_pk, crypto_box_PUBLICKEYBYTES); |
264 | 286 | ||
287 | if (old) { | ||
288 | add_to_closest(g_c, groupnumber, old_real_pk, old_temp_pk); | ||
289 | } | ||
290 | |||
265 | if (!g->changed) | 291 | if (!g->changed) |
266 | g->changed = GROUPCHAT_CLOSEST_ADDED; | 292 | g->changed = GROUPCHAT_CLOSEST_ADDED; |
267 | 293 | ||