2 This file is part of GNUnet.
3 Copyright (C) 2004, 2009 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file peerinfo/test_peerinfo_api.c
23 * @brief testcase for peerinfo_api.c
24 * @author Christian Grothoff
27 * - test merging of HELLOs (add same peer twice...)
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet_testing_lib.h"
36 static struct GNUNET_PEERINFO_IteratorContext *ic;
38 static struct GNUNET_PEERINFO_Handle *h;
40 static unsigned int retries;
42 static int global_ret;
46 check_it (void *cls, const struct GNUNET_HELLO_Address *address,
47 struct GNUNET_TIME_Absolute expiration)
49 unsigned int *agc = cls;
53 GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name));
55 strncmp ("Address", address->address,
56 address->address_length));
57 (*agc) -= (1 << (address->address_length - 1));
64 address_generator (void *cls, size_t max, void *buf)
68 struct GNUNET_HELLO_Address address;
71 return GNUNET_SYSERR; /* Done */
72 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
73 address.address = "Address";
74 address.transport_name = "peerinfotest";
75 address.address_length = *agc;
77 GNUNET_HELLO_add_address (&address,
78 GNUNET_TIME_relative_to_absolute
79 (GNUNET_TIME_UNIT_HOURS), buf, max);
84 struct GNUNET_PeerIdentity pid;
89 struct GNUNET_HELLO_Message *h2;
93 memset (&pid, 32, sizeof (pid));
94 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_NO);
95 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
102 process (void *cls, const struct GNUNET_PeerIdentity *peer,
103 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
110 _("Error in communication with PEERINFO service\n"));
116 if ((3 == global_ret) && (retries < 50))
121 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
126 GNUNET_assert (peer == NULL);
127 GNUNET_assert (2 == global_ret);
128 GNUNET_PEERINFO_disconnect (h);
135 GNUNET_assert (3 == global_ret);
137 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
139 GNUNET_assert (agc == 0);
147 const struct GNUNET_CONFIGURATION_Handle *cfg,
148 struct GNUNET_TESTING_Peer *peer)
150 h = GNUNET_PEERINFO_connect (cfg);
151 GNUNET_assert (NULL != h);
153 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid,
159 main (int argc, char *argv[])
162 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo",
164 "test_peerinfo_api_data.conf",
170 /* end of test_peerinfo_api.c */