diff options
Diffstat (limited to 'src/transport/test_transport_api_restart_reconnect.c')
-rw-r--r-- | src/transport/test_transport_api_restart_reconnect.c | 169 |
1 files changed, 85 insertions, 84 deletions
diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c index bf9a7f9a1..dff57a3a8 100644 --- a/src/transport/test_transport_api_restart_reconnect.c +++ b/src/transport/test_transport_api_restart_reconnect.c | |||
@@ -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 | ||
38 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 38 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
@@ -47,112 +47,113 @@ static int restarted; | |||
47 | 47 | ||
48 | 48 | ||
49 | static void | 49 | static void |
50 | custom_shutdown(void *cls) | 50 | custom_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 | ||
60 | static void | 60 | static void |
61 | restart_cb(void *cls) | 61 | restart_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 | ||
81 | static void | 81 | static void |
82 | restart(struct GNUNET_TRANSPORT_TESTING_PeerContext *p) | 82 | restart (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 | ||
95 | static void | 95 | static void |
96 | notify_receive(void *cls, | 96 | notify_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 ( |
115 | message->header.size))) | ||
116 | { | ||
117 | if (GNUNET_NO == restarted) | ||
115 | { | 118 | { |
116 | if (GNUNET_NO == restarted) | 119 | restarted = GNUNET_YES; |
117 | { | 120 | fprintf (stderr, "TN: %s\n", ccc->test_name); |
118 | restarted = GNUNET_YES; | 121 | restart (ccc->p[0]); |
119 | fprintf(stderr, "TN: %s\n", ccc->test_name); | 122 | if (NULL != strstr (ccc->test_name, |
120 | restart(ccc->p[0]); | 123 | "2peers")) |
121 | if (NULL != strstr(ccc->test_name, | 124 | restart (ccc->p[1]); |
122 | "2peers")) | 125 | return; |
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 | } | ||
133 | } | 126 | } |
134 | else | 127 | else |
135 | { | 128 | { |
136 | GNUNET_break(0); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
137 | ccc->global_ret = GNUNET_SYSERR; | 130 | "Restarted peers connected and message was sent, stopping test...\n"); |
138 | GNUNET_SCHEDULER_shutdown(); | 131 | ccc->global_ret = GNUNET_OK; |
132 | GNUNET_SCHEDULER_shutdown (); | ||
139 | } | 133 | } |
134 | } | ||
135 | else | ||
136 | { | ||
137 | GNUNET_break (0); | ||
138 | ccc->global_ret = GNUNET_SYSERR; | ||
139 | GNUNET_SCHEDULER_shutdown (); | ||
140 | } | ||
140 | } | 141 | } |
141 | 142 | ||
142 | 143 | ||
143 | static void | 144 | static void |
144 | notify_connect(void *cls, | 145 | notify_connect (void *cls, |
145 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 146 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
146 | const struct GNUNET_PeerIdentity *other) | 147 | const struct GNUNET_PeerIdentity *other) |
147 | { | 148 | { |
148 | static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | 149 | static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { |
149 | .num_messages = 1 | 150 | .num_messages = 1 |
150 | }; | 151 | }; |
151 | 152 | ||
152 | sc.ccc = ccc; | 153 | sc.ccc = ccc; |
153 | GNUNET_TRANSPORT_TESTING_log_connect(cls, | 154 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
154 | me, | 155 | me, |
155 | other); | 156 | other); |
156 | if (me == ccc->p[0]) | 157 | if (me == ccc->p[0]) |
157 | p1_connected = GNUNET_YES; | 158 | p1_connected = GNUNET_YES; |
158 | if (me == ccc->p[1]) | 159 | if (me == ccc->p[1]) |
@@ -161,22 +162,22 @@ notify_connect(void *cls, | |||
161 | if ((GNUNET_YES == restarted) && | 162 | if ((GNUNET_YES == restarted) && |
162 | (GNUNET_YES == p1_connected) && | 163 | (GNUNET_YES == p1_connected) && |
163 | (GNUNET_YES == p2_connected)) | 164 | (GNUNET_YES == p2_connected)) |
164 | { | 165 | { |
165 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | 166 | /* 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, | 167 | GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, |
167 | &sc); | 168 | &sc); |
168 | } | 169 | } |
169 | } | 170 | } |
170 | 171 | ||
171 | 172 | ||
172 | static void | 173 | static void |
173 | notify_disconnect(void *cls, | 174 | notify_disconnect (void *cls, |
174 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 175 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
175 | const struct GNUNET_PeerIdentity *other) | 176 | const struct GNUNET_PeerIdentity *other) |
176 | { | 177 | { |
177 | GNUNET_TRANSPORT_TESTING_log_disconnect(cls, | 178 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
178 | me, | 179 | me, |
179 | other); | 180 | other); |
180 | if (me == ccc->p[0]) | 181 | if (me == ccc->p[0]) |
181 | p1_connected = GNUNET_NO; | 182 | p1_connected = GNUNET_NO; |
182 | if (me == ccc->p[1]) | 183 | if (me == ccc->p[1]) |
@@ -185,8 +186,8 @@ notify_disconnect(void *cls, | |||
185 | 186 | ||
186 | 187 | ||
187 | int | 188 | int |
188 | main(int argc, | 189 | main (int argc, |
189 | char *argv[]) | 190 | char *argv[]) |
190 | { | 191 | { |
191 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | 192 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { |
192 | .num_messages = 1 | 193 | .num_messages = 1 |
@@ -205,9 +206,9 @@ main(int argc, | |||
205 | ccc = &my_ccc; | 206 | ccc = &my_ccc; |
206 | sc.ccc = ccc; | 207 | sc.ccc = ccc; |
207 | if (GNUNET_OK != | 208 | if (GNUNET_OK != |
208 | GNUNET_TRANSPORT_TESTING_main(2, | 209 | GNUNET_TRANSPORT_TESTING_main (2, |
209 | &GNUNET_TRANSPORT_TESTING_connect_check, | 210 | &GNUNET_TRANSPORT_TESTING_connect_check, |
210 | ccc)) | 211 | ccc)) |
211 | return 1; | 212 | return 1; |
212 | return 0; | 213 | return 0; |
213 | } | 214 | } |