From: Philipp Tölke Date: Mon, 10 Jan 2011 21:41:47 +0000 (+0000) Subject: let -vpn and -exit use mesh instead of core X-Git-Tag: initial-import-from-subversion-38251~19346 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0a6ec77c1fa98c3c3b7bd5ea4cc6a4f645138354;p=oweals%2Fgnunet.git let -vpn and -exit use mesh instead of core --- diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 1f5f5c5c0..9100fd900 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am @@ -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 = \ diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 68c32eaec..909f67842 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #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); diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c index d0b407667..0149f3323 100644 --- a/src/vpn/gnunet-daemon-vpn-dns.c +++ b/src/vpn/gnunet-daemon-vpn-dns.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index 8c4eb593d..880a53b81 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -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)); } } diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index b67e4670c..604bb6e1a 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -32,7 +32,7 @@ #include "gnunet_common.h" #include #include "gnunet_protocols.h" -#include +#include #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_; diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h index cec47ae76..382ac9a72 100644 --- a/src/vpn/gnunet-daemon-vpn.h +++ b/src/vpn/gnunet-daemon-vpn.h @@ -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; /**