Revision fe40d609 src/topology.c
src/topology.c | ||
---|---|---|
40 | 40 |
#include "streaming.h" |
41 | 41 |
|
42 | 42 |
#define MAX(A,B) (((A) > (B)) ? (A) : (B)) |
43 |
#define NEIGHBOURHOOD_ADD 0
|
|
44 |
#define NEIGHBOURHOOD_REMOVE 1 |
|
43 |
enum neighbourhood_msg_t {NEIGHBOURHOOD_ADD, NEIGHBOURHOOD_REMOVE, NEIGHBOURHOOD_QUIT};
|
|
44 |
|
|
45 | 45 |
#define DEFAULT_PEER_CBSIZE 50 |
46 | 46 |
|
47 | 47 |
#ifndef NAN //NAN is missing in some old math.h versions |
... | ... | |
199 | 199 |
} |
200 | 200 |
} |
201 | 201 |
|
202 |
void topology_remove_peer(struct topology * t, const struct nodeID *id) |
|
203 |
{ |
|
204 |
if(t && id) |
|
205 |
{ |
|
206 |
peerset_remove_peer(t->neighbourhood, id); |
|
207 |
peerset_remove_peer(t->swarm_bucket, id); |
|
208 |
peerset_remove_peer(t->locked_neighs, id); |
|
209 |
psample_remove_peer(t->tc, id); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
202 | 213 |
void neighbourhood_message_parse(struct topology * t, struct nodeID *from, const uint8_t *buff, size_t len) |
203 | 214 |
{ |
204 | 215 |
struct metadata m = {0}; |
... | ... | |
218 | 229 |
case NEIGHBOURHOOD_REMOVE: |
219 | 230 |
neighbourhood_remove_peer(t, from); |
220 | 231 |
break; |
232 |
case NEIGHBOURHOOD_QUIT: |
|
233 |
topology_remove_peer(t, from); |
|
234 |
break; |
|
221 | 235 |
default: |
222 | 236 |
dprintf("Unknown neighbourhood message type"); |
223 | 237 |
} |
... | ... | |
329 | 343 |
return res; |
330 | 344 |
} |
331 | 345 |
|
346 |
void topology_quit_overlay(struct topology *t) |
|
347 |
{ |
|
348 |
const struct peer * p; |
|
349 |
int i; |
|
350 |
|
|
351 |
dprintf("Notifying known peers of quitting...\n"); |
|
352 |
peerset_for_each(t->neighbourhood, p, i) |
|
353 |
neighbourhood_send_msg(t, p, NEIGHBOURHOOD_QUIT); |
|
354 |
peerset_for_each(t->swarm_bucket, p, i) |
|
355 |
neighbourhood_send_msg(t, p, NEIGHBOURHOOD_QUIT); |
|
356 |
} |
|
357 |
|
|
332 | 358 |
void peerset_destroy_reference_copy(struct peerset ** pset) |
333 | 359 |
{ |
334 | 360 |
while (peerset_size(*pset)) |
... | ... | |
474 | 500 |
|
475 | 501 |
void topology_destroy(struct topology **t) |
476 | 502 |
{ |
503 |
topology_quit_overlay(*t); |
|
477 | 504 |
if (t && *t) |
478 | 505 |
{ |
479 | 506 |
if(((*t)->locked_neighs)) |
Also available in: Unified diff