Statistics
| Branch: | Revision:

streamers / topology.c @ fbeb4f32

History | View | Annotate | Download (1.19 KB)

1
#include <stdint.h>
2
#include <sys/time.h>
3
#include <time.h>
4

    
5
#include <net_helper.h>
6
#include <peerset.h>
7
#include <peer.h>
8
#include <topmanager.h>
9

    
10
#include "topology.h"
11
#include "dbg.h"
12

    
13
static struct timeval tout_bmap = {3, 0};
14

    
15
// currently it just makes the peerset grow
16
void update_peers(struct peerset *pset, struct nodeID *from, const uint8_t *buff, int len)
17
{
18
  int n_ids, i;
19
  const struct nodeID **ids;
20
  struct peer *peers;
21
  struct timeval tnow, told;
22

    
23
  dprintf("Update peers: topo_msg:%d, ",len);
24
  dprintf("before:%d, ",peerset_size(pset));
25
  topParseData(buff, len);
26
  ids = topGetNeighbourhood(&n_ids);
27
  peerset_add_peers(pset,ids,n_ids);
28
  dprintf("after:%d, ",peerset_size(pset));
29

    
30
  gettimeofday(&tnow, NULL);
31
  timersub(&tnow, &tout_bmap, &told);
32
  peers = peerset_get_peers(pset);
33
  for (i = 0; i < peerset_size(pset); i++) {
34
    if ( (!timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].creation_timestamp, &told, <) ) ||
35
         ( timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].bmap_timestamp, &told, <)     )   ) {
36
      topRemoveNeighbour(peers[i].id);
37
      peerset_remove_peer(pset, peers[i--].id);
38
    }
39
  }
40
  dprintf("after timer check:%d\n",peerset_size(pset));
41
}