summaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_restart_reconnect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_api_restart_reconnect.c')
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c182
1 files changed, 91 insertions, 91 deletions
diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c
index 5a6c10f8a..bf9a7f9a1 100644
--- a/src/transport/test_transport_api_restart_reconnect.c
+++ b/src/transport/test_transport_api_restart_reconnect.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_restart_reconnect.c 21 * @file transport/test_transport_api_restart_reconnect.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -32,7 +32,7 @@
32/** 32/**
33 * How long until we give up on transmitting the message? 33 * How long until we give up on transmitting the message?
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
36 36
37 37
38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; 38static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
@@ -47,136 +47,136 @@ static int restarted;
47 47
48 48
49static void 49static void
50custom_shutdown (void *cls) 50custom_shutdown(void *cls)
51{ 51{
52 if (NULL != ats_sh) 52 if (NULL != ats_sh)
53 { 53 {
54 GNUNET_ATS_connectivity_suggest_cancel (ats_sh); 54 GNUNET_ATS_connectivity_suggest_cancel(ats_sh);
55 ats_sh = NULL; 55 ats_sh = NULL;
56 } 56 }
57} 57}
58 58
59 59
60static void 60static void
61restart_cb (void *cls) 61restart_cb(void *cls)
62{ 62{
63 static unsigned int c; 63 static unsigned int c;
64 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 64 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
65 65
66 c++; 66 c++;
67 if ( (2 != c) && 67 if ((2 != c) &&
68 (NULL != strstr (ccc->test_name, 68 (NULL != strstr(ccc->test_name,
69 "2peers")) ) 69 "2peers")))
70 return; 70 return;
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
72 "Restarted peer %u (`%s'), issuing reconnect\n", 72 "Restarted peer %u (`%s'), issuing reconnect\n",
73 p->no, 73 p->no,
74 GNUNET_i2s (&p->id)); 74 GNUNET_i2s(&p->id));
75 ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, 75 ats_sh = GNUNET_ATS_connectivity_suggest(p->ats,
76 &ccc->p[1]->id, 76 &ccc->p[1]->id,
77 1); 77 1);
78} 78}
79 79
80 80
81static void 81static void
82restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) 82restart(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
83{ 83{
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
85 "Restarting peer %u (`%s')\n", 85 "Restarting peer %u (`%s')\n",
86 p->no, 86 p->no,
87 GNUNET_i2s (&p->id)); 87 GNUNET_i2s(&p->id));
88 GNUNET_assert (GNUNET_OK == 88 GNUNET_assert(GNUNET_OK ==
89 GNUNET_TRANSPORT_TESTING_restart_peer (p, 89 GNUNET_TRANSPORT_TESTING_restart_peer(p,
90 &restart_cb, 90 &restart_cb,
91 p)); 91 p));
92} 92}
93 93
94 94
95static void 95static void
96notify_receive (void *cls, 96notify_receive(void *cls,
97 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 97 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
98 const struct GNUNET_PeerIdentity *sender, 98 const struct GNUNET_PeerIdentity *sender,
99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 99 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
100{ 100{
101 { 101 {
102 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 102 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
103 103
104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 104 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
105 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 105 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
106 receiver->no, 106 receiver->no,
107 ps, 107 ps,
108 ntohs (message->header.type), 108 ntohs(message->header.type),
109 ntohs (message->header.size), 109 ntohs(message->header.size),
110 GNUNET_i2s (sender)); 110 GNUNET_i2s(sender));
111 GNUNET_free (ps); 111 GNUNET_free(ps);
112 } 112 }
113 if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && 113 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) &&
114 (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size)) ) 114 (sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs(message->header.size)))
115 {
116 if (GNUNET_NO == restarted)
117 { 115 {
118 restarted = GNUNET_YES; 116 if (GNUNET_NO == restarted)
119 fprintf (stderr, "TN: %s\n", ccc->test_name); 117 {
120 restart (ccc->p[0]); 118 restarted = GNUNET_YES;
121 if (NULL != strstr (ccc->test_name, 119 fprintf(stderr, "TN: %s\n", ccc->test_name);
122 "2peers")) 120 restart(ccc->p[0]);
123 restart (ccc->p[1]); 121 if (NULL != strstr(ccc->test_name,
124 return; 122 "2peers"))
123 restart(ccc->p[1]);
124 return;
125 }
126 else
127 {
128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
129 "Restarted peers connected and message was sent, stopping test...\n");
130 ccc->global_ret = GNUNET_OK;
131 GNUNET_SCHEDULER_shutdown();
132 }
125 } 133 }
126 else 134 else
127 { 135 {
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 136 GNUNET_break(0);
129 "Restarted peers connected and message was sent, stopping test...\n"); 137 ccc->global_ret = GNUNET_SYSERR;
130 ccc->global_ret = GNUNET_OK; 138 GNUNET_SCHEDULER_shutdown();
131 GNUNET_SCHEDULER_shutdown ();
132 } 139 }
133 }
134 else
135 {
136 GNUNET_break (0);
137 ccc->global_ret = GNUNET_SYSERR;
138 GNUNET_SCHEDULER_shutdown ();
139 }
140} 140}
141 141
142 142
143static void 143static void
144notify_connect (void *cls, 144notify_connect(void *cls,
145 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 145 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
146 const struct GNUNET_PeerIdentity *other) 146 const struct GNUNET_PeerIdentity *other)
147{ 147{
148 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 148 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
149 .num_messages = 1 149 .num_messages = 1
150 }; 150 };
151 151
152 sc.ccc = ccc; 152 sc.ccc = ccc;
153 GNUNET_TRANSPORT_TESTING_log_connect (cls, 153 GNUNET_TRANSPORT_TESTING_log_connect(cls,
154 me, 154 me,
155 other); 155 other);
156 if (me == ccc->p[0]) 156 if (me == ccc->p[0])
157 p1_connected = GNUNET_YES; 157 p1_connected = GNUNET_YES;
158 if (me == ccc->p[1]) 158 if (me == ccc->p[1])
159 p2_connected = GNUNET_YES; 159 p2_connected = GNUNET_YES;
160 160
161 if ( (GNUNET_YES == restarted) && 161 if ((GNUNET_YES == restarted) &&
162 (GNUNET_YES == p1_connected) && 162 (GNUNET_YES == p1_connected) &&
163 (GNUNET_YES == p2_connected) ) 163 (GNUNET_YES == p2_connected))
164 { 164 {
165 /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ 165 /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */
166 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, 166 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send,
167 &sc); 167 &sc);
168 } 168 }
169} 169}
170 170
171 171
172static void 172static void
173notify_disconnect (void *cls, 173notify_disconnect(void *cls,
174 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 174 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
175 const struct GNUNET_PeerIdentity *other) 175 const struct GNUNET_PeerIdentity *other)
176{ 176{
177 GNUNET_TRANSPORT_TESTING_log_disconnect (cls, 177 GNUNET_TRANSPORT_TESTING_log_disconnect(cls,
178 me, 178 me,
179 other); 179 other);
180 if (me == ccc->p[0]) 180 if (me == ccc->p[0])
181 p1_connected = GNUNET_NO; 181 p1_connected = GNUNET_NO;
182 if (me == ccc->p[1]) 182 if (me == ccc->p[1])
@@ -185,8 +185,8 @@ notify_disconnect (void *cls,
185 185
186 186
187int 187int
188main (int argc, 188main(int argc,
189 char *argv[]) 189 char *argv[])
190{ 190{
191 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 191 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
192 .num_messages = 1 192 .num_messages = 1
@@ -205,9 +205,9 @@ main (int argc,
205 ccc = &my_ccc; 205 ccc = &my_ccc;
206 sc.ccc = ccc; 206 sc.ccc = ccc;
207 if (GNUNET_OK != 207 if (GNUNET_OK !=
208 GNUNET_TRANSPORT_TESTING_main (2, 208 GNUNET_TRANSPORT_TESTING_main(2,
209 &GNUNET_TRANSPORT_TESTING_connect_check, 209 &GNUNET_TRANSPORT_TESTING_connect_check,
210 ccc)) 210 ccc))
211 return 1; 211 return 1;
212 return 0; 212 return 0;
213} 213}