diff options
Diffstat (limited to 'src/transport/test_transport_api_manipulation_cfg.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_cfg.c | 175 |
1 files changed, 89 insertions, 86 deletions
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index 2d17cca45..4661a85a2 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.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_cfg.c | 21 | * @file transport/test_transport_api_manipulation_cfg.c |
22 | * @brief base test case for transport traffic manipulation implementation | 22 | * @brief base test case for transport traffic manipulation implementation |
@@ -35,12 +35,12 @@ | |||
35 | /** | 35 | /** |
36 | * How long until we give up on transmitting the message? | 36 | * How long until we give up on transmitting the message? |
37 | */ | 37 | */ |
38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) |
39 | 39 | ||
40 | 40 | ||
41 | #define TEST_MESSAGE_SIZE 2600 | 41 | #define TEST_MESSAGE_SIZE 2600 |
42 | 42 | ||
43 | #define TEST_RESPONSE_MESSAGE_TYPE | 43 | #define TEST_RESPONSE_MESSAGE_TYPE |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Test delay, in microseconds. | 46 | * Test delay, in microseconds. |
@@ -56,104 +56,107 @@ static struct GNUNET_TIME_Absolute start_response; | |||
56 | 56 | ||
57 | 57 | ||
58 | static void | 58 | static void |
59 | sendtask_response_task (void *cls) | 59 | sendtask_response_task(void *cls) |
60 | { | 60 | { |
61 | int ret; | 61 | int ret; |
62 | 62 | ||
63 | start_response = GNUNET_TIME_absolute_get(); | 63 | start_response = GNUNET_TIME_absolute_get(); |
64 | ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[1], | 64 | ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[1], |
65 | ccc->p[0], | 65 | ccc->p[0], |
66 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, | 66 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, |
67 | TEST_MESSAGE_SIZE, | 67 | TEST_MESSAGE_SIZE, |
68 | 1, | 68 | 1, |
69 | NULL, | 69 | NULL, |
70 | NULL); | 70 | NULL); |
71 | if (GNUNET_NO == ret) | 71 | if (GNUNET_NO == ret) |
72 | { | 72 | { |
73 | GNUNET_break (0); | 73 | GNUNET_break(0); |
74 | GNUNET_SCHEDULER_shutdown (); | 74 | GNUNET_SCHEDULER_shutdown(); |
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | GNUNET_assert (GNUNET_SYSERR != ret); | 77 | GNUNET_assert(GNUNET_SYSERR != ret); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | static void | 81 | static void |
82 | notify_receive (void *cls, | 82 | notify_receive(void *cls, |
83 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 83 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
84 | const struct GNUNET_PeerIdentity *sender, | 84 | const struct GNUNET_PeerIdentity *sender, |
85 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | 85 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) |
86 | { | 86 | { |
87 | struct GNUNET_TIME_Relative duration; | 87 | struct GNUNET_TIME_Relative duration; |
88 | 88 | ||
89 | { | 89 | { |
90 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 90 | char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); |
91 | 91 | ||
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 92 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
93 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", | 93 | "Peer %u (`%s') received message of type %d and size %u size from peer %s)!\n", |
94 | receiver->no, | 94 | receiver->no, |
95 | ps, | 95 | ps, |
96 | ntohs (message->header.type), | 96 | ntohs(message->header.type), |
97 | ntohs (message->header.size), | 97 | ntohs(message->header.size), |
98 | GNUNET_i2s (sender)); | 98 | GNUNET_i2s(sender)); |
99 | GNUNET_free (ps); | 99 | GNUNET_free(ps); |
100 | } | 100 | } |
101 | 101 | ||
102 | switch (ntohs (message->header.type)) { | 102 | switch (ntohs(message->header.type)) |
103 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: | ||
104 | duration = GNUNET_TIME_absolute_get_difference (start_request, | ||
105 | GNUNET_TIME_absolute_get()); | ||
106 | if (duration.rel_value_us >= TEST_DELAY) | ||
107 | { | 103 | { |
108 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 104 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE: |
109 | "Request message was delayed for %s\n", | 105 | duration = GNUNET_TIME_absolute_get_difference(start_request, |
110 | GNUNET_STRINGS_relative_time_to_string (duration, | 106 | GNUNET_TIME_absolute_get()); |
111 | GNUNET_YES)); | 107 | if (duration.rel_value_us >= TEST_DELAY) |
108 | { | ||
109 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
110 | "Request message was delayed for %s\n", | ||
111 | GNUNET_STRINGS_relative_time_to_string(duration, | ||
112 | GNUNET_YES)); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
117 | "Request message was delayed for unexpected duration %s\n", | ||
118 | GNUNET_STRINGS_relative_time_to_string(duration, | ||
119 | GNUNET_YES)); | ||
120 | ccc->global_ret = GNUNET_SYSERR; | ||
121 | GNUNET_SCHEDULER_shutdown(); | ||
122 | } | ||
123 | /* Send response */ | ||
124 | GNUNET_SCHEDULER_add_now(&sendtask_response_task, | ||
125 | NULL); | ||
126 | return; | ||
127 | |||
128 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2: | ||
129 | duration = GNUNET_TIME_absolute_get_difference(start_response, | ||
130 | GNUNET_TIME_absolute_get()); | ||
131 | if (duration.rel_value_us >= TEST_DELAY) | ||
132 | { | ||
133 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
134 | "Response message was delayed for %s\n", | ||
135 | GNUNET_STRINGS_relative_time_to_string(duration, | ||
136 | GNUNET_YES)); | ||
137 | ccc->global_ret = GNUNET_OK; | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
142 | "Response message was delayed for unexpected duration %s\n", | ||
143 | GNUNET_STRINGS_relative_time_to_string(duration, | ||
144 | GNUNET_YES)); | ||
145 | ccc->global_ret = GNUNET_SYSERR; | ||
146 | } | ||
147 | GNUNET_SCHEDULER_shutdown(); | ||
148 | break; | ||
149 | |||
150 | default: | ||
151 | GNUNET_break(0); | ||
152 | break; | ||
112 | } | 153 | } |
113 | else | ||
114 | { | ||
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
116 | "Request message was delayed for unexpected duration %s\n", | ||
117 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
118 | GNUNET_YES)); | ||
119 | ccc->global_ret = GNUNET_SYSERR; | ||
120 | GNUNET_SCHEDULER_shutdown (); | ||
121 | } | ||
122 | /* Send response */ | ||
123 | GNUNET_SCHEDULER_add_now (&sendtask_response_task, | ||
124 | NULL); | ||
125 | return; | ||
126 | case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2: | ||
127 | duration = GNUNET_TIME_absolute_get_difference(start_response, | ||
128 | GNUNET_TIME_absolute_get()); | ||
129 | if (duration.rel_value_us >= TEST_DELAY) | ||
130 | { | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
132 | "Response message was delayed for %s\n", | ||
133 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
134 | GNUNET_YES)); | ||
135 | ccc->global_ret = GNUNET_OK; | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
140 | "Response message was delayed for unexpected duration %s\n", | ||
141 | GNUNET_STRINGS_relative_time_to_string (duration, | ||
142 | GNUNET_YES)); | ||
143 | ccc->global_ret = GNUNET_SYSERR; | ||
144 | } | ||
145 | GNUNET_SCHEDULER_shutdown (); | ||
146 | break; | ||
147 | default: | ||
148 | GNUNET_break (0); | ||
149 | break; | ||
150 | } | ||
151 | } | 154 | } |
152 | 155 | ||
153 | 156 | ||
154 | int | 157 | int |
155 | main (int argc, | 158 | main(int argc, |
156 | char *argv[]) | 159 | char *argv[]) |
157 | { | 160 | { |
158 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | 161 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { |
159 | .num_messages = 1 | 162 | .num_messages = 1 |
@@ -170,11 +173,11 @@ main (int argc, | |||
170 | 173 | ||
171 | ccc = &my_ccc; | 174 | ccc = &my_ccc; |
172 | sc.ccc = ccc; | 175 | sc.ccc = ccc; |
173 | start_request = GNUNET_TIME_absolute_get (); | 176 | start_request = GNUNET_TIME_absolute_get(); |
174 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
175 | GNUNET_TRANSPORT_TESTING_main (2, | 178 | GNUNET_TRANSPORT_TESTING_main(2, |
176 | &GNUNET_TRANSPORT_TESTING_connect_check, | 179 | &GNUNET_TRANSPORT_TESTING_connect_check, |
177 | ccc)) | 180 | ccc)) |
178 | return 1; | 181 | return 1; |
179 | return 0; | 182 | return 0; |
180 | } | 183 | } |