aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_wlan.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-04-12 23:33:44 +0000
committerDavid Brodski <david@brodski.eu>2011-04-12 23:33:44 +0000
commitd47e8be9228c131f93441743c8e90b360d554e9d (patch)
tree9a5d82775a5e7c46ac4ba01784f129a2c8db387c /src/transport/plugin_transport_wlan.c
parentd8cd4422e9d88a0c8180976179662ae2e890db6d (diff)
downloadgnunet-d47e8be9228c131f93441743c8e90b360d554e9d.tar.gz
gnunet-d47e8be9228c131f93441743c8e90b360d554e9d.zip
Big cleanup and heap used for fragments send and with the timeouts
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r--src/transport/plugin_transport_wlan.c737
1 files changed, 405 insertions, 332 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 950ad9ccf..0564e9127 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -61,6 +61,7 @@
61#define HALLO_BEACON_SCALING_FACTOR 900 61#define HALLO_BEACON_SCALING_FACTOR 900
62 62
63#define DEBUG_wlan GNUNET_NO 63#define DEBUG_wlan GNUNET_NO
64#define DEBUG_wlan_retransmission GNUNET_NO
64 65
65#define MESSAGE_LENGHT_UNKNOWN -1 66#define MESSAGE_LENGHT_UNKNOWN -1
66//#define NO_MESSAGE_OR_MESSAGE_FINISHED -2 67//#define NO_MESSAGE_OR_MESSAGE_FINISHED -2
@@ -194,17 +195,7 @@ struct Plugin
194 /** 195 /**
195 * Messages in the fragmentation queue, head 196 * Messages in the fragmentation queue, head
196 */ 197 */
197 struct FragmentMessage * pending_Fragment_Messages_head; 198 struct GNUNET_CONTAINER_Heap * pending_Fragment_Messages;
198
199 /**
200 * Messages in the fragmentation queue, tail
201 */
202 struct FragmentMessage * pending_Fragment_Messages_tail;
203
204 /**
205 * number of pending fragment message
206 */
207 unsigned int pending_fragment_messages;
208 199
209 /** 200 /**
210 * Messages in the in Queue, head 201 * Messages in the in Queue, head
@@ -247,6 +238,7 @@ struct Finish_send
247 char * msgheader; 238 char * msgheader;
248 struct GNUNET_MessageHeader * msgstart; 239 struct GNUNET_MessageHeader * msgstart;
249 ssize_t size; 240 ssize_t size;
241 struct GNUNET_TIME_Absolute next_send;
250}; 242};
251 243
252/** 244/**
@@ -273,6 +265,17 @@ struct Receive_Fragment_Queue
273 struct Radiotap_rx rxinfo; 265 struct Radiotap_rx rxinfo;
274}; 266};
275 267
268struct Session_id_pair
269{
270 struct Session * session;
271 uint32_t message_id;
272};
273
274struct Plugin_Session_pair
275{
276 struct Plugin * plugin;
277 struct Session * session;
278};
276 279
277/** 280/**
278 * Queue for the fragments received 281 * Queue for the fragments received
@@ -477,6 +480,11 @@ struct Session
477struct FragmentMessage 480struct FragmentMessage
478{ 481{
479 /** 482 /**
483 * heap pointer of this message
484 */
485 struct GNUNET_CONTAINER_HeapNode * node;
486
487 /**
480 * Session this message belongs to 488 * Session this message belongs to
481 */ 489 */
482 490
@@ -498,6 +506,13 @@ struct FragmentMessage
498 char *msg; 506 char *msg;
499 507
500 /** 508 /**
509 * 0 if not in ack queue
510 * 1 if in ack queue
511 */
512
513 char in_ack_queue;
514
515 /**
501 * Timeout value for the pending message. 516 * Timeout value for the pending message.
502 */ 517 */
503 struct GNUNET_TIME_Absolute timeout; 518 struct GNUNET_TIME_Absolute timeout;
@@ -550,11 +565,10 @@ struct FragmentationAckHeader
550 565
551}; 566};
552 567
553static void 568static struct FragmentMessage * return_val;
554do_transmit(void *cls,
555 const struct GNUNET_SCHEDULER_TaskContext *tc);
556
557 569
570static void
571do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
558 572
559/** 573/**
560 * Sets a bit active in the bitArray. Increment bit-specific 574 * Sets a bit active in the bitArray. Increment bit-specific
@@ -574,7 +588,6 @@ setBit(char *bitArray, unsigned int bitIdx)
574 bitArray[arraySlot] |= targetBit; 588 bitArray[arraySlot] |= targetBit;
575} 589}
576 590
577
578/** 591/**
579 * Checks if a bit is active in the bitArray 592 * Checks if a bit is active in the bitArray
580 * 593 *
@@ -602,10 +615,9 @@ testBit(char *bitArray, unsigned int bitIdx)
602static uint32_t 615static uint32_t
603get_next_message_id() 616get_next_message_id()
604{ 617{
605 return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 618 return GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
606} 619}
607 620
608
609/** 621/**
610 * search for a session with the addr 622 * search for a session with the addr
611 * 623 *
@@ -614,22 +626,50 @@ get_next_message_id()
614 * @return returns the session 626 * @return returns the session
615 */ 627 */
616static struct Session * 628static struct Session *
617search_session(struct Plugin *plugin, 629search_session(struct Plugin *plugin, const struct MacAddress *addr)
618 const struct MacAddress *addr)
619{ 630{
620 struct Sessionqueue * queue = plugin->sessions; 631 struct Sessionqueue * queue = plugin->sessions;
621 632
622 while (queue != NULL) 633 while (queue != NULL)
623 { 634 {
624 GNUNET_assert (queue->content != NULL); 635 GNUNET_assert (queue->content != NULL);
625 if (memcmp(addr, &queue->content->addr, sizeof (struct MacAddress)) == 0) 636 if (memcmp(addr, &queue->content->addr, sizeof(struct MacAddress)) == 0)
626 return queue->content; /* session found */ 637 return queue->content; /* session found */
627 queue = queue->next; 638 queue = queue->next;
628 } 639 }
629 return NULL; 640 return NULL;
630} 641}
631 642
632/** 643/**
644 * Function called for a quick conversion of the binary address to
645 * a numeric address. Note that the caller must not free the
646 * address and that the next call to this function is allowed
647 * to override the address again.
648 *
649 * @param cls closure
650 * @param addr binary address
651 * @param addrlen length of the address
652 * @return string representing the same address
653 */
654static const char*
655wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
656{
657 static char ret[40];
658 const struct MacAddress *mac;
659
660 if (addrlen != sizeof(struct MacAddress))
661 {
662 GNUNET_break (0);
663 return NULL;
664 }
665 mac = addr;
666 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
667 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3],
668 mac->mac[4], mac->mac[5]);
669 return ret;
670}
671
672/**
633 * create a new session 673 * create a new session
634 * 674 *
635 * @param plugin pointer to the plugin struct 675 * @param plugin pointer to the plugin struct
@@ -638,8 +678,7 @@ search_session(struct Plugin *plugin,
638 */ 678 */
639 679
640static struct Session * 680static struct Session *
641create_session(struct Plugin *plugin, 681create_session(struct Plugin *plugin, const struct MacAddress * addr)
642 const struct MacAddress * addr)
643{ 682{
644 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue)); 683 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue));
645 684
@@ -661,7 +700,6 @@ create_session(struct Plugin *plugin,
661 return queue->content; 700 return queue->content;
662} 701}
663 702
664
665/** 703/**
666 * Get session from address, create if no session exists 704 * Get session from address, create if no session exists
667 * 705 *
@@ -670,8 +708,7 @@ create_session(struct Plugin *plugin,
670 * @return returns the session 708 * @return returns the session
671 */ 709 */
672static struct Session * 710static struct Session *
673get_Session (struct Plugin *plugin, 711get_session(struct Plugin *plugin, const struct MacAddress *addr)
674 const struct MacAddress *addr)
675{ 712{
676 struct Session * session = search_session(plugin, addr); 713 struct Session * session = search_session(plugin, addr);
677 if (session != NULL) 714 if (session != NULL)
@@ -679,41 +716,45 @@ get_Session (struct Plugin *plugin,
679 return create_session(plugin, addr); 716 return create_session(plugin, addr);
680} 717}
681 718
682
683/** 719/**
684 * Queue the session to send data 720 * Queue the session to send data
721 * checks if there is a message pending
722 * checks if this session is not allready in the queue
723 * @param plugin pointer to the plugin
724 * @param session pointer to the session to add
685 */ 725 */
686//TODO doxigen
687static void 726static void
688queue_Session(struct Plugin *plugin, struct Session * session) 727queue_session(struct Plugin *plugin, struct Session * session)
689{ 728{
690 struct Sessionqueue * queue = plugin->pending_Sessions; 729 struct Sessionqueue * queue = plugin->pending_Sessions;
691 struct Sessionqueue * lastitem = NULL; 730 struct Sessionqueue * lastitem = NULL;
692 731
693 while (queue != NULL) 732 if (session->pending_message != NULL)
694 { 733 {
695 // content is never NULL 734 while (queue != NULL)
696 GNUNET_assert (queue->content != NULL);
697 // is session already in queue?
698 if (session == queue->content)
699 { 735 {
700 return; 736 // content is never NULL
737 GNUNET_assert (queue->content != NULL);
738 // is session already in queue?
739 if (session == queue->content)
740 {
741 return;
742 }
743 // try next
744 lastitem = queue;
745 queue = queue->next;
701 } 746 }
702 // try next
703 lastitem = queue;
704 queue = queue->next;
705 }
706 747
707 // Session is not in the queue 748 // Session is not in the queue
708 749
709 queue = GNUNET_malloc (sizeof (struct Sessionqueue)); 750 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
710 queue->content = session; 751 queue->content = session;
711 752
712 //insert at the tail 753 //insert at the tail
713 GNUNET_CONTAINER_DLL_insert_after (plugin->pending_Sessions, 754 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions,
714 plugin->pending_Sessions_tail, 755 plugin->pending_Sessions_tail, queue);
715 plugin->pending_Sessions_tail, queue); 756 plugin->pendingsessions++;
716 plugin->pendingsessions++; 757 }
717 758
718} 759}
719 760
@@ -792,11 +833,12 @@ get_ack_timeout(struct FragmentMessage * fm)
792 * Function to set the timer for the next timeout of the fragment queue 833 * Function to set the timer for the next timeout of the fragment queue
793 * @param plugin the handle to the plugin struct 834 * @param plugin the handle to the plugin struct
794 */ 835 */
836
795static void 837static void
796check_next_fragment_timeout(struct Plugin * const plugin) 838set_next_send(struct Plugin * const plugin)
797{ 839{
798 struct FragmentMessage * fm; 840 struct FragmentMessage * fm;
799 struct GNUNET_TIME_Relative next_send; 841 struct GNUNET_TIME_Relative next_send = GNUNET_TIME_UNIT_FOREVER_REL;
800 842
801 //cancel old task 843 //cancel old task
802 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 844 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
@@ -804,36 +846,52 @@ check_next_fragment_timeout(struct Plugin * const plugin)
804 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); 846 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task);
805 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 847 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
806 } 848 }
807 fm = plugin->pending_Fragment_Messages_head;
808 849
809 GNUNET_assert(plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK); 850 fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages);
810 851
811 //check if some acks are in the queue 852 //check if some acks are in the queue
812 if (plugin->ack_send_queue_head != NULL) 853 if (plugin->ack_send_queue_head != NULL)
813 { 854 {
814 next_send = GNUNET_TIME_UNIT_ZERO; 855 next_send = GNUNET_TIME_UNIT_ZERO;
815 } 856 }
857
816 //check if there are some fragments in the queue 858 //check if there are some fragments in the queue
817 else 859 else
818 { 860 {
819 next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); 861 next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time);
820 if (fm != NULL) 862 if (fm != NULL)
821 { 863 {
822 next_send = GNUNET_TIME_relative_min(next_send, 864 if (GNUNET_CONTAINER_node_get_cost(fm->node) != 0)
823 get_next_frag_timeout(fm)); 865 {
866 next_send = GNUNET_TIME_relative_min(next_send,
867 get_next_frag_timeout(fm));
868 }
869 else
870 {
871 next_send = GNUNET_TIME_UNIT_ZERO;
872 }
824 } 873 }
825 } 874 }
875
876#if DEBUG_wlan
877
878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Next packet is send in: %u\n",
879 next_send.rel_value);
880
881#endif
882
826 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, 883 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send,
827 &delay_fragment_task, plugin); 884 &delay_fragment_task, plugin);
885
828} 886}
829 887
830//TODO doxigen
831/** 888/**
832 * Function to get the next queued Session, removes the session from the queue 889 * Function to get the next queued Session, removes the session from the queue
890 * @param plugin pointer to the plugin struct
891 * @return pointer to the session found, returns NULL if there is now session in the queue
833 */ 892 */
834
835static struct Session * 893static struct Session *
836get_next_queue_Session(struct Plugin * plugin) 894get_next_queue_session(struct Plugin * plugin)
837{ 895{
838 struct Session * session; 896 struct Session * session;
839 struct Sessionqueue * sessionqueue; 897 struct Sessionqueue * sessionqueue;
@@ -845,14 +903,15 @@ get_next_queue_Session(struct Plugin * plugin)
845 session = sessionqueue->content; 903 session = sessionqueue->content;
846 904
847 pm = session->pending_message; 905 pm = session->pending_message;
906
907#if DEBUG_wlan
848 if (pm == NULL) 908 if (pm == NULL)
849 { 909 {
850#if DEBUG_wlan
851 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 910 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
852 "pending message is empty, should not happen. session %p\n", 911 "pending message is empty, should not happen. session %p\n",
853 session); 912 session);
854#endif
855 } 913 }
914#endif
856 GNUNET_assert(pm != NULL); 915 GNUNET_assert(pm != NULL);
857 916
858 //check for message timeout 917 //check for message timeout
@@ -905,38 +964,6 @@ get_next_queue_Session(struct Plugin * plugin)
905} 964}
906 965
907/** 966/**
908 * Function to sort the message into the message fragment queue
909 * @param plugin the plugin struct
910 * @param fm message to sort into the queue
911 */
912static void
913sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm)
914{
915 struct FragmentMessage * fm2;
916 //sort into the list at the right position
917
918 fm2 = plugin->pending_Fragment_Messages_head;
919
920 while (fm2 != NULL)
921 {
922 if (GNUNET_TIME_absolute_get_difference(fm2->next_ack, fm->next_ack).rel_value
923 == 0)
924 {
925 GNUNET_CONTAINER_DLL_insert_before(plugin->pending_Fragment_Messages_head,
926 plugin->pending_Fragment_Messages_tail,fm2,fm);
927 return;
928 }
929 else
930 {
931 fm2 = fm2->next;
932 }
933 }
934
935 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head,
936 plugin->pending_Fragment_Messages_tail,fm);
937}
938
939/**
940 * frees the space of a message in the fragment queue (send queue) 967 * frees the space of a message in the fragment queue (send queue)
941 * @param plugin the plugin struct 968 * @param plugin the plugin struct
942 * @param fm message to free 969 * @param fm message to free
@@ -944,19 +971,20 @@ sort_fragment_into_queue(struct Plugin * plugin, struct FragmentMessage * fm)
944static void 971static void
945free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) 972free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
946{ 973{
974 struct Session * session = fm->session;
975
947 if (fm != NULL) 976 if (fm != NULL)
948 { 977 {
949 (fm->session->fragment_messages_out_count)--; 978 (session->fragment_messages_out_count)--;
950 GNUNET_free_non_null(fm->msg); 979 GNUNET_free_non_null(fm->msg);
951 GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head, 980 GNUNET_CONTAINER_heap_remove_node(fm->node);
952 plugin->pending_Fragment_Messages_tail, fm);
953 GNUNET_free(fm); 981 GNUNET_free(fm);
954 plugin->pending_fragment_messages--;
955 982
983 queue_session(plugin, session);
956#if DEBUG_wlan 984#if DEBUG_wlan
957 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 985 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
958 "free pending fragment messages, pending messages remaining %u\n", 986 "free pending fragment messages, pending messages remaining %u\n",
959 plugin->pending_fragment_messages); 987 GNUNET_CONTAINER_heap_get_size(plugin->pending_Fragment_Messages));
960#endif 988#endif
961 } 989 }
962} 990}
@@ -976,9 +1004,10 @@ check_fragment_queue(struct Plugin * plugin)
976 1004
977 struct PendingMessage * pm; 1005 struct PendingMessage * pm;
978 1006
979 if (plugin->pending_fragment_messages < FRAGMENT_QUEUE_SIZE) 1007 if (GNUNET_CONTAINER_heap_get_size(plugin->pending_Fragment_Messages)
1008 < FRAGMENT_QUEUE_SIZE)
980 { 1009 {
981 session = get_next_queue_Session(plugin); 1010 session = get_next_queue_session(plugin);
982 if (session != NULL) 1011 if (session != NULL)
983 { 1012 {
984 pm = session->pending_message; 1013 pm = session->pending_message;
@@ -995,9 +1024,8 @@ check_fragment_queue(struct Plugin * plugin)
995 fm->next_ack = GNUNET_TIME_absolute_get(); 1024 fm->next_ack = GNUNET_TIME_absolute_get();
996 fm->message_id_out = get_next_message_id(); 1025 fm->message_id_out = get_next_message_id();
997 fm->ack_bitfield = 0; 1026 fm->ack_bitfield = 0;
998 1027 fm->node = GNUNET_CONTAINER_heap_insert(
999 sort_fragment_into_queue(plugin, fm); 1028 plugin->pending_Fragment_Messages, fm, 0);
1000 plugin->pending_fragment_messages++;
1001 1029
1002 if (pm->transmit_cont != NULL) 1030 if (pm->transmit_cont != NULL)
1003 { 1031 {
@@ -1022,13 +1050,14 @@ check_fragment_queue(struct Plugin * plugin)
1022 session->pending_message = session->pending_message2; 1050 session->pending_message = session->pending_message2;
1023 session->pending_message2 = NULL; 1051 session->pending_message2 = NULL;
1024 //requeue session 1052 //requeue session
1025 queue_Session(plugin, session); 1053 queue_session(plugin, session);
1026 } 1054 }
1027 1055
1028 //check if timeout changed
1029 check_next_fragment_timeout(plugin);
1030 } 1056 }
1031 } 1057 }
1058
1059 //check if timeout changed
1060 set_next_send(plugin);
1032} 1061}
1033 1062
1034/** 1063/**
@@ -1056,14 +1085,16 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
1056 if (fm->ack_bitfield == tmpfield) 1085 if (fm->ack_bitfield == tmpfield)
1057 { 1086 {
1058 1087
1059 free_fragment_message(plugin, fm); 1088#if DEBUG_wlan_retransmission
1060
1061#if DEBUG_wlan
1062 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1089 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1063 "Finished sending and got all acks for a fragmented message\n"); 1090 "Finished sending and got all acks; message_id %u\n",
1091 fm->message_id_out);
1064#endif 1092#endif
1065 1093
1066 check_next_fragment_timeout(plugin); 1094 free_fragment_message(plugin, fm);
1095
1096
1097
1067 check_fragment_queue(plugin); 1098 check_fragment_queue(plugin);
1068 1099
1069 } 1100 }
@@ -1075,9 +1106,12 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
1075 */ 1106 */
1076 1107
1077static void 1108static void
1078set_next_message_fragment_pos(struct FragmentMessage * fm) 1109set_next_message_fragment_pos(struct Plugin * plugin,
1110 struct FragmentMessage * fm)
1079{ 1111{
1080 1112
1113 fm->message_pos++;
1114
1081 //check if retransmit is needed 1115 //check if retransmit is needed
1082 if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0) 1116 if (GNUNET_TIME_absolute_get_remaining(fm->next_ack).rel_value == 0)
1083 { 1117 {
@@ -1087,6 +1121,15 @@ set_next_message_fragment_pos(struct FragmentMessage * fm)
1087 // find first missing fragment 1121 // find first missing fragment
1088 1122
1089 fm->message_pos = 0; 1123 fm->message_pos = 0;
1124
1125 GNUNET_CONTAINER_heap_update_cost(plugin->pending_Fragment_Messages,
1126 fm->node, 0);
1127
1128#if DEBUG_wlan_retransmission
1129 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1130 "Retransmit; message_id %u; fragment number %i, size: %u\n",
1131 fm->message_id_out, fm->message_pos, fm->message_size);
1132#endif
1090 } 1133 }
1091 1134
1092 //test if ack 0 (or X) was already received 1135 //test if ack 0 (or X) was already received
@@ -1118,7 +1161,6 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session,
1118 return GNUNET_YES; 1161 return GNUNET_YES;
1119} 1162}
1120 1163
1121
1122/** 1164/**
1123 * function to generate the wlan hardware header for one packet 1165 * function to generate the wlan hardware header for one packet
1124 * @param Header address to write the header to 1166 * @param Header address to write the header to
@@ -1127,9 +1169,8 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session,
1127 * @return GNUNET_YES if there was no error 1169 * @return GNUNET_YES if there was no error
1128 */ 1170 */
1129static int 1171static int
1130getWlanHeader(struct ieee80211_frame * Header, 1172getWlanHeader(struct ieee80211_frame * Header,
1131 const struct MacAddress * to_mac_addr, 1173 const struct MacAddress * to_mac_addr, struct Plugin * plugin)
1132 struct Plugin * plugin)
1133{ 1174{
1134 Header->i_fc[0] = 0x80; 1175 Header->i_fc[0] = 0x80;
1135 Header->i_fc[1] = 0x00; 1176 Header->i_fc[1] = 0x00;
@@ -1171,7 +1212,6 @@ getcrc16(const char *msgbuf, size_t msgbuf_size)
1171 return 0; 1212 return 0;
1172} 1213}
1173 1214
1174
1175static void 1215static void
1176send_hello_beacon(struct Plugin * plugin) 1216send_hello_beacon(struct Plugin * plugin)
1177{ 1217{
@@ -1182,16 +1222,17 @@ send_hello_beacon(struct Plugin * plugin)
1182 1222
1183 uint16_t size; 1223 uint16_t size;
1184 ssize_t bytes; 1224 ssize_t bytes;
1225 uint16_t hallo_size;
1185 struct GNUNET_MessageHeader * msgheader; 1226 struct GNUNET_MessageHeader * msgheader;
1186 struct ieee80211_frame * ieeewlanheader; 1227 struct ieee80211_frame * ieeewlanheader;
1187 struct Radiotap_Send * radioHeader; 1228 struct Radiotap_Send * radioHeader;
1188 struct GNUNET_MessageHeader * msgheader2; 1229 struct GNUNET_MessageHeader * msgheader2;
1189 1230
1190 GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size( 1231 hallo_size = GNUNET_HELLO_size(*(plugin->env->our_hello));
1191 *(plugin->env->our_hello)) <= WLAN_MTU); 1232 GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU);
1192 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1233 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
1193 + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader) 1234 + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)
1194 + GNUNET_HELLO_size(*(plugin->env->our_hello)); 1235 + hallo_size;
1195 1236
1196 msgheader = GNUNET_malloc(size); 1237 msgheader = GNUNET_malloc(size);
1197 msgheader->size = htons(size); 1238 msgheader->size = htons(size);
@@ -1207,8 +1248,7 @@ send_hello_beacon(struct Plugin * plugin)
1207 + sizeof(struct GNUNET_MessageHeader)); 1248 + sizeof(struct GNUNET_MessageHeader));
1208 1249
1209 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); 1250 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
1210 memcpy(&msgheader2[1], *plugin->env->our_hello, GNUNET_HELLO_size( 1251 memcpy(&msgheader2[1], *plugin->env->our_hello, hallo_size);
1211 *(plugin->env->our_hello)));
1212 1252
1213 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); 1253 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size);
1214 1254
@@ -1224,7 +1264,7 @@ send_hello_beacon(struct Plugin * plugin)
1224 GNUNET_free(msgheader); 1264 GNUNET_free(msgheader);
1225 1265
1226 set_next_beacon_time(plugin); 1266 set_next_beacon_time(plugin);
1227 check_next_fragment_timeout(plugin); 1267 set_next_send(plugin);
1228} 1268}
1229 1269
1230static void 1270static void
@@ -1276,7 +1316,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1276 GNUNET_assert(bytes != GNUNET_SYSERR); 1316 GNUNET_assert(bytes != GNUNET_SYSERR);
1277 GNUNET_assert(bytes == size); 1317 GNUNET_assert(bytes == size);
1278 GNUNET_free(msgheader); 1318 GNUNET_free(msgheader);
1279 check_next_fragment_timeout(plugin); 1319 set_next_send(plugin);
1280} 1320}
1281 1321
1282static void 1322static void
@@ -1295,7 +1335,6 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1295 finish->msgheader, finish->size); 1335 finish->msgheader, finish->size);
1296 GNUNET_assert(bytes != GNUNET_SYSERR); 1336 GNUNET_assert(bytes != GNUNET_SYSERR);
1297 1337
1298 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1299 if (bytes != finish->size) 1338 if (bytes != finish->size)
1300 { 1339 {
1301 1340
@@ -1309,12 +1348,12 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1309 { 1348 {
1310 GNUNET_free(finish->msgstart); 1349 GNUNET_free(finish->msgstart);
1311 GNUNET_free(finish); 1350 GNUNET_free(finish);
1312 check_next_fragment_timeout(plugin);
1313 }
1314 1351
1315} 1352 set_next_send(plugin);
1316 1353
1354 }
1317 1355
1356}
1318 1357
1319/** 1358/**
1320 * Function called when wlan helper is ready to get some data 1359 * Function called when wlan helper is ready to get some data
@@ -1332,21 +1371,22 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1332 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1371 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1333 return; 1372 return;
1334 1373
1335 struct Session * session = NULL; 1374 struct Session * session;
1336 struct FragmentMessage * fm = NULL; 1375 struct FragmentMessage * fm;
1337 struct ieee80211_frame * ieeewlanheader = NULL; 1376 struct ieee80211_frame * ieeewlanheader;
1338 struct Radiotap_Send * radioHeader = NULL; 1377 struct Radiotap_Send * radioHeader;
1339 struct GNUNET_MessageHeader * msgheader = NULL; 1378 struct GNUNET_MessageHeader * msgheader;
1340 1379
1341 struct FragmentationHeader fragheader; 1380 struct FragmentationHeader fragheader;
1342 struct FragmentationHeader * fragheaderptr = NULL; 1381 struct FragmentationHeader * fragheaderptr;
1343 struct Finish_send * finish = NULL; 1382 struct Finish_send * finish;
1344 struct AckSendQueue * ack; 1383 struct AckSendQueue * ack;
1345 uint16_t size = 0; 1384 uint16_t size;
1346 ssize_t bytes; 1385 ssize_t bytes;
1347 const char * copystart = NULL; 1386 const char * copystart;
1348 uint16_t copysize = 0; 1387 uint16_t copysize;
1349 uint copyoffset = 0; 1388 uint copyoffset;
1389 struct GNUNET_TIME_Absolute next_send;
1350 1390
1351 if (plugin->ack_send_queue_head != NULL) 1391 if (plugin->ack_send_queue_head != NULL)
1352 { 1392 {
@@ -1367,7 +1407,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1367 1407
1368 } 1408 }
1369 1409
1370 fm = plugin->pending_Fragment_Messages_head; 1410 fm = GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages);
1411
1371 if (fm != NULL) 1412 if (fm != NULL)
1372 { 1413 {
1373 session = fm->session; 1414 session = fm->session;
@@ -1380,8 +1421,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1380 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n"); 1421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "message timeout\n");
1381#endif 1422#endif
1382 1423
1383 check_fragment_queue(plugin);
1384 free_fragment_message(plugin, fm); 1424 free_fragment_message(plugin, fm);
1425 check_fragment_queue(plugin);
1385 1426
1386 } 1427 }
1387 else 1428 else
@@ -1391,13 +1432,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1391 // { 1432 // {
1392 size = sizeof(struct FragmentationHeader); 1433 size = sizeof(struct FragmentationHeader);
1393 1434
1394 set_next_message_fragment_pos(fm); 1435 set_next_message_fragment_pos(plugin, fm);
1395 1436
1396 copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader)) 1437 copyoffset = (WLAN_MTU - sizeof(struct FragmentationHeader))
1397 * fm->message_pos; 1438 * fm->message_pos;
1398 1439
1399
1400
1401 fragheader.fragment_off_or_num = htons(fm->message_pos); 1440 fragheader.fragment_off_or_num = htons(fm->message_pos);
1402 fragheader.message_id = htonl(fm->message_id_out); 1441 fragheader.message_id = htonl(fm->message_id_out);
1403 copystart = fm->msg + copyoffset; 1442 copystart = fm->msg + copyoffset;
@@ -1478,6 +1517,27 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1478 } 1517 }
1479 GNUNET_assert(bytes != GNUNET_SYSERR); 1518 GNUNET_assert(bytes != GNUNET_SYSERR);
1480 1519
1520 //check if this was the last fragment of this message, if true then queue at the end of the list
1521 if (copysize + copyoffset >= fm->message_size)
1522 {
1523 GNUNET_assert(copysize + copyoffset == fm->message_size);
1524
1525 GNUNET_CONTAINER_heap_update_cost(
1526 plugin->pending_Fragment_Messages, fm->node, MIN(
1527 fm->timeout.abs_value, fm->next_ack.abs_value));
1528 // if fragments have opimized timeouts
1529 //sort_fragment_into_queue(plugin,fm);
1530
1531#if DEBUG_wlan_retransmission
1532 GNUNET_log(
1533 GNUNET_ERROR_TYPE_DEBUG,
1534 "Finished sending all fragments waiting for acks; message_id %u; message_id %u; fragment number %i, size: %u, time until timeout %u\n",
1535 fm->message_id_out, fm->message_id_out, fm->message_pos,
1536 fm->message_size, GNUNET_TIME_absolute_get_remaining(
1537 fm->timeout));
1538#endif
1539 }
1540
1481 if (bytes != size) 1541 if (bytes != size)
1482 { 1542 {
1483 finish = GNUNET_malloc(sizeof( struct Finish_send)); 1543 finish = GNUNET_malloc(sizeof( struct Finish_send));
@@ -1485,6 +1545,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1485 finish->msgheader = (char *) msgheader + bytes; 1545 finish->msgheader = (char *) msgheader + bytes;
1486 finish->size = size - bytes; 1546 finish->size = size - bytes;
1487 finish->msgstart = msgheader; 1547 finish->msgstart = msgheader;
1548 finish ->next_send = next_send;
1488 1549
1489 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); 1550 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1490 1551
@@ -1496,24 +1557,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1496 else 1557 else
1497 { 1558 {
1498 GNUNET_assert(bytes == size); 1559 GNUNET_assert(bytes == size);
1499
1500 GNUNET_free(msgheader); 1560 GNUNET_free(msgheader);
1501 check_next_fragment_timeout(plugin); 1561 set_next_send(plugin);
1502 }
1503
1504 //check if this was the last fragment of this message, if true then queue at the end of the list
1505 if (copysize + copyoffset >= fm->message_size)
1506 {
1507 GNUNET_assert(copysize + copyoffset == fm->message_size);
1508
1509 GNUNET_CONTAINER_DLL_remove (plugin->pending_Fragment_Messages_head,
1510 plugin->pending_Fragment_Messages_tail, fm);
1511
1512 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Fragment_Messages_head,
1513 plugin->pending_Fragment_Messages_tail, fm);
1514 // if fragments have opimized timeouts
1515 //sort_fragment_into_queue(plugin,fm);
1516
1517 } 1562 }
1518 1563
1519 } 1564 }
@@ -1523,7 +1568,6 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1523 "do_transmit did nothing, should not happen!\n"); 1568 "do_transmit did nothing, should not happen!\n");
1524} 1569}
1525 1570
1526
1527/** 1571/**
1528 * Another peer has suggested an address for this 1572 * Another peer has suggested an address for this
1529 * peer and transport plugin. Check that this could be a valid 1573 * peer and transport plugin. Check that this could be a valid
@@ -1556,8 +1600,6 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
1556 return GNUNET_SYSERR; 1600 return GNUNET_SYSERR;
1557} 1601}
1558 1602
1559
1560
1561/** 1603/**
1562 * Function that can be used by the transport service to transmit 1604 * Function that can be used by the transport service to transmit
1563 * a message using the plugin. 1605 * a message using the plugin.
@@ -1567,7 +1609,7 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
1567 * @param priority how important is the message 1609 * @param priority how important is the message
1568 * @param msgbuf the message to transmit 1610 * @param msgbuf the message to transmit
1569 * @param msgbuf_size number of bytes in 'msgbuf' 1611 * @param msgbuf_size number of bytes in 'msgbuf'
1570 * @param timeout when should we time out 1612 * @param timeout when should we time out
1571 * @param session which session must be used (or NULL for "any") 1613 * @param session which session must be used (or NULL for "any")
1572 * @param addr the address to use (can be NULL if the plugin 1614 * @param addr the address to use (can be NULL if the plugin
1573 * is "on its own" (i.e. re-use existing TCP connection)) 1615 * is "on its own" (i.e. re-use existing TCP connection))
@@ -1592,8 +1634,8 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1592 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1634 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1593{ 1635{
1594 struct Plugin * plugin = cls; 1636 struct Plugin * plugin = cls;
1595 struct PendingMessage * newmsg = NULL; 1637 struct PendingMessage * newmsg;
1596 struct WlanHeader * wlanheader = NULL; 1638 struct WlanHeader * wlanheader;
1597 1639
1598 //check if msglen > 0 1640 //check if msglen > 0
1599 GNUNET_assert(msgbuf_size > 0); 1641 GNUNET_assert(msgbuf_size > 0);
@@ -1603,7 +1645,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1603 { 1645 {
1604 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) 1646 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK)
1605 { 1647 {
1606 session = get_Session(plugin, addr); 1648 session = get_session(plugin, addr);
1607 } 1649 }
1608 else 1650 else
1609 { 1651 {
@@ -1677,7 +1719,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1677#endif 1719#endif
1678 1720
1679 //queue session 1721 //queue session
1680 queue_Session(plugin, session); 1722 queue_session(plugin, session);
1681 1723
1682 check_fragment_queue(plugin); 1724 check_fragment_queue(plugin);
1683 //FIXME not the correct size 1725 //FIXME not the correct size
@@ -1686,23 +1728,58 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1686} 1728}
1687 1729
1688/** 1730/**
1689 * function to get the first message in the fragement queue (out) of a session 1731 * Iterate over the fragment messages of the given session.
1690 * @param session pointer to the session 1732 *
1691 * @return pointer to the struct FragmentMessage 1733 * @param cls argument to give to iterator
1734 * @param node node to iterate over
1735 * @param element value stored at the node
1736 * @param cost cost associated with the node
1737 * @return GNUNET_YES if we should continue to iterate,
1738 * GNUNET_NO if not.
1692 */ 1739 */
1693static struct FragmentMessage * 1740static int
1694get_fragment_message_from_session(struct Session * session) 1741free_fragment_message_from_session(void *cls,
1742 struct GNUNET_CONTAINER_HeapNode *node, void *element,
1743 GNUNET_CONTAINER_HeapCostType cost)
1695{ 1744{
1696 struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head; 1745 struct Plugin_Session_pair * pair = (struct Plugin_Session_pair *) cls;
1697 while (fm != NULL) 1746 struct FragmentMessage * fm = (struct FragmentMessage*) element;
1747
1748 if (fm->session == pair->session)
1698 { 1749 {
1699 if (fm->session == session) 1750
1700 { 1751 free_fragment_message(pair->plugin, fm);
1701 return fm;
1702 }
1703 fm = fm->next;
1704 } 1752 }
1705 return NULL; 1753 return GNUNET_YES;
1754
1755}
1756
1757/**
1758 * Search for fragment message with given id and session
1759 *
1760 * @param cls argument to give to iterator
1761 * @param node node to iterate over
1762 * @param element value stored at the node
1763 * @param cost cost associated with the node
1764 * @return GNUNET_YES if we should continue to iterate,
1765 * GNUNET_NO if not.
1766 */
1767static int
1768search_fragment_message_from_session_and_id(void *cls,
1769 struct GNUNET_CONTAINER_HeapNode *node, void *element,
1770 GNUNET_CONTAINER_HeapCostType cost)
1771{
1772 struct Session_id_pair * pair = (struct Session_id_pair *) cls;
1773 struct FragmentMessage * fm = (struct FragmentMessage*) element;
1774
1775 if ((fm->session == pair->session)
1776 && (fm->message_id_out == pair->message_id))
1777 {
1778 return_val = fm;
1779 return GNUNET_NO;
1780 }
1781 return GNUNET_YES;
1782
1706} 1783}
1707 1784
1708/** 1785/**
@@ -1712,22 +1789,17 @@ get_fragment_message_from_session(struct Session * session)
1712 * @return pointer to the struct FragmentMessage 1789 * @return pointer to the struct FragmentMessage
1713 */ 1790 */
1714static struct FragmentMessage * 1791static struct FragmentMessage *
1715get_fragment_message_from_session_and_id(struct Session * session, 1792get_fragment_message_from_session_and_id(struct Plugin * plugin,
1716 uint32_t message_id) 1793 struct Session * session, uint32_t message_id)
1717{ 1794{
1718 struct FragmentMessage * fm = session->plugin->pending_Fragment_Messages_head; 1795 struct Session_id_pair pair;
1719 while (fm != NULL) 1796 pair.session = session;
1720 { 1797 pair.message_id = message_id;
1721 if ((fm->session == session) && (fm->message_id_out == message_id)) 1798 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages,
1722 { 1799 &search_fragment_message_from_session_and_id, &pair);
1723 return fm; 1800 return return_val;
1724 }
1725 fm = fm->next;
1726 }
1727 return NULL;
1728} 1801}
1729 1802
1730
1731/** 1803/**
1732 * function to get the receive message of a session 1804 * function to get the receive message of a session
1733 * @param plugin pointer to the plugin struct 1805 * @param plugin pointer to the plugin struct
@@ -1749,7 +1821,6 @@ get_receive_message_from_session(struct Plugin * plugin,
1749 return NULL; 1821 return NULL;
1750} 1822}
1751 1823
1752
1753/** 1824/**
1754 * Function to dispose the fragments received for a message and the message 1825 * Function to dispose the fragments received for a message and the message
1755 * @param plugin pointer to the plugin struct 1826 * @param plugin pointer to the plugin struct
@@ -1780,6 +1851,67 @@ free_receive_message(struct Plugin* plugin,
1780 GNUNET_free(rx_message); 1851 GNUNET_free(rx_message);
1781} 1852}
1782 1853
1854static void
1855free_session(struct Plugin * plugin, struct Sessionqueue * queue)
1856{
1857 struct Sessionqueue * pendingsession = plugin->pending_Sessions;
1858 struct PendingMessage * pm;
1859 struct Receive_Message_Queue * receive_queue;
1860 struct Plugin_Session_pair pair;
1861
1862 //session found
1863 //is this session pending for send
1864 while (pendingsession != NULL)
1865 {
1866 if (pendingsession->content == queue->content)
1867 {
1868 plugin->pendingsessions--;
1869 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
1870 plugin->pending_Sessions_tail, pendingsession);
1871 GNUNET_free(pendingsession);
1872 break;
1873 }
1874 pendingsession = pendingsession->next;
1875 }
1876
1877 //is something of this session in the fragment queue?
1878 pair.plugin = plugin;
1879 pair.session = queue->content;
1880 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages,
1881 &free_fragment_message_from_session, &pair);
1882
1883 //dispose all received fragments
1884 receive_queue = get_receive_message_from_session(plugin, queue->content);
1885 while (receive_queue != NULL)
1886 {
1887 free_receive_message(plugin, receive_queue);
1888 receive_queue = get_receive_message_from_session(plugin, queue->content);
1889 }
1890
1891 // remove PendingMessage
1892 pm = queue->content->pending_message;
1893 if (pm != NULL)
1894 {
1895 GNUNET_free_non_null(pm->msg);
1896 GNUNET_free(pm);
1897 }
1898
1899 // remove PendingMessage
1900 pm = queue->content->pending_message2;
1901 if (pm != NULL)
1902 {
1903 GNUNET_free_non_null(pm->msg);
1904 GNUNET_free(pm);
1905 }
1906
1907 GNUNET_free(queue->content);
1908 GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue);
1909 GNUNET_free(queue);
1910 plugin->session_count--;
1911
1912 check_fragment_queue(plugin);
1913
1914}
1783 1915
1784/** 1916/**
1785 * Function that can be used to force the plugin to disconnect 1917 * Function that can be used to force the plugin to disconnect
@@ -1794,10 +1926,6 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
1794{ 1926{
1795 struct Plugin *plugin = cls; 1927 struct Plugin *plugin = cls;
1796 struct Sessionqueue * queue = plugin->sessions; 1928 struct Sessionqueue * queue = plugin->sessions;
1797 struct Sessionqueue * pendingsession = plugin->pending_Sessions;
1798 struct PendingMessage * pm = NULL;
1799 struct FragmentMessage * fm;
1800 struct Receive_Message_Queue * receive_queue;
1801 1929
1802 // just look at all the session for the needed one 1930 // just look at all the session for the needed one
1803 while (queue != NULL) 1931 while (queue != NULL)
@@ -1807,53 +1935,7 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
1807 if (memcmp(target, &(queue->content->target), 1935 if (memcmp(target, &(queue->content->target),
1808 sizeof(struct GNUNET_PeerIdentity)) == 0) 1936 sizeof(struct GNUNET_PeerIdentity)) == 0)
1809 { 1937 {
1810 //session found 1938 free_session(plugin, queue);
1811 //is this session pending for send
1812 while (pendingsession != NULL)
1813 {
1814 if (pendingsession->content == queue->content)
1815 {
1816 plugin->pendingsessions--;
1817 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions,
1818 plugin->pending_Sessions_tail, pendingsession);
1819 GNUNET_free(pendingsession);
1820 break;
1821 }
1822 pendingsession = pendingsession->next;
1823 }
1824
1825 //is something of this session in the fragment queue?
1826 fm = get_fragment_message_from_session(queue->content);
1827 while (fm != NULL)
1828 {
1829 free_fragment_message(plugin, fm);
1830 fm = get_fragment_message_from_session(queue->content);
1831 }
1832 check_next_fragment_timeout(plugin);
1833
1834 //dispose all received fragments
1835 receive_queue = get_receive_message_from_session(plugin,
1836 queue->content);
1837 while (receive_queue != NULL)
1838 {
1839 free_receive_message(plugin, receive_queue);
1840 receive_queue = get_receive_message_from_session(plugin,
1841 queue->content);
1842 }
1843
1844 // remove PendingMessage
1845 pm = queue->content->pending_message;
1846 if (pm != NULL)
1847 {
1848 GNUNET_free_non_null(pm->msg);
1849 GNUNET_free(pm);
1850 }
1851
1852 GNUNET_free(queue->content);
1853 GNUNET_CONTAINER_DLL_remove(plugin->sessions, plugin->sessions_tail, queue);
1854 GNUNET_free(queue);
1855 plugin->session_count--;
1856
1857 return; 1939 return;
1858 } 1940 }
1859 // try next 1941 // try next
@@ -1899,55 +1981,24 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type,
1899 asc(asc_cls, ret); 1981 asc(asc_cls, ret);
1900} 1982}
1901 1983
1902
1903
1904/**
1905 * Function called for a quick conversion of the binary address to
1906 * a numeric address. Note that the caller must not free the
1907 * address and that the next call to this function is allowed
1908 * to override the address again.
1909 *
1910 * @param cls closure
1911 * @param addr binary address
1912 * @param addrlen length of the address
1913 * @return string representing the same address
1914 */
1915static const char*
1916wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
1917{
1918 static char ret[40];
1919 const struct MacAddress *mac;
1920
1921 if (addrlen != sizeof(struct MacAddress))
1922 {
1923 GNUNET_break (0);
1924 return NULL;
1925 }
1926 mac = addr;
1927 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
1928 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3],
1929 mac->mac[4], mac->mac[5]);
1930 return ret;
1931}
1932
1933/** 1984/**
1934 * function to check if bitfield is representation of fragments of the message 1985 * function to check if bitfield is representation of fragments of the message
1935 * @param rec_message message to check 1986 * @param rec_message message to check
1936 */ 1987 */
1937 1988
1938void 1989void
1939check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message) 1990check_message_fragment_bitfield(struct Receive_Message_Queue * rx_msg)
1940{ 1991{
1941 uint64_t checkfragments = 0; 1992 uint64_t checkfragments = 0;
1942 struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; 1993 struct Receive_Fragment_Queue * rx_frag = rx_msg->frag_head;
1943 1994
1944 while (rec_queue != NULL) 1995 while (rx_frag != NULL)
1945 { 1996 {
1946 setBit((char*) &checkfragments, rec_queue->num); 1997 setBit((char*) &checkfragments, rx_frag->num);
1947 rec_queue = rec_queue->next; 1998 rx_frag = rx_frag->next;
1948 1999
1949 } 2000 }
1950 GNUNET_assert(checkfragments == rec_message->received_fragments); 2001 GNUNET_assert(checkfragments == rx_msg->received_fragments);
1951} 2002}
1952 2003
1953/** 2004/**
@@ -1959,15 +2010,15 @@ check_message_fragment_bitfield(struct Receive_Message_Queue * rec_message)
1959 */ 2010 */
1960 2011
1961static const int 2012static const int
1962is_double_msg(struct Receive_Message_Queue * rec_message, 2013is_double_msg(struct Receive_Message_Queue * rx_msg,
1963 struct FragmentationHeader * fh) 2014 struct FragmentationHeader * fh)
1964{ 2015{
1965 //test if bitfield is okay 2016 //test if bitfield is okay
1966#if DEBUG_wlan 2017#if DEBUG_wlan
1967 check_message_fragment_bitfield(rec_message); 2018 check_message_fragment_bitfield(rx_msg);
1968#endif 2019#endif
1969 2020
1970 return testBit((char *) &rec_message->received_fragments, ntohs( 2021 return testBit((char *) &rx_msg->received_fragments, ntohs(
1971 fh->fragment_off_or_num)); 2022 fh->fragment_off_or_num));
1972 2023
1973} 2024}
@@ -1986,8 +2037,7 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message,
1986 GNUNET_assert(rx_frag != NULL); 2037 GNUNET_assert(rx_frag != NULL);
1987 2038
1988 struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head; 2039 struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head;
1989 struct WlanHeader * wlanheader = NULL; 2040 struct WlanHeader * wlanheader;
1990
1991 2041
1992 //this is the first fragment of the message (fragment id 0) 2042 //this is the first fragment of the message (fragment id 0)
1993 if (rx_frag->num == 0) 2043 if (rx_frag->num == 0)
@@ -2015,10 +2065,6 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message,
2015 setBit((char *) &rx_message->received_fragments, rx_frag->num); 2065 setBit((char *) &rx_message->received_fragments, rx_frag->num);
2016} 2066}
2017 2067
2018
2019
2020
2021
2022/** 2068/**
2023 * handels the data after all fragments are put together 2069 * handels the data after all fragments are put together
2024 * @param plugin 2070 * @param plugin
@@ -2026,14 +2072,14 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message,
2026 * @param hdr pointer to the data 2072 * @param hdr pointer to the data
2027 */ 2073 */
2028static void 2074static void
2029wlan_data_massage_handler(struct Plugin * plugin, 2075wlan_data_message_handler(struct Plugin * plugin,
2030 struct Session_light * session_light, 2076 struct Session_light * session_light,
2031 const struct GNUNET_MessageHeader * hdr) 2077 const struct GNUNET_MessageHeader * hdr)
2032{ 2078{
2033 struct WlanHeader * wlanheader = NULL; 2079 struct WlanHeader * wlanheader;
2034 struct Session * session = NULL; 2080 struct Session * session;
2035 const char * tempmsg = NULL; 2081 const char * tempmsg;
2036 const struct GNUNET_MessageHeader * temp_hdr = NULL; 2082 const struct GNUNET_MessageHeader * temp_hdr;
2037 struct GNUNET_PeerIdentity tmptarget; 2083 struct GNUNET_PeerIdentity tmptarget;
2038 2084
2039 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) 2085 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
@@ -2042,7 +2088,7 @@ wlan_data_massage_handler(struct Plugin * plugin,
2042#if DEBUG_wlan 2088#if DEBUG_wlan
2043 GNUNET_log( 2089 GNUNET_log(
2044 GNUNET_ERROR_TYPE_DEBUG, 2090 GNUNET_ERROR_TYPE_DEBUG,
2045 "Func wlan_data_massage_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n", 2091 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2046 ntohs(hdr->size)); 2092 ntohs(hdr->size));
2047#endif 2093#endif
2048 2094
@@ -2136,13 +2182,11 @@ wlan_data_massage_handler(struct Plugin * plugin,
2136 else 2182 else
2137 { 2183 {
2138 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2184 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2139 "wlan_data_massage_handler got wrong message type\n"); 2185 "wlan_data_message_handler got wrong message type\n");
2140 return; 2186 return;
2141 } 2187 }
2142} 2188}
2143 2189
2144
2145
2146/** 2190/**
2147 * Function to check if all fragments of a message have been received 2191 * Function to check if all fragments of a message have been received
2148 * @param plugin the plugin handle 2192 * @param plugin the plugin handle
@@ -2152,7 +2196,7 @@ wlan_data_massage_handler(struct Plugin * plugin,
2152 */ 2196 */
2153 2197
2154static void 2198static void
2155check_rec_finished_msg(struct Plugin* plugin, 2199check_rx_finished_msg(struct Plugin* plugin,
2156 struct Session_light * session_light, struct Session * session, 2200 struct Session_light * session_light, struct Session * session,
2157 struct Receive_Message_Queue * rx_message) 2201 struct Receive_Message_Queue * rx_message)
2158{ 2202{
@@ -2160,8 +2204,8 @@ check_rec_finished_msg(struct Plugin* plugin,
2160 2204
2161 struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; 2205 struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head;
2162 int packetsize = rx_message->rec_size; 2206 int packetsize = rx_message->rec_size;
2163 int sum = 0; 2207 int sum;
2164 int aktnum = 0; 2208 int aktnum;
2165 uint64_t bitfield = 0; 2209 uint64_t bitfield = 0;
2166 char * msg; 2210 char * msg;
2167 2211
@@ -2171,6 +2215,7 @@ check_rec_finished_msg(struct Plugin* plugin,
2171 return; 2215 return;
2172 } 2216 }
2173 // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader 2217 // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader
2218
2174 else if (packetsize < sizeof(struct WlanHeader) 2219 else if (packetsize < sizeof(struct WlanHeader)
2175 + sizeof(struct GNUNET_MessageHeader)) 2220 + sizeof(struct GNUNET_MessageHeader))
2176 { 2221 {
@@ -2191,7 +2236,7 @@ check_rec_finished_msg(struct Plugin* plugin,
2191 bitfield = bitfield >> (63 - rx_message->frag_tail->num); 2236 bitfield = bitfield >> (63 - rx_message->frag_tail->num);
2192 if (rx_message->received_fragments == bitfield) 2237 if (rx_message->received_fragments == bitfield)
2193 { 2238 {
2194 2239 sum = 0;
2195 while (rx_frag != NULL) 2240 while (rx_frag != NULL)
2196 { 2241 {
2197 sum += rx_frag->size; 2242 sum += rx_frag->size;
@@ -2222,7 +2267,7 @@ check_rec_finished_msg(struct Plugin* plugin,
2222 2267
2223 free_receive_message(plugin, rx_message); 2268 free_receive_message(plugin, rx_message);
2224 //call wlan_process_helper to process the message 2269 //call wlan_process_helper to process the message
2225 wlan_data_massage_handler(plugin, session_light, 2270 wlan_data_message_handler(plugin, session_light,
2226 (struct GNUNET_MessageHeader*) msg); 2271 (struct GNUNET_MessageHeader*) msg);
2227 //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); 2272 //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
2228 2273
@@ -2250,12 +2295,13 @@ process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2250#if DEBUG_wlan 2295#if DEBUG_wlan
2251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2252 "Calling plugin->env->receive for session %p; %s; size: %u\n", session, 2297 "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
2253 wlan_plugin_address_to_string(NULL, session->addr, 6), htons(hdr->size)); 2298 wlan_plugin_address_to_string(NULL, session->addr.mac, 6), htons(
2299 hdr->size));
2254#endif 2300#endif
2255 2301
2256 plugin->env->receive(plugin->env->cls, &(session->target), hdr, 2302 plugin->env->receive(plugin->env->cls, &(session->target), hdr,
2257 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, 2303 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
2258 (const char*) &session->addr, sizeof(session->addr)); 2304 (const char*) &session->addr, sizeof(session->addr));
2259} 2305}
2260 2306
2261/** 2307/**
@@ -2310,8 +2356,6 @@ get_receive_message(struct Plugin * plugin, struct Session * session,
2310 return NULL; 2356 return NULL;
2311} 2357}
2312 2358
2313
2314
2315/** 2359/**
2316 * function to insert a received fragment into the right fragment queue of the right message 2360 * function to insert a received fragment into the right fragment queue of the right message
2317 * @param plugin pointer to the plugin struct 2361 * @param plugin pointer to the plugin struct
@@ -2369,7 +2413,8 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2369 2413
2370 GNUNET_log( 2414 GNUNET_log(
2371 GNUNET_ERROR_TYPE_INFO, 2415 GNUNET_ERROR_TYPE_INFO,
2372 "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached\n"); 2416 "WLAN fragment message_id and session message_id do not exist, max MESSAGES_IN_QUEUE_PER_SESSION reached, akt in message_id %u\n",
2417 get_receive_message_from_session(plugin, session)->message_id_in);
2373 setBit((char *) &retval, ntohs(fh->fragment_off_or_num)); 2418 setBit((char *) &retval, ntohs(fh->fragment_off_or_num));
2374 return retval; 2419 return retval;
2375 } 2420 }
@@ -2378,7 +2423,6 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2378 if (is_double_msg(rx_message, fh) != GNUNET_YES) 2423 if (is_double_msg(rx_message, fh) != GNUNET_YES)
2379 { 2424 {
2380 2425
2381
2382 //report size 2426 //report size
2383 rx_frag = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + 2427 rx_frag = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) +
2384 ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); 2428 ntohs(fh->header.size) - sizeof(struct FragmentationHeader));
@@ -2401,7 +2445,7 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2401 rx_message->received_fragments, session); 2445 rx_message->received_fragments, session);
2402#endif 2446#endif
2403 2447
2404 check_rec_finished_msg(plugin, session_light, session, rx_message); 2448 check_rx_finished_msg(plugin, session_light, session, rx_message);
2405 } 2449 }
2406 else 2450 else
2407 { 2451 {
@@ -2425,13 +2469,13 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2425 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) 2469 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo)
2426{ 2470{
2427 struct Plugin *plugin = cls; 2471 struct Plugin *plugin = cls;
2428 struct Session * session = NULL; 2472 struct Session * session;
2429 2473
2430 struct FragmentationHeader * fh = NULL; 2474 struct FragmentationHeader * fh;
2431 struct FragmentationAckHeader * fah = NULL; 2475 struct FragmentationAckHeader * fah;
2432 struct FragmentMessage * fm = NULL; 2476 struct FragmentMessage * fm;
2433 2477
2434 const char * tempmsg = NULL; 2478 const char * tempmsg;
2435 2479
2436 uint64_t fragment_bitfield = 0; 2480 uint64_t fragment_bitfield = 0;
2437 2481
@@ -2448,12 +2492,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2448 GNUNET_ERROR_TYPE_DEBUG, 2492 GNUNET_ERROR_TYPE_DEBUG,
2449 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", 2493 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
2450 ntohs(hdr->size), wlan_plugin_address_to_string(NULL, 2494 ntohs(hdr->size), wlan_plugin_address_to_string(NULL,
2451 session_light->addr, 6)); 2495 session_light->addr.mac, 6));
2452#endif 2496#endif
2453 2497
2454 if (session_light->session == NULL) 2498 if (session_light->session == NULL)
2455 { 2499 {
2456 session_light->session = get_Session(plugin, &session_light->addr); 2500 session_light->session = get_session(plugin, &session_light->addr);
2457 } 2501 }
2458 GNUNET_assert(GNUNET_HELLO_get_id( 2502 GNUNET_assert(GNUNET_HELLO_get_id(
2459 (const struct GNUNET_HELLO_Message *) &hdr[1], 2503 (const struct GNUNET_HELLO_Message *) &hdr[1],
@@ -2462,6 +2506,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2462 } 2506 }
2463 2507
2464 //FRAGMENT 2508 //FRAGMENT
2509
2465 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT) 2510 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT)
2466 { 2511 {
2467 2512
@@ -2481,7 +2526,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2481 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n", 2526 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u; %s\n",
2482 ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs( 2527 ntohl(fh->message_id), ntohs(fh->fragment_off_or_num), ntohs(
2483 hdr->size), wlan_plugin_address_to_string(NULL, 2528 hdr->size), wlan_plugin_address_to_string(NULL,
2484 session_light->addr, 6)); 2529 session_light->addr.mac, 6));
2485#endif 2530#endif
2486 2531
2487 if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc)) 2532 if (getcrc16(tempmsg, ntohs(fh->header.size)) != ntohs(fh->message_crc))
@@ -2504,7 +2549,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2504 GNUNET_ERROR_TYPE_INFO, 2549 GNUNET_ERROR_TYPE_INFO,
2505 "WLAN client not in session list, fragment num %u, message id %u\n", 2550 "WLAN client not in session list, fragment num %u, message id %u\n",
2506 ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); 2551 ntohs(fh->fragment_off_or_num), ntohl(fh->message_id));
2507 wlan_data_massage_handler(plugin, session_light, 2552 wlan_data_message_handler(plugin, session_light,
2508 (struct GNUNET_MessageHeader *) tempmsg); 2553 (struct GNUNET_MessageHeader *) tempmsg);
2509 session = session_light->session; 2554 session = session_light->session;
2510 //test if a session was created 2555 //test if a session was created
@@ -2516,11 +2561,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2516 } 2561 }
2517 2562
2518 add_ack_for_send(plugin, session, fragment_bitfield, fh); 2563 add_ack_for_send(plugin, session, fragment_bitfield, fh);
2519 check_next_fragment_timeout(plugin); 2564 set_next_send(plugin);
2520 2565
2521 } 2566 }
2522 2567
2523 //ACK 2568 //ACK
2569
2524 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK) 2570 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK)
2525 { 2571 {
2526 2572
@@ -2529,7 +2575,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2529 GNUNET_ERROR_TYPE_DEBUG, 2575 GNUNET_ERROR_TYPE_DEBUG,
2530 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n", 2576 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT_ACK size: %u; %s\n",
2531 ntohs(hdr->size), wlan_plugin_address_to_string(NULL, 2577 ntohs(hdr->size), wlan_plugin_address_to_string(NULL,
2532 session_light->addr, 6)); 2578 session_light->addr.mac, 6));
2533#endif 2579#endif
2534 2580
2535 GNUNET_assert(session_light != NULL); 2581 GNUNET_assert(session_light != NULL);
@@ -2540,13 +2586,23 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2540 } 2586 }
2541 session = session_light->session; 2587 session = session_light->session;
2542 fah = (struct FragmentationAckHeader *) hdr; 2588 fah = (struct FragmentationAckHeader *) hdr;
2543 fm = get_fragment_message_from_session_and_id(session, ntohl( 2589 fm = get_fragment_message_from_session_and_id(plugin, session, ntohl(
2544 fah->message_id)); 2590 fah->message_id));
2591
2545 if (fm != NULL) 2592 if (fm != NULL)
2546 { 2593 {
2547 2594
2548 fm->ack_bitfield = fm->ack_bitfield | GNUNET_ntohll(fah->fragment_field); 2595 fm->ack_bitfield = fm->ack_bitfield | GNUNET_ntohll(
2596 fah->fragment_field);
2597 fm->next_ack = GNUNET_TIME_relative_to_absolute(get_ack_timeout(fm));
2598
2599#if DEBUG_wlan_retransmission
2600 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got ack for: %u; %u\n",
2601 fm->message_id_out, fm->ack_bitfield);
2602#endif
2549 check_finished_fragment(plugin, fm); 2603 check_finished_fragment(plugin, fm);
2604 set_next_send(plugin);
2605
2550 } 2606 }
2551 else 2607 else
2552 { 2608 {
@@ -2564,7 +2620,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2564 GNUNET_ERROR_TYPE_INFO, 2620 GNUNET_ERROR_TYPE_INFO,
2565 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", 2621 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2566 ntohs(hdr->type), ntohs(hdr->size)); 2622 ntohs(hdr->type), ntohs(hdr->size));
2567 GNUNET_assert(0); 2623 GNUNET_break(0);
2568 return; 2624 return;
2569 } 2625 }
2570 2626
@@ -2603,7 +2659,7 @@ wlan_process_helper(void *cls, void *client,
2603 const struct GNUNET_MessageHeader * temp_hdr = NULL; 2659 const struct GNUNET_MessageHeader * temp_hdr = NULL;
2604 2660
2605 int datasize = 0; 2661 int datasize = 0;
2606 int pos = 0; 2662 int pos;
2607 2663
2608 switch (ntohs(hdr->type)) 2664 switch (ntohs(hdr->type))
2609 { 2665 {
@@ -2635,8 +2691,8 @@ wlan_process_helper(void *cls, void *client,
2635 //process only if it is an broadcast or for this computer both with the gnunet bssid 2691 //process only if it is an broadcast or for this computer both with the gnunet bssid
2636 2692
2637 //check for bssid 2693 //check for bssid
2638 if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, sizeof(struct MacAddress)) 2694 if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid,
2639 == 0) 2695 sizeof(struct MacAddress)) == 0)
2640 { 2696 {
2641 //check for broadcast or mac 2697 //check for broadcast or mac
2642 if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac, 2698 if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac,
@@ -2654,11 +2710,10 @@ wlan_process_helper(void *cls, void *client,
2654 2710
2655 session_light = GNUNET_malloc(sizeof(struct Session_light)); 2711 session_light = GNUNET_malloc(sizeof(struct Session_light));
2656 memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2), 2712 memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2),
2657 sizeof(struct MacAddress)); 2713 sizeof(struct MacAddress));
2658 //session_light->session = search_session(plugin,session_light->addr); 2714 //session_light->session = search_session(plugin,session_light->addr);
2659 2715
2660 pos = 0; 2716 pos = 0;
2661 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1];
2662 while (pos < datasize) 2717 while (pos < datasize)
2663 { 2718 {
2664 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] 2719 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]
@@ -2836,6 +2891,8 @@ libgnunet_plugin_transport_wlan_done(void *cls)
2836{ 2891{
2837 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2892 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2838 struct Plugin *plugin = api->cls; 2893 struct Plugin *plugin = api->cls;
2894 struct Sessionqueue * queue = plugin->sessions;
2895 struct FragmentMessage * fm;
2839 2896
2840#if DEBUG_wlan 2897#if DEBUG_wlan
2841 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2898 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -2850,7 +2907,21 @@ libgnunet_plugin_transport_wlan_done(void *cls)
2850 if (plugin->data_tokenizer != NULL) 2907 if (plugin->data_tokenizer != NULL)
2851 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); 2908 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer);
2852 2909
2910
2911 fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages);
2912 while (fm != NULL){
2913 free_fragment_message(plugin, fm);
2914 fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(plugin->pending_Fragment_Messages);
2915 }
2916
2917 //free sessions
2918 while (queue != NULL)
2919 {
2920 free_session(plugin, queue);
2921 }
2922
2853 GNUNET_free_non_null(plugin->interface); 2923 GNUNET_free_non_null(plugin->interface);
2924 GNUNET_CONTAINER_heap_destroy(plugin->pending_Fragment_Messages);
2854 GNUNET_free (plugin); 2925 GNUNET_free (plugin);
2855 GNUNET_free (api); 2926 GNUNET_free (api);
2856 return NULL; 2927 return NULL;
@@ -2880,6 +2951,8 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2880 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2951 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2881 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2952 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2882 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2953 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2954 plugin->pending_Fragment_Messages = GNUNET_CONTAINER_heap_create(
2955 GNUNET_CONTAINER_HEAP_ORDER_MIN);
2883 2956
2884 plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, 2957 plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper,
2885 plugin); 2958 plugin);