2 This file is part of GNUnet.
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file peerstore/test_peerstore_api.c
22 * @brief testcase for peerstore_api.c
25 #include "gnunet_util_lib.h"
26 #include "gnunet_testing_lib.h"
27 #include "gnunet_peerstore_service.h"
30 //TODO: test single cycle of watch, store, iterate
34 static int counter = 0;
36 struct GNUNET_PEERSTORE_Handle *h;
38 int iterate_cb (void *cls,
39 struct GNUNET_PEERSTORE_Record *record,
44 printf("Error received: %s.\n", emsg);
50 GNUNET_assert(counter > 0);
53 GNUNET_PEERSTORE_disconnect(h);
56 printf("Sub system: %s\n", record->sub_system);
57 printf("Peer: %s\n", GNUNET_i2s (record->peer));
58 printf("Key: %s\n", record->key);
59 printf("Value: %.*s\n", (int)record->value_size, (char *)record->value);
60 printf("Expiry: %" PRIu64 "\n", record->expiry->abs_value_us);
66 void store_cont(void *cls, int success)
68 if(GNUNET_OK == success)
72 printf("Store success: %d\n", success);
73 GNUNET_PEERSTORE_iterate(h, "peerstore-test",
76 GNUNET_TIME_UNIT_FOREVER_REL,
81 int watch_cb (void *cls,
82 struct GNUNET_PEERSTORE_Record *record,
87 printf("Error received: %s.\n", emsg);
91 printf("Watch Record:\n");
92 printf("Sub system: %s\n", record->sub_system);
93 printf("Peer: %s\n", GNUNET_i2s (record->peer));
94 printf("Key: %s\n", record->key);
95 printf("Value: %.*s\n", (int)record->value_size, (char *)record->value);
96 printf("Expiry: %" PRIu64 "\n", record->expiry->abs_value_us);
102 const struct GNUNET_CONFIGURATION_Handle *cfg,
103 struct GNUNET_TESTING_Peer *peer)
105 struct GNUNET_PeerIdentity pid;
106 char *val = "peerstore-test-value";
107 size_t val_size = strlen(val);
108 struct GNUNET_TIME_Absolute expiry;
111 memset (&pid, 32, sizeof (pid));
112 expiry = GNUNET_TIME_absolute_get();
113 h = GNUNET_PEERSTORE_connect(cfg);
114 GNUNET_assert(NULL != h);
115 GNUNET_PEERSTORE_watch(h,
118 "peerstore-test-key",
121 GNUNET_PEERSTORE_store(h,
124 "peerstore-test-key",
132 int iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
134 struct GNUNET_CONTAINER_MultiHashMap *map = cls;
137 printf("Received value: %d\n", *x);
139 GNUNET_CONTAINER_multihashmap_remove(map, key, value);
144 main (int argc, char *argv[])
146 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore",
148 "test_peerstore_api_data.conf",
154 /* end of test_peerstore_api.c */