Statistics
| Branch: | Revision:

streamers / topology.c @ 793894a9

History | View | Annotate | Download (990 Bytes)

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

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

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

    
22

    
23
  topParseData(buff, len);
24
  ids = topGetNeighbourhood(&n_ids);
25
  peerset_add_peers(pset,ids,n_ids);
26

    
27
  gettimeofday(&tnow, NULL);
28
  timersub(&tnow, &tout_bmap, &told);
29
  peers = peerset_get_peers(pset);
30
  for (i = 0; i < peerset_size(pset); i++) {
31
    if ( (!timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].creation_timestamp, &told, <) ) ||
32
         ( timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].bmap_timestamp, &told, <)     )   ) {
33
      topRemoveNeighbour(peers[i].id);
34
      peerset_remove_peer(pset, peers[i--].id);
35
    }
36
  }
37
}