Statistics
| Branch: | Revision:

grapes / src / TopologyManager / dummy.c @ e2b6ad48

History | View | Annotate | Download (2.06 KB)

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

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

    
12

    
13
#include "net_helper.h"
14
#include "peersampler_iface.h"
15

    
16
#define MAX_PEERS 5000
17
static struct nodeID *table[MAX_PEERS];
18

    
19
static int dummy_init(struct nodeID *myID, void *metadata, int metadata_size, const char *config)
20
{
21
  FILE *f;
22
  int i = 0;
23

    
24
  f = fopen("peers.txt", "r");
25
  while(!feof(f)) {
26
    int res;
27
    char addr[32];
28
    int port;
29

    
30
    res = fscanf(f, "%s %d\n", addr, &port);
31
    if ((res == 2) && (i < MAX_PEERS - 1)) {
32
fprintf(stderr, "Creating table[%d]\n", i);
33
      table[i++] = create_node(addr, port);
34
    }
35
  }
36
  table[i] = NULL;
37

    
38
  return i;
39
}
40

    
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)
48
{
49
  int i;
50

    
51
  for (i = 0; table[i] != NULL; i++);
52
  table[i++] = neighbour;
53
  table[i] = NULL;
54

    
55
  return i;
56
}
57

    
58
static int dummy_parse_data(const uint8_t *buff, int len)
59
{
60
  /* FAKE! */
61
  return 0;
62
}
63

    
64
static const struct nodeID **dummy_get_neighbourhood(int *n)
65
{
66
  for (*n = 0; table[*n] != NULL; (*n)++) {
67
fprintf(stderr, "Checking table[%d]\n", *n);
68
  }
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;
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