let -vpn and -exit use mesh instead of core
authorPhilipp Tölke <toelke@in.tum.de>
Mon, 10 Jan 2011 21:41:47 +0000 (21:41 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Mon, 10 Jan 2011 21:41:47 +0000 (21:41 +0000)
src/vpn/Makefile.am
src/vpn/gnunet-daemon-exit.c
src/vpn/gnunet-daemon-vpn-dns.c
src/vpn/gnunet-daemon-vpn-helper.c
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-daemon-vpn.h

index 1f5f5c5c05710f30b1dad897d72d4b1e3d0f687e..9100fd900a679e8685ac05af9b291232ab2386c7 100644 (file)
@@ -43,6 +43,7 @@ gnunet_daemon_vpn_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/mesh/libgnunetmesh.la \
   $(GN_LIBINTL)
 
 gnunet_service_dns_SOURCES = \
@@ -62,6 +63,7 @@ gnunet_daemon_exit_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/mesh/libgnunetmesh.la \
   $(GN_LIBINTL)
 
 #check_PROGRAMS = \
index 68c32eaec3873b3b136e937397d8d320ddbc65c5..909f67842812c86cab053ed401bbc2a20f75accc 100644 (file)
@@ -27,7 +27,7 @@
 #include <gnunet_common.h>
 #include <gnunet_program_lib.h>
 #include <gnunet_protocols.h>
-#include <gnunet_core_service.h>
+#include <gnunet_mesh_service.h>
 #include <gnunet_constants.h>
 
 #include "gnunet-vpn-packet.h"
@@ -38,9 +38,9 @@
 static int ret;
 
 /**
- * The handle to core
+ * The handle to mesh
  */
-static struct GNUNET_CORE_Handle *core_handle;
+static struct GNUNET_MESH_Handle *mesh_handle;
 
 /**
  * This hashmap contains the mapping from peer, service-descriptor,
@@ -54,6 +54,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *udp_connections;
 struct udp_state
 {
   struct GNUNET_PeerIdentity peer;
+  struct GNUNET_MESH_Tunnel *tunnel;
   GNUNET_HashCode desc;
   short spt;
   short dpt;
@@ -75,10 +76,10 @@ static void
 cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
     GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
 
-    if (core_handle != NULL)
+    if (mesh_handle != NULL)
       {
-       GNUNET_CORE_disconnect(core_handle);
-       core_handle = NULL;
+       GNUNET_MESH_disconnect(mesh_handle);
+       mesh_handle = NULL;
       }
 }
 
@@ -137,9 +138,10 @@ receive_from_network (void *cls,
   memcpy (desc, &data->state.desc, sizeof (GNUNET_HashCode));
   memcpy (pkt + 1, buf, len);
 
-  GNUNET_CORE_notify_transmit_ready (core_handle, 42,
+  GNUNET_MESH_notify_transmit_ready (data->state.tunnel, 42,
+                                    GNUNET_NO,
                                     GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
-                                    &data->state.peer, len_pkt,
+                                    len_pkt,
                                     send_udp_service, hdr);
 
 out:
@@ -169,13 +171,16 @@ send_to_network (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
 }
 
+/** 
+ * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
+ */
 static int
-receive_udp_service (void *cls, const struct GNUNET_PeerIdentity *other,
+receive_udp_service (void *cls,
+                    struct GNUNET_MESH_Tunnel *tunnel,
+                    void **tunnel_ctx,
                     const struct GNUNET_MessageHeader *message,
                     const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received UDP-Packet from peer %s\n",
-             GNUNET_i2s (other));
   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
   struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
 
@@ -191,7 +196,7 @@ receive_udp_service (void *cls, const struct GNUNET_PeerIdentity *other,
   struct udp_state *state = &send->state;
   unsigned int new = GNUNET_NO;
 
-  memcpy (&state->peer, other, sizeof (struct GNUNET_PeerIdentity));
+  state->tunnel = tunnel;
   memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
   state->spt = ntohs (pkt->spt);
 
@@ -250,21 +255,13 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg_)
 {
-  const static struct GNUNET_CORE_MessageHandler handlers[] = {
+  const static struct GNUNET_MESH_MessageHandler handlers[] = {
        {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0},
        {NULL, 0, 0}
   };
-  core_handle = GNUNET_CORE_connect(cfg_,
-                                   42,
-                                   NULL,
-                                   NULL,
-                                   NULL,
-                                   NULL,
-                                   NULL,
-                                   NULL,
-                                   0,
+  mesh_handle = GNUNET_MESH_connect(cfg_,
                                    NULL,
-                                   0,
+                                   NULL, /* FIXME */
                                    handlers);
 
   udp_connections = GNUNET_CONTAINER_multihashmap_create(65536);
index d0b4076674b02c3c99d6b6652d2d9b9d2db5deea..0149f332300a77cf17f9c52a891036d4c2b380bf 100644 (file)
@@ -27,7 +27,7 @@
 #include <gnunet_common.h>
 #include <gnunet_client_lib.h>
 #include <gnunet_os_lib.h>
-#include <gnunet_core_service.h>
+#include <gnunet_mesh_service.h>
 #include <gnunet_protocols.h>
 #include <gnunet_server_lib.h>
 #include <gnunet_container_lib.h>
index 8c4eb593d21474425d5542185d474322b1c980e2..880a53b81328ea4a4f470bed43e4d8c111e0e6ed 100644 (file)
@@ -27,7 +27,7 @@
 #include <gnunet_common.h>
 #include <gnunet_client_lib.h>
 #include <gnunet_os_lib.h>
-#include <gnunet_core_service.h>
+#include <gnunet_mesh_service.h>
 #include <gnunet_protocols.h>
 #include <gnunet_server_lib.h>
 #include <gnunet_container_lib.h>
@@ -243,18 +243,28 @@ message_token(void *cls,
                    (port_in_ports(me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
                     port_in_ports(me->additional_ports, pkt6_udp->udp_hdr.dpt)))
                  {
-                   size_t size = sizeof(struct GNUNET_PeerIdentity) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len);
-                   struct GNUNET_PeerIdentity *cls = GNUNET_malloc(size);
+                   size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + sizeof(GNUNET_HashCode) + ntohs(pkt6_udp->udp_hdr.len);
+                   struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc(size);
                    struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader*)(cls+1);
                    GNUNET_HashCode* hc = (GNUNET_HashCode*)(hdr + 1);
-                   memcpy(cls, &me->desc.peer, sizeof(struct GNUNET_PeerIdentity));
+
                    memcpy(hc, &me->desc.service_descriptor, sizeof(GNUNET_HashCode));
                    memcpy(hc+1, &pkt6_udp->udp_hdr, ntohs(pkt6_udp->udp_hdr.len));
-                   GNUNET_CORE_peer_request_connect(core_handle,
-                                       GNUNET_TIME_UNIT_FOREVER_REL,
-                                       (struct GNUNET_PeerIdentity*)&me->desc.peer,
-                                       send_udp_to_peer,
-                                       cls);
+
+                   if (me->tunnel == NULL)
+                     {
+                       *cls = GNUNET_MESH_peer_request_connect_all(mesh_handle,
+                                                                   GNUNET_TIME_UNIT_FOREVER_REL,
+                                                                   1,
+                                                                   (struct GNUNET_PeerIdentity*)&me->desc.peer,
+                                                                   send_udp_to_peer,
+                                                                   NULL,
+                                                                   cls);
+                       me->tunnel = *cls;
+                     }
+                   else
+                     *cls = me->tunnel;
+                     //FIXME: somehow call send_udp_to_peer
                    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued to send to peer %x\n", *((unsigned int*)&me->desc.peer));
                  }
              }
index b67e4670cd042c19b5838403ead8af889836d70f..604bb6e1a8f1949bd3338035098ed873b3751301 100644 (file)
@@ -32,7 +32,7 @@
 #include "gnunet_common.h"
 #include <gnunet_os_lib.h>
 #include "gnunet_protocols.h"
-#include <gnunet_core_service.h>
+#include <gnunet_mesh_service.h>
 #include "gnunet_client_lib.h"
 #include "gnunet_container_lib.h"
 #include "gnunet_constants.h"
@@ -78,10 +78,10 @@ cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
        dns_connection = NULL;
       }
 
-    if (core_handle != NULL)
+    if (mesh_handle != NULL)
       {
-       GNUNET_CORE_disconnect(core_handle);
-       core_handle = NULL;
+       GNUNET_MESH_disconnect(mesh_handle);
+       mesh_handle = NULL;
       }
 }
 /*}}}*/
@@ -199,17 +199,18 @@ port_in_ports (uint64_t ports, uint16_t port)
 
 void
 send_udp_to_peer (void *cls, 
-                 int success)
+                 const struct GNUNET_PeerIdentity *peer,
+                 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
-  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);
-  GNUNET_CORE_notify_transmit_ready (core_handle,
+  GNUNET_MESH_notify_transmit_ready (*tunnel,
+                                    GNUNET_NO,
                                     42,
                                     GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2),
-                                    peer,
                                     htons (sizeof
                                            (struct GNUNET_MessageHeader) +
                                            sizeof (GNUNET_HashCode) +
@@ -374,13 +375,16 @@ add_additional_port (struct map_entry *me, uint16_t port)
 }
 
 static int
-receive_udp_back (void *cls, const struct GNUNET_PeerIdentity *other,
-            const struct GNUNET_MessageHeader *message,
-            const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+receive_udp_back (void *cls, struct GNUNET_MESH_Tunnel* tunnel,
+                 void **tunnel_ctx,
+                 const struct GNUNET_MessageHeader *message,
+                 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
   GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
   struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
   char addr[16];
+  const struct GNUNET_PeerIdentity* other = GNUNET_MESH_get_peer(tunnel);
+
   new_ip6addr(addr, &other->hashPubKey, desc);
 
   size_t size = sizeof(struct ip6_udp) + ntohs(pkt->len) - 1 - sizeof(struct udp_pkt);
@@ -444,11 +448,11 @@ receive_udp_back (void *cls, const struct GNUNET_PeerIdentity *other,
   return GNUNET_OK;
 }
 
-void init_core (void* cls, struct GNUNET_CORE_Handle* server, const struct GNUNET_PeerIdentity* my_identity, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey) {
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to CORE, I am %x\n", *((unsigned long*)my_identity));
+void init_mesh (void* cls, struct GNUNET_MESH_Handle* server, const struct GNUNET_PeerIdentity* my_identity, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey) {
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to MESH, I am %x\n", *((unsigned long*)my_identity));
 }
 
-void connect_core (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) {
+void connect_mesh (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) {
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %x\n", *((unsigned long*)peer));
 }
 
@@ -466,21 +470,13 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg_)
 {
-    const static struct GNUNET_CORE_MessageHandler handlers[] = {
+    const static struct GNUNET_MESH_MessageHandler handlers[] = {
          {receive_udp_back, GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK, 0},
          {NULL, 0, 0}
     };
-    core_handle = GNUNET_CORE_connect(cfg_,
-                                     42,
-                                     NULL,
-                                     init_core,
-                                     connect_core,
-                                     NULL,
-                                     NULL,
+    mesh_handle = GNUNET_MESH_connect(cfg_,
                                      NULL,
-                                     0,
                                      NULL,
-                                     0,
                                      handlers);
     mst = GNUNET_SERVER_mst_create(&message_token, NULL);
     cfg = cfg_;
index cec47ae765d14f1f81722fb48a3604aa942bd31e..382ac9a720795e0873180fe14b042c9fc7d2157d 100644 (file)
@@ -55,7 +55,9 @@ GNUNET_HashCode* address_mapping_exists(unsigned char addr[]);
 unsigned int port_in_ports (uint64_t ports, uint16_t port);
 
 void
-send_udp_to_peer (void *cls, int success);
+send_udp_to_peer (void *cls,
+                 const struct GNUNET_PeerIdentity *peer,
+                 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
 
 /**
  * The configuration to use
@@ -63,9 +65,9 @@ send_udp_to_peer (void *cls, int success);
 const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 /**
- * The handle to core
+ * The handle to mesh
  */
-struct GNUNET_CORE_Handle *core_handle;
+struct GNUNET_MESH_Handle *mesh_handle;
 
 /**
  * The hashmap containing the mappings from ipv6-addresses to gnunet-descriptors
@@ -74,6 +76,7 @@ struct GNUNET_CONTAINER_MultiHashMap* hashmap;
 
 struct map_entry {
     struct GNUNET_vpn_service_descriptor desc;
+    struct GNUNET_MESH_Tunnel *tunnel;
     uint16_t namelen;
     uint64_t additional_ports;
     /**