fix usage of mesh_api
authorPhilipp Tölke <toelke@in.tum.de>
Wed, 12 Jan 2011 14:02:33 +0000 (14:02 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Wed, 12 Jan 2011 14:02:33 +0000 (14:02 +0000)
assert invariant in core_api
fix mesh_api

src/core/core_api.c
src/mesh/mesh_api.c
src/vpn/gnunet-daemon-vpn-helper.c
src/vpn/gnunet-daemon-vpn.c

index 9001b21d9f0993b0e0802b6e6c0f9114ce7e5ecc..c355b626eba0c5b89d98ebc06e3b87704eb08968 100644 (file)
@@ -1518,6 +1518,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
                  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);
index c424dfd998dbb43335d7b2b0b680c49b678eb46a..82fb75c5128a959f8b47be9bba43470b2a158401 100644 (file)
@@ -46,6 +46,13 @@ struct tunnel_message
   /* 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 GNUNET_MESH_Tunnel
 
   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 @@ core_receive (void *cls,
 
   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 @@ core_receive (void *cls,
   /* 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 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
   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,14 +401,17 @@ GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel)
 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 = ncls->notify(ncls->notify_cls, size - sizeof(struct tunnel_message), cbuf);
 
-  size_t sent = tunnel->notify(tunnel->notify_cls, size - sizeof(struct tunnel_message), cbuf);
+  GNUNET_free(ncls);
 
-  tunnel->notify = NULL;
-  tunnel->notify_cls = NULL;
+  if (0 == sent) return 0;
 
   sent += sizeof(struct tunnel_message);
 
@@ -427,15 +435,18 @@ GNUNET_MESH_notify_transmit_ready (struct
                                   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 @@ GNUNET_MESH_connect (const struct
 
   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));
 
index 880a53b81328ea4a4f470bed43e4d8c111e0e6ed..468658c4873cf25acac6e52d4f3b9ee1b95a0f6d 100644 (file)
@@ -263,8 +263,10 @@ message_token(void *cls,
                        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));
                  }
              }
index 604bb6e1a8f1949bd3338035098ed873b3751301..be62724eec073ab6a25e46d6356d1d40fb606699 100644 (file)
@@ -173,9 +173,9 @@ send_icmp_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
 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 @@ send_udp_to_peer (void *cls,
                  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);