* @param tunnel new handle to the tunnel
* @param initiator peer that started the tunnel
* @param atsi performance information for the tunnel
- * @return initial tunnel context for the tunnel (can be NULL -- that's not an error)
+ * @return initial tunnel context for the tunnel
+ * (can be NULL -- that's not an error)
*/
-typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- const struct
- GNUNET_PeerIdentity *
- initiator,
- const struct
- GNUNET_TRANSPORT_ATS_Information *
- atsi);
+typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (
+ void *cls,
+ struct GNUNET_MESH_Tunnel * tunnel,
+ const struct GNUNET_PeerIdentity * initiator,
+ const struct GNUNET_TRANSPORT_ATS_Information * atsi);
/**
*/
struct GNUNET_MESH_Handle *
GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned int queue_size, void *cls,
+ unsigned int queue_size,
+ void *cls,
GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
GNUNET_MESH_TunnelEndHandler cleaner,
const struct GNUNET_MESH_MessageHandler *handlers,
* @param cls closure
* @param peer peer identity the tunnel stopped working with
*/
-typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls,
- const struct
- GNUNET_PeerIdentity *
- peer);
+typedef void (*GNUNET_MESH_PeerDisconnectHandler) (
+ void *cls,
+ const struct GNUNET_PeerIdentity * peer);
/**
* @param peer peer identity the tunnel was created to, NULL on timeout
* @param atsi performance data for the connection
*/
-typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls,
- const struct
- GNUNET_PeerIdentity * peer,
- const struct
- GNUNET_TRANSPORT_ATS_Information
- * atsi);
+typedef void (*GNUNET_MESH_PeerConnectHandler) (
+ void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_TRANSPORT_ATS_Information * atsi);
* @param handler_cls closure for connect/disconnect handlers
*/
struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
- GNUNET_MESH_TunnelConnectHandler connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler, void *handler_cls);
+GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
+ void *tunnel_ctx,
+ GNUNET_MESH_PeerConnectHandler connect_handler,
+ GNUNET_MESH_PeerDisconnectHandler disconnect_handler,
+ void *handler_cls);
/**
* Destroy an existing tunnel.
*
- * @param tun tunnel handle
+ * @param tunnel tunnel handle
*/
void
-GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun);
+GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel);
/**
* memory); if NULL is returned, "notify" will NOT be called.
*/
struct GNUNET_MESH_TransmitHandle *
-GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
+GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
+ int cork,
uint32_t priority,
struct GNUNET_TIME_Relative maxdelay,
const struct GNUNET_PeerIdentity *target,
{
r = GNUNET_SYSERR;
}
- GNUNET_CONTAINER_multihashmap_destroy(t->peers);
+ GNUNET_CONTAINER_multihashmap_destroy (t->peers);
q = t->queue_head;
while (NULL != q)
{
if (NULL != q->data)
- GNUNET_free(q->data);
+ GNUNET_free (q->data);
qn = q->next;
- GNUNET_free(q);
+ GNUNET_free (q);
q = qn;
/* TODO cancel core transmit ready in case it was active */
}
/* deregister clients applications */
for (i = 0; i < c->app_counter; i++)
{
- for (j = 0; j < n_apps; j++)
- {
- if (c->apps[i] == applications[j] && 0 == --applications_rc[j])
- {
- applications[j] = applications[n_apps - 1];
- GNUNET_array_grow(applications, n_apps, n_apps - 1);
- n_apps++;
- applications_rc[j] = applications_rc[n_apps - 1];
- GNUNET_array_grow(applications_rc, n_apps, n_apps - 1);
-
- }
- break;
- }
+ for (j = 0; j < n_apps; j++)
+ {
+ if (c->apps[i] == applications[j] && 0 == --applications_rc[j])
+ {
+ applications[j] = applications[n_apps - 1];
+ GNUNET_array_grow (applications, n_apps, n_apps - 1);
+ n_apps++;
+ applications_rc[j] = applications_rc[n_apps - 1];
+ GNUNET_array_grow (applications_rc, n_apps, n_apps - 1);
+
+ }
+ break;
+ }
}
GNUNET_free (c->apps);
if (0 == n_apps)
{
- GNUNET_SCHEDULER_cancel (announce_applications_task);
+ GNUNET_SCHEDULER_cancel (announce_applications_task);
}
}
if (0 != c->type_counter)
if (!known)
{
/* Register previously unknown application */
- GNUNET_array_append(applications, n_apps, c->apps[i]);
+ GNUNET_array_append (applications, n_apps, c->apps[i]);
n_apps--;
- GNUNET_array_append(applications_rc, n_apps, 1);
+ GNUNET_array_append (applications_rc, n_apps, 1);
if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
{
announce_applications_task =
GNUNET_free (handle);
}
-/* end of mesh_api.c */
+/* end of mesh_api.c */
\ No newline at end of file
/**
* Callback to execute when peers connect to the tunnel
*/
- GNUNET_MESH_TunnelConnectHandler connect_handler;
+ GNUNET_MESH_PeerConnectHandler connect_handler;
/**
* Callback to execute when peers disconnect from the tunnel
*/
- GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
+ GNUNET_MESH_PeerDisconnectHandler disconnect_handler;
/**
* Closure for the connect/disconnect handlers
if (NULL == t)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return;
}
h = t->mesh;
if (th->tunnel == t)
{
aux = th->next;
- GNUNET_CONTAINER_DLL_remove(h->th_head, h->th_tail, th);
+ GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
if (NULL == h->th_head && NULL != h->th)
{
- GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+ GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
h->th = NULL;
}
if (NULL != th->notify)
- th->notify(th->notify_cls, 0, NULL);
+ th->notify (th->notify_cls, 0, NULL);
if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task)
- GNUNET_SCHEDULER_cancel(th->timeout_task);
+ GNUNET_SCHEDULER_cancel (th->timeout_task);
GNUNET_free (th);
th = aux;
}
GNUNET_free (t->peers[i]);
}
if (t->npeers > 0)
- GNUNET_free (t->peers);
+ GNUNET_free (t->peers);
if (NULL != h->cleaner && 0 != t->owner)
h->cleaner (h->cls, t, t->ctx);
if (0 != t->owner)
h->client = GNUNET_CLIENT_connect ("mesh", h->cfg);
if (h->client == NULL)
{
- GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h);
- h->reconnect_time = GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS,
- GNUNET_TIME_relative_multiply(h->reconnect_time, 2));
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
+ h->reconnect_time =
+ GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
+ GNUNET_TIME_relative_multiply
+ (h->reconnect_time, 2));
GNUNET_break (0);
return GNUNET_NO;
}
reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_MESH_Handle *h = cls;
+
if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
return;
- reconnect(h);
+ reconnect (h);
}
*/
static void
process_tunnel_created (struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MESH_TunnelNotification *msg)
+ const struct GNUNET_MESH_TunnelNotification *msg)
{
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_TRANSPORT_ATS_Information atsi;
{
atsi.type = 0;
atsi.value = 0;
- t->ctx = h->new_tunnel(h->cls, t, &msg->peer, &atsi);
+ t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
}
GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t);
return;
if (NULL == t)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return;
}
if (0 == t->owner)
{
- GNUNET_break(0);
+ GNUNET_break (0);
}
- destroy_tunnel(t);
+ destroy_tunnel (t);
return;
}
t = retrieve_tunnel (h, ntohl (msg->tunnel_id));
if (NULL == t)
{
- GNUNET_break(0);
+ GNUNET_break (0);
return;
}
id = GNUNET_PEER_search (&msg->peer);
GNUNET_break (0);
return;
}
- type = ntohs(payload->type);
+ type = ntohs (payload->type);
for (i = 0; i < h->n_handlers; i++)
{
handler = &h->message_handlers[i];
{
#if DEBUG
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: type: %u\n",
- ntohs (((struct GNUNET_MessageHeader *)&th[1])->type));
+ ntohs (((struct GNUNET_MessageHeader *) &th[1])->type));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: size: %u\n",
- ntohs (((struct GNUNET_MessageHeader *)&th[1])->size));
+ ntohs (((struct GNUNET_MessageHeader *) &th[1])->size));
#endif
if (NULL != th->notify)
{
mc.header.size = htons (sizeof (mc) + th->size);
mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
mc.tid = htonl (th->tunnel->tid);
- memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
+ memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
memcpy (cbuf, &mc, sizeof (mc));
psize = th->size + sizeof (mc);
}
uc.header.size = htons (sizeof (uc) + th->size);
uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
uc.tid = htonl (th->tunnel->tid);
- memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself */
+ memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
GNUNET_PEER_resolve (th->target, &uc.destination);
memcpy (cbuf, &uc, sizeof (uc));
psize = th->size + sizeof (uc);
*/
struct GNUNET_MESH_Tunnel *
GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
- GNUNET_MESH_TunnelConnectHandler connect_handler,
- GNUNET_MESH_TunnelDisconnectHandler
- disconnect_handler, void *handler_cls)
+ GNUNET_MESH_PeerConnectHandler connect_handler,
+ GNUNET_MESH_PeerDisconnectHandler disconnect_handler,
+ void *handler_cls)
{
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_MESH_TunnelMessage msg;
* @param tun tunnel handle
*/
void
-GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *t)
+GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
{
struct GNUNET_MESH_Handle *h;
struct GNUNET_MESH_TunnelMessage msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
- h = t->mesh;
+ h = tunnel->mesh;
- if (0 != t->owner)
- GNUNET_PEER_change_rc (t->owner, -1);
+ if (0 != tunnel->owner)
+ GNUNET_PEER_change_rc (tunnel->owner, -1);
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
- msg.tunnel_id = htonl (t->tid);
- destroy_tunnel (t);
+ msg.tunnel_id = htonl (tunnel->tid);
+ destroy_tunnel (tunnel);
send_packet (h, &msg.header);
}
uint32_t least_priority;
size_t overhead;
- GNUNET_assert(NULL != notify);
+ GNUNET_assert (NULL != notify);
if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
tunnel->npackets > 0)
{
}
if (NULL == least_priority_th)
return NULL;
- GNUNET_assert(NULL != least_priority_th->notify); /* Cant be a cntrl msg */
- least_priority_th->notify(notify_cls, 0, NULL);
+ /* Can't be a control message */
+ GNUNET_assert (NULL != least_priority_th->notify);
+ least_priority_th->notify (notify_cls, 0, NULL);
least_priority_th->tunnel->npackets--;
tunnel->mesh->npackets--;
- GNUNET_CONTAINER_DLL_remove(tunnel->mesh->th_head,
- tunnel->mesh->th_tail,
- least_priority_th);
+ GNUNET_CONTAINER_DLL_remove (tunnel->mesh->th_head, tunnel->mesh->th_tail,
+ least_priority_th);
if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task)
- GNUNET_SCHEDULER_cancel(least_priority_th->timeout_task);
- GNUNET_free(least_priority_th);
+ GNUNET_SCHEDULER_cancel (least_priority_th->timeout_task);
+ GNUNET_free (least_priority_th);
}
tunnel->npackets++;
tunnel->mesh->npackets++;
th->priority = priority;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
th->target = GNUNET_PEER_intern (target);
- overhead =
- (NULL ==
- target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct
- GNUNET_MESH_Unicast);
+ if (NULL == target)
+ overhead = sizeof (struct GNUNET_MESH_Multicast);
+ else
+ overhead = sizeof (struct GNUNET_MESH_Unicast);
th->size = notify_size + overhead;
th->notify = notify;
th->notify_cls = notify_cls;
GNUNET_MESH_tunnel_destroy (t);
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL);
}
static GNUNET_SCHEDULER_TaskIdentifier abort_task;
static GNUNET_SCHEDULER_TaskIdentifier test_task;
+static struct GNUNET_MESH_MessageHandler handlers1[] = {
+ {&callback, 1, 0},
+ {NULL, 0, 0}
+};
+
+static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} };
+
+
+
/**
* Function is called whenever a message is received.
*
const struct GNUNET_MessageHeader *message,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n");
return GNUNET_OK;
}
-static struct GNUNET_MESH_MessageHandler handlers1[] = {
- {&callback, 1, 0},
- {NULL, 0, 0}
-};
-static struct GNUNET_MESH_MessageHandler handlers2[] = {{NULL, 0, 0}};
+/**
+ * Method called whenever another peer has added us to a tunnel
+ * the other peer initiated.
+ *
+ * @param cls closure
+ * @param tunnel new handle to the tunnel
+ * @param initiator peer that started the tunnel
+ * @param atsi performance information for the tunnel
+ * @return initial tunnel context for the tunnel (can be NULL -- that's not an error)
+ */
+static void *
+inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+ const struct GNUNET_PeerIdentity *initiator,
+ const structGNUNET_TRANSPORT_ATS_Information * atsi)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: \n");
+ return NULL;
+}
+
+
+
+
+
+
+
+
static void
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
static const GNUNET_MESH_ApplicationType app1[] =
{ 1, 2, 3, 4, 5, 6, 7, 8, 0 };
- static const GNUNET_MESH_ApplicationType app2[] =
- { 0 };
+ static const GNUNET_MESH_ApplicationType app2[] = { 0 };
test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
mesh_peer_1 = GNUNET_MESH_connect (cfg, 10, 1, NULL, NULL, handlers1, app1);
t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, 1);
// t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS,
- 2),
- &do_shutdown,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown,
NULL);
}