diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/Makefile.am | 14 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 1258 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 11 | ||||
-rw-r--r-- | src/transport/test_transport_api_wlan_peer1.conf | 3 | ||||
-rw-r--r-- | src/transport/test_transport_api_wlan_peer2.conf | 3 |
5 files changed, 821 insertions, 468 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index db528d80c..339e58bed 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -34,11 +34,12 @@ endif | |||
34 | 34 | ||
35 | if HAVE_PCAP | 35 | if HAVE_PCAP |
36 | if LINUX | 36 | if LINUX |
37 | if HAVE_EXPERIMENTAL | 37 | #if HAVE_EXPERIMENTAL |
38 | WANBIN = gnunet-transport-wlan-helper | 38 | WANBIN = gnunet-transport-wlan-helper |
39 | WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la | 39 | WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la |
40 | WLAN_API_TEST = test_transport_api_wlan | 40 | WLAN_API_TEST = test_transport_api_wlan |
41 | endif | 41 | WLAN_REL_TEST = test_transport_api_reliability_wlan |
42 | #endif | ||
42 | endif | 43 | endif |
43 | endif | 44 | endif |
44 | 45 | ||
@@ -212,6 +213,7 @@ check_PROGRAMS = \ | |||
212 | $(HTTPS_PLUGIN_TEST) \ | 213 | $(HTTPS_PLUGIN_TEST) \ |
213 | $(HTTPS_API_TEST) \ | 214 | $(HTTPS_API_TEST) \ |
214 | $(WLAN_API_TEST) \ | 215 | $(WLAN_API_TEST) \ |
216 | $(WLAN_REL_TEST) \ | ||
215 | test_transport_api_multi \ | 217 | test_transport_api_multi \ |
216 | test_transport_api_reliability_tcp \ | 218 | test_transport_api_reliability_tcp \ |
217 | test_transport_api_reliability_tcp_nat \ | 219 | test_transport_api_reliability_tcp_nat \ |
@@ -285,6 +287,14 @@ test_transport_api_reliability_tcp_nat_LDADD = \ | |||
285 | $(top_builddir)/src/hello/libgnunethello.la \ | 287 | $(top_builddir)/src/hello/libgnunethello.la \ |
286 | $(top_builddir)/src/util/libgnunetutil.la | 288 | $(top_builddir)/src/util/libgnunetutil.la |
287 | 289 | ||
290 | test_transport_api_reliability_wlan_SOURCES = \ | ||
291 | test_transport_api_reliability.c | ||
292 | test_transport_api_reliability_wlan_LDADD = \ | ||
293 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
294 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
295 | $(top_builddir)/src/util/libgnunetutil.la | ||
296 | |||
297 | |||
288 | test_transport_api_udp_SOURCES = \ | 298 | test_transport_api_udp_SOURCES = \ |
289 | test_transport_api.c | 299 | test_transport_api.c |
290 | test_transport_api_udp_LDADD = \ | 300 | test_transport_api_udp_LDADD = \ |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index f184ff47a..4f6b514f3 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -48,13 +48,19 @@ | |||
48 | #define FRAGMENT_TIMEOUT GNUNET_TIME_UNIT_SECONDS | 48 | #define FRAGMENT_TIMEOUT GNUNET_TIME_UNIT_SECONDS |
49 | 49 | ||
50 | #define FRAGMENT_QUEUE_SIZE 10 | 50 | #define FRAGMENT_QUEUE_SIZE 10 |
51 | #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION 1 | ||
52 | |||
53 | #define MESSAGE_IN_TIMEOUT GNUNET_TIME_UNIT_SECONDS | ||
54 | |||
55 | #define MESSAGES_IN_QUEUE_SIZE 10 | ||
56 | #define MESSAGES_IN_QUEUE_PER_SESSION 1 | ||
51 | 57 | ||
52 | #define HALLO_BEACON_SCALING_FACTOR 900 | 58 | #define HALLO_BEACON_SCALING_FACTOR 900 |
53 | 59 | ||
54 | #define DEBUG_wlan GNUNET_NO | 60 | #define DEBUG_wlan GNUNET_YES |
55 | 61 | ||
56 | #define MESSAGE_LENGHT_UNKNOWN -1 | 62 | #define MESSAGE_LENGHT_UNKNOWN -1 |
57 | #define NO_MESSAGE_OR_MESSAGE_FINISHED -2 | 63 | //#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 |
58 | 64 | ||
59 | /** | 65 | /** |
60 | * After how long do we expire an address that we | 66 | * After how long do we expire an address that we |
@@ -204,21 +210,46 @@ struct Plugin | |||
204 | unsigned int pending_fragment_messages; | 210 | unsigned int pending_fragment_messages; |
205 | 211 | ||
206 | /** | 212 | /** |
213 | * Messages in the in Queue, head | ||
214 | */ | ||
215 | |||
216 | struct Receive_Message_Queue * receive_messages_head; | ||
217 | |||
218 | /** | ||
219 | * Messages in the in Queue, tail | ||
220 | */ | ||
221 | |||
222 | struct Receive_Message_Queue * receive_messages_teil; | ||
223 | |||
224 | /** | ||
225 | * number of messages in the in queue | ||
226 | */ | ||
227 | |||
228 | unsigned int pending_receive_messages; | ||
229 | |||
230 | /** | ||
207 | * time of the next "hello-beacon" | 231 | * time of the next "hello-beacon" |
208 | */ | 232 | */ |
209 | 233 | ||
210 | struct GNUNET_TIME_Absolute beacon_time; | 234 | struct GNUNET_TIME_Absolute beacon_time; |
211 | 235 | ||
212 | /** | 236 | /** |
213 | * queue to send acks for received fragments | 237 | * queue to send acks for received fragments (head) |
214 | */ | 238 | */ |
215 | 239 | ||
216 | struct AckSendQueue * ack_send_queue_head; | 240 | struct AckSendQueue * ack_send_queue_head; |
217 | 241 | ||
242 | /** | ||
243 | * queue to send acks for received fragments (tail) | ||
244 | */ | ||
245 | |||
218 | struct AckSendQueue * ack_send_queue_tail; | 246 | struct AckSendQueue * ack_send_queue_tail; |
219 | 247 | ||
220 | }; | 248 | }; |
221 | 249 | ||
250 | /** | ||
251 | * Struct to store data if file write did not accept the whole packet | ||
252 | */ | ||
222 | struct Finish_send | 253 | struct Finish_send |
223 | { | 254 | { |
224 | struct Plugin * plugin; | 255 | struct Plugin * plugin; |
@@ -239,27 +270,69 @@ struct Sessionqueue | |||
239 | }; | 270 | }; |
240 | 271 | ||
241 | /** | 272 | /** |
242 | * Queue of ack received for messages send | 273 | * Queue for the fragments received |
243 | */ | 274 | */ |
244 | 275 | ||
245 | struct AckQueue | 276 | struct Receive_Fragment_Queue |
246 | { | 277 | { |
247 | struct AckQueue * next; | 278 | struct Receive_Fragment_Queue * next; |
248 | struct AckQueue * prev; | 279 | struct Receive_Fragment_Queue * prev; |
249 | int fragment_num; //TODO change it to offset if better | 280 | uint16_t num; |
281 | const char * msg; | ||
282 | uint16_t size; | ||
250 | }; | 283 | }; |
251 | 284 | ||
252 | /** | 285 | /** |
253 | * Queue for the fragments received | 286 | * Queue for the fragments received |
254 | */ | 287 | */ |
255 | 288 | ||
256 | struct RecQueue | 289 | struct Receive_Message_Queue |
257 | { | 290 | { |
258 | struct RecQueue * next; | 291 | struct Receive_Message_Queue * next; |
259 | struct RecQueue * prev; | 292 | |
260 | uint16_t num; | 293 | struct Receive_Message_Queue * prev; |
261 | const char * msg; | 294 | |
262 | uint16_t size; | 295 | /** |
296 | * current number for message incoming, to distinguish between the messages | ||
297 | */ | ||
298 | uint32_t message_id_in; | ||
299 | |||
300 | /** | ||
301 | * size of the message received, | ||
302 | * MESSAGE_LENGHT_UNKNOWN means that the size is not known, | ||
303 | * NO_MESSAGE_OR_MESSAGE_FINISHED means no message received | ||
304 | */ | ||
305 | |||
306 | int rec_size; | ||
307 | |||
308 | /** | ||
309 | * Sorted queue with the fragments received; head | ||
310 | */ | ||
311 | |||
312 | struct Receive_Fragment_Queue * frag_head; | ||
313 | |||
314 | /** | ||
315 | * Sorted queue with the fragments received; tail | ||
316 | */ | ||
317 | |||
318 | struct Receive_Fragment_Queue * frag_tail; | ||
319 | |||
320 | /** | ||
321 | * Session this fragment belongs to | ||
322 | */ | ||
323 | |||
324 | struct Session * session; | ||
325 | |||
326 | /** | ||
327 | * Timeout value for the pending message. | ||
328 | */ | ||
329 | struct GNUNET_TIME_Absolute timeout; | ||
330 | |||
331 | /** | ||
332 | * Bitfield of received fragments | ||
333 | */ | ||
334 | |||
335 | uint64_t received_fragments; | ||
263 | }; | 336 | }; |
264 | 337 | ||
265 | /** | 338 | /** |
@@ -312,12 +385,12 @@ struct AckSendQueue | |||
312 | /** | 385 | /** |
313 | * ID of message, to distinguish between the messages, picked randomly. | 386 | * ID of message, to distinguish between the messages, picked randomly. |
314 | */ | 387 | */ |
315 | uint32_t message_id GNUNET_PACKED; | 388 | uint32_t message_id; |
316 | 389 | ||
317 | /** | 390 | /** |
318 | * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD) | 391 | * Bit field for received fragments |
319 | */ | 392 | */ |
320 | uint16_t fragment_off_or_num GNUNET_PACKED; | 393 | uint64_t fragments_field; |
321 | 394 | ||
322 | }; | 395 | }; |
323 | 396 | ||
@@ -360,41 +433,16 @@ struct Session | |||
360 | struct PendingMessage *pending_message; | 433 | struct PendingMessage *pending_message; |
361 | 434 | ||
362 | /** | 435 | /** |
363 | * To whom are we talking to (set to our identity | 436 | * Message currently pending for transmission |
364 | * if we are still waiting for the welcome message) | 437 | * to this peer, if any. |
365 | */ | ||
366 | struct GNUNET_PeerIdentity target; | ||
367 | |||
368 | /** | ||
369 | * encapsulation of the receive data | ||
370 | */ | ||
371 | //struct GNUNET_SERVER_MessageStreamTokenizer * receive_token; | ||
372 | |||
373 | /** | ||
374 | * offset of the next fragment for the receive_token, -1 means last message finished | ||
375 | */ | ||
376 | |||
377 | //int rec_offset; | ||
378 | |||
379 | /** | ||
380 | * size of the message received, | ||
381 | * MESSAGE_LENGHT_UNKNOWN means that the size is not known, | ||
382 | * NO_MESSAGE_OR_MESSAGE_FINISHED means no message received | ||
383 | */ | ||
384 | |||
385 | int rec_size; | ||
386 | |||
387 | /** | ||
388 | * Sorted queue with the fragments received; head | ||
389 | */ | 438 | */ |
390 | 439 | struct PendingMessage *pending_message2; | |
391 | struct RecQueue * frag_head; | ||
392 | 440 | ||
393 | /** | 441 | /** |
394 | * Sorted queue with the fragments received; tail | 442 | * To whom are we talking to (set to our identity |
443 | * if we are still waiting for the welcome message) | ||
395 | */ | 444 | */ |
396 | 445 | struct GNUNET_PeerIdentity target; | |
397 | struct RecQueue * frag_tail; | ||
398 | 446 | ||
399 | /** | 447 | /** |
400 | * peer mac address | 448 | * peer mac address |
@@ -414,20 +462,16 @@ struct Session | |||
414 | struct GNUNET_TIME_Absolute last_activity; | 462 | struct GNUNET_TIME_Absolute last_activity; |
415 | 463 | ||
416 | /** | 464 | /** |
417 | * current number for message incoming, to distinguish between the messages | 465 | * count of messages in the fragment out queue for this session |
418 | */ | 466 | */ |
419 | uint32_t message_id_in; | ||
420 | 467 | ||
421 | /** | 468 | int fragment_messages_out_count; |
422 | * current number for message outgoing, to distinguish between the messages | ||
423 | */ | ||
424 | uint32_t message_id_out; | ||
425 | 469 | ||
426 | /** | 470 | /** |
427 | * does this session have a message in the fragment queue | 471 | * count of messages in the fragment in queue for this session |
428 | */ | 472 | */ |
429 | 473 | ||
430 | int has_fragment; | 474 | int fragment_messages_in_count; |
431 | 475 | ||
432 | }; | 476 | }; |
433 | 477 | ||
@@ -470,16 +514,9 @@ struct FragmentMessage | |||
470 | struct GNUNET_TIME_Absolute next_ack; | 514 | struct GNUNET_TIME_Absolute next_ack; |
471 | 515 | ||
472 | /** | 516 | /** |
473 | * Sorted queue with the acks received for fragments; head | 517 | * bitfield with all acks received for this message |
474 | */ | ||
475 | |||
476 | struct AckQueue * head; | ||
477 | |||
478 | /** | ||
479 | * Sorted queue with the acks received for fragments; tail | ||
480 | */ | 518 | */ |
481 | 519 | uint64_t ack_bitfield; | |
482 | struct AckQueue * tail; | ||
483 | 520 | ||
484 | /** | 521 | /** |
485 | * Size of the message | 522 | * Size of the message |
@@ -492,6 +529,10 @@ struct FragmentMessage | |||
492 | */ | 529 | */ |
493 | uint32_t message_pos; | 530 | uint32_t message_pos; |
494 | 531 | ||
532 | /** | ||
533 | * current number for message outgoing, to distinguish between the messages | ||
534 | */ | ||
535 | uint32_t message_id_out; | ||
495 | }; | 536 | }; |
496 | 537 | ||
497 | /** | 538 | /** |
@@ -526,12 +567,6 @@ struct FragmentationHeader | |||
526 | struct GNUNET_MessageHeader header; | 567 | struct GNUNET_MessageHeader header; |
527 | 568 | ||
528 | /** | 569 | /** |
529 | * To whom are we talking to (set to our identity | ||
530 | * if we are still waiting for the welcome message) | ||
531 | */ | ||
532 | // struct GNUNET_PeerIdentity target GNUNET_PACKED; | ||
533 | |||
534 | /** | ||
535 | * ID of message, to distinguish between the messages, picked randomly. | 570 | * ID of message, to distinguish between the messages, picked randomly. |
536 | */ | 571 | */ |
537 | uint32_t message_id GNUNET_PACKED; | 572 | uint32_t message_id GNUNET_PACKED; |
@@ -546,21 +581,27 @@ struct FragmentationHeader | |||
546 | */ | 581 | */ |
547 | uint16_t message_crc GNUNET_PACKED; | 582 | uint16_t message_crc GNUNET_PACKED; |
548 | 583 | ||
549 | /** | 584 | // followed by payload |
550 | * Flags | 585 | |
551 | * // 0x1 ack => Use two different message types in header.type! (FRAG_MESSAGE; FRAG_ACK) | 586 | }; |
552 | * // 0x2 has data (not only ack) | ||
553 | * // 0x4 last fragment of message | ||
554 | * // 0x8 new message | ||
555 | */ | ||
556 | // uint32_t flags GNUNET_PACKED; | ||
557 | 587 | ||
558 | /** | 588 | /** |
559 | * checksum/error correction | 589 | * Header for messages which need fragmentation |
560 | */ | 590 | */ |
561 | // uint32_t crc GNUNET_PACKED; | 591 | struct FragmentationAckHeader |
592 | { | ||
562 | 593 | ||
563 | // followed by payload unless ACK | 594 | struct GNUNET_MessageHeader header; |
595 | |||
596 | /** | ||
597 | * ID of message, to distinguish between the messages, picked randomly. | ||
598 | */ | ||
599 | uint32_t message_id GNUNET_PACKED; | ||
600 | |||
601 | /** | ||
602 | * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD) | ||
603 | */ | ||
604 | uint64_t fragment_field GNUNET_PACKED; | ||
564 | 605 | ||
565 | }; | 606 | }; |
566 | 607 | ||
@@ -568,7 +609,7 @@ int | |||
568 | getRadiotapHeader(struct RadiotapHeader * Header); | 609 | getRadiotapHeader(struct RadiotapHeader * Header); |
569 | 610 | ||
570 | int | 611 | int |
571 | getWlanHeader(struct IeeeHeader * Header,const char * to_mac_addr, | 612 | getWlanHeader(struct IeeeHeader * Header, const char * to_mac_addr, |
572 | struct Plugin * plugin); | 613 | struct Plugin * plugin); |
573 | 614 | ||
574 | static int | 615 | static int |
@@ -587,7 +628,12 @@ uint32_t | |||
587 | getcrc32(const char *msgbuf, size_t msgbuf_size); | 628 | getcrc32(const char *msgbuf, size_t msgbuf_size); |
588 | 629 | ||
589 | static void | 630 | static void |
590 | free_rec_frag_queue(struct Session * session); | 631 | free_receive_message(struct Plugin* plugin, |
632 | struct Receive_Message_Queue * rec_message); | ||
633 | |||
634 | struct Receive_Message_Queue * | ||
635 | get_receive_message_from_session(struct Plugin * plugin, | ||
636 | struct Session * session); | ||
591 | 637 | ||
592 | static void | 638 | static void |
593 | wlan_data_helper(void *cls, struct Session_light * session_light, | 639 | wlan_data_helper(void *cls, struct Session_light * session_light, |
@@ -608,6 +654,129 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
608 | static const char * | 654 | static const char * |
609 | wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen); | 655 | wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen); |
610 | 656 | ||
657 | struct Receive_Message_Queue * | ||
658 | get_receive_message(struct Plugin * plugin, struct Session * session, | ||
659 | uint32_t message_id); | ||
660 | |||
661 | static uint64_t | ||
662 | htonll(uint64_t input) | ||
663 | { | ||
664 | return input; | ||
665 | } | ||
666 | |||
667 | static uint64_t | ||
668 | ntohll(uint64_t input) | ||
669 | { | ||
670 | return input; | ||
671 | } | ||
672 | |||
673 | /** | ||
674 | * Sets a bit active in the bitArray. Increment bit-specific | ||
675 | * usage counter on disk only if below 4bit max (==15). | ||
676 | * | ||
677 | * @param bitArray memory area to set the bit in | ||
678 | * @param bitIdx which bit to set | ||
679 | */ | ||
680 | static void | ||
681 | setBit(char *bitArray, unsigned int bitIdx) | ||
682 | { | ||
683 | size_t arraySlot; | ||
684 | unsigned int targetBit; | ||
685 | |||
686 | arraySlot = bitIdx / 8; | ||
687 | targetBit = (1L << (bitIdx % 8)); | ||
688 | bitArray[arraySlot] |= targetBit; | ||
689 | } | ||
690 | |||
691 | /** | ||
692 | * Clears a bit from bitArray. Bit is cleared from the array | ||
693 | * only if the respective usage counter on the disk hits/is zero. | ||
694 | * | ||
695 | * @param bitArray memory area to set the bit in | ||
696 | * @param bitIdx which bit to unset | ||
697 | */ | ||
698 | /*static void | ||
699 | clearBit(char *bitArray, unsigned int bitIdx) | ||
700 | { | ||
701 | size_t slot; | ||
702 | unsigned int targetBit; | ||
703 | |||
704 | slot = bitIdx / 8; | ||
705 | targetBit = (1L << (bitIdx % 8)); | ||
706 | bitArray[slot] = bitArray[slot] & (~targetBit); | ||
707 | }*/ | ||
708 | |||
709 | /** | ||
710 | * Checks if a bit is active in the bitArray | ||
711 | * | ||
712 | * @param bitArray memory area to set the bit in | ||
713 | * @param bitIdx which bit to test | ||
714 | * @return GNUNET_YES if the bit is set, GNUNET_NO if not. | ||
715 | */ | ||
716 | static int | ||
717 | testBit(char *bitArray, unsigned int bitIdx) | ||
718 | { | ||
719 | size_t slot; | ||
720 | unsigned int targetBit; | ||
721 | |||
722 | slot = bitIdx / 8; | ||
723 | targetBit = (1L << (bitIdx % 8)); | ||
724 | if (bitArray[slot] & targetBit) | ||
725 | return GNUNET_YES; | ||
726 | else | ||
727 | return GNUNET_NO; | ||
728 | } | ||
729 | |||
730 | /** | ||
731 | * Sets a bit active in the bitArray. | ||
732 | * | ||
733 | * @param bitArray memory area to set the bit in | ||
734 | * @param bitIdx which bit to set | ||
735 | */ | ||
736 | /*static uint64_t | ||
737 | setBit (uint64_t bitArray, unsigned int bitIdx) | ||
738 | { | ||
739 | uint64_t targetBit; | ||
740 | |||
741 | targetBit = (1ULL << bitIdx); | ||
742 | return bitArray | targetBit; | ||
743 | } | ||
744 | */ | ||
745 | /** | ||
746 | * Clears a bit from bitArray. | ||
747 | * | ||
748 | * @param bitArray memory area to set the bit in | ||
749 | * @param bitIdx which bit to unset | ||
750 | */ | ||
751 | /*static uint64_t | ||
752 | clearBit (uint64_t bitArray, unsigned int bitIdx) | ||
753 | { | ||
754 | uint64_t targetBit; | ||
755 | |||
756 | targetBit = (1ULL << bitIdx); | ||
757 | return bitArray & (~targetBit); | ||
758 | } | ||
759 | */ | ||
760 | /** | ||
761 | * Checks if a bit is active in the bitArray | ||
762 | * | ||
763 | * @param bitArray memory area to set the bit in | ||
764 | * @param bitIdx which bit to test | ||
765 | * @return GNUNET_YES if the bit is set, GNUNET_NO if not. | ||
766 | */ | ||
767 | /*static int | ||
768 | testBit (uint64_t bitArray, unsigned int bitIdx) | ||
769 | { | ||
770 | uint64_t targetBit; | ||
771 | |||
772 | |||
773 | targetBit = (1ULL << bitIdx); | ||
774 | if (bitArray & targetBit) | ||
775 | return GNUNET_YES; | ||
776 | else | ||
777 | return GNUNET_NO; | ||
778 | } | ||
779 | */ | ||
611 | /** | 780 | /** |
612 | * get the next message number, at the moment just a random one | 781 | * get the next message number, at the moment just a random one |
613 | * @return returns the next valid message-number for sending packets | 782 | * @return returns the next valid message-number for sending packets |
@@ -678,15 +847,14 @@ create_session(struct Plugin *plugin, const uint8_t * addr) | |||
678 | queue->content = GNUNET_malloc (sizeof (struct Session)); | 847 | queue->content = GNUNET_malloc (sizeof (struct Session)); |
679 | queue->content->plugin = plugin; | 848 | queue->content->plugin = plugin; |
680 | memcpy(queue->content->addr, addr, 6); | 849 | memcpy(queue->content->addr, addr, 6); |
681 | queue->content->message_id_out = get_next_message_id(); | 850 | queue->content->fragment_messages_out_count = 0; |
682 | queue->content->has_fragment = 0; | 851 | queue->content->fragment_messages_in_count = 0; |
683 | queue->content->rec_size = NO_MESSAGE_OR_MESSAGE_FINISHED; | ||
684 | 852 | ||
685 | plugin->session_count++; | 853 | plugin->session_count++; |
686 | 854 | ||
687 | #if DEBUG_wlan | 855 | #if DEBUG_wlan |
688 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 856 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New session %p with %s\n", |
689 | "New session %p with %s\n", queue->content ,wlan_plugin_address_to_string(NULL,addr, 6)); | 857 | queue->content, wlan_plugin_address_to_string(NULL, addr, 6)); |
690 | #endif | 858 | #endif |
691 | 859 | ||
692 | return queue->content; | 860 | return queue->content; |
@@ -769,22 +937,6 @@ queue_Session(struct Plugin *plugin, struct Session * session) | |||
769 | } | 937 | } |
770 | 938 | ||
771 | //TODO doxigen | 939 | //TODO doxigen |
772 | static void | ||
773 | free_acks(struct FragmentMessage * fm) | ||
774 | { | ||
775 | struct AckQueue * fq; | ||
776 | while (fm->head != NULL) | ||
777 | { | ||
778 | fq = fm->head; | ||
779 | GNUNET_CONTAINER_DLL_remove(fm->head, fm->tail, fq); | ||
780 | GNUNET_free(fq); | ||
781 | } | ||
782 | //needed? | ||
783 | fm->head = NULL; | ||
784 | fm->tail = NULL; | ||
785 | } | ||
786 | |||
787 | //TODO doxigen | ||
788 | /** | 940 | /** |
789 | * Function to schedule the write task, executed after a delay | 941 | * Function to schedule the write task, executed after a delay |
790 | */ | 942 | */ |
@@ -908,13 +1060,22 @@ get_next_queue_Session(struct Plugin * plugin) | |||
908 | while (sessionqueue != NULL) | 1060 | while (sessionqueue != NULL) |
909 | { | 1061 | { |
910 | session = sessionqueue->content; | 1062 | session = sessionqueue->content; |
1063 | |||
911 | pm = session->pending_message; | 1064 | pm = session->pending_message; |
1065 | if (pm == NULL){ | ||
1066 | #if DEBUG_wlan | ||
1067 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1068 | "pending message is empty, should not happen. session %p\n", session); | ||
1069 | #endif | ||
1070 | } | ||
1071 | GNUNET_assert(pm != NULL); | ||
912 | 1072 | ||
913 | //check for message timeout | 1073 | //check for message timeout |
914 | if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0) | 1074 | if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0) |
915 | { | 1075 | { |
916 | //check if session has no message in the fragment queue | 1076 | //check if session has no message in the fragment queue |
917 | if (!session->has_fragment) | 1077 | if (session->fragment_messages_out_count |
1078 | < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION) | ||
918 | { | 1079 | { |
919 | plugin->pendingsessions--; | 1080 | plugin->pendingsessions--; |
920 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | 1081 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, |
@@ -931,7 +1092,9 @@ get_next_queue_Session(struct Plugin * plugin) | |||
931 | else | 1092 | else |
932 | { | 1093 | { |
933 | 1094 | ||
934 | session->pending_message = NULL; | 1095 | session->pending_message = session->pending_message2; |
1096 | session->pending_message2 = NULL; | ||
1097 | |||
935 | //call the cont func that it did not work | 1098 | //call the cont func that it did not work |
936 | if (pm->transmit_cont != NULL) | 1099 | if (pm->transmit_cont != NULL) |
937 | pm->transmit_cont(pm->transmit_cont_cls, &(session->target), | 1100 | pm->transmit_cont(pm->transmit_cont_cls, &(session->target), |
@@ -939,13 +1102,16 @@ get_next_queue_Session(struct Plugin * plugin) | |||
939 | GNUNET_free(pm->msg); | 1102 | GNUNET_free(pm->msg); |
940 | GNUNET_free(pm); | 1103 | GNUNET_free(pm); |
941 | 1104 | ||
942 | sessionqueue_alt = sessionqueue; | 1105 | if (session->pending_message == NULL) |
943 | sessionqueue = sessionqueue->next; | 1106 | { |
944 | plugin->pendingsessions--; | 1107 | sessionqueue_alt = sessionqueue; |
945 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | 1108 | sessionqueue = sessionqueue->next; |
946 | plugin->pending_Sessions_tail, sessionqueue_alt); | 1109 | plugin->pendingsessions--; |
1110 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, | ||
1111 | plugin->pending_Sessions_tail, sessionqueue_alt); | ||
947 | 1112 | ||
948 | GNUNET_free(sessionqueue_alt); | 1113 | GNUNET_free(sessionqueue_alt); |
1114 | } | ||
949 | 1115 | ||
950 | } | 1116 | } |
951 | 1117 | ||
@@ -993,16 +1159,17 @@ free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) | |||
993 | { | 1159 | { |
994 | if (fm != NULL) | 1160 | if (fm != NULL) |
995 | { | 1161 | { |
996 | free_acks(fm); | 1162 | (fm->session->fragment_messages_out_count)--; |
997 | GNUNET_free_non_null(fm->msg); | 1163 | GNUNET_free_non_null(fm->msg); |
998 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, | 1164 | GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, |
999 | plugin->pending_Fragment_Messages_tail, fm); | 1165 | plugin->pending_Fragment_Messages_tail, fm); |
1000 | GNUNET_free(fm); | 1166 | GNUNET_free(fm); |
1001 | plugin->pending_fragment_messages--; | 1167 | plugin->pending_fragment_messages--; |
1002 | check_fragment_queue(plugin); | ||
1003 | 1168 | ||
1004 | #if DEBUG_wlan | 1169 | #if DEBUG_wlan |
1005 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Pending fragment messages: %u\n", plugin->pending_fragment_messages); | 1170 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1171 | "free pending fragment messages, pending messages remaining %u\n", | ||
1172 | plugin->pending_fragment_messages); | ||
1006 | #endif | 1173 | #endif |
1007 | } | 1174 | } |
1008 | } | 1175 | } |
@@ -1029,7 +1196,7 @@ check_fragment_queue(struct Plugin * plugin) | |||
1029 | { | 1196 | { |
1030 | pm = session->pending_message; | 1197 | pm = session->pending_message; |
1031 | session->pending_message = NULL; | 1198 | session->pending_message = NULL; |
1032 | session->has_fragment = 1; | 1199 | session->fragment_messages_out_count++; |
1033 | GNUNET_assert(pm != NULL); | 1200 | GNUNET_assert(pm != NULL); |
1034 | 1201 | ||
1035 | fm = GNUNET_malloc(sizeof(struct FragmentMessage)); | 1202 | fm = GNUNET_malloc(sizeof(struct FragmentMessage)); |
@@ -1039,28 +1206,36 @@ check_fragment_queue(struct Plugin * plugin) | |||
1039 | fm->timeout.abs_value = pm->timeout.abs_value; | 1206 | fm->timeout.abs_value = pm->timeout.abs_value; |
1040 | fm->message_pos = 0; | 1207 | fm->message_pos = 0; |
1041 | fm->next_ack = GNUNET_TIME_absolute_get(); | 1208 | fm->next_ack = GNUNET_TIME_absolute_get(); |
1209 | fm->message_id_out = get_next_message_id(); | ||
1210 | fm->ack_bitfield = 0; | ||
1042 | 1211 | ||
1043 | if (pm->transmit_cont != NULL) { | 1212 | sort_fragment_into_queue(plugin, fm); |
1044 | pid = session->target; | 1213 | plugin->pending_fragment_messages++; |
1045 | pm->transmit_cont(pm->transmit_cont_cls, &pid, | 1214 | |
1046 | GNUNET_OK); | 1215 | if (pm->transmit_cont != NULL) |
1216 | { | ||
1217 | pid = session->target; | ||
1218 | pm->transmit_cont(pm->transmit_cont_cls, &pid, GNUNET_OK); | ||
1047 | #if DEBUG_wlan | 1219 | #if DEBUG_wlan |
1048 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "called pm->transmit_cont for %p\n", session); | 1220 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1221 | "called pm->transmit_cont for %p\n", session); | ||
1049 | #endif | 1222 | #endif |
1050 | } | 1223 | } |
1051 | else | 1224 | else |
1052 | { | 1225 | { |
1053 | #if DEBUG_wlan | 1226 | #if DEBUG_wlan |
1054 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "no pm->transmit_cont for %p\n", session); | 1227 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1228 | "no pm->transmit_cont for %p\n", session); | ||
1055 | #endif | 1229 | #endif |
1056 | } | 1230 | } |
1057 | GNUNET_free(pm); | 1231 | GNUNET_free(pm); |
1058 | 1232 | ||
1059 | sort_fragment_into_queue(plugin, fm); | 1233 | if (session->pending_message2 != NULL){ |
1060 | plugin->pending_fragment_messages++; | 1234 | session->pending_message = session->pending_message2; |
1061 | 1235 | session->pending_message2 = NULL; | |
1062 | //generate new message id | 1236 | //requeue session |
1063 | session->message_id_out = get_next_message_id(); | 1237 | queue_Session(plugin, session); |
1238 | } | ||
1064 | 1239 | ||
1065 | //check if timeout changed | 1240 | //check if timeout changed |
1066 | check_next_fragment_timeout(plugin); | 1241 | check_next_fragment_timeout(plugin); |
@@ -1077,37 +1252,31 @@ check_fragment_queue(struct Plugin * plugin) | |||
1077 | static void | 1252 | static void |
1078 | check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) | 1253 | check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) |
1079 | { | 1254 | { |
1080 | struct AckQueue * ack; | 1255 | //maxack = size of message / max packet size, eg 12 / 5 = 2 start at 0 so ack numbers are 0,1,2 |
1081 | int counter = 0; | 1256 | unsigned int maxack = 63 - ((fm->message_size - 1) / (WLAN_MTU |
1082 | 1257 | - sizeof(struct FragmentationHeader))); | |
1083 | if (fm->message_size >= (WLAN_MTU - sizeof(struct FragmentationHeader)) | 1258 | uint64_t tmpfield = 0xFFFFFFFFFFFFFFFF; |
1084 | * fm->tail->fragment_num) | 1259 | tmpfield = tmpfield >> maxack; |
1260 | |||
1261 | //#if DEBUG_wlan | ||
1262 | if (maxack != 63) | ||
1263 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1264 | "Test bitfields %X and %X, maxack is %u, fm size %u\n", | ||
1265 | fm->ack_bitfield, tmpfield, maxack, fm->message_size); | ||
1266 | //#endif | ||
1267 | |||
1268 | if (fm->ack_bitfield == tmpfield) | ||
1085 | { | 1269 | { |
1086 | ack = fm->head; | 1270 | |
1087 | counter = 0; | ||
1088 | //check if all acks are present | ||
1089 | while (ack != NULL) | ||
1090 | { | ||
1091 | if (counter == ack->fragment_num) | ||
1092 | { | ||
1093 | counter++; | ||
1094 | ack = ack->next; | ||
1095 | } | ||
1096 | else | ||
1097 | { | ||
1098 | //ack is missing | ||
1099 | return; | ||
1100 | } | ||
1101 | } | ||
1102 | fm->session->has_fragment = 0; | ||
1103 | free_fragment_message(plugin, fm); | 1271 | free_fragment_message(plugin, fm); |
1104 | 1272 | ||
1105 | #if DEBUG_wlan | 1273 | #if DEBUG_wlan |
1106 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished a fragmented message\n"); | 1274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1275 | "Finished sending and got all acks for a fragmented message\n"); | ||
1107 | #endif | 1276 | #endif |
1108 | 1277 | ||
1109 | |||
1110 | check_next_fragment_timeout(plugin); | 1278 | check_next_fragment_timeout(plugin); |
1279 | check_fragment_queue(plugin); | ||
1111 | 1280 | ||
1112 | } | 1281 | } |
1113 | } | 1282 | } |
@@ -1120,7 +1289,7 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm) | |||
1120 | void | 1289 | void |
1121 | set_next_message_fragment_pos(struct FragmentMessage * fm) | 1290 | set_next_message_fragment_pos(struct FragmentMessage * fm) |
1122 | { | 1291 | { |
1123 | struct AckQueue * akt = NULL; | 1292 | |
1124 | //check if retransmit is needed | 1293 | //check if retransmit is needed |
1125 | if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0) | 1294 | if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0) |
1126 | { | 1295 | { |
@@ -1132,25 +1301,10 @@ set_next_message_fragment_pos(struct FragmentMessage * fm) | |||
1132 | fm->message_pos = 0; | 1301 | fm->message_pos = 0; |
1133 | } | 1302 | } |
1134 | 1303 | ||
1135 | akt = fm->head; | ||
1136 | //test if ack 0 (or X) was already received | 1304 | //test if ack 0 (or X) was already received |
1137 | while (akt != NULL) | 1305 | while (testBit((char*) &fm->ack_bitfield, fm->message_pos) == GNUNET_YES) |
1138 | { | 1306 | { |
1139 | //if fragment is present, take next | 1307 | fm->message_pos++; |
1140 | if (akt->fragment_num == fm->message_pos) | ||
1141 | { | ||
1142 | fm->message_pos++; | ||
1143 | } | ||
1144 | //next ack is bigger then the fragment number | ||
1145 | //in case there is something like this: (acks) 1, 2, 5, 6, ... | ||
1146 | //and we send 3 again, the next number should be 4 | ||
1147 | else if (akt->fragment_num > fm->message_pos) | ||
1148 | { | ||
1149 | break; | ||
1150 | } | ||
1151 | |||
1152 | akt = akt->next; | ||
1153 | |||
1154 | } | 1308 | } |
1155 | 1309 | ||
1156 | } | 1310 | } |
@@ -1163,48 +1317,48 @@ send_hello_beacon(struct Plugin * plugin) | |||
1163 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello beacon\n"); | 1317 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello beacon\n"); |
1164 | #endif | 1318 | #endif |
1165 | 1319 | ||
1166 | uint16_t size = 0; | 1320 | uint16_t size = 0; |
1167 | ssize_t bytes; | 1321 | ssize_t bytes; |
1168 | struct GNUNET_MessageHeader * msgheader = NULL; | 1322 | struct GNUNET_MessageHeader * msgheader = NULL; |
1169 | struct IeeeHeader * ieeewlanheader = NULL; | 1323 | struct IeeeHeader * ieeewlanheader = NULL; |
1170 | struct RadiotapHeader * radioHeader = NULL; | 1324 | struct RadiotapHeader * radioHeader = NULL; |
1171 | struct GNUNET_MessageHeader * msgheader2 = NULL; | 1325 | struct GNUNET_MessageHeader * msgheader2 = NULL; |
1172 | 1326 | ||
1173 | GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size( | 1327 | GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size( |
1174 | *(plugin->env->our_hello)) <= WLAN_MTU); | 1328 | *(plugin->env->our_hello)) <= WLAN_MTU); |
1175 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) | 1329 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) |
1176 | + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader) | 1330 | + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader) |
1177 | + GNUNET_HELLO_size(*(plugin->env->our_hello)); | 1331 | + GNUNET_HELLO_size(*(plugin->env->our_hello)); |
1178 | 1332 | ||
1179 | msgheader = GNUNET_malloc(size); | 1333 | msgheader = GNUNET_malloc(size); |
1180 | msgheader->size = htons(size); | 1334 | msgheader->size = htons(size); |
1181 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 1335 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
1182 | 1336 | ||
1183 | radioHeader = (struct RadiotapHeader*) &msgheader[1]; | 1337 | radioHeader = (struct RadiotapHeader*) &msgheader[1]; |
1184 | getRadiotapHeader(radioHeader); | 1338 | getRadiotapHeader(radioHeader); |
1185 | ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; | 1339 | ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; |
1186 | getWlanHeader(ieeewlanheader, bc_all_mac, plugin); | 1340 | getWlanHeader(ieeewlanheader, bc_all_mac, plugin); |
1187 | 1341 | ||
1188 | msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; | 1342 | msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; |
1189 | msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) | 1343 | msgheader2->size = htons(GNUNET_HELLO_size(*(plugin->env->our_hello)) |
1190 | + sizeof(struct GNUNET_MessageHeader)); | 1344 | + sizeof(struct GNUNET_MessageHeader)); |
1191 | 1345 | ||
1192 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); | 1346 | msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); |
1193 | memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( | 1347 | memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( |
1194 | *(plugin->env->our_hello))); | 1348 | *(plugin->env->our_hello))); |
1195 | 1349 | ||
1196 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); | 1350 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); |
1197 | 1351 | ||
1198 | if (bytes == GNUNET_SYSERR) | 1352 | if (bytes == GNUNET_SYSERR) |
1199 | { | 1353 | { |
1200 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1354 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1201 | _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), | 1355 | _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), |
1202 | errno, strerror(errno)); | 1356 | errno, strerror(errno)); |
1203 | 1357 | ||
1204 | } | 1358 | } |
1205 | GNUNET_assert(bytes != GNUNET_SYSERR); | 1359 | GNUNET_assert(bytes != GNUNET_SYSERR); |
1206 | GNUNET_assert(bytes == size); | 1360 | GNUNET_assert(bytes == size); |
1207 | GNUNET_free(msgheader); | 1361 | GNUNET_free(msgheader); |
1208 | 1362 | ||
1209 | set_next_beacon_time(plugin); | 1363 | set_next_beacon_time(plugin); |
1210 | check_next_fragment_timeout(plugin); | 1364 | check_next_fragment_timeout(plugin); |
@@ -1219,18 +1373,18 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1219 | struct GNUNET_MessageHeader * msgheader = NULL; | 1373 | struct GNUNET_MessageHeader * msgheader = NULL; |
1220 | struct IeeeHeader * ieeewlanheader = NULL; | 1374 | struct IeeeHeader * ieeewlanheader = NULL; |
1221 | struct RadiotapHeader * radioHeader = NULL; | 1375 | struct RadiotapHeader * radioHeader = NULL; |
1222 | struct FragmentationHeader * msgheader2 = NULL; | 1376 | struct FragmentationAckHeader * msgheader2 = NULL; |
1223 | 1377 | ||
1224 | GNUNET_assert(sizeof(struct FragmentationHeader) <= WLAN_MTU); | 1378 | GNUNET_assert(sizeof(struct FragmentationAckHeader) <= WLAN_MTU); |
1225 | 1379 | ||
1226 | #if DEBUG_wlan | 1380 | #if DEBUG_wlan |
1227 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1381 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1228 | "Sending ack for message_id %u with fragment number %u\n", | 1382 | "Sending ack for message_id %u with fragment field %u\n", |
1229 | ack->message_id, ack->fragment_off_or_num); | 1383 | ack->message_id, ack->fragments_field); |
1230 | #endif | 1384 | #endif |
1231 | 1385 | ||
1232 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) | 1386 | size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) |
1233 | + sizeof(struct IeeeHeader) + sizeof(struct FragmentationHeader); | 1387 | + sizeof(struct IeeeHeader) + sizeof(struct FragmentationAckHeader); |
1234 | msgheader = GNUNET_malloc(size); | 1388 | msgheader = GNUNET_malloc(size); |
1235 | msgheader->size = htons(size); | 1389 | msgheader->size = htons(size); |
1236 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 1390 | msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
@@ -1240,11 +1394,11 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack) | |||
1240 | ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; | 1394 | ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; |
1241 | getWlanHeader(ieeewlanheader, ack->session->addr, plugin); | 1395 | getWlanHeader(ieeewlanheader, ack->session->addr, plugin); |
1242 | 1396 | ||
1243 | msgheader2 = (struct FragmentationHeader*) &ieeewlanheader[1]; | 1397 | msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1]; |
1244 | msgheader2->header.size = htons(sizeof(struct FragmentationHeader)); | 1398 | msgheader2->header.size = htons(sizeof(struct FragmentationAckHeader)); |
1245 | msgheader2->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK); | 1399 | msgheader2->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK); |
1246 | msgheader2->message_id = htonl(ack->message_id); | 1400 | msgheader2->message_id = htonl(ack->message_id); |
1247 | msgheader2->fragment_off_or_num = htons(ack->fragment_off_or_num); | 1401 | msgheader2->fragment_field = htonll(ack->fragments_field); |
1248 | 1402 | ||
1249 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); | 1403 | bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); |
1250 | if (bytes == GNUNET_SYSERR) | 1404 | if (bytes == GNUNET_SYSERR) |
@@ -1324,16 +1478,10 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1324 | #if DEBUG_wlan | 1478 | #if DEBUG_wlan |
1325 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n"); | 1479 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n"); |
1326 | #endif | 1480 | #endif |
1327 | free_acks(fm); | ||
1328 | GNUNET_assert(plugin->pending_fragment_messages > 0); | ||
1329 | plugin->pending_fragment_messages--; | ||
1330 | GNUNET_CONTAINER_DLL_remove(plugin->pending_Fragment_Messages_head, | ||
1331 | plugin->pending_Fragment_Messages_tail, fm); | ||
1332 | 1481 | ||
1333 | GNUNET_free(fm->msg); | ||
1334 | |||
1335 | GNUNET_free(fm); | ||
1336 | check_fragment_queue(plugin); | 1482 | check_fragment_queue(plugin); |
1483 | free_fragment_message(plugin, fm); | ||
1484 | |||
1337 | } | 1485 | } |
1338 | else | 1486 | else |
1339 | { | 1487 | { |
@@ -1346,12 +1494,35 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1346 | 1494 | ||
1347 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) | 1495 | copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) |
1348 | * fm->message_pos; | 1496 | * fm->message_pos; |
1497 | |||
1498 | #if DEBUG_wlan | ||
1499 | GNUNET_log( | ||
1500 | GNUNET_ERROR_TYPE_DEBUG, | ||
1501 | "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n", | ||
1502 | fm->message_id_out, fm->message_pos, copysize | ||
1503 | + sizeof(struct FragmentationHeader), copyoffset, | ||
1504 | GNUNET_TIME_absolute_get_remaining(fm->timeout)); | ||
1505 | #endif | ||
1506 | |||
1349 | fragheader.fragment_off_or_num = htons(fm->message_pos); | 1507 | fragheader.fragment_off_or_num = htons(fm->message_pos); |
1350 | fragheader.message_id = htonl(session->message_id_out); | 1508 | fragheader.message_id = htonl(fm->message_id_out); |
1351 | GNUNET_assert(copyoffset < fm->message_size); | ||
1352 | copystart = fm->msg + copyoffset; | 1509 | copystart = fm->msg + copyoffset; |
1353 | copysize = GNUNET_MIN(fm->message_size - copyoffset, | 1510 | copysize = GNUNET_MIN(fm->message_size - copyoffset, |
1354 | WLAN_MTU - sizeof(struct FragmentationHeader)); | 1511 | WLAN_MTU - sizeof(struct FragmentationHeader)); |
1512 | |||
1513 | if (copyoffset >= fm->message_size) | ||
1514 | { | ||
1515 | GNUNET_log( | ||
1516 | GNUNET_ERROR_TYPE_ERROR, | ||
1517 | "offset in message for fragment too large, offset %u, size %u, max size %u, copysize %u, message_pos %u,\n", | ||
1518 | copyoffset, fm->message_size, WLAN_MTU | ||
1519 | - sizeof(struct FragmentationHeader), copysize, | ||
1520 | fm->message_pos); | ||
1521 | } | ||
1522 | GNUNET_assert(copyoffset < fm->message_size); | ||
1523 | //FIXME remove later | ||
1524 | GNUNET_assert(copystart < fm->msg + fm->message_size); | ||
1525 | |||
1355 | fragheader.header.size = htons(copysize | 1526 | fragheader.header.size = htons(copysize |
1356 | + sizeof(struct FragmentationHeader)); | 1527 | + sizeof(struct FragmentationHeader)); |
1357 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); | 1528 | fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); |
@@ -1364,15 +1535,6 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1364 | copysize = fm->message_size; | 1535 | copysize = fm->message_size; |
1365 | }*/ | 1536 | }*/ |
1366 | 1537 | ||
1367 | #if DEBUG_wlan | ||
1368 | GNUNET_log( | ||
1369 | GNUNET_ERROR_TYPE_DEBUG, | ||
1370 | "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, time until timeout %u\n", | ||
1371 | session->message_id_out, fm->message_pos, copysize | ||
1372 | + sizeof(struct FragmentationHeader), | ||
1373 | GNUNET_TIME_absolute_get_remaining(fm->timeout)); | ||
1374 | #endif | ||
1375 | |||
1376 | size += copysize; | 1538 | size += copysize; |
1377 | size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader) | 1539 | size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader) |
1378 | + sizeof(struct GNUNET_MessageHeader); | 1540 | + sizeof(struct GNUNET_MessageHeader); |
@@ -1510,7 +1672,7 @@ getRadiotapHeader(struct RadiotapHeader * Header) | |||
1510 | */ | 1672 | */ |
1511 | 1673 | ||
1512 | int | 1674 | int |
1513 | getWlanHeader(struct IeeeHeader * Header,const char * const to_mac_addr, | 1675 | getWlanHeader(struct IeeeHeader * Header, const char * const to_mac_addr, |
1514 | struct Plugin * plugin) | 1676 | struct Plugin * plugin) |
1515 | { | 1677 | { |
1516 | memcpy(&Header->mac2, macbc, sizeof(macbc)); | 1678 | memcpy(&Header->mac2, macbc, sizeof(macbc)); |
@@ -1587,8 +1749,6 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1587 | struct Plugin * plugin = cls; | 1749 | struct Plugin * plugin = cls; |
1588 | struct PendingMessage * newmsg = NULL; | 1750 | struct PendingMessage * newmsg = NULL; |
1589 | struct WlanHeader * wlanheader = NULL; | 1751 | struct WlanHeader * wlanheader = NULL; |
1590 | //struct GNUNET_MessageHeader * innermsg = | ||
1591 | // (struct GNUNET_MessageHeader *) msgbuf; | ||
1592 | 1752 | ||
1593 | //check if msglen > 0 | 1753 | //check if msglen > 0 |
1594 | GNUNET_assert(msgbuf_size > 0); | 1754 | GNUNET_assert(msgbuf_size > 0); |
@@ -1608,20 +1768,15 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1608 | } | 1768 | } |
1609 | } | 1769 | } |
1610 | 1770 | ||
1611 | #if DEBUG_wlan | ||
1612 | GNUNET_log( | ||
1613 | GNUNET_ERROR_TYPE_DEBUG, | ||
1614 | "wlan_plugin_send got %u bytes data, packet says it has %u bytes for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", | ||
1615 | msgbuf_size, ntohs(innermsg->size), session->addr[0], session->addr[1], | ||
1616 | session->addr[2], session->addr[3], session->addr[4], session->addr[5]); | ||
1617 | #endif | ||
1618 | |||
1619 | //TODO target "problem" not solved | 1771 | //TODO target "problem" not solved |
1620 | session->target = *target; | 1772 | //if (session->target != NULL){ |
1773 | // GNUNET_assert(session->target == *target); | ||
1774 | //} else { | ||
1775 | session->target = *target; | ||
1776 | //} | ||
1777 | |||
1621 | 1778 | ||
1622 | //queue message: | 1779 | //queue message: |
1623 | //first queue session | ||
1624 | queue_Session(plugin, session); | ||
1625 | 1780 | ||
1626 | //queue message in session | 1781 | //queue message in session |
1627 | //test if there is no other message in the "queue" | 1782 | //test if there is no other message in the "queue" |
@@ -1632,9 +1787,16 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1632 | newmsg = session->pending_message; | 1787 | newmsg = session->pending_message; |
1633 | GNUNET_log( | 1788 | GNUNET_log( |
1634 | GNUNET_ERROR_TYPE_ERROR, | 1789 | GNUNET_ERROR_TYPE_ERROR, |
1635 | "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u\n", | 1790 | "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages %u\n", |
1636 | GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value); | 1791 | GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value, |
1637 | return -1; | 1792 | session->fragment_messages_out_count); |
1793 | if (session->pending_message2 != NULL) | ||
1794 | { | ||
1795 | GNUNET_log( | ||
1796 | GNUNET_ERROR_TYPE_ERROR, | ||
1797 | "wlan_plugin_send: two pending messages are already in the queue for this client\n"); | ||
1798 | return -1; | ||
1799 | } | ||
1638 | } | 1800 | } |
1639 | 1801 | ||
1640 | newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); | 1802 | newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); |
@@ -1654,7 +1816,24 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1654 | 1816 | ||
1655 | newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); | 1817 | newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); |
1656 | 1818 | ||
1657 | session->pending_message = newmsg; | 1819 | if (session->pending_message == NULL) |
1820 | { | ||
1821 | session->pending_message = newmsg; | ||
1822 | } | ||
1823 | else | ||
1824 | { | ||
1825 | session->pending_message2 = newmsg; | ||
1826 | } | ||
1827 | |||
1828 | #if DEBUG_wlan | ||
1829 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1830 | "New message for %p with size (incl wlan header) %u added\n", session, | ||
1831 | newmsg->message_size); | ||
1832 | #endif | ||
1833 | |||
1834 | |||
1835 | //queue session | ||
1836 | queue_Session(plugin, session); | ||
1658 | 1837 | ||
1659 | check_fragment_queue(plugin); | 1838 | check_fragment_queue(plugin); |
1660 | //FIXME not the correct size | 1839 | //FIXME not the correct size |
@@ -1662,7 +1841,11 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, | |||
1662 | 1841 | ||
1663 | } | 1842 | } |
1664 | 1843 | ||
1665 | //TODO doxigen | 1844 | /** |
1845 | * function to get the first message in the fragement queue (out) of a session | ||
1846 | * @param session pointer to the session | ||
1847 | * @return pointer to the struct FragmentMessage | ||
1848 | */ | ||
1666 | static struct FragmentMessage * | 1849 | static struct FragmentMessage * |
1667 | get_fragment_message_from_session(struct Session * session) | 1850 | get_fragment_message_from_session(struct Session * session) |
1668 | { | 1851 | { |
@@ -1679,6 +1862,28 @@ get_fragment_message_from_session(struct Session * session) | |||
1679 | } | 1862 | } |
1680 | 1863 | ||
1681 | /** | 1864 | /** |
1865 | * function to get the message in the fragement queue (out) of a session with a specific id | ||
1866 | * @param session pointer to the session | ||
1867 | * @param message_id id of the message | ||
1868 | * @return pointer to the struct FragmentMessage | ||
1869 | */ | ||
1870 | static struct FragmentMessage * | ||
1871 | get_fragment_message_from_session_and_id(struct Session * session, | ||
1872 | uint32_t message_id) | ||
1873 | { | ||
1874 | struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head; | ||
1875 | while (fm != NULL) | ||
1876 | { | ||
1877 | if ((fm->session == session) && (fm->message_id_out == message_id)) | ||
1878 | { | ||
1879 | return fm; | ||
1880 | } | ||
1881 | fm = fm->next; | ||
1882 | } | ||
1883 | return NULL; | ||
1884 | } | ||
1885 | |||
1886 | /** | ||
1682 | * Function that can be used to force the plugin to disconnect | 1887 | * Function that can be used to force the plugin to disconnect |
1683 | * from the given peer and cancel all previous transmissions | 1888 | * from the given peer and cancel all previous transmissions |
1684 | * (and their continuation). | 1889 | * (and their continuation). |
@@ -1694,6 +1899,7 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | |||
1694 | struct Sessionqueue * pendingsession = plugin->pending_Sessions; | 1899 | struct Sessionqueue * pendingsession = plugin->pending_Sessions; |
1695 | struct PendingMessage * pm = NULL; | 1900 | struct PendingMessage * pm = NULL; |
1696 | struct FragmentMessage * fm; | 1901 | struct FragmentMessage * fm; |
1902 | struct Receive_Message_Queue * receive_queue; | ||
1697 | 1903 | ||
1698 | // just look at all the session for the needed one | 1904 | // just look at all the session for the needed one |
1699 | while (queue != NULL) | 1905 | while (queue != NULL) |
@@ -1720,10 +1926,22 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | |||
1720 | 1926 | ||
1721 | //is something of this session in the fragment queue? | 1927 | //is something of this session in the fragment queue? |
1722 | fm = get_fragment_message_from_session(queue->content); | 1928 | fm = get_fragment_message_from_session(queue->content); |
1723 | free_fragment_message(plugin, fm); | 1929 | while (fm != NULL) |
1930 | { | ||
1931 | free_fragment_message(plugin, fm); | ||
1932 | fm = get_fragment_message_from_session(queue->content); | ||
1933 | } | ||
1934 | check_next_fragment_timeout(plugin); | ||
1724 | 1935 | ||
1725 | //dispose all received fragments | 1936 | //dispose all received fragments |
1726 | free_rec_frag_queue(queue->content); | 1937 | receive_queue = get_receive_message_from_session(plugin, |
1938 | queue->content); | ||
1939 | while (receive_queue != NULL) | ||
1940 | { | ||
1941 | free_receive_message(plugin, receive_queue); | ||
1942 | receive_queue = get_receive_message_from_session(plugin, | ||
1943 | queue->content); | ||
1944 | } | ||
1727 | 1945 | ||
1728 | // remove PendingMessage | 1946 | // remove PendingMessage |
1729 | pm = queue->content->pending_message; | 1947 | pm = queue->content->pending_message; |
@@ -1777,9 +1995,9 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type, | |||
1777 | return; | 1995 | return; |
1778 | } | 1996 | } |
1779 | input = (const unsigned char*) addr; | 1997 | input = (const unsigned char*) addr; |
1780 | GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 1998 | GNUNET_snprintf(ret, sizeof(ret), |
1781 | PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4], | 1999 | "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", PROTOCOL_PREFIX, |
1782 | input[5]); | 2000 | input[0], input[1], input[2], input[3], input[4], input[5]); |
1783 | asc(asc_cls, ret); | 2001 | asc(asc_cls, ret); |
1784 | } | 2002 | } |
1785 | 2003 | ||
@@ -1845,57 +2063,75 @@ wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | |||
1845 | return NULL; | 2063 | return NULL; |
1846 | } | 2064 | } |
1847 | input = (const unsigned char*) addr; | 2065 | input = (const unsigned char*) addr; |
1848 | GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 2066 | GNUNET_snprintf(ret, sizeof(ret), |
1849 | PROTOCOL_PREFIX, input[0], input[1], input[2], input[3], input[4], | 2067 | "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", PROTOCOL_PREFIX, |
1850 | input[5]); | 2068 | input[0], input[1], input[2], input[3], input[4], input[5]); |
1851 | return ret; | 2069 | return ret; |
1852 | } | 2070 | } |
1853 | 2071 | ||
1854 | /** | 2072 | /** |
2073 | * function to check if bitfield is representation of fragments of the message | ||
2074 | * @param rec_message message to check | ||
2075 | */ | ||
2076 | |||
2077 | void | ||
2078 | check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message) | ||
2079 | { | ||
2080 | uint64_t checkfragments = 0; | ||
2081 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; | ||
2082 | |||
2083 | while (rec_queue != NULL) | ||
2084 | { | ||
2085 | setBit((char*) &checkfragments, rec_queue->num); | ||
2086 | rec_queue = rec_queue->next; | ||
2087 | |||
2088 | } | ||
2089 | GNUNET_assert(checkfragments == rec_message->received_fragments); | ||
2090 | } | ||
2091 | |||
2092 | /** | ||
1855 | * Function to test if fragment number already exists in the fragments received | 2093 | * Function to test if fragment number already exists in the fragments received |
1856 | * | 2094 | * |
1857 | * @param session session the fragment belongs to | 2095 | * @param rec_message message this fragment belongs to |
1858 | * @param fh Fragmentheader of the fragment | 2096 | * @param fh Fragmentheader of the fragment |
1859 | * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session | 2097 | * @return GNUNET_YES if fragment exists already, GNUNET_NO if it does not exists in the queue of the session |
1860 | */ | 2098 | */ |
1861 | 2099 | ||
1862 | static const int | 2100 | static const int |
1863 | is_double_msg(struct Session * session, struct FragmentationHeader * fh) | 2101 | is_double_msg(struct Receive_Message_Queue * rec_message, |
2102 | struct FragmentationHeader * fh) | ||
1864 | { | 2103 | { |
1865 | struct RecQueue * rec_queue = session->frag_head; | 2104 | //test if bitfield is okay |
1866 | while (rec_queue != NULL) | 2105 | #if DEBUG_wlan |
1867 | { | 2106 | check_message_fragment_bitfield(rec_message); |
1868 | if (rec_queue->num == fh->fragment_off_or_num) | 2107 | #endif |
1869 | { | 2108 | |
1870 | return GNUNET_YES; | 2109 | return testBit((char *) &rec_message->received_fragments, ntohs( |
1871 | } | 2110 | fh->fragment_off_or_num)); |
1872 | rec_queue = rec_queue->next; | ||
1873 | 2111 | ||
1874 | } | ||
1875 | return GNUNET_NO; | ||
1876 | } | 2112 | } |
1877 | 2113 | ||
1878 | /** | 2114 | /** |
1879 | * Function to insert a fragment in a queue of a session | 2115 | * Function to insert a fragment in a queue of a message |
1880 | * @param session session the fragment belongs to | 2116 | * @param session session the fragment belongs to |
1881 | * @param rec_queue fragment to add | 2117 | * @param rec_queue fragment to add |
1882 | */ | 2118 | */ |
1883 | 2119 | ||
1884 | static void | 2120 | static void |
1885 | insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue) | 2121 | insert_fragment_in_queue(struct Receive_Message_Queue * rec_message, |
2122 | struct Receive_Fragment_Queue * rec_queue) | ||
1886 | { | 2123 | { |
1887 | struct RecQueue * rec_queue2 = session->frag_head; | 2124 | struct Receive_Fragment_Queue * rec_queue2 = rec_message->frag_head; |
1888 | struct WlanHeader * wlanheader = NULL; | 2125 | struct WlanHeader * wlanheader = NULL; |
1889 | //first received fragment of message | 2126 | |
1890 | if (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED) | 2127 | GNUNET_assert(rec_message != NULL); |
1891 | { | 2128 | GNUNET_assert(rec_queue != NULL); |
1892 | session->rec_size = MESSAGE_LENGHT_UNKNOWN; | 2129 | |
1893 | } | ||
1894 | //this is the first fragment of the message (fragment id 0) | 2130 | //this is the first fragment of the message (fragment id 0) |
1895 | if (rec_queue->num == 0) | 2131 | if (rec_queue->num == 0) |
1896 | { | 2132 | { |
1897 | wlanheader = (struct WlanHeader *) rec_queue->msg; | 2133 | wlanheader = (struct WlanHeader *) rec_queue->msg; |
1898 | session->rec_size = ntohs(wlanheader->header.size); | 2134 | rec_message->rec_size = ntohs(wlanheader->header.size); |
1899 | } | 2135 | } |
1900 | 2136 | ||
1901 | //sort into list | 2137 | //sort into list |
@@ -1904,34 +2140,46 @@ insert_fragment_in_queue(struct Session * session, struct RecQueue * rec_queue) | |||
1904 | if (rec_queue2->num > rec_queue->num) | 2140 | if (rec_queue2->num > rec_queue->num) |
1905 | { | 2141 | { |
1906 | //next element number is grater than the current num | 2142 | //next element number is grater than the current num |
1907 | GNUNET_CONTAINER_DLL_insert_before(session->frag_head, session->frag_tail, rec_queue2, rec_queue); | 2143 | GNUNET_CONTAINER_DLL_insert_before(rec_message->frag_head, rec_message->frag_tail, rec_queue2, rec_queue); |
2144 | setBit((char *) &rec_message->received_fragments, rec_queue->num); | ||
1908 | return; | 2145 | return; |
1909 | } | 2146 | } |
1910 | rec_queue = rec_queue->next; | 2147 | rec_queue = rec_queue->next; |
1911 | } | 2148 | } |
1912 | //no element has a grater number | 2149 | //no element has a grater number |
1913 | GNUNET_CONTAINER_DLL_insert_tail(session->frag_head, session->frag_tail, rec_queue); | 2150 | GNUNET_CONTAINER_DLL_insert_tail(rec_message->frag_head, rec_message->frag_tail, rec_queue); |
2151 | |||
2152 | setBit((char *) &rec_message->received_fragments, rec_queue->num); | ||
1914 | } | 2153 | } |
1915 | 2154 | ||
1916 | /** | 2155 | /** |
1917 | * Function to dispose the fragments received for a message | 2156 | * Function to dispose the fragments received for a message and the message |
1918 | * @param session session to free the fragments from | 2157 | * @param session session to free the fragments from |
1919 | */ | 2158 | */ |
1920 | 2159 | ||
1921 | static void | 2160 | static void |
1922 | free_rec_frag_queue(struct Session * session) | 2161 | free_receive_message(struct Plugin* plugin, |
2162 | struct Receive_Message_Queue * rec_message) | ||
1923 | { | 2163 | { |
1924 | struct RecQueue * rec_queue = session->frag_head; | 2164 | GNUNET_assert(rec_message !=NULL); |
1925 | struct RecQueue * rec_queue2; | 2165 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; |
2166 | struct Receive_Fragment_Queue * rec_queue2; | ||
2167 | |||
1926 | while (rec_queue != NULL) | 2168 | while (rec_queue != NULL) |
1927 | { | 2169 | { |
1928 | rec_queue2 = rec_queue; | 2170 | rec_queue2 = rec_queue; |
1929 | rec_queue = rec_queue->next; | 2171 | rec_queue = rec_queue->next; |
1930 | GNUNET_free(rec_queue2); | 2172 | GNUNET_free(rec_queue2); |
1931 | } | 2173 | } |
1932 | session->frag_head = NULL; | 2174 | |
1933 | session->frag_tail = NULL; | 2175 | GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rec_message); |
1934 | session->rec_size = NO_MESSAGE_OR_MESSAGE_FINISHED; | 2176 | |
2177 | GNUNET_assert(plugin->pending_receive_messages > 0); | ||
2178 | GNUNET_assert(rec_message->session->fragment_messages_in_count > 0); | ||
2179 | |||
2180 | plugin->pending_receive_messages--; | ||
2181 | rec_message->session->fragment_messages_in_count--; | ||
2182 | GNUNET_free(rec_message); | ||
1935 | } | 2183 | } |
1936 | 2184 | ||
1937 | /** | 2185 | /** |
@@ -1943,70 +2191,77 @@ free_rec_frag_queue(struct Session * session) | |||
1943 | 2191 | ||
1944 | static void | 2192 | static void |
1945 | check_rec_finished_msg(struct Plugin* plugin, | 2193 | check_rec_finished_msg(struct Plugin* plugin, |
1946 | struct Session_light * session_light, struct Session * session) | 2194 | struct Session_light * session_light, struct Session * session, |
2195 | struct Receive_Message_Queue * rec_message) | ||
1947 | { | 2196 | { |
1948 | struct RecQueue * rec_queue = session->frag_head; | 2197 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; |
1949 | int packetsize = session->rec_size; | 2198 | int packetsize = rec_message->rec_size; |
1950 | int sum = 0; | 2199 | int sum = 0; |
1951 | int aktnum = 0; | 2200 | int aktnum = 0; |
2201 | uint64_t bitfield = 0; | ||
1952 | char * msg; | 2202 | char * msg; |
1953 | //some fragment should be received | 2203 | |
1954 | GNUNET_assert(session->rec_size != NO_MESSAGE_OR_MESSAGE_FINISHED); | 2204 | GNUNET_assert(rec_message !=NULL); |
1955 | //check if first fragment is present | 2205 | //check if first fragment is present |
1956 | if (session->rec_size == MESSAGE_LENGHT_UNKNOWN) | 2206 | if (packetsize == MESSAGE_LENGHT_UNKNOWN) |
1957 | { | 2207 | { |
1958 | return; | 2208 | return; |
1959 | } | 2209 | } |
1960 | while (rec_queue != NULL) | ||
1961 | { | ||
1962 | sum += rec_queue->size; | ||
1963 | //check if all fragment numbers are present | ||
1964 | if (rec_queue->num != aktnum) | ||
1965 | { | ||
1966 | return; | ||
1967 | } | ||
1968 | aktnum++; | ||
1969 | rec_queue = rec_queue->next; | ||
1970 | } | ||
1971 | //sum should always be smaller or equal of | ||
1972 | GNUNET_assert(sum <= packetsize); | ||
1973 | if (sum == packetsize) | ||
1974 | { | ||
1975 | |||
1976 | #if DEBUG_wlan | 2210 | #if DEBUG_wlan |
1977 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2211 | check_message_fragment_bitfield(rec_message); |
1978 | "check_rec_finished_msg: A message for %p is complete\n", session); | ||
1979 | #endif | 2212 | #endif |
1980 | 2213 | ||
1981 | //copy fragments together | 2214 | bitfield = ~bitfield; |
1982 | msg = GNUNET_malloc(packetsize); | 2215 | bitfield = bitfield >> (63 - rec_message->frag_tail->num); |
1983 | rec_queue = session->frag_head; | 2216 | if (rec_message->received_fragments == bitfield) |
1984 | aktnum = 0; | 2217 | { |
2218 | |||
1985 | while (rec_queue != NULL) | 2219 | while (rec_queue != NULL) |
1986 | { | 2220 | { |
1987 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY | 2221 | sum += rec_queue->size; |
1988 | memcpy(msg + aktnum, rec_queue->msg, rec_queue->size); | ||
1989 | aktnum += rec_queue->size; | ||
1990 | rec_queue = rec_queue->next; | 2222 | rec_queue = rec_queue->next; |
1991 | } | 2223 | } |
1992 | free_rec_frag_queue(session); | 2224 | //sum should always be smaller or equal of |
1993 | //call wlan_process_helper to process the message | 2225 | GNUNET_assert(sum <= packetsize); |
1994 | wlan_data_massage_handler(plugin, session_light, | 2226 | if (sum == packetsize) |
1995 | (struct GNUNET_MessageHeader*) msg); | 2227 | { |
1996 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | ||
1997 | 2228 | ||
1998 | GNUNET_free(msg); | 2229 | #if DEBUG_wlan |
2230 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2231 | "check_rec_finished_msg: A message for %p is complete\n", session); | ||
2232 | #endif | ||
2233 | |||
2234 | //TODO use mst | ||
2235 | //copy fragments together | ||
2236 | msg = GNUNET_malloc(packetsize); | ||
2237 | rec_queue = rec_message->frag_head; | ||
2238 | aktnum = 0; | ||
2239 | while (rec_queue != NULL) | ||
2240 | { | ||
2241 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY | ||
2242 | memcpy(msg + aktnum, rec_queue->msg, rec_queue->size); | ||
2243 | aktnum += rec_queue->size; | ||
2244 | rec_queue = rec_queue->next; | ||
2245 | } | ||
2246 | free_receive_message(plugin, rec_message); | ||
2247 | //call wlan_process_helper to process the message | ||
2248 | wlan_data_massage_handler(plugin, session_light, | ||
2249 | (struct GNUNET_MessageHeader*) msg); | ||
2250 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | ||
2251 | |||
2252 | GNUNET_free(msg); | ||
2253 | } | ||
1999 | } | 2254 | } |
2000 | } | 2255 | } |
2001 | 2256 | ||
2002 | static void | 2257 | static void |
2003 | process_data(void *cls, void *client, | 2258 | process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
2004 | const struct GNUNET_MessageHeader *hdr){ | 2259 | { |
2005 | 2260 | ||
2006 | GNUNET_assert(client != NULL); | 2261 | GNUNET_assert(client != NULL); |
2007 | GNUNET_assert(cls != NULL); | 2262 | GNUNET_assert(cls != NULL); |
2008 | struct Session * session = (struct Session * )client; | 2263 | struct Session * session = (struct Session *) client; |
2009 | struct Plugin * plugin = (struct Plugin * ) cls; | 2264 | struct Plugin * plugin = (struct Plugin *) cls; |
2010 | 2265 | ||
2011 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; | 2266 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; |
2012 | distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); | 2267 | distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); |
@@ -2015,14 +2270,14 @@ process_data(void *cls, void *client, | |||
2015 | distance[1].value = htonl(0); | 2270 | distance[1].value = htonl(0); |
2016 | 2271 | ||
2017 | #if DEBUG_wlan | 2272 | #if DEBUG_wlan |
2018 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2273 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2019 | "Calling plugin->env->receive for session %p; %s\n", session, | 2274 | "Calling plugin->env->receive for session %p; %s\n", session, |
2020 | wlan_plugin_address_to_string(NULL, session->addr, 6)); | 2275 | wlan_plugin_address_to_string(NULL, session->addr, 6)); |
2021 | #endif | 2276 | #endif |
2022 | 2277 | ||
2023 | plugin->env->receive(plugin->env->cls, &(session->target), hdr, | 2278 | plugin->env->receive(plugin->env->cls, &(session->target), hdr, |
2024 | (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, | 2279 | (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, |
2025 | session, session->addr, sizeof(session->addr)); | 2280 | session->addr, sizeof(session->addr)); |
2026 | } | 2281 | } |
2027 | 2282 | ||
2028 | /** | 2283 | /** |
@@ -2125,10 +2380,10 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2125 | //"receive" the message | 2380 | //"receive" the message |
2126 | 2381 | ||
2127 | 2382 | ||
2128 | GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session, (const char *) temp_hdr, | 2383 | GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session, |
2384 | (const char *) temp_hdr, | ||
2129 | ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO); | 2385 | ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO); |
2130 | 2386 | ||
2131 | |||
2132 | return; | 2387 | return; |
2133 | } | 2388 | } |
2134 | else | 2389 | else |
@@ -2148,7 +2403,7 @@ wlan_data_massage_handler(struct Plugin * plugin, | |||
2148 | 2403 | ||
2149 | void | 2404 | void |
2150 | add_ack_for_send(struct Plugin * plugin, struct Session * session, | 2405 | add_ack_for_send(struct Plugin * plugin, struct Session * session, |
2151 | struct FragmentationHeader * fh) | 2406 | uint64_t bitfield, struct FragmentationHeader * fh) |
2152 | { | 2407 | { |
2153 | struct AckSendQueue * ack; | 2408 | struct AckSendQueue * ack; |
2154 | 2409 | ||
@@ -2157,7 +2412,7 @@ add_ack_for_send(struct Plugin * plugin, struct Session * session, | |||
2157 | GNUNET_assert(fh != NULL); | 2412 | GNUNET_assert(fh != NULL); |
2158 | 2413 | ||
2159 | ack = GNUNET_malloc(sizeof(struct AckSendQueue)); | 2414 | ack = GNUNET_malloc(sizeof(struct AckSendQueue)); |
2160 | ack->fragment_off_or_num = ntohs(fh->fragment_off_or_num); | 2415 | ack->fragments_field = bitfield; |
2161 | ack->message_id = ntohl(fh->message_id); | 2416 | ack->message_id = ntohl(fh->message_id); |
2162 | ack->session = session; | 2417 | ack->session = session; |
2163 | 2418 | ||
@@ -2167,6 +2422,150 @@ add_ack_for_send(struct Plugin * plugin, struct Session * session, | |||
2167 | } | 2422 | } |
2168 | 2423 | ||
2169 | /** | 2424 | /** |
2425 | * function to get the receive message from the message id and the session | ||
2426 | * @param plugin pointer to the plugin struct | ||
2427 | * @param session session this fragment belongs to | ||
2428 | * @param message_id id of the message | ||
2429 | */ | ||
2430 | |||
2431 | struct Receive_Message_Queue * | ||
2432 | get_receive_message(struct Plugin * plugin, struct Session * session, | ||
2433 | uint32_t message_id) | ||
2434 | { | ||
2435 | struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; | ||
2436 | while (rec_message != NULL) | ||
2437 | { | ||
2438 | if ((rec_message->message_id_in == message_id) && (rec_message->session | ||
2439 | == session)) | ||
2440 | { | ||
2441 | return rec_message; | ||
2442 | } | ||
2443 | rec_message = rec_message->next; | ||
2444 | } | ||
2445 | return NULL; | ||
2446 | } | ||
2447 | |||
2448 | /** | ||
2449 | * function to get the receive message of a session | ||
2450 | * @param plugin pointer to the plugin struct | ||
2451 | * @param session session this fragment belongs to | ||
2452 | */ | ||
2453 | |||
2454 | struct Receive_Message_Queue * | ||
2455 | get_receive_message_from_session(struct Plugin * plugin, | ||
2456 | struct Session * session) | ||
2457 | { | ||
2458 | struct Receive_Message_Queue * rec_message = plugin->receive_messages_head; | ||
2459 | while (rec_message != NULL) | ||
2460 | { | ||
2461 | if (rec_message->session == session) | ||
2462 | { | ||
2463 | return rec_message; | ||
2464 | } | ||
2465 | rec_message = rec_message->next; | ||
2466 | } | ||
2467 | return NULL; | ||
2468 | } | ||
2469 | |||
2470 | /** | ||
2471 | * function to insert a received fragment into the right fragment queue of the right message | ||
2472 | * @param plugin pointer to the plugin struct | ||
2473 | * @param session session this fragment belongs to | ||
2474 | * @param fh pointer to the header of the fragment | ||
2475 | * @return new fragment bitfield for the message | ||
2476 | */ | ||
2477 | |||
2478 | uint64_t | ||
2479 | insert_fragment_in_in_message_queue(struct Plugin * plugin, | ||
2480 | struct Session_light * session_light, struct Session * session, | ||
2481 | struct FragmentationHeader * fh) | ||
2482 | { | ||
2483 | struct Receive_Fragment_Queue * rec_queue = NULL; | ||
2484 | struct Receive_Message_Queue * rec_message; | ||
2485 | const char * tempmsg = (char*) &fh[1]; | ||
2486 | uint64_t retval = 0; | ||
2487 | |||
2488 | //TODO fragments do not timeout | ||
2489 | //check if message_id is right or it is a new msg | ||
2490 | GNUNET_assert(fh != NULL); | ||
2491 | |||
2492 | rec_message = get_receive_message(plugin, session, ntohs(fh->message_id)); | ||
2493 | |||
2494 | if (rec_message == NULL) | ||
2495 | { | ||
2496 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) | ||
2497 | { | ||
2498 | |||
2499 | //new message incoming | ||
2500 | rec_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); | ||
2501 | rec_message->message_id_in = ntohs(fh->message_id); | ||
2502 | rec_message->rec_size = MESSAGE_LENGHT_UNKNOWN; | ||
2503 | rec_message->session = session; | ||
2504 | rec_message->timeout = GNUNET_TIME_absolute_add( | ||
2505 | GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT); | ||
2506 | rec_message->received_fragments = 0; | ||
2507 | |||
2508 | GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rec_message); | ||
2509 | |||
2510 | session->fragment_messages_in_count++; | ||
2511 | plugin->pending_receive_messages++; | ||
2512 | |||
2513 | #if DEBUG_wlan | ||
2514 | GNUNET_log( | ||
2515 | GNUNET_ERROR_TYPE_DEBUG, | ||
2516 | "New fragmented message started: message id %u, messages in for this session %u, messages in %u\n", | ||
2517 | rec_message->message_id_in, session->fragment_messages_in_count, | ||
2518 | plugin->pending_receive_messages); | ||
2519 | #endif | ||
2520 | } | ||
2521 | else | ||
2522 | { | ||
2523 | |||
2524 | GNUNET_log( | ||
2525 | GNUNET_ERROR_TYPE_INFO, | ||
2526 | "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached\n"); | ||
2527 | setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); | ||
2528 | return retval; | ||
2529 | } | ||
2530 | } | ||
2531 | |||
2532 | if (is_double_msg(rec_message, fh) != GNUNET_YES) | ||
2533 | { | ||
2534 | |||
2535 | //report size | ||
2536 | rec_queue = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + | ||
2537 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); | ||
2538 | rec_queue->size = ntohs(fh->header.size) | ||
2539 | - sizeof(struct FragmentationHeader); | ||
2540 | rec_queue->num = ntohs(fh->fragment_off_or_num); | ||
2541 | rec_queue->msg = (char*) &(rec_queue[1]); | ||
2542 | //copy msg to buffer | ||
2543 | memcpy(rec_queue->msg, tempmsg, rec_queue->size); | ||
2544 | insert_fragment_in_queue(rec_message, rec_queue); | ||
2545 | //save bitfield | ||
2546 | retval = rec_message->received_fragments; | ||
2547 | |||
2548 | #if DEBUG_wlan | ||
2549 | GNUNET_log( | ||
2550 | GNUNET_ERROR_TYPE_DEBUG, | ||
2551 | "New fragment: size %u, fragsize %u, message id %u, bitfield %X, session %u\n", | ||
2552 | rec_message->rec_size, rec_queue->size, | ||
2553 | rec_message->received_fragments, rec_message->message_id_in, session); | ||
2554 | #endif | ||
2555 | |||
2556 | check_rec_finished_msg(plugin, session_light, session, rec_message); | ||
2557 | } | ||
2558 | else | ||
2559 | { | ||
2560 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN fragment is a clone\n"); | ||
2561 | retval = rec_message->received_fragments; | ||
2562 | |||
2563 | } | ||
2564 | return retval; | ||
2565 | |||
2566 | } | ||
2567 | |||
2568 | /** | ||
2170 | * Function used for to process the data received from the wlan interface | 2569 | * Function used for to process the data received from the wlan interface |
2171 | * | 2570 | * |
2172 | * @param cls the plugin handle | 2571 | * @param cls the plugin handle |
@@ -2181,14 +2580,13 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2181 | struct Session * session = NULL; | 2580 | struct Session * session = NULL; |
2182 | 2581 | ||
2183 | struct FragmentationHeader * fh = NULL; | 2582 | struct FragmentationHeader * fh = NULL; |
2583 | struct FragmentationAckHeader * fah = NULL; | ||
2184 | struct FragmentMessage * fm = NULL; | 2584 | struct FragmentMessage * fm = NULL; |
2185 | 2585 | ||
2186 | const char * tempmsg = NULL; | 2586 | const char * tempmsg = NULL; |
2187 | 2587 | ||
2188 | struct AckQueue * ack = NULL; | 2588 | uint64_t fragment_bitfield = 0; |
2189 | struct AckQueue * ack2 = NULL; | ||
2190 | 2589 | ||
2191 | struct RecQueue * rec_queue = NULL; | ||
2192 | //ADVERTISEMENT | 2590 | //ADVERTISEMENT |
2193 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT) | 2591 | if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT) |
2194 | { | 2592 | { |
@@ -2201,7 +2599,8 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2201 | GNUNET_log( | 2599 | GNUNET_log( |
2202 | GNUNET_ERROR_TYPE_DEBUG, | 2600 | GNUNET_ERROR_TYPE_DEBUG, |
2203 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", | 2601 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", |
2204 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL,session_light->addr, 6)); | 2602 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, |
2603 | session_light->addr, 6)); | ||
2205 | #endif | 2604 | #endif |
2206 | 2605 | ||
2207 | if (session_light->session == NULL) | 2606 | if (session_light->session == NULL) |
@@ -2233,7 +2632,8 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2233 | GNUNET_ERROR_TYPE_DEBUG, | 2632 | GNUNET_ERROR_TYPE_DEBUG, |
2234 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", | 2633 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", |
2235 | ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( | 2634 | ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( |
2236 | hdr->size), wlan_plugin_address_to_string(NULL,session_light->addr, 6)); | 2635 | hdr->size), wlan_plugin_address_to_string(NULL, |
2636 | session_light->addr, 6)); | ||
2237 | #endif | 2637 | #endif |
2238 | 2638 | ||
2239 | if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) | 2639 | if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) |
@@ -2246,52 +2646,16 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2246 | //if in the session list | 2646 | //if in the session list |
2247 | if (session != NULL) | 2647 | if (session != NULL) |
2248 | { | 2648 | { |
2249 | //TODO fragments do not timeout | 2649 | fragment_bitfield = insert_fragment_in_in_message_queue(plugin, |
2250 | //check if message_id is right or it is a new msg | 2650 | session_light, session, fh); |
2251 | if ((session->message_id_in == ntohs(fh->message_id)) | ||
2252 | || (session->rec_size == NO_MESSAGE_OR_MESSAGE_FINISHED)) | ||
2253 | { | ||
2254 | session->message_id_in = ntohs(fh->message_id); | ||
2255 | if (is_double_msg(session, fh) != GNUNET_YES) | ||
2256 | { | ||
2257 | //report size | ||
2258 | //TODO ask if it is right like this | ||
2259 | if (plugin->env->traffic_report != NULL) | ||
2260 | { | ||
2261 | plugin->env->traffic_report(plugin->env->cls, | ||
2262 | &session->target, ntohs(fh->header.size)); | ||
2263 | } | ||
2264 | rec_queue | ||
2265 | = GNUNET_malloc(sizeof (struct RecQueue) + | ||
2266 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); | ||
2267 | rec_queue->size = ntohs(fh->header.size) | ||
2268 | - sizeof(struct FragmentationHeader); | ||
2269 | rec_queue->num = ntohs(fh->fragment_off_or_num); | ||
2270 | rec_queue->msg = (char*) &rec_queue[1]; | ||
2271 | //copy msg to buffer | ||
2272 | memcpy((char *) rec_queue->msg, tempmsg, rec_queue->size); | ||
2273 | insert_fragment_in_queue(session, rec_queue); | ||
2274 | check_rec_finished_msg(plugin, session_light, session); | ||
2275 | } | ||
2276 | else | ||
2277 | { | ||
2278 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
2279 | "WLAN fragment is a clone\n"); | ||
2280 | |||
2281 | } | ||
2282 | } | ||
2283 | else | ||
2284 | { | ||
2285 | GNUNET_log( | ||
2286 | GNUNET_ERROR_TYPE_INFO, | ||
2287 | "WLAN fragment message_id and session message_id are not the same and a message is already (partly) received\n"); | ||
2288 | |||
2289 | } | ||
2290 | } | 2651 | } |
2291 | else | 2652 | else |
2292 | { | 2653 | { |
2293 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2654 | // new session |
2294 | "WLAN client not in session list\n"); | 2655 | GNUNET_log( |
2656 | GNUNET_ERROR_TYPE_INFO, | ||
2657 | "WLAN client not in session list, fragment num %u, message id %u\n", | ||
2658 | ntohs(fh->fragment_off_or_num), ntohs(fh->message_id)); | ||
2295 | wlan_data_massage_handler(plugin, session_light, | 2659 | wlan_data_massage_handler(plugin, session_light, |
2296 | (struct GNUNET_MessageHeader *) tempmsg); | 2660 | (struct GNUNET_MessageHeader *) tempmsg); |
2297 | session = session_light->session; | 2661 | session = session_light->session; |
@@ -2300,10 +2664,10 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2300 | { | 2664 | { |
2301 | return; | 2665 | return; |
2302 | } | 2666 | } |
2667 | setBit((char *) &fragment_bitfield, ntohs(fh->fragment_off_or_num)); | ||
2303 | } | 2668 | } |
2304 | 2669 | ||
2305 | //TODO make and send ack | 2670 | add_ack_for_send(plugin, session, fragment_bitfield, fh); |
2306 | add_ack_for_send(plugin, session, fh); | ||
2307 | check_next_fragment_timeout(plugin); | 2671 | check_next_fragment_timeout(plugin); |
2308 | 2672 | ||
2309 | } | 2673 | } |
@@ -2316,7 +2680,8 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2316 | GNUNET_log( | 2680 | GNUNET_log( |
2317 | GNUNET_ERROR_TYPE_DEBUG, | 2681 | GNUNET_ERROR_TYPE_DEBUG, |
2318 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", | 2682 | "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", |
2319 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL,session_light->addr, 6)); | 2683 | ntohs(hdr->size), wlan_plugin_address_to_string(NULL, |
2684 | session_light->addr, 6)); | ||
2320 | #endif | 2685 | #endif |
2321 | 2686 | ||
2322 | GNUNET_assert(session_light != NULL); | 2687 | GNUNET_assert(session_light != NULL); |
@@ -2326,68 +2691,21 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2326 | GNUNET_assert(session_light->session != NULL); | 2691 | GNUNET_assert(session_light->session != NULL); |
2327 | } | 2692 | } |
2328 | session = session_light->session; | 2693 | session = session_light->session; |
2329 | fh = (struct FragmentationHeader *) hdr; | 2694 | fah = (struct FragmentationAckHeader *) hdr; |
2330 | if (session->message_id_out == ntohl(fh->message_id)) | 2695 | fm = get_fragment_message_from_session_and_id(session, ntohl( |
2696 | fah->message_id)); | ||
2697 | if (fm != NULL) | ||
2331 | { | 2698 | { |
2332 | fm = get_fragment_message_from_session(session); | ||
2333 | if (fm != NULL) | ||
2334 | { | ||
2335 | |||
2336 | ack2 = fm->head; | ||
2337 | while (ack2 != NULL) | ||
2338 | { | ||
2339 | // check for double | ||
2340 | if (ack2->fragment_num != ntohs(fh->fragment_off_or_num)) | ||
2341 | { | ||
2342 | // check if next ack has bigger number | ||
2343 | if (ack2->fragment_num > ntohs(fh->fragment_off_or_num)) | ||
2344 | { | ||
2345 | ack = GNUNET_malloc(sizeof(struct AckQueue)); | ||
2346 | ack->fragment_num = ntohs(fh->fragment_off_or_num); | ||
2347 | GNUNET_CONTAINER_DLL_insert_before(fm->head,fm->tail,ack2,ack); | ||
2348 | //check if finished | ||
2349 | check_finished_fragment(plugin, fm); | ||
2350 | return; | ||
2351 | } | ||
2352 | } | ||
2353 | else | ||
2354 | { | ||
2355 | //double ack | ||
2356 | #if DEBUG_wlan | ||
2357 | GNUNET_log( | ||
2358 | GNUNET_ERROR_TYPE_DEBUG, | ||
2359 | "WLAN got double ack for message id %u and fragment num %u\n", | ||
2360 | session->message_id_out, ack2->fragment_num); | ||
2361 | #endif | ||
2362 | return; | ||
2363 | } | ||
2364 | ack2 = ack2->next; | ||
2365 | } | ||
2366 | |||
2367 | //all acks are have smaller numbers | ||
2368 | ack = GNUNET_malloc(sizeof(struct AckQueue)); | ||
2369 | ack->fragment_num = ntohs(fh->fragment_off_or_num); | ||
2370 | GNUNET_CONTAINER_DLL_insert_tail(fm->head,fm->tail,ack); | ||
2371 | check_finished_fragment(plugin, fm); | ||
2372 | } | ||
2373 | else | ||
2374 | { | ||
2375 | GNUNET_log( | ||
2376 | GNUNET_ERROR_TYPE_WARNING, | ||
2377 | "WLAN fragment not in fragment list but id %u of ack is right\n", | ||
2378 | ntohl(fh->message_id)); | ||
2379 | return; | ||
2380 | } | ||
2381 | 2699 | ||
2700 | fm->ack_bitfield = fm->ack_bitfield | ntohll(fah->fragment_field); | ||
2701 | check_finished_fragment(plugin, fm); | ||
2382 | } | 2702 | } |
2383 | else | 2703 | else |
2384 | { | 2704 | { |
2385 | #if DEBUG_wlan | 2705 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2386 | GNUNET_log( | 2706 | "WLAN fragment not in fragment list with id %u of ack\n", ntohl( |
2387 | GNUNET_ERROR_TYPE_DEBUG, | 2707 | fh->message_id)); |
2388 | _("WLAN got ack but session->message_id_out %u and fragment id %u mismatch\n"), | 2708 | return; |
2389 | session->message_id_out, ntohl(fh->message_id)); | ||
2390 | #endif | ||
2391 | } | 2709 | } |
2392 | 2710 | ||
2393 | } | 2711 | } |
@@ -2406,6 +2724,16 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2406 | 2724 | ||
2407 | } | 2725 | } |
2408 | 2726 | ||
2727 | char * | ||
2728 | macprinter(struct MacAddress macx) | ||
2729 | { | ||
2730 | static char macstr[20]; | ||
2731 | char * mac = macx.mac; | ||
2732 | sprintf(macstr, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], | ||
2733 | mac[3], mac[4], mac[5]); | ||
2734 | return macstr; | ||
2735 | } | ||
2736 | |||
2409 | /** | 2737 | /** |
2410 | * Function used for to process the data from the suid process | 2738 | * Function used for to process the data from the suid process |
2411 | * | 2739 | * |
@@ -2482,8 +2810,8 @@ wlan_process_helper(void *cls, void *client, | |||
2482 | { | 2810 | { |
2483 | #if DEBUG_wlan | 2811 | #if DEBUG_wlan |
2484 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2812 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2485 | "Func wlan_process_helper got wrong MAC: %s\n", | 2813 | "Func wlan_process_helper got wrong MAC: %s\n", macprinter( |
2486 | wlanIeeeHeader->mac1); | 2814 | wlanIeeeHeader->mac1)); |
2487 | #endif | 2815 | #endif |
2488 | } | 2816 | } |
2489 | } | 2817 | } |
@@ -2491,13 +2819,11 @@ wlan_process_helper(void *cls, void *client, | |||
2491 | { | 2819 | { |
2492 | #if DEBUG_wlan | 2820 | #if DEBUG_wlan |
2493 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2821 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2494 | "Func wlan_process_helper got wrong BSSID: %s\n", | 2822 | "Func wlan_process_helper got wrong BSSID: %s\n", macprinter( |
2495 | wlanIeeeHeader->mac2); | 2823 | wlanIeeeHeader->mac2)); |
2496 | #endif | 2824 | #endif |
2497 | } | 2825 | } |
2498 | 2826 | ||
2499 | |||
2500 | |||
2501 | } | 2827 | } |
2502 | 2828 | ||
2503 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL) | 2829 | else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL) |
@@ -2527,7 +2853,7 @@ wlan_process_helper(void *cls, void *client, | |||
2527 | else | 2853 | else |
2528 | { | 2854 | { |
2529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n", | 2855 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n", |
2530 | plugin->mac_address); | 2856 | macprinter(plugin->mac_address)); |
2531 | } | 2857 | } |
2532 | 2858 | ||
2533 | } | 2859 | } |
@@ -2580,8 +2906,8 @@ wlan_plugin_helper_read(void *cls, | |||
2580 | #endif | 2906 | #endif |
2581 | return; | 2907 | return; |
2582 | } | 2908 | } |
2583 | GNUNET_SERVER_mst_receive(plugin->suid_tokenizer, NULL, mybuf, bytes, GNUNET_NO, | 2909 | GNUNET_SERVER_mst_receive(plugin->suid_tokenizer, NULL, mybuf, bytes, |
2584 | GNUNET_NO); | 2910 | GNUNET_NO, GNUNET_NO); |
2585 | 2911 | ||
2586 | GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); | 2912 | GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); |
2587 | plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( | 2913 | plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( |
@@ -2677,8 +3003,7 @@ libgnunet_plugin_transport_wlan_done(void *cls) | |||
2677 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); | 3003 | GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); |
2678 | 3004 | ||
2679 | if (plugin->data_tokenizer != NULL) | 3005 | if (plugin->data_tokenizer != NULL) |
2680 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); | 3006 | GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); |
2681 | |||
2682 | 3007 | ||
2683 | GNUNET_free_non_null(plugin->interface); | 3008 | GNUNET_free_non_null(plugin->interface); |
2684 | GNUNET_free (plugin); | 3009 | GNUNET_free (plugin); |
@@ -2731,7 +3056,8 @@ libgnunet_plugin_transport_wlan_init(void *cls) | |||
2731 | } | 3056 | } |
2732 | 3057 | ||
2733 | wlan_transport_start_wlan_helper(plugin, testmode); | 3058 | wlan_transport_start_wlan_helper(plugin, testmode); |
2734 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, plugin); | 3059 | plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, |
3060 | plugin); | ||
2735 | 3061 | ||
2736 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); | 3062 | plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); |
2737 | 3063 | ||
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 661792ffb..17007ab88 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -85,6 +85,8 @@ static int is_udp; | |||
85 | 85 | ||
86 | static int is_unix; | 86 | static int is_unix; |
87 | 87 | ||
88 | static int is_wlan; | ||
89 | |||
88 | static int connected; | 90 | static int connected; |
89 | 91 | ||
90 | static unsigned long long total_bytes; | 92 | static unsigned long long total_bytes; |
@@ -682,6 +684,11 @@ run (void *cls, | |||
682 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); | 684 | setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); |
683 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); | 685 | setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); |
684 | } | 686 | } |
687 | else if (is_wlan) | ||
688 | { | ||
689 | setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); | ||
690 | setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); | ||
691 | } | ||
685 | else | 692 | else |
686 | GNUNET_assert (0); | 693 | GNUNET_assert (0); |
687 | GNUNET_assert(p1.th != NULL); | 694 | GNUNET_assert(p1.th != NULL); |
@@ -807,6 +814,10 @@ main (int argc, char *argv[]) | |||
807 | is_unix = GNUNET_YES; | 814 | is_unix = GNUNET_YES; |
808 | GNUNET_asprintf(&test_name, "unix"); | 815 | GNUNET_asprintf(&test_name, "unix"); |
809 | } | 816 | } |
817 | else if (strstr(argv[0], "wlan") != NULL) | ||
818 | { | ||
819 | is_wlan = GNUNET_YES; | ||
820 | } | ||
810 | GNUNET_log_setup ("test-transport-api-reliability", | 821 | GNUNET_log_setup ("test-transport-api-reliability", |
811 | #if VERBOSE | 822 | #if VERBOSE |
812 | "DEBUG", | 823 | "DEBUG", |
diff --git a/src/transport/test_transport_api_wlan_peer1.conf b/src/transport/test_transport_api_wlan_peer1.conf index 62c10748a..ecfcebf64 100644 --- a/src/transport/test_transport_api_wlan_peer1.conf +++ b/src/transport/test_transport_api_wlan_peer1.conf | |||
@@ -10,6 +10,7 @@ AUTOSTART = NO | |||
10 | [transport-wlan] | 10 | [transport-wlan] |
11 | INTERFACE = wlan0 | 11 | INTERFACE = wlan0 |
12 | TESTMODE = 1 | 12 | TESTMODE = 1 |
13 | #PREFIX = gdbserver :2345 | ||
13 | 14 | ||
14 | [hostlist] | 15 | [hostlist] |
15 | HTTP-PROXY = | 16 | HTTP-PROXY = |
@@ -43,8 +44,10 @@ HOSTNAME = localhost | |||
43 | PORT = 12365 | 44 | PORT = 12365 |
44 | UNIXPATH = /tmp/gnunet-p1-service-transport.sock | 45 | UNIXPATH = /tmp/gnunet-p1-service-transport.sock |
45 | #PREFIX = xterm -T transport2 -e gdb --command=cmd --args | 46 | #PREFIX = xterm -T transport2 -e gdb --command=cmd --args |
47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 | ||
46 | #PREFIX = valgrind --leak-check=full | 48 | #PREFIX = valgrind --leak-check=full |
47 | #PREFIX = valgrind --tool=massif | 49 | #PREFIX = valgrind --tool=massif |
50 | #PREFIX = gdbserver :2345 | ||
48 | 51 | ||
49 | [peerinfo] | 52 | [peerinfo] |
50 | TRUST = $SERVICEHOME/data/credit/ | 53 | TRUST = $SERVICEHOME/data/credit/ |
diff --git a/src/transport/test_transport_api_wlan_peer2.conf b/src/transport/test_transport_api_wlan_peer2.conf index ce80062b3..eff0c2516 100644 --- a/src/transport/test_transport_api_wlan_peer2.conf +++ b/src/transport/test_transport_api_wlan_peer2.conf | |||
@@ -10,6 +10,7 @@ AUTOSTART = NO | |||
10 | [transport-wlan] | 10 | [transport-wlan] |
11 | INTERFACE = wlan1 | 11 | INTERFACE = wlan1 |
12 | TESTMODE = 2 | 12 | TESTMODE = 2 |
13 | #PREFIX = gdbserver :2346 | ||
13 | 14 | ||
14 | [hostlist] | 15 | [hostlist] |
15 | HTTP-PROXY = | 16 | HTTP-PROXY = |
@@ -43,8 +44,10 @@ HOSTNAME = localhost | |||
43 | PORT = 22365 | 44 | PORT = 22365 |
44 | UNIXPATH = /tmp/gnunet-p2-service-transport.sock | 45 | UNIXPATH = /tmp/gnunet-p2-service-transport.sock |
45 | #PREFIX = xterm -T transport1 -e gdb --command=cmd --args | 46 | #PREFIX = xterm -T transport1 -e gdb --command=cmd --args |
47 | #PREFIX = valgrind --leak-check=full --show-reachable=yes --main-stacksize=104857600 | ||
46 | #PREFIX = valgrind --leak-check=full | 48 | #PREFIX = valgrind --leak-check=full |
47 | #PREFIX = valgrind --tool=massif | 49 | #PREFIX = valgrind --tool=massif |
50 | #PREFIX = gdbserver :2346 | ||
48 | 51 | ||
49 | [peerinfo] | 52 | [peerinfo] |
50 | TRUST = $SERVICEHOME/data/credit/ | 53 | TRUST = $SERVICEHOME/data/credit/ |