- // 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);
-
-#if DEBUG_wlan
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Calling plugin->env->receive for session %p; %s; size: %u\n", session,
- wlan_plugin_address_to_string(NULL, session->addr, 6), htons(hdr->size));
-#endif
-
- plugin->env->receive(plugin->env->cls, &(session->target), hdr,
- (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session,
- (const char*) &session->addr, sizeof(session->addr));
-}
-
-/**
- * function to add an ack to send it for a received fragment
- * @param plugin pointer to the global plugin structure
- * @param session pointer to the session this ack belongs to
- * @param bitfield bitfield to send
- * @param fh pointer to the fragmentation header which we would like to acknolage
- */
-
-void
-add_ack_for_send(struct Plugin * plugin, struct Session * session,
- uint64_t bitfield, struct FragmentationHeader * fh)
-{
- struct AckSendQueue * ack;
-
- GNUNET_assert(plugin != NULL);
- GNUNET_assert(session != NULL);
- GNUNET_assert(fh != NULL);
-
- ack = GNUNET_malloc(sizeof(struct AckSendQueue));
- ack->fragments_field = bitfield;
- ack->message_id = ntohl(fh->message_id);
- ack->session = session;
-
- GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head,
- plugin->ack_send_queue_tail, ack);
-
-}
-
-/**
- * function to get the receive message from the message id and the session
- * @param plugin pointer to the plugin struct
- * @param session session this fragment belongs to
- * @param message_id id of the message
- */
-
-struct Receive_Message_Queue *
-get_receive_message(struct Plugin * plugin, struct Session * session,
- uint32_t message_id)
-{
- struct Receive_Message_Queue * rec_message = plugin->receive_messages_head;
- while (rec_message != NULL)
- {
- if ((rec_message->message_id_in == message_id) && (rec_message->session
- == session))
- {
- return rec_message;
- }
- rec_message = rec_message->next;
- }
- return NULL;
-}
-
-
-
-/**
- * function to insert a received fragment into the right fragment queue of the right message
- * @param plugin pointer to the plugin struct
- * @param session_light pointer to the session_light struct of this message
- * @param session session this fragment belongs to
- * @param fh pointer to the header of the fragment
- * @return new fragment bitfield for the message
- */
-
-uint64_t
-insert_fragment_in_in_message_queue(struct Plugin * plugin,
- struct Session_light * session_light, struct Session * session,
- struct FragmentationHeader * fh, const struct Radiotap_rx * rxinfo)
-{
- struct Receive_Fragment_Queue * rx_frag = NULL;
- struct Receive_Message_Queue * rx_message;
- const char * tempmsg = (char*) &fh[1];
- uint64_t retval = 0;
-
- //TODO fragments do not timeout
- //check if message_id is right or it is a new msg
- GNUNET_assert(fh != NULL);
-
- rx_message = get_receive_message(plugin, session, ntohl(fh->message_id));
-
- if (rx_message == NULL)
- {
- if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION)
- {
-
- //new message incoming
- rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue));
- rx_message->message_id_in = ntohl(fh->message_id);
- rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN;
- rx_message->session = session;
- rx_message->timeout = GNUNET_TIME_absolute_add(
- GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT);
- rx_message->received_fragments = 0;
-
- GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message);
-
- session->fragment_messages_in_count++;
- plugin->pending_receive_messages++;