Statistics
| Branch: | Revision:

grapes / som / Tests / topology.c @ 483ff9b6

History | View | Annotate | Download (2.22 KB)

1
/*
2
 *  Copyright (c) 2010 Marco Biazzini
3
 *
4
 *  This is free software; see lgpl-2.1.txt
5
 */
6

    
7
#include <sys/time.h>
8
#include <time.h>
9
#include <stdlib.h>
10
#include <stdint.h>
11
#include <stdio.h>
12
#include <string.h>
13

    
14
#include "msg_types.h"
15
#include "net_helper.h"
16
#include "topmanager.h"
17
#include "tman.h"
18

    
19
#define TMAN_MAX_IDLE 5
20

    
21
static int counter = 0;
22

    
23

    
24
int topoChangeMetadata(struct nodeID *peer, void *metadata, int metadata_size)
25
{
26
        // this because if my own metadata are to be changed, it shouldn't be done twice!
27
         if (counter <= TMAN_MAX_IDLE)
28
                 return topChangeMetadata(metadata,metadata_size);
29
    return tmanChangeMetadata(metadata,metadata_size);
30
}
31

    
32
int topoAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size, tmanRankingFunction rfun)
33
{
34
//        int ncs;
35
//        topGetNeighbourhood(&ncs);
36
        // TODO: check this!! Just to use this function to bootstrap ncast...
37
        if (counter < TMAN_MAX_IDLE)
38
                return topAddNeighbour(neighbour,metadata,metadata_size);
39
        else return tmanAddNeighbour(neighbour,metadata,metadata_size);
40
}
41

    
42
int topoParseData(const uint8_t *buff, int len, tmanRankingFunction f)
43
{
44
        int res,ncs,msize;
45
        const struct nodeID **n; const void *m;
46
        res = topParseData(buff,len);
47
        if (res==0 && counter <= TMAN_MAX_IDLE)
48
                counter++;
49
        if (res !=0 || counter >= TMAN_MAX_IDLE)
50
        {
51
                n = topGetNeighbourhood(&ncs);
52
                m = topGetMetadata(&msize);
53
                res = tmanParseData(buff,len,n,ncs,m,msize);
54
        }
55
  return res;
56
}
57

    
58
const struct nodeID **topoGetNeighbourhood(int *n)
59
{
60
        if (counter > TMAN_MAX_IDLE) {
61
                struct nodeID ** neighbors; void *mdata; int msize;
62
                *n = tmanGetNeighbourhoodSize();
63
                neighbors = calloc(*n,sizeof(struct nodeID *));
64
                tmanGetMetadata(&msize);
65
                mdata = calloc(*n,msize);
66
                tmanGivePeers(*n,neighbors,mdata);
67
                free(mdata);
68
                return (const struct nodeID **)neighbors;
69
        }
70
        else
71
                return topGetNeighbourhood(n);
72
}
73

    
74
const void *topoGetMetadata(int *metadata_size)
75
{
76
        if (counter > TMAN_MAX_IDLE)
77
                return tmanGetMetadata(metadata_size);
78
        else
79
                return topGetMetadata(metadata_size);
80
}
81

    
82
int topoGrowNeighbourhood(int n)
83
{
84
        return tmanGrowNeighbourhood(n);
85
}
86

    
87
int topoShrinkNeighbourhood(int n)
88
{
89
  return tmanShrinkNeighbourhood(n);
90
}
91

    
92
int topoRemoveNeighbour(struct nodeID *neighbour)
93
{
94
  return topRemoveNeighbour(neighbour);
95
}
96

    
97