Statistics
| Branch: | Revision:

grapes / src / Tests / topo_msg_size_test.c @ 04dd3295

History | View | Annotate | Download (1.45 KB)

1 3dc90458 Luca Abeni
/*
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 19879e8e Luca Abeni
  memset(psample_cfg, 0, sizeof(psample_cfg));
32 3dc90458 Luca Abeni
  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 a55d9f46 Luca Abeni
    nodeid_free(knownHost);
50 3dc90458 Luca Abeni
  }
51
  printf("Waiting 5s...\n");
52 04dd3295 Luca Abeni
  usleep(5000);
53 3dc90458 Luca Abeni
  printf("Trying to send a gossiping message...\n");
54 8a028299 Luca Abeni
  res = psample_parse_data(context, NULL, 0);
55
  if (res < 0) {
56
    fprintf(stderr, "Error sending a gossiping message: %d\n", res);
57
  }
58 3dc90458 Luca Abeni
59 a55d9f46 Luca Abeni
  nodeid_free(myID);
60
61 3dc90458 Luca Abeni
  return 0;
62
}