Statistics
| Branch: | Revision:

streamers / topology.c @ 282209fa

History | View | Annotate | Download (1.28 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
  if (from) {
25
    dprintf("from:%s, ",node_addr(from));
26
    peerset_add_peer(pset,from);
27
  }
28

    
29
  dprintf("before:%d, ",peerset_size(pset));
30
  topParseData(buff, len);
31
  ids = topGetNeighbourhood(&n_ids);
32
  peerset_add_peers(pset,ids,n_ids);
33
  dprintf("after:%d, ",peerset_size(pset));
34

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