Statistics
| Branch: | Revision:

grapes / som / TopologyManager / dummy.c @ 8ab58ec7

History | View | Annotate | Download (1.06 KB)

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

    
7
#include <stdint.h>
8
#include <stdio.h>
9

    
10
#include "net_helper.h"
11
#include "topmanager.h"
12

    
13
#define MAX_PEERS 5000
14
static struct socketID *table[MAX_PEERS];
15

    
16
int topInit(struct socketID *myID)
17
{
18
  FILE *f;
19
  int i = 0;
20

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

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

    
35
  return i;
36
}
37

    
38
int topAddNeighbour(struct socketID *neighbour)
39
{
40
  int i;
41

    
42
  for (i = 0; table[i] != NULL; i++);
43
  table[i++] = neighbour;
44
  table[i] = NULL;
45

    
46
  return i;
47
}
48

    
49
int topParseData(const struct connectionID *conn, const uint8_t *buff, int len)
50
{
51
  /* FAKE! */
52
  return 0;
53
}
54

    
55
const struct socketID **topGetNeighbourhood(int *n)
56
{
57
  for (*n = 0; table[*n] != NULL; (*n)++) {
58
fprintf(stderr, "Checking table[%d]\n", *n);
59
  }
60
  return (const struct socketID **)table;
61
}