diff options
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 146 |
1 files changed, 65 insertions, 81 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 10c1c68a8..878ab2618 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -90,9 +90,7 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; | |||
90 | static void | 90 | static void |
91 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, | 91 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, |
92 | const struct GNUNET_ATS_Information *ats, | 92 | const struct GNUNET_ATS_Information *ats, |
93 | uint32_t ats_count, | 93 | uint32_t ats_count, const char *transport, const void *addr, |
94 | const char * transport, | ||
95 | const void * addr, | ||
96 | size_t addrlen) | 94 | size_t addrlen) |
97 | { | 95 | { |
98 | const struct GNUNET_MessageHeader *hello = cls; | 96 | const struct GNUNET_MessageHeader *hello = cls; |
@@ -118,7 +116,7 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | |||
118 | 116 | ||
119 | 117 | ||
120 | /** | 118 | /** |
121 | * We received some payload. Prepare to pass it on to our clients. | 119 | * We received some payload. Prepare to pass it on to our clients. |
122 | * | 120 | * |
123 | * @param peer (claimed) identity of the other peer | 121 | * @param peer (claimed) identity of the other peer |
124 | * @param message the message, never NULL | 122 | * @param message the message, never NULL |
@@ -128,48 +126,45 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | |||
128 | */ | 126 | */ |
129 | static struct GNUNET_TIME_Relative | 127 | static struct GNUNET_TIME_Relative |
130 | process_payload (const struct GNUNET_PeerIdentity *peer, | 128 | process_payload (const struct GNUNET_PeerIdentity *peer, |
131 | const struct GNUNET_MessageHeader *message, | 129 | const struct GNUNET_MessageHeader *message, |
132 | const struct GNUNET_ATS_Information *ats, | 130 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
133 | uint32_t ats_count) | ||
134 | { | 131 | { |
135 | struct GNUNET_TIME_Relative ret; | 132 | struct GNUNET_TIME_Relative ret; |
136 | int do_forward; | 133 | int do_forward; |
137 | struct InboundMessage *im; | 134 | struct InboundMessage *im; |
138 | size_t msg_size = ntohs (message->size); | 135 | size_t msg_size = ntohs (message->size); |
139 | size_t size = sizeof (struct InboundMessage) + msg_size + sizeof (struct GNUNET_ATS_Information) * ats_count; | 136 | size_t size = |
137 | sizeof (struct InboundMessage) + msg_size + | ||
138 | sizeof (struct GNUNET_ATS_Information) * ats_count; | ||
140 | char buf[size]; | 139 | char buf[size]; |
141 | struct GNUNET_ATS_Information *ap; | 140 | struct GNUNET_ATS_Information *ap; |
142 | 141 | ||
143 | ret = GNUNET_TIME_UNIT_ZERO; | 142 | ret = GNUNET_TIME_UNIT_ZERO; |
144 | do_forward = GNUNET_SYSERR; | 143 | do_forward = GNUNET_SYSERR; |
145 | ret = | 144 | ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); |
146 | GST_neighbours_calculate_receive_delay (peer, | ||
147 | msg_size, | ||
148 | &do_forward); | ||
149 | 145 | ||
150 | if (!GST_neighbours_test_connected (peer)) | 146 | if (!GST_neighbours_test_connected (peer)) |
151 | { | 147 | { |
152 | 148 | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarded %u bytes type %u payload from peer `%s'\n", | 149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | msg_size, | 150 | "Discarded %u bytes type %u payload from peer `%s'\n", msg_size, |
155 | ntohs (message->type), | 151 | ntohs (message->type), GNUNET_i2s (peer)); |
156 | GNUNET_i2s (peer)); | ||
157 | 152 | ||
158 | GNUNET_STATISTICS_update (GST_stats, | 153 | GNUNET_STATISTICS_update (GST_stats, |
159 | gettext_noop ("# bytes payload discarded due to not connected peer "), | 154 | gettext_noop |
160 | msg_size, | 155 | ("# bytes payload discarded due to not connected peer "), |
161 | GNUNET_NO); | 156 | msg_size, GNUNET_NO); |
162 | return ret; | 157 | return ret; |
163 | } | 158 | } |
164 | 159 | ||
165 | if (do_forward != GNUNET_YES) | 160 | if (do_forward != GNUNET_YES) |
166 | return ret; | 161 | return ret; |
167 | im = (struct InboundMessage*) buf; | 162 | im = (struct InboundMessage *) buf; |
168 | im->header.size = htons (size); | 163 | im->header.size = htons (size); |
169 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | 164 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); |
170 | im->ats_count = htonl (ats_count); | 165 | im->ats_count = htonl (ats_count); |
171 | im->peer = *peer; | 166 | im->peer = *peer; |
172 | ap = (struct GNUNET_ATS_Information*) &im[1]; | 167 | ap = (struct GNUNET_ATS_Information *) &im[1]; |
173 | memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 168 | memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); |
174 | memcpy (&ap[ats_count], message, ntohs (message->size)); | 169 | memcpy (&ap[ats_count], message, ntohs (message->size)); |
175 | 170 | ||
@@ -213,7 +208,7 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
213 | const char *plugin_name = cls; | 208 | const char *plugin_name = cls; |
214 | struct GNUNET_TIME_Relative ret; | 209 | struct GNUNET_TIME_Relative ret; |
215 | uint16_t type; | 210 | uint16_t type; |
216 | 211 | ||
217 | ret = GNUNET_TIME_UNIT_ZERO; | 212 | ret = GNUNET_TIME_UNIT_ZERO; |
218 | if (NULL == message) | 213 | if (NULL == message) |
219 | goto end; | 214 | goto end; |
@@ -231,43 +226,38 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
231 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | 226 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
232 | #if DEBUG_TRANSPORT | 227 | #if DEBUG_TRANSPORT |
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
234 | "Processing `%s' from `%s'\n", "PING", | 229 | "Processing `%s' from `%s'\n", "PING", |
235 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 230 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, |
236 | sender_address, | 231 | sender_address, |
237 | sender_address_len) | 232 | sender_address_len) |
238 | : "<inbound>"); | 233 | : "<inbound>"); |
239 | #endif | 234 | #endif |
240 | GST_validation_handle_ping (peer, message, plugin_name, session, | 235 | GST_validation_handle_ping (peer, message, plugin_name, session, |
241 | sender_address, sender_address_len); | 236 | sender_address, sender_address_len); |
242 | break; | 237 | break; |
243 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 238 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
244 | #if DEBUG_TRANSPORT | 239 | #if DEBUG_TRANSPORT |
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
246 | "Processing `%s' from `%s'\n", "PONG", | 241 | "Processing `%s' from `%s'\n", "PONG", |
247 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 242 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, |
248 | sender_address, | 243 | sender_address, |
249 | sender_address_len) | 244 | sender_address_len) |
250 | : "<inbound>"); | 245 | : "<inbound>"); |
251 | #endif | 246 | #endif |
252 | GST_validation_handle_pong (peer, message); | 247 | GST_validation_handle_pong (peer, message); |
253 | break; | 248 | break; |
254 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: | 249 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: |
255 | GST_neighbours_handle_connect (message, | 250 | GST_neighbours_handle_connect (message, peer, plugin_name, sender_address, |
256 | peer, | 251 | sender_address_len, session, ats, ats_count); |
257 | plugin_name, sender_address, sender_address_len, | ||
258 | session, ats, ats_count); | ||
259 | break; | 252 | break; |
260 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: | 253 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: |
261 | GST_neighbours_handle_connect_ack (message, | 254 | GST_neighbours_handle_connect_ack (message, peer, plugin_name, |
262 | peer, | 255 | sender_address, sender_address_len, |
263 | plugin_name, sender_address, sender_address_len, | 256 | session, ats, ats_count); |
264 | session, ats, ats_count); | ||
265 | break; | 257 | break; |
266 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | 258 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: |
267 | GST_neighbours_handle_ack (message, | 259 | GST_neighbours_handle_ack (message, peer, plugin_name, sender_address, |
268 | peer, | 260 | sender_address_len, session, ats, ats_count); |
269 | plugin_name, sender_address, sender_address_len, | ||
270 | session, ats, ats_count); | ||
271 | break; | 261 | break; |
272 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 262 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
273 | GST_neighbours_handle_disconnect_message (peer, message); | 263 | GST_neighbours_handle_disconnect_message (peer, message); |
@@ -277,25 +267,20 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
277 | break; | 267 | break; |
278 | default: | 268 | default: |
279 | /* should be payload */ | 269 | /* should be payload */ |
280 | ret = process_payload (peer, | 270 | ret = process_payload (peer, message, ats, ats_count); |
281 | message, | ||
282 | ats, ats_count); | ||
283 | break; | 271 | break; |
284 | } | 272 | } |
285 | end: | 273 | end: |
286 | #if 1 | 274 | #if 1 |
287 | /* FIXME: this should not be needed, and not sure it's good to have it, but without | 275 | /* FIXME: this should not be needed, and not sure it's good to have it, but without |
288 | this connections seem to go extra-slow */ | 276 | * this connections seem to go extra-slow */ |
289 | GNUNET_ATS_address_update (GST_ats, peer, | 277 | GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, |
290 | plugin_name, sender_address, sender_address_len, | 278 | sender_address_len, session, ats, ats_count); |
291 | session, | ||
292 | ats, ats_count); | ||
293 | #endif | 279 | #endif |
294 | #if DEBUG_TRANSPORT | 280 | #if DEBUG_TRANSPORT |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Allowing receive from peer %s to continue in %llu ms\n", | 282 | "Allowing receive from peer %s to continue in %llu ms\n", |
297 | GNUNET_i2s (peer), | 283 | GNUNET_i2s (peer), (unsigned long long) ret.rel_value); |
298 | (unsigned long long) ret.rel_value); | ||
299 | #endif | 284 | #endif |
300 | return ret; | 285 | return ret; |
301 | } | 286 | } |
@@ -340,16 +325,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
340 | struct Session *session) | 325 | struct Session *session) |
341 | { | 326 | { |
342 | #if DEBUG_TRANSPORT | 327 | #if DEBUG_TRANSPORT |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", |
344 | "Session %X to peer `%s' ended \n", | ||
345 | session, GNUNET_i2s (peer)); | 329 | session, GNUNET_i2s (peer)); |
346 | #endif | 330 | #endif |
347 | if (NULL != session) | 331 | if (NULL != session) |
348 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 332 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
349 | "transport-ats", | 333 | "transport-ats", |
350 | "Telling ATS to destroy session %p from peer %s\n", | 334 | "Telling ATS to destroy session %p from peer %s\n", |
351 | session, | 335 | session, GNUNET_i2s (peer)); |
352 | GNUNET_i2s (peer)); | ||
353 | GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); | 336 | GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); |
354 | GST_neighbours_session_terminated (peer, session); | 337 | GST_neighbours_session_terminated (peer, session); |
355 | } | 338 | } |
@@ -373,32 +356,32 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
373 | */ | 356 | */ |
374 | static void | 357 | static void |
375 | ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | 358 | ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, |
376 | const char *plugin_name, | 359 | const char *plugin_name, const void *plugin_addr, |
377 | const void *plugin_addr, size_t plugin_addr_len, | 360 | size_t plugin_addr_len, struct Session *session, |
378 | struct Session *session, | ||
379 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 361 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
380 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 362 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
381 | const struct GNUNET_ATS_Information * ats, | 363 | const struct GNUNET_ATS_Information *ats, |
382 | uint32_t ats_count) | 364 | uint32_t ats_count) |
383 | { | 365 | { |
384 | uint32_t bw_in = ntohl (bandwidth_in.value__); | 366 | uint32_t bw_in = ntohl (bandwidth_in.value__); |
385 | uint32_t bw_out = ntohl (bandwidth_out.value__); | 367 | uint32_t bw_out = ntohl (bandwidth_out.value__); |
386 | 368 | ||
387 | /* ATS tells me to disconnect from peer*/ | 369 | /* ATS tells me to disconnect from peer */ |
388 | if ((bw_in == 0) && (bw_out == 0)) | 370 | if ((bw_in == 0) && (bw_out == 0)) |
389 | { | 371 | { |
390 | #if DEBUG_TRANSPORT | 372 | #if DEBUG_TRANSPORT |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
392 | "ATS tells me to disconnect from peer `%s'\n", | 374 | "ATS tells me to disconnect from peer `%s'\n", |
393 | GNUNET_i2s (peer)); | 375 | GNUNET_i2s (peer)); |
394 | #endif | 376 | #endif |
395 | GST_neighbours_force_disconnect(peer); | 377 | GST_neighbours_force_disconnect (peer); |
396 | return; | 378 | return; |
397 | } | 379 | } |
398 | /* will never return GNUNET_YES since connection is to be established */ | 380 | /* will never return GNUNET_YES since connection is to be established */ |
399 | GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, | 381 | GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, |
400 | plugin_addr_len, session, ats, ats_count, | 382 | plugin_addr_len, session, ats, |
401 | bandwidth_in, bandwidth_out); | 383 | ats_count, bandwidth_in, |
384 | bandwidth_out); | ||
402 | } | 385 | } |
403 | 386 | ||
404 | 387 | ||
@@ -414,10 +397,11 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
414 | static void | 397 | static void |
415 | neighbours_connect_notification (void *cls, | 398 | neighbours_connect_notification (void *cls, |
416 | const struct GNUNET_PeerIdentity *peer, | 399 | const struct GNUNET_PeerIdentity *peer, |
417 | const struct GNUNET_ATS_Information | 400 | const struct GNUNET_ATS_Information *ats, |
418 | *ats, uint32_t ats_count) | 401 | uint32_t ats_count) |
419 | { | 402 | { |
420 | size_t len = sizeof (struct ConnectInfoMessage) + | 403 | size_t len = |
404 | sizeof (struct ConnectInfoMessage) + | ||
421 | ats_count * sizeof (struct GNUNET_ATS_Information); | 405 | ats_count * sizeof (struct GNUNET_ATS_Information); |
422 | char buf[len]; | 406 | char buf[len]; |
423 | struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; | 407 | struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; |
@@ -428,8 +412,7 @@ neighbours_connect_notification (void *cls, | |||
428 | connect_msg->ats_count = htonl (ats_count); | 412 | connect_msg->ats_count = htonl (ats_count); |
429 | connect_msg->id = *peer; | 413 | connect_msg->id = *peer; |
430 | ap = (struct GNUNET_ATS_Information *) &connect_msg[1]; | 414 | ap = (struct GNUNET_ATS_Information *) &connect_msg[1]; |
431 | memcpy (ap, ats, | 415 | memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); |
432 | ats_count * sizeof (struct GNUNET_ATS_Information)); | ||
433 | GST_clients_broadcast (&connect_msg->header, GNUNET_NO); | 416 | GST_clients_broadcast (&connect_msg->header, GNUNET_NO); |
434 | } | 417 | } |
435 | 418 | ||
@@ -548,7 +531,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
548 | GST_plugins_load (&plugin_env_receive_callback, | 531 | GST_plugins_load (&plugin_env_receive_callback, |
549 | &plugin_env_address_change_notification, | 532 | &plugin_env_address_change_notification, |
550 | &plugin_env_session_end); | 533 | &plugin_env_session_end); |
551 | GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 534 | GST_ats = |
535 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | ||
552 | GST_neighbours_start (NULL, &neighbours_connect_notification, | 536 | GST_neighbours_start (NULL, &neighbours_connect_notification, |
553 | &neighbours_disconnect_notification); | 537 | &neighbours_disconnect_notification); |
554 | GST_clients_start (server); | 538 | GST_clients_start (server); |