aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/test_peerinfo_api.c')
-rw-r--r--src/peerinfo/test_peerinfo_api.c127
1 files changed, 63 insertions, 64 deletions
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index 9060cf7b7..4c2184904 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file peerinfo/test_peerinfo_api.c 22 * @file peerinfo/test_peerinfo_api.c
@@ -43,25 +43,25 @@ static int global_ret;
43 43
44 44
45static int 45static int
46check_it (void *cls, const struct GNUNET_HELLO_Address *address, 46check_it(void *cls, const struct GNUNET_HELLO_Address *address,
47 struct GNUNET_TIME_Absolute expiration) 47 struct GNUNET_TIME_Absolute expiration)
48{ 48{
49 unsigned int *agc = cls; 49 unsigned int *agc = cls;
50 50
51 if (address != NULL) 51 if (address != NULL)
52 { 52 {
53 GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name)); 53 GNUNET_assert(0 == strcmp("peerinfotest", address->transport_name));
54 GNUNET_assert (0 == 54 GNUNET_assert(0 ==
55 strncmp ("Address", address->address, 55 strncmp("Address", address->address,
56 address->address_length)); 56 address->address_length));
57 (*agc) -= (1 << (address->address_length - 1)); 57 (*agc) -= (1 << (address->address_length - 1));
58 } 58 }
59 return GNUNET_OK; 59 return GNUNET_OK;
60} 60}
61 61
62 62
63static ssize_t 63static ssize_t
64address_generator (void *cls, size_t max, void *buf) 64address_generator(void *cls, size_t max, void *buf)
65{ 65{
66 size_t *agc = cls; 66 size_t *agc = cls;
67 ssize_t ret; 67 ssize_t ret;
@@ -69,14 +69,14 @@ address_generator (void *cls, size_t max, void *buf)
69 69
70 if (0 == *agc) 70 if (0 == *agc)
71 return GNUNET_SYSERR; /* Done */ 71 return GNUNET_SYSERR; /* Done */
72 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 72 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
73 address.address = "Address"; 73 address.address = "Address";
74 address.transport_name = "peerinfotest"; 74 address.transport_name = "peerinfotest";
75 address.address_length = *agc; 75 address.address_length = *agc;
76 ret = 76 ret =
77 GNUNET_HELLO_add_address (&address, 77 GNUNET_HELLO_add_address(&address,
78 GNUNET_TIME_relative_to_absolute 78 GNUNET_TIME_relative_to_absolute
79 (GNUNET_TIME_UNIT_HOURS), buf, max); 79 (GNUNET_TIME_UNIT_HOURS), buf, max);
80 (*agc)--; 80 (*agc)--;
81 return ret; 81 return ret;
82} 82}
@@ -84,85 +84,84 @@ address_generator (void *cls, size_t max, void *buf)
84struct GNUNET_PeerIdentity pid; 84struct GNUNET_PeerIdentity pid;
85 85
86static void 86static void
87add_peer () 87add_peer()
88{ 88{
89 struct GNUNET_HELLO_Message *h2; 89 struct GNUNET_HELLO_Message *h2;
90 size_t agc; 90 size_t agc;
91 91
92 agc = 2; 92 agc = 2;
93 memset (&pid, 32, sizeof (pid)); 93 memset(&pid, 32, sizeof(pid));
94 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_NO); 94 h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, GNUNET_NO);
95 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 95 GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL);
96 GNUNET_free (h2); 96 GNUNET_free(h2);
97
98} 97}
99 98
100 99
101static void 100static void
102process (void *cls, const struct GNUNET_PeerIdentity *peer, 101process(void *cls, const struct GNUNET_PeerIdentity *peer,
103 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 102 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
104{ 103{
105 unsigned int agc; 104 unsigned int agc;
106 105
107 if (err_msg != NULL) 106 if (err_msg != NULL)
108 { 107 {
109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 108 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
110 _("Error in communication with PEERINFO service\n")); 109 _("Error in communication with PEERINFO service\n"));
111 } 110 }
112 111
113 if (peer == NULL) 112 if (peer == NULL)
114 {
115 ic = NULL;
116 if ((3 == global_ret) && (retries < 50))
117 { 113 {
118 /* try again */ 114 ic = NULL;
119 retries++; 115 if ((3 == global_ret) && (retries < 50))
120 add_peer (); 116 {
121 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, 117 /* try again */
122 &process, 118 retries++;
123 cls); 119 add_peer();
120 ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, NULL,
121 &process,
122 cls);
123 return;
124 }
125 GNUNET_assert(peer == NULL);
126 GNUNET_assert(2 == global_ret);
127 GNUNET_PEERINFO_disconnect(h);
128 h = NULL;
129 global_ret = 0;
124 return; 130 return;
125 } 131 }
126 GNUNET_assert (peer == NULL);
127 GNUNET_assert (2 == global_ret);
128 GNUNET_PEERINFO_disconnect (h);
129 h = NULL;
130 global_ret = 0;
131 return;
132 }
133 if (hello != NULL) 132 if (hello != NULL)
134 { 133 {
135 GNUNET_assert (3 == global_ret); 134 GNUNET_assert(3 == global_ret);
136 agc = 3; 135 agc = 3;
137 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, 136 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO,
138 &check_it, &agc); 137 &check_it, &agc);
139 GNUNET_assert (agc == 0); 138 GNUNET_assert(agc == 0);
140 global_ret = 2; 139 global_ret = 2;
141 } 140 }
142} 141}
143 142
144 143
145static void 144static void
146run (void *cls, 145run(void *cls,
147 const struct GNUNET_CONFIGURATION_Handle *cfg, 146 const struct GNUNET_CONFIGURATION_Handle *cfg,
148 struct GNUNET_TESTING_Peer *peer) 147 struct GNUNET_TESTING_Peer *peer)
149{ 148{
150 h = GNUNET_PEERINFO_connect (cfg); 149 h = GNUNET_PEERINFO_connect(cfg);
151 GNUNET_assert (NULL != h); 150 GNUNET_assert(NULL != h);
152 add_peer (); 151 add_peer();
153 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid, 152 ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, &pid,
154 &process, cls); 153 &process, cls);
155} 154}
156 155
157 156
158int 157int
159main (int argc, char *argv[]) 158main(int argc, char *argv[])
160{ 159{
161 global_ret = 3; 160 global_ret = 3;
162 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo", 161 if (0 != GNUNET_TESTING_service_run("test-gnunet-peerinfo",
163 "peerinfo", 162 "peerinfo",
164 "test_peerinfo_api_data.conf", 163 "test_peerinfo_api_data.conf",
165 &run, NULL)) 164 &run, NULL))
166 return 1; 165 return 1;
167 return global_ret; 166 return global_ret;
168} 167}