#include "gnunet_block_lib.h"
#include "block_dns.h"
#include "gnunet_crypto_lib.h"
-#include "gnunet_mesh_service.h"
+#include "gnunet_mesh_service_new.h"
#include "gnunet_signatures.h"
struct GNUNET_MESH_Handle *mesh_handle;
GNUNET_CONNECTION_TransmitReadyNotify cb;
};
+struct tunnel_state
+{
+ struct tunnel_notify_queue *head,*tail;
+ struct GNUNET_MESH_TransmitHandle *th;
+};
+
/**
* Hijack all outgoing DNS-Traffic but for traffic leaving "our" port.
*/
GNUNET_free (virt_dns);
}
+static void *
+new_tunnel (void *cls __attribute__((unused)),
+ struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator __attribute__((unused)),
+ const struct GNUNET_ATS_Information *ats __attribute__((unused)))
+{
+ struct tunnel_state *s = GNUNET_malloc(sizeof *s);
+ s->head = NULL;
+ s->tail = NULL;
+ s->th = NULL;
+ return s;
+}
+
+static void
+clean_tunnel (void *cls __attribute__((unused)),
+ const struct GNUNET_MESH_Tunnel *tunnel,
+ void *tunnel_ctx)
+{
+ GNUNET_free(tunnel_ctx);
+}
+
/**
* Delete the hijacking-routes
*/
GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader)));
memcpy (hdr + 1, dns, *sz);
-
- if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel);
+ if (NULL != s->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 = s->head;
+ struct tunnel_notify_queue *head = s->head;
+ struct tunnel_notify_queue *tail = s->tail;
GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head (*tunnel, head);
- GNUNET_MESH_tunnel_set_tail (*tunnel, tail);
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (*tunnel,
GNUNET_NO,
42,
(const struct GNUNET_PeerIdentity *)
NULL, element->len,
element->cb, element->cls);
-
- /* save the handle */
- GNUNET_MESH_tunnel_set_data (*tunnel, th);
}
GNUNET_free (cls);
memcpy (buf, &cls_->hdr, size);
- if (NULL != GNUNET_MESH_tunnel_get_head (cls_->tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
+ if (NULL != s->head)
{
struct tunnel_notify_queue *element =
- GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ s->head;
struct tunnel_notify_queue *head =
- GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ s->head;
struct tunnel_notify_queue *tail =
- GNUNET_MESH_tunnel_get_tail (cls_->tunnel);
+ s->tail;;
GNUNET_CONTAINER_DLL_remove (head, tail, element);
- GNUNET_MESH_tunnel_set_head (cls_->tunnel, head);
- GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
GNUNET_NO,
42,
NULL, element->len,
element->cb, element->cls);
- /* save the handle */
- GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
GNUNET_free (element);
}
void
mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
if (NULL == peer)
return;
"Connected to peer %s, %x, sending query with id %d\n",
GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id));
- if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel);
+ if (NULL == s->head)
{
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (cls_->tunnel,
GNUNET_YES,
42,
mesh_send,
cls);
- GNUNET_MESH_tunnel_set_data (cls_->tunnel, th);
}
else
{
struct tunnel_notify_queue *head =
- GNUNET_MESH_tunnel_get_head (cls_->tunnel);
+ s->head;
struct tunnel_notify_queue *tail =
- GNUNET_MESH_tunnel_get_tail (cls_->tunnel);
+ s->tail;
struct tunnel_notify_queue *element =
GNUNET_malloc (sizeof (struct tunnel_notify_queue));
element->cb = mesh_send;
GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
- GNUNET_MESH_tunnel_set_head (cls_->tunnel, head);
- GNUNET_MESH_tunnel_set_tail (cls_->tunnel, tail);
}
}
struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
+ struct tunnel_state *s = GNUNET_malloc(sizeof *s);
+ s->head = NULL;
+ s->tail = NULL;
+ s->th = NULL;
+
cls_->tunnel =
- GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
- GNUNET_TIME_UNIT_HOURS,
- GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
- mesh_connect, NULL, cls_);
+ GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_);
+
+ GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel,
+ GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER);
remote_pending[cls_->dns.s.id] = cls_;
}
__attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
/* TODo: size check */
struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
*t = query_states[dns->s.id].tunnel;
memcpy (t + 1, dns, r);
- if (NULL ==
- GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel);
+ if (NULL == s->th)
{
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel,
GNUNET_YES,
32,
sizeof (struct
GNUNET_MessageHeader),
mesh_send_response, c);
-
- GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, th);
}
else
{
struct tunnel_notify_queue *head =
- GNUNET_MESH_tunnel_get_head (query_states[dns->s.id].tunnel);
+ s->head;
struct tunnel_notify_queue *tail =
- GNUNET_MESH_tunnel_get_tail (query_states[dns->s.id].tunnel);
+ s->tail;
struct tunnel_notify_queue *element =
GNUNET_malloc (sizeof (struct tunnel_notify_queue));
element->cb = mesh_send_response;
GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
- GNUNET_MESH_tunnel_set_head (query_states[dns->s.id].tunnel, head);
- GNUNET_MESH_tunnel_set_tail (query_states[dns->s.id].tunnel, tail);
}
}
else
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
- mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes);
+ mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes);
cfg = cfg_;
dht = GNUNET_DHT_connect (cfg, 1024);