-
- return testBit((char *) &rec_message->received_fragments, ntohs(
- fh->fragment_off_or_num));
-
-}
-
-/**
- * Function to insert a fragment in a queue of a message
- * @param session session the fragment belongs to
- * @param rec_queue fragment to add
- */
-
-static void
-insert_fragment_in_queue(struct Receive_Message_Queue * rx_message,
- struct Receive_Fragment_Queue * rx_frag)
-{
- GNUNET_assert(rx_message != NULL);
- GNUNET_assert(rx_frag != NULL);
-
- struct Receive_Fragment_Queue * rx_frag2 = rx_message->frag_head;
- struct WlanHeader * wlanheader = NULL;
-
-
- //this is the first fragment of the message (fragment id 0)
- if (rx_frag->num == 0)
- {
- wlanheader = (struct WlanHeader *) rx_frag->msg;
- rx_message->rec_size = ntohs(wlanheader->header.size);
- }
-
- //sort into list
- while (rx_frag2 != NULL)
- {
- if (rx_frag2->num > rx_frag->num)
- {
- //next element number is grater than the current num
- GNUNET_CONTAINER_DLL_insert_before(rx_message->frag_head, rx_message->frag_tail, rx_frag2, rx_frag);
- setBit((char *) &rx_message->received_fragments, rx_frag->num);
- return;
- }
- rx_frag2 = rx_frag2->next;
- }
-
- //no element has a grater number
- GNUNET_CONTAINER_DLL_insert_tail(rx_message->frag_head, rx_message->frag_tail, rx_frag);
-
- setBit((char *) &rx_message->received_fragments, rx_frag->num);
-}
-
-
-
-
-
-/**
- * handels the data after all fragments are put together
- * @param plugin
- * @param session_light
- * @param hdr pointer to the data
- */
-static void
-wlan_data_massage_handler(struct Plugin * plugin,
- struct Session_light * session_light,
- const struct GNUNET_MessageHeader * hdr)
-{
- struct WlanHeader * wlanheader = NULL;
- struct Session * session = NULL;
- const char * tempmsg = NULL;
- const struct GNUNET_MessageHeader * temp_hdr = NULL;
- struct GNUNET_PeerIdentity tmptarget;
-
- if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
- {
-
-#if DEBUG_wlan
- GNUNET_log(
- GNUNET_ERROR_TYPE_DEBUG,
- "Func wlan_data_massage_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
- ntohs(hdr->size));
-#endif
-
- if (ntohs(hdr->size) < sizeof(struct WlanHeader)
- + sizeof(struct GNUNET_MessageHeader))
- {
- //packet not big enought
- return;
- }
-
- GNUNET_assert(session_light != NULL);
- if (session_light->session == NULL)
- {
- session_light->session = search_session(plugin, &session_light->addr);
- }
- session = session_light->session;
- wlanheader = (struct WlanHeader *) hdr;
-
- tempmsg = (char*) &wlanheader[1];
- temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
-
- if (getcrc32(tempmsg, ntohs(wlanheader->header.size)) != ntohl(
- wlanheader->crc))
- {
- //wrong crc, dispose message
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Wlan message Header crc was wrong\n");
- return;
- }
-
- //if not in session list
- if (session == NULL)
- {
-#if DEBUG_wlan
- GNUNET_log(
- GNUNET_ERROR_TYPE_DEBUG,
- "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
- ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
- sizeof(struct WlanHeader));
-#endif
- //try if it is a hello message
- if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size)
- + sizeof(struct WlanHeader))
- {
- if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
- {
- if (GNUNET_HELLO_get_id(
- (const struct GNUNET_HELLO_Message *) temp_hdr,
- &tmptarget) == GNUNET_OK)
- {
- session = create_session(plugin, &session_light->addr);
- session_light->session = session;
- memcpy(&session->target, &tmptarget,
- sizeof(struct GNUNET_PeerIdentity));
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "WLAN client not in session list and hello message not okay\n");
- return;
- }
-
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "WLAN client not in session list and not a hello message\n");
- return;
- }
- }
- else
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_WARNING,
- "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
- ntohs(wlanheader->header.size), ntohs(temp_hdr->size),
- sizeof(struct WlanHeader));
- return;
- }
- }
-
- //"receive" the message
-
-
- GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session,
- (const char *) temp_hdr,
- ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO);
-
- return;
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "wlan_data_massage_handler got wrong message type\n");
- return;
- }
-}
-
-
-
-/**
- * Function to check if all fragments of a message have been received
- * @param plugin the plugin handle
- * @param session_light information of the message sender
- * @param session session the message belongs to
- * @param rec_message pointer to the message that should be checked
- */
-
-static void
-check_rec_finished_msg(struct Plugin* plugin,
- struct Session_light * session_light, struct Session * session,
- struct Receive_Message_Queue * rx_message)
-{
- GNUNET_assert(rx_message !=NULL);
-
- struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head;
- int packetsize = rx_message->rec_size;
- int sum = 0;
- int aktnum = 0;
- uint64_t bitfield = 0;
- char * msg;
-
- //check if first fragment is present
- if (packetsize == MESSAGE_LENGHT_UNKNOWN)
- {
- return;
- }
- // test if message has at least the size of the WlanHeader and a GNUNET_MessageHeader
- else if (packetsize < sizeof(struct WlanHeader)
- + sizeof(struct GNUNET_MessageHeader))
- {
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Message not big enough\n");
-#endif
- free_receive_message(plugin, rx_message);
- return;
- }
-
-#if DEBUG_wlan
- check_message_fragment_bitfield(rx_message);
-#endif
-
- // if (rx_message->frag_tail->num == ffsl(rx_message->received_fragments))
- // {
- bitfield = ~bitfield;
- bitfield = bitfield >> (63 - rx_message->frag_tail->num);
- if (rx_message->received_fragments == bitfield)
- {
-
- while (rx_frag != NULL)
- {
- sum += rx_frag->size;
- rx_frag = rx_frag->next;
- }
- //sum should always be smaller or equal of
- GNUNET_assert(sum <= packetsize);
- if (sum == packetsize)
- {
-
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "check_rec_finished_msg: A message for %p is complete\n", session);
-#endif
-
- //TODO use mst
- //copy fragments together
- msg = GNUNET_malloc(packetsize);
- rx_frag = rx_message->frag_head;
- aktnum = 0;
- while (rx_frag != NULL)
- {
- //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY
- memcpy(msg + aktnum, rx_frag->msg, rx_frag->size);
- aktnum += rx_frag->size;
- rx_frag = rx_frag->next;
- }
-
- free_receive_message(plugin, rx_message);
- //call wlan_process_helper to process the message
- wlan_data_massage_handler(plugin, session_light,
- (struct GNUNET_MessageHeader*) msg);
- //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg);
-
- GNUNET_free(msg);
- }
- }
- // }
-}
-
-static void
-process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
-{
-
- GNUNET_assert(client != NULL);
- GNUNET_assert(cls != NULL);
- struct Session * session = (struct Session *) client;
- struct Plugin * plugin = (struct Plugin *) cls;
-
- struct GNUNET_TRANSPORT_ATS_Information distance[2];
- distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
- distance[0].value = htonl(1);
- distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
- distance[1].value = htonl(0);
-