gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r14156 - in gnunet/src: core mesh vpn


From: gnunet
Subject: [GNUnet-SVN] r14156 - in gnunet/src: core mesh vpn
Date: Wed, 12 Jan 2011 15:02:33 +0100

Author: toelke
Date: 2011-01-12 15:02:33 +0100 (Wed, 12 Jan 2011)
New Revision: 14156

Modified:
   gnunet/src/core/core_api.c
   gnunet/src/mesh/mesh_api.c
   gnunet/src/vpn/gnunet-daemon-vpn-helper.c
   gnunet/src/vpn/gnunet-daemon-vpn.c
Log:
fix usage of mesh_api
assert invariant in core_api
fix mesh_api

Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c  2011-01-12 12:53:14 UTC (rev 14155)
+++ gnunet/src/core/core_api.c  2011-01-12 14:02:33 UTC (rev 14156)
@@ -1518,6 +1518,7 @@
                  GNUNET_SERVER_MAX_MESSAGE_SIZE);
   th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
   th->peer = pr;
+  GNUNET_assert(NULL != notify);
   th->get_message = notify;
   th->get_message_cls = notify_cls;
   th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2011-01-12 12:53:14 UTC (rev 14155)
+++ gnunet/src/mesh/mesh_api.c  2011-01-12 14:02:33 UTC (rev 14156)
@@ -46,6 +46,13 @@
   /* followed by another GNUNET_MessageHeader */
 };
 
+struct notify_cls
+{
+  void* notify_cls;
+  GNUNET_CONNECTION_TransmitReadyNotify notify;
+  struct GNUNET_MESH_Tunnel *tunnel;
+};
+
 struct GNUNET_MESH_Tunnel
 {
   /* The other peer this tunnel leads to; just unicast for the moment! */
@@ -53,9 +60,6 @@
 
   struct tunnel_id id;
 
-  void* notify_cls;
-  GNUNET_CONNECTION_TransmitReadyNotify notify;
-
   /* The handlers and cls for outbound tunnels. Are NULL for inbound tunnels. 
*/
   GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
   GNUNET_MESH_TunnelConnectHandler connect_handler;
@@ -260,7 +264,7 @@
 
   struct GNUNET_MESH_MessageHandler *handler;
 
-  for (handler = handle->handlers; handler != NULL; handler++)
+  for (handler = handle->handlers; handler->callback != NULL; handler++)
     {
       if ( (ntohs (rmessage->type) == handler->type)
           && ( (handler->expected_size == 0)
@@ -273,7 +277,7 @@
   /* handler->callback handles this message */
 
   /* If no handler was found, drop the message but keep the channel open */
-  if (handler == NULL)
+  if (handler->callback == NULL)
     return GNUNET_OK;
 
   struct tunnel_list_element *tunnel = handle->established_tunnels.head;
@@ -341,6 +345,7 @@
   memcpy (&tunnel->tunnel.id.target, peers,
          sizeof (struct GNUNET_PeerIdentity));
   tunnel->tunnel.id.id = current_id++;
+  memcpy (&tunnel->tunnel.peer, peers, sizeof(struct GNUNET_PeerIdentity));
 
   struct peer_list_element *element = handle->connected_peers.head;
   while (element != NULL)
@@ -396,15 +401,18 @@
 static size_t
 core_notify(void* cls, size_t size, void* buf)
 {
-  struct GNUNET_MESH_Tunnel *tunnel = cls;
+  struct notify_cls *ncls = cls;
+  struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel;
   struct tunnel_message* message = buf;
   void* cbuf = (void*) &message[1];
+  GNUNET_assert(NULL != ncls->notify);
 
-  size_t sent = tunnel->notify(tunnel->notify_cls, size - sizeof(struct 
tunnel_message), cbuf);
+  size_t sent = ncls->notify(ncls->notify_cls, size - sizeof(struct 
tunnel_message), cbuf);
 
-  tunnel->notify = NULL;
-  tunnel->notify_cls = NULL;
+  GNUNET_free(ncls);
 
+  if (0 == sent) return 0;
+
   sent += sizeof(struct tunnel_message);
 
   message->hdr.type = htons(GNUNET_MESSAGE_TYPE_MESH);
@@ -427,15 +435,18 @@
                                   GNUNET_CONNECTION_TransmitReadyNotify
                                   notify, void *notify_cls)
 {
-  tunnel->notify_cls = notify_cls;
-  tunnel->notify = notify;
+  struct notify_cls *cls = GNUNET_malloc(sizeof(struct notify_cls));
+  cls->notify_cls = notify_cls;
+  GNUNET_assert(NULL != notify);
+  cls->notify = notify;
+  cls->tunnel = tunnel;
   GNUNET_CORE_notify_transmit_ready(tunnel->handle->core,
                                    priority,
                                    maxdelay,
                                    &tunnel->peer,
                                    notify_size + sizeof(struct tunnel_message),
                                    &core_notify,
-                                   (void*)tunnel);
+                                   (void*)cls);
 
   /* aborting is not implemented yet */
   return (struct GNUNET_MESH_TransmitHandle*) 1;
@@ -468,6 +479,7 @@
 
   ret->handlers =
     GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler));
+  memset(ret->handlers, 0, len * sizeof(struct GNUNET_MESH_MessageHandler));
   memcpy (ret->handlers, handlers,
          len * sizeof (struct GNUNET_MESH_MessageHandler));
 

Modified: gnunet/src/vpn/gnunet-daemon-vpn-helper.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2011-01-12 12:53:14 UTC (rev 
14155)
+++ gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2011-01-12 14:02:33 UTC (rev 
14156)
@@ -263,8 +263,10 @@
                        me->tunnel = *cls;
                      }
                    else
-                     *cls = me->tunnel;
-                     //FIXME: somehow call send_udp_to_peer
+                     {
+                       *cls = me->tunnel;
+                       send_udp_to_peer(cls, (struct GNUNET_PeerIdentity*)1, 
NULL);
+                     }
                    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued to send to peer 
%x\n", *((unsigned int*)&me->desc.peer));
                  }
              }

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2011-01-12 12:53:14 UTC (rev 14155)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2011-01-12 14:02:33 UTC (rev 14156)
@@ -173,9 +173,9 @@
 static size_t
 send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_PeerIdentity *peer = cls;
+  struct GNUNET_MESH_Tunnel **tunnel = cls;
   struct GNUNET_MessageHeader *hdr =
-    (struct GNUNET_MessageHeader *) (peer + 1);
+    (struct GNUNET_MessageHeader *) (tunnel + 1);
   GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
   struct udp_pkt *udp = (struct udp_pkt *) (hc + 1);
   hdr->size = htons (sizeof (struct GNUNET_MessageHeader) +
@@ -202,6 +202,7 @@
                  const struct GNUNET_PeerIdentity *peer,
                  const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
+  if (peer == NULL) return;
   struct GNUNET_MESH_Tunnel **tunnel = cls;
   struct GNUNET_MessageHeader *hdr =
     (struct GNUNET_MessageHeader *) (tunnel + 1);




reply via email to

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