aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_wlan.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-04-20 04:51:01 +0000
committerDavid Brodski <david@brodski.eu>2011-04-20 04:51:01 +0000
commitd0d88da8754bd5184be826dc4d271c5abeece0c5 (patch)
tree610d7d600a82d464dd4cb56b2dee5c3890f18d3e /src/transport/plugin_transport_wlan.c
parentff74c423c7528e4920a7591e0e64b0b282a81bec (diff)
downloadgnunet-d0d88da8754bd5184be826dc4d271c5abeece0c5.tar.gz
gnunet-d0d88da8754bd5184be826dc4d271c5abeece0c5.zip
More cleanup, some errors, message in timeout implemented
Diffstat (limited to 'src/transport/plugin_transport_wlan.c')
-rw-r--r--src/transport/plugin_transport_wlan.c261
1 files changed, 166 insertions, 95 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index f8178f101..f53e4b648 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -60,7 +60,7 @@
60 60
61#define HALLO_BEACON_SCALING_FACTOR 900 61#define HALLO_BEACON_SCALING_FACTOR 900
62 62
63#define DEBUG_wlan GNUNET_YES 63#define DEBUG_wlan GNUNET_NO
64#define DEBUG_wlan_retransmission GNUNET_NO 64#define DEBUG_wlan_retransmission GNUNET_NO
65 65
66#define MESSAGE_LENGHT_UNKNOWN -1 66#define MESSAGE_LENGHT_UNKNOWN -1
@@ -121,9 +121,13 @@ struct Plugin
121 struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer; 121 struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer;
122 122
123 /** 123 /**
124 * encapsulation of packets received 124 * encapsulation of packets received from the wlan helper
125 */ 125 */
126 struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer; 126 struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer;
127 /**
128 * encapsulation of packets received
129 */
130 struct GNUNET_SERVER_MessageStreamTokenizer * fragment_tokenizer;
127 131
128 /** 132 /**
129 * stdout pipe handle for the gnunet-wlan-helper process 133 * stdout pipe handle for the gnunet-wlan-helper process
@@ -179,7 +183,7 @@ struct Plugin
179 * Sessions currently pending for transmission 183 * Sessions currently pending for transmission
180 * to this peer, if any. 184 * to this peer, if any.
181 */ 185 */
182 struct Sessionqueue * pending_Sessions; 186 struct Sessionqueue * pending_Sessions_head;
183 187
184 /** 188 /**
185 * Sessions currently pending for transmission 189 * Sessions currently pending for transmission
@@ -244,7 +248,7 @@ struct Finish_send
244/** 248/**
245 * Queue of sessions, for the general session queue and the pending session queue 249 * Queue of sessions, for the general session queue and the pending session queue
246 */ 250 */
247 251//TODO DOXIGEN
248struct Sessionqueue 252struct Sessionqueue
249{ 253{
250 struct Sessionqueue * next; 254 struct Sessionqueue * next;
@@ -255,6 +259,7 @@ struct Sessionqueue
255/** 259/**
256 * Queue for the fragments received 260 * Queue for the fragments received
257 */ 261 */
262//TODO DOXIGEN
258struct Receive_Fragment_Queue 263struct Receive_Fragment_Queue
259{ 264{
260 struct Receive_Fragment_Queue * next; 265 struct Receive_Fragment_Queue * next;
@@ -265,12 +270,15 @@ struct Receive_Fragment_Queue
265 struct Radiotap_rx rxinfo; 270 struct Radiotap_rx rxinfo;
266}; 271};
267 272
268struct Session_id_pair 273//TODO DOXIGEN
274struct Session_id_fragment_triple
269{ 275{
270 struct Session * session; 276 struct Session * session;
271 uint32_t message_id; 277 uint32_t message_id;
278 struct FragmentMessage * fm;
272}; 279};
273 280
281//TODO DOXIGEN
274struct Plugin_Session_pair 282struct Plugin_Session_pair
275{ 283{
276 struct Plugin * plugin; 284 struct Plugin * plugin;
@@ -367,13 +375,20 @@ struct PendingMessage
367/** 375/**
368 * Queue for acks to send for fragments recived 376 * Queue for acks to send for fragments recived
369 */ 377 */
370//TODO comments
371struct AckSendQueue 378struct AckSendQueue
372{ 379{
373 380
381 /**
382 * next ack in the ack send queue
383 */
374 struct AckSendQueue * next; 384 struct AckSendQueue * next;
385 /**
386 * previous ack in the ack send queue
387 */
375 struct AckSendQueue * prev; 388 struct AckSendQueue * prev;
376 389 /**
390 * pointer to the session this ack belongs to
391 */
377 struct Session * session; 392 struct Session * session;
378 /** 393 /**
379 * ID of message, to distinguish between the messages, picked randomly. 394 * ID of message, to distinguish between the messages, picked randomly.
@@ -565,8 +580,6 @@ struct FragmentationAckHeader
565 580
566}; 581};
567 582
568static struct FragmentMessage * return_val;
569
570static void 583static void
571do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 584do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
572 585
@@ -726,8 +739,7 @@ get_session(struct Plugin *plugin, const struct MacAddress *addr)
726static void 739static void
727queue_session(struct Plugin *plugin, struct Session * session) 740queue_session(struct Plugin *plugin, struct Session * session)
728{ 741{
729 struct Sessionqueue * queue = plugin->pending_Sessions; 742 struct Sessionqueue * queue = plugin->pending_Sessions_head;
730 struct Sessionqueue * lastitem = NULL;
731 743
732 if (session->pending_message != NULL) 744 if (session->pending_message != NULL)
733 { 745 {
@@ -741,7 +753,6 @@ queue_session(struct Plugin *plugin, struct Session * session)
741 return; 753 return;
742 } 754 }
743 // try next 755 // try next
744 lastitem = queue;
745 queue = queue->next; 756 queue = queue->next;
746 } 757 }
747 758
@@ -751,16 +762,17 @@ queue_session(struct Plugin *plugin, struct Session * session)
751 queue->content = session; 762 queue->content = session;
752 763
753 //insert at the tail 764 //insert at the tail
754 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions, 765 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions_head,
755 plugin->pending_Sessions_tail, queue); 766 plugin->pending_Sessions_tail, queue);
756 plugin->pendingsessions++; 767 plugin->pendingsessions++;
757 } 768 }
758 769
759} 770}
760 771
761//TODO doxigen
762/** 772/**
763 * Function to schedule the write task, executed after a delay 773 * Function to schedule the write task, executed after a delay
774 * @param cls pointer to the plugin struct
775 * @param tc GNUNET_SCHEDULER_TaskContext pointer
764 */ 776 */
765static void 777static void
766delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 778delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -780,10 +792,11 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
780 } 792 }
781} 793}
782 794
783//TODO doxigen
784/** 795/**
785 * Function to calculate the time of the next periodic "hello-beacon" 796 * Function to calculate the time of the next periodic "hello-beacon"
797 * @param plugin pointer to the plugin struct
786 */ 798 */
799
787static void 800static void
788set_next_beacon_time(struct Plugin * const plugin) 801set_next_beacon_time(struct Plugin * const plugin)
789{ 802{
@@ -810,21 +823,11 @@ set_next_beacon_time(struct Plugin * const plugin)
810 } 823 }
811} 824}
812 825
813//TODO doxigen
814/*
815 static struct GNUNET_TIME_Relative
816 get_next_frag_timeout(struct FragmentMessage * fm)
817 {
818 return GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(
819 fm->next_ack), GNUNET_TIME_absolute_get_remaining(fm->timeout));
820 }
821 */
822
823//TODO doxigen
824/** 826/**
825 * Function to get the timeout value for acks for this session 827 * Function to get the timeout value for acks for this session
828 * @param fm pointer to the FragmentMessage to get the next timeout
829 * @return time until the next ack should be received, in GNUNET_TIME_Relative
826 */ 830 */
827
828static struct GNUNET_TIME_Relative 831static struct GNUNET_TIME_Relative
829get_ack_timeout(struct FragmentMessage * fm) 832get_ack_timeout(struct FragmentMessage * fm)
830{ 833{
@@ -879,9 +882,20 @@ set_next_send(struct Plugin * const plugin)
879 882
880#endif 883#endif
881 884
882 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, 885 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
883 &delay_fragment_task, plugin); 886 {
884 887 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
888 {
889 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file(
890 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle,
891 &do_transmit, plugin);
892 }
893 }
894 else
895 {
896 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send,
897 &delay_fragment_task, plugin);
898 }
885} 899}
886 900
887/** 901/**
@@ -896,15 +910,19 @@ get_next_queue_session(struct Plugin * plugin)
896 struct Sessionqueue * sessionqueue; 910 struct Sessionqueue * sessionqueue;
897 struct Sessionqueue * sessionqueue_alt; 911 struct Sessionqueue * sessionqueue_alt;
898 struct PendingMessage * pm; 912 struct PendingMessage * pm;
899 sessionqueue = plugin->pending_Sessions; 913 sessionqueue = plugin->pending_Sessions_head;
900 914
901 while (sessionqueue != NULL) 915 while (sessionqueue != NULL)
902 { 916 {
903 session = sessionqueue->content; 917 session = sessionqueue->content;
904 918
905 GNUNET_assert(session != NULL); 919 GNUNET_assert(session != NULL);
920 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
921 "Found session %p from pending session queue\n", session
922 );
906 pm = session->pending_message; 923 pm = session->pending_message;
907 924
925
908#if DEBUG_wlan 926#if DEBUG_wlan
909 if (pm == NULL) 927 if (pm == NULL)
910 { 928 {
@@ -924,7 +942,7 @@ get_next_queue_session(struct Plugin * plugin)
924 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION) 942 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)
925 { 943 {
926 plugin->pendingsessions--; 944 plugin->pendingsessions--;
927 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, 945 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
928 plugin->pending_Sessions_tail, sessionqueue); 946 plugin->pending_Sessions_tail, sessionqueue);
929 GNUNET_free(sessionqueue); 947 GNUNET_free(sessionqueue);
930 948
@@ -953,7 +971,7 @@ get_next_queue_session(struct Plugin * plugin)
953 sessionqueue_alt = sessionqueue; 971 sessionqueue_alt = sessionqueue;
954 sessionqueue = sessionqueue->next; 972 sessionqueue = sessionqueue->next;
955 plugin->pendingsessions--; 973 plugin->pendingsessions--;
956 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, 974 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
957 plugin->pending_Sessions_tail, sessionqueue_alt); 975 plugin->pending_Sessions_tail, sessionqueue_alt);
958 976
959 GNUNET_free(sessionqueue_alt); 977 GNUNET_free(sessionqueue_alt);
@@ -1082,9 +1100,9 @@ check_finished_fragment(struct Plugin * plugin, struct FragmentMessage * fm)
1082 1100
1083#if DEBUG_wlan 1101#if DEBUG_wlan
1084 if (maxack != 63) 1102 if (maxack != 63)
1085 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1103 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1086 "Test bitfields %X and %X, maxack is %u, fm size %u\n", 1104 "Test bitfields %X and %X, maxack is %u, fm size %u\n",
1087 fm->ack_bitfield, tmpfield, maxack, fm->message_size); 1105 fm->ack_bitfield, tmpfield, maxack, fm->message_size);
1088#endif 1106#endif
1089 1107
1090 if (fm->ack_bitfield == tmpfield) 1108 if (fm->ack_bitfield == tmpfield)
@@ -1143,6 +1161,7 @@ set_next_message_fragment_pos(struct Plugin * plugin,
1143 1161
1144} 1162}
1145 1163
1164//TODO DOXIGEN
1146static int 1165static int
1147getRadiotapHeader(struct Plugin * plugin, struct Session * session, 1166getRadiotapHeader(struct Plugin * plugin, struct Session * session,
1148 struct Radiotap_Send * header) 1167 struct Radiotap_Send * header)
@@ -1223,6 +1242,7 @@ getcrc16(const char *msgbuf, size_t msgbuf_size)
1223 return 0; 1242 return 0;
1224} 1243}
1225 1244
1245//TODO DOXIGEN
1226static void 1246static void
1227send_hello_beacon(struct Plugin * plugin) 1247send_hello_beacon(struct Plugin * plugin)
1228{ 1248{
@@ -1278,6 +1298,7 @@ send_hello_beacon(struct Plugin * plugin)
1278 set_next_send(plugin); 1298 set_next_send(plugin);
1279} 1299}
1280 1300
1301//TODO DOXIGEN
1281static void 1302static void
1282send_ack(struct Plugin * plugin, struct AckSendQueue * ack) 1303send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1283{ 1304{
@@ -1298,7 +1319,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1298 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1319 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1299 "Sending ack for message_id %u with fragment field %u, size %u\n", 1320 "Sending ack for message_id %u with fragment field %u, size %u\n",
1300 ack->message_id, ack->fragments_field, size 1321 ack->message_id, ack->fragments_field, size
1301 - sizeof(struct Radiotap_Send)); 1322 - sizeof(struct Radiotap_Send));
1302#endif 1323#endif
1303 1324
1304 msgheader = GNUNET_malloc(size); 1325 msgheader = GNUNET_malloc(size);
@@ -1330,6 +1351,7 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1330 set_next_send(plugin); 1351 set_next_send(plugin);
1331} 1352}
1332 1353
1354//TODO DOXIGEN
1333static void 1355static void
1334finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1356finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1335{ 1357{
@@ -1459,7 +1481,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1459 GNUNET_ERROR_TYPE_DEBUG, 1481 GNUNET_ERROR_TYPE_DEBUG,
1460 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n", 1482 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT with message_id %u with fragment number %i, size: %u, offset %u, time until timeout %u\n",
1461 fm->message_id_out, fm->message_pos, copysize 1483 fm->message_id_out, fm->message_pos, copysize
1462 + sizeof(struct FragmentationHeader), copyoffset, 1484 + sizeof(struct FragmentationHeader), copyoffset,
1463 GNUNET_TIME_absolute_get_remaining(fm->timeout)); 1485 GNUNET_TIME_absolute_get_remaining(fm->timeout));
1464#endif 1486#endif
1465 1487
@@ -1473,21 +1495,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1473 fm->message_pos); 1495 fm->message_pos);
1474 } 1496 }
1475 GNUNET_assert(copyoffset < fm->message_size); 1497 GNUNET_assert(copyoffset < fm->message_size);
1476 //FIXME remove later
1477 GNUNET_assert(copystart < fm->msg + fm->message_size);
1478 1498
1479 fragheader.header.size = htons(copysize 1499 fragheader.header.size = htons(copysize
1480 + sizeof(struct FragmentationHeader)); 1500 + sizeof(struct FragmentationHeader));
1481 fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT); 1501 fragheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT);
1482 1502
1483 /* }
1484 else
1485 {
1486 // there is no need to split
1487 copystart = fm->msg;
1488 copysize = fm->message_size;
1489 }*/
1490
1491 size += copysize; 1503 size += copysize;
1492 size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame) 1504 size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame)
1493 + sizeof(struct GNUNET_MessageHeader); 1505 + sizeof(struct GNUNET_MessageHeader);
@@ -1503,18 +1515,11 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1503 1515
1504 //could be faster if content is just send and not copyed before 1516 //could be faster if content is just send and not copyed before
1505 //fragmentheader is needed 1517 //fragmentheader is needed
1506 //if (fm->message_size > WLAN_MTU)
1507 // {
1508 fragheader.message_crc = htons(getcrc16(copystart, copysize)); 1518 fragheader.message_crc = htons(getcrc16(copystart, copysize));
1509 memcpy(&ieeewlanheader[1], &fragheader, 1519 memcpy(&ieeewlanheader[1], &fragheader,
1510 sizeof(struct FragmentationHeader)); 1520 sizeof(struct FragmentationHeader));
1511 fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1]; 1521 fragheaderptr = (struct FragmentationHeader *) &ieeewlanheader[1];
1512 memcpy(&fragheaderptr[1], copystart, copysize); 1522 memcpy(&fragheaderptr[1], copystart, copysize);
1513 /* }
1514 else
1515 {
1516 memcpy(&ieeewlanheader[1], copystart, copysize);
1517 }*/
1518 1523
1519 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, 1524 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle,
1520 msgheader, size); 1525 msgheader, size);
@@ -1581,6 +1586,7 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1581 } 1586 }
1582 return; 1587 return;
1583 } 1588 }
1589
1584 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1590 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1585 "do_transmit did nothing, should not happen!\n"); 1591 "do_transmit did nothing, should not happen!\n");
1586} 1592}
@@ -1786,13 +1792,14 @@ search_fragment_message_from_session_and_id(void *cls,
1786 struct GNUNET_CONTAINER_HeapNode *node, void *element, 1792 struct GNUNET_CONTAINER_HeapNode *node, void *element,
1787 GNUNET_CONTAINER_HeapCostType cost) 1793 GNUNET_CONTAINER_HeapCostType cost)
1788{ 1794{
1789 struct Session_id_pair * pair = (struct Session_id_pair *) cls; 1795 struct Session_id_fragment_triple * triple =
1796 (struct Session_id_fragment_triple *) cls;
1790 struct FragmentMessage * fm = (struct FragmentMessage*) element; 1797 struct FragmentMessage * fm = (struct FragmentMessage*) element;
1791 1798
1792 if ((fm->session == pair->session) 1799 if ((fm->session == triple->session) && (fm->message_id_out
1793 && (fm->message_id_out == pair->message_id)) 1800 == triple->message_id))
1794 { 1801 {
1795 return_val = fm; 1802 triple->fm = fm;
1796 return GNUNET_NO; 1803 return GNUNET_NO;
1797 } 1804 }
1798 return GNUNET_YES; 1805 return GNUNET_YES;
@@ -1809,12 +1816,12 @@ static struct FragmentMessage *
1809get_fragment_message_from_session_and_id(struct Plugin * plugin, 1816get_fragment_message_from_session_and_id(struct Plugin * plugin,
1810 struct Session * session, uint32_t message_id) 1817 struct Session * session, uint32_t message_id)
1811{ 1818{
1812 struct Session_id_pair pair; 1819 struct Session_id_fragment_triple triple;
1813 pair.session = session; 1820 triple.session = session;
1814 pair.message_id = message_id; 1821 triple.message_id = message_id;
1815 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages, 1822 GNUNET_CONTAINER_heap_iterate(plugin->pending_Fragment_Messages,
1816 &search_fragment_message_from_session_and_id, &pair); 1823 &search_fragment_message_from_session_and_id, &triple);
1817 return return_val; 1824 return triple.fm;
1818} 1825}
1819 1826
1820/** 1827/**
@@ -1822,7 +1829,7 @@ get_fragment_message_from_session_and_id(struct Plugin * plugin,
1822 * @param plugin pointer to the plugin struct 1829 * @param plugin pointer to the plugin struct
1823 * @param session session this fragment belongs to 1830 * @param session session this fragment belongs to
1824 */ 1831 */
1825struct Receive_Message_Queue * 1832static struct Receive_Message_Queue *
1826get_receive_message_from_session(struct Plugin * plugin, 1833get_receive_message_from_session(struct Plugin * plugin,
1827 struct Session * session) 1834 struct Session * session)
1828{ 1835{
@@ -1868,28 +1875,59 @@ free_receive_message(struct Plugin* plugin,
1868 GNUNET_free(rx_message); 1875 GNUNET_free(rx_message);
1869} 1876}
1870 1877
1878/**
1879 * function to get the receive message of a session
1880 * @param plugin pointer to the plugin struct
1881 * @param session session this fragment belongs to
1882 */
1883static void
1884check_receive_message_timeouts(struct Plugin * plugin, struct Session * session)
1885{
1886 struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
1887 while (rec_message != NULL)
1888 {
1889 if (GNUNET_TIME_absolute_get_remaining(rec_message->timeout).rel_value
1890 == 0)
1891 {
1892 free_receive_message(plugin, rec_message);
1893 }
1894 rec_message = rec_message->next;
1895 }
1896
1897}
1898
1899//TODO DOXIGEN
1871static void 1900static void
1872free_session(struct Plugin * plugin, struct Sessionqueue * queue) 1901free_session(struct Plugin * plugin, struct Sessionqueue * queue)
1873{ 1902{
1874 struct Sessionqueue * pendingsession = plugin->pending_Sessions; 1903 struct Sessionqueue * pendingsession;
1904 struct Sessionqueue * pendingsession_tmp;
1875 struct PendingMessage * pm; 1905 struct PendingMessage * pm;
1876 struct Receive_Message_Queue * receive_queue; 1906 struct Receive_Message_Queue * receive_queue;
1877 struct Plugin_Session_pair pair; 1907 struct Plugin_Session_pair pair;
1878 int check = 0; 1908 int check = 0;
1879 1909
1880 GNUNET_assert(queue != NULL); 1910 GNUNET_assert(queue != NULL);
1911 GNUNET_assert(queue->content != NULL);
1881 1912
1882 //session found 1913 //session found
1883 //is this session pending for send 1914 //is this session pending for send
1915 pendingsession = plugin->pending_Sessions_head;
1884 while (pendingsession != NULL) 1916 while (pendingsession != NULL)
1885 { 1917 {
1918 pendingsession_tmp = pendingsession->next;
1886 if (pendingsession->content == queue->content) 1919 if (pendingsession->content == queue->content)
1887 { 1920 {
1888 plugin->pendingsessions--; 1921 plugin->pendingsessions--;
1889 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions, 1922 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1890 plugin->pending_Sessions_tail, pendingsession); 1923 plugin->pending_Sessions_tail, pendingsession);
1891 GNUNET_free(pendingsession); 1924 GNUNET_free(pendingsession);
1892 1925
1926 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1927 "Remove session %p from pending session queue\n", queue->content
1928 );
1929
1930
1893 if (check == 1) 1931 if (check == 1)
1894 { 1932 {
1895 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1933 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
@@ -1898,7 +1936,7 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue)
1898 1936
1899 check = 1; 1937 check = 1;
1900 } 1938 }
1901 pendingsession = pendingsession->next; 1939 pendingsession = pendingsession_tmp;
1902 } 1940 }
1903 1941
1904 //is something of this session in the fragment queue? 1942 //is something of this session in the fragment queue?
@@ -2099,10 +2137,11 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rx_message,
2099 * @param hdr pointer to the data 2137 * @param hdr pointer to the data
2100 */ 2138 */
2101static void 2139static void
2102wlan_data_message_handler(struct Plugin * plugin, 2140wlan_data_message_handler(void *cls, void *client,
2103 struct Session_light * session_light, 2141 const struct GNUNET_MessageHeader *hdr)
2104 const struct GNUNET_MessageHeader * hdr)
2105{ 2142{
2143 struct Plugin * plugin = (struct Plugin*) cls;
2144 struct Session_light * session_light = (struct Session_light *) client;
2106 struct WlanHeader * wlanheader; 2145 struct WlanHeader * wlanheader;
2107 struct Session * session; 2146 struct Session * session;
2108 const char * tempmsg; 2147 const char * tempmsg;
@@ -2232,9 +2271,10 @@ check_rx_finished_msg(struct Plugin* plugin,
2232 struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; 2271 struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head;
2233 int packetsize = rx_message->rec_size; 2272 int packetsize = rx_message->rec_size;
2234 int sum; 2273 int sum;
2235 int aktnum; 2274 //TODO CLEANUP
2275 //int aktnum;
2236 uint64_t bitfield = 0; 2276 uint64_t bitfield = 0;
2237 char * msg; 2277 //char * msg;
2238 2278
2239 //check if first fragment is present 2279 //check if first fragment is present
2240 if (packetsize == MESSAGE_LENGHT_UNKNOWN) 2280 if (packetsize == MESSAGE_LENGHT_UNKNOWN)
@@ -2279,31 +2319,50 @@ check_rx_finished_msg(struct Plugin* plugin,
2279 "check_rec_finished_msg: A message for %p is complete\n", session); 2319 "check_rec_finished_msg: A message for %p is complete\n", session);
2280#endif 2320#endif
2281 2321
2282 //TODO use mst 2322 //TODO cleanup
2323
2283 //copy fragments together 2324 //copy fragments together
2284 msg = GNUNET_malloc(packetsize); 2325 //msg = GNUNET_malloc(packetsize);
2285 rx_frag = rx_message->frag_head; 2326 rx_frag = rx_message->frag_head;
2286 aktnum = 0; 2327 //aktnum = 0;
2328 /*while (rx_frag != NULL)
2329 {
2330 //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY
2331 memcpy(msg + aktnum, rx_frag->msg, rx_frag->size);
2332 aktnum += rx_frag->size;
2333 rx_frag = rx_frag->next;
2334 }*/
2335
2287 while (rx_frag != NULL) 2336 while (rx_frag != NULL)
2288 { 2337 {
2289 //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY 2338 if (rx_frag->next != NULL)
2290 memcpy(msg + aktnum, rx_frag->msg, rx_frag->size); 2339 {
2291 aktnum += rx_frag->size; 2340 GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer,
2341 session_light, rx_frag->msg, rx_frag->size, GNUNET_NO,
2342 GNUNET_NO);
2343 }
2344 else
2345 {
2346 //if it is the last fragment just kill all leftover
2347 GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer,
2348 session_light, rx_frag->msg, rx_frag->size, GNUNET_YES,
2349 GNUNET_NO);
2350 }
2292 rx_frag = rx_frag->next; 2351 rx_frag = rx_frag->next;
2293 } 2352 }
2294
2295 free_receive_message(plugin, rx_message); 2353 free_receive_message(plugin, rx_message);
2296 //call wlan_process_helper to process the message 2354 //call wlan_process_helper to process the message
2297 wlan_data_message_handler(plugin, session_light, 2355 //wlan_data_message_handler(plugin, session_light,
2298 (struct GNUNET_MessageHeader*) msg); 2356 // (struct GNUNET_MessageHeader*) msg);
2299 //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); 2357 //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
2300 2358
2301 GNUNET_free(msg); 2359 //GNUNET_free(msg);
2302 } 2360 }
2303 } 2361 }
2304 // } 2362 // }
2305} 2363}
2306 2364
2365//TODO DOXIGEN
2307static void 2366static void
2308process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 2367process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2309{ 2368{
@@ -2412,14 +2471,17 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2412 { 2471 {
2413 if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) 2472 if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION)
2414 { 2473 {
2474 check_receive_message_timeouts(plugin, session);
2475 }
2476
2477 if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION)
2478 {
2415 2479
2416 //new message incoming 2480 //new message incoming
2417 rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); 2481 rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue));
2418 rx_message->message_id_in = ntohl(fh->message_id); 2482 rx_message->message_id_in = ntohl(fh->message_id);
2419 rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN; 2483 rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN;
2420 rx_message->session = session; 2484 rx_message->session = session;
2421 rx_message->timeout = GNUNET_TIME_absolute_add(
2422 GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT);
2423 rx_message->received_fragments = 0; 2485 rx_message->received_fragments = 0;
2424 2486
2425 GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message); 2487 GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message);
@@ -2447,6 +2509,11 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2447 } 2509 }
2448 } 2510 }
2449 2511
2512 //reset timeout
2513 rx_message->timeout = GNUNET_TIME_absolute_add(
2514 GNUNET_TIME_absolute_get(),
2515 MESSAGE_IN_TIMEOUT);
2516
2450 if (is_double_msg(rx_message, fh) != GNUNET_YES) 2517 if (is_double_msg(rx_message, fh) != GNUNET_YES)
2451 { 2518 {
2452 2519
@@ -2576,8 +2643,12 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2576 GNUNET_ERROR_TYPE_INFO, 2643 GNUNET_ERROR_TYPE_INFO,
2577 "WLAN client not in session list, fragment num %u, message id %u\n", 2644 "WLAN client not in session list, fragment num %u, message id %u\n",
2578 ntohs(fh->fragment_off_or_num), ntohl(fh->message_id)); 2645 ntohs(fh->fragment_off_or_num), ntohl(fh->message_id));
2579 wlan_data_message_handler(plugin, session_light, 2646
2580 (struct GNUNET_MessageHeader *) tempmsg); 2647 GNUNET_SERVER_mst_receive(plugin->fragment_tokenizer, session_light,
2648 tempmsg, ntohs(hdr->size) - sizeof(struct FragmentationHeader),
2649 GNUNET_YES, GNUNET_NO);
2650 //wlan_data_message_handler(plugin, session_light,
2651 // (struct GNUNET_MessageHeader *) tempmsg);
2581 session = session_light->session; 2652 session = session_light->session;
2582 //test if a session was created 2653 //test if a session was created
2583 if (session == NULL) 2654 if (session == NULL)
@@ -2658,6 +2729,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2658 2729
2659} 2730}
2660 2731
2732//TODO DOXIGEN
2661const char * 2733const char *
2662macprinter(const u_int8_t * mac) 2734macprinter(const u_int8_t * mac)
2663{ 2735{
@@ -2706,7 +2778,7 @@ wlan_process_helper(void *cls, void *client,
2706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2707 "Size of packet is too small; size: %u min size: %u\n", ntohs( 2779 "Size of packet is too small; size: %u min size: %u\n", ntohs(
2708 hdr->size), sizeof(struct ieee80211_frame) 2780 hdr->size), sizeof(struct ieee80211_frame)
2709 + sizeof(struct GNUNET_MessageHeader)); 2781 + sizeof(struct GNUNET_MessageHeader));
2710#endif 2782#endif
2711 //GNUNET_break (0); 2783 //GNUNET_break (0);
2712 /* FIXME: restart SUID process */ 2784 /* FIXME: restart SUID process */
@@ -2812,12 +2884,6 @@ wlan_plugin_helper_read(void *cls,
2812 struct Plugin *plugin = cls; 2884 struct Plugin *plugin = cls;
2813 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2885 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2814 2886
2815 /*
2816 #if DEBUG_wlan
2817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2818 "Start reading from STDIN\n");
2819 #endif
2820 */
2821 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 2887 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2822 return; 2888 return;
2823 2889
@@ -2935,6 +3001,9 @@ libgnunet_plugin_transport_wlan_done(void *cls)
2935 if (plugin->data_tokenizer != NULL) 3001 if (plugin->data_tokenizer != NULL)
2936 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); 3002 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer);
2937 3003
3004 if (plugin->fragment_tokenizer != NULL)
3005 GNUNET_SERVER_mst_destroy(plugin->fragment_tokenizer);
3006
2938 fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek( 3007 fm = (struct FragmentMessage *) GNUNET_CONTAINER_heap_peek(
2939 plugin->pending_Fragment_Messages); 3008 plugin->pending_Fragment_Messages);
2940 3009
@@ -2992,9 +3061,11 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2992 plugin); 3061 plugin);
2993 3062
2994 plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); 3063 plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin);
3064 plugin->fragment_tokenizer = GNUNET_SERVER_mst_create(
3065 &wlan_data_message_handler, plugin);
2995 3066
2996 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); 3067 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
2997 //plugin->pending_Sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); 3068 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
2998 3069
2999 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 3070 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3000 api->cls = plugin; 3071 api->cls = plugin;