diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-04 13:56:50 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-04 13:56:50 +0000 |
commit | 0fd8f9587471a5b2b5107ebd62c9f424266d5eef (patch) | |
tree | f16f330a9ef3062f465e4f93d7b9cc580d7cc131 | |
parent | 40ae7b109ac101984cebc3f506c2fe390a803b54 (diff) | |
download | gnunet-0fd8f9587471a5b2b5107ebd62c9f424266d5eef.tar.gz gnunet-0fd8f9587471a5b2b5107ebd62c9f424266d5eef.zip |
test
-rw-r--r-- | src/peerinfo/Makefile.am | 9 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_friend_only.c | 159 |
2 files changed, 168 insertions, 0 deletions
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am index 8387c4fc4..5a2558048 100644 --- a/src/peerinfo/Makefile.am +++ b/src/peerinfo/Makefile.am | |||
@@ -48,6 +48,7 @@ endif | |||
48 | 48 | ||
49 | check_PROGRAMS = \ | 49 | check_PROGRAMS = \ |
50 | test_peerinfo_api \ | 50 | test_peerinfo_api \ |
51 | test_peerinfo_api_friend_only \ | ||
51 | $(PEERINFO_BENCHMARKS) | 52 | $(PEERINFO_BENCHMARKS) |
52 | 53 | ||
53 | if ENABLE_TEST_RUN | 54 | if ENABLE_TEST_RUN |
@@ -62,6 +63,14 @@ test_peerinfo_api_LDADD = \ | |||
62 | $(top_builddir)/src/testing/libgnunettesting.la \ | 63 | $(top_builddir)/src/testing/libgnunettesting.la \ |
63 | $(top_builddir)/src/util/libgnunetutil.la | 64 | $(top_builddir)/src/util/libgnunetutil.la |
64 | 65 | ||
66 | test_peerinfo_api_friend_only_SOURCES = \ | ||
67 | test_peerinfo_api_friend_only.c | ||
68 | test_peerinfo_api_friend_only_LDADD = \ | ||
69 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
70 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
71 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
72 | $(top_builddir)/src/util/libgnunetutil.la | ||
73 | |||
65 | perf_peerinfo_api_SOURCES = \ | 74 | perf_peerinfo_api_SOURCES = \ |
66 | perf_peerinfo_api.c | 75 | perf_peerinfo_api.c |
67 | perf_peerinfo_api_LDADD = \ | 76 | perf_peerinfo_api_LDADD = \ |
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c new file mode 100644 index 000000000..61abd40c6 --- /dev/null +++ b/src/peerinfo/test_peerinfo_api_friend_only.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2004, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file peerinfo/test_peerinfo_api_friend_only.c | ||
23 | * @brief testcase friend only HELLO restrictions in for peerinfo | ||
24 | * @author Christian Grothoff | ||
25 | * @author Matthias Wachs | ||
26 | * | ||
27 | * TODO: | ||
28 | * - test merging of HELLOs (add same peer twice...) | ||
29 | */ | ||
30 | #include "platform.h" | ||
31 | #include "gnunet_hello_lib.h" | ||
32 | #include "gnunet_util_lib.h" | ||
33 | #include "gnunet_peerinfo_service.h" | ||
34 | #include "gnunet_testing_lib.h" | ||
35 | #include "peerinfo.h" | ||
36 | |||
37 | static struct GNUNET_PEERINFO_IteratorContext *ic; | ||
38 | |||
39 | static struct GNUNET_PEERINFO_Handle *h; | ||
40 | |||
41 | static unsigned int retries; | ||
42 | |||
43 | static int global_ret; | ||
44 | |||
45 | static size_t | ||
46 | address_generator (void *cls, size_t max, void *buf) | ||
47 | { | ||
48 | size_t *agc = cls; | ||
49 | size_t ret; | ||
50 | struct GNUNET_HELLO_Address address; | ||
51 | |||
52 | if (0 == *agc) | ||
53 | return 0; | ||
54 | memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); | ||
55 | address.address = "Address"; | ||
56 | address.transport_name = "peerinfotest"; | ||
57 | address.address_length = *agc; | ||
58 | ret = | ||
59 | GNUNET_HELLO_add_address (&address, | ||
60 | GNUNET_TIME_relative_to_absolute | ||
61 | (GNUNET_TIME_UNIT_HOURS), buf, max); | ||
62 | (*agc)--; | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | |||
67 | static void | ||
68 | add_peer () | ||
69 | { | ||
70 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey; | ||
71 | struct GNUNET_PeerIdentity pid; | ||
72 | struct GNUNET_HELLO_Message *h2; | ||
73 | size_t agc; | ||
74 | |||
75 | agc = 2; | ||
76 | memset (&pkey, 32, sizeof (pkey)); | ||
77 | GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); | ||
78 | h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc, GNUNET_YES); | ||
79 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); | ||
80 | GNUNET_free (h2); | ||
81 | |||
82 | } | ||
83 | |||
84 | |||
85 | static void | ||
86 | process (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
87 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | ||
88 | { | ||
89 | if (err_msg != NULL) | ||
90 | { | ||
91 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
92 | _("Error in communication with PEERINFO service\n")); | ||
93 | } | ||
94 | |||
95 | if (peer == NULL) | ||
96 | { | ||
97 | ic = NULL; | ||
98 | if ((3 == global_ret) && (retries < 50)) | ||
99 | { | ||
100 | /* try again */ | ||
101 | retries++; | ||
102 | add_peer (); | ||
103 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, | ||
104 | GNUNET_TIME_relative_multiply | ||
105 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, | ||
106 | cls); | ||
107 | return; | ||
108 | } | ||
109 | GNUNET_assert (peer == NULL); | ||
110 | GNUNET_assert (2 == global_ret); | ||
111 | GNUNET_PEERINFO_disconnect (h); | ||
112 | h = NULL; | ||
113 | global_ret = 0; | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | if (hello == NULL) | ||
118 | { | ||
119 | GNUNET_assert (3 == global_ret); | ||
120 | global_ret = 2; | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | fprintf (stderr, "Received %s HELLO\n", | ||
125 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public"); | ||
126 | GNUNET_PEERINFO_disconnect (h); | ||
127 | h = NULL; | ||
128 | return; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | |||
133 | static void | ||
134 | run (void *cls, | ||
135 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
136 | struct GNUNET_TESTING_Peer *peer) | ||
137 | { | ||
138 | h = GNUNET_PEERINFO_connect (cfg); | ||
139 | GNUNET_assert (NULL != h); | ||
140 | add_peer (); | ||
141 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, | ||
142 | GNUNET_TIME_relative_multiply | ||
143 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); | ||
144 | } | ||
145 | |||
146 | |||
147 | int | ||
148 | main (int argc, char *argv[]) | ||
149 | { | ||
150 | global_ret = 3; | ||
151 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", | ||
152 | "peerinfo", | ||
153 | "test_peerinfo_api_data.conf", | ||
154 | &run, NULL)) | ||
155 | return 1; | ||
156 | return global_ret; | ||
157 | } | ||
158 | |||
159 | /* end of test_peerinfo_api_friend_only */ | ||