gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r14814 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r14814 - gnunet/src/transport
Date: Fri, 1 Apr 2011 10:53:19 +0200

Author: grothoff
Date: 2011-04-01 10:53:19 +0200 (Fri, 01 Apr 2011)
New Revision: 14814

Modified:
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/plugin_transport_wlan.c
   gnunet/src/transport/plugin_transport_wlan.h
Log:
fixes

Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2011-04-01 08:33:51 UTC (rev 14813)
+++ gnunet/src/transport/Makefile.am    2011-04-01 08:53:19 UTC (rev 14814)
@@ -84,7 +84,7 @@
 gnunet_nat_server_SOURCES = \
  $(NATSERVER)
 
-    
+
 gnunet_transport_wlan_helper_SOURCES = \
  wlan/radiotap-parser.c \
  wlan/helper_common.c \

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2011-04-01 08:33:51 UTC 
(rev 14813)
+++ gnunet/src/transport/gnunet-service-transport.c     2011-04-01 08:53:19 UTC 
(rev 14814)
@@ -2248,7 +2248,8 @@
   al = p->addresses;
   while (al != NULL)
     {
-      if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
+      if ( (addrlen == al->addrlen) && 
+          (0 == memcmp (addr, &al[1], addrlen)) )
         {            
          al->expires = abex;
          update_addresses (p, GNUNET_NO);
@@ -2256,7 +2257,6 @@
         }
       al = al->next;
     }
-
   al = GNUNET_malloc (sizeof (struct OwnAddressList) + addrlen);
   al->next = p->addresses;
   p->addresses = al;

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2011-04-01 08:33:51 UTC 
(rev 14813)
+++ gnunet/src/transport/plugin_transport_wlan.c        2011-04-01 08:53:19 UTC 
(rev 14814)
@@ -974,8 +974,6 @@
   struct FragmentMessage * fm;
   struct GNUNET_TIME_Relative next_send;
 
-  next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time);
-
   //cancel old task
   if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
     {
@@ -989,13 +987,17 @@
   //check if some acks are in the queue
   if (plugin->ack_send_queue_head != NULL)
     {
-      next_send = GNUNET_TIME_relative_get_zero();
+      next_send = GNUNET_TIME_UNIT_ZERO;
     }
   //check if there are some fragments in the queue
-  else if (fm != NULL)
+  else
     {
-      next_send
-          = GNUNET_TIME_relative_min(next_send, get_next_frag_timeout(fm));
+      next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time);
+      if (fm != NULL)
+       {
+         next_send
+           = GNUNET_TIME_relative_min(next_send, get_next_frag_timeout(fm));
+       }
     }
   plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send,
       &delay_fragment_task, plugin);
@@ -2014,22 +2016,25 @@
  * @return string representing the same address 
  */
 static const char*
-wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
+wlan_plugin_address_to_string (void *cls, 
+                              const void *addr, 
+                              size_t addrlen)
 {
   static char ret[40];
-  const unsigned char * input;
+  const struct MacAddress *mac;
 
-  //GNUNET_assert(cls !=NULL);
-  if (addrlen != 6)
+  if (addrlen != sizeof (struct MacAddress))
     {
-      /* invalid address (MAC addresses have 6 bytes) */
       GNUNET_break (0);
       return NULL;
     }
-  input = (const unsigned char*) addr;
+  mac = addr;
   GNUNET_snprintf(ret, sizeof(ret),
-      "%s Mac-Address %02X:%02X:%02X:%02X:%02X:%02X", PROTOCOL_PREFIX,
-      input[0], input[1], input[2], input[3], input[4], input[5]);
+                 "%s Mac-Address %X:%X:%X:%X:%X:%X", 
+                 PROTOCOL_PREFIX,
+                 mac->mac[0], mac->mac[1],
+                 mac->mac[2], mac->mac[3], 
+                 mac->mac[4], mac->mac[5]);
   return ret;
 }
 
@@ -2692,15 +2697,21 @@
 
 }
 
-char *
-macprinter(u_int8_t * mac)
+
+const char *
+macprinter(const u_int8_t * mac)
 {
   static char macstr[20];
-  sprintf(macstr, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2],
-      mac[3], mac[4], mac[5]);
+
+  GNUNET_snprintf (macstr,
+                  sizeof (macstr),
+                  "%X:%X:%X:%X:%X:%X", 
+                  mac[0], mac[1], mac[2],
+                  mac[3], mac[4], mac[5]);
   return macstr;
 }
 
+
 /**
  * Function used for to process the data from the suid process
  *
@@ -2708,10 +2719,10 @@
  * @param client client that send the data (not used)
  * @param hdr header of the GNUNET_MessageHeader
  */
-
 static void
-wlan_process_helper(void *cls, void *client,
-    const struct GNUNET_MessageHeader *hdr)
+wlan_process_helper (void *cls, 
+                    void *client,
+                    const struct GNUNET_MessageHeader *hdr)
 {
   struct Plugin *plugin = cls;
   struct ieee80211_frame * wlanIeeeHeader = NULL;
@@ -2721,17 +2732,22 @@
   int datasize = 0;
   int pos = 0;
 
-  if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA)
+  switch (ntohs(hdr->type))
     {
+    case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
 #if DEBUG_wlan
-      GNUNET_log(
-          GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_process_helper got  GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 
size: %u\n",
-          ntohs(hdr->size));
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+                "Func wlan_process_helper got  
GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
+                ntohs(hdr->size));
 #endif
 
       //call wlan_process_helper with the message inside, later with wlan: 
analyze signal
-      GNUNET_assert(ntohs(hdr->size) >= sizeof(struct ieee80211_frame) + 
sizeof(struct GNUNET_MessageHeader));
+      if (ntohs(hdr->size) < sizeof(struct ieee80211_frame) + sizeof(struct 
GNUNET_MessageHeader))
+       {
+         GNUNET_break (0);
+         /* FIXME: restart SUID process */
+         return;
+       }
       wlanIeeeHeader = (struct ieee80211_frame *) &hdr[1];
 
       //process only if it is an broadcast or for this computer both with the 
gnunet bssid
@@ -2790,50 +2806,37 @@
                   wlanIeeeHeader->i_addr2));
 #endif
         }
-
-    }
-
-  else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL)
-    {
-
-#if DEBUG_wlan
-      GNUNET_log(
-          GNUNET_ERROR_TYPE_DEBUG,
-          "Func wlan_process_helper got  
GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL size: %u\n",
-          ntohs(hdr->size));
-#endif
-
+      break;
+    case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
       //TODO more control messages
       //TODO use struct wlan_helper_control
-      if (ntohs(hdr->size) == sizeof(struct Wlan_Helper_Control_Message))
+      if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message))
         {
-          //plugin->mac_address = GNUNET_malloc(sizeof(struct MacAddress));
-          memcpy(&(plugin->mac_address), &hdr[1], sizeof(struct MacAddress));
-          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-              "Notifying transport of address %s\n",
-              wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs(
-                  hdr->size) - sizeof(struct GNUNET_MessageHeader)));
-          plugin->env->notify_address(plugin->env->cls, "wlan",
-              &plugin->mac_address.mac, sizeof(struct MacAddress),
-              GNUNET_TIME_UNIT_FOREVER_REL);
-        }
-      else
-        {
-          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n",
-              macprinter(plugin->mac_address.mac));
-        }
-
-    }
-
-  else
-    {
-      // TODO Wrong data?
-      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-          "WLAN helper packet has not the right type\n");
+         GNUNET_break (0);
+         /* FIXME: restart SUID process */       
+         return;
+       }
+      memcpy (&plugin->mac_address, 
+             &hdr[1], 
+             sizeof(struct MacAddress));
+#if DEBUG_WLAN
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                 "Received WLAN_HELPER_CONTROL message with transport of 
address %s\n",
+                 wlan_plugin_address_to_string (cls, 
+                                                &plugin->mac_address, 
+                                                sizeof (struct MacAddress)));
+#endif
+      plugin->env->notify_address(plugin->env->cls, "wlan",
+                                 &plugin->mac_address, sizeof(struct 
MacAddress),
+                                 GNUNET_TIME_UNIT_FOREVER_REL);
+      break;
+    default:
+      GNUNET_break (0);
       return;
     }
 }
 
+
 /**
  * We have been notified that wlan-helper has written something to stdout.
  * Handle the output, then reschedule this function to be called again once
@@ -2842,7 +2845,6 @@
  * @param cls the plugin handle
  * @param tc the scheduling context
  */
-
 static void
 wlan_plugin_helper_read(void *cls,
     const struct GNUNET_SCHEDULER_TaskContext *tc)

Modified: gnunet/src/transport/plugin_transport_wlan.h
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.h        2011-04-01 08:33:51 UTC 
(rev 14813)
+++ gnunet/src/transport/plugin_transport_wlan.h        2011-04-01 08:53:19 UTC 
(rev 14814)
@@ -40,7 +40,7 @@
 struct Wlan_Helper_Control_Message
 {
   struct GNUNET_MessageHeader hdr;
-  struct MacAddress mac ;
+  struct MacAddress mac;
 };
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]