Statistics
| Branch: | Revision:

grapes / src / Tests / topo_msg_size_test.c @ a55d9f46

History | View | Annotate | Download (1.45 KB)

1
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6
#include <unistd.h>
7
#include <stdlib.h>
8
#include <stdint.h>
9
#include <stdio.h>
10
#include <string.h>
11
#include <getopt.h>
12

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

    
16
static int cache_size = 100;
17

    
18
int main(int argc, char *argv[])
19
{
20
  struct nodeID *myID;
21
  struct psample_context *context;
22
  int port, res;
23
  char psample_cfg[16];
24

    
25
  myID = net_helper_init("127.0.0.1", 5555, "");
26
  if (myID == NULL) {
27
    fprintf(stderr, "Error creating my socket (127.0.0.1:5555)!\n");
28

    
29
    return -1;
30
  }
31
  memset(psample_cfg, 0, sizeof(psample_cfg));
32
  sprintf(psample_cfg, "cache_size=%d", cache_size);
33
  context = psample_init(myID, NULL, 0, psample_cfg);
34

    
35
  /* Fill the cache */
36
  for (port = 6666; port < 6666 + cache_size; port++) {
37
    struct nodeID *knownHost;
38

    
39
    knownHost = create_node("127.0.0.1", port);
40
    if (knownHost == NULL) {
41
      fprintf(stderr, "Error creating knownHost socket (127.0.0.1:%d)!\n", port);
42

    
43
      return -1;
44
    }
45
    res = psample_add_peer(context, knownHost, NULL, 0);
46
    if (res < 0) {
47
      fprintf(stderr, "Error adding 127.0.0.1:%d: %d\n", port, res);
48
    }
49
    nodeid_free(knownHost);
50
  }
51
  printf("Waiting 5s...\n");
52
  sleep(5);
53
  printf("Trying to send a gossiping message...\n");
54
  res = psample_parse_data(context, NULL, 0);
55
  if (res < 0) {
56
    fprintf(stderr, "Error sending a gossiping message: %d\n", res);
57
  }
58

    
59
  nodeid_free(myID);
60

    
61
  return 0;
62
}