diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-22 22:07:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-22 22:07:51 +0000 |
commit | 8a732552157d565ff2a0636121e1f9fd93804c64 (patch) | |
tree | 4afb4f5d5e89ea1648348913ff6dba1ceb0ebcb4 /src/transport/test_transport_api_disconnect.c | |
parent | 25a2ea0274d4d958bd9b7ca72390f0a4fb0cfc9d (diff) | |
download | gnunet-8a732552157d565ff2a0636121e1f9fd93804c64.tar.gz gnunet-8a732552157d565ff2a0636121e1f9fd93804c64.zip |
migrate more tests to new transmission API
Diffstat (limited to 'src/transport/test_transport_api_disconnect.c')
-rw-r--r-- | src/transport/test_transport_api_disconnect.c | 112 |
1 files changed, 14 insertions, 98 deletions
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 070a4124c..c8cf89d7e 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c | |||
@@ -34,32 +34,13 @@ | |||
34 | */ | 34 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
36 | 36 | ||
37 | /** | ||
38 | * How long until we give up on transmitting the message? | ||
39 | */ | ||
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
41 | |||
42 | #define MTYPE 12345 | ||
43 | 37 | ||
44 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 38 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
45 | 39 | ||
46 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
47 | |||
48 | static int shutdown_; | 40 | static int shutdown_; |
49 | 41 | ||
50 | 42 | ||
51 | static void | 43 | static void |
52 | custom_shutdown (void *cls) | ||
53 | { | ||
54 | if (th != NULL) | ||
55 | { | ||
56 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
57 | th = NULL; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | |||
62 | static void | ||
63 | notify_disconnect (void *cls, | 44 | notify_disconnect (void *cls, |
64 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 45 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
65 | const struct GNUNET_PeerIdentity *other) | 46 | const struct GNUNET_PeerIdentity *other) |
@@ -69,12 +50,7 @@ notify_disconnect (void *cls, | |||
69 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, | 50 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
70 | me, | 51 | me, |
71 | other); | 52 | other); |
72 | if (th != NULL) | 53 | if (GNUNET_YES == shutdown_) |
73 | { | ||
74 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
75 | th = NULL; | ||
76 | } | ||
77 | if (shutdown_ == GNUNET_YES) | ||
78 | { | 54 | { |
79 | ccc->global_ret = GNUNET_OK; | 55 | ccc->global_ret = GNUNET_OK; |
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 56 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -115,8 +91,8 @@ notify_receive (void *cls, | |||
115 | GNUNET_i2s (sender)); | 91 | GNUNET_i2s (sender)); |
116 | GNUNET_free (ps); | 92 | GNUNET_free (ps); |
117 | } | 93 | } |
118 | if ((MTYPE == ntohs (message->type)) && | 94 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->type)) && |
119 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 95 | (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->size))) |
120 | { | 96 | { |
121 | GNUNET_SCHEDULER_add_now (&stop_peer, | 97 | GNUNET_SCHEDULER_add_now (&stop_peer, |
122 | NULL); | 98 | NULL); |
@@ -125,86 +101,26 @@ notify_receive (void *cls, | |||
125 | } | 101 | } |
126 | 102 | ||
127 | 103 | ||
128 | static size_t | ||
129 | notify_ready (void *cls, | ||
130 | size_t size, | ||
131 | void *buf) | ||
132 | { | ||
133 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
134 | struct GNUNET_MessageHeader *hdr; | ||
135 | |||
136 | th = NULL; | ||
137 | |||
138 | if (buf == NULL) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
141 | "Transmission error occurred in transmit_ready\n"); | ||
142 | GNUNET_SCHEDULER_shutdown (); | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | GNUNET_assert (size >= 256); | ||
147 | |||
148 | if (NULL != buf) | ||
149 | { | ||
150 | hdr = buf; | ||
151 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
152 | hdr->type = htons (MTYPE); | ||
153 | } | ||
154 | { | ||
155 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); | ||
156 | |||
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
158 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
159 | ccc->p[1]->no, | ||
160 | ps, | ||
161 | ntohs (hdr->type), | ||
162 | ntohs (hdr->size), | ||
163 | p->no, | ||
164 | GNUNET_i2s (&p->id)); | ||
165 | GNUNET_free (ps); | ||
166 | } | ||
167 | return sizeof (struct GNUNET_MessageHeader); | ||
168 | } | ||
169 | |||
170 | |||
171 | static void | ||
172 | sendtask (void *cls) | ||
173 | { | ||
174 | ccc->global_ret = GNUNET_SYSERR; | ||
175 | { | ||
176 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
177 | |||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
179 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
180 | ccc->p[1]->no, | ||
181 | GNUNET_i2s (&ccc->p[1]->id), | ||
182 | ccc->p[0]->no, | ||
183 | receiver_s); | ||
184 | GNUNET_free (receiver_s); | ||
185 | } | ||
186 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | ||
187 | &ccc->p[0]->id, 256, | ||
188 | TIMEOUT_TRANSMIT, | ||
189 | ¬ify_ready, | ||
190 | ccc->p[0]); | ||
191 | } | ||
192 | |||
193 | |||
194 | int | 104 | int |
195 | main (int argc, char *argv[]) | 105 | main (int argc, |
106 | char *argv[]) | ||
196 | { | 107 | { |
108 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | ||
109 | .num_messages = 1 | ||
110 | }; | ||
197 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 111 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
198 | .connect_continuation = &sendtask, | 112 | .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send, |
113 | .connect_continuation_cls = &sc, | ||
199 | .config_file = "test_transport_api_data.conf", | 114 | .config_file = "test_transport_api_data.conf", |
200 | .rec = ¬ify_receive, | 115 | .rec = ¬ify_receive, |
201 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | 116 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
202 | .nd = ¬ify_disconnect, | 117 | .nd = ¬ify_disconnect, |
203 | .shutdown_task = &custom_shutdown, | 118 | .timeout = TIMEOUT, |
204 | .timeout = TIMEOUT | 119 | .global_ret = GNUNET_SYSERR |
205 | }; | 120 | }; |
121 | |||
206 | ccc = &my_ccc; | 122 | ccc = &my_ccc; |
207 | 123 | sc.ccc = ccc; | |
208 | if (GNUNET_OK != | 124 | if (GNUNET_OK != |
209 | GNUNET_TRANSPORT_TESTING_main (2, | 125 | GNUNET_TRANSPORT_TESTING_main (2, |
210 | &GNUNET_TRANSPORT_TESTING_connect_check, | 126 | &GNUNET_TRANSPORT_TESTING_connect_check, |