#include <gnunet_program_lib.h>
#include <gnunet_protocols.h>
#include <gnunet_applications.h>
-#include <gnunet_mesh_service.h>
+#include <gnunet_mesh_service_new.h>
#include <gnunet_constants.h>
#include <string.h>
size_t len;
};
+struct tunnel_state
+{
+ struct tunnel_notify_queue *head;
+ struct tunnel_notify_queue *tail;
+ struct GNUNET_MESH_TransmitHandle *th;
+};
+
/**
* Function that frees everything from a hashmap
*/
}
}
+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);
+}
+
static void
collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
memcpy (buf, hdr, ntohs (hdr->size));
size = ntohs (hdr->size);
- 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,
element->cls);
/* save the handle */
- GNUNET_MESH_tunnel_set_data (*tunnel, th);
GNUNET_free (element);
}
memcpy (_udp, udp, ntohs (udp->len));
- if (NULL == GNUNET_MESH_tunnel_get_data (tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel);
+ if (NULL == s->th)
{
/* No notify is pending */
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (tunnel,
GNUNET_NO,
42,
NULL, len,
send_udp_to_peer_notify_callback,
ctunnel);
-
- /* save the handle */
- GNUNET_MESH_tunnel_set_data (tunnel, th);
}
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 = s->head;
+ struct tunnel_notify_queue *tail = s->tail;
struct tunnel_notify_queue *element =
GNUNET_malloc (sizeof (struct tunnel_notify_queue));
element->len = len;
GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
- GNUNET_MESH_tunnel_set_head (tunnel, head);
- GNUNET_MESH_tunnel_set_tail (tunnel, tail);
}
}
memcpy (_tcp, tcp, pktlen);
- if (NULL == GNUNET_MESH_tunnel_get_data (tunnel))
+ struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel);
+ if (NULL == s->th)
{
/* No notify is pending */
- struct GNUNET_MESH_TransmitHandle *th =
+ s->th =
GNUNET_MESH_notify_transmit_ready (tunnel,
GNUNET_NO,
42,
len,
send_udp_to_peer_notify_callback,
ctunnel);
-
- /* save the handle */
- GNUNET_MESH_tunnel_set_data (tunnel, th);
}
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 = s->head;
+ struct tunnel_notify_queue *tail = s->tail;
struct tunnel_notify_queue *element =
GNUNET_malloc (sizeof (struct tunnel_notify_queue));
element->len = len;
GNUNET_CONTAINER_DLL_insert_tail (head, tail, element);
- GNUNET_MESH_tunnel_set_head (tunnel, head);
- GNUNET_MESH_tunnel_set_tail (tunnel, tail);
}
}
__attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n");
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
__attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
__attribute__ ((unused)),
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *atsi
- __attribute__ ((unused)),
- unsigned int atsi_count
- __attribute__ ((unused)))
+ __attribute__ ((unused)))
{
GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
* The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
*/
static int
-receive_udp_service (void *cls
- __attribute__ ((unused)),
- struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx
- __attribute__ ((unused)),
- const struct GNUNET_PeerIdentity *sender
- __attribute__ ((unused)),
+receive_udp_service (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 udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
app_idx++;
}
- mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, apptypes);
+ mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes);
}