aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_monitor_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_api_monitor_peers.c')
-rw-r--r--src/transport/test_transport_api_monitor_peers.c206
1 files changed, 103 insertions, 103 deletions
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 9c3e535fe..a76ebe5ee 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.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 * @file transport/test_transport_api_monitor_peers.c 21 * @file transport/test_transport_api_monitor_peers.c
22 * @brief base test case for transport peer monitor API 22 * @brief base test case for transport peer monitor API
@@ -28,12 +28,12 @@
28/** 28/**
29 * How long until we give up on transmitting the message? 29 * How long until we give up on transmitting the message?
30 */ 30 */
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 31#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120)
32 32
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 36#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
37 37
38#define TEST_MESSAGE_SIZE 2600 38#define TEST_MESSAGE_SIZE 2600
39 39
@@ -55,151 +55,151 @@ static int p2_c_notify;
55 55
56 56
57static void 57static void
58custom_shutdown (void *cls) 58custom_shutdown(void *cls)
59{ 59{
60 if (NULL != pmc_p1) 60 if (NULL != pmc_p1)
61 { 61 {
62 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); 62 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p1);
63 pmc_p1 = NULL; 63 pmc_p1 = NULL;
64 } 64 }
65 if (NULL != pmc_p2) 65 if (NULL != pmc_p2)
66 { 66 {
67 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); 67 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p2);
68 pmc_p2 = NULL; 68 pmc_p2 = NULL;
69 } 69 }
70} 70}
71 71
72 72
73static void 73static void
74notify_receive (void *cls, 74notify_receive(void *cls,
75 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 75 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
76 const struct GNUNET_PeerIdentity *sender, 76 const struct GNUNET_PeerIdentity *sender,
77 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 77 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
78{ 78{
79 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 79 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
80 80
81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 81 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
82 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 82 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
83 receiver->no, 83 receiver->no,
84 ps, 84 ps,
85 ntohs (message->header.type), 85 ntohs(message->header.type),
86 ntohs (message->header.size), 86 ntohs(message->header.size),
87 GNUNET_i2s (sender)); 87 GNUNET_i2s(sender));
88 GNUNET_free (ps); 88 GNUNET_free(ps);
89} 89}
90 90
91 91
92static void 92static void
93sendtask (void *cls) 93sendtask(void *cls)
94{ 94{
95 /* intentionally empty */ 95 /* intentionally empty */
96} 96}
97 97
98 98
99static void 99static void
100check_done () 100check_done()
101{ 101{
102 if ( (GNUNET_YES == p1_c) && 102 if ((GNUNET_YES == p1_c) &&
103 (GNUNET_YES == p2_c) && 103 (GNUNET_YES == p2_c) &&
104 p1_c_notify && 104 p1_c_notify &&
105 p2_c_notify) 105 p2_c_notify)
106 { 106 {
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
108 "Both peers state to be connected\n"); 108 "Both peers state to be connected\n");
109 ccc->global_ret = GNUNET_OK; 109 ccc->global_ret = GNUNET_OK;
110 GNUNET_SCHEDULER_shutdown (); 110 GNUNET_SCHEDULER_shutdown();
111 } 111 }
112} 112}
113 113
114 114
115static void 115static void
116notify_connect (void *cls, 116notify_connect(void *cls,
117 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 117 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
118 const struct GNUNET_PeerIdentity *other) 118 const struct GNUNET_PeerIdentity *other)
119{ 119{
120 GNUNET_TRANSPORT_TESTING_log_connect (cls, 120 GNUNET_TRANSPORT_TESTING_log_connect(cls,
121 me, 121 me,
122 other); 122 other);
123 if (0 == memcmp (other, &ccc->p[0]->id, sizeof (struct GNUNET_PeerIdentity))) 123 if (0 == memcmp(other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity)))
124 { 124 {
125 p1_c_notify = GNUNET_YES; 125 p1_c_notify = GNUNET_YES;
126 } 126 }
127 if (0 == memcmp (other, &ccc->p[1]->id, sizeof (struct GNUNET_PeerIdentity))) 127 if (0 == memcmp(other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity)))
128 { 128 {
129 p2_c_notify = GNUNET_YES; 129 p2_c_notify = GNUNET_YES;
130 } 130 }
131 check_done (); 131 check_done();
132} 132}
133 133
134 134
135static void 135static void
136monitor1_cb (void *cls, 136monitor1_cb(void *cls,
137 const struct GNUNET_PeerIdentity *peer, 137 const struct GNUNET_PeerIdentity *peer,
138 const struct GNUNET_HELLO_Address *address, 138 const struct GNUNET_HELLO_Address *address,
139 enum GNUNET_TRANSPORT_PeerState state, 139 enum GNUNET_TRANSPORT_PeerState state,
140 struct GNUNET_TIME_Absolute state_timeout) 140 struct GNUNET_TIME_Absolute state_timeout)
141{ 141{
142 if ((NULL == address) || (NULL == ccc->p[0])) 142 if ((NULL == address) || (NULL == ccc->p[0]))
143 return; 143 return;
144 144
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 145 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
146 "Monitor 1: %s %s %s\n", 146 "Monitor 1: %s %s %s\n",
147 GNUNET_i2s (&address->peer), 147 GNUNET_i2s(&address->peer),
148 GNUNET_TRANSPORT_ps2s (state), 148 GNUNET_TRANSPORT_ps2s(state),
149 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 149 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
150 if ( (0 == memcmp (&address->peer, &ccc->p[1]->id, sizeof (ccc->p[1]->id))) && 150 if ((0 == memcmp(&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) &&
151 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 151 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
152 (GNUNET_NO == p1_c) ) 152 (GNUNET_NO == p1_c))
153 { 153 {
154 p1_c = GNUNET_YES; 154 p1_c = GNUNET_YES;
155 check_done (); 155 check_done();
156 } 156 }
157} 157}
158 158
159 159
160static void 160static void
161monitor2_cb (void *cls, 161monitor2_cb(void *cls,
162 const struct GNUNET_PeerIdentity *peer, 162 const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_HELLO_Address *address, 163 const struct GNUNET_HELLO_Address *address,
164 enum GNUNET_TRANSPORT_PeerState state, 164 enum GNUNET_TRANSPORT_PeerState state,
165 struct GNUNET_TIME_Absolute state_timeout) 165 struct GNUNET_TIME_Absolute state_timeout)
166{ 166{
167 if ((NULL == address) || (NULL == ccc->p[1])) 167 if ((NULL == address) || (NULL == ccc->p[1]))
168 return; 168 return;
169 169
170 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 170 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
171 "Monitor 2: %s %s %s\n", 171 "Monitor 2: %s %s %s\n",
172 GNUNET_i2s (&address->peer), 172 GNUNET_i2s(&address->peer),
173 GNUNET_TRANSPORT_ps2s (state), 173 GNUNET_TRANSPORT_ps2s(state),
174 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 174 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
175 if ( (0 == memcmp (&address->peer, &ccc->p[0]->id, sizeof (ccc->p[0]->id))) && 175 if ((0 == memcmp(&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) &&
176 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 176 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
177 (GNUNET_NO == p2_c) ) 177 (GNUNET_NO == p2_c))
178 { 178 {
179 p2_c = GNUNET_YES; 179 p2_c = GNUNET_YES;
180 check_done (); 180 check_done();
181 } 181 }
182} 182}
183 183
184 184
185static void 185static void
186start_monitors (void *cls) 186start_monitors(void *cls)
187{ 187{
188 pmc_p1 = GNUNET_TRANSPORT_monitor_peers (ccc->p[0]->cfg, 188 pmc_p1 = GNUNET_TRANSPORT_monitor_peers(ccc->p[0]->cfg,
189 NULL, 189 NULL,
190 GNUNET_NO, 190 GNUNET_NO,
191 &monitor1_cb, 191 &monitor1_cb,
192 NULL); 192 NULL);
193 pmc_p2 = GNUNET_TRANSPORT_monitor_peers (ccc->p[1]->cfg, 193 pmc_p2 = GNUNET_TRANSPORT_monitor_peers(ccc->p[1]->cfg,
194 NULL, 194 NULL,
195 GNUNET_NO, 195 GNUNET_NO,
196 &monitor2_cb, 196 &monitor2_cb,
197 NULL); 197 NULL);
198} 198}
199 199
200 200
201int 201int
202main (int argc, char *argv[]) 202main(int argc, char *argv[])
203{ 203{
204 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 204 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
205 .pre_connect_task = &start_monitors, 205 .pre_connect_task = &start_monitors,
@@ -214,9 +214,9 @@ main (int argc, char *argv[])
214 214
215 ccc = &my_ccc; 215 ccc = &my_ccc;
216 if (GNUNET_OK != 216 if (GNUNET_OK !=
217 GNUNET_TRANSPORT_TESTING_main (2, 217 GNUNET_TRANSPORT_TESTING_main(2,
218 &GNUNET_TRANSPORT_TESTING_connect_check, 218 &GNUNET_TRANSPORT_TESTING_connect_check,
219 ccc)) 219 ccc))
220 return 1; 220 return 1;
221 return 0; 221 return 0;
222} 222}