diff options
Diffstat (limited to 'src/transport/test_transport_api_manipulation_send_tcp.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_send_tcp.c | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c index 408301b0f..ea4c7621b 100644 --- a/src/transport/test_transport_api_manipulation_send_tcp.c +++ b/src/transport/test_transport_api_manipulation_send_tcp.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_manipulation_send_tcp.c | 21 | * @file transport/test_transport_api_manipulation_send_tcp.c |
22 | * @brief base test case for transport traffic manipulation implementation | 22 | * @brief base test case for transport traffic manipulation implementation |
@@ -34,7 +34,7 @@ | |||
34 | /** | 34 | /** |
35 | * How long until we give up on transmitting the message? | 35 | * How long until we give up on transmitting the message? |
36 | */ | 36 | */ |
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
38 | 38 | ||
39 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | 39 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
40 | 40 | ||
@@ -50,130 +50,130 @@ static struct GNUNET_TIME_Relative dur_delayed; | |||
50 | 50 | ||
51 | 51 | ||
52 | static void | 52 | static void |
53 | do_free (void *cls) | 53 | do_free(void *cls) |
54 | { | 54 | { |
55 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; | 55 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; |
56 | 56 | ||
57 | GNUNET_free (sc); | 57 | GNUNET_free(sc); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static void | 61 | static void |
62 | delayed_transmit (void *cls) | 62 | delayed_transmit(void *cls) |
63 | { | 63 | { |
64 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; | 64 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; |
65 | 65 | ||
66 | start_delayed = GNUNET_TIME_absolute_get (); | 66 | start_delayed = GNUNET_TIME_absolute_get(); |
67 | GNUNET_TRANSPORT_TESTING_large_send (sc); | 67 | GNUNET_TRANSPORT_TESTING_large_send(sc); |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | static void | 71 | static void |
72 | sendtask (void *cls) | 72 | sendtask(void *cls) |
73 | { | 73 | { |
74 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; | 74 | struct GNUNET_TRANSPORT_TESTING_SendClosure *sc; |
75 | struct GNUNET_TIME_Relative delay; | 75 | struct GNUNET_TIME_Relative delay; |
76 | struct GNUNET_ATS_Properties prop; | 76 | struct GNUNET_ATS_Properties prop; |
77 | 77 | ||
78 | sc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_SendClosure); | 78 | sc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_SendClosure); |
79 | sc->num_messages = 1; | 79 | sc->num_messages = 1; |
80 | sc->ccc = ccc; | 80 | sc->ccc = ccc; |
81 | sc->cont = &do_free; | 81 | sc->cont = &do_free; |
82 | sc->cont_cls = sc; | 82 | sc->cont_cls = sc; |
83 | if (0 == messages_recv) | 83 | if (0 == messages_recv) |
84 | { | 84 | { |
85 | start_normal = GNUNET_TIME_absolute_get (); | 85 | start_normal = GNUNET_TIME_absolute_get(); |
86 | } | 86 | } |
87 | if (1 == messages_recv) | 87 | if (1 == messages_recv) |
88 | { | 88 | { |
89 | memset (&prop, | 89 | memset(&prop, |
90 | 0, | 90 | 0, |
91 | sizeof (prop)); | 91 | sizeof(prop)); |
92 | delay = GNUNET_TIME_UNIT_SECONDS; | 92 | delay = GNUNET_TIME_UNIT_SECONDS; |
93 | GNUNET_TRANSPORT_manipulation_set (ccc->p[0]->tmh, | 93 | GNUNET_TRANSPORT_manipulation_set(ccc->p[0]->tmh, |
94 | &ccc->p[1]->id, | 94 | &ccc->p[1]->id, |
95 | &prop, | 95 | &prop, |
96 | GNUNET_TIME_UNIT_ZERO, | 96 | GNUNET_TIME_UNIT_ZERO, |
97 | delay); | 97 | delay); |
98 | /* wait 1s to allow manipulation to go into effect */ | 98 | /* wait 1s to allow manipulation to go into effect */ |
99 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 99 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
100 | &delayed_transmit, | 100 | &delayed_transmit, |
101 | sc); | 101 | sc); |
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | GNUNET_TRANSPORT_TESTING_large_send (sc); | 104 | GNUNET_TRANSPORT_TESTING_large_send(sc); |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | static void | 108 | static void |
109 | notify_receive (void *cls, | 109 | notify_receive(void *cls, |
110 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 110 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
111 | const struct GNUNET_PeerIdentity *sender, | 111 | const struct GNUNET_PeerIdentity *sender, |
112 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 112 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
113 | { | 113 | { |
114 | { | 114 | { |
115 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 115 | char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); |
116 | 116 | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 117 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
118 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", | 118 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
119 | receiver->no, | 119 | receiver->no, |
120 | ps, | 120 | ps, |
121 | ntohs (message->header.type), | 121 | ntohs(message->header.type), |
122 | ntohs (message->header.size), | 122 | ntohs(message->header.size), |
123 | GNUNET_i2s (sender)); | 123 | GNUNET_i2s(sender)); |
124 | GNUNET_free (ps); | 124 | GNUNET_free(ps); |
125 | } | 125 | } |
126 | 126 | ||
127 | if ( (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (message->header.type)) || | 127 | if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(message->header.type)) || |
128 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs (message->header.size)) ) | 128 | (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE != ntohs(message->header.size))) |
129 | { | 129 | { |
130 | GNUNET_break (0); | 130 | GNUNET_break(0); |
131 | ccc->global_ret = GNUNET_SYSERR; | 131 | ccc->global_ret = GNUNET_SYSERR; |
132 | GNUNET_SCHEDULER_shutdown (); | 132 | GNUNET_SCHEDULER_shutdown(); |
133 | return; | 133 | return; |
134 | } | 134 | } |
135 | 135 | ||
136 | if (0 == messages_recv) | 136 | if (0 == messages_recv) |
137 | { | 137 | { |
138 | /* Received non-delayed message */ | 138 | /* Received non-delayed message */ |
139 | dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); | 139 | dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
141 | "Received non-delayed message %u after %s\n", | 141 | "Received non-delayed message %u after %s\n", |
142 | messages_recv, | 142 | messages_recv, |
143 | GNUNET_STRINGS_relative_time_to_string (dur_normal, | 143 | GNUNET_STRINGS_relative_time_to_string(dur_normal, |
144 | GNUNET_YES)); | 144 | GNUNET_YES)); |
145 | GNUNET_SCHEDULER_add_now (&sendtask, | 145 | GNUNET_SCHEDULER_add_now(&sendtask, |
146 | NULL); | 146 | NULL); |
147 | messages_recv++; | 147 | messages_recv++; |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | /* Received manipulated message */ | 150 | /* Received manipulated message */ |
151 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); | 151 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 152 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
153 | "Received delayed message %u after %s\n", | 153 | "Received delayed message %u after %s\n", |
154 | messages_recv, | 154 | messages_recv, |
155 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, | 155 | GNUNET_STRINGS_relative_time_to_string(dur_delayed, |
156 | GNUNET_YES)); | 156 | GNUNET_YES)); |
157 | if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) | 157 | if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) |
158 | { | 158 | { |
159 | GNUNET_break (0); | 159 | GNUNET_break(0); |
160 | ccc->global_ret = GNUNET_SYSERR; | 160 | ccc->global_ret = GNUNET_SYSERR; |
161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 161 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
162 | "Delayed message was not delayed correctly: took only %s\n", | 162 | "Delayed message was not delayed correctly: took only %s\n", |
163 | GNUNET_STRINGS_relative_time_to_string (dur_delayed, | 163 | GNUNET_STRINGS_relative_time_to_string(dur_delayed, |
164 | GNUNET_YES)); | 164 | GNUNET_YES)); |
165 | } | 165 | } |
166 | else | 166 | else |
167 | { | 167 | { |
168 | ccc->global_ret = GNUNET_OK; | 168 | ccc->global_ret = GNUNET_OK; |
169 | } | 169 | } |
170 | GNUNET_SCHEDULER_shutdown (); | 170 | GNUNET_SCHEDULER_shutdown(); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | int | 174 | int |
175 | main (int argc, | 175 | main(int argc, |
176 | char *argv[]) | 176 | char *argv[]) |
177 | { | 177 | { |
178 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { | 178 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
179 | .connect_continuation = &sendtask, | 179 | .connect_continuation = &sendtask, |
@@ -187,9 +187,9 @@ main (int argc, | |||
187 | 187 | ||
188 | ccc = &my_ccc; | 188 | ccc = &my_ccc; |
189 | if (GNUNET_OK != | 189 | if (GNUNET_OK != |
190 | GNUNET_TRANSPORT_TESTING_main (2, | 190 | GNUNET_TRANSPORT_TESTING_main(2, |
191 | &GNUNET_TRANSPORT_TESTING_connect_check, | 191 | &GNUNET_TRANSPORT_TESTING_connect_check, |
192 | ccc)) | 192 | ccc)) |
193 | return 1; | 193 | return 1; |
194 | return 0; | 194 | return 0; |
195 | } | 195 | } |