30 |
30 |
#include <peersampler.h>
|
31 |
31 |
#include <peer.h>
|
32 |
32 |
#include <grapes_msg_types.h>
|
|
33 |
#include<grapes_config.h>
|
33 |
34 |
//
|
34 |
35 |
#include "compatibility/timer.h"
|
35 |
36 |
//
|
... | ... | |
105 |
106 |
|
106 |
107 |
int topology_init(struct topology * t, const struct psinstance * ps, const char *config)
|
107 |
108 |
{
|
|
109 |
struct tag * tags;
|
|
110 |
int peer_timeout;
|
|
111 |
|
|
112 |
tags = grapes_config_parse(config);
|
|
113 |
|
108 |
114 |
bind_msg_type(MSG_TYPE_NEIGHBOURHOOD);
|
109 |
115 |
bind_msg_type(MSG_TYPE_TOPOLOGY);
|
110 |
|
t->tout_bmap.tv_sec = 20;
|
|
116 |
|
|
117 |
grapes_config_value_int_default(tags, "peer_timeout", &peer_timeout, 10);
|
|
118 |
t->tout_bmap.tv_sec = peer_timeout;
|
111 |
119 |
t->tout_bmap.tv_usec = 0;
|
112 |
120 |
t->ps = ps;
|
113 |
121 |
|
... | ... | |
128 |
136 |
update_metadata(t);
|
129 |
137 |
t->tc = psample_init(psinstance_nodeid(ps), &(t->my_metadata), sizeof(struct metadata), config);
|
130 |
138 |
|
131 |
|
//fprintf(stderr,"[DEBUG] done with topology init\n");
|
|
139 |
free(tags);
|
132 |
140 |
return t->tc && t->neighbourhood && t->swarm_bucket ? 1 : 0;
|
133 |
141 |
}
|
134 |
142 |
|
... | ... | |
295 |
303 |
if ( (!timerisset(&peers[i]->bmap_timestamp) && timercmp(&peers[i]->creation_timestamp, &told, <) ) ||
|
296 |
304 |
( timerisset(&peers[i]->bmap_timestamp) && timercmp(&peers[i]->bmap_timestamp, &told, <) ) ) {
|
297 |
305 |
dprintf("Topo: dropping inactive %s (peersset_size: %d)\n", nodeid_static_str(peers[i]->id), peerset_size(t->neighbourhood));
|
298 |
|
if (peerset_size(t->neighbourhood) > 1) { // avoid dropping our last link to the world
|
|
306 |
// if (peerset_size(t->neighbourhood) > 1) { // avoid dropping our last link to the world
|
299 |
307 |
topology_blacklist_add(t, peers[i]->id);
|
300 |
|
neighbourhood_remove_peer(t, peers[i]->id);
|
301 |
|
}
|
|
308 |
topology_remove_peer(t, peers[i]->id);
|
|
309 |
// }
|
302 |
310 |
}
|
303 |
311 |
}
|
304 |
312 |
|