From 6813281cd9f9eac5e6d285fb87725d5d71b76ebb Mon Sep 17 00:00:00 2001 From: Philipp Tölke Date: Sun, 30 Oct 2011 19:35:13 +0000 Subject: gnunet-daemon-vpn uses the new mesh --- src/vpn/Makefile.am | 2 +- src/vpn/gnunet-daemon-vpn-dns.c | 2 +- src/vpn/gnunet-daemon-vpn-helper.c | 65 +++++++++++++---------------- src/vpn/gnunet-daemon-vpn.c | 83 +++++++++++++++++++------------------- src/vpn/gnunet-daemon-vpn.h | 5 ++- 5 files changed, 74 insertions(+), 83 deletions(-) (limited to 'src/vpn') diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 5627773aa..a81a71838 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am @@ -42,7 +42,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 \ + $(top_builddir)/src/mesh/libgnunetmeshnew.la \ $(GN_LIBINTL) gnunet_service_dns_SOURCES = \ diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c index 7f762238c..b3a9929a1 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 a91a0591f..9ee6021c8 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 @@ -152,13 +152,13 @@ start_helper_and_schedule (void *cls, /*}}}*/ -void -initialize_tunnel_state(struct GNUNET_MESH_Tunnel* tunnel, int addrlen, struct GNUNET_MESH_TransmitHandle* th) +static void* +initialize_tunnel_state(int addrlen, struct GNUNET_MESH_TransmitHandle* th) { struct tunnel_state* ts = GNUNET_malloc(sizeof *ts); ts->addrlen = addrlen; ts->th = th; - GNUNET_MESH_tunnel_set_data(tunnel, ts); + return ts; } /** @@ -424,21 +424,19 @@ message_token (void *cls __attribute__ ((unused)), void *client if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_peer_request_connect_all (mesh_handle, - GNUNET_TIME_UNIT_FOREVER_REL, - 1, + GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), + &send_pkt_to_peer, NULL, cls); + + GNUNET_MESH_peer_request_connect_add (*cls, (struct GNUNET_PeerIdentity *) - &me->desc.peer, - send_pkt_to_peer, NULL, - cls); + &me->desc.peer); me->tunnel = *cls; - initialize_tunnel_state(me->tunnel, 16, NULL); } else if (NULL != cls) { *cls = me->tunnel; - send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL, 0); + send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queued to send IPv6 to peer %x, type %d\n", *((unsigned int *) &me->desc.peer), ntohs (hdr->type)); @@ -475,13 +473,12 @@ message_token (void *cls __attribute__ ((unused)), void *client if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_peer_request_connect_by_type (mesh_handle, - GNUNET_TIME_UNIT_FOREVER_REL, - app_type, - send_pkt_to_peer, - NULL, cls); + GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(16, NULL), + &send_pkt_to_peer, NULL, cls); + + GNUNET_MESH_peer_request_connect_by_type (*cls, + app_type); me->tunnel = *cls; - initialize_tunnel_state(me->tunnel, 16, NULL); if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) udp_tunnel = *cls; else if (GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY == app_type) @@ -490,7 +487,7 @@ message_token (void *cls __attribute__ ((unused)), void *client else if (NULL != cls) { *cls = me->tunnel; - send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL, 0); + send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL); } } } @@ -628,22 +625,18 @@ message_token (void *cls __attribute__ ((unused)), void *client } if (me->tunnel == NULL && NULL != cls) { - *cls = - GNUNET_MESH_peer_request_connect_all (mesh_handle, - GNUNET_TIME_UNIT_FOREVER_REL, - 1, - (struct - GNUNET_PeerIdentity *) - &me->desc.peer, - send_pkt_to_peer, NULL, - cls); + *cls = GNUNET_MESH_tunnel_create(mesh_handle, + initialize_tunnel_state(4, NULL), + send_pkt_to_peer, NULL, cls); + GNUNET_MESH_peer_request_connect_add (*cls, + (struct GNUNET_PeerIdentity *) + &me->desc.peer); me->tunnel = *cls; - initialize_tunnel_state(me->tunnel, 4, NULL); } else if (NULL != cls) { *cls = me->tunnel; - send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL, 0); + send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queued to send IPv4 to peer %x, type %d\n", *((unsigned int *) &me->desc.peer), @@ -676,18 +669,16 @@ message_token (void *cls __attribute__ ((unused)), void *client if (me->tunnel == NULL && NULL != cls) { *cls = - GNUNET_MESH_peer_request_connect_by_type (mesh_handle, - GNUNET_TIME_UNIT_FOREVER_REL, - app_type, - send_pkt_to_peer, - NULL, cls); + GNUNET_MESH_tunnel_create(mesh_handle, initialize_tunnel_state(4, NULL), + send_pkt_to_peer, NULL, cls); + + GNUNET_MESH_peer_request_connect_by_type (*cls, app_type); me->tunnel = *cls; - initialize_tunnel_state(me->tunnel, 4, NULL); } else if (NULL != cls) { *cls = me->tunnel; - send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL, 0); + send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1, NULL); } } } diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index bd5938604..5b96f201e 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -30,7 +30,7 @@ #include "gnunet_common.h" #include "gnunet_protocols.h" #include "gnunet_applications.h" -#include +#include #include "gnunet_client_lib.h" #include "gnunet_container_lib.h" #include "gnunet_constants.h" @@ -300,17 +300,14 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) else size = 0; - if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel)) + if (NULL != ts->head) { - struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head (*tunnel); - struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); - struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); + struct tunnel_notify_queue *element = ts->head; + struct tunnel_notify_queue *head = ts->head; + struct tunnel_notify_queue *tail = ts->tail; GNUNET_CONTAINER_DLL_remove (head, tail, element); - GNUNET_MESH_tunnel_set_head (*tunnel, head); - GNUNET_MESH_tunnel_set_tail (*tunnel, tail); - ts->th = GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, @@ -340,10 +337,7 @@ port_in_ports (uint64_t ports, uint16_t port) void send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi - __attribute__ ((unused)), - unsigned int atsi_count - __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) { /* peer == NULL means that all peers in this request are connected */ if (peer == NULL) @@ -372,17 +366,14 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, } else { - struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); - struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); + struct tunnel_notify_queue *head = ts->head; + struct tunnel_notify_queue *tail = ts->tail; struct tunnel_notify_queue *element = GNUNET_malloc (sizeof *element); element->cls = cls; element->len = ntohs (hdr->size); GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); - - GNUNET_MESH_tunnel_set_head (*tunnel, head); - GNUNET_MESH_tunnel_set_tail (*tunnel, tail); } } @@ -865,23 +856,18 @@ add_additional_port (struct map_entry *me, uint16_t port) } static int -receive_udp_back (void *cls - __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx - __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *sender - __attribute__ ((unused)), +receive_udp_back (void *cls __attribute__ ((unused)), + struct GNUNET_MESH_Tunnel *tunnel, + void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi - __attribute__ ((unused)), - unsigned int atsi_count - __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) { GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); struct remote_addr *s = (struct remote_addr *) desc; struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); - const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); - struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(tunnel); + const struct GNUNET_PeerIdentity *other = sender; + struct tunnel_state *ts = *tunnel_ctx; if (16 == ts->addrlen) { @@ -1047,23 +1033,18 @@ receive_udp_back (void *cls } static int -receive_tcp_back (void *cls - __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, - void **tunnel_ctx - __attribute__ ((unused)), - const struct GNUNET_PeerIdentity *sender - __attribute__ ((unused)), +receive_tcp_back (void *cls __attribute__ ((unused)), + struct GNUNET_MESH_Tunnel *tunnel, + void **tunnel_ctx, + const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), const struct GNUNET_MessageHeader *message, - const struct GNUNET_ATS_Information *atsi - __attribute__ ((unused)), - unsigned int atsi_count - __attribute__ ((unused))) + const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) { GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); struct remote_addr *s = (struct remote_addr *) desc; struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); - const struct GNUNET_PeerIdentity *other = GNUNET_MESH_get_peer (tunnel); - struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(tunnel); + const struct GNUNET_PeerIdentity *other = sender; + struct tunnel_state *ts = *tunnel_ctx; size_t pktlen = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - @@ -1236,6 +1217,24 @@ receive_tcp_back (void *cls return GNUNET_OK; } +static void* new_tunnel(void* cls, + struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *initiator, + const struct GNUNET_ATS_Information *atsi) +{ + /* Why should anyone open an inbound tunnel to vpn? */ + GNUNET_break(0); + return NULL; +} + +static void cleaner(void *cls, + const struct GNUNET_MESH_Tunnel *tunnel, + void *tunnel_ctx) +{ + /* Why should anyone open an inbound tunnel to vpn? */ + GNUNET_break(0); +} + /** * Main function that will be run by the scheduler. * @@ -1260,7 +1259,7 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep GNUNET_APPLICATION_TYPE_END }; - mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, handlers, types); + mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, types); cfg = cfg_; restart_hijack = 0; hashmap = GNUNET_CONTAINER_multihashmap_create (65536); diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h index 641be914d..95218aa61 100644 --- a/src/vpn/gnunet-daemon-vpn.h +++ b/src/vpn/gnunet-daemon-vpn.h @@ -56,8 +56,7 @@ port_in_ports (uint64_t ports, uint16_t port); void send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_ATS_Information *atsi, - unsigned int atsi_count); + const struct GNUNET_ATS_Information *atsi); /** * The configuration to use @@ -132,6 +131,8 @@ struct remote_addr struct tunnel_state { struct GNUNET_MESH_TransmitHandle *th; + struct tunnel_notify_queue *head, *tail; + int addrlen; }; -- cgit v1.2.3