Revision e2b6ad48

View differences:

src/TopologyManager/Makefile
1 1
BASE = ../..
2 2

  
3
OBJS = peersampler.o ncast.o topo_proto.o topocache.o tman.o
3
OBJS = peersampler.o ncast.o dummy.o topo_proto.o topocache.o tman.o
4 4

  
5 5
all: libtopman.a
6 6

  
src/TopologyManager/dummy.c
4 4
 *  This is free software; see lgpl-2.1.txt
5 5
 */
6 6

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

  
12

  
10 13
#include "net_helper.h"
11
#include "topmanager.h"
14
#include "peersampler_iface.h"
12 15

  
13 16
#define MAX_PEERS 5000
14
static struct socketID *table[MAX_PEERS];
17
static struct nodeID *table[MAX_PEERS];
15 18

  
16
int topInit(struct nodeID *myID, void *metadata, int metadata_size, const char *config)
19
static int dummy_init(struct nodeID *myID, void *metadata, int metadata_size, const char *config)
17 20
{
18 21
  FILE *f;
19 22
  int i = 0;
......
27 30
    res = fscanf(f, "%s %d\n", addr, &port);
28 31
    if ((res == 2) && (i < MAX_PEERS - 1)) {
29 32
fprintf(stderr, "Creating table[%d]\n", i);
30
      table[i++] = create_socket(addr, port);
33
      table[i++] = create_node(addr, port);
31 34
    }
32 35
  }
33 36
  table[i] = NULL;
......
35 38
  return i;
36 39
}
37 40

  
38
int topAddNeighbour(struct socketID *neighbour)
41
static int dummy_change_metadata(void *metadata, int metadata_size)
42
{
43
  /* Metadata not supported: fail! */
44
  return -1;
45
}
46

  
47
static int dummy_add_neighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
39 48
{
40 49
  int i;
41 50

  
......
46 55
  return i;
47 56
}
48 57

  
49
int topParseData(const struct connectionID *conn, const uint8_t *buff, int len)
58
static int dummy_parse_data(const uint8_t *buff, int len)
50 59
{
51 60
  /* FAKE! */
52 61
  return 0;
53 62
}
54 63

  
55
const struct socketID **topGetNeighbourhood(int *n)
64
static const struct nodeID **dummy_get_neighbourhood(int *n)
56 65
{
57 66
  for (*n = 0; table[*n] != NULL; (*n)++) {
58 67
fprintf(stderr, "Checking table[%d]\n", *n);
59 68
  }
60
  return (const struct socketID **)table;
69
  return (const struct nodeID **)table;
70
}
71

  
72
static const void *dummy_get_metadata(int *metadata_size)
73
{
74
  /* Metadata not supported: fail! */
75
  *metadata_size = -1;
76

  
77
  return NULL;
78
}
79

  
80
static int dummy_grow_neighbourhood(int n)
81
{
82
  return -1;
83
}
84

  
85
static int dummy_shrink_neighbourhood(int n)
86
{
87
  return -1;
88
}
89

  
90
static int dummy_remove_neighbour(struct nodeID *neighbour)
91
{
92
  return -1;
61 93
}
94

  
95

  
96
struct peersampler_iface dummy = {
97
  .init = dummy_init,
98
  .change_metadata = dummy_change_metadata,
99
  .add_neighbour = dummy_add_neighbour,
100
  .parse_data = dummy_parse_data,
101
  .get_neighbourhood = dummy_get_neighbourhood,
102
  .get_metadata = dummy_get_metadata,
103
  .grow_neighbourhood = dummy_grow_neighbourhood,
104
  .shrink_neighbourhood = dummy_shrink_neighbourhood,
105
  .remove_neighbour = dummy_remove_neighbour,
106
};
107

  
src/TopologyManager/peersampler.c
7 7
#include "peersampler_iface.h"
8 8

  
9 9
extern struct peersampler_iface ncast;
10
extern struct peersampler_iface dummy;
11
static struct peersampler_iface *ps;
10 12

  
11 13
int topInit(struct nodeID *myID, void *metadata, int metadata_size, const char *config)
12 14
{
13
  return ncast.init(myID, metadata, metadata_size, config);
15
  ps = &ncast;
16
  return ps->init(myID, metadata, metadata_size, config);
14 17
}
15 18

  
16 19
int topChangeMetadata(void *metadata, int metadata_size)
17 20
{
18
  return ncast.change_metadata(metadata, metadata_size);
21
  return ps->change_metadata(metadata, metadata_size);
19 22
}
20 23

  
21 24
int topAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
22 25
{
23
  return ncast.add_neighbour(neighbour, metadata, metadata_size);
26
  return ps->add_neighbour(neighbour, metadata, metadata_size);
24 27
}
25 28

  
26 29
int topParseData(const uint8_t *buff, int len)
27 30
{
28
  return ncast.parse_data(buff, len);
31
  return ps->parse_data(buff, len);
29 32
}
30 33

  
31 34
const struct nodeID **topGetNeighbourhood(int *n)
32 35
{
33
  return ncast.get_neighbourhood(n);
36
  return ps->get_neighbourhood(n);
34 37
}
35 38

  
36 39
const void *topGetMetadata(int *metadata_size)
37 40
{
38
  return ncast.get_metadata(metadata_size);
41
  return ps->get_metadata(metadata_size);
39 42
}
40 43

  
41 44
int topGrowNeighbourhood(int n)
42 45
{
43
  return ncast.grow_neighbourhood(n);
46
  return ps->grow_neighbourhood(n);
44 47
}
45 48

  
46 49
int topShrinkNeighbourhood(int n)
47 50
{
48
  return ncast.shrink_neighbourhood(n);
51
  return ps->shrink_neighbourhood(n);
49 52
}
50 53

  
51 54
int topRemoveNeighbour(struct nodeID *neighbour)
52 55
{
53
  return ncast.remove_neighbour(neighbour);
56
  return ps->remove_neighbour(neighbour);
54 57
}

Also available in: Unified diff