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 it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @file peerinfo/test_peerinfo_api.c
18 * @brief testcase for peerinfo_api.c
19 * @author Christian Grothoff
22 * - test merging of HELLOs (add same peer twice...)
25 #include "gnunet_hello_lib.h"
26 #include "gnunet_util_lib.h"
27 #include "gnunet_peerinfo_service.h"
28 #include "gnunet_testing_lib.h"
31 static struct GNUNET_PEERINFO_IteratorContext *ic;
33 static struct GNUNET_PEERINFO_Handle *h;
35 static unsigned int retries;
37 static int global_ret;
41 check_it (void *cls, const struct GNUNET_HELLO_Address *address,
42 struct GNUNET_TIME_Absolute expiration)
44 unsigned int *agc = cls;
48 GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name));
50 strncmp ("Address", address->address,
51 address->address_length));
52 (*agc) -= (1 << (address->address_length - 1));
59 address_generator (void *cls, size_t max, void *buf)
63 struct GNUNET_HELLO_Address address;
66 return GNUNET_SYSERR; /* Done */
67 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
68 address.address = "Address";
69 address.transport_name = "peerinfotest";
70 address.address_length = *agc;
72 GNUNET_HELLO_add_address (&address,
73 GNUNET_TIME_relative_to_absolute
74 (GNUNET_TIME_UNIT_HOURS), buf, max);
79 struct GNUNET_PeerIdentity pid;
84 struct GNUNET_HELLO_Message *h2;
88 memset (&pid, 32, sizeof (pid));
89 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_NO);
90 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
97 process (void *cls, const struct GNUNET_PeerIdentity *peer,
98 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 _("Error in communication with PEERINFO service\n"));
111 if ((3 == global_ret) && (retries < 50))
116 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
121 GNUNET_assert (peer == NULL);
122 GNUNET_assert (2 == global_ret);
123 GNUNET_PEERINFO_disconnect (h);
130 GNUNET_assert (3 == global_ret);
132 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
134 GNUNET_assert (agc == 0);
142 const struct GNUNET_CONFIGURATION_Handle *cfg,
143 struct GNUNET_TESTING_Peer *peer)
145 h = GNUNET_PEERINFO_connect (cfg);
146 GNUNET_assert (NULL != h);
148 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid,
154 main (int argc, char *argv[])
157 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo",
159 "test_peerinfo_api_data.conf",
165 /* end of test_peerinfo_api.c */